Nginx腳本一鍵安裝第二版

#!/bin/bash
#判斷是否是roo用戶
if [ $(id -u) != "0" ]; then
        echo "Error:You must be root to run this script"
fi
#每次使用只需修改自定義內容即可
#自定義用戶名和組
Group_Name="nginx"
User_Name="nginx"
#自定義nginx變量
Install_Path="/usr/local/nginx"
Package_Type=".tar.gz"
Version="nginx-1.9.8"
Package=$Version$Package_Type
Setup_path="/root/"
RPM="nginx"
#自定義/var/tmp/nginx目錄
DIR_File="/var/tmp/nginx"

#安裝依賴關係
yum group install "Development Tools" "Server Platform Deveopment"
yum install -y curl openssl-devel pcre-devel
Group_User(){
egrep "^$Group_Name" /etc/group >& /dev/null
if [ $? -ne 0 ]
then
    echo "nginx 用戶組正在添加."
    groupadd $Group_Name
else
    echo " The $Group_Name user group already exists."
    echo "nginx 用戶組已經添加."
fi
#判斷nginx用戶是否存在
egrep "^$User_Name" /etc/passwd >& /dev/null
if [ $? -ne 0 ]
then
    echo "nginx 用戶正在添加."
    useradd -g $Group_Name $User_Name
else
    echo "nginx 用戶已經添加."
    echo " The $User_Name user already exists."
fi
}
Group_User
#創建/var/tmp/nginx目錄
#mkdir /var/tmp/nginx
if [ -e $DIR_File ]
then
	echo " $DIR_File 目錄已經存在."
	echo " $DIR_File Directory Already Exists."
else 
	echo " $DIR_File 目錄正在創建."
	mkdir $DIR_File
fi	
#判斷文件是否存在
if [ -e $Setup_path$Version$Package_Type ]
then
        echo "$Package The Package exists."
else
        echo "$Package The package does not exist."
fi
#判斷是否用RPM方式安裝
function RPM_Install(){
rpm -qa | egrep "$RPM" >>/dev/null
	if [ $? -eq 0 ]
	then
		echo "$RPM is install Yes."
	else 
		echo "$RPM is Not install."
	fi
}
RPM_Install
#編譯安裝nginx
cd $Setup_path
tar -zxvf $Package
cd $Version
configure_opts=(
--prefix=$Install_Path 
--sbin-path=$Install_Path/sbin/nginx 
--conf-path=/etc/nginx/nginx.conf 
--error-log-path=/var/log/nginx/error.log 
--http-log-path=/var/log/nginx/access.log 
--pid-path=/var/run/nginx/nginx.pid 
--lock-path=/var/lock/nginx.lock 
--user=nginx 
--group=nginx 
--with-http_ssl_module 
--with-http_flv_module
--with-http_stub_status_module 
--with-http_gzip_static_module 
--http-client-body-temp-path=/var/tmp/nginx/client 
--http-proxy-temp-path=/var/tmp/nginx/proxy 
--http-fastcgi-temp-path=/var/tmp/nginx/fcgi 
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi 
--http-scgi-temp-path=/var/tmp/nginx/scgi 
--with-pcre
)
./configure ${configure_opts[@]}
if [[ $? -eq 0 ]]
then
	make && make install
else
	echo "編譯失敗,請重新編譯" && exit 1
fi
#添加Nginx命令到環境變量
cat >/etc/profile.d/nginx.sh <<EOF
export PATH=/usr/local/nginx/sbin/:$PATH
EOF
source /etc/profile
#啓動服務
/usr/local/nginx/sbin/nginx
ss -tnlp | grep nginx

不足之處:沒有添加啓動腳本,直接用命令啓動的,希望各位大佬能給加上,共享下

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