OS: CentOS7 minimal(VBox)
Virtual Box Network configure:
- Attached to
Bridged Adapter
- Advanced
promiscuous mode:
Allow All
一、安装
prepare tool:
#yum install gcc make autoconf automake openssl-devel libnl3-devel \
iptables-devel ipset-devel net-snmp-devel libnfnetlink-devel file-devel \
glib2-devel pcre2-revel libnftnl-devel libmnl-devel systemd-devel kmod-devel
LVS manager:
yum install ipvsadm
installation
- MASTER
Node 1 - BACKUP
Node 2
down and unzip
$git clone https://github.com/acassen/keepalived.git
for me:
$git clone https://gitee.com/xiaobin80/keepalived
installation
$cd keepalived
$./autogen.sh
configure:
$./configure --prefix=/usr
make:
$make
Root permission Required
#make install
setup
#mkdir -p /etc/keepalived
$sudo mv /etc/keepalived/keepalived.conf.sample /etc/keepalived/keepalived.conf
$sudo cp ./keepalived/etc/init.d/keepalived /etc/init.d/
$sudo chmod 755 /etc/init.d/keepalived
- test
$keepalived -v
Security Options
allow fire wall port:
#firewall-cmd --permanent --zone=public --add-port=80/tcp
#firewall-cmd --reload
selinux
$vi /etc/selinux/config
更改enforcing为disabled:
SELINUX=disabled
二、配置
Table 4.1. lv_algo Values for Virtual Server
Algorithm Name | lv_algo value |
---|---|
Round-Robin | rr |
Weighted Round-Robin | wrr |
Least-Connection | lc |
Weighted Least-Connection | wlc |
Locality-Based Least-Connection | lblc |
Locality-Based Least-Connection Scheduling with Replication | lblcr |
Destination Hash | dh |
Source Hash | sh |
Source Expected Delay | sed |
Never Queue | nq |
example
/etc/keepalived/keepalived.conf
global_defs {
max_auto_priority
}
vrrp_instance VI_1 {
state MASTER
interface enp0s3
virtual_router_id 49
priority 200
advert_int 1
authentication {
auth_type PASS
auth_pass passw123
}
virtual_ipaddress {
192.168.0.220/24
}
}
virtual_server 192.168.0.220 80 {
delay_loop 6
lb_algo wrr
lb_kind DR
persistence_timeout 9600
protocol TCP
real_server 192.168.0.127 80 {
weight 3
TCP_CHECK {
connect_timeout 10
retry 3
delay_before_retry 3
connect_port 80
}
}
real_server 192.168.0.122 80 {
weight 1
TCP_CHECK {
connect_timeout 10
retry 3
delay_before_retry 3
connect_port 80
}
}
}
priority
- node 1
200
- node 2
150