安装keepalived+lvs

安装keepalived+lvs
[root@lvs ~]# yum install -y kernel-devel kernel
[root@lvs ~]# yum install -y keepalived
[root@lvs ~]# vim /etc/sysctl.conf  追加arp抑制
net.ipv4.conf.eth0.arp_ignore = 1
net.ipv4.conf.eth0.arp_announce = 2
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
[root@Nginx ~]# sysctl -p  使内核配置生效

在主keepalived服务器nginx修改keepalived配置文件
[root@Nginx ~]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived

global_defs {
notification_email {br/>[email protected]
[email protected]
br/>[email protected]
}
notification_email_from [email protected]
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
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.159.14
}
}

virtual_server 192.168.159.14 80 {
delay_loop 3
lb_algo rr
lb_kind DR
nat_mask 255.255.255.0
persistence_timeout 50
protocol TCP

real_server 192.168.159.20 80 {
    weight 10
    TCP_CHECK {
   connect_timeout 10
   nb_get_retry 3
   delay_before_retry 3
   connect_port 80

}
}
real_server 192.168.159.21 80 {
weight 10
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
}
[root@lvs2~]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived

! Configuration File for keepalived

global_defs {
notification_email {
br/>[email protected]
[email protected]
br/>[email protected]
}
notification_email_from [email protected]
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
priority 90
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.159.14
}
}

virtual_server 192.168.159.14 80 {
delay_loop 3
lb_algo rr
lb_kind DR
nat_mask 255.255.255.0
persistence_timeout 50
protocol TCP

real_server 192.168.159.20 80 {
    weight 10
    TCP_CHECK {
   connect_timeout 10
   nb_get_retry 3
   delay_before_retry 3
   connect_port 80

}
}
real_server 192.168.159.21 80 {
weight 10
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
}
8.3.1设置keepalived开机启动
[root@lvs ~]# chkconfig keepalived on
[root@lvs ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:0c:69:fe brd ff:ff:ff:ff:ff:ff
inet 192.168.159.23/24 brd 192.168.159.255 scope global eth0
inet 192.168.159.14/32 scope global eth0
inet6 fe80::20c:29ff:fe0c:69fe/64 scope link
valid_lft forever preferred_lft forever

猜你喜欢

转载自blog.51cto.com/980696/2144010