脚本

NGINX_FILE=nginx-1.22.0
#NGINX_FILE=nginx-1.20.2
#NGINX_FILE=nginx-1.18.0
NGINX_URL=http://nginx.org/download/
TAR=.tar.gz
SRC_DIR=/usr/local/src
#安装路径
NGINX_INSTALL_DIR=/apps/nginx
CPUS=`lscpu |awk '/^CPU\(s\)/{print $2}'`
. /etc/os-release#颜色
color () {RES_COL=60MOVE_TO_COL="echo -en \\033[${RES_COL}G"SETCOLOR_SUCCESS="echo -en \\033[1;32m"SETCOLOR_FAILURE="echo -en \\033[1;31m"SETCOLOR_WARNING="echo -en \\033[1;33m"SETCOLOR_NORMAL="echo -en \E[0m"echo -n "$1" && $MOVE_TO_COLecho -n "["if [ $2 = "success" -o $2 = "0" ] ;then${SETCOLOR_SUCCESS}echo -n $"  OK  "    elif [ $2 = "failure" -o $2 = "1"  ] ;then${SETCOLOR_FAILURE}echo -n $"FAILED"else${SETCOLOR_WARNING}echo -n $"WARNING"fi${SETCOLOR_NORMAL}echo -n "]"echo
}#检查是否安装,未安装下载安装包到/usr/local/src
check () {[ -e ${NGINX_INSTALL_DIR} ] && { color "nginx 已安装,请卸载后再安装" 1; exit; }cd  ${SRC_DIR}if [  -e ${NGINX_FILE}${TAR} ];thencolor "相关文件已准备好" 0elsecolor '开始下载 nginx 源码包' 0wget ${NGINX_URL}${NGINX_FILE}${TAR}[ $? -ne 0 ] && { color "下载 ${NGINX_FILE}${TAR}文件失败" 1; exit; }fi
}
#判断系统安装nginx
install () {color "开始安装 nginx" 0if id nginx  &> /dev/null;thencolor "nginx 用户已存在" 1elseuseradd -s /sbin/nologin -r  nginxcolor "创建 nginx 用户" 0ficolor "开始安装 nginx 依赖包" 0if [ $ID == "centos" ] ;thenif [[ $VERSION_ID =~ ^7 ]];thenyum -y  install  gcc  make pcre-devel openssl-devel zlib-devel perl-ExtUtils-Embedelif [[ $VERSION_ID =~ ^8 ]];thenyum -y  install make gcc-c++ libtool pcre pcre-devel zlib zlib-devel openssl openssl-devel perl-ExtUtils-Embedelsecolor '不支持此系统!'  1exitfielif [ $ID == "rocky"  ];thenyum -y  install gcc make gcc-c++ libtool pcre pcre-devel zlib zlib-devel openssl openssl-devel perl-ExtUtils-Embedelseapt updateapt -y install gcc make  libpcre3 libpcre3-dev openssl libssl-dev zlib1g-devficd $SRC_DIRtar xf ${NGINX_FILE}${TAR}NGINX_DIR=`echo ${NGINX_FILE}${TAR}| sed -nr 's/^(.*[0-9]).*/\1/p'`cd ${NGINX_DIR}./configure --prefix=${NGINX_INSTALL_DIR} --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_modulemake -j $CPUS && make install[ $? -eq 0 ] && color "nginx 编译安装成功" 0 ||  { color "nginx 编译安装失败,退出!" 1 ;exit; }chown -R nginx.nginx ${NGINX_INSTALL_DIR}echo "PATH=${NGINX_INSTALL_DIR}/sbin:${PATH}" > /etc/profile.d/nginx.sh
#添加自启动文件
cat > /lib/systemd/system/nginx.service <<EOF
[Unit]
Description=The nginx HTTP and reverse proxy server
After=network.target remote-fs.target nss-lookup.target[Service]
Type=forking
PIDFile=${NGINX_INSTALL_DIR}/logs/nginx.pid
ExecStartPre=/bin/rm -f ${NGINX_INSTALL_DIR}/logs/nginx.pid
ExecStartPre=${NGINX_INSTALL_DIR}/sbin/nginx -t
ExecStart=${NGINX_INSTALL_DIR}/sbin/nginx
ExecReload=/bin/kill -s HUP \$MAINPID
KillSignal=SIGQUIT
TimeoutStopSec=5
KillMode=process
PrivateTmp=true
LimitNOFILE=100000[Install]
WantedBy=multi-user.target
EOF
#加载service文件,启动nginxsystemctl daemon-reloadsystemctl enable --now nginx &> /dev/nullsystemctl is-active nginx &> /dev/null ||  { color "nginx 启动失败,退出!" 1 ; exit; }color "nginx 安装完成" 0
}check
install

安装好后

source /etc/profile.d/nginx.sh

文件总大小

[root@rocky86-101 ~]# du -sh /apps/nginx/
108M    /apps/nginx/

目录结构

[root@rocky86-101 ~]# tree /apps/nginx
/apps/nginx
├── client_body_temp
├── conf
│   ├── fastcgi.conf
│   ├── fastcgi.conf.default
│   ├── fastcgi_params
│   ├── fastcgi_params.default
│   ├── koi-utf
│   ├── koi-win
│   ├── mime.types
│   ├── mime.types.default
│   ├── nginx.conf
│   ├── nginx.conf.default
│   ├── scgi_params
│   ├── scgi_params.default
│   ├── uwsgi_params
│   ├── uwsgi_params.default
│   └── win-utf
├── fastcgi_temp
├── html
│   ├── 50x.html
│   ├── index.html
│   └── test.img
├── logs
│   ├── access.log
│   ├── error.log
│   └── nginx.pid
├── proxy_temp
├── sbin
│   └── nginx
├── scgi_temp
└── uwsgi_temp9 directories, 22 files

配置文件

[root@rocky86-101 ~]# grep -Ev '^ *#|^$' /apps/nginx/conf/nginx.conf
worker_processes  1;
events {worker_connections  1024;
}
http {include       mime.types;default_type  application/octet-stream;sendfile        on;keepalive_timeout  65;server {listen       80;server_name  localhost;location / {root   html;index  index.html index.htm;}error_page   500 502 503 504  /50x.html;location = /50x.html {root   html;}}
}

一键安装nginx脚本相关推荐

  1. shell脚本一键安装nginx

        使用shell脚本一键安装Nginx 操作环境Centos7,联网进行安装. 代码如下: #!/bin/bash #this is nginx.sh #date 2018.10.6 [ $(i ...

  2. 一键安装nginx(auto_nginx_install.sh

    #!/bin/bash#auto install nginx#by 杨进 2021-02#nginx define path variable#加入变量后期维护更加简单,智能化#替换所有的的 %s#y ...

  3. centos6一键安装vsftpd脚本

    centos6一键安装vsftpd脚本 手动安装vsftpd参考教程:Centos下安装Vsftpd的图文教程 vsftpd脚本功能: 1.安装 (命令执行:sh xxx.sh)2.添加ftp用户 ( ...

  4. 【Linux】Aria2 一键安装管理脚本 BT\PT一键安装包

    项目地址 https://github.com/P3TERX/aria2.sh 系统要求 CentOS 6+ / Debian 6+ / Ubuntu 14.04+ 下载安装 执行下面的代码下载并运行 ...

  5. Centos Denyhosts 一键安装配置脚本

    Centos Denyhosts 一键安装配置脚本 一键安装denyhosts脚本并配置为常用配置.放置Linux服务器被暴力破解 由于不能上传tar文件.所以改为zip压缩. 将附件的zip压缩包解 ...

  6. s14.一键安装haproxy脚本

    一键安装haproxy脚本 root@ubuntu1804:~# cat install_haproxy.sh #!/bin/bash # #***************************** ...

  7. s15.一键安装java脚本

    一键安装java脚本 #安装java8 root@ubuntu1804:~# cat install_jdk_8.sh #!/bin/bash # #************************* ...

  8. centos8中一键安装Nginx

    1:检查是否安装 [root@aa ~]# nginx -v -bash: nginx: command not found 2:一键安装yum install -y nginx [root@aa ~ ...

  9. 一键安装lamp脚本--初级版

    #!/bin/bash #write by zhang_pc #at 2015.07.21 #apache2.2.27 mysql5.1 php5.4 #安装说明,由于网速原因,就不下载了,执行脚本前 ...

最新文章

  1. ADI射频电路计算小工具ADIsimRF介绍
  2. 服务器返回的信息无效或无法识别的响应,c# - 服务器从Visual Studio返回了无效或无法识别的响应错误 - 堆栈内存溢出...
  3. 【HDU 4547 CD操作】LCA问题 Tarjan算法
  4. Hadoop Hive 创建表及count/distinct操作(会被翻译成mr程序)
  5. wxWidgets:wxCaret 示例
  6. python中的any函数_python函数-any()
  7. 环的寻找:寻找无向图中所有存在的环-删除点法
  8. F. 更改apache端口号
  9. 二叉树的遍历(算法导论第三版12.1-4)(包含先序遍历,后序遍历和中序遍历)
  10. 产品经理专业知识50篇(五)-用户成长体系设计方案
  11. Git rebase命令实战
  12. 南阳oj92--图像有用区域(Bfs)
  13. nginx的限流配置
  14. jstat命令(Java Virtual Machine Statistics Monitoring Tool
  15. PyTorch 1.0 中文文档:torch.distributed
  16. python 绝对路径找不到文件_python获取文件绝对路径解决找不到文件句柄的问题实例(readConfig.py)V1.2...
  17. c++学习笔记(5)
  18. simhash与minhash
  19. 已测试:网上大神写的快手极速版脚本,autojs版快手极速版自动脚本下载
  20. Java编程语言的重要性

热门文章

  1. html div 居中心,div在屏幕中水平居中 div内容居中
  2. 用HTML+CSS跟简单的js操作完成响应式星巴克首页
  3. Composer 基本使用方法
  4. 接触角测量方法的发展
  5. Wind River Workbench VxWorks项目开发流程
  6. Java之Math三种取整方法
  7. 纺织厂布匹唛头标签快速打印系统
  8. 【转载】使用JQDATA获取数据并本地化(Mysql储存)
  9. 士兵队列训练问题(队列--先进先出)
  10. feign.RetryableException: 连接超时 (Connection timed out) executing xxx FeignException.java:249