Chinaunix首页 | 论坛 | 博客
  • 博客访问: 707708
  • 博文数量: 143
  • 博客积分: 1554
  • 博客等级: 上尉
  • 技术积分: 1767
  • 用 户 组: 普通用户
  • 注册时间: 2011-04-10 11:50
文章分类

全部博文(143)

文章存档

2017年(2)

2016年(5)

2015年(16)

2014年(25)

2013年(27)

2012年(16)

2011年(52)

分类: LINUX

2011-06-30 19:27:19

keepalived 实现前端HA双机热备
 
# tar zxvf keepalived-1.1.19.tar.gz
# cd keepalived-1.1.19
# ./configure --prefix=/opt/app/keepalived
# make
# make install
# cp /opt/app/keepalived/sbin/keepalived /usr/sbin/
# cp /opt/app/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
# cp /opt/app/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
# mkdir /etc/keepalived
# cd /etc/keepalived/# vi keepalived.conf! Configuration File for keepalived
global_defs {
notification_email {

}
notification_email

smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
mcast_src_ip 192.168.2.20    <==辅nginx的IP地址
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass chtopnet
}
virtual_ipaddress {
192.168.2.88                  <==VIP地址
}
}
# service keepalived start
通过命令看一下# ip a
1: lo: mtu 16436 qdisc noqueue
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 brd 127.255.255.255 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: mtu 1500 qdisc pfifo_fast qlen 1000
link/ether 00:0c:29:af:08:1d brd ff:ff:ff:ff:ff:ff
inet 192.168.10.61/24 brd 192.168.10.255 scope global eth0
inet 192.168.10.60/32 scope global eth0
inet6 fe80::20c:29ff:feaf:81d/64 scope link
valid_lft forever preferred_lft forever
3: sit0: mtu 1480 qdisc noop
link/sit 0.0.0.0 brd 0.0.0.0说明vip已经启动,这样主服务器就配置好了,辅机的配置大致一样,除了配置文件有少部分的变化,下面贴出辅机的配置文件:
! Configuration File for keepalived
global_defs {
notification_email {

}
notification_email_from

smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 51
mcast_src_ip 192.168.2.10         
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass yahunet
}
virtual_ipaddress {
192.168.2.88
}

 

两台服务器都需要配置keepalived

手动切换,只需要在主机上停止keepalived服务,自动会切到备机上。用命令ip a可查看虚拟IP地址!


阅读(1287) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~