keepalived源码包下载地址:Keepalived for Linux
下载完之后传到服务器上
检查安装环境
yum install curl gcc openssl-devel libnl3-devel net-snmp-devel libnfnetlink-devel -y
进入源码包目录
解压
tar xf keepalived-2.1.5.tar.gz
cd keepalived-2.1.5
编译
./configure --prefix=/usr/local/keepalived --sysconf=/etc
安装
make && make install
配置
主备节点分别修改配置
vi /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
ops@wangshibo.cn
tech@wangshibo.cn
}
notification_email_from ops@wangshibo.cn
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id MASTER-HA
}
vrrp_instance VI_1 {
state MASTER # MASTER为主实例,BACKUP 为从实例
interface ens33 # 网卡名称
virtual_router_id 51 # 主备这里要配置为同样的
priority 100 # 优先级,主要高于备. 一般主配置为100 备配置为80
advert_int 1
authentication {
auth_type PASS # 主备必须配置成同样的
auth_pass 1111 # 主备必须配置成同样的
}
virtual_ipaddress {
192.168.6.100 # vip主备必须配置一样
}
}
启动服务
systemctl restart keepalived
查看IP
ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
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 group default qlen 1000
link/ether 00:0c:29:8c:ce:78 brd ff:ff:ff:ff:ff:ff
inet 192.168.230.102/24 brd 192.168.230.255 scope global noprefixroute ens33
valid_lft forever preferred_lft forever
inet 192.168.230.104/32 scope global ens33
valid_lft forever preferred_lft forever
inet6 fe80::6989:66c5:4e66:4eb5/64 scope link noprefixroute
valid_lft forever preferred_lft forever
|