Batch management execution
pssh command is a tool written in Python that can execute commands on multiple servers. It also supports copying files. It is an outstanding tool among similar tools. It is similar to pdsh. I personally think it is simpler than pdsh. It must be used on each server. Configure key authentication access.
In CentOS system environment, introduce the installation method of yum and source code installation:
yum method
yum install pssh
Compile and install
wget http://parallel-ssh.googlecode.com/files/pssh-2.3.1.tar.gz
tar xf pssh-2.3.1.tar.gz
cd pssh-2.3.1/
python setup.py install
--version: View version
--help: View help, that is, this information
-h: host file list, content format "[user@]host[:port]"
-H: host string, content format "[user@]host[:port]"
-: Username used to log in
-p: Number of concurrent threads [optional]
-o: Output file directory [optional]
-e: Error input file [optional]
-t: TIMEOUT timeout setting, 0 unlimited [optional]
-O: SSH options
-v: verbose mode
-A: Manually enter password mode
-x: Use whitespace, quotes, and backslashes for additional command line parameters.
-X: Additional command line parameters, single parameter mode, same as -x
-i: Each server handles information output internally
-P: Print out the server return information
Get the uptime of each server:
# pssh -h ip.txt -i uptime
[1] 11:15:03 [SUCCESS] Mar.mars.he
11:15:11 up 4 days, 16:25, 1 user, load average: 0.00, 0.00, 0.00
[2] 11:15:03 [SUCCESS] Jan.mars.he
11:15:12 up 3 days, 23:26, 0 users, load average: 0.00, 0.00, 0.00
[3] 11:15:03 [SUCCESS] Feb.mars.he
11:15:12 up 4 days, 16:26, 2 users, load average: 0.08, 0.02, 0.01
Check the running status information of mysql replication IO/SQL thread on each server:
# pssh -h IP.txt -i "/usr/local/mysql/bin/mysql -e 'show slave status \G'"|grep Running:
Slave_IO_Running: yes
Slave_SQL_Running: Yes
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Save the results of each server run:
# pssh -h IP.txt -i -o /tmp/pssh/ uptime
[1] 11:19:47 [SUCCESS] Feb.mars.he
11:19:55 up 4 days, 16:31, 2 users, load average: 0.02, 0.03, 0.00
[2] 11:19:47 [SUCCESS] Jan.mars.he
11:19:56 up 3 days, 23:30, 0 users, load average: 0.01, 0.00, 0.00
[3] 11:19:47 [SUCCESS] Mar.mars.he
11:19:56 up 4 days, 16:30, 1 user, load average: 0.00, 0.00, 0.00
Let’s take a look at the files and their contents under /tmp/pssh/
# ll /tmp/pssh/
Total usage 12
-rw-r--r--. 1 root root 70 December 1 11:19 Feb.mars.he
-rw-r--r--. 1 root root 70 December 1 11:19 Jan.mars.he
-rw-r--r--. 1 root root 69 December 1 11:19 Mar.mars.he
# cat /tmp/pssh/*
11:19:55 up 4 days, 16:31, 2 users, load average: 0.02, 0.03, 0.00
11:19:56 up 3 days, 23:30, 0 users, load average: 0.01, 0.00, 0.00
11:19:56 up 4 days, 16:30, 1 user, load average: 0.00, 0.00, 0.00
The above introduction is a small part of the pssh command. You can use it to suit your own scenarios and maximize its effectiveness.