1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
| #!/bin/bash
set -e echo -e "\033[33m 1.此脚本只适用于首次安装部署,多次执行此脚本会覆盖nginx配置文件 \n 2.想部署其他版本的需要自行更改链接:http://nginx.org/download/nginx-1.13.0.tar.gz 找到指定版本即可 \n \033[0m" echo -e "\033[36m ===========================start -初始化 \033[0m" sleep 2 nginx_v="nginx-1.16.1.tar.gz" dir="nginx-1.16.1"
nginx_install_app() { echo -e "\033[36m 下载安装编译的依赖包 \033[0m" sudo apt-get install build-essential libtool -y sudo apt-get install libpcre3 libpcre3-dev -y sudo apt-get install zlib1g-dev -y sudo apt-get install openssl -y sudo apt install zlib1g-dev openssl libssl-dev libpcre3 libpcre3-dev -y [ $? = 0 ] && echo -e "\033[36m 依赖:${yilai} 安装完成 \033[0m" || echo -e "\033[33m 依赖安装失败 \033[0m" echo -e "\033[36m =============开始下载nginx压缩包 \033[0m" wget http://nginx.org/download/${nginx_v} tar -zxvf ./${nginx_v} -C /usr/local/src/ } nginx_make() { echo -e "\033[36m 开始编译安装:${nginx_v} \033[0m" cd /usr/local/src/${dir} && ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_slice_module --with-stream echo -e "\033[36m make \033[0m" cd /usr/local/src/${dir} && make echo -e "\033[36m make install \033[0m" cd /usr/local/src/${dir} && make install [ $? = 0 ] && echo -e "\033[36m 依赖:编译安装完成全路径启动命令"/usr/local/nginx/sbin/nginx" \033[0m" || echo -e "\033[33m 编译安装失败 \033[0m" /usr/local/nginx/sbin/nginx -t } nginx_system() { echo -e "\033[36m ==============================开始建立'nginx'托管文件 \033[0m" cat <<EOF >/etc/systemd/system/nginx.service [Unit] Description=nginx server Documentation=http://nginx.org/en/docs/ After=network.target
[Service] Type=forking #Type=simple #PIDFile=/usr/local/nginx/logs/nginx.pid ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf ExecReload=/bin/kill -SIGHUP \$MAINPID ExecStop=/bin/kill -SIGINT \$MAINPID Restart=always RestartSec=5 #StartLimitInterval=0
[Install] WantedBy=multi-user.target EOF systemctl daemon-reload systemctl start nginx.service systemctl status nginx.service echo -e "\033[36m 概览 nginx安装完成访问方式-----------------------------------浏览器访问: http://localhost 1. nginx执行文件全路径为:"/usr/local/nginx/sbin/nginx" 若要使用nginx命令需要以 全路径方式 2. nginx 常用命令: /usr/local/nginx/sbin/nginx -v # -V 查看编译模块 /usr/local/nginx/sbin/nginx -V /usr/local/nginx/sbin/nginx -t 等 3. ----------------------------------------------------nginx版本为: \033[0m" /usr/local/nginx/sbin/nginx -v } main(){ nginx_install_app nginx_make nginx_system } main
|