两台主机
实机ip
web1:10.0.17.205
wen2:10.0.17.206
VIP
10.0.17.250
web1
yum install httpd -y
yum install keepalived
nmcli connection add con-name ens33 ifname ens33 type ethernet
nmcli connection modify ens33 ipv4.method manual ipv4.addresses 10.0.17.205/24 connection.autoconnect yes
nmcli connection up ens33
echo "10.0.17.205" >/var/www/html/index.html
systemctl restart httpd
iptables -F
firewall-cmd --set-default-zone=trusted
配置keepalived
vi /etc/keepalived/keepalived.conf
global_defs {
router_id web1
vrrp_iptables
}
vrrp_instance VI_1 {
state MASTER
interface ens33
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.0.17.250:80
}
}
systemctl enable keepalived.service
systemctl start keepalived.service
web2
yum install httpd -y
yum install keepalived
nmcli connection add con-name ens33 ifname ens33 type ethernet
nmcli connection modify ens33 ipv4.method manual ipv4.addresses 10.0.17.206/24 connection.autoconnect yes
nmcli connection up ens33
echo "10.0.17.206" >/var/www/html/index.html
systemctl restart httpd
iptables -F
firewall-cmd --set-default-zone=trusted
配置keepalived
vi /etc/keepalived/keepalived.conf
global_defs {
router_id web1
vrrp_iptables
}
vrrp_instance VI_1 {
state BACKUP
interface ens33
virtual_router_id 51
priority 50
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.0.17.250:80
}
}
systemctl enable keepalived.service
systemctl start keepalived.service