方法一:yum方式
yum安装
安装依赖包
yum install -y curl gcc openssl-devel libnl3-devel net-snmp-devel
安装keepalived
yum install -y keepalived
初始化及启动
启动keepalived
start keepalived
加入开机启动keepalived
enable keepalived
重新启动keepalived
restart keepalived
查看keepalived状态
status keepalived
方法二、源码包
源码包解压安装
官网下载keepalived的最新版本,解压并安装。
wget http://www.keepalived.org/software/keepalived-2.2.2.tar.gz
tar xzvf keepalived-2.2.2.tar.gz
cd keepalived-2.2.2
./configure --prefix=/usr/local/keepalived
make && make install
初始化及启动
keepalived启动脚本变量引用文件,默认文件路径是/etc/sysconfig/,也可以不做软链接,直接修改启动脚本中文件路径即可(安装目录下)
cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/keepalived
将keepalived主程序加入到环境变量(安装目录下)
cp /usr/local/keepalived/sbin/keepalived /usr/sbin/keepalived
keepalived启动脚本(源码目录下),放到/etc/init.d/目录下就可以使用service命令便捷调用
cp /usr/local/src/keepalived-2.0.7/keepalived/etc/init.d/keepalived /etc/init.d/keepalived
将配置文件放到默认路径下
mkdir /etc/keepalived
cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf
- 加为系统服务:chkconfig –add keepalived
- 开机启动:chkconfig keepalived on
- 查看开机启动的服务:chkconfig –list
- 启动、关闭、重启service keepalived start|stop|restart