]# corosync-keygen --help
Usage: corosync-keygen [-k <keyfile>] [-l]
-k / --key-file=<filename> - Write to the specified keyfile
instead of the default /etc/corosync/authkey.
-l / --less-secure - Use a less secure random number source
(/dev/urandom) that is guaranteed not to require user
input for entropy. This can be used when this
application is used from a script.
]# corosync-keygen -l //生成简单的密钥
]# cd /etc/corosync/
]# ll
total 16
-r-------- 1 root root 128 May 29 18:16 authkey //自动生成在/etc/corosync/目录下,确保为400
]# crm_mon //查看集群节点
Last updated: Sun May 29 21:53:09 2016 Last change: Sun May 29 20:09:08 2016 by root via cibadmin on node1.magedu.com
Stack: corosync
Current DC: node1.magedu.com (version 1.1.13-10.el7-44eb2dd) - partition with quorum
2 nodes and 0 resources configured
crm的特性:
1、任何操作都需要commit提交后才会生效;
2、想要删除一个资源之前需要先将资源停止
3、可以用 help COMMAND 获取该命令的帮助
4、与Linux命令行一样,都支持TAB补全
crm有两种工作方式:
1、命令行模式:
1
2
3
4
5
6
7
]# crm status
Last updated: Mon May 30 10:07:02 2016 Last change: Mon May 30 10:06:50 2016 by hacluster via crmd on node1.magedu.com
Stack: corosync
Current DC: node1.magedu.com (version 1.1.13-10.el7-44eb2dd) - partition with quorum
2 nodes and 1 resource configured
Online: [ node1.magedu.com node2.magedu.com ]
2、交互式模式:
1
2
3
4
5
6
7
8
]# crm
crm(live)# status
Last updated: Mon May 30 10:07:08 2016 Last change: Mon May 30 10:06:50 2016 by hacluster via crmd on node1.magedu.com
Stack: corosync
Current DC: node1.magedu.com (version 1.1.13-10.el7-44eb2dd) - partition with quorum
2 nodes and 1 resource configured
Online: [ node1.magedu.com node2.magedu.com ]
1
2
3
4
5
6
7
8
9
10
11
crm(live)# help
cib manage shadow CIBs // cib管理
resource resources management // 管理资源的启动、停止等
configure CRM cluster configuration // 编辑集群配置信息
node nodes management // 集群节点管理子命令
history CRM cluster history
site Geo-cluster support
ra resource agents information center // 资源代理子命令(所有与资源代理相关的程都在此命令之下)
status show cluster status # 显示当前集群的状态信息
template Edit and import a configuration from a template //编辑或导入一个配置模板
script Cluster script management //集群脚本管理
crm(live)# configure
crm(live)configure# help
acl_target Define target access rights
_test Help for command _test
clone Define a clone //定义一个克隆
colocation Colocate resources //定义资源的约束
commit Commit the changes to the CIB //保存配置到CIB
default-timeouts Set timeouts for operations to minimums from the meta-data
delete Delete CIB objects //删除一个CIB配置
edit Edit CIB objects //编辑配置文件
erase Erase the CIB
fencing_topology Node fencing order //隔离节点顺序
filter Filter CIB objects //对CIB进行过滤
graph Generate a directed graph
group Define a group //定义一个组
load Import the CIB from a file //从文件中导入CIB
location A location preference
modgroup Modify group
monitor Add monitor operation to a primitive //监控一个资源
ms Define a master-slave resource
node Define a cluster node //定义一个集群界定
op_defaults Set resource operations defaults
order Order resources //顺序排列资源
primitive Define a resource //定义一个资源
property Set a cluster property //设置集群全局配置
verify verify the CIB with crm_verify // CIB语法验证
show display CIB objects // 显示CIB配置文件
rsc_defaults set resource defaults // 设置资源默认属性(粘性)
location a location preference // 定义位置约束优先级(默认运行于那一个节点(如果位置约束的值相同,默认倾向性那一个高,就在那一个节点上运行))
order order resources // 资源的启动的先后顺序
crm(live)resource# help
cleanup Cleanup resource status //清理资源的状态
emote Demote a master-slave resource //对一个资源降级操作
failcount Manage failcounts //管理资源的错误次数
help Show help (help topics for list of topics)
ls List levels and commands //列出等级和命令
maintenance Enable/disable per-resource maintenance mode
manage Put a resource into managed mode
meta Manage a meta attribute //管理资源的属性
migrate Migrate a resource to another node //强制对资源进行迁移
param Manage a parameter of a resource //管理资源的参数
promote Promote a master-slave resource //对一个资源升级操作
quit Exit the interactive shell //退出
refresh Refresh CIB from the LRM status
reprobe Probe for resources not started by the CRM
restart Restart a resource //重启资源
scores Display resource scores
secret Manage sensitive parameters
start Start a resource
status Show status of resources //显示资源的状态
stop Stop a resource
trace Start RA tracing //开启RA跟踪
unmanage Put a resource into unmanaged mode
unmigrate Unmigrate a resource to another node
untrace Stop RA tracing
up Go back to previous level
utilization Manage a utilization attribute
3、管理节点:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
crm(live)# node
crm(live)node# help
attribute Manage attributes
cd Navigate the level structure
clearstate Clear node state //清除节点状态
delete Delete node //删除节点
fence Fence node //隔离节点
help Show help (help topics for list of topics)
ls List levels and commands
maintenance Put node into maintenance mode
online Set node online //节点上线
quit Exit the interactive shell
ready Put node into ready mode
show Show node //显示节点的信息
standby Put node into standby //节点下线
status Show nodes' status as XML //已XML格式显示节点信息
status-attr Manage status attributes
up Go back to previous level
utilization Manage utilization attributes
4、RA资源代理:实现服务的真正启动、停止等操作
1
2
3
4
5
6
7
8
9
10
crm(live)ra# help
cd Navigate the level structure
classes List classes and providers // 为资源代理分类
help Show help (help topics for list of topics)
info Show meta data for a RA //显示资源的属性
list List RA for a class (and provider) //列出RA可管理的服务
ls List levels and commands
providers Show providers for a RA and a class
quit Exit the interactive shell
up Go back to previous level
crm(live)configure# primitive vip ocf:heartbeat:IPaddr params ip=172.18.250.79 op monitor interval=20 timeout=20
crm(live)configure# primitive webserver systemd:httpd op monitor interval=20 timeout=20
crm(live)configure# verify
crm(live)configure# commit
crm(live)# status
Last updated: Mon May 30 10:49:44 2016 Last change: Mon May 30 10:49:27 2016 by root via cibadmin on node1.magedu.com
Stack: corosync
Current DC: node1.magedu.com (version 1.1.13-10.el7-44eb2dd) - partition with quorum
2 nodes and 2 resources configured
Online: [ node1.magedu.com node2.magedu.com ]
vip (ocf::heartbeat:IPaddr): Started node1.magedu.com
webserver (systemd:httpd): Started node2.magedu.com
//定义的webserver会自动分配到node2节点上,corosync会自动实现资源均衡分配
crm(live)configure# group webservice vip webserver //定义组约束
crm(live)configure# verify
crm(live)configure# commit
crm(live)# status //资源都约束在了node1节点
Last updated: Mon May 30 10:52:53 2016 Last change: Mon May 30 10:52:31 2016 by root via cibadmin on node1.magedu.com
Stack: corosync
Current DC: node1.magedu.com (version 1.1.13-10.el7-44eb2dd) - partition with quorum
2 nodes and 2 resources configured
Online: [ node1.magedu.com node2.magedu.com ]
Resource Group: webservice
vip (ocf::heartbeat:IPaddr): Started node1.magedu.com
webserver (systemd:httpd): Started node1.magedu.com
测试是否实现httpd的高可用:
手动停止node1节点:
1
]# crm node standby //在250.77上手动下线node1
资源发生了迁移,并实现了httpd的高可用:
1
2
3
4
5
6
7
8
9
10
11
12
scrm(live)# status
Last updated: Mon May 30 10:59:04 2016 Last change: Mon May 30 10:57:45 2016 by root via crm_attribute on node1.magedu.com
Stack: corosync
Current DC: node1.magedu.com (version 1.1.13-10.el7-44eb2dd) - partition with quorum
2 nodes and 2 resources configured
crm(live)# status //现在是在Node1上
Last updated: Mon May 30 13:05:46 2016 Last change: Mon May 30 12:54:24 2016 by root via crm_attribute on node1.magedu.com
Stack: corosync
Current DC: node1.magedu.com (version 1.1.13-10.el7-44eb2dd) - partition with quorum
2 nodes and 3 resources configured
Online: [ node1.magedu.com node2.magedu.com ]
Resource Group: webservice
vip (ocf::heartbeat:IPaddr): Started node1.magedu.com
webnfs (ocf::heartbeat:Filesystem): Started node1.magedu.com
webmysql (systemd:mariadb): Started node1.magedu.com
]# crm node standby //node1执行standby
crm(live)# status //资源转移到了node2上
Last updated: Mon May 30 13:07:00 2016 Last change: Mon May 30 13:06:35 2016 by root via crm_attribute on node1.magedu.com
Stack: corosync
Current DC: node1.magedu.com (version 1.1.13-10.el7-44eb2dd) - partition with quorum
2 nodes and 3 resources configured
Resource Group: webservice
vip (ocf::heartbeat:IPaddr): Started node2.magedu.com
webnfs (ocf::heartbeat:Filesystem): Started node2.magedu.com
webmysql (systemd:mariadb): Started node2.magedu.com
crm(live)configure# property no-quorum-policy= //默认为stop
no-quorum-policy (enum, [stop]): What to do when the cluster does not have quorum
What to do when the cluster does not have quorum Allowed values: stop, freeze, ignore, suicide
crm(live)configure# primitive vip ocf:heartbeat:IPaddr2 params ip="172.18.250.80" lvs_support="DR" op monitor interval=15 timeout=15
crm(live)configure# primitive director systemd:ldirectord op monitor interval=15 timeout=15
crm(live)configure# group dirservice vip director
crm(live)# status
Last updated: Mon May 30 14:18:50 2016 Last change: Mon May 30 14:18:43 2016 by root via cibadmin on node1.magedu.com
Stack: corosync
Current DC: node1.magedu.com (version 1.1.13-10.el7-44eb2dd) - partition with quorum
2 nodes and 2 resources configured
Online: [ node1.magedu.com node2.magedu.com ]
Resource Group: dirservice
vip (ocf::heartbeat:IPaddr2): Started node1.magedu.com
director (systemd:ldirectord): Started node1.magedu.com
crm(live)# status //转移成功
Last updated: Mon May 30 14:32:31 2016 Last change: Mon May 30 14:32:26 2016 by root via crm_attribute on node1.magedu.com
Stack: corosync
Current DC: node1.magedu.com (version 1.1.13-10.el7-44eb2dd) - partition with quorum
2 nodes and 2 resources configured