【HA】Heartbeat高可用集群配置

简介:

            主:hh.huangmingming.cn 192.168.1.31

            从:yo.huangmingming.cn 192.168.1.250

        主和从hosts文件配置:

        192.168.1.31 hh hh.huangmingming.cn

        192.168.1.250 yo yo.huangmingming.cn

一、安装epel扩展源

[root@yo ~]# wget http://mirrors.sohu.com/fedora-epel/6/i386/epel-release-6-8.noarch.rpm

[root@hh ~]# yum list |grep heartbeat

heartbeat.x86_64                            3.0.4-2.el6                  epel   

heartbeat-devel.i686                        3.0.4-2.el6                  epel   

heartbeat-devel.x86_64                      3.0.4-2.el6                  epel   

heartbeat-libs.i686                         3.0.4-2.el6                  epel   

heartbeat-libs.x86_64                       3.0.4-2.el6                  epel 

二、安装heartbeat、libnet(主从都需要安装)

[root@hh ~]# yum -y install heartbeat

[root@hh ~]# yum -y install libnet

[root@hh ~]# yum -y install nginx  (安装nginx做测试)


三、配置heartbeat(在主上配置)

1、拷贝配置文件authkeys、ha.cf、haresources到目录/etc/ha.d/下

[root@hh ~]# cd /usr/share/doc/heartbeat-3.0.4/

[root@hh heartbeat-3.0.4]# ls

apphbd.cf  authkeys  AUTHORS  ChangeLog  COPYING  COPYING.LGPL  ha.cf  haresources  README

[root@hh heartbeat-3.0.4]# cp authkeys ha.cf haresources /etc/ha.d/


2、配置authkeys文件

[root@hh ~]# cd /etc/ha.d/

[root@hh ha.d]# vim authkeys 

auth 3

#1 crc

#2 sha1 HI!

3 md5 Hello!

[root@hh ha.d]# chmod 600 authkeys   (authkeys文件的权限要注意改成600)


3、配置haresources文件

[root@hh ha.d]# vim haresources 

hh.huangmingming.cn     192.168.1.13/24/eth0:0 nginx  (指定集群IP)


4、配置ha.cf文件

[root@hh 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.1.250

auto_failback on

node hh.huangmingming.cn

node yo.huangmingming.cn

ping 192.168.1.1

respawn hacluster /usr/lib64/heartbeat/ipfail


5、把这三个文件发送到yo(从机器上)

[root@hh ha.d]# scp authkeys haresources ha.cf yo:/etc/ha.d/


6、启动heartbeat服务,先主后从

[root@hh ha.d]# /etc/init.d/heartbeat start

Starting High-Availability services: INFO:  Resource is stopped

Done.


四、启动产生的错误

1、<--respawn hacluster /usr/lib64/heartbeat/ipfail (注意当前系统是64位还是32位的否则会产生以下错误)--/>

[root@hh ha.d]# /etc/init.d/heartbeat start

heartbeat: udpport setting must precede media statementsheartbeat[4227]: 2016/01/01_05:04:26 ERROR: Client child command [/usr/lib/heartbeat/ipfail] is not executable

heartbeat[4227]: 2016/01/01_05:04:26 ERROR: Heartbeat not started: configuration error.

heartbeat[4227]: 2016/01/01_05:04:26 ERROR: Configuration error, heartbeat not started.


2、<--以下两个错误都是因为主机名配置不对造成的,在heartbeat配置中指定主机名的地方要与当前主机名对应,否则启不来--/>

[root@hh ha.d]# /etc/init.d/heartbeat start

heartbeat: udpport setting must precede media statementsheartbeat: baudrate setting must precede media statementsheartbeat[28195]: 2015/10/29_21:31:14 info: Pacemaker support: false

heartbeat[28195]: 2015/10/29_21:31:14 ERROR: Current node [hh.huangmingming.com] not in configuration!

heartbeat[28195]: 2015/10/29_21:31:14 info: By default, cluster nodes are named by `uname -n` and must be declared with a 'node' directive in the ha.cf file.

heartbeat[28195]: 2015/10/29_21:31:14 info: See also: http://linux-ha.org/wiki/Ha.cf#node_directive

heartbeat[28195]: 2015/10/29_21:31:14 WARN: Logging daemon is disabled --enabling logging daemon is recommended

heartbeat[28195]: 2015/10/29_21:31:14 ERROR: Configuration error, heartbeat not started.


[root@hh ha.d]# /etc/init.d/heartbeat start

Starting High-Availability services: INFO:  Resource is stopped

 Heartbeat failure [rc=6]. Failed.

heartbeat: udpport setting must precede media statementsheartbeat: baudrate setting must precede media statementsheartbeat[30724]: 2015/10/29_21:56:29 info: Pacemaker support: false

heartbeat[30724]: 2015/10/29_21:56:29 WARN: Logging daemon is disabled --enabling logging daemon is recommended

heartbeat[30724]: 2015/10/29_21:56:29 info: **************************

heartbeat[30724]: 2015/10/29_21:56:29 info: Configuration validated. Starting heartbeat 3.0.4

heartbeat[30724]: 2015/10/29_21:56:29 ERROR: Bad nodename in /etc/ha.d//haresources [hh]

heartbeat[30724]: 2015/10/29_21:56:29 ERROR: Configuration error, heartbeat not started.


五、故障模拟测试,如主down掉,看会不会切换到从继续提供服务

1、正常情况下

[root@hh ha.d]# /etc/init.d/heartbeat start

Starting High-Availability services: INFO:  Resource is stopped

Done.

[root@hh ~]# ifconfig 

eth0      Link encap:Ethernet  HWaddr 00:0C:29:97:EE:BF  

          inet addr:192.168.1.31  Bcast:192.168.1.255  Mask:255.255.255.0

          inet6 addr: fe80::20c:29ff:fe97:eebf/64 Scope:Link

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:37359 errors:0 dropped:0 overruns:0 frame:0

          TX packets:22139 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:1000 

          RX bytes:36402808 (34.7 MiB)  TX bytes:2377053 (2.2 MiB)


eth0:0    Link encap:Ethernet  HWaddr 00:0C:29:97:EE:BF  

          inet addr:192.168.1.13  Bcast:192.168.1.255  Mask:255.255.255.0

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1


eth0:1    Link encap:Ethernet  HWaddr 00:0C:29:97:EE:BF  

          inet addr:192.168.1.144  Bcast:192.168.1.255  Mask:255.255.255.0

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1


lo        Link encap:Local Loopback  

          inet addr:127.0.0.1  Mask:255.0.0.0

          inet6 addr: ::1/128 Scope:Host

          UP LOOPBACK RUNNING  MTU:16436  Metric:1

          RX packets:28 errors:0 dropped:0 overruns:0 frame:0

          TX packets:28 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:0 

          RX bytes:2727 (2.6 KiB)  TX bytes:2727 (2.6 KiB)


[root@hh ha.d]# ps aux |grep nginx    (主)

root      31367  0.0  0.1  96488  1728 ?        Ss   21:58   0:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf

nginx     31368  0.0  0.2  96876  2500 ?        S    21:58   0:00 nginx: worker process                   

root      31643  0.0  0.0 103252   824 pts/0    S+   22:16   0:00 grep nginx


[root@yo ha.d]# netstat -tnlp |grep nginx   (从)

[root@yo ha.d]# ps aux |grep nginx

root       5217  0.0  0.0 103256   828 pts/0    S+   06:11   0:00 grep nginx


2、创建测试页面,并在正常情况下测试访问,此时由主提供服务

[root@hh ha.d]# echo "AAAAAAAAAAAAAAAAhh192.168.1.31" >/usr/share/nginx/html/index.html 

[root@yo ha.d]# echo "AAAAAAAAAAAAAAAAyo192.168.1.250" >/usr/share/nginx/html/index.html

wKioL1aFQg3jsPM6AAAwcUpor1I756.jpg


3、主服务节点down掉之后(测试)

[root@hh ~]# iptables -A INPUT -p icmp -j DROP

[root@hh ~]# tail /var/log/ha-log   (查看日志信息)

ResourceManager(default)[32095]:2015/10/29_22:24:20 info: Running /etc/ha.d/resource.d/IPaddr 192.168.1.13/24/eth0:0 start

IPaddr(IPaddr_192.168.1.13)[32256]:2015/10/29_22:24:20 INFO: Adding inet address 192.168.1.13/24 with broadcast address 192.168.1.255 to device eth0 (with label eth0:0)

IPaddr(IPaddr_192.168.1.13)[32256]:2015/10/29_22:24:20 INFO: Bringing device eth0 up

IPaddr(IPaddr_192.168.1.13)[32256]:2015/10/29_22:24:20 INFO: /usr/libexec/heartbeat/send_arp -i 200 -r 5 -p /var/run/resource-agents/send_arp-192.168.1.13 eth0 192.168.1.13 auto not_used not_used

/usr/lib/ocf/resource.d//heartbeat/IPaddr(IPaddr_192.168.1.13)[32230]:2015/10/29_22:24:20 INFO:  Success

ResourceManager(default)[32095]:2015/10/29_22:24:20 info: Running /etc/init.d/nginx  start

Oct 29 22:24:20 hh.huangmingming.cn ipfail: [30881]: info: NS: We are still alive!

Oct 29 22:24:20 hh.huangmingming.cn ipfail: [30881]: info: Link Status update: Link yo.huangmingming.cn/eth0 now has status dead

Oct 29 22:24:22 hh.huangmingming.cn ipfail: [30881]: info: Asking other side for ping node count.

Oct 29 22:24:22 hh.huangmingming.cn ipfail: [30881]: info: Checking remote count of ping nodes.


4、在从(yo)上查看有没有自动启动nginx,并在客户端访问,此时由从提供服务

[root@yo ha.d]# ps aux |grep nginx

root       5534  0.0  0.1  96496  1972 ?        Ss   06:20   0:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf

nginx      5535  0.0  0.2  96884  2960 ?        S    06:20   0:00 nginx: worker process                   

root       5546  0.0  0.0 103256   828 pts/0    S+   06:24   0:00 grep nginx

[root@yo ha.d]# ifconfig 

eth0      Link encap:Ethernet  HWaddr 00:0C:29:8B:40:4A  

          inet addr:192.168.1.250  Bcast:192.168.1.255  Mask:255.255.255.0

          inet6 addr: fe80::20c:29ff:fe8b:404a/64 Scope:Link

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:36106 errors:0 dropped:0 overruns:0 frame:0

          TX packets:21435 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:1000 

          RX bytes:39751462 (37.9 MiB)  TX bytes:2077943 (1.9 MiB)


eth0:0    Link encap:Ethernet  HWaddr 00:0C:29:8B:40:4A  

          inet addr:192.168.1.13  Bcast:192.168.1.255  Mask:255.255.255.0

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1


lo        Link encap:Local Loopback  

          inet addr:127.0.0.1  Mask:255.0.0.0

          inet6 addr: ::1/128 Scope:Host

          UP LOOPBACK RUNNING  MTU:16436  Metric:1

          RX packets:31 errors:0 dropped:0 overruns:0 frame:0

          TX packets:31 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:0 

          RX bytes:3005 (2.9 KiB)  TX bytes:3005 (2.9 KiB)

wKioL1aFQejDrevfAAAuKKHAdqs612.jpg

删除防火墙再测试

[root@hh ~]# iptables -nvL

[root@hh ~]# iptables -D INPUT -p icmp -j DROP



本文转自 HMLinux 51CTO博客,原文链接:http://blog.51cto.com/7424593/1730575


相关文章
|
20天前
|
存储 人工智能 测试技术
小鱼深度评测 | 通义灵码2.0,不仅可跨语言编码,自动生成单元测试,更炸裂的是集成DeepSeek模型且免费使用,太炸裂了。
小鱼深度评测 | 通义灵码2.0,不仅可跨语言编码,自动生成单元测试,更炸裂的是集成DeepSeek模型且免费使用,太炸裂了。
141061 20
小鱼深度评测 | 通义灵码2.0,不仅可跨语言编码,自动生成单元测试,更炸裂的是集成DeepSeek模型且免费使用,太炸裂了。
|
19天前
|
人工智能 运维 前端开发
基于阿里百炼的DeepSeek-R1满血版模型调用【零门槛保姆级2084小游戏开发实战】
本文介绍基于阿里百炼的DeepSeek-R1满血版模型调用,提供零门槛保姆级2048小游戏开发实战。文章分为三部分:定位与核心优势、实战部署操作指南、辅助实战开发。通过详细步骤和案例展示,帮助开发者高效利用DeepSeek-R1的强大推理能力,优化游戏逻辑与视觉效果,解决官网响应延迟问题,提升开发效率和用户体验。适合企业开发者、教育行业及多模态探索者使用。
70896 17
基于阿里百炼的DeepSeek-R1满血版模型调用【零门槛保姆级2084小游戏开发实战】
|
27天前
|
人工智能 自然语言处理 Shell
深度评测 | 仅用3分钟,百炼调用满血版 Deepseek-r1 API,百万Token免费用,简直不要太爽。
仅用3分钟,百炼调用满血版Deepseek-r1 API,享受百万免费Token。阿里云提供零门槛、快速部署的解决方案,支持云控制台和Cloud Shell两种方式,操作简便。Deepseek-r1满血版在推理能力上表现出色,尤其擅长数学、代码和自然语言处理任务,使用过程中无卡顿,体验丝滑。结合Chatbox工具,用户可轻松掌控模型,提升工作效率。阿里云大模型服务平台百炼不仅速度快,还确保数据安全,值得信赖。
358007 62
深度评测 | 仅用3分钟,百炼调用满血版 Deepseek-r1 API,百万Token免费用,简直不要太爽。
|
23天前
|
人工智能 自然语言处理 API
快速使用 DeepSeek-R1 满血版
DeepSeek是一款基于Transformer架构的先进大语言模型,以其强大的自然语言处理能力和高效的推理速度著称。近年来,DeepSeek不断迭代,从DeepSeek-V2到参数达6710亿的DeepSeek-V3,再到性能比肩GPT-4的DeepSeek-R1,每次都带来重大技术突破。其开源策略降低了AI应用门槛,推动了AI普惠化。通过阿里云百炼调用满血版API,用户可以快速部署DeepSeek,享受高效、低成本的云端服务,最快10分钟完成部署,且提供免费token,极大简化了开发流程。
191005 23
快速使用 DeepSeek-R1 满血版
|
8天前
|
人工智能 搜索推荐 数据可视化
Manus:或将成为AI Agent领域的标杆
随着人工智能技术的飞速发展,AI Agent(智能体)作为人工智能领域的重要分支,正逐渐从概念走向现实,并在各行各业展现出巨大的应用潜力。在众多AI Agent产品中,Manus以其独特的技术优势和市场表现,有望成为该领域的标杆。作为资深AI工程师,本文将深入探讨Manus的背景知识、主要业务场景、底层原理、功能的优缺点,并尝试使用Java搭建一个属于自己的Manus助手,以期为AI Agent技术的发展和应用提供参考。
11063 13
|
8天前
|
机器学习/深度学习 人工智能 测试技术
阿里云百炼已上线超强推理开源模型QwQ-32B,尺寸更小,性能比肩DeepSeek满血版
通义千问团队推出了320亿参数的QwQ-32B模型,通过大规模强化学习和多阶段训练,在数学、编程及通用能力上达到或超越了DeepSeek-R1等先进模型。QwQ-32B模型已在阿里云百炼上线,支持API调用,用户可通过官方文档了解详细使用方法。未来,团队将继续探索智能体与RL集成,推动人工通用智能的发展。
|
25天前
|
机器学习/深度学习 人工智能 自然语言处理
快来零门槛、即刻拥有 DeepSeek-R1 满血版
随着人工智能技术的发展,DeepSeek作为一款新兴推理模型,凭借强大的技术实力和广泛的应用场景崭露头角。本文基于阿里云提供的零门槛解决方案,评测DeepSeek的部署与使用。该方案支持多模态任务,涵盖文本生成、代码补全等,融合NLP、IR和ML技术,提供快速实现AI应用的便利。用户无需编码,最快5分钟、最低0元即可部署DeepSeek模型。阿里云还提供100万免费Token,适合预算有限的个人或小型团队试用。通过Chatbox客户端配置API,用户可轻松体验智能交互功能,如数学提问和代码书写等。
37603 5
|
20天前
|
人工智能 编解码 算法
DeepSeek加持的通义灵码2.0 AI程序员实战案例:助力嵌入式开发中的算法生成革新
本文介绍了通义灵码2.0 AI程序员在嵌入式开发中的实战应用。通过安装VS Code插件并登录阿里云账号,用户可切换至DeepSeek V3模型,利用其强大的代码生成能力。实战案例中,AI程序员根据自然语言描述快速生成了C语言的base64编解码算法,包括源代码、头文件、测试代码和CMake编译脚本。即使在编译错误和需求迭代的情况下,AI程序员也能迅速分析问题并修复代码,最终成功实现功能。作者认为,通义灵码2.0显著提升了开发效率,打破了编程语言限制,是AI编程从辅助工具向工程级协同开发转变的重要标志,值得开发者广泛使用。
7908 68
DeepSeek加持的通义灵码2.0 AI程序员实战案例:助力嵌入式开发中的算法生成革新
|
7天前
|
机器学习/深度学习 弹性计算 搜索推荐
真正的0代码,0脚本,0门槛,QwQ-32B一键部署!
阿里云最新发布的QwQ-32B模型通过强化学习显著提升了推理能力,在多个核心指标上达到DeepSeek-R1满血版水平,超越了DeepSeek-R1-Distill-Qwen-32B。用户可通过阿里云系统运维管理(OOS)的公共扩展功能,一键部署OpenWebUI+Ollama至ECS,轻松运行QwQ-32B模型。该方案支持本地部署和连接阿里云百炼在线模型,无需编写代码,操作简便,适合新手尝试。具体步骤包括:在阿里云控制台安装OpenWebUI扩展、选择ECS实例并创建、等待几分钟后获取URL链接,即可开始使用。此外,还提供了详细的配置指南和高级玩法介绍,帮助用户更好地利用该模型。
|
10天前
|
开发者 异构计算
高效部署通义万相Wan2.1:ComfyUI文生/图生视频实战,工作流直取!
通义万相Wan2.1开源不到一周,已登顶HuggingFace Model 和 Space 榜双榜首,在HuggingFace和ModelScope平台的累计下载量突破100万次,社区热度持续攀升!为响应小伙伴们对ComfyUI工作流运行Wan2.1的强烈需求,社区开发者整理了实战教程👇
1270 21
高效部署通义万相Wan2.1:ComfyUI文生/图生视频实战,工作流直取!