您好,登錄后才能下訂單哦!
#!/bin/bash #判斷是否是roo用戶 if [ $(id -u) != "0" ]; then echo "Error:You must be root to run this script" fi #每次使用只需修改自定義內(nèi)容即可 #自定義用戶名和組 User="nginx" Group="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="/var/tmp/nginx" #安裝依賴關系 yum group install "Development Tools" "Server Platform Deveopment" yum install -y curl openssl-devel pcre-devel #判斷nginx組是否存在 egrep "^$group" /etc/group >& /dev/null if [ $? -ne 0 ] then groupadd $group else echo " The $Group user group already exists." fi #判斷nginx用戶是否存在 egrep "^$user" /etc/passwd >& /dev/null if [ $? -ne 0 ] then useradd -g $group $user else echo " The $User user already exists." fi #創(chuàng)建/var/tmp/nginx目錄 #mkdir /var/tmp/nginx if [ -e $dir ] then echo " $DIR Directory Already Exists." else mkdir /var/tmp/nginx 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命令到環(huán)境變量 cat >/etc/profile.d/nginx.sh <<EOF export PATH=/usr/local/nginx/sbin/:$PATH EOF #開機啟動 chkconfig --add nginx chkconfig nginx on chkconfig --list | grep nginx #啟動服務 nginx ss -tnlp | grep nginx
不足之處:沒有啟動文件,我是直接加了個環(huán)境變量用nginx回車啟動的
看到此篇文章的大佬們,有啟動文件的希望把啟動文件加進來,希望給補充下,
有錯誤什么的,或者有更好的建議請留言
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內(nèi)容。