内容简介:本文风哥教程参考Linux官方文档、Red Hat Enterprise Linux官方文档、Ansible Automation Platform官方文档、Docker官方文档、Kubernetes官方文档和Podman官方文档等内容,详细介绍了相关技术的配置和使用方法。
本
风哥提示:
文档详细介绍集群资源的克隆和主从配置方法。
Part01-资源克隆
1.1 创建克隆资源
[rfrom PG视频:www.itpux.comoot@ha-node1 ~]# pcs resource create web_vip ocf:heartbeat:IPaddr2 \
ip=192.168.1.100 cidr_netmask=24 \
op monitor interval=30s
# 创建克隆资源
[root@ha-node1 ~]# pcs resource clone web_vip
Cloning resource ‘web_vip’…
* Clone name: web_vip-clone
* Clone instances: 2
Clone created
# 查看克隆资源
[root@ha-node1 ~]# pcs resource show web_vip-clone
Clone: web_vip-clone
Resource: web_vip (class=ocf provider=heartbeat type=IPaddr2)
Attributes: cidr_netmask=24 ip=192.168.1.100
Operations: monitor interval=30s (web_vip-monitor-interval-30s)
# 查看资源状态
[root@ha-node1 ~]# pcs status resources
* Clone Set: web_vip-clone [web_vip]
* Started: [ ha-node1 ha-node2 ]
1.2 克隆资源配置
[root@ha-node1 ~]# pcs resource create httpd systemd:httpd op monitor interval=20s
[root@ha-node1 ~]# pcs resource clone httpd clone-max=2 clone-node-max=1
# 查看克隆配置
[root@ha-node1 ~]# pcs resource show httpd-clone
Clone: httpd-clone
Attributes: clone-max=2 clone-node-max=1
Resource: httpd (class=systemd type=httpd)
Operations: monitor interval=20s (httpd-monitor-interval-20s)
# 更新克隆选项
[root@ha-node1 ~]# pcs resource update httpd-clone clone-max=3 clone-node-max=2
# 验证更新
[root@ha-node1 ~]# pcs resource show httpd-clone
Clone: httpd-clone
Attributes: clone-max=3 clone-node-max=2
Resource: httpd (class=systemd type=httpd)
Operations: monitor interval=20s (httpd-monitor-interval-20s)
# 克隆选项说明:
# clone-max: 克隆实例总数
# clone-node-max: 每个节点最大实例数
# notify: 是否通知其他克隆实例
# globally-unique: 是否全局唯一
# ordered: 是否按顺序启动
# interleave: 是否交错启动
Part02-主从资源
2.1 创建主从资源
[root@ha-node1 ~]# pcs resource create drbd_data ocf:linbit:drbd \
drbd_resource=r0 \
op monitor interval=30s role=Master \
op monitor interval=31s role=Slave
# 创建主从资源
[root@ha-node1 ~]# pcs resource master drbd_ms drbd_data \
master-max=1 master-node-max=1 \
clone-max=2 clone-node-max=1
# 查看主从资源
[root@ha-node1 ~]# pcs resource show drbd_ms
Master: drbd_ms
Resource: drbd_data (class=ocf provider=linbit type=drbd)
Attributes: drbd_resource=r0
Operations: monitor interval=30s role=Master (drbd_data-monitor-interval-30s-role-Master)
monitor interval=31s role=Slave (drbd_data-monitor-interval-31s-role-Slave)
# 查看资源状态
[root@ha-node1 ~]# pcs status resources
* Master/Slave Set: drbd_ms [drbd_data]
* Masters: [ ha-node1 ]
* Slaves: [ ha-node2 ]
2.2 主从资源配置
[root@ha-node1 ~]# pcs resource create mysql_replication ocf:heartbeat:mysql \
binary=”/usr/bin/mysqld_safe” \
config=”/etc/my.cnf” \
datadir=”/var/lib/mysql” \
user=”root” \
op monitor interval=20s role=Master \
op monitor interval=30s role=Slave
# 创建主从资源
[root@ha-node1 ~]# pcs resource master mysql_ms mysql_replication \
master-max=1 master-node-max=1
# 查看主从资源
[root@ha-node1 ~]# pcs resource show mysql_ms
Master: mysql_ms
Resource: mysql_replication (class=ocf provider=heartbeat type=mysql)
Attributes: binary=/usr/bin/mysqld_safe config=/etc/my.cnf datadir=/var/lib/mysql user=root
Operations: monitor interval=20s role=Master (mysql_replication-monitor-interval-20s-role-Master)
monitor interval=30s role=Slave (mysql_replication-monitor-interval-30s-role-Slave)
# 查看资源状态
[root@ha-node1 ~]# pcs status resources
* Master/Slave Set: mysql_ms [mysql_replication]
* Masters: [ ha-node1 ]
* Slaves: [ ha-node2 ]
Part03-克隆资源管理
3.1 管理克隆资源
[root@ha-node1 ~]# pcs resource enable httpd-clone
# 停止克隆资源
[root@ha-node1 ~]# pcs resource disable httpd-clone
# 查看克隆资源状态
[root@ha-node1 ~]# pcs status resources
* Clone Set: httpd-clone [httpd]
* Started: [ ha-node1 ha-node2 ]
# 清理克隆资源
[root@ha-node1 ~]# pcs resource cleanup httpd-clone
Cleaned up httpd:0 on ha-node1
Cleaned up httpd:1 on ha-node2
# 删除克隆资源
[root@ha-node1 ~]# pcs resource delete httpd-clone
Attempting to stop: httpd-clone… Stopped
# 验证删除
[root@ha-node1 ~]# pcs resource show
No resources found
3.2 克隆资源约束
[root@ha-node1 ~]# pcs constraint location httpd-clone prefers ha-node1=100
# 查看约束
[root@ha-node1 ~]# pcs constraint location
Location Constraints:
Resource: httpd-clone
Enabled on: ha-node1 (score:100)
# 创建克隆资源顺序约束
[root@ha-node1 ~]# pcs constraint order web_vip-clone then httpd-clone
# 查看约束
[root@ha-node1 ~]# pcs constraint order
Ordering Constraints:
start web_vip-clone then start httpd-clone (Mandatory)
# 创建克隆资源共置约束
[root@ha-node1 ~]# pcs constraint colocation add httpd-clone with web_vip-clone INFINITY
# 查看约束
[root@ha-node1 ~]# pcs constraint colocation
Colocation Constraints:
httpd-clone with web_vip-clone (score:INFINITY)
Part04-主从资源管理
4.1 管理主从资源
[root@ha-node1 ~]# pcs status resources
* Master/Slave Set: drbd_ms [drbd_data]
* Masters: [ ha-node1 ]
* Slaves: [ ha-node2 ]
# 手动切换主从
[root@ha-node1 ~]# pcs resource move drbd_ms ha-node2
# 查看状态
[root@ha-node1 ~]# pcs status resources
* Master/Slave Set: drbd_ms [drbd_data]
* Masters: [ ha-node2 ]
* Slaves: [ ha-node1 ]
# 清除移动约束
[root@ha-node1 ~]# pcs resource clear drbd_ms
# 查看主从资源详情
[root@ha-node1 ~]# pcs resource show drbd_ms –full
Master: drbd_ms
Meta Attrs: clone-max=2 clone-node-max=1 master-max=1 master-node-max=1
Resource: drbd_data (class=ocf provider=linbit type=drbd)
Attributes: drbd_resource=r0
Operations: monitor interval=30s role=Master (drbd_data-monitor-interval-30s-role-Master)
monitor interval=31s role=Slave (drbd_data-monitor-interval-31s-role-Slave)
4.2 主从资源约束
[root@ha-node1 ~]# pcs constraint colocation add master drbd_ms with vip INFINITY
# 查看约束
[root@ha-node1 ~]# pcs constraint colocation
Colocation Constraints:
vip with drbd_ms (score:INFINITY) (rsc-role:Started) (with-rsc-role:Master)
# 创建顺序约束
[root@ha-node1 ~]# pcs constraint order promote drbd_ms then start vip
# 查看约束
[root@ha-node1 ~]# pcs constraint order
Ordering Constraints:
promote drbd_ms then start vip (Mandatory)
# 验证资源配置
[root@ha-node1 ~]# pcs constraint
Location Constraints:
No location constraints found
Ordering Constraints:
promote drbd_ms then start vip (Mandatory)
Colocation Constraints:
vip with drbd_ms (score:INFINITY) (rsc-role:Started) (with-rsc-role:Master)
- 克隆资源用于多节点同时运行
- 主从资源用于主备切换场景
- 设置合理的监控间隔
- 配置正确的资源约束
- 定期测试资源切换
本文由风哥教程整理发布,仅用于学习测试使用,转载注明出处:http://www.fgedu.net.cn/10327.html
