nginx自动安装脚本
本次环境为centos7,本人小菜鸟一只,希望各位大佬提出宝贵的意见,小弟谢谢了!!!
#!/bin/bash echo "安装必要的依赖环境" yum install -y gcc gcc-c++ make echo "下载相关库文件和nginx安装包" wget https://www.openssl.org/source/openssl-1.1.1.tar.gz wget http://www.zlib.net/zlib-1.2.11.tar.gz wget https://ftp.pcre.org/pub/pcre/pcre-8.33.tar.gz wget http://nginx.org/download/nginx-1.14.0.tar.gz echo "解压并安装库文件" #安装pcre库 temp_path=/root/nginx install_path=/usr/local/nginx rm -rf $temp_path rm -rf $install_path mkdir $temp_path mkdir $install_path tar -xvf pcre-8.33.tar.gz -C $temp_path cd /root/nginx/pcre-8.33 ./configure --prefix=/usr/local/nginx/pcre make && make install cd - #安装openssl库 tar -xvf openssl-1.1.1.tar.gz -C $temp_path cd /root/nginx/openssl-1.1.1 ./config --prefix=/usr/local/nginx/openssl make && make install cd - #安装zlib库 tar -xvf zlib-1.2.11.tar.gz -C $temp_path cd /root/nginx/zlib-1.2.11 ./configure --prefix=/usr/local/nginx/zlib make && make install cd - #安装nginx tar -xvf nginx-1.14.0.tar.gz -C $temp_path cd /root/nginx/nginx-1.14.0 ./configure --prefix=/usr/local/nginx/nginx make && make install cd /usr/local/nginx/nginx/sbin ./nginx netstat -ntlp echo "complete!" echo "#######################" echo "将nginx加入环境变量" cat >> /etc/profile << EOF NGINX_HOME=/usr/local/nginx/nginx PATH=$NGINX_HOME/sbin:$PATH export PATH EOF source /etc/profile #这里是为了验证配置的环境是否生效 /usr/local/nginx/nginx/sbin/nginx /usr/local/nginx/nginx/sbin/nginx -V #配置开机启动命令 qidong_path=/lib/systemd/system/nginx.service touch $qidong_path cat > $qidong_path << EOF [Unit] Description=nginx After=network.target [Service] Type=forking ExecStart=/usr/local/nginx/nginx/sbin/nginx ExecReload=/usr/local/nginx/nginx/sbin/nginx reload ExecStop=/usr/local/nginx/nginx/sbin/nginx quit PrivateTmp=true [Install] WantedBy=multi-user.target EOF systemctl start nginx systemctl status nignx
版本信息:2020/09/08修改
本文仅为学习交流所用,部分来源于网上整理,文中涉及的环境均为虚拟环境,请勿用于真实生产环境,否则后果自负!所有责任均与本人和平台无关!!!
转载请注明原处!!!