一键部署nginx1.19.7(Centos7)

一键部署nginx1.19.7(Centos7)

提示:

  • 脚本默认安装Nginx1.19.7,您可以通过修改nginx变量的地址和名称,安装其他版本即可
  • 安装方式是编译安装,编译的模块有:stream、http_ssl_module等,详情见代码“Nginx Configure”
  • 脚本复制使用注意格式问题,脚本经过腾讯云测试,亲测可用,无人值守,有问题可以留言
**以 nginx 1.18.0 稳定版为例**
nginx_Download="http://nginx.org/download/nginx-1.18.0.tar.gz"
nginx="nginx-1.18.0"
#!/bin/bash
#作者:wzx
#更新时间:2021-02-19
#版本V1.0
#path
pcre_Download="https://ftp.pcre.org/pub/pcre/pcre-8.44.tar.gz"
zlib_Download="http://www.zlib.net/zlib-1.2.11.tar.gz"
openssl_Download="https://www.openssl.org/source/openssl-1.1.1j.tar.gz"
perl_Download="https://www.cpan.org/src/5.0/perl-5.32.1.tar.gz"
nginx_Download="http://nginx.org/download/nginx-1.19.7.tar.gz"
pcre="pcre-8.44"
zlib="zlib-1.2.11"
openssl="openssl-1.1.1j"
perl="perl-5.32.1"
nginx="nginx-1.19.7"

#ti qian chuang jian mu lu , ri zhi File.
mkdir -p /etc/nginx
mkdir -p /var/log/nginx
touch /var/log/nginx/access.log
touch /var/log/nginx/erro.log
touch /usr/lib/systemd/system/nginx.service
nginx_service="/usr/lib/systemd/system/nginx.service"

#xia zai
echo "start Download GCC Pcre zlib openssl nginx perl ...."
echo "wait to finshed...."

yum install -y gcc-c++ &> /dev/null

if [ -f /root/"$pcre".tar.gz ]
then
    echo "File exists"
else
	echo "Starting Download ""$pcre"" , please wait...."
	cd /root
	wget $pcre_Download &> /dev/null
fi

if [ -f /root/"$zlib".tar.gz ]
then
    echo "File exists"
else
	echo "Starting Download ""$zlib"" , please wait...."
	cd /root
	wget $zlib_Download &> /dev/null
fi

if [ -f /root/"$openssl".tar.gz ]
then
    echo "File exists"
else
	echo "Starting Download ""$openssl"" , please wait...."
	cd /root
	wget $openssl_Download &> /dev/null
fi

if [ -f /root/"$perl".tar.gz ]
then
    echo "File exists"
else
	echo "Starting Download ""$perl"" , please wait...."
	cd /root
	wget $perl_Download &> /dev/null
fi

if [ -f /root/"$nginx".tar.gz ]
then
    echo "File exists"
else
	echo "Starting Download ""$nginx"" , please wait...."
	cd /root
	wget $nginx_Download &> /dev/null
fi

if [ $? -eq 0 ];then
echo "Download ALL successfully"
fi

#jie ya suo
PATH1=/root
PATH2=/root
for i in `ls ${PATH1}/*`  
do
tar -zxvf  $i  -C $PATH2
done

echo "Install perl 5 Just waiting.."
cd /root/$perl

echo "Configure.."
./Configure -des -Dprefix=$HOME/localperl

if [ $? -eq 0 ];then
echo "Perl 5 Configure successfully.."
fi

echo "Is install waiting..."
make && make install
if [ $? -eq 0 ];then
echo "Perl 5 install successfully"
fi
sleep 3

echo "Waiting install nginx.."
cd /root/$nginx
echo "Nginx Configure......."
./configure \--prefix=/etc/nginx \--with-pcre=../$pcre \--with-zlib=../$zlib \--with-openssl=../$openssl \--user=root \--group=root \--with-file-aio \--with-http_v2_module \--with-http_ssl_module \--with-http_realip_module \--with-http_sub_module \--with-http_gzip_static_module \--with-http_stub_status_module \--with-stream
if [ $? -eq 0 ];then
echo "Nginx Configure successfully.."
fi

echo "Nginx install...."
make && make install
if [ $? -eq 0 ];then
echo "Nginx install successfully"
fi

cat>$nginx_service<<EOF
[Unit]
Description=nginx
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/etc/nginx/logs/nginx.pid
ExecStart=/etc/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
EOF

cp /etc/nginx/sbin/nginx /usr/bin

echo "正在关闭防火墙..."
systemctl stop firewalld
systemctl disable firewalld
if [ $? -eq 0 ];then
echo "firewall stop successfully!"
fi

echo "正在关闭selinux..."
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/sysconfig/selinux
setenforce 0
if [ $? -eq 0 ];then
echo "selinux stop successfully!"
fi

systemctl daemon-reload
echo "Start Nginx"
systemctl start nginx
if [ $? -eq 0 ];then
echo "Nginx start successfully"
fi

echo "Enable Nginx"
systemctl enable nginx
if [ $? -eq 0 ];then
echo "Enable Nginx successfully"
fi

systemctl status nginx | grep Active
nginx -t

#del setup package
echo "Start to del Setup package..."

rm -rf /root/nginx*
rm -rf /root/pcre*
rm -rf /root/zlib*
rm -rf /root/openssl*
if [ $? -eq 0 ];then
echo "del Setup package Done!!"
fi
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值