ip划分:
RS1:192.168.223.135
RS2:192.168.223.137
节点node1和node2的keepalived(node1:192.168.223.136,node2:192.168.223.128)
1、首先设置RS
[root@wadeson ~]# cat set_arp_args.sh
#!/bin/bash
case "$1" in
start)
echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore
echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce
ifconfig lo:0 192.168.223.100/32 broadcast 192.168.223.100 up
route add -host 192.168.223.100 dev lo:0
;;
stop)
echo 0 > /proc/sys/net/ipv4/conf/all/arp_ignore
echo 0 > /proc/sys/net/ipv4/conf/lo/arp_ignore
echo 0 > /proc/sys/net/ipv4/conf/all/arp_announce
echo 0 > /proc/sys/net/ipv4/conf/lo/arp_announce
;;
esac
2、设置节点node1和node2的keepalived(node1:192.168.223.136,node2:192.168.223.128)
node1设置:
[root@node1 ~]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
json_hc@163.com
}
notification_email_from json_hc@163.com
smtp_server smtp.163.com
smtp_connect_timeout 30
router_id node1
}
vrrp_script chk_keepalived_down {
script "[[ -f /etc/keepalived/down ]] && exit 1 || exit 0"
interval 1
weight -2
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass password
}
virtual_ipaddress {
192.168.223.100/24 dev eth0 label eth0:0
}
notify_master "/etc/keepalived/notify.sh master"
notify_backup "/etc/keepalived/notify.sh backup"
notify_fault "/etc/keepalived/notify.sh fault"
track_script {
chk_keepalived_down
}
}
virtual_server 192.168.223.100 80 {
delay_loop 6
lb_algo rr
lb_kind DR
nat_mask 255.255.255.0
#persistence_timeout 50
protocol TCP
real_server 192.168.223.135 80 {
weight 1
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 192.168.223.137 80 {
weight 1
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
node2设置:
[root@node2 ~]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
json_hc@163.com
}
notification_email_from json_hc@163.com
smtp_server smtp.163.com
smtp_connect_timeout 30
router_id node2
}
vrrp_script chk_keepalived_down {
script "[[ -f /etc/keepalived/down ]] && exit 1 || exit 0"
interval 1
weight -2
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 51
priority 99
advert_int 1
authentication {
auth_type PASS
auth_pass password
}
virtual_ipaddress {
192.168.223.100/24 dev eth0 label eth0:0
}
notify_master "/etc/keepalived/notify.sh master"
notify_backup "/etc/keepalived/notify.sh backup"
notify_fault "/etc/keepalived/notify.sh fault"
track_script {
chk_keepalived_down
}
}
virtual_server 192.168.223.100 80 {
delay_loop 6
lb_algo rr
lb_kind DR
nat_mask 255.255.255.0
#persistence_timeout 50
protocol TCP
real_server 192.168.223.135 80 {
weight 1
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 192.168.223.137 80 {
weight 1
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
然后测试网页:由于现在vip在node1上面,需要在node2上面访问
[root@node2 ~]# curl http://192.168.223.100
<h1>test 192.168.223.135 centos7</h1>
[root@node2 ~]# curl http://192.168.223.100
<h1>test 192.168.223.137 html</h1>
[root@node2 ~]# curl http://192.168.223.100
<h1>test 192.168.223.135 centos7</h1>
[root@node2 ~]# curl http://192.168.223.100
<h1>test 192.168.223.137 html</h1>
[root@node2 ~]# curl http://192.168.223.100
<h1>test 192.168.223.135 centos7</h1>
[root@node2 ~]# curl http://192.168.223.100
<h1>test 192.168.223.137 html</h1>
现在在node1上面创建down,使vip漂移到node2节点上:
[root@node1 keepalived]# touch down
观察日志信息可以看见vip已经飘到node2节点上了,而且我的163邮件已经收到了邮件
现在测试curl http://192.168.223.100只能在node1节点上测试
[root@node1 ~]# curl http://192.168.223.100
<h1>test 192.168.223.135 centos7</h1>
[root@node1 ~]# curl http://192.168.223.100
<h1>test 192.168.223.137 html</h1>
[root@node1 ~]# curl http://192.168.223.100
<h1>test 192.168.223.135 centos7</h1>
[root@node1 ~]# curl http://192.168.223.100
<h1>test 192.168.223.137 html</h1>
notify.sh脚本通知到邮箱:
[root@node1 keepalived]# cat notify.sh
#!/bin/bash
send_mail="json_hc@163.com"
HOSTNAME=$(hostname)
notify() {
mail_subject="$HOSTNAME to be $1:vip floating"
mail_body="$(date +'%Y-%m-%d %H:%M:%S'):vrrp transaction change to be $1"
echo ${mail_body}|mail -s "${mail_subject}" ${send_mail}
}
case "$1" in
master)
notify master
exit 0
;;
backup)
notify backup
exit 0
;;
fault)
notify fault
exit 0
;;
*)
echo "Usage:$(basename $0) {master|backup|fault}"
exit 1
;;
esac
现在将RS其中的某一台宕掉:
[root@wadeson script]# /usr/local/apache2.4/bin/apachectl stop
测试:
[root@node1 keepalived]# curl http://192.168.223.100
<h1>test 192.168.223.135 centos7</h1>
[root@node1 keepalived]# curl http://192.168.223.100
<h1>test 192.168.223.135 centos7</h1>
[root@node1 keepalived]# curl http://192.168.223.100
<h1>test 192.168.223.135 centos7</h1>
[root@node1 keepalived]# curl http://192.168.223.100
<h1>test 192.168.223.135 centos7</h1>
[root@node1 keepalived]# curl http://192.168.223.100
<h1>test 192.168.223.135 centos7</h1>
然后将该宕掉的RS恢复:可能需要稍等一下
[root@node1 keepalived]# curl http://192.168.223.100
<h1>test 192.168.223.137 html</h1>
[root@node1 keepalived]# curl http://192.168.223.100
<h1>test 192.168.223.135 centos7</h1>
[root@node1 keepalived]# curl http://192.168.223.100
<h1>test 192.168.223.137 html</h1>
[root@node1 keepalived]# curl http://192.168.223.100
<h1>test 192.168.223.135 centos7</h1>
[root@node1 keepalived]# curl http://192.168.223.100
<h1>test 192.168.223.137 html</h1>
当然如果后端的RS都宕机了那么可以设置keepalived自身具有web服务提供一个友好的页面提示:
配置操作如下:
virtual_server 192.168.223.100 80 {
delay_loop 6
lb_algo rr
lb_kind DR
nat_mask 255.255.255.0
#persistence_timeout 50
protocol TCP
只需在这后面加上:
sorry_server 127.0.0.1 80(两台keepalived节点都给加上)
那么RS都宕机后,本机会提供一个友好的web页面
除了HTTP_CHECK还可以TCP_CHECK:
TCP_CHECK {
connect_timeout 3
}
- MySQL HA方案之MySQL半复制+MHA+Keepalived+Atlas+LVS[转]
MySQL HA方案之MySQL半复制+MHA+Keepalived+Atlas+LVS 简介 目前Mysql高可用的方案有好多,比如MMM,heartbeat+drbd,Cluster等,还有per ...
- 实战--Keepalived和LVS实现负载高可用
显然,只有上一篇的操作,在WEB运维技术中,只能承担一半的角色. 想像一下,如何LVS本身倒了,肿么办?后端的NGINX再多,也只能是干着急,请求过来不呀! 所以,在本篇时,我们来实现LVS永不倒, ...
- 基于Keepalived实现LVS双主高可用集群
Reference: https://mp.weixin.qq.com/s?src=3×tamp=1512896424&ver=1&signature=L1C7us ...
- Linux-利用keepalived实现lvs的高可用性
单主模型IPVS示例 配置keepalive 高可用的ipvs集群示例:修改keepalived配置文件 修改主机:192.168.234.27的keepalived配置文件 [root@234c27 ...
- 使用Keepalived构建LVS高可用集群
LVS的DR模型配置+Keepalive部署 介绍 下图为DR模型的通信过程,图中的IP不要被扑结构中的IP迷惑,图里只是为了说明DR的通信原理,应用到本例中的拓扑上其工作原理不变. 拓扑结构 服务器 ...
- keepalived给LVS带来了什么
LVS+Keepalived 1>Keepalived简介 Keepalived是Linux下一个轻量级别的高可用解决方案,高可用(High Avalilability,HA),其实两种不同的 ...
- 003.Keepalived搭建LVS高可用集群
一 基础环境 1.1 IP规划 OS:CentOS 6.8 64位 节点类型 IP规划 主机名 类型 主 Director Server eth0:172.24.8.10 DR1 公共IP eth1: ...
- keepalived heartbeat lvs haproxy
一, keeplived @ 01,keeplived 是什么? Keepalived起初是为LVS设计的,专门用来监控集群系统中各个服务节点的状态,它根据TCP/IP参考模型的第三.第四层.第五层交 ...
- Linux keepalived与lvs的深入分析
一)概述 在本篇文章里,我们会涉及两部份内容,一个是LVS,另一个则是keepalived. 即我们用LVS和keepalived实现了负载均衡及高可用的服务器. LVS有实现三种IP负载均衡技术 ...
- [LVS] 用keepalived实现LVS NAT模式高可用性
默认前提是LVS已经可以正常工作了. 因为是NAT模式,RS的路由要指向LVS的接口地址,所以需要一个统一的后台浮动地址,使得RS都指向这个浮动IP.否则在切换时,会导致RS回包到DOWN掉的LVS上 ...
随机推荐
- node.js创建server服务---sublime 的node及typescript环境配置
一.初始环境搭建 mkdir server //创建server文件夹 cd server //进入到创建的文件夹目录下 npm init -y //生成含有默认配置的package.json文件 n ...
- 修改 GitHub 仓库默认显示的项目语言类型
GitHub 是采用 Linguist 来自动识别仓库代码应该归为哪一类的,也就是根据项目里文件数目最多的文件类型来识别项目类型. 解决办法是:在仓库的根目录下创建或修改 .gitattributes ...
- jquery的强大选择器
$("#myELement") 选择id值等于myElement的元素,id值不能重复在文档中只能有一个id值是myElement所以得到的是唯一的元素 $("di ...
- Java实现断点续传
原理: 断点续传的关键是断点,所以在制定传输协议的时候要设计好,如上图,我自定义了一个交互协议,每次下载请求都会带上下载的起始点,这样就可以支持从断点下载了,其实HTTP里的断点续传也是这个原理,在H ...
- 剑指Offer——整数中1出现的次数(从1到n整数中1出现的次数)
题目描述: 求出1~13的整数中1出现的次数,并算出100~1300的整数中1出现的次数?为此他特别数了一下1~13中包含1的数字有1.10.11.12.13因此共出现6次,但是对于后面问题他就没辙了 ...
- Aggregated Counting-----hdu5439(2015 长春网络赛 找规律)
#include<stdio.h> #include<string.h> #include<iostream> #include<math.h> #in ...
- Fibonacci----poj3070(矩阵快速幂, 模板)
题目链接:http://poj.org/problem?id=3070 . 就是斐波那契的另一种表示方法是矩阵的幂: 所以是矩阵快速幂:矩阵快速幂学习 #include <cstdio> ...
- 创建正真的Java不可变类
如果需要设计一个不可变类,尤其要注意其引用类型Field,如果其引用类型Field的类是可变的,就必须采取必要的措施来保护该Field所引用的对象不会被修改,这样才能创建真正的不可变类. class ...
- 存储库之——MongoDB
阅读目录 一 简介 二 MongoDB基础知识 三 安装 四 基本数据类型 五 CRUD操作 六 可视化工具 七 pymongo 一 简介 MongoDB是一款强大.灵活.且易于扩展的通用型数据库1. ...
- php 单线程 (http://bbs.csdn.net/topics/390778072)
以前想php单线程,网站肯定是用于多人访问的,如果访问量大,那岂不是出现排队问题? apache+php是阻塞型处理,nginx+php是异步非阻塞的,php有进程管理器,fpm fcgi什么的.ph ...