clustershell是Python写来专门操作集群的,以group为类,分别操作,后面使用就会感受到
一、安装
yum install -y clustershell
二、配置group
vi /etc/clustershell/groups.d/local.cfg
进行编辑该文件:
# ClusterShell groups config local.cfg
#
# Replace /etc/clustershell/groups
#
# Note: file auto-loaded unless /etc/clustershell/groups is present
#
# See also groups.d/cluster.yaml.example for an example of multiple
# sources single flat file setup using YAML syntax.
#
# Feel free to edit to fit your needs.
all:node[1-3]
zk: node[2-3]
cm:node[1-3]
因为我的服务器的名称是以node01,node02,node03,所以写成上面这样。
三、使用
clush命令:clush -参数 操作
参数:
-g 后面指定设置的组
-a 表示所有的组
-w 后面跟主机节点,多个主机中间用逗号隔开
-x 表示去掉某个节点进行操作。后面跟主机节点,多个主机中间用逗号隔开
-X 表示去掉某个组进行操作,多个组之间用逗号隔开
-b 相同输出结果合并
案例:clush -g all -b 'yum install -y curl'这个命令是将所有的服务器进行yum install -y tree
运行结果:
[root@node01 .ssh]# clush -g all -b 'yum install -y tree'
---------------
node01
---------------
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Install Process
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* epel: hkg.mirror.rackspace.com
* extras: mirrors.aliyun.com
* updates: mirrors.cqu.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package tree.x86_64 0:1.5.3-3.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
tree x86_64 1.5.3-3.el6 base 36 k
Transaction Summary
================================================================================
Install 1 Package(s)
Total download size: 36 k
Installed size: 65 k
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : tree-1.5.3-3.el6.x86_64 1/1
Verifying : tree-1.5.3-3.el6.x86_64 1/1
Installed:
tree.x86_64 0:1.5.3-3.el6
Complete!
---------------
node02
---------------
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Install Process
Loading mirror speeds from cached hostfile
* base: mirrors.163.com
* epel: mirrors.aliyun.com
* extras: mirrors.163.com
* updates: mirrors.aliyun.com
Package tree-1.5.3-3.el6.x86_64 already installed and latest version
Nothing to do
---------------
node03
---------------
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Install Process
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* epel: mirrors.aliyun.com
* extras: mirrors.163.com
* updates: mirrors.aliyun.com
Package tree-1.5.3-3.el6.x86_64 already installed and latest version
Nothing to do
补充:在后来重新换的机器yum安装就不成功了,会报错:
No package clustershell available
解决方法:
sudo yum install epel-release