您的位置:新葡亰496net > 服务器网络 > 新葡亰496net:服务器配置,Java运维情况之

新葡亰496net:服务器配置,Java运维情况之

发布时间:2019-06-21 08:51编辑:服务器网络浏览(121)

    三、Java运维条件之 cent os6.8 陆十一位安装nginx,os6.8nginx

    作品转发:

    依照专门的工作必要,未来内需设置nginx服务器,本来能够直接设置旁人成立好的rpm包的,然而本着爱折腾和每天尝鲜的神气,小编决定从官方网站下载最新的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. #新葡亰496net,  
    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 六11个人安装nginx,os6.8nginx 小说转载: 依照办事索要,未来须要设置nginx服...

    #安装pcre

    Nginx安装步骤:

     独自等待

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

    yum install -y pcre-devel

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

    1、编写脚本,名称叫nginx
    #!/bin/sh
    #
    # nginx - this script starts and stops the nginx daemon
    #
    # chkconfig: - 85 15
    #新葡亰496net:服务器配置,Java运维情况之。 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

    在安装完nginx后,重新开动要求“killall nginx进度编号”来拓展双重加载,分明非常不便利。假使能像apache同样,直接通过脚本实行管理就方便多了。

    #安装zlib-devel

    1. 安装Nginx
      ./configure

    2. make && make install

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

    nginx官方早已想好了,也提供了那些本子,地址:

    yum install -y zlib-devel

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

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

    #!/bin/sh

    #下载nginx

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

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

    #

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

    #!/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
    新葡亰496net:服务器配置,Java运维情况之。 
    # 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="/usr/local/nginx/sbin/nginx"
    prog=$(basename $nginx)

    # nginx - this script starts and stops the nginx daemon

    #解压nginx

    在意修改成温馨的设置目录!!!
    3、修改nginx文件的试行权限
        chmod x nginx
    4、增加该公文到系统服务中去
        chkconfig --add nginx
        查看是还是不是丰盛成功
        chkconfig --list nginx

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

    #

    tar zxvf nginx-1.13.0.tar.gz

    起头,停止,重新装载
    service nginx start|stop

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

    # 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

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

    # Check that networking is up.

    #输入以下内容

    1、编写脚本,名字为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 [ `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=([^ ]*).*/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

     

     

    本文由新葡亰496net发布于服务器网络,转载请注明出处:新葡亰496net:服务器配置,Java运维情况之

    关键词: