Keepalived Installation and Configuration
I. Environmental description
1, operating system kernel version: CentOS7
2, keepalived software version: keepalived-1.2.13-8.el7.x86_64
Second, the Environment configuration
1, the main keepalived server IP address 192.168.170.156
2, Standby keepalived server IP address 192.168.170.157
3, keepalived virtual IP address 192.168.170.160/192.168.170.161
Third, the software download address
http://www.keepalived.org/
Iv. installation Process
1, yum Installation
[Root@mdb02 ~]# Yum install-y keepalived
2, set up for service, boot up
[Root@mdb02 ~]# vi/etc/rc.local
#!/bin/bash
# This FILE was ADDED for compatibility purposes
#
# It is highly advisable to create own SYSTEMD services or Udev rules
# To run scripts during boot instead of the using this file.
#
# In contrast to previous versions due to parallel execution boot
# This script won't be run on all other services.
#
# Please be must run ' chmod +x/etc/rc.d/rc.local ' to ensure
# that this script would be executed during boot.
Touch/var/lock/subsys/local
/bin/systemctl Start Keepalived.service
~
"/etc/rc.local" 14L, 514C written
[Root@mdb02 ~]#/bin/systemctl start Keepalived.service
V. Main keepalived Configuration
1, modify the configuration file
! Configuration File for Keepalived
Global_defs {
Notification_email {
31601254@qq.com
}
Notification_email_from 31601254@qq.com
Smtp_server 127.0.0.1
Smtp_connect_timeout 30
router_id Lvs_devel
}
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 {
192.168.170.160 # #群集虚拟IP
192.168.170.161
}
}
2, Start keepalived
[ROOT@MDB01 etc]# Service keepalived start
3, Query enabled status
[Root@mdb01 etc]# IP Add show
1:lo: <LOOPBACK,UP,LOWER_UP> MTU 65536 qdisc noqueue State UNKNOWN Qlen 1
Link/loopback 00:00:00:00:00:00 BRD 00:00:00:00:00:00
inet 127.0.0.1/8 Scope host Lo
Valid_lft Forever Preferred_lft Forever
INET6:: 1/128 Scope Host
Valid_lft Forever Preferred_lft Forever
2:ENS33: <BROADCAST,MULTICAST,UP,LOWER_UP> MTU 1500 Qdisc pfifo_fast State up Qlen 1000
Link/ether 00:0c:29:65:43:9c BRD FF:FF:FF:FF:FF:FF
inet 192.168.170.156/24 BRD 192.168.170.255 Scope Global ENS33
Valid_lft Forever Preferred_lft Forever
inet 192.168.170.160/32 Scope Global ENS33
Valid_lft Forever Preferred_lft Forever
inet 192.168.170.161/32 Scope Global ENS33
Valid_lft Forever Preferred_lft Forever
Inet6 FE80::B9FE:6E0:ED29:1519/64 Scope link
Valid_lft Forever Preferred_lft Forever
Inet6 fe80::4791:4dd4:b281:ca5/64 Scope link tentative dadfailed
Valid_lft Forever Preferred_lft Forever
Vi. Preparation of keepalived configuration
1, modifying configuration files
! Configuration File for keepalived
global_defs {
notification_email {
& nbsp 31601254@qq.com
}
notification_email_from 31601254@qq.com
smtp_ Server 127.0.0.1
smtp_connect_timeout
router_id lvs_devel
}
Vrrp_ Instance Vi_1 {
State BACKUP
interface Ens33
VIRTUAL_ROUTER_ID
Priority
advert_int 1
Authentication {
auth_type pass
auth_pass 1111
}
virtual_ipaddress {
192.168.170.160
192.168.170.161
}
}
2, start keepalived
[ROOT@MDB01 etc]# Service keepalived start 3, query startup status
[Root@mdb01 ~]# IP Add show
1:lo: <LOOPBACK,UP,LOWER_UP> MTU 65536 qdisc noqueue State UNKNOWN Qlen 1
Link/loopback 00:00:00:00:00:00 BRD 00:00:00:00:00:00
inet 127.0.0.1/8 Scope host Lo
Valid_lft Forever Preferred_lft Forever
INET6:: 1/128 Scope Host
Valid_lft Forever Preferred_lft Forever
2:ENS33: <BROADCAST,MULTICAST,UP,LOWER_UP> MTU 1500 Qdisc pfifo_fast State up Qlen 1000
Link/ether 00:0c:29:56:82:5f BRD FF:FF:FF:FF:FF:FF
inet 192.168.170.156/24 BRD 192.168.170.255 Scope Global ENS33
Valid_lft Forever Preferred_lft Forever
inet 192.168.170.160/32 Scope Global ENS33
Valid_lft Forever Preferred_lft Forever
inet 192.168.170.161/32 Scope Global ENS33
Valid_lft Forever Preferred_lft Forever
Inet6 FE80::EBEF:2358:8EAB:4AF8/64 Scope link
Valid_lft Forever Preferred_lft Forever
Seven, start the service
[ROOT@MDB02 ~]# Service keepalived start
Redirecting To/bin/systemctl start Keepalived.service
Eight, view the network card information
IX. Verification Test
can refer to
1, on the main server to create a new page, content for 192.168.111.223
2, on the standby server to create a new Web page, content for 192.168.111.100
3, start the primary standby server HTTP service and keepalived service
4, by browsing number, enter the virtual IP address 192.168.111.150
page appears as 192.168.111.223
5. Turn off the keepalived service of the primary server and enter the IP address through the browser 192.168.111.150
page appears as 192.168.111.100
6. Start the keepalived service of the primary server again and enter the IP address through the browser 192.168.111.150
page appears as 192.168.111.223