安装keepalived+lvs

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了安装keepalived+lvs相关的知识,希望对你有一定的参考价值。

安装keepalived+lvs
[[email protected] ~]# yum install -y kernel-devel kernel
[[email protected] ~]# yum install -y keepalived
[[email protected] ~]# 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
[[email protected] ~]# sysctl -p  使内核配置生效

在主keepalived服务器nginx修改keepalived配置文件
[[email protected] ~]# 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
}
}
}
[[email protected]~]# 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开机启动
[[email protected] ~]# chkconfig keepalived on
[[email protected] ~]# 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





以上是关于安装keepalived+lvs的主要内容,如果未能解决你的问题,请参考以下文章

LVS+Nginx(LVS + Keepalived + Nginx安装及配置)

keepalived+nginx+lvs 安装流程

lvs+keepalived实战

安装keepalived+lvs

lvs+keepalived

keepalived lvs