分类: LINUX
2014-04-02 15:57:59
LVS-HA安装配置
一、安装
1. Yum install ipvsadm piranha
二、配置(主备配置文件相同)
1. 编辑主配置文件 /etc/sysconfig/ha/lvs.cf 如下:
2. serial_no = 37 #主从配置相同
3. primary = 113.106.48.87 #主服务器IP地址
4. service = lvs #服务名
5. backup_active = 1 #是否有备份
6. backup = 113.106.48.88 #备服务器IP地址
7. heartbeat = 1 #是否启用心跳
8. heartbeat_port = 539 #心跳监测端口
9. keepalive = 6 #心跳间隔时间/秒
10. deadtime = 18 #心跳超时时间
11. network = direct #LVS连接方式
12. debug_level = NONE #日志级别
13. monitor_links = 0
14. syncdaemon = 0
15.
16. virtual WEB {
17. active = 1 #是否激活
18. address = 113.106.48.67 eth0:2 #虚拟服务所绑定的ip(vip)以及设备名
19. vip_nmask = 255.255.255.255 #vip相对应的掩码
20. port = 80 #虚拟服务的端口
21. send = "GET / HTTP/1.0\r\n\r\n" #请求包监测
22. expect = "HTTP" #请求包响应状态
23. use_regex = 0 #否使用正则表达式
24. load_monitor = none
25. scheduler = wlc #LVS调度算法
26. protocol = tcp #虚拟服务使用的协议类型
27. timeout = 6 #realserver失效后从lvs路由条目中移除realserver所必须经过的时间(秒)
28. reentry = 15 #移除以后的realserver重新加入lvs路由条目所必须经过的时间(秒)
29. quiesce_server = 0
30. server 12006113 { #realsever服务名称,可自定义,在这里我使用主机名
31. address = 113.106.48.89 #realserver的ip地址
32. active = 1 #是否激活
33. port = 80 #rs端口
34. weight = 1 #权重
35. }
36. server 12006117 {
37. address = 113.106.48.88
38. active = 1
39. port = 80
40. weight = 1
41. }
42. server 12006118 {
43. address = 113.106.48.87
44. active = 1
45. port = 80
46. weight = 1
47. }
48. server 12006116 {
49. address = 113.106.48.91
50. active = 1
51. port = 80
52. weight = 1
53. }
54. server 12006114 {
55. address = 113.106.48.92
56. active = 1
57. port = 80
58. weight = 1
59. }
60. }
三、启动
1. /etc/init.d/pulse start
四、Realserver运行绑定脚本
1. Realserver start 0 113.106.48.67 #其中数据0表示设备名称,IP为VIP地址
2. 脚本如下:
3. #!/bin/bash
4. WEB_VIP=$3
5.
6. . /etc/rc.d/init.d/functions
7.
8. case "$1" in
9. start)
10. ifconfig lo:$2 $WEB_VIP netmask 255.255.255.255 broadcast $WEB_VIP
11. /sbin/route add -host $WEB_VIP dev lo:$2
12. echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore
13. echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce
14. echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
15. echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce
16. sysctl -p >/dev/null 2>&1
17. echo "RealServer Start OK"
18.
19. ;;
20. stop)
21. ifconfig lo:$2 down
22. route del $WEB_VIP >/dev/null 2>&1
23. echo "0" >/proc/sys/net/ipv4/conf/lo/arp_ignore
24. echo "0" >/proc/sys/net/ipv4/conf/lo/arp_announce
25. echo "0" >/proc/sys/net/ipv4/conf/all/arp_ignore
26. echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce
27. echo "RealServer Stoped"
28. ;;
29. status)
30. # Status of LVS-DR real server.
31. islothere=`/sbin/ifconfig lo:$2 | grep $WEB_VIP`
32. isrothere=`netstat -rn | grep "lo:$2" | grep $web_VIP`
33. if [ ! "$islothere" -o ! "isrothere" ];then
34. # Either the route or the lo:$2 device
35. # not found.
36. echo "LVS-DR real server Stopped."
37. else
38. echo "LVS-DR Running."
39. fi
40. ;;
41. *)
42. # Invalid entry.
43. echo "$0: Usage: $0 {start|status|stop}"
44. exit 1
45. ;;
46. esac
47. exit 0
五、查看测试
1. Ipvsadm –ln 查看LVS状态及连接数据
2. 当停止主服务器后,备服务器会在心跳时间后自动接管LVS