当前位置: 56net亚洲必嬴 > 服务器&运维 > 正文

把nginx参预到系统服务,利用chkconfig调整

时间:2019-10-31 20:19来源:服务器&运维
三、Java运维条件之 cent os6.8 六10个人安装nginx,os6.8nginx 小说转发: 依据专门的工作须求,以后内需设置nginx服务器,本来能够一直设置外人成立好的rpm包的,但是针对爱折腾和每13日尝

三、Java运维条件之 cent os6.8 六10个人安装nginx,os6.8nginx

小说转发:

依据专门的工作须求,以后内需设置nginx服务器,本来能够一直设置外人成立好的rpm包的,但是针对爱折腾和每13日尝鲜的饱满,笔者决定从官方网站下载最新的nginx源码来设置,上面记录了自己的安装进度。

下边包车型地铁装置假定是以root客商登入并实行
1.装置依赖库
那一个正视库入眼有g++、gcc、openssl-devel、pcre-devel和zlib-devel 
yum -y install make gcc gcc-c++ glibc glibc-devel lsof   
yum -y install pcre pcre-devel  
yum -y install zlib zlib-devel  
yum -y install openssl openssl--devel 

2.下载源码包
cd /usr/local/src
wget -d ""
tar zxvf nginx-1.8.0.tar.gz
cd nginx-1.8.0
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_realip_module --with-http_ssl_module 
make -j 4
make install

3.验证性运行nginx
瞩目,在未曾安装nginx为系统服务在此之前,这里仅是验证性的启航空衡量试。使用上边包车型地铁吩咐查看nginx可执路程序的渠道
whereis nginx
诚如默许在/usr/local/nginx目录上面
ulimit -SHn 65535
/usr/local/nginx/sbin/nginx

4.增加nginx为系统服务
增进如下文件

vim /etc/init.d/nginx

[html] view plain copy

  1. #!/bin/sh  
  2. #  
  3. # nginx - this script starts and stops the nginx daemon  
  4. #  
  5. # chkconfig:   - 85 15  
  6. # description: Nginx is an HTTP(S) server, HTTP(S) reverse   
  7. #               proxy and IMAP/POP3 proxy server  
  8. # processname: nginx  
  9. # config:      /etc/nginx/nginx.conf  
  10. # config:      /etc/sysconfig/nginx  
  11. # pidfile:     /var/run/nginx.pid  
  12. # Source function library.  
  13. . /etc/rc.d/init.d/functions  
  14. # Source networking configuration.  
  15. . /etc/sysconfig/network  
  16. # Check that networking is up.  
  17. [ "$NETWORKING" = "no" ] && exit 0  
  18. nginx="/usr/local/nginx/sbin/nginx"  
  19. prog=$(basename $nginx)  
  20. NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"  
  21. [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx  
  22. lockfile=/var/lock/subsys/nginx  
  23. start() {  
  24.     [ -x $nginx ] || exit 5  
  25.     [ -f $NGINX_CONF_FILE ] || exit 6  
  26.     echo -n $"Starting $prog: "  
  27.     daemon $nginx -c $NGINX_CONF_FILE  
  28.     retval=$?  
  29.     echo  
  30.     [ $retval -eq 0 ] && touch $lockfile  
  31.     return $retval  
  32. }  
  33. stop() {  
  34.     echo -n $"Stopping $prog: "  
  35.     killproc $prog -QUIT  
  36.     retval=$?  
  37.     echo  
  38.     [ $retval -eq 0 ] && rm -f $lockfile  
  39.     return $retval  
  40. killall -9 nginx  
  41. }  
  42. restart() {  
  43.     configtest || return $?  
  44.     stop  
  45.     sleep 1  
  46.     start  
  47. }  
  48. reload() {  
  49.     configtest || return $?  
  50.     echo -n $"Reloading $prog: "  
  51.     killproc $nginx -HUP  
  52. RETVAL=$?  
  53.     echo  
  54. }  
  55. force_reload() {  
  56.     restart  
  57. }  
  58. configtest() {  
  59. $nginx -t -c $NGINX_CONF_FILE  
  60. }  
  61. rh_status() {  
  62.     status $prog  
  63. }  
  64. rh_status_q() {  
  65.     rh_status >/dev/null 2>&1  
  66. }  
  67. case "$1" in  
  68.     start)  
  69.         rh_status_q && exit 0  
  70.     $1  
  71.         ;;  
  72.     stop)  
  73.         rh_status_q || exit 0  
  74.         $1  
  75.         ;;  
  76.     restart|configtest)  
  77.         $1  
  78.         ;;  
  79.     reload)  
  80.         rh_status_q || exit 7  
  81.         $1  
  82.         ;;  
  83.     force-reload)  
  84.         force_reload  
  85.         ;;  
  86.     status)  
  87.         rh_status  
  88.         ;;  
  89.     condrestart|try-restart)  
  90.         rh_status_q || exit 0  
  91.             ;;  
  92.     *)      
  93.       echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"  
  94.         exit 2  
  95. esac  

chmod +x /etc/init.d/nginx
注册 nginx 服务
chkconfig --add nginx
chkconfig --list nginx
要是查看见nginx服务在各类品级下,都并未有展开,能够再一次利用上边包车型客车通令分明建议在不一样等第下展开:
chkconfig --level 2345 nginx on
再一次利用
chkconfig --list nginx
翻开,是还是不是在上述各品级下已经展开。这里之所以要如此重申,是梦想在断电后nginx服务能自动重启。

4.改造配置文件nginx.conf

驷不及舌是根据职业逻辑来配置nginx.conf,这里忽视具体内容

配置完毕后,重新测验并加载nginx.conf
service nginx configtest
service nginx reload
让nginx在新的计划下运维就足以了

5.安装中冒出的主题材料和不当
因为nginx.conf中冒出难题,突显错误如下:
nginx: [emerg] unknown directive "lua_shared_dict" in /usr/local/nginx/conf/nginx.conf:11

nginx: [emerg] unknown directive "rewrite_by_lua_file" in /usr/local/nginx/conf/nginx.conf:136

解决措施

那五个报错,是因为nginx.conf中增添了那三个指令,将对应安插及逻辑删除就足以了。

参照他事他说加以考查链接

本人一时将它们批注掉    


0


0

查看讨论

cent os6.8 陆拾几位安装nginx,os6.8nginx 文章转发: 依据职业急需,以往急需设置nginx性格很顽强在荆棘载途或巨大压力面前不屈...

#安装pcre

 独自等待

Nginx安装步骤:

yum install -y pcre-devel

1、编写脚本,名称叫nginx
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /etc/sysconfig/nginx
# pidfile: /var/run/nginx.pid

1.依赖 gcc openssl-devel pcre-devel zlib-devel
    安装:yum install gcc openssl-devel pcre-devel zlib-devel -y

#安装zlib-devel

# Source function library.
. /etc/rc.d/init.d/functions

  1. 安装Nginx
    ./configure

  2. make && make install

yum install -y zlib-devel

# Source networking configuration.
. /etc/sysconfig/network

暗许安装目录:
/usr/local/nginx

#下载nginx

# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0

4.布局Nginx为系统服务,以方便管理
  1、在/etc/rc.d/init.d/目录中国建工业总会公司立文本文件nginx
  2、在文书中粘贴上面包车型大巴源委:

wget -r -np -nd http://nginx.org/download/nginx-1.13.0.tar.gz

nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)

#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig:   - 85 15
# description:  Nginx is an HTTP(S) server, HTTP(S) reverse
#               proxy and IMAP/POP3 proxy server
# processname: nginx
# config:      /etc/nginx/nginx.conf
# config:      /etc/sysconfig/nginx
# pidfile:     /var/run/nginx.pid
 
# Source function library.
. /etc/rc.d/init.d/functions
 
# Source networking configuration.
. /etc/sysconfig/network
 
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
 
nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)
 
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
 
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
 
lockfile=/var/lock/subsys/nginx
 
make_dirs() {
   # make required directories
   user=`nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=([^ ]*).*/1/g' -`
   options=`$nginx -V 2>&1 | grep 'configure arguments:'`
   for opt in $options; do
       if [ `echo $opt | grep '.*-temp-path'` ]; then
           value=`echo $opt | cut -d "=" -f 2`
           if [ ! -d "$value" ]; then
               # echo "creating" $value
               mkdir -p $value && chown -R $user $value
           fi
       fi
   done
}
 
start() {
    [ -x $nginx ] || exit 5
    [ -f $NGINX_CONF_FILE ] || exit 6
    make_dirs
    echo -n $"Starting $prog: "
    daemon $nginx -c $NGINX_CONF_FILE
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}
 
stop() {
    echo -n $"Stopping $prog: "
    killproc $prog -QUIT
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}
 
restart() {
    configtest || return $?
    stop
    sleep 1
    start
}
 
reload() {
    configtest || return $?
    echo -n $"Reloading $prog: "
    killproc $nginx -HUP
    RETVAL=$?
    echo
}
 
force_reload() {
    restart
}
 
configtest() {
  $nginx -t -c $NGINX_CONF_FILE
}
 
rh_status() {
    status $prog
}
 
rh_status_q() {
    rh_status >/dev/null 2>&1
}
 
case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart|configtest)
        $1
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    force-reload)
        force_reload
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
            ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
        exit 2
esac

#解压nginx

NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"

潜心改革成温馨的设置目录!!!
3、修改nginx文件的实践权限
    chmod +x nginx
4、加多该文件到系统服务中去
    chkconfig --add nginx
    查看是不是丰富成功
    chkconfig --list nginx

tar zxvf nginx-1.13.0.tar.gz

[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx

发轫,甘休,重新装载
service nginx start|stop

#配置nginx,需进入nginx目录

lockfile=/var/lock/subsys/nginx

./configure

start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}

#安装nginx

stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
killall -9 nginx
}

make

restart() {
configtest || return $?
stop
sleep 1
start
}

make install

reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
}

#nginx私下认可安装在/usr/local/nginx

force_reload() {
restart
}

#这时亟需配备nginx 的布署文件

configtest() {
$nginx -t -c $NGINX_CONF_FILE
}

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

rh_status() {
status $prog
}

安装开机运转:

rh_status_q() {
rh_status >/dev/null 2>&1
}

#制造文件

case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac
2、加入chkconfig
[[email protected] ~]# cp nginx /etc/init.d/
[[email protected] ~]# chmod 755 /etc/init.d/nginx
[[email protected] ~]# chkconfig --add nginx

vi /etc/init.d/nginx

3、nginx运转、截止、无间断服务重启
[[email protected] ~]# service nginx start
[[email protected] ~]# service nginx stop
[[email protected] ~]# service nginx reload

#输入以下内容

1、编写脚本,名字为nginx #!/bin/sh # # nginx - this script starts and stops the nginx daemon # # chkconfig: - 85 15 # description: Nginx is an HTTP(S) server, HT...

#!/bin/sh

#

# nginx - this script starts and stops the nginx daemon

#

# chkconfig: - 85 15

# description: NGINX is an HTTP(S) server, HTTP(S) reverse

# proxy and IMAP/POP3 proxy server

# processname: nginx

# config: /etc/nginx/nginx.conf

# config: /etc/sysconfig/nginx

# pidfile: /var/run/nginx.pid

# Source function library.

. /etc/rc.d/init.d/functions

# Source networking configuration.

. /etc/sysconfig/network

编辑:服务器&运维 本文来源:把nginx参预到系统服务,利用chkconfig调整

关键词: