一、下载Keepalive
官网下载keepalive,https://www.keepalived.org/download.html ,我这里下载的是1.3.5版本
二、将master包上传到 各个master服务器上
解压文件:tar -zxvf keepalived-1.3.5.tar.gz
进入文件夹 keepalived-1.3.5 , 执行./configure
出现如下界面:
缺少编译器,安装gcc
yum install gcc-c++
yum install openssl openssl-devel
./configure
最后进行编译安装
make && make install
三、修改配置文件
进入keepalive配置文件夹
cd /usr/local/etc/keepalived
修改keepalived.conf
主master配置文件如下
! Configuration File for keepalived
global_defs {
router_id LVS_MASETR
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.40.300/24
}
}
备份配置 文件如下:
global_defs {
router_id LVS_SLAVE
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.40.300/24
}
}
192.168.40.197是我们自己虚构的一个ip
进入到 usr/local/sbin 目录下,可以看到 keepalived 启动文件
执行命令启动keepalive : ./keepalived -D -f /usr/local/etc/keepalived/keepalived.conf
ip -a 查看 启动情况
主节点除了绑定了自己的ip200外,还绑定了197
从节点目前只绑定了自己的ip
使用sqlyog,使用我们虚拟的ip,登录mysql,登录成功,关掉主master,还能登录成功,则keepalive配置成功