PSSH lightweight operation and maintenance tool installation and use

Password-free login

1. First generate a secret key pair (public key and private key)

ssh-keygen

2. Check whether the generation is successful

ll /root/.ssh 

3. Copy A’s own public key and append it to B’s authorization list file authorized_keys

ssh-copy-id 192.168.1.100

4. Password-free ssh login

ssh 192.168.1.100

pssh installation

Download address: https://pypi.org/project/pssh/#files

1. Install dependency packages

yum install -y make gcc gcc++ python-devel python-pip

2. Upload the installation package and install pssh

tar zxvf pssh-2.3.1.tar.gz
cd pssh-2.3.1
python setup.py install

pssh use

pssh tool usage

app Instructions for use
pssh Run commands in parallel on multiple hosts
pscp Copy files to multiple hosts in parallel
prsync Efficiently synchronize files to multiple hosts through the rsync protocol
pslurp Copy files from multiple remote hosts to the local machine in parallel
books Kill processes on multiple remote machines in parallel

pssh tool parameters

parameter illustrate
-h List of remote hosts to execute the command; or -H user@ip:port; file content format [user@]host[:port]
-l The username of the remote machine
-P Output execution information during execution
-p Maximum number of connections allowed at one time
-o Redirect output to a file
-e Redirect execution errors to a file
-t Set the timeout for command execution
-A Prompt for password and pass password to ssh
-O To set the specific configuration of ssh parameters, refer to the ssh_config configuration file.
-x Pass multiple SSH commands. Multiple commands are separated by spaces and enclosed in quotes.
-X Same as -x but only one command can be passed at a time
-i Display standard output and standard error after each host completes execution

pssh usage example

1. pssh executes commands in parallel on multiple hosts

# 获取每台机器上的时间,先在管理机上新建 ip.txt
pssh -p 2 -i -h /root/test/ip.txt "date"

2. pscp copies files to multiple machines in parallel

# 将本地的 /root/kaishi.sh 文件复制到目标服务器的 /tmp/ 目录下
pscp -h /root/test/pssh.txt /root/kaishi.sh /tmp/
# 验证文件是否已经成功复制过去
pssh -p 2 -i -h /root/test/pssh.txt "ls /tmp/kaishi.sh"

3. prsync uses the rsync protocol to synchronize files from the local computer to the remote host

#  将本地的 /etc/sysconfig 目录递归同步到目标服务器的 /tmp/ 目录下
prsync -h /root/test/pssh.txt -l -a -r /etc/sysconfig /tmp/test/
# 验证文件是否已经成功同步过去
pssh -p 2 -i -h /root/test/pssh.txt "ls /tmp/test/"

4. pslurp copies files from remote host to local host

# 将目标服务器的 /tmp/*.log 格式的文件复制到本地的 /tmp 目录下,并更名为 test1.log 格式
pslurp -p 2  -h /root/test/pssh.txt -L /tmp -l root /tmp/*.log test1.log
# 在 /tmp/ 目录下即可看见以远端IP地址命名为目录,目录中存放复制过来的文件
ll /tmp/

5. pnuke kills the process on the remote host in parallel and kills the nginx process on the remote server

# 查看远端nginx状态
pssh -p 2 -i -h /root/test/pssh.txt "lsof -i:80"
# 杀死远端nginx进程
pnuke -p 2 -h /root/test/pssh.txt nginx

Guess you like

Origin blog.csdn.net/weixin_41166785/article/details/125504358