热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

keepalived高可用lvs集群

主[root@zxw8sh]#vimetckeepalivedkeepalived.confvrrp_scriptcheck_httpd{#check_mysql是为执行脚本计划起


[root@zxw8 sh]# vim /etc/keepalived/keepalived.conf
vrrp_script check_httpd { #check_mysql是为执行脚本计划起的名字
script "/root/sh/httpd.sh" #指定要执行脚本的路径
interval 2 ##脚本执行间隔,每2s检测一次
}
vrrp_instance VI_1 { #角色类型
state MASTER MASTER|BACKUP
interface ens33 #网卡名称
virtual_router_id 88 #虚拟路由id(需要与BACKUP一致)
priority 100 #优先级
advert_int 1 #每1秒检查一次
nopreempt #非抢占模式
authentication {
auth_type PASS #认证类型 主备之间必须一样
auth_pass 8888 #认证密码 主备之间必须一样
}
virtual_ipaddress {
192.168.126.77/24 #虚拟ip(vip)
}
track_script {
check_httpd
}
}
virtual_server 192.168.126.77 80 {
delay_loop 3 #健康检查时间间隔
lb_algo rr #负载均衡调度算法
lb_kind DR #负载均衡转发规则
protocol TCP #负载均衡转发规则

real_server 192.168.126.6 80 { 要监控的real_server的ip和端口号
weight 1 #权重
TCP_CHECK { #基于tcp协议的检查
connect_timeout 3 #连接时间超时
retry 3 nb_get_retry 3 #重连次数
delay_before_retry 3 #重连间隔时间
}
}


real_server 192.168.126.4 80 {
weight 1
TCP_CHECK {
connect_timeout 3
retry 3 nb_get_retry 3
delay_before_retry 3
}
}
}


[root@zxw8 sh]# cat httpd.yaml
- hosts: zxw
remote_user: root
tasks:
- name: yum install net-tools -y
yum: name=net-tools state=latest
- name: ifconfig
command: ifconfig lo:0 192.168.126.77 broadcast 192.168.126.77 netmask 255.255.255.255 up
ignore_errors: yes
- name: route add -host 192.168.126.77 dev lo:0
command: route add -host 192.168.126.77 dev lo:0
ignore_errors: yes
- name: echo "1" > /proc/sys/net/ipv4/conf/all/arp_ignore
shell: echo "1" > /proc/sys/net/ipv4/conf/all/arp_ignore
- name: echo "2" > /proc/sys/net/ipv4/conf/all/arp_announce
shell: echo "2" > /proc/sys/net/ipv4/conf/all/arp_announce
- name: echo "1" > /proc/sys/net/ipv4/conf/lo/arp_ignore
shell: echo "1" > /proc/sys/net/ipv4/conf/lo/arp_ignore
- name: echo "2" > /proc/sys/net/ipv4/conf/lo/arp_announce
shell: echo "2" > /proc/sys/net/ipv4/conf/lo/arp_announce
[zxw]
192.168.126.6 ansible_ssh_user=root ansible_ssh_port=22 ansible_ssh_pass=123
#192.168.126.7 ansible_ssh_user=root ansible_ssh_port=22 ansible_ssh_pass=123
192.168.126.4 ansible_ssh_user=root ansible_ssh_port=22 ansible_ssh_pass=123

 

systemctl status httpd &> /dev/null
if [ $? -ne 0 ];then
systemctl stop keepalived
echo "跳转到备用"
else
echo "启动httpd"
fi

 


vrrp_instance VI_1 {
state BACKUP
interface ens33
virtual_router_id 88
priority 99
advert_int 1
authentication {
auth_type PASS
auth_pass 8888
}
virtual_ipaddress {
192.168.126.77/24
}
}
real_server 192.168.126.6 80 {
weight 1
TCP_CHECK {
connect_timeout 3
retry 3 nb_get_retry 3
delay_before_retry 3
}
}


real_server 192.168.126.4 80 {
weight 1
TCP_CHECK {
connect_timeout 3
retry 3 nb_get_retry 3
delay_before_retry 3
}
}
}

 

 


推荐阅读
author-avatar
手机用户2602936475
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有