卸载
查找安装目录
[root@CentOS-003 keepalived]# find / -name keepalived
删除安装目录
rm -rf /etc/sysconfig/keepalived
rm -rf /etc/keepalived
rm -rf /var/lib/selinux/targeted/active/modules/100/keepalived
rm -rf /usr/sbin/keepalived
rm -rf /usr/share/doc/keepalived
rm -rf /usr/share/selinux/targeted/default/active/modules/100/keepalived
rm -rf /usr/libexec/keepalived
查看进程
[root@CentOS-001 /]# ps aux|grep keepalived
1.下载安装包
2.上次解压
[root@CentOS-001 /]# cd /opt/
[root@CentOS-001 opt]# tar xvf keepalived-2.0.20.tar.gz
3.安装
[root@CentOS-003 opt]# cd keepalived-2.0.20/
[root@CentOS-003 keepalived-2.0.20]# ./configure --prefix=/usr/local/keepalived
[root@CentOS-003 keepalived-2.0.20]# make & make install
4.修改配置
# keepalived 启动脚本变量引用文件,默认文件路径是 /etc/sysconfig/,也可以不做软链接,直接修改启动脚本中文件路径即可(安装目录下)
[root@CentOS-001 keepalived-2.0.20]# cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/keepalived
# 将keepalived 主程序加入到环境变量(安装目录下)
[root@CentOS-001 keepalived-2.0.20]# cp /usr/local/keepalived/sbin/keepalived /usr/sbin/keepalived
# keepalived 启动脚本(源码目录下),放到 /etc/init.d/ 目录下就可以使用 service 命令便捷调用
[root@CentOS-001 keepalived-2.0.20]# cp /opt/keepalived-2.0.20/keepalived/etc/init.d/keepalived /etc/init.d/keepalived
# 将配置文件放到默认路径下
[root@CentOS-001 keepalived-2.0.20]# mkdir /etc/keepalived
[root@CentOS-001 keepalived-2.0.20]# cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf
5.启动
[root@CentOS-001 keepalived-2.0.20]# service keepalived start
6.日志位置
[root@CentOS-001 log]# tail -f /var/log/messages
- 加为系统服务:chkconfig –add keepalived
- 开机启动:chkconfig keepalived on
- 查看开机启动的服务:chkconfig –list
- 启动、关闭、重启 service keepalived start|stop|restart
ip a show |grep -w inet
主从配置
配置文件位置
/etc/keepalived
主
! Configuration File for keepalived
global_defs {
notification_email {
acassen@firewall.loc
failover@firewall.loc
sysadmin@firewall.loc
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id LVS_DEVEL
vrrp_skip_check_adv_addr
vrrp_garp_interval 0
vrrp_gna_interval 0
}
#vrrp_script checkhaproxy
#{
# script "/etc/keepalived/do_sth.sh"
# interval 5
#}
vrrp_instance VI_1 {
state MASTER #设置ECS1实例为主实例
interface eth0 #设置网卡名,本示例配置为eth0
virtual_router_id 51
nopreempt
# preempt_delay 10
priority 100 #设置优先级,数字越大,优先级越高,本示例配置主用实例优先级为100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
unicast_src_ip 172.23.27.241 #设置ECS实例的私网IP地址,本示例配置为192.168.0.209
unicast_peer {
172.23.27.240 #对端ECS实例的私网IP地址,本示例配置为192.168.0.210
}
virtual_ipaddress {
120.55.71.172
172.23.27.242 #设置HaVip的IP地址,本示例配置为192.168.0.88
}
notify_master "/etc/keepalived/notify_action.sh MASTER"
notify_backup "/etc/keepalived/notify_action.sh BACKUP"
notify_fault "/etc/keepalived/notify_action.sh FAULT"
notify_stop "/etc/keepalived/notify_action.sh STOP"
garp_master_delay 1
garp_master_refresh 5
track_interface {
eth0 #设置ECS实例网卡名,本示例配置为eth0
}
# track_script {
# checkhaproxy
# }
}
从
! Configuration File for keepalived
global_defs {
notification_email {
acassen@firewall.loc
failover@firewall.loc
sysadmin@firewall.loc
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id LVS_DEVEL
vrrp_skip_check_adv_addr
vrrp_garp_interval 0
vrrp_gna_interval 0
}
#vrrp_script checkhaproxy
#{
# script "/etc/keepalived/do_sth.sh"
# interval 5
#}
vrrp_instance VI_1 {
state BACKUP #设置ECS2实例为备用实例
interface eth0 #设置网卡名,本示例配置为eth0
virtual_router_id 51
nopreempt
# preempt_delay 10
priority 10 #设置优先级,数字越大,优先级越高,本示例配置备用实例优先级为10
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
unicast_src_ip 172.23.27.240 #设置ECS实例的私网IP地址,本示例配置为192.168.0.210
unicast_peer {
172.23.27.241 #对端ECS实例的私网IP地址,本示例配置为192.168.0.209
}
virtual_ipaddress {
120.55.71.172
172.23.27.242 #设置HaVip的IP地址,本示例配置为192.168.0.88
}
notify_master "/etc/keepalived/notify_action.sh MASTER"
notify_backup "/etc/keepalived/notify_action.sh BACKUP"
notify_fault "/etc/keepalived/notify_action.sh FAULT"
notify_stop "/etc/keepalived/notify_action.sh STOP"
garp_master_delay 1
garp_master_refresh 5
track_interface {
eth0 #设置ECS实例网卡名,本示例配置为eth0
}
# track_script {
# checkhaproxy
# }
}