Centos6 nginx1.16一键安装脚本

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 ]];then
		startNginx 
	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) ]];then
				tar -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") ]];then
				rpm -Uvh rpm/*.rpm
			else
				sed -i "s/keepcache=0/keepcache=1/g" /etc/yum.conf
				yum -y install gcc gcc-c++ make pcre-devel zlib-devel
				VERSION=$(cat /etc/redhat-release|sed -r 's/.* ([0-9]+)\..*/\1/')
				mkdir rpm
				mv /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 == "" ]];then
				echo "$NGINX_HOME/nginx/sbin/nginx -c $NGINX_HOME/nginx/conf/nginx.conf" >> /etc/rc.d/rc.local
			else
				echo "/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 save
				service iptables restart
			fi
		else 
			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

验证

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章