安装依赖:
yum install popt-devel
安装keepalived
软件下载地址:
链接:https://pan.baidu.com/s/1_Nw7ypOozezxI3SKO45aMw
提取码:9qp1
cd /usr/local/src
tar zxvf keepalived-1.1.15.tar.gz
cd keepalived-1.1.15
./configure --prefix=/usr/local/keepalived
make
make install
配置启动方式
cp keepalived/etc/init.d/keepalived.rh.init /etc/init.d/keepalived
chmod +x /etc/init.d/keepalived
cp keepalived/etc/init.d/keepalived.sysconfig /etc/sysconfig/keepalived
chkconfig --add keepalived
chkconfig --level 345 keepalived on
cp /usr/local/keepalived/sbin/keepalived /bin/
创建配置文件
mkdir /etc/keepalived
vim /etc/keepalived/keepalived.conf
主服务器添入以下内容:
- ! Configuration File for keepalived
-
- #global_defs {
- # notification_email {
- # xxxxxx@sina.com #设置报警邮件地址,可以设置多个,每行一个。需要开启sendmail服务。
- # }
- # notification_email_from keepalived@localhost #设置邮件的发送地址
- # smtp_server 127.0.0.1 #设置SMTP Server地址
- # smtp_connect_timeout 30 #设置SMTP Server的超时时间
- # router_id LVS_DEVEL #表示运行Keepalived服务器的一个标识。发邮件时显示大邮件主题中的信息
- #}
-
- vrrp_instance VI_1 {
- state MASTER --> 主服务器,从服务器为(BACKUP)
- interface eth0
- mcast_src_ip 192.168.2.103 --》 本机的IP地址
- virtual_router_id 51
- priority 100 --> 优先级要高于从服务器
- advert_int 1
- authentication {
- auth_type PASS
- auth_pass 1111
- }
- virtual_ipaddress {
- 192.168.2.119 --》 虚拟的IP地址,可以写多个
- #....
- }
- }
从服务器上也要装配置文件如下:
- ! Configuration File for keepalived
-
- vrrp_instance VI_1 {
- state BACKUP --> 从服务器
- interface eth0
- mcast_src_ip 192.168.2.104 --》 本机的IP地址
- virtual_router_id 51
- priority 90 --> 优先级要低于主服务器
- advert_int 1
- authentication {
- auth_type PASS
- auth_pass 1111
- }
- virtual_ipaddress {
- 192.168.2.119 --》 虚拟的IP地址,可以写多个
- #....
- }
- }
启动
service keepalived start
一条评论
文章写得很好,拜访站长、支持站长!