开发学院服务器WEB服务器Nginx 使用Nginx帮助Jboss负载 阅读

使用Nginx帮助Jboss负载

 2010-01-09 17:21:00 来源:WEB开发网   
核心提示:下载稳定版本,目前是nginx-0.7.64 http://nginx.net/shell>> cd /optshell>> wget http://sysoev.ru/nginx/nginx-0.7.64.tar.gzshell>> tar xzvf nginx-0.7.64.

下载稳定版本,目前是nginx-0.7.64
   http://nginx.net/

shell>> cd /opt
shell>> wget http://sysoev.ru/nginx/nginx-0.7.64.tar.gz
shell>> tar xzvf nginx-0.7.64.tar.gz
shell>> cd nginx-0.7.64

   然后开始编译安装,先配置编译变量:

./configure \
    --user=nginx \
    --group=nginx \
    --prefix=/opt/nginx \
    --sbin-path=/usr/sbin/nginx \
    --conf-path=/etc/nginx/nginx.conf \
    --error-log-path=/var/log/nginx/error.log \
    --http-log-path=/var/log/nginx/access.log \
    --http-client-body-temp-path=/tmp/nginx/client_body \
    --http-proxy-temp-path=/tmp/nginx/proxy \
    --http-fastcgi-temp-path=/tmp/nginx/fastcgi \
    --pid-path=/var/run/nginx.pid \
    --lock-path=/var/lock/subsys/nginx \
    --with-http_stub_status_module

这里解释一下:
# --user       是指启用程序所属用户
# --group      是指启动程序所属组
# --prefix      是指nginx安装目录(不是源代码目录)
# --sbin-path    是指nginx命令位置
# --conf-path    是指配置文件路径
# --error-log-path  是错误日志路径
# --http-log-path  是访问日志

   其他是一些临时文件的路径和做linux service需要用到的文件

需要监控服务需安装此监控状态模块

# --with-http_stub_status_module

   然后make

shell>> cd /opt/nginx
shell>> make
shell>> make install


   现在已经可以通过nginx命令来启动了,但是我们如果想要把nginx做成一个服务,必须要写一个shell.
简单说一下,
# chkconfig:  - 85 15 所有运行级别,启动优先级85, 关闭优先级15
# processname: 进程名称
# config:    nginx配置文件位置
# config:    系统会优先找第一个,如果找不到再去找第二个
# pidfile:   进程ID存放文件,用来存放程序启动后的进程ID

# Source function library.  linux常用的方法库,有兴趣可以去看看service XXX status 就使用了里边的一个方法
# Source networking configuration.  网络配置

#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#         by haitao.tu at 2009-12-15
#         email:tuhaitao@foxmail.com
#
# 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/sbin/nginx"
prog=$(basename $nginx)

NGINX_CONF_FILE="/etc/nginx/nginx.conf"

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

lockfile=/var/lock/subsys/nginx

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
}

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

restart() {
    configtest_q || configtest || return 6
    stop
    start
}

reload() {
    configtest_q || configtest || return 6
    echo -n $"Reloading $prog: "
    killproc $nginx -HUP
    echo
}

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

configtest_q() {
    configtest >/dev/null 2>&1
}

rh_status() {
    status $prog
}

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

# Upgrade the binary with no downtime.
upgrade() {
    local pidfile="/var/run/${prog}.pid"
    local oldbin_pidfile="${pidfile}.oldbin"

    configtest_q || configtest || return 6
    echo -n $"Staring new master $prog: "
    killproc $nginx -USR2
    retval=$?
    echo 
    sleep 1
    if [[ -f ${oldbin_pidfile} && -f ${pidfile} ]];  then
        echo -n $"Graceful shutdown of old $prog: "
        killproc -p ${oldbin_pidfile} -QUIT
        retval=$?
        echo 
        return 0
    else
        echo $"Something bad happened, manual intervention required, maybe restart?"
        return 1
    fi
}

case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart|configtest)
        $1
        ;;
    force-reload|upgrade)
        rh_status_q || exit 7
        upgrade
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    status|status_q)
        rh_$1
        ;;
    condrestart|try-restart)
        rh_status_q || exit 7
        restart
            ;;
    *)
        echo $"Usage: $0 {start|stop|reload|configtest|status|force-reload|upgrade|restart}"
        exit 2
esac

   好了,已经做成chkconfig了,下边需要配置一下nginx反向代理,需要修改/etc/nginx/nginx.conf配置文件

user  nginx;
worker_processes  2;

error_log   /var/log/nginx/error.log;
#error_log  /var/log/nginx/error.log  notice;
#error_log  /var/log/nginx/error.log  info;

pid         /var/run/nginx.pid;


events {
    use epoll; # 采用epoll,是linux下最快的event
    worker_connections  2048;
}


http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    #gzip  on;

    #反向代理配置 ,向内网6台jboss转发
    upstream jboss5 {
        server 172.16.201.127:8080 weight=10;
        server 172.16.201.128:8080 weight=10;
        server 172.16.201.129:8080 weight=10;
        server 172.16.201.130:8080 weight=10;
        server 172.16.201.131:8080 weight=10;
        server 172.16.201.132:8080 weight=10;
    }

    server {
        listen       80;
        server_name  localhost;

        location ~ ^/nginx_status/ {
            stub_status on;
            access_log off;
        }

        location / {
            proxy_pass http://jboss5;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

    }

}

Tags:使用 Nginx 帮助

编辑录入:爽爽 [复制链接] [打 印]
[]
  • 好
  • 好的评价 如果觉得好,就请您
      0%(0)
  • 差
  • 差的评价 如果觉得差,就请您
      0%(0)
更多精彩
    赞助商链接

    热点阅读
      焦点图片
        最新推荐
          精彩阅读