The article directories
Check the installation environment Install PSSHPSSH command package command using PSSH remote batch execute command PSCP parallel transfer file to remote Prsync parallel transfer file to remote Pslurp pull remotely to local Pnuke remote batch Killall
Check the installation environment
PSSH requires Python 2.4 or above, first query your own Python version in CentOS, the query command is as follows:
[root@hadoop-master ~]# python --version
Python 2.7.5
If you haven’t already installed Python, you can install Basic Installation of Python for Beginners under Linux.
Install the PSSH
wget https://pypi.python.org/packages/60/9a/8035af3a7d3d1617ae2c7c174efa4f154e5bf9c24b36b623413b38be8e4a/pssh-2.3.1.tar.gz
tar xf pssh-2.3.1.tar.gz -C /usr/local/pssh/
cd /usr/local/pssh/pssh-2.3.1/
python setup.py install
Check the installation
[root@hadoop-master pssh-2.3.1]# pssh --help
Usage: pssh [OPTIONS] command [...]
Options:
--version show program's version number and exit
--help show this help message and exit
-h HOST_FILE, --hosts=HOST_FILE
hosts file (each line "[user@]host[:port]")
-H HOST_STRING, --host=HOST_STRING
additional host entries ("[user@]host[:port]")
-l USER, --user=USER username (OPTIONAL)
-p PAR, --par=PAR max number of parallel threads (OPTIONAL)
-o OUTDIR, --outdir=OUTDIR
output directory for stdout files (OPTIONAL)
-e ERRDIR, --errdir=ERRDIR
output directory for stderr files (OPTIONAL)
-t TIMEOUT, --timeout=TIMEOUT
timeout (secs) (0 = no timeout) per host (OPTIONAL)
-O OPTION, --option=OPTION
SSH option (OPTIONAL)
-v, --verbose turn on warning and diagnostic messages (OPTIONAL)
-A, --askpass Ask for a password (OPTIONAL)
-x ARGS, --extra-args=ARGS
Extra command-line arguments, with processing for
spaces, quotes, and backslashes
-X ARG, --extra-arg=ARG
Extra command-line argument
-i, --inline inline aggregated output and error for each server
--inline-stdout inline standard output for each server
-I, --send-input read from standard input and send as input to ssh
-P, --print print output as we get it
Example: pssh -h hosts.txt -l irb2 -o /tmp/foo uptime
PSSH package command
Command specific use
First, edit a hosts. TXT file to record the host address to be operated. The following is the one configured by my host, in which hadoopy-slave2 and
hadoopy-slave3 are in shutdown state
[root@hadoop-master pssh]# cat hosts.text
hadoop-slave1
hadoop-slave2
hadoop-slave3
PSSH remote batch execution command
#-h followed by the host ip file, file data format [user@]host[:port]
#-P Displaying output contents
The specific use
[root@hadoop-master pssh]# pssh -P -h hosts.text uptime
hadoop-slave1: 13:55:14 up 1 day, 4:03, 0 users, load average: 0.00, 0.01, 0.05
[1] 13:55:31 [SUCCESS] hadoop-slave1
[2] 13:55:33 [FAILURE] hadoop-slave2 Exited with error code 255
[3] 13:55:33 [FAILURE] hadoop-slave3 Exited with error code 255
To enter a password, use the following command:
[root@hadoop-master pssh]# pssh -A -h hosts.text uptime
If it’s a executive shell command
, you can do something like this
[root@hadoop-master pssh]# pssh -h hosts.text "source /etc/profile"
[1] 21:01:46 [SUCCESS] hadoop-slave3
[2] 21:01:46 [SUCCESS] hadoop-slave2
[3] 21:01:46 [SUCCESS] hadoop-slave1
PSCP transfers files to remote in parallel
File transfer, but remote directory creation is not supported
[root@hadoop-master pssh]# pscp -r -h hosts.text ./* /usr/local
[1] 14:10:31 [SUCCESS] hadoop-slave1
[2] 14:10:34 [FAILURE] hadoop-slave2 Exited with error code 1
[3] 14:10:34 [FAILURE] hadoop-slave3 Exited with error code 1
Prsync transfers files to remote locations in parallel
File transfer, and support remote new directory
[root@hadoop-master pssh]# pscp -r -h hosts.text hosts.text /usr/local/pssh/
[1] 14:17:18 [FAILURE] hadoop-slave1 Exited with error code 1
[2] 14:17:21 [FAILURE] hadoop-slave2 Exited with error code 1
[3] 14:17:21 [FAILURE] hadoop-slave3 Exited with error code 1
contrast
[root@hadoop-master pssh]# prsync -r -h hosts.text hosts.text /usr/local/pssh/
[1] 14:18:08 [SUCCESS] hadoop-slave1
[2] 14:18:11 [FAILURE] hadoop-slave2 Exited with error code 255
[3] 14:18:11 [FAILURE] hadoop-slave3 Exited with error code 255
Pslurp pulls from remote to local
Pslurp will pull the file from the remote to the local, automatically create the directory named remote host IP in the local, and put the pulled file in the corresponding host IP directory
format: pslurp-h ip.txt-l < Local directory & GT; < Remote directory/file & GT; < Local renaming & GT;
[root@hadoop-master pssh]# pslurp -h hosts.text -L /usr/local/test /usr/local/pssh/hosts.text psshtest
[1] 14:26:49 [SUCCESS] hadoop-slave1
[2] 14:26:52 [FAILURE] hadoop-slave2 Exited with error code 1
[3] 14:26:52 [FAILURE] hadoop-slave3 Exited with error code 1
This will create the folder directory based on the configured IP or host
drwxr-xr-x. 2 root root 22 Agu 11 14:26 hadoop-slave1
drwxr-xr-x. 2 root root 6 Agu 11 14:24 hadoop-slave2
drwxr-xr-x. 2 root root 6 Agu 11 14:24 hadoop-slave3
Pnuke remote mass killall
[root@hadoop-master pssh]# pnuke -h hosts.text java
[1] 14:32:04 [SUCCESS] hadoop-slave1
[2] 14:32:06 [FAILURE] hadoop-slave2 Exited with error code 255
[3] 14:32:06 [FAILURE] hadoop-slave3 Exited with error code 255