内容简介:本文风哥教程参考Linux官方文档、Red Hat Enterprise Linux官方文档、Ansible Automation Platform官方文档、Docker官方文档、Kuberne学习交流加群风哥微信: itpux-comtes官方文档和Podman官方文档等内容,详细介绍了相关技术的配置和使用方法。
本文档详细介绍pcs constraint命令的使
风哥提示:
用方法,包括位置约束、顺序约束和共置约束的配置。
Part01-位置约束
1.1 创建位置约束
[root@ha-node1 ~]# pcs constraint location vip prefers ha-node1=100
# 查看约束
[root@ha-node1 ~]# pcs constraint location
Location Constraints:
Resource: vip
Enabled on: ha-node1 (score:100)
# 设置资源避免在node2运行
[root@ha-node1 ~]# pcs constraint location vip avoids ha-node2=50
# 查看所有位置约束
[root@ha-node1 ~]# pcs constraint location
Location Constraints:
Resource: vip
Enabled on: ha-node1 (score:100)
Disabled on: ha-node2 (score:-50)
# 设置资源必须在指定节点运行
[root@ha-node1 ~]# pcs constraint location vip rule score=INFINITY #uname eq ha-node1
# 查看规则约束
[root@ha-node1 ~]# pcs constraint location vip
Location Constraints:
Resource: vip
Rule: score=INFINITY
Expression: #uname eq ha-node1
1.2 删除位置约束
[root@ha-node1 ~]# pcs constraint location –full
Location Constraints:
Resource: vip
Constraint: location-vip-ha-node1-INFINITY
Rule: score=INFINITY (id:location-vip-ha-node1-INFINITY-rule)
Expression: #uname eq ha-node1 (id:location-vip-ha-node1-INFINITY-expr)
# 删除约束
[root@ha-node1 ~]# pcs constraint remove location-vip-ha-node1-INFINITY
# 验证删除
[root@ha-node1 ~]# pcs constraint location
No location constraints found
Part02-顺序约束
2.1 创建顺序约束
[root@ha-node1 ~]# pcs constraint order vip then nginx
Adding vip nginx (kind: Mandatory) (Options: first-action=start then-action=start)
# 查看顺序约束
[root@ha-node1 ~]# pcs constraint order
Ordering Constraints:
start vip then start nginx (Mandatory)
# 设置启动顺序(可选)
[root@ha-node1 ~]# pcs constraint order vip then nginx kind=Optional
# 查看约束
[root@ha-node1 ~]# pcs constraint order
Ordering Constraints:
start vip then start nginx (Mandatory)
start vip then start nginx (Optional)
# 设置对称顺序
[root@ha-node1 ~]# pcs constraint order vip then nginx symmetrical=true
# 设置停止顺序
[root@ha-node1 ~]# pcs constraint order stop nginx then stop vip
Adding nginx vip (kind: Mandatory) (Options: first-action=stop then-action=stop)
# 查看所有顺序约束
[root@ha-node1 ~]# pcs constraint order
Ordering Constraints:
start vip then start nginx (Mandatory)
start vip then start nginx (Optional)
stop nginx then stop vip (Mandatory)
2.2 删除顺序约束
[root@ha-node1 ~]# pcs constraint order –full
Ordering Constraints:
Constraint: order-vip-nginx-mandatory
start vip then start nginx (Mandatory)
Constraint: order-vip-nginx-optional
start vip then start nginx (Optional)
# 删除约束
[root@ha-node1 ~]# pcs constraint remove order-vip-nginx-mandatory
# 验证删除
[root@ha-node1 ~]# pcs constraint order
Ordering Constraints:
start vip then start nginx (Optional)
Part03-共置约束
3.1 创建共置约束
[root@ha-node1 ~]# pcs constraint colocation add vip with nginx INFINITY
# 查看共置约束
[root@ha-node1 ~]# pcs constraint colocation
Colocation Constraints:
vip with nginx (score:INFINITY)
# 设置vip和nginx不能在同一节点运行
[root@ha-node1 ~]# pcs constraint colocation add vip with nginx -INFINITY
# 查看约束
[root@ha-node1 ~]# pcs constraint colocation
Colocation Constraints:
vip with nginx (score:INFINITY)
vip with nginx (score:-INFINITY)
# 设置资源组共置
[root@ha-node1 ~]# pcs constraint colocation add webgroup with dbgroup 100
# 查看所有约束
[root@ha-node1 ~]# pcs constraint
Location Constraints:
No location constraints found
Ordering Constraints:
start vip then start nginx (Optional)
Colocation Constraints:
vip with nginx (score:INFINITY)
vip with nginx (score:-INFINITY)
3.2 删除共置约束
[root@ha-node1 ~]# pcs constraint colocation –full
Colocation Constraints:
Constraint: colocation-vip-nginx-INFINITY
vip with nginx (score:INFINITY)
Constraint: colocation-vip-nginx–INFINITY
vip with nginx (score:-INFINITY)
# 删除约束
[root@ha-node1 ~]# pcs constraint remove colocation-vip-nginx-INFINITY
# 验证删除
[root@ha-node1 ~]# pcs constraint colocation
Colocation Constraints:
vip with nginx (score:-INFINITY)
Part04-约束管理
4.1 查看所有约束
[root@ha-node1 ~]# pcs constraint
Location Constraints:
No location constraints found
Ordering Constraints:
start vip then start nginx (Optional)
Colocation Constraints:
vip with nginx (score:-INFINITY)
Ticket Constraints:
# 查看详细约束
[root@ha-node1 ~]# pcs constraint –full
Location Constraints:
No location constraints found
Ordering Constraints:
Constraint: order-vip-nginx-optional
start vip then start nginx (Optional)
Colocation Constraints:
Constraint: colocation-vip-nginx–INFINITY
vip with nginx (score:-INFINITY)
Ticket Constraints:
# 查看特定资源的约束
[root@ha-node1 ~]# pcs constraint ref vip
Resource: vip
order-vip-nginx-optional
colocation-vip-nginx–INFINITY
4.2 清除约束
[root@ha-node1 ~]# pcs constraint clear vip
Removing all constraints for vip
* Removed: order-vip-nginx-optional
* Removed: colocation-vip-nginx–INFINITY
# 验证清除
[root@ha-node1 ~]# pcs constraint ref vip
No constraints found for vip
# 清除所有约束
[root@ha-node1 ~]# pcs constraint remove –all
Removing all constraints
* Removed: all constraints
# 验证清除
[root@ha-node1 ~]# pcs constraint
Location Constraints:
No location constraints found
Ordering Constraints:
No ordering constraints found
Colocation Constraints:
No colocation constraints found
Ticket Constraints:
No ticket constraints found
- 使用位置约束控制资源运行位置
- 使用顺序约束控制资源启动顺序
- 使用共置约束确保资源在同一节点
- 约束分数:INFINITY表示必须,-INFINITY表示禁止
- 定期检查约束配置
本文由风哥教程整理发布,仅用于学习测试使用,转载注明出处:http://www.fgedu.net.cn/10327.html
