码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2018-09-28 00:05:43      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:Fix   bsp   emd   lis   pre   useradd   sys   esc   http   

技术分享图片

 

解压包

 #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%]

 

 

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

[root@localhost ~]# rpm -q zlib-devel pcre-devle

zlib-devel-1.2.7-13.el7.x86_64

package pcre-devle is not installed

 

[root@localhost ~]# 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

查看一下

[root@localhost ~]# id nginx

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

 

进到nginx目录下

# cd nginx-1.11.2

[root@localhost nginx-1.11.2]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx

 

编译并安装

#make install

 

截取一下80

[root@localhost 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)

 

 

[root@localhost nginx-1.11.2]# /usr/local/nginx/sbin/nginx

[root@localhost 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/

[root@localhost init.d]# ls

functions  iprinit    netconsole  nginx   rhnsd

iprdump    iprupdate  network     README

 

 

用chkconfig –add nginx

[root@localhost init.d]# chkconfig --add nginx

[root@localhost 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

 

关闭防火墙

[root@localhost init.d]# iptables -F

[root@localhost init.d]# iptables -X

 [root@localhost init.d]# setenforce 0

打开浏览器输入ip

技术分享图片

 

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

标签:Fix   bsp   emd   lis   pre   useradd   sys   esc   http   

原文地址:https://www.cnblogs.com/Zxiaotian/p/9716178.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!