Linux 集群管理工具Clustershell,pssh

来源:互联网 发布:thinkphp sql注入漏洞 编辑:程序博客网 时间:2024/05/22 13:02

在集群的现在,管理成千上万的Linux机子成为了一个难题,不能再使用一台一台登录主机去进行管理了,工作量无疑是非常巨大的,这里我们可以借助Clustershellpssh管理,它原理是自动登录主机集群帮我们将脚本进行执行,或者是文件的操作等。

演示Clustershell

使用的是Centos7如操作,我们只需要在一台主机上操作即可完成对集群机子的所有配置
master host.com #主机
cluster1 2.host.com #节点1
cluster2 3.host.com #节点2
cluster3 4.host.com #节点3

免密码登录

主机使用ssh登录1,2,3节点必须是免密码登录方式,不能是首次登录,因为Clustershell不会自动输入交互命令,例如第一次登录主机会有下面提示。

ssh root@2.host.comThe authenticity of host '2.host.com (192.168.0.20)' can't be established.ECDSA key fingerprint is d4:5d:d6:e6:bc:70:86:1b:42:32:aa:6b:86:a6:34:d4.Are you sure you want to continue connecting (yes/no)?

Clustershell不能处理会提示以下错误

[1] 11:32:17 [FAILURE] 2.host.com Exited with error code 255

生成密钥

ssh-keygen -t rsa

公钥内容复制到各个节点上

scp ~/.ssh/id_rsa.pub 192.168.0.20:/root/.ssh/authorized_keysscp ~/.ssh/id_rsa.pub 192.168.0.21:/root/.ssh/authorized_keysscp ~/.ssh/id_rsa.pub 192.168.0.22:/root/.ssh/authorized_keys

配置ClusterShell

vim /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.adm: example0oss: example4 example5mds: example6io: example[4-6]compute: example[32-159]gpu: example[156-159]all: example[4-6,32-159]demo: [1-3].host.com

以上我们定义了一个分组:demo,通过这个分组可连接1.host.com,2.host.com,3.host.com,如果此三个节点对应的IP地扯没有映射有连接失败,可设置/etc/hosts对应关系

cat /etc/hosts127.0.0.1 localhost::1         localhost localhost.localdomain localhost6 localhost6.localdomain6192.168.0.20 1.host.com192.168.0.21 2.host.com192.168.0.22 3.host.com

clush命令几个重要的参数

  • -b : 相同输出结果合并
  • -w : 指定节点
  • -a : 所有节点
  • -g : 指定组
  • –copy : 群发文件

各个节点执行ls命令

clush -g demo "ls"

创建文件

clush -g demo "touch /root/demo.txt"

群发文件

clush -g demo --copy groups --dest /root  

演示pssh

安装

yum install pssh -y

编辑节点IP地扯
vim /root/hosts.txt

1.host.com2.host.com3.host.com

节点执行命令

pssh -H hosts.txt -P "ls"
原创粉丝点击