a13698822086 发表于 2018-12-3 13:14:35

nginx+tomcat+jvm+keepalived部署实验手册

简单拓扑如下:
nginx(主负载均衡器):192.168.0.130
    nginx(从负载均衡器):192.168.0.136
    VIP地址:                      192.168.0.135
    tomcat1的IP                192.168.0.131
    tomcat2的IP               192.168.0.140
    布置整个环境用到的软件为:
   apache-tomcat-6.0.29.tar.gz
   jdk-6u23-linux-i586.bin
   nginx-0.8.53.tar.gz
nginx-upstream-jvm-route-0.1.tar.gz
   pcre-8.10.tar.gz
keepalived-1.1.15.tar.gz
实验运行的操作系统:centos5.3

一、 nginx服务器的安装和配置(192.168.0.130,192.168.0.136)
1. 安装openssl-devel
yum –y installopenssl-devel
2. 安装pcre
cd /usr/local
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.10.tar.gz
tar -zxvf pcre-8.10.tar.gz
cd pcre-8.10
./configure
make && make install
cp /usr/local/lib/libpcre.a /usr/include/pcre/libpcre.a
cp /usr/local/lib/libpcre.a /usr/include/pcre/libpcre.la
cp /usr/local/include/pcre.h /usr/include/pcre/pcre.h
mkdir /usr/include/pcre/.libs
cp /usr/local/lib/libpcre.a /usr/include/pcre/.libs/libpcre.a
cp /usr/local/lib/libpcre.a /usr/include/pcre/.libs/libpcre.la
cp /usr/local/include/pcre.h /usr/include/pcre/.libs/pcre.h
安装pcre-devel
yum –y install prce-devel

3.nginx+jvm-router安装
添加nginx使用的用户和组
# groupadd www                  #nginx使用的组;
# useradd -g www www            #nginx使用用户;
cd /usr/local
到http://code.google.com/p/nginx-upstream-jvm-route/downloads/list 下载 nginx-upstream-jvm-route-0.1.tar.gz
tar -zxvf nginx-upstream-jvm-route-0.1.tar.gz   
wget http://www.nginx.org/download/nginx-0.8.53.tar.gz
tar -zxvf nginx-0.8.53.tar.gz
cdnginx-0.8.53
patch -p0 < ../nginx_upstream_jvm_route/jvm_route.patch
./configure --user=www --group=www --prefix=/usr/local//nginx --with-http_stub_status_module --with-http_ssl_module--add-module=/usr/local/nginx_upstream_jvm_route/
make && make install

4.Nginx的配置文件 (主、辅配置一样)
    vi/usr/local/nginx/conf/nginx.conf
userwwwwww;
worker_processes1;

#error_loglogs/error.log;
#error_loglogs/error.lognotice;
#error_loglogs/error.loginfo;

#pid      logs/nginx.pid;


events {
    worker_connections1024;
}


http {
    include       mime.types;
    default_typeapplication/octet-stream;
    keepalive_timeout120;
    tcp_nodelay on;


upstream oa.com {
    server 192.168.0.131:8080 srun_id=a;
    server 192.168.0.140:8080 srun_id=b;
    jvm_route $cookie_JSESSIONID|sessionid reverse;
}


    server {
      listen       80;
      server_nameoa.com;

      #charset koi8-r;

      #access_loglogs/host.access.logmain;

      location / {
            root   /home/oa;
   indexindex.jsp   index.html index.htm;
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://oa.com;
    }

   log_format access '$remote_addr - $remote_user [$time_local] &quot;$request&quot; '
    '$status $body_bytes_sent &quot;$http_referer&quot; '
    '&quot;$http_user_agent&quot; $http_x_forwarded_for';
    access_log /var/log/access.log access;
}
}   


5. 启动nginx
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

Nginx 的重启:
ps -ef | grep &quot;nginx: master process&quot; | grep -v &quot;grep&quot; | awk -F ' ' '{print $2}'
kill   -HUB3944
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
6.设置ngnix为系统开机自动启动
#vi /etc/rc.d/rc.local
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf




页: [1]
查看完整版本: nginx+tomcat+jvm+keepalived部署实验手册