内容简介:本文风哥教程参考Linux官方文档、Red Hat Enterprise Linux官方文档、Ansible Automation Platform官方文档、Docker官方文档、Kubernetes官方文档和Podman官方文档等内容,详细介绍了相关技术的配置和使用方法。更多视频教程www.fgedu.net.cn
风哥提示:
本文档详细介绍pcs resource命令的使用方法,包括资源的创建、管理和监控。
Part01-创建资源
1.1 创建IP地址资源
[root@ha-node1 ~]# pcs resource create vip ocf:heartbeat:IPaddr2 \
ip=192.168.1.100 cidr_netmask=24 op monitor interval=30s
Assumed agent name ‘ocf:heartbeat:IPaddr2’ (deduced from ‘IPaddr2’)
Creating Resource (vip)…
* Check: vip-ocf:heartbeat:IPaddr2
* Check: vip-ip=192.168.1.100
* Check: vip-cidr_netmask=24
* Check: vip-op-monitor-interval=30s
Resource ‘vip’ created
# 验证资源创建
[root@ha-node1 ~]# pcs resource show vip
Resource: vip (class=ocf provider=heartbeat type=IPaddr2)
Attributes: cidr_netmask=24 ip=192.168.1.100
Operations: monitor interval=30s (vip-monitor-interval-30s)
# 查看资源状态
[root@ha-node1 ~]# pcs status resources
* vip (ocf::heartbeat:IPaddr2): Started ha-node1
1.2 创建服务资源
[root@ha-node1 ~]# pcs resource create nginx systemd:nginx \
op monitor interval=20s timeout=10s \
op start timeout=60s \
op stop timeout=60s
Creating Resource (nginx)…
* Check: nginx-systemd:nginx
* Check: nginx-op-monitor-interval=20s
* Check: nginx-op-start-timeout=60s
* Check: nginx-op-stop-timeout=60s
Resource ‘nginx’ created
# 创建Apache服务资源
[root@ha-node1 ~]# pcs resource create httpd systemd:httpd \
op monitor interval=30s
Creating Resource (httpd)…
* Check: httpd-systemd:httpd
* Check: httpd-op-monitor-interval-30s
Resource ‘httpd’ created
# 查看所有资源
[root@ha-node1 ~]# pcs resource show
vip (ocf::heartbeat:IPaddr2): Started
nginx (systemd:nginx): Started
httpd (systemd:httpd): Started
Part02-资源管理
2.1 启动停止资源
[root@ha-node1 ~]# pcs resource enable nginx
# 停止资源
[root@ha-node1 ~]# pcs resource disable nginx
# 查看资源状态
[root@ha-node1 ~]# pcs status resources
* vip (ocf::heartbeat:IPaddr2): Started ha-node1
* nginx (systemd:nginx): Stopped (disabled)
* httpd (systemd:httpd): Started ha-node1
# 重启资源
[root@ha-node1 ~]# pcs resource restart nginx
nginx: Restarting…
nginx: Successfully restarted
# 清理资源状态
[root@ha-node1 ~]# pcs resource cleanup nginx
Cleaned up nginx on ha-node1
Cleaned up nginx on ha-node2
Waiting for 1 replies from the controller
2.2 移动资源
[root@ha-node1 ~]# pcs resource move vip ha-node2
Moving vip to ha-node2…
* vip: vip-move
* vip: vip-migrate-from-ha-node1
* vip: vip-migrate-to-ha-node2
vip moved to ha-node2
# 查看资源位置
[root@ha-node1 ~]# pcs status resources
* vip (ocf::heartbeat:IPaddr2): Started ha-node2
# 移除资源位置约束
[root@ha-node1 ~]# pcs resource clear vip
Removing constraint for vip
vip constraint removed
# 资源可能回到原节点
[root@ha-node1 ~]# pcs status resources
* vip (ocf::heartbeat:IPaddr2): Started ha-node1
Part03-资更多学习教程公众号风哥教程itpux_com源配置
3.1 修改资源参数
[root@ha-node1 ~]# pcs resource show vip
Resource: vip (class=ocf provider=heartbeat type=IPaddr2)
Attributes: cidr_netmask=24 ip=192.168.1.100
Operations: monitor interval=30s (vip-monitor-interval-30s)
# 修改资源参数
[root@ha-node1 ~]# pcs resource up学习交流加群风哥微信: itpux-comdate vip ip=192.168.1.200
# 验证修改
[root@ha-node1 ~]# pcs resource show vip
Resource: vip (class=ocf provider=heartbeat type=IPaddr2)
Attributes: cidr_netmask=24 ip=192.168.1.200
Operations: monitor interval=30s (vip-monitor-interval-30s)
# 添加监控操作
[root@ha-node1 ~]# pcs resource update vip op monitor interval=15s timeout=10s
# 验证操作
[root@ha-node1 ~]# pcs resource show vip
Resource: vip (class=ocf provider=heartbeat type=IPaddr2)
Attributes: cidr_netmask=24 ip=192.168.1.200
Operations: monitor interval=15s timeout=10s (vip-monitor-interval-15s)
3.2 资源组
[root@ha-node1 ~]# pcs resource group add webgroup vip nginx
# 查看资源组
[root@ha-node1 ~]# pcs resource show webgroup
Group: webgroup
Resource: vip (class=ocf provider=heartbeat type=IPaddr2)
Attributes: cidr_netmask=24 ip=192.168.1.200
Operations: monitor interval=15s timeout=10s (vip-monitor-interval-15s)
Resource: nginx (class=systemd type=nginx)
Operations: monitor interval=20s timeout=10s (nginx-monitor-interval-20s)
# 从组中移除资源
[root@ha-node1 ~]# pcs resource group remove webgroup nginx
# 删除资源组
[root@ha-node1 ~]# pcs resource group remove webgroup
# 验证删除
[root@ha-node1 ~]# pcs resource show
vip (ocf::heartbeat:IPaddr2): Started
nginx (systemd:nginx): Started
Part04-资源删除
4.1 删除资源
[root@ha-node1 ~]# pcs resource disable httpd
# 删除资源
[root@ha-node1 ~]# pcs resource delete httpd
Attempting to stop: httpd… Stopped
# 验证删除
[root@ha-node1 ~]# pcs resource show
vip (ocf::heartbeat:IPaddr2): Started
nginx (systemd:nginx): Started
# 批量删除资源
[root@ha-node1 ~]# pcs resource delete vip nginx
Attempting to stop: vip… Stopped
Attempting to stop: nginx… Stopped
# 验证删除
[root@ha-node1 ~]# pcs resource show
No resources found
- 创建资源前先测试资源代理
- 设置合理的监控间隔
- 相关资源使用资源组
- 删除资源前先停止
- 定期检查资源状态
本文由风哥教程整理发布,仅用于学习测试使用,转载注明出处:http://www.fgedu.net.cn/10327.html
