clustershell的使用

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

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值