tar包,shell脚本百度云盘链接,提取码:0y39
https://pan.baidu.com/s/1T9hrt-gWuMscnaaXhy6vXg
安装脚本如下
可参考https://blog.csdn.net/rzhidong/article/details/78432119
将安装包、脚本、配置文件放在同一目录
此脚本适用于centos6,centos7防火墙开放端口命令不一致,如需在centos7安装,80开启命令改成
firewall-cmd --zone=public --add-port=80/tcp --permanent
#!/bin/bash
# write by luozhidong
# date: 20190619
# description:默认路径为/usr/local,若要变更则修改NGINX_HOME
# nginx包为:nginx-1.16.0.tar.gz,下载地址:http://nginx.org/en/download.html
NGINX_HOME='/usr/local'
startNginx(){ $NGINX_HOME/nginx/sbin/nginx -c $NGINX_HOME/nginx/conf/nginx.conf
}
PID=$(ps -ef |grep nginx|grep -v grep|grep -v install)
if [[ -z $PID ]];then #echo "not nginx pid" #$NGINX_HOME NGINXFOLDER=$(find $NGINX_HOME -name 'nginx') if [[ -n $NGINXFOLDER ]];thenstartNginx else TARPATH=$(find . -maxdepth 1 -name '*nginx*'|grep tar.gz|grep -v sh)if [[ -n $TARPATH ]];then echo "nginx tar path: "$TARPATH if [[ -z $(find . -maxdepth 1 -name '*nginx*'|grep -v tar.gz|grep -v sh) ]];thentar -zxf $TARPATH fi PACKPATH=$(find . -maxdepth 1 -name '*nginx*'|grep -v tar.gz|grep -v sh) #yum -y install gcc gcc-c++ make pcre-devel zlib-devel#安装包内已有6.6版本的依赖rpm包if [[ -n $(find . -name "rpm") ]];thenrpm -Uvh rpm/*.rpmelsesed -i "s/keepcache=0/keepcache=1/g" /etc/yum.confyum -y install gcc gcc-c++ make pcre-devel zlib-develVERSION=$(cat /etc/redhat-release|sed -r 's/.* ([0-9]+)\..*/\1/')mkdir rpmmv /var/cache/yum/x86_64/$VERSION/base/packages/*.rpm rpm/fi#安装cd $PACKPATH ./configure --prefix=$NGINX_HOME/nginx make make install#添加到自启动RC=$(cat /etc/rc.d/rc.local |grep nginx)if [[ $RC == "" ]];thenecho "$NGINX_HOME/nginx/sbin/nginx -c $NGINX_HOME/nginx/conf/nginx.conf" >> /etc/rc.d/rc.localelseecho "/etc/rc.d/rc.local 存在 $RC"fi startNginx#打开80端口if [[ -z $(/etc/init.d/iptables status|grep 'tcp dpt:80') ]];then/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT/etc/init.d/iptables saveservice iptables restartfielse echo "nginx tar.gz not exist in current folder!" fi fi
fi
curl localhost|grep '<title>'
ps -ef |grep nginx|grep -v grep|grep -v install
验证