1、下载
自行去Keepalived官网进行下载,也可以通过如下链接进行下载
wget https://link.zhihu.com/?target=https%3A//www.keepalived.org/software/keepalived-1.3.4.tar.gz
2、安装
这里可能有些小伙伴的环境需要安装一些依赖包,不然会造成一些安装失败的问题;
yum -y install libnl libnl-devel libnfnetlink-devel
yum -y install ipvsadm
yum -y install popt-devel
yum -y install openssl-devel
若你的环境已安装,请忽略!
解压:
tar -zxvf keepalived-1.3.4.tar.gz
进入解压之后的Keepalived目录之下,有一个configure的文件,这是keepalived的配置文件
cd keepalived-1.3.4
配置keepalived,使用如下命令:
./configure --prefix=/usr/local/keepalived --sysconf=/etc
--prefix :keepalived安装目录
--sysconf :keepalived的核心配置文件,必须要在 /etc 目录下面,固定位置,改为其他
位置会导致启动不了不在该目录下的话,会在启动keepalived的时候,会在
日志文件里面抱一个错误,说找不到/etc这个文件夹。
随后会得到一个keepalived的文件夹
编译和安装keepalived
make && make install
使用如下命令可查看keepalived安装在那儿
whereis keepalived
会得到两个目录, /etc/keepalived /usr/local/keepalived
/usr/local/keepalived :是之前指定的安装目录位置
安装目录和nginx的一样,启动keepalived的话就进入sbin目录之下,然后
./keepalived
/etc/keepalived :是keepalived的核心配置文件所在位置
这里面的keepalived.conf 就是核心配置文件
3、配置(KeepAlived.conf)
进入核心配置文件之下
cd /etc/keepalived
vi keepalived.conf 配置内容如下
4、测试
启动keepalived,查看机器ip地址,可发现多出一个244.200的ip
此时,若您的机器上装有nginx的话,使用原机器ip地址 和 新配置的新的虚拟ip地址244.200也能打开
发现两个打开的页面是一样的
到此keepalived就安装配置成功了。
keepalived从机配置
从机配置与主机过程完全一样,配置文件内以下标识id与优先级稍作变化即可
服务的管理:
重启keepalived服务:
systemctl restart keepalived
停止keepalived服务:
systemctl stop keepalived
如果机器重启之后keepalived没有启动的话,可以安装如下设置Keepalived开机自启动
chkconfig --add keepalived
chkconfig keepalived on
注意:
添加时,必须保证/etc/init.d/keepalived存在
查看系统服务
chkconfig list