先檢查/usr/src/kernels目錄下是否有文件,沒有則須要安裝kernelslinux
ll /usr/src/kernelsvim
安裝Kernels後端
yum -y install kernel-devel服務器
安裝軟連接檢查內核版本ide
ln -s /usr/src/kernels/3.10.0-957.27.2.el7.x86_64/ /usr/src/linuxoop
檢查內核模塊,看一下ip_vs 是否被加載測試
lsmod |grep ip_vs插件
!若是沒有則運行如下命令code
modprobe ip_vsrouter
安裝依賴插件
yum install libnl libpopt -y
yum install popt-static -y
安裝ipvsadm
cd /usr/src
wget -c http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.26.tar.gz
tar -xzvf ipvsadm-1.26.tar.gz
cd ipvsadm-1.26
make
make install
檢查安裝是否成功
whereis ipvsadm
ipvsadm配置:添加虛擬服務器IP,添加readlserver後端服務
ipvsadm -A -t 172.24.77.246:80 -s rr
ipvsadm -a -t 172.24.77.246:80 -r 172.24.77.241 -g -w2
ipvsadm -a -t 172.24.77.246:80 -r 172.24.77.242 -g -w2
查看LVS ipvsadm配置參數
ipvsadm -Ln
LVS服務器綁定VIP地址
ifconfig lo:0 172.24.77.246 netmask 255.255.255.0
查看地址是否添加成功
ip addr |grep 246
安裝keepalive
yum install keepalived -y
查看安裝版本信息
rpm -qi keepalived
配置Keepalived,master配置以下
vim /etc/keepalived/keepalived.conf
!刪除多餘配置
:35,156d
!修改成如下內容
! Configuration File for keepalived
global_defs {
notification_email {br/>root@locahost
}
notification_email_from keepalived@localhost
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id ha1.jay.com
vrrp_skip_check_adv_addr
vrrp_strict
vrrp_garp_interval 0
vrrp_gna_interval 0
vrrp_mcast_group4 224.0.0.18
}
vrrp_instance VI_1 {
state MASTER
interface ens33
virtual_router_id 80
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass silence2t
}virtual_ipaddress {
172.24.77.246 dev ens33 lable ens33:0
}
vrrp_script chk_LVS{
script "/data/sh/check_LVS.sh"
interval 2
weight 2
}
virtual_server 172.24.77.246 80 {
delay_loop 6
lb_algo wrt
lb_kind DR
persistence_timeout 60
protocol TCP
read_server 172.24.77.241 80 { weight 100 TCP_CHECK { connect_timeout 10 nb_get_retry 3 delay_before_retry 3 connect_port 80 }
}
read_server 172.24.77.242 80 { weight 100 TCP_CHECK { connect_timeout 10 nb_get_retry 3 delay_before_retry 3 connect_port 80
}
}
配置Keepalived,backup配置以下
vim /etc/keepalived/keepalived.conf
!刪除全部配置
:%d
!粘貼如下內容
! Configuration File for keepalived
global_defs {
notification_email {br/>root@locahost
}
notification_email_from keepalived@localhost
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id ha1.jay.com
vrrp_skip_check_adv_addr
vrrp_strict
vrrp_garp_interval 0
vrrp_gna_interval 0
vrrp_mcast_group4 224.0.0.18
}
vrrp_instance VI_1 {
state BACKUP
interface ens33
virtual_router_id 80
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass silence2t
}virtual_ipaddress {
172.24.77.246 dev ens33 lable ens33:0
}
vrrp_script chk_LVS{
script "/data/sh/check_LVS.sh"
interval 2
weight 2
}
virtual_server 10.206.35.253 80 {
delay_loop 6
lb_algo wrt
lb_kind DR
persistence_timeout 60
protocol TCP
read_server 172.24.77.241 80 { weight 100 TCP_CHECK { connect_timeout 10 nb_get_retry 3 delay_before_retry 3 connect_port 80 }
}
read_server 172.24.77.242 80 { weight 100 TCP_CHECK { connect_timeout 10 nb_get_retry 3 delay_before_retry 3 connect_port 80
}
}
查看VIP地址
ip addr
查看Iptalbes策略並刪除
iptables -vnL --line-number
iptables -D INPUT 1
測試訪問VIP
ping 172.24.77.246
測試keepalive高可用
check_LVS.sh腳本內容以下:
!將佔有VIP地址的主機關機,查看
systemctl stop keepalived
killall keepalived