Centos-Server-Nginx-服务(二)功能使用-脚本化安装

 本文提供单独安装Nginx的安装脚本:

 

源码安装脚本:

#!/bin/bash

#Thanks Opensource

#Stone 制作

echo "Nginx安装即将开始,请稍等...."

echo "正在关闭SElinux......."

setenforce 0

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

echo "正在关闭Iptables......"

service iptables stop

chkconfig iptables off

echo "检查SElinux和Iptables是否关闭成功.."

getenforce

echo "显示Disabled,表示Selinux关闭成功"

chkconfig --list iptables

echo "0-6显示off,表示Iptables关闭成功且不会开机自动启动.."

echo "请选择安装

         继续安装 请输入Y\y

         退出  请输入N\n

"

read -p "请根据编号选择(Y\y or N\n).. " SERVER_ID

if [ $SERVER_ID == Y ] || [ $SERVER_ID == y ];then

        SERVER="继续安装"

elif [ $SERVER_ID == N ] || [ $SERVER_ID == n ];then

        SERVER="Quit"

exit 5

else

        exit

fi

########################################################### 

echo "正在安装系统基础包..........."

yum -y install openssl openssl-devel pcre pcre-devel gcc gcc-c++ make wget zlib-static zlib zlib-devel

echo "正在Nginx创建管理帐号........"

groupadd nginx

useradd -g nginx nginx

echo "正在处理Nginx源代码包........"

DOWNLOAD=/usr/local/src/

INSTALL_DIR=/usr/local/

cd ${DOWNLOAD}

#wget 'http://nginx.org/download/nginx-1.0.8.tar.gz'

echo "正在解压Nginx源代码包........"

tar zxvf 'nginx-1.0.12.tar.gz'

echo "正在编译Nginx源代码包........"

cd 'nginx-1.0.12'

###########选择安装############

echo "请选择安装

         继续安装 请输入Y\y

         退出     请输入N\n

"

read -p "请根据编号选择(Y\y or N\n).. " SERVER_ID

if [ $SERVER_ID == Y ] || [ $SERVER_ID == y ];then

        SERVER="继续安装"

elif [ $SERVER_ID == N ] || [ $SERVER_ID == n ];then

        SERVER="Quit"

exit 5

else

        exit

fi

echo "开始编译源代码包......."

cd ${DOWNLOAD}/nginx-1.0.12

./configure --prefix=${INSTALL_DIR}/nginx --with-http_ssl_module --with-http_gzip_static_module  --with-http_stub_status_module --user=nginx --group=nginx

echo "正在安装Nginx................"

#[ $? != 0 ] && err_exit "Nginx编译错误......"

make

#[ $? != 0 ] && err_exit "Nginx安装错误......"

make install

#[ $? != 0 ] && err_exit "Nginx编译安装失败......"

echo "正在启动Nginx服务"

sed -i 's/^#user.*/user nginx;/g' /usr/local/nginx/conf/nginx.conf

/usr/local/nginx/sbin/nginx 

echo "正在复制开机启动脚本....."

`cp /root/nginx /etc/rc.d/init.d/`

###################################################

echo "是否需要查看80端口处于监听状态..."

echo "请选择

         查看 请输入Y\y

         退出 请输入N\n

"

read -p "请根据编号选择(Y\y or N\n).. " SERVER_ID

if [ $SERVER_ID == Y ] || [ $SERVER_ID == y ];then

        SERVER="查看"

elif [ $SERVER_ID == N ] || [ $SERVER_ID == n ];then

        SERVER="Quit"

exit 5

else

        exit

fi

netstat -tlnp | grep nginx

echo "如果出现80端口处于Listen状态,说明Nginx已经起来.恭喜你Nginx安装成功!"

echo "请测试Nginx!"

 

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

开机启动脚本

#!/bin/bash

# Nginx Server

# chkconfig: 2345 50 90

# description: Activates/Deactivates nginx Web Server

# config: /usr/local/nginx/conf/nginx.conf

# pidfile: /usr/local/nginx/log/nginx.pid

. /etc/init.d/functions

. /etc/sysconfig/network

#####Nginx-Server Let go.....####

if [ -f /etc/sysconfig/nginx ];then

. /etc/sysconfig/nginx

fi

RETVAL=0

prog="nginx"

start() {

# Check that networking is up.

[ "$NETWORKING" = "no" ] && exit 1

echo -n $"Starting $prog: "

daemon /usr/local/nginx/sbin/nginx $OPTIONS

RETVAL=$?

echo

[ $RETVAL -eq 0 ] && touch /var/lock/subsys/nginx

return $RETVAL

}

stop() {

echo -n $"Shutting down $prog: "

killproc /usr/local/nginx/sbin/nginx

RETVAL=$?

echo

[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/nginx

return $RETVAL

}

 #Se how we were called.

case "$1" in

################server nginx start###############

start)

start

;;

###############server nginx stop################

stop)

stop

;;

##############server nginx status##############

status)

status nginx

RETVAL=$?

;;

##############server nginx restart/reload#####

restart|reload)

stop

start

RETVAL=$?

;;

condrestart)

if [ -f /var/lock/subsys/nginx ]; then

stop

start

RETVAL=$?

fi

;;

*)

echo $"Usage: $0 {start|stop|restart|condrestart|status}"

RETVAL=3

esac

exit $RETVAL

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
脚本说明,安装脚本可以直接ctrl+c ctrl+v使用,开机启动脚本需要授权并且存放在能够随服务器开机自动加载启动,具体路径哈哈你自己定哦.后续Centos-Server-Nginx-服务(三)会讲到Nginx的一些使用技巧,我们一起期待吧...

你可能感兴趣的:(nginx)