手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

基于Keepalived实现LVS高可用以及Web服务高可用

[日期:2013-05-18] 来源:51cto  作者:邓俊阳 [字体:大 中 小]

基于keepalived实现web服务的高可用

这是在完成上述实验后在HA1与HA2主机实现web服务的高可用

关闭node1与node2的keepalive

#service keepalived stop

在node1与node2上安装web服务

#yum -y install httpd

启动web服务后,分别准备web页面

# echo "node1.magedu.com" >/var/www/html/index.html

# echo "node2.magedu.com" >/var/www/html/index.html

访问web进行测试

配置文件准备与配置,此rpm制作(马哥专利的哦)时已经提供了(rpm包已经上传到附件了)

# cp keepalived.conf.haproxy_examplekeepalived.conf

# vim keepalived.conf

修改内容

定义一下服务脚本名称httpd(整个配置文件就贴出来了)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
! Configuration File for keepalived
global_defs {
notification_email {
linuxedu@foxmail.com
mageedu@126.com
}
notification_email_from kanotify@magedu.com
! Configuration File for keepalived
global_defs {
notification_email {
linuxedu@foxmail.com
mageedu@126.com
}
notification_email_from kanotify@magedu.com
smtp_connect_timeout 3
smtp_server 127.0.0.1
router_id LVS_DEVEL
}
vrrp_script chk_httpd {
script "killall -0 httpd"
interval 2
# check every 2 seconds
weight -2
# if failed, decrease 2 of the priority
fall 2
# require 2 failures for failures
rise 1
# require 1 sucesses for ok
}
vrrp_script chk_schedown {
script "[[ -f /etc/keepalived/down ]]&& exit 1 || exit 0"
interval 2
weight -2
}
vrrp_instance VI_1 {
interface eth0
# interface for inside_network, bound byvrrp
state MASTER
# Initial state, MASTER|BACKUP
# As soon as the other machine(s) come up,
# an election will be held and the machine
# with the highest "priority"will become MASTER.
# So the entry here doesn't matter a wholelot.
priority 101
# for electing MASTER, highest prioritywins.
# to be MASTER, make 50 more than other machines.
virtual_router_id 51
# arbitary unique number 0..255
# used to differentiate multiple instancesof vrrpd
# running on the same NIC (and hence samesocket).
garp_master_delay 1
authentication {
auth_typePASS
auth_pass password
}
track_interface {
eth0
}
# optional, monitor these as well.
# go to FAULT state if any of these godown.
virtual_ipaddress {
172.16.51.70/16 dev eth0 label eth0:0
}
#addresses add|del on change to MASTER, toBACKUP.
#With the same entries on other machines,
#the opposite transition will be occuring.
}
track_interface {
eth0
}
# optional, monitor these as well.
# go to FAULT state if any of these godown.
virtual_ipaddress {
172.16.51.70/16 dev eth0 label eth0:0
}
#addresses add|del on change to MASTER, toBACKUP.
#With the same entries on other machines,
#the opposite transition will be occuring.
#<IPADDR>/<MASK> brd<IPADDR> dev <STRING> scope <SCOPE> label <LABEL>
track_script {
chk_httpd
chk_schedown
}
notify_master"/etc/keepalived/notify.sh master"
notify_backup"/etc/keepalived/notify.sh backup"
notify_fault"/etc/keepalived/notify.sh fault"
}
#vrrp_instance VI_2 {
# interface eth0
# state MASTER # BACKUP for slaverouters
# priority 101 # 100 for BACKUP
# virtual_router_id 52
# garp_master_delay 1
#
# authentication {
# auth_typePASS
# auth_pass password
# }
# track_interface {
# eth0
# }
# virtual_ipaddress {
# 172.16.100.2/16 dev eth0 label eth0:1
# }
# track_script {
# chk_haproxy
# chk_mantaince_down
# }
#
# notify_master "/etc/keepalived/notify.sh master eth0:1"
# notify_backup "/etc/keepalived/notify.sh backup eth0:1"
# notify_fault "/etc/keepalived/notify.sh fault eth0:1"
#
}

 

复制配置文件到node2主机

# scp /etc/keepalived/keepalived.confnode2:/etc/keepalived/

复制后需要修改内容如下

state BACKUP

priority 100

启动keepalived服务

查看MASTER(node1)上主机定义的VIP(eth0别名IP)是否成功

访问虚拟IP地址

主备转换测试

# cd /etc/keepalived/

# touch down

在备用节点node2上查看

访问虚拟IP

现在把down文件删除,MASTER节点会夺回资源,因为在node1上的优先级(101)比nod2上的优先级(100)高

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款