HA(High Available):高可用性群集,是保证业务连续性的有效解决方案,一般有两个或两个以上的节点,且分为活动节点(master)及备用节点(slave)。当master出现问题,导致正在运行的业务(任务)不能正常运行时,slave此时就会侦测到,并立即接续活动节点来执行业务。从而实现业务的不中断或短暂中断,在此过程中,用户使用不会受到任何影响。
测试机器3台:
1.nginx:部署nginx主要作用是进行代理转发操作
2.master:部署master的apache和tomcat服务
3.slave:部署slave的apache和tomcat服务
安装命令:
apt-get install nginx //安装nginx
apt-get install apache2 libapache2-mod-jk tomcat6//master和slave服务器安装apache和tomcat
服务器配置:
nginx服务器配置,/etc/nginx/sites-enabled/VTWeb//sites-enabled下配置文件名自定义
upstream VTWeb {
server 192.168.1.72 max_fails=3; //将72设置为master
server 192.168.1.10 backup; //将10设置为slave
} server {
// server port and name //
listen 192.168.1.11:80 ; //此处端口填写apache所使用端口,默认80
server_name lacalhost; //填写ip地址或域名
access_log /var/log/nginx/tracker3.videodna.com.access.logrequest_time;
location / {
proxy_pass http://tracker3.videodna.com;
proxy_next_upstream error timeout invalid_headerhttp_503;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For$remote_addr;
proxy_set_header X-Forwarded-Host$server_name;
proxy_set_header Host $host;
proxy_connect_timeout 60;
proxy_send_timeout 60; proxy_read_timeout 900;
} }
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
master和slave中apache2配置,/etc/apache2/sites-enabled/VTWeb,以下两个文件在master和slave都需要进行配置
#loadModule jk_module /usr/lib/apache2/modules/mod_jk.so
JkWorkersFile "/etc/apache2/workers.properties"//填写转发文件绝对路径,重要
JkLogFile "/var/log/apache2/mod_jk.log"
Alias /cache /var/www/cache
Alias /vtontc /var/www/vtontc
Alias /vtontc1.2 /var/www/vtontc1.2
Alias /data /var/www/data
Alias /resource /var/www/resource
Alias /msn /var/www/msn
ServerName 192.168.1.10 //当前服务器地址
Options FollowSymLinks AllowOverride None
DocumentRoot "/var/lib/tomcat6/webapps/VTWeb/" ServerName192.168.1.10
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
AllowOverride None Options +ExecCGI -MultiViews? +SymLinksIfOwnerMatch? Orderallow,deny Allow from all
#Deny direct access to WEB-INF and META-INF deny from all
AllowOverride None deny from all
#Use Directory too. On Windows, Location doesn't work unlesscase matches AllowOverride None deny from all
AllowOverride None deny from all
jkMount / ajp13
JkMount /*.do ajp13
JkMount /*.jsp ajp13
JkMount /dwr/* ajp13
jkMount /exportWhiteListReport ajp13
jkMount /dataFeedForMatch ajp13
jkMount /josso_security_check ajp13
jkMount /josso_user_login/ ajp13
jkMount /josso_logout/ ajp13
CustomLog /var/log/apache2/tracker3.log vhost_combined//输出log配置
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
apache2配置,/etc/apache2/workers.properties,该文件不存在时需手动创建
worker.list=ajp13
# Define a worker using ajp13 worker.app1.port=8009//该端口为nginx转发时所用端口,如被占用将影响服务
worker.app1.host=localhost
worker.app1.type=ajp13
# Define the LB worker
worker.ajp13.type=lb
worker.ajp13.sticky_session=True
#worker.ajp13.sticky_session_force=True
worker.ajp13.balance_workers=app1
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
注意事项: 1.tomcat配置增加了一行
vdna@qa-10:/etc/apache2/sites-enabled $ less/var/lib/tomcat6/conf/server.xml |grep VTWeb
2.系统中部分端口默认是不开启的,需要手动开启
测试方法:
开启nginx,/etc/init.d/nginx start
开启apache,/etc/init.d/apache2 start
开启tomcat,/etc/init.d/tomcat6 start
case1:3个服务器中5个服务均开启,访问nginx地址:192.168.1.11成功打开VTWeb首页
case2:将master服务器中的apache服务停止,访问nginx地址:192.168.1.11成功打开VTWeb首页,并且在slave的log中输出请求日志格式如下:
192.168.1.10:80 192.168.1.11 - - [09/Oct/2014:18:10:12+0800] "GET/VTWeb/login/images/bot/top_contact_2.gif HTTP/1.0" 404 642" http://192.168.1.11/VTWeb/""Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5)AppleWebKit/600.1.17 (KHTML, like Gecko) Version/7.1Safari/537.85.10"
case3:将slave服务器中的apache服务停止,访问nginx地址:192.168.1.11成功打开VTWeb首页
case4:将master服务器中的tomcat停止
case5:将master服务器中的apache和tomcat全部停止
master在不同情况下测试结果:
apache up, tomcat up, 访问正常
apache up, tomcat down, 检测到503错误,切换到备份服务器,访问正常
apache down, tomcat up, 检测到502错误,切换到备份服务器,访问正常
apache down, tomcat down, 切换到备份服务器,访问正常
原文地址:http://blog.sina.com.cn/s/blog_4d3ff0eb0102vc0o.html