澳门新浦京娱乐场网站-www.146.net-新浦京娱乐场官网
做最好的网站

centos下nginx运转脚本和chkconfig处理,Nginx源码搭建

3、Java运营遭受之 cent os6.八 陆14个人安装nginx,os六.八nginx

文章转载:

基于办事亟待,未来亟需设置nginx服务器,本来能够直接设置外人创立好的rpm包的,可是本着爱折腾和天天尝鲜的激昂,作者调整从官方网站下载最新的nginx源码来设置,下边记录了自家的装置进度。

上边包车型大巴装置假定是以root用户登6并执行
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 

二.下载源码包
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

三.验证性运转nginx
专注,在未有安装nginx为系统服务此前,这里仅是验证性的启航空衡量试。使用下边包车型大巴授命查看nginx可施行程序的路线
whereis nginx
诚如暗许在/usr/local/nginx目录上边
ulimit -SHn 65535
/usr/local/nginx/sbin/nginx

四.增添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服务能自行重启。

四.改变配置文件nginx.conf

重中之重是依据职业逻辑来安排nginx.conf,这里忽略具体内容

布署达成后,重新测试并加载nginx.conf
service nginx configtest
service nginx reload
让nginx在新的安排下运转就可以了

伍.设置中出现的难点和错误
因为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陆15位安装nginx,os6.捌nginx 文章转发: 根据专门的学业须求,现在内需设置nginx服...

#安装pcre

 独自等待

Nginx安装步骤:

原博客地址:centos下nginx运营脚本和chkconfig管理

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

在设置完nginx后,重新启航要求“killall nginx进度编号”来张开重复加载,显明卓殊不便于。借使能像apache同样,直接通过脚本举办保管就有益多了。

#安装zlib-devel

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

  1. 安装Nginx
    ./configure

  2. make && make install

nginx官方早就想好了,也提供了这些剧本,地址:

yum install -y zlib-devel

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

暗中同意安装目录:
/usr/local/nginx

#!/bin/sh

#下载nginx

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

4.配备Nginx为系统服务,以方便管理
  一、在/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 - this script starts and stops the nginx daemon

#澳门新浦京娱乐场网站,解压nginx

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

留神修改成团结的安装目录!!!
三、修改nginx文件的进行权限
    chmod x nginx
四、增加该公文到系统服务中去
    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

# chkconfig:   - 85 15

#配置nginx,需进入nginx目录

lockfile=/var/lock/subsys/nginx

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

./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
}

#               proxy and IMAP/POP3 proxy server

#安装nginx

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

# processname: nginx

make

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

# config:      /etc/nginx/nginx.conf

make install

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

# config:      /etc/sysconfig/nginx

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

force_reload() {
restart
}

# pidfile:     /var/run/nginx.pid

#那时候内需配备nginx 的安顿文件

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

# Source function library.

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

rh_status() {
status $prog
}

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

设置开机运转:

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

# Source networking configuration.

#创设文件

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

. /etc/sysconfig/network

vi /etc/init.d/nginx

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

# Check that networking is up.

#输入以下内容

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

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

#!/bin/sh

nginx="/usr/local/nginx/sbin/nginx"

#

prog=$(basename $nginx)

# nginx - this script starts and stops the nginx daemon

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

#

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

# chkconfig: - 85 15

lockfile=/var/lock/subsys/nginx

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

make_dirs() {

# proxy and IMAP/POP3 proxy server

# make required directories

# processname: nginx

user=`$nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=([^ ]*).*/1/g' -`

# config: /etc/nginx/nginx.conf

if [ -z "`grep $user /etc/passwd`" ]; then

# config: /etc/sysconfig/nginx

useradd -M -s /bin/nologin $user

# pidfile: /var/run/nginx.pid

fi

# Source function library.

options=`$nginx -V 2>&1 | grep 'configure arguments:'`

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

for opt in $options; do

# Source networking configuration.

if [ `centos下nginx运转脚本和chkconfig处理,Nginx源码搭建。echo $opt | grep '.*-temp-path'` ]; then

. /etc/sysconfig/network

value=`echo $opt | cut -d "=" -f 2`

# Check that networking is up.

if [ ! -d "$value" ]; then

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

# echo "creating" $value

nginx="/usr/local/nginx/sbin/nginx"

mkdir -p $value && chown -R $user $value

prog=$(basename $nginx)

fi

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

fi

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

done

lockfile=/var/lock/subsys/nginx

}

make_dirs() {

start() {

# make required directories

[ -x $nginx ] || exit 5

user=`$nginx -V 2>&1 | grep "configure arguments:.*--user=" | sed 's/[^*]*--user=([^ ]*centos下nginx运转脚本和chkconfig处理,Nginx源码搭建。).*/1/g' -`

[ -f $NGINX_CONF_FILE ] || exit 6

if [ -n "$user" ]; then

make_dirs

if [ -z "`grep $user /etc/passwd`" ]; then

echo -n $"Starting $prog: "

useradd -M -s /bin/nologin $user

daemon $nginx -c $NGINX_CONF_FILE

fi

retval=$?

options=`$nginx -V 2>&1 | grep 'configure arguments:'`

echo

for opt in $options; do

[ $retval -eq 0 ] && touch $lockfile

if [ `echo $opt | grep '.*-temp-path'` ]; then

return $retval

value=`echo $opt | cut -d "=" -f 2`

}

if [ ! -d "$value" ]; then

stop() {

# echo "creating" $value

echo -n $"Stopping $prog: "

mkdir -p $value && chown -R $user $value

killproc $prog -QUIT

fi

retval=$?

fi

echo

done

[ $retval -eq 0 ] && rm -f $lockfile

fi

return $retval

}

}

start() {

restart() {

[ -x $nginx ] || exit 5

configtest || return $?

[ -f $NGINX_CONF_FILE ] || exit 6

stop

make_dirs

sleep 1

echo -n $"Starting $prog: "

start

daemon $nginx -c $NGINX_CONF_FILE

}

retval=$?

reload() {

echo

configtest || return $?

[ $retval -eq 0 ] && touch $lockfile

echo -n $"Reloading $prog: "

return $retval

killproc $nginx -HUP

}

RETVAL=$?

stop() {

echo

echo -n $"Stopping $prog: "

}

killproc $prog -QUIT

force_reload() {

retval=$?

restart

echo

}

[ $retval -eq 0 ] && rm -f $lockfile

configtest() {

return $retval

$nginx -t -c $NGINX_CONF_FILE

}

}

restart() {

rh_status() {

configtest || return $?

status $prog

stop

}

sleep 1

rh_status_q() {

start

rh_status >/dev/null 2>&1

}

}

reload() {

case "$1" in

configtest || return $?

start)

echo -n $"Reloading $prog: "

rh_status_q && exit 0

killproc $nginx -HUP RETVAL=$?

$1

echo

;;

}

stop)

force_reload() {

rh_status_q || exit 0

restart

$1

}

;;

configtest() {

restart|configtest)

$nginx -t -c $NGINX_CONF_FILE

$1

}

;;

rh_status() {

reload)

status $prog

rh_status_q || exit 7

}

$1

rh_status_q() {

;;

rh_status >/dev/null 2>&1

force-reload)

}

force_reload

case "$1" in

;;

start)

status)

rh_status_q && exit 0

rh_status

$1

;;

;;

condrestart|try-restart)

stop)

rh_status_q || exit 0

rh_status_q || exit 0

;;

$1

*)

;;

echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"

restart|configtest)

exit 2

$1

esac

;;

将以上脚本保存到/etc/init.d/nginx文件,将其文件权限改为755并修改多少个地点:

reload)

nginx=”/usr/local/nginx/sbin/nginx” 修改成团结设置nginx路线上面nginx实行顺序的路子。

rh_status_q || exit 7

NGINX_CONF_FILE=”/usr/local/nginx/conf/nginx.conf” 修改成本人安装nginx路线上边配置文件的不二等秘书技。

$1

保留后,就可以透过该脚本对nginx服务举行田间管理了:

;;

$ /etc/init.d/nginx start

force-reload)

$ /etc/init.d/nginx stop

force_reload

$ /etc/init.d/nginx reload

;;

...

status)

行使chkconfig实行管理

rh_status

下边包车型地铁情势成功了用剧本管理nginx服务的作用,可是依旧不太方便,比方要安装nginx开机运维等。那时能够选拔chkconfig来设置。

;;

先将nginx服务进入chkconfig处理列表:

condrestart|try-restart)

chkconfig --add /etc/init.d/nginx

rh_status_q || exit 0

加完这些今后,就足以应用service对nginx举行运营,重启等操作了。

;;

$ service nginx start

*)

$ service nginx stop

echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"

$ service nginx reload

exit 2

...

esac

设置极端格局开机运营:

 

$ chkconfig --level 3 nginx on

#授权

chmod a x /etc/init.d/nginx

#开机运行

chkconfig nginx on

 

 

本文由澳门新浦京娱乐场网站发布于服务器,转载请注明出处:centos下nginx运转脚本和chkconfig处理,Nginx源码搭建