centos nginx源碼shell腳本安裝

#!/bin/sh

echo "---------------start install nginx,安裝所需依賴包 -----------------------------"

yum -y install gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel pam pam-devel libacl-devel openldap-devel libcap libcap-devel tcp_wrappers tcp_wrappers-devel tcp_wrappers_devel policycoreutils-python vim lrzsz ntpdate sysstat net-tools unzip zip wget redhat_lsb

if [ 'grep "nginx" /etc/passwd | wc -l' ]; then

echo "adding user nginx"

groupadd nginx

useradd -s /sbin/nologin -M -g nginx nginx

else

echo "user nginx exsits"

fi

echo "-----------------------------------downloading nginx-------------------------------"

cd /javadev/src

tar -xvf nginx-1.16.1.tar.gz

cd nginx-1.16.1

echo "------------------------------------configuring nginx,plz wait----------------------"

./configure --prefix=/javadev/nginx --with-http_stub_status_module --with-http_gzip_static_module --with-http_ssl_module --with-http_addition_module --with-http_flv_module --with-http_mp4_module --with-http_stub_status_module --with-pcre

if [ $? -ne 0 ];then

echo "configure failed ,please check it out!"

else

echo "make nginx, please wait for 20 minutes"

make

fi

if [ $? -ne 0 ];then

echo "make failed ,please check it out!"

else

echo "install nginx, please wait for 20 minutes"

make install

fi

cd /javadev/nginx/conf && mv nginx.conf nginx.conf.bak

echo "------------------------替換準備好的Nginx配置文件----------------------------------"

cd /javadev/temp && cp -r nginx.conf /javadev/nginx/conf

echo "-----------------------將Nginx添加安裝成系統服務,做成自啟動---------------------"

cd /javadev/init.d && cp -r nginx /etc/init.d && chmod +x nginx

chkconfig --add nginx && chkconfig --level 2345 nginx on

echo "------------------------------nginx chkconfig----------------------------------------"

chkconfig --list nginx

echo "-----------------------------nginx service----------------------------------"

chmod +x /etc/init.d/nginx

service nginx start

service nginx status

echo "---------------------firewall config-----------------------------"

systemctl status firewalld

systemctl restart firewalld

systemctl enable firewalld

firewall-cmd --permanent --zone=public --add-port=80/tcp

firewall-cmd --permanent --zone=public --add-port=8180/tcp

firewall-cmd --permanent --zone=public --add-port=8880/tcp

firewall-cmd --reload

sed -i 's/SELINUX=enforcing/SELINUX=Permissive/g' /etc/selinux/config

sed -i 's/SELINUX=enforcing/SELINUX=Permissive/g' /etc/sysconfig/selinux

setenforce 0

getenforce

echo "-----------------------------nginx install OK Ok OK----------------------------------"


分享到:


相關文章: