jetty昨天的帖子里面已经安装完成,运行一个jetty对于服务太不稳定或者安全,在实际运营中有很少见到,今天的想法是使用两个NG 代理多个jetty。

一、下载与编译安装
mginx---主程序
upstream---上游服务健康检查,实现和后端服务器(php/jboss等)进行通信。
sticky---使用cookie代替客户端连接的IP,基于一个“最佳”算法。它的目标不是处理安全以某种方式。这是被作出保证正常用户永远都重定向到同一后端服务器
mkdir /ftp    //习惯性在根下面建立一个ftp目录,ng或者jetty之后的LVS是放在/web下的
cd /ftp
wget http://nginx.org/download/nginx-1.2.2.tar.gz
wget http://nginx-sticky-module.googlecode.com/files/nginx-sticky-module-1.0.tar.gz
wget https://github.com/yaoweibin/nginx_upstream_check_module/zipball/master/
mv master master.zip
yaoweibin 写的upstream 介绍:
https://github.com/yaoweibin/nginx_upstream_check_module
 

unzip master.zip
tar -zxvf nginx-sticky-module-1.0.tar.gz
tar -zxvf nginx-1.2.2.tar.gz
[root@res02 nginx-1.2.2]#patch -p1 < ../yaoweibin-nginx_upstream_check_module-be97c70/check_1.2.2+.patch
[root@res02 nginx-1.2.2]#mkdir /web/nginx
[root@res02 nginx-1.2.2]# yum install gd-devel openssh-clients openssl-devel gcc make pcre-devel -y
[root@res02 nginx-1.2.2]# rpm -qa  gd-devel openssh-clients openssl-devel gcc make pcre-devel
openssh-clients-5.3p1-81.el6.x86_64
gd-devel-2.0.35-10.el6.x86_64
make-3.81-20.el6.x86_64
gcc-4.4.6-4.el6.x86_64
pcre-devel-7.8-4.el6.x86_64
openssl-devel-1.0.0-20.el6_2.5.x86_64
[root@res02 nginx-1.2.2]# useradd nginx -d /dev/null -s /sbin/nologin
[root@res02 nginx-1.2.2]# ./configure --user=www --group=www --prefix=/web/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --pid-path=/var/run/nginx.pid --lock-path=/var/lock/subsys/nginx --user=nginx --group=nginx --with-poll_module --with-http_ssl_module --with-http_p_w_picpath_filter_module --with-http_sub_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_realip_module --with-http_p_w_picpath_filter_module --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/ftp/ --http-proxy-temp-path=/var/tmp/nginx/proxy/ --add-module=../yaoweibin-nginx_upstream_check_module-be97c70 --add-module=../nginx-sticky-module-1.0
[root@res02 nginx-1.2.2]# make
[root@res02 nginx-1.2.2]# make install
[root@res02 nginx-1.2.2]# cd /etc/sysconfig/
[root@res02 sysconfig]# echo 'NGINX_CONF_FILE="/etc/nginx/nginx.conf"'  > nginx

[root@res02 sysconfig]# cd /etc/nginx/
上传附件启动脚本到该目录。
[root@res02 nginx]# chmod 755 /etc/nginx/nginx.sh
[root@res02 nginx]#ln -s /etc/nginx/nginx.sh /etc/init.d/nginx
[root@res02 nginx]# mkdir -p /var/tmp/nginx/proxy

安装到这里nginx 已经安装完毕,输入命令:service nginx start 即可启动。默认端口80
后面是整合jetty 的配置。
 


二、配置nginx 负载均衡
[root@res02 nginx]# vim /etc/nginx/nginx.conf
注释掉默认server 的配置,加入代码:

 
  
  1. proxy_headers_hash_bucket_size 1024;  
  2. proxy_headers_hash_max_size 512;  
  3.  
  4. upstream res {  
  5.      sticky;  
  6.      server 10.10.15.230:8080 down;  
  7.      server 10.10.15.220:8080;  
  8.              check interval=3000 rise=2 fall=5 timeout=1000 type=http;  
  9.              check_http_send "GET / HTTP/1.0\r\n\r\n";  
  10.              check_http_expect_alive http_2xx http_3xx;  
  11.     }  
  12.  
  13.     server {  
  14.         listen       80;  
  15.         server_name  res.888jk.net;  
  16.  
  17.          location / {  
  18.          proxy_set_header Host $host;  
  19.          proxy_set_header X-Real-IP $remote_addr;  
  20.          proxy_set_header X-Forwarded-For $http_x_forwarded_for;  
  21.          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;  
  22.          proxy_pass http://res;  
  23.          }  
  24.  
  25.  location /status {  
  26.              check_status;  
  27.              access_log      /var/log/nginx/res.log;  
  28.              auth_basic "RES-Nginx-Status";  
  29.              auth_basic_user_file "/usr/local/nginx/html/.htpasswd";  
  30.              }  

[root@res02 nginx]# mkdir -p /usr/local/nginx/html
[root@res02 nginx]# vim /usr/local/nginx/html/.htpasswd
blueway:4hInEbbTbERQ
密码是由htpasswd 生成的。
比如在安装有apache 的服务器上生成MD5密码:
htpasswd -bc .passwd blueway php!
注释:生成一个.passwd文件,用户名blueway,密码:php!,默认采用MD5加密方式