surroundings:
centos7.6
node1 master 192.168.1.172
node backup 192.168.1.173
vip 192.168.1.174
First realserver installed separately install httpd and keepalived, yum install it
Creating index.html file in node1 / var / www / html / directory
Open httpd service access 192.168.1.172
Creating index.html in node2 / var / www / html / directory
Open httpd service access 192.168.1.173
keepalived Configuration
master configuration
global_defs {
notification_email {
[email protected]
}
# notification_email_from [email protected]
# smtp_server 192.168.200.1
# smtp_connect_timeout 30
router_id node1
# vrrp_skip_check_adv_addr
# vrrp_strict
# vrrp_garp_interval 0
# vrrp_gna_interval 0
}
vrrp_instance VI_1 {
state MASTER
interface ens160 # Set monitor network port
51 is virtual_router_id
priority # 100 The higher the number, the higher the level, to ensure higher than the backup
advert_int. 1
authentication {
AUTH_TYPE the PASS
AUTH_PASS 1111
}
virtual_ipaddress {
192.168.1.174
}
}
backup configuration
Above with reference to the configuration file, modified as follows
router_id node2
state BAKCUP
priority 99
After saving, standby opening keepalived systemctl start keepalived
With ip al ip command to view a virtual server on which
192.168.1.174 browser access can see is to visit the node1
The network or the master port is closed off keepalived shutdown operation, ip automatically migrating virtual backup.
Have the above drawbacks, if the httpd server does not automatically linked to the master cut to bakcup
Solution:
Change the profile, increase port monitor
global_defs {
notification_email {
[email protected]
}
# notification_email_from [email protected]
# smtp_server 192.168.200.1
# smtp_connect_timeout 30
router_id node1
# vrrp_skip_check_adv_addr
# vrrp_strict
# vrrp_garp_interval 0
# vrrp_gna_interval 0
}
vrrp_script chk_httpd_port {
script "</dev/tcp/127.0.0.1/80"
interval 2
weight 2
}
vrrp_instance VI_1 {
state BACKUP #该值主备要一致
interface ens160
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.1.174
}
track_script {
chk_httpd_port
}
}