在集群的現(xiàn)在,管理成千上萬(wàn)的
Linux機(jī)子成為了一個(gè)難題,不能再使用一臺(tái)一臺(tái)登錄主機(jī)去進(jìn)行管理了,工作量無(wú)疑是非常巨大的,這里我們可以借助Clustershell與pssh管理,它原理是自動(dòng)登錄主機(jī)集群幫我們將腳本進(jìn)行執(zhí)行,或者是文件的操作等,當(dāng)初大豬是一臺(tái)一臺(tái)去管理的,一個(gè)字:好累呀。
使用指南
Clustershell工具
使用的是Centos7如操作,我們只需要在一臺(tái)主機(jī)上操作即可完成對(duì)集群機(jī)子的所有配置
master host.com #主機(jī)
cluster1 2.host.com #節(jié)點(diǎn)1
cluster2 3.host.com #節(jié)點(diǎn)2
cluster3 4.host.com #節(jié)點(diǎn)3
免密碼登錄
主機(jī)使用ssh登錄1,2,3節(jié)點(diǎn)必須是免密碼登錄方式,并且不能是首次登錄,因?yàn)?code>Clustershell不會(huì)自動(dòng)輸入交互命令,例如第一次登錄主機(jī)會(huì)有下面提示。
ssh root@2.host.com
The 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不能自動(dòng)處理,會(huì)提示以下錯(cuò)誤
[1] 11:32:17 [FAILURE] 2.host.com Exited with error code 255
生成密鑰
ssh-keygen -t rsa
公鑰內(nèi)容復(fù)制到各個(gè)節(jié)點(diǎn)上
scp ~/.ssh/id_rsa.pub 192.168.0.20:/root/.ssh/authorized_keys
scp ~/.ssh/id_rsa.pub 192.168.0.21:/root/.ssh/authorized_keys
scp ~/.ssh/id_rsa.pub 192.168.0.22:/root/.ssh/authorized_keys
配置ClusterShell
vim /etc/clustershell/groups.d/local.cfg
內(nèi)容如下
# 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: example0
oss: example4 example5
mds: example6
io: example[4-6]
compute: example[32-159]
gpu: example[156-159]
all: example[4-6,32-159]
demo: [1-3].host.com
以上我們定義了一個(gè)分組:demo,通過(guò)這個(gè)分組可連接1.host.com,2.host.com,3.host.com,如果此三個(gè)節(jié)點(diǎn)對(duì)應(yīng)的IP地扯沒(méi)有映射有連接失敗,可設(shè)置/etc/hosts對(duì)應(yīng)關(guān)系
cat /etc/hosts
127.0.0.1 localhost
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.0.20 1.host.com
192.168.0.21 2.host.com
192.168.0.22 3.host.com
clush命令幾個(gè)重要的參數(shù)
- -b : 相同輸出結(jié)果合并
- -w : 指定節(jié)點(diǎn)
- -a : 所有節(jié)點(diǎn)
- -g : 指定組
- --copy : 群發(fā)文件
各個(gè)節(jié)點(diǎn)執(zhí)行ls命令
clush -g demo "ls"
創(chuàng)建文件
clush -g demo "touch /root/demo.txt"
群發(fā)文件
clush -g demo --copy groups --dest /root
pssh工具
安裝
yum install pssh -y
編輯節(jié)點(diǎn)IP地扯
vim /root/hosts.txt
1.host.com
2.host.com
3.host.com
節(jié)點(diǎn)執(zhí)行命令
pssh -H hosts.txt -P "ls"
