一、硬件环境准备
kep1 192.168.89.100 master
kep2 192.168.89.101 slave
二、安装keepalived(两台服务器都要安装)
yum -y install keepalived
三、启动keepalived并检查
1、两台服务器上启动keep服务
[[email protected] ~]# /etc/init.d/keepalived start
正在启动 keepalived: [确定]
[[email protected] ~]# /etc/init.d/keepalived start
正在启动 keepalived: [确定]
2、两台服务器上检查进程(启动后会有3个进程,说明安装成功)
[[email protected] ~]# ps -ef | grep keep|grep -v grep
root 1286 1 0 05:40 ? 00:00:00 /usr/sbin/keepalived -D
root 1288 1286 0 05:40 ? 00:00:00 /usr/sbin/keepalived -D
root 1289 1286 0 05:40 ? 00:00:00 /usr/sbin/keepalived -D
3、一切正常后,两台服务器先关闭掉keep服务
[[email protected] ~]# /etc/init.d/keepalived stop
停止 keepalived: [确定]
四、keep配置文件路径,
如果是yum安装,那么这是默认的路径
[[email protected] ~]# ls -l /etc/keepalived/keepalived.conf
-rw-r--r--. 1 root root 3562 3月 19 2015 /etc/keepalived/keepalived.conf
五、配置文件说明(高可用相关参数)
1、全局定义(这部分主要设置keepalived的故障通知和RouerID标识)
! Configuration File for keepalived
global_defs {
notification_email { #配置邮件报警
[email protected] #收件人可以有多个
[email protected] #收件人
[email protected] #收件人
}
notification_email_from [email protected] #指定发送邮件的发件人
smtp_server 192.168.200.1 #SMTP服务器
smtp_connect_timeout 30 #连接SMTP服务器的超时时间
router_id LVS_DEVEL #服务器路由标识,在同一网络里是唯一的
}
2、VRRP实例定义区块
vrrp_instance VI_1 {
state MASTER #角色状态,要么是MASTER,要么是BACKUP
interface eth0 #对外提供服务的网络接口
virtual_router_id 51 #虚拟路由ID标识,主和备的配置中,相同的实例必须一致
priority 100 #优先级,主的优先级要比备的优先级高
advert_int 1 主备之间通信检查的时间间隔,单位为妙
authentication { #权限认证配置
auth_type PASS #认证类型
auth_pass 1111 #验证密码
}
virtual_ipaddress { #虚拟IP,可以有多个
192.168.200.16 #虚拟IP
192.168.200.17
192.168.200.18
}