keepalive安装文档

[复制链接]
wangzuopu 发表于 2019-1-30 23:03:00 | 显示全部楼层 |阅读模式
本次安装均使用root用户
一、安装环境
yum -y install kernel-devel*
yum -y install openssl-*
yum -y install popt-devel
二、安装keepalived
1.解压缩keepalived-1.2.2.tar.gz并重命名为keepalived
cd keepalived
./configure --prefix=/usr/local/keepalived -enable-lvs-syncd --enable-lvs --with-kernel-dir=/lib/modules/2.6.32-431.el6.x86_64/build
make
make install
ln -s /usr/src/kernels/2.6.32-431.5.1.el6.x86_64/ /usr/src/linux
cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
mkdir -p /etc/keepalived
cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
ln -s /usr/local/keepalived/sbin/keepalived /sbin/

2.加入开机启动:chkconfig keepalived on

3.vi /etc/keepalived/keepalived.conf

MASTER:
BACKUP:


详解:
===================================================================
! Configuration File for keepalived
global_defs {
# notification_email { ##指定keepalived在发生切换时需要发送email到的对象,一行一个
# aaaa@aaaa.com.cn
# }
# notification_email_from aaaa@aaaa.com.cn #指定发件人
# smtp_server 127.0.0.1#指定smtp服务器地址
# smtp_connect_timeout 30 #指定smtp连接超时时间
router_id LVS_DEVEL#运行keepalived机器的一个标识
}
vrrp_instance VI_1 {
state MASTER ##指定那个为master,那个为backup,如果设置了nopreempt这个值不起作用,主备考priority决
interface em1 #设置实例绑定的网卡
virtual_router_id 51 #同一实例下virtual_router_id必须相同
priority 100 #定义优先级,数字越大,优先级越高,备机要小于主
advert_int 1 #MASTER与BACKUP负载均衡器之间同步检查的时间间隔,单位是秒
#nopreempt #设置为不抢占,从启动后主不会自动切换回来, 注:这个配置只能设置在backup主机上,而且这个主机优先级要比另外一台高
authentication {#设置认证
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {#设置vip
192.168.56.70 ####虚拟IP
}
}
virtual_server 192.168.56.70 8080 {
delay_loop 6 #健康检查时间间隔
lb_algo rr #lvs调度算法rr|wrr|lc|wlc|lblc|sh|dh
lb_kind DR #负载均衡转发规则NAT|DR|RUN
persistence_timeout 5 #会话保持时间
protocol TCP #使用的协议
persistence_granularity <NETMASK> #lvs会话保持粒度
virtualhost <string> #检查的web服务器的虚拟主机(host:头)
sorry_server<IPADDR> <port> #备用机,所有realserver失效后启用
real_server 192.168.56.97 8080 {
weight 1 #默认为1,0为失效
inhibit_on_failure #在服务器健康检查失效时,将其设为0,而不是直接从ipvs中删除
notify_up <string> | <quoted-string> #在检测到server up后执行脚本
notify_down <string> | <quoted-string> #在检测到server down后执行脚本

TCP_CHECK {
connect_timeout 3 #连接超时时间
nb_get_retry 3 #重连次数
delay_before_retry 3 #重连间隔时间
connect_port 23 健康检查的端口的端口
bindto <ip>
}
HTTP_GET | SSL_GET{
url{ #检查url,可以指定多个
path /
digest <string> #检查后的摘要信息
status_code 200 #检查的返回状态码
}
connect_port <port>
bindto <IPADD>
connect_timeout 5
nb_get_retry 3
delay_before_retry 2
}

SMTP_CHECK{
host{
connect_ip <IP ADDRESS>
connect_port <port> #默认检查25端口
bindto <IP ADDRESS>
}
connect_timeout 5
retry 3
delay_before_retry 2
helo_name <string> | <quoted-string> #smtp helo请求命令参数,可选
}
MISC_CHECK{
misc_path <string> | <quoted-string> #外部脚本路径
misc_timeout #脚本执行超时时间
misc_dynamic #如设置该项,则退出状态码会用来动态调整服务器的权重,返回0 正常,不修改;返回1,

检查失败,权重改为0;返回2-255,正常,权重设置为:返回状态码-2
}
}

============================================================================






5、两台机器启动keepalived:
service keepalived start

三、验证
ip a

【智云杂货铺 bbs.0936sht.com】
回复 论坛版权

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则