hp-ux nginx實現webservice請求負載均衡,並監控nginx進程

下載nginx-1.5.7.tar.gz, zlib-1.2.8.tar.gz
安裝nginx:
./configure: error: the HTTP rewrite module requires the PCRE library.

root安裝pcre-8.33.tar.gz perl庫
再nginx:
./configure: error: the HTTP gzip module requires the zlib library.


gzip -d或者gunzip 解壓tar.gz文件
tar xvf zlib-1.2.8.tar

安裝nginx時還是報錯:
./configure: error: the HTTP gzip module requires the zlib library.


nginx without去除安裝模塊,默認安裝到/usr/local/nginx下
./configure --user=root --group=sys --without-http_gzip_module即可成功安裝(./cofigure ,make,make install)

修改/usr/local/nginx/conf/nginx.conf增加配置:
  #設定負載均衡的服務器列表
    upstream localhost {
    #    #weigth參數表示權值,權值越高被分配到的機率越大
    #    #本機上的Squid開啓3128端口
    #    #server 192.168.8.3:80 weight=6;
    server 10.25.79.97:9998;
    server 10.25.79.98:9998;
    }

server {
        #listen       80;
        listen       9999;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
            #webservice conf
            proxy_redirect off; 
            proxy_set_header Host $host; 
            proxy_set_header X-Real-IP $remote_addr; 
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
            proxy_pass http://localhost; 
        }

啓動/停止:參考http://blog.csdn.net/lhl62411570/article/details/8108627
啓動:
[interface1]:/usr/local/nginx/sbin #/usr/local/nginx/sbin/nginx
nginx: [emerg] bind() to 0.0.0.0:9999 failed (226: Unknown error)------端口被佔用了
查看進程:ps -ef|grep nginx

停止:./nginx -s stop
nginx多站點配置:http://www.jb51.net/article/27533.htm
http://blog.csdn.net/ouyangzhan/article/details/6015243

monNginx.sh:監控腳本

#Deploy to nginx/sbin
WORK_HOME=/usr/local/nginx

Restart()
{
    $WORK_HOME/sbin/nginx -s stop
    sleep 1
    $WORK_HOME/sbin/nginx
    
    msg=`hostname`,Ngnix,`date +%Y%m%d%H%M%S`,$1
    echo "$msg" >> $WORK_HOME/sbin/mon.log
    #sh $WORK_HOME/sh/sendmail.sh $msg
}

MonPname()
{
    pid=`ps -ef | grep "$WORK_HOME/sbin/nginx" |grep -v grep| wc -l`
    if [ $pid -le 0 ] ; then
        Restart "MonPname,restart"
    fi
}

MonPort()
{
    pid=`netstat -an |grep 9999 |grep LISTEN`
    if [ "$pid" = "" ]
    then
        Restart "MonPort,restart"
    fi
}

MonPname
MonPort




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章