一、KEEPALIVED双机热备
1、安装
yum install gcc kernel-devel openssl-devel popt-devel libnl-devel -y
rpm -ivh ipvsadm-1.25-10.el6.i686.rpm
./configure --prefix=/ --with-kernel-dir=/usr/src/kernels/2.6.32-279.el6.i686/&&make&&make install
chkconfig --add keepalived
chkconfig keepalived on
service keepalived start
2、配置主服务器
vim /etc/keepalived/keepalived.conf
global_defs {
router_id HA_1 //本服务器的名称
}
vrrp_instance VI_1 { //定义VRRP热备实例
state MASTER //MASTER表示主服务器
interface eth0 //承载VIP地址的物理接口
virtual_router_id 1 //虚拟路由器的ID号
priority 100 //优先级,数值越大优先级越高
advert_int 1 //通告间隔秒数(心跳频率)
authentication { //认证信息
auth_type PASS //认证类型
auth_pass 123456 //密码字串
}
virtual_ipaddress {
192.168.100.200 //指定漂移地址(VIP)
}
}
service keepalived restart
ip addr show dev eth0
3、配置从服务器
vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
router_id HA-2
}
vrrp_instance VI_1 {
state SLAVE
interface eth0
virtual_router_id 1
priority 80
advert_int 1
authentication {
auth_type PASS
auth_pass 123456
}
virtual_ipaddress {
192.168.100.200
}
}
service keepalived restart
ip addr show dev eth0
二、KEEPALIVED+LVS-DR
1、配置NFS
yum install nfs-utils portmap(rpcbind) -y
vim /etc/exports
/opt/wwwroot 192.168.100.0/24(ro)
service nfs restart
2、配置节点服务器
showmount -e 192.168.100.100
vim /etc/fstab
192.168.100.100:/opt/wwwroot /var/www/html nfs defaults 0 0
mount -a
service httpd start
3、配置主调度服务器
yum install gcc kernel-devel openssl-devel popt-devel libnl-devel -y
rpm -ivh ipvsadm-1.25-10.el6.i686.rpm
./configure --prefix=/ --with-kernel-dir=/usr/src/kernels/2.6.32-279.el6.i686/&&make&&make install
chkconfig --add keepalived
chkconfig keepalived on
service keepalived start
vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
router_id HA-1
}
vrrp_instance VI_1 {
state MASTER
interface eth1
virtual_router_id 1
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 123456
}
virtual_ipaddress {
202.106.195.111
}
}
virtual_server 202.106.195.111 80 {
delay_loop 15
lb_algo rr
lb_kind DR
! persistence 60
protocol TCP
real_server 202.106.195.10 80 {
weight 1
TCP_CHECK {
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 4
}
}
real_server 202.106.195.20 80 {
weight 1
TCP_CHECK {
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 4
}
}
}
4、配置从调度服务器
yum install gcc kernel-devel openssl-devel popt-devel libnl-devel -y
rpm -ivh ipvsadm-1.25-10.el6.i686.rpm
./configure --prefix=/ --with-kernel-dir=/usr/src/kernels/2.6.32-279.el6.i686/&&make&&make install
chkconfig --add keepalived
chkconfig keepalived on
service keepalived start
vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
router_id HA-2
}
vrrp_instance VI_1 {
state SLAVE
interface eth1
virtual_router_id 1
priority 80
advert_int 1
authentication {
auth_type PASS
auth_pass 123456
}
virtual_ipaddress {
202.106.195.111
}
}
virtual_server 202.106.195.111 80 {
delay_loop 15
lb_algo rr
lb_kind DR
! persistence 60
protocol TCP
real_server 202.106.195.10 80 {
weight 1
TCP_CHECK {
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 4
}
}
real_server 202.106.195.20 80 {
weight 1
TCP_CHECK {
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 4
}
}
}
5、配置节点服务器
cp ifcfg-lo ifcfg-lo:0
vim ifcfg-lo:0
DEVICE=lo:0
IPADDR=202.106.195.111
NETMASK=255.255.255.255
#NETWORK=127.0.0.0
# If you're having problems with gated making 127.0.0.0/8 a martian,
# you can change this to something else (255.255.255.255, for example)
#BROADCAST=127.255.255.255
ONBOOT=yes
#NAME=loopback
vim /etc/rc.local
/sbin/route add -host 202.106.195.111 dev lo:0
vim /etc/sysctl.conf
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.default.arp_ignore = 1
net.ipv4.conf.default.arp_announce = 2
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2
sysctl -p
reboot
编辑回复