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

Posted zxiaotian

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了nginx二进制编译-启动脚本编写相关的知识,希望对你有一定的参考价值。

技术分享图片

 

解压包

 #tar zxf nginx-1.11.2.tar.gz 

 

编写脚本

# vi nginx-running.sh

内容:

 

#!/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 runing!"
else
echo "nginx service not runing!"
$nginx
fi
;;
restart)
$nginx -s reload
if [ $? -eq 0 ]
then
echo "nginx server is begin restart"
else
echo "nginx service runing!"
fi
;;
stop)
$nginx -s stop
if [ $? -eq 0 ]
then
echo "nginx server is begin stop"
else
echo "nginx service stop,try again!"
fi
;;
status)
netstat -anlpt | grep nginx
if [ $? -eq 0 ]
then
echo "nginx server is runing!"
else
echo "nginx server is not runing.try to restart!"
fi
;;
*)
echo "Please enter (start|restart|stop|status)"
;;
esac
exit 0

 

 

rpm安装两个包

# rpm -ivh /opt/dvd/Packages/zlib-devel-1.2.7-13.el7.x86_64.rpm

warning: /opt/dvd/Packages/zlib-devel-1.2.7-13.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY

Preparing...                          ################################# [100%]

Updating / installing...

   1:zlib-devel-1.2.7-13.el7          ################################# [100%]

 

# rpm -ivh /opt/dvd/Packages/pcre-devel-8.32-12.el7.x86_64.rpm

warning: /opt/dvd/Packages/pcre-devel-8.32-12.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY

Preparing...                          ################################# [100%]

Updating / installing...

   1:pcre-devel-8.32-12.el7           ################################# [100%]

 

 

看一下这两个包已经安上了

[[email protected] ~]# rpm -q zlib-devel pcre-devle

zlib-devel-1.2.7-13.el7.x86_64

package pcre-devle is not installed

 

[[email protected] ~]# rpm -q zlib-devel pcre-devel

zlib-devel-1.2.7-13.el7.x86_64

pcre-devel-8.32-12.el7.x86_64

 

 

创建用户

#useradd -s /sbin/nologin -M nginx

查看一下

[[email protected] ~]# id nginx

uid=1000(nginx) gid=1000(nginx) groups=1000(nginx)

 

进到nginx目录下

# cd nginx-1.11.2

[[email protected] nginx-1.11.2]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx

 

编译并安装

#make install

 

截取一下80

[[email protected] nginx-1.11.2]#  ss -tanml | grep 80

        skmem:(r0,rb87380,t0,tb16384,f0,w0,o0,bl0)

        skmem:(r0,rb87380,t0,tb16384,f0,w0,o0,bl0)

        skmem:(r0,rb87380,t0,tb16384,f0,w0,o0,bl0)

        skmem:(r0,rb87380,t0,tb16384,f0,w0,o0,bl0)

 

 

[[email protected] nginx-1.11.2]# /usr/local/nginx/sbin/nginx

[[email protected] nginx-1.11.2]#  ss -tanml | grep 80

        skmem:(r0,rb87380,t0,tb16384,f0,w0,o0,bl0)

LISTEN     0      128                       *:80                       *:*    

        skmem:(r0,rb87380,t0,tb16384,f0,w0,o0,bl0)

        skmem:(r0,rb87380,t0,tb16384,f0,w0,o0,bl0)

        skmem:(r0,rb87380,t0,tb16384,f0,w0,o0,bl0)

        skmem:(r0,rb87380,t0,tb16384,f0,w0,o0,bl0)

 

# ps aux | grep nginx

root      25698  0.0  0.0  20936   608 ?        Ss   16:32   0:00 nginx: master process /usr/local/nginx/sbin/nginx

nginx     25699  0.0  0.0  21364  1316 ?        S    16:32   0:00 nginx: worker process

root      25703  0.0  0.0 112640   980 pts/0    S+   16:33   0:00 grep --color=auto nginx

 

想要删除前两条,

#kill -9 25698

#kill -9 25699

 

 

# cp nginx-running.sh nginx

# ll

total 920

-rw-------. 1 root root   1102 Sep 16 11:18 anaconda-ks.cfg

-rwxr--r--. 1 root root   1121 Sep 27 16:02 nginx

drwxr-xr-x. 9 1001 1001   4096 Sep 27 11:17 nginx-1.11.2

-rw-r--r--. 1 root root 924979 Sep 27 11:01 nginx-1.11.2.tar.gz

-rwxr--r--. 1 root root   1121 Sep 27 11:32 nginx-running.sh

 

# cp nginx /etc/init.d/

# cd /etc/init.d/

[[email protected] init.d]# ls

functions  iprinit    netconsole  nginx   rhnsd

iprdump    iprupdate  network     README

 

 

用chkconfig –add nginx

[[email protected] init.d]# chkconfig --add nginx

[[email protected] init.d]# chkconfig --list nginx

 

Note: This output shows SysV services only and does not include native

      systemd services. SysV configuration data might be overridden by native

      systemd configuration.

 

      If you want to list systemd services use ‘systemctl list-unit-files‘.

      To see services enabled on particular target use

      ‘systemctl list-dependencies [target]‘.

 

nginx            0:off 1:off 2:on 3:on 4:on 5:o6:off

 

关闭防火墙

[[email protected] init.d]# iptables -F

[[email protected] init.d]# iptables -X

 [[email protected] init.d]# setenforce 0

打开浏览器输入ip

技术分享图片

 















































以上是关于nginx二进制编译-启动脚本编写的主要内容,如果未能解决你的问题,请参考以下文章

nginx 源码编译安装并编写服务启动脚本

nginx编译安装服务启动脚本在哪

nginx启动脚本编写及设置开机自启动

nginx启动脚本编写

Nginx的编译安装及服务启动脚本

使用本脚本可以自动批量完成中间节点环境的部署工作,包括:Nginx编译安装添加程序管理脚本设置开机启动反向代理配置证书分发添加iptables规则等