
原理:两台web服务器,通过心跳线进行通信,当主节点出现服务异常,备用节点通过探测判断主节点是否存活,若是不存活,就把服务接管过来。
Web1和Web2中间有一根心跳线,检查对方的存活状态。流动IP:也叫vip是对外提供服务的ip,正常情况下是配置在Web1上的,当Web1宕机后,Web2会自动配置该vip,对外提供服务。
需求:在线上环境有一台nginx服务器提供对外web访问,为了防止服务器突然宕机造成业务损失,则需要两台服务器提供高可用集群一主一备服务,主的服务器宕机,备的服务器立即接管主的继续对外提供访问,让业务不受影响。
实验环境所需要工具:heartbeat、libnet、nginx
默认是没有heartbeat包,需要安装扩展源:epel
epel下载地址:wget www.lishiming.net/data/attachment/forum/epel-release-6-8_32.noarch.rpm
安装工具:yum -y install heartbeat
安装工具:yum -y install libnet
master IP: 192.168.2.254
slave IP:192.168.2.253
一、master服务器配置
1:修改hosts文件
[root@master ~]# vim /etc/hosts
说明:将主和备份的服务器地址和主机写入hosts文件,将红色的字段复制到备份的文件
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.2.254 master
192.168.2.253 slave
2:切换到hearteat工具文件目录
[root@master ~]cd /usr/share/doc/heartbeat-3.0.4/
[root@master heartbeat-3.0.4]# ls
apphbd.cf authkeys AUTHORS ChangeLog COPYING COPYING.LGPL ha.cf haresources README
3:拷贝authkeys、ha.cf、haresources三个配置文件
[root@master heartbeat-3.0.4] cp authkeys ha.cf haresources /etc/ha.d/
[root@master heartbeat-3.0.4] cd /etc/ha.d/
4:编辑配置文件
[root@master ha.d ] vim authkeys
auth 3 ##这里定义的是你下面所开启的级别
#1 crc
#2 sha1 HI!
3 md5 Hello!
5:aurhkeys文件权限需要设置600
[root@master ha.d ] chmod 600 authkeys
6:配置虚接口和编辑vip的文件
[root@master ha.d]# cd /etc/sysconfig/network-scripts/
[root@master network-scripts]# cp ifcfg-eth0 ifcfg-eth0\:1
[root@master network-scripts]# vim ifcfg-eth0:1
加入下面的内容
DEVICE=eth0:1
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=192.168.2.110
NETMASK=255.255.255.0
7:重启网络服务
[root@master network-scripts]# service network restart
正在关闭接口 eth0: [确定]
关闭环回接口: [确定]
弹出环回接口: [确定]
弹出界面 eth0: Determining if ip address 192.168.2.254 is already in use for device eth0...
Determining if ip address 192.168.2.110 is already in use for device eth0...
[确定]
8:重启服务和编辑配置文件
[root@master network-scripts]# vim haresources
说明:
master ##表示是主的主机名
192.168.2.110/24 ##表示流动vip也就是虚接口地址
eth0:0 ##表示你所用的网卡
nginx ##表示你用什么服务做的集群,这里用的是Nginx,根据自己使用情况设置
加入下面内容
master 192.168.2.110/24/eth0:1 nginx
9:编辑ha.cf文件
[root@master ha.d]# vim ha.cf
debugfile /var/log/ha-debug
logfile /var/log/ha-log ##设置系统日志的信息范围为 local0
logfacility local0 ##这是日志的级别
keepalive 2 ##设置心跳的检测时间,默认单位为秒
deadtime 30 ##宣布节点死亡的时间,单位为秒
warntime 10 ##通过这个来调整判断节点的死亡时间
initdead 60 ##Heartbeat 启动资源的等待时间,单位为秒
udpport 694 ##设定用于bcast和ucast通信的端口,默认为 UDP 694
ucast eth0 192.168.2.253 ##心跳网卡和对方的ip地址
auto_failback on ##这个设定会使节点具备优先级。当服务运行于备机上时,如果主节点已恢复,会自动取回运行在备机上的服务。
node master ##设置主的主机名
node slave ##设置备份的主机名
ping 192.168.2.1 ##指定ping节点,检测网络状态,通常是网关
respawn hacluster /usr/lib/heartbeat/ipfail ##设定 Heartbeat 监控的服务,该服务会随着 Heartbeat 服务启动时启动,停止时则一起停止。当出现意外导致该服务停止时,Heartbeat 将自动重启该服务
10:复制三个配置文件到备份服务器
[root@master ha.d]# scp authkeys ha.cf haresources slave:/etc/ha.d/
The authenticity of host 'slave (192.168.2.253)' can't be established.
RSA key fingerprint is 74:0a:ee:44:ae:1a:9f:86:47:43:92:4b:c0:02:29:0b.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'slave,192.168.2.253' (RSA) to the list of known hosts.
root@slave's password:
authkeys 100% 643 0.6KB/s 00:00
ha.cf 100% 331 0.3KB/s 00:00
haresources 100% 5888 5.8KB/s 00:00
二、slave服务器配置
1:修改hosts文件
[root@slave ~]# vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.2.254 master
192.168.2.253 slave
2:在备份服务器slave里只需要编辑ha.cf配置文件,其它两个文件默认
[root@slave src]# cd /etc/ha.d/
[root@slave ha.d]# ls
authkeys ha.cf harc haresources rc.d README.config resource.d shellfuncs
[root@slave ha.d]# vim ha.cf
debugfile /var/log/ha-debug
logfile /var/log/ha-log
logfacility local0
keepalive 2
deadtime 30
warntime 10
initdead 60
udpport 694
ucast eth0 192.168.2.254 ##改成master的地址
auto_failback on
node master
node slave
ping 192.168.2.2
respawn hacluster /usr/lib/heartbeat/ipfail
三、启动heartbeat、测试结果
说明:在高可用集群中启动heartbeat是按照先启动主,再启动备份的顺序
1:启动master,关闭iptables和selinux
[root@master ha.d]# iptables -F
[root@master ha.d]# setenforce 0
[root@master ha.d]# /etc/init.d/heartbeat start
Starting High-Availability services: INFO: Resource is stopped
Done.
2:启动slave,关闭iptables和selinux
[root@slave ha.d]# iptables -F
[root@slave ha.d]# setenforce 0
[root@slave ha.d]# /etc/init.d/heartbeat start
Starting High-Availability services: INFO: Resource is stopped
Done.
3:测试,使master服务器不能ping通slave的服务器,让master死掉,slave的继承
更改下主页文件
[root@master ~]# echo "1111111111111111111master" > /usr/share/nginx/html/index.html
4:用curl测试
[root@master ~]# curl -x 127.0.0.1:80 192.168.2.110
1111111111111111111master
5:使用命令禁掉主Ping工具,让其死掉
[root@master ha.d]# iptables -A INPUT -p icmp -j DROP
6:在备份服务查看有没有虚接口过来
[root@slave ha.d]# ifconfig
eth0:1 Link encap:Ethernet HWaddr 00:0C:29:4D:F5:D8
inet addr:192.168.1.110 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
Interrupt:19 Base address:0x2000
7:curl访问测试
[root@slave ha.d]# curl -x127.0.0.1:80 192.168.2.110
222222222222slave
##备用的服务器成功继承,高可用集群实验成功
- Hadoop HA高可用集群搭建(Hadoop+Zookeeper+HBase)
声明:作者原创,转载注明出处. 作者:帅气陈吃苹果 一.服务器环境 主机名 IP 用户名 密码 安装目录 master188 192.168.29.188 hadoop hadoop /home/ha ...
- Hadoop 3.1.2(HA)+Zookeeper3.4.13+Hbase1.4.9(HA)+Hive2.3.4+Spark2.4.0(HA)高可用集群搭建
目录 目录 1.前言 1.1.什么是 Hadoop? 1.1.1.什么是 YARN? 1.2.什么是 Zookeeper? 1.3.什么是 Hbase? 1.4.什么是 Hive 1.5.什么是 Sp ...
- linux -- 基于zookeeper搭建yarn的HA高可用集群
linux -- 基于zookeeper搭建yarn的HA高可用集群 实现方式:配置yarn-site.xml配置文件 <configuration> <property> & ...
- centos HA高可用集群 heartbeat搭建 heartbeat测试 主上停止heartbeat服务 测试脑裂 两边都禁用ping仲裁 第三十二节课
centos HA高可用集群 heartbeat搭建 heartbeat测试 主上停止heartbeat服务 测试脑裂 两边都禁用ping仲裁 第三十二节课 heartbeat是Linu ...
- HA 高可用集群概述及其原理解析
HA 高可用集群概述及其原理解析 1. 概述 1)所谓HA(High Available),即高可用(7*24小时不中断服务). 2)实现高可用最关键的策略是消除单点故障.HA严格来说应该分成各个组件 ...
- 七、Hadoop3.3.1 HA 高可用集群QJM (基于Zookeeper,NameNode高可用+Yarn高可用)
目录 前文 Hadoop3.3.1 HA 高可用集群的搭建 QJM 的 NameNode HA Hadoop HA模式搭建(高可用) 1.集群规划 2.Zookeeper集群搭建: 3.修改Hadoo ...
- Kubeadm 1.9 HA 高可用集群本地离线镜像部署【已验证】
k8s介绍 k8s 发展速度很快,目前很多大的公司容器集群都基于该项目,如京东,腾讯,滴滴,瓜子二手车,易宝支付,北森等等. kubernetes1.9版本发布2017年12月15日,每三个月一个迭代 ...
- [K8s 1.9实践]Kubeadm 1.9 HA 高可用 集群 本地离线镜像部署
k8s介绍 k8s 发展速度很快,目前很多大的公司容器集群都基于该项目,如京东,腾讯,滴滴,瓜子二手车,北森等等. kubernetes1.9版本发布2017年12月15日,每是那三个月一个迭代, W ...
- Hadoop HA 高可用集群的搭建
hadoop部署服务器 系统 主机名 IP centos6.9 hadoop01 192.168.72.21 centos6.9 hadoop02 192.168.72.22 centos6.9 ha ...
- Hadoop HA高可用集群搭建(2.7.2)
1.集群规划: 主机名 IP 安装的软件 执行的进程 drguo1 192.168.80.149 j ...
随机推荐
- 在C\C++中char 、short 、int各占多少个字节
在C\C++中char .short .int各占多少个字节 : #include <bits/stdc++.h> using namespace std; int main() { co ...
- nyoj 455-黑色帽子
455-黑色帽子 内存限制:64MB 时间限制:1000ms 特判: No 通过数:4 提交数:7 难度:1 题目描述: 最近发现了一个搞笑的游戏,不过目前还没玩过.一个舞会上,每个人 ...
- nyoj 206-矩形的个数 (a*b*(a+1)*(b+1)/4)
206-矩形的个数 内存限制:64MB 时间限制:1000ms 特判: No 通过数:16 提交数:37 难度:1 题目描述: 在一个3*2的矩形中,可以找到6个1*1的矩形,4个2*1的矩形3个1* ...
- SpringBoot学习(三)—— springboot快速整合swagger文档
目录 MyBatis 简介 引入mybatis组件 代码实战 MyBatis @ 简介 优点 最大的优点是SQL语句灵活,适合调优情景,业务复杂情景 劣势 最大的劣势是不同数据库之间的迁移 引入myb ...
- Install gitlab
yum install -y curl policycoreutils-python openssh-server postfix wget wget https://mirrors.tuna.tsi ...
- scrapy下载中间件结合selenium抓取全国空气质量检测数据
1.所需知识补充 1.下载中间件常用函数 process_request(self, request, spider): 当每个request通过下载中间件是,该方法被调用 process_reque ...
- SpringBoot学习(七)—— springboot快速整合Redis
目录 Redis缓存 简介 引入redis缓存 代码实战 Redis缓存 @ 简介 redis是一个高性能的key-value数据库 优势 性能强,适合高度的读写操作(读的速度是110000次/s,写 ...
- poj 2991 起重机
地址 http://poj.org/problem?id=2991 题解 本来以为这是一个简单的线段树模板 不料始终不太明白线段树如何记录转动角度后的各个线段端的XY值 学习了网络上的一些博客题解 感 ...
- 【RN - 基础】之View使用简介
简介 View是一个容器,支持FlexBox布局. View既可以作为容器容纳其他组件,也可以作为一个组件包含进另一个容器中. 无论运行在哪个平台上,View都会直接对应这个平台的原生视图,如iOS中 ...
- 行内元素(inline标签)设置了行高为什么不生效,还是表现为父盒子的行高?行内元素行高问题终极解释
最近在看张鑫旭大佬的<css世界>,读到5.2.4 内联元素 line-height 的“大值特性” ,产生了疑惑, 在开发中确实也遇到了同样的问题,深入探究后得出结果,先说结论吧,论证 ...