当前位置:网站首页>使用树莓派做Apache2 HA实验
使用树莓派做Apache2 HA实验
2022-07-24 13:45:00 【Ki1381】
听闻树莓派也已经是个理财产品了,默默关闭了某宝网页的我不禁陷入了沉思,然后翻出了之前买的一堆3B。话说回来,虽然账面上浮盈了,但乐不出来。按郭德纲的说法,真乐出来这堆树莓派治不好我。要不就挑两个做个HA的实验吧,这个做成了可能还乐的出来一点。
所以尝试这么个场景:
有个网站假设很重要,一台服务器挂了能有另一台顶上
以下就是实验设备的基本信息:
节点1:hostname ki01;IP:192.168.1.81
节点2:hostname ki02;IP:192.168.1.82
将这两个节点做个群集,虚拟出一个新地址 192.168.1.83。访问网站使用这个地址。
怎么设置固定IP,怎么设置hostname就略过不说了。
【以下操作两个节点上都要执行】
1、修改/etc/hosts,强制加入ki01和ki02对应的IP
192.168.1.81 ki01
192.168.1.82 ki02
2、安装必备的HA服务并做简单初始配置:
sudo apt install pacemaker pcs resource-agents
sudo systemctl start pcsd.service
sudo systemctl enable pcsd.service
sudo passwd hacluster
设置hacluster的密码并牢记。
【以下操作仅需在任意一个节点上操作】
3、形成群集
# 强制清理
sudo pcs cluster destroy
# 注册群集节点并形成群集
sudo pcs --force host auth ki01 ki02 -u hacluster -p 刚才设置的密码
sudo pcs --force cluster setup kicluster ki01 ki02
4、启动群集并设置成开机后自动启动:
sudo pcs cluster start –-all
sudo pcs cluster enable --all
5、禁用stonith和仲裁(针对这个实验这些个都没必要)
sudo pcs property set stonith-enabled=false
sudo pcs property set no-quorum-policy=ignore
【以下操作两个节点上都要执行】
6、安装Apache2,并设置禁止自动启动:
sudo apt install -y apache2
sudo systemctl stop apache2
sudo systemctl disable apache2
7、编辑/var/www/html/a.html,以便观察效果(这个是以ki01举例的。ki02就改KI02):
<html>
<body>THIS IS KI01.</body>
</html>
8、查看 /etc/apache2/mods-available/status.conf,确认有以下语句:
<Location /server-status>
SetHandler server-status
Require local
</Location>
【以下操作仅需在任意一个节点上操作】
9、配置群集资源:WebSite(对应Apache2)和虚拟IP
# 创建 WebSite 群集资源
sudo pcs --force resource create WebSite ocf:heartbeat:apache \
configfile=/etc/apache2/apache2.conf \
statusurl="http://localhost/server-status" \
op monitor interval=1min
# 创建 虚拟IP 群集资源
sudo pcs --force resource create ClusterIP ocf:heartbeat:IPaddr2 ip=192.168.1.8310、设置WebSite和虚拟IP的依赖关系、启动顺序、节点权重等。正常情况应该WebSite和虚拟IP是在一个节点上的:
sudo pcs constraint colocation add WebSite with ClusterIP INFINITY
sudo pcs constraint order ClusterIP then WebSite
sudo pcs constraint location WebSite prefers ki01=50
11、可以随时用 sudo pcs status 查看群集的状态。重点关注节点的online/offline状态、资源的状态。

此时可以用浏览器访问http://192.168.1.83/a.html。此刻资源在ki01上,那么就会显示THIS IS KI01。
12、手动切换测试(以下语句针对当前资源在ki01上的):
sudo pcs resource move WebSite ki02使用sudo pcs status命令,以及浏览器访问192.168.1.83看看是不是已经切过去了。
13、自动切换测试:
使用sudo pcs status命令或访问192.168.1.83确定当前资源在哪个节点上。然后关闭该节点。正常情况就是应该很快就切到存活的节点上了。在存活的节点上继续使用sudo pcs status命令,以及浏览器访问192.168.1.83确认是否工作正常。

当关闭的节点重新打开上线后,因为设置了优先级ki01=50(数字越大优先级越高),资源还是会切回ki01:

参考资料:
https://clusterlabs.org/quickstart-redhat.html
pcs(8) — pcs — Debian unstable — Debian Manpages
边栏推荐
- The latest and complete Flink series tutorials in 2021_ Preliminary exploration of Flink principle and flow batch integration API (II. V) V2
- SQL Server 启停作业脚本
- Chrome plug-in development tutorial
- 网络安全——服务漏洞扫描与利用
- The scroll bar in unity ugui is not displayed from the top when launching the interface in the game
- 2022.7.22 模拟赛
- 数据修改修改
- 游戏思考04总结:针对帧、状态、物理同步的总结(之前写的太长,现在简略下)
- Simulate the implementation of the library function memcpy-- copy memory blocks. Understand memory overlap and accurate replication in detail
- R语言检验样本比例:使用prop.test函数执行单样本比例检验计算总体中成功样本比例p值的置信区间
猜你喜欢

How to generate expected data? Emory University and others' latest "deep learning controllable data generation" review, 52 page PDF, covering 346 documents, comprehensively expounds the controllable g

CSDN垃圾的没有底线!

Game thinking 04 summary: a summary of frame, state and physical synchronization (it was too long before, and now it's brief)

Chapter VI bus

From cloud native to intelligent, in-depth interpretation of the industry's first "best practice map of live video technology"

Network security - function bypass injection

网络安全——文件上传黑名单绕过

第六章 总线

简易订单管理系统小练习

Explain the edge cloud in simple terms | 2. architecture
随机推荐
Packet switching and label switching in MPLS
R language uses the statstack function of epidisplay package to view the statistics (mean, median, etc.) of continuous variables and the corresponding hypothesis test in a hierarchical manner based on
Ansible服务常用命令模块详细解析
在EXCEL表格中如何进行快速换行
Unity UGUI中scroll bar在游戏中启动界面时没有从最上面显示
Dtcloud uses custom fonts
基于群体熵的机器人群体智能汇聚度量
Network security - file upload competitive conditions bypass
网络安全——文件上传竞争条件绕过
Hcip day 13
【无标题】
Flex layout
网络安全——Web渗透测试
Network security - error injection
Odoo+ test
Interface document evolution atlas, some ancient interface document tools, you may not have used them
Game thinking 04 summary: a summary of frame, state and physical synchronization (it was too long before, and now it's brief)
How can the easycvr platform access special devices without authentication?
Happy number ~ ~ ~ (in fact, I'm not happy at all) & ugly number
Spelling words~