yinian 发表于 2019-2-17 08:24:55

Linux PSSH

下面是pssh的安装、配置与使用,假设试图通过1台主机器(主节点192.168.21.200)去修改从机器(从节点192.168.21.201)
1.PSSH安装
(系统中已经安装有python)
只需要在主节点上安装pssh
下载地址:
https://files.pythonhosted.org/packages/60/9a/8035af3a7d3d1617ae2c7c174efa4f154e5bf9c24b36b623413b38be8e4a/pssh-2.3.1.tar.gz
解压后进入该目录,安装
wget https://files.pythonhosted.org/packages/60/9a/8035af3a7d3d1617ae2c7c174efa4f154e5bf9c24b36b623413b38be8e4a/pssh-2.3.1.tar.gz
tar -zxvf pssh-2.3.1.tar.gz
cd pssh-2.3.1
python setup.py build
python setup.py install
2.PSSH配置
配置主要有两项内容:
一、从结点的IP列表文件;二、主节点到从节点的ssh无密钥登录
IP列表文件就是将从结点的IP按行存在一个文件里,我给它命名为hostlist.txt,
下面是ssh无密钥登录
由于很多操作需要有sudo权限,所以尽量ssh无密钥登录到从节点的root用户下。
# ssh-keygen         (然后按提示输入信息)
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:+8RJmmCwgEREs0wJN7l1Vz5jybw4714krEbcq1SsXNc root@docker
The key's randomart image is:
+-------+
|*B+.   ..      |
|+++.. . .+ .   |
|.o.o.. .O      |
|.. o . * + .   |
|    . o S X o E|
|   . + & *   |
|      X * .    |
|       o = .   |
|      ..+      |
+---------+
# ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.21.201      (将密钥复制到从节点,需要输入密码)
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.21.201 (192.168.21.201)' can't be established.
ECDSA key fingerprint is SHA256:pE3X5rj4mSUgLaKCfrpRMa0gUbmL/8WIUesRUhszNs8.
ECDSA key fingerprint is MD5:b5:48:05:27:69:e1:a1:82:2f:86:dd:66:42:8a:25:5c.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.21.201's password:
Number of key(s) added: 1
Now try logging into the machine, with:   "ssh 'root@192.168.21.201'"
and check to make sure that only the key(s) you wanted were added.
#
3.PSSH使用
# vim hostlist.txt
# more hostlist.txt
192.168.21.201
#
# ls
anaconda-ks.cfg   dstat-0.7.2-12.el7.noarch.rpminitial-setup-ks.cfg模板图片下载桌面
docker-install.txthostlist.txt                   公共                  视频文档音乐
#例如将主节点的/root/dstat-0.7.2-12.el7.noarch.rpm拷贝到从节点的/home/目录下
# pscp -h hostlist.txt -r dstat-0.7.2-12.el7.noarch.rpm/home/
09:53:10 192.168.21.201
#
# ip a
1: lo:mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens33:mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:a6:22:fe brd ff:ff:ff:ff:ff:ff
inet 192.168.21.201/24 brd 192.168.21.255 scope global noprefixroute ens33
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fea6:22fe/64 scope link
valid_lft forever preferred_lft forever
# ls
dstat-0.7.2-12.el7.noarch.rpm
#
例如在从节点建立新目录/home/testssh
# pssh -h hostlist.txt -P "mkdir -p /home/testssh"
09:54:39 192.168.21.201
#
# ls
dstat-0.7.2-12.el7.noarch.rpmtestssh
#



页: [1]
查看完整版本: Linux PSSH