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

驗證

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