nginx二进制编译-启动脚本编写

1、上传nginx包,并查看,然后安装zlib-devel和pcre-devel

查看是否安装

2、为nginx创建一个不登陆的用户

3、解压nginx包,指定安装路径

之后编译并安装

扫描二维码关注公众号,回复: 3382169 查看本文章

4、创建脚本

脚本代码如下:

#!/bin/bash
#chkconfig: 2345 97 25
#description nginx-server-scryt
nginx=/usr/local/nginx/sbin/nginx
case "$1" in
start )
netstat -anlpt | grep nginx
if [ $? -eq 0 ]
then
echo "nginx service running!"
else
echo "nginx service not running!"
$nginx
fi
;;
restart)
$nginx -s reload
if [ $? -eq 0 ]
then
echo "nginx server is begin restart"
else
echo "nginx server restart"
fi
;;
stop)
$nginx -s stop
if [ $? -eq 0 ]
then
echo "nginx server is stop"
else
echo "nginx server stop,try again"
fi
;;
status)
netstat -anlpt | grep nginx
if [ $? -eq 0 ]
then
echo "nginx server is running!"
else
echo "nginx server is not running,try to restart"
fi
;;
*)
echo "Please enter (start|restart|stop|status)"
;;
esac
exit 0

5、将脚本拷贝成nginx,然后拷贝到etc下init.d目录下,之后进入到init.d目录下执行命令

6、关闭防火墙

7、执行脚本

8、成功的截图

 

猜你喜欢

转载自www.cnblogs.com/ATMA/p/9715140.html