Use PSSH to batch operate Linux servers and psshlinux servers

Source: Internet
Author: User
Tags pscp

Use PSSH to batch operate Linux servers and psshlinux servers
Introduction

When there are more servers, one problem is how to quickly operate multiple servers in batches. I found the PSSH tool on the Internet. I tried it and found it useful. I recommend it to you.

Pssh is a lightweight management tool written in python that can execute commands on multiple servers. It also supports file copying. The python version is later than 2.4. Project address: parallel-ssh.

Install
$ wget http://parallel-ssh.googlecode.com/files/pssh-2.3.1.tar.gz$ tar -xzvf pssh-2.3.1.tar.gz$ cd pssh-2.3.1$ python setup.py install
PSSH Parameters
  • -H: the remote host list file for executing commands. The file content format is [user @] host [: port].
    • Such as test@127.0.0.2: 229
  • -H: run the command host in the format of user @ ip: port.
  • -L User Name of the remote machine
  • -P maximum number of connections allowed at a time
  • -P: Output execution information during execution
  • -O: redirects the output content to a file.
  • -E: The execution error is redirected to a file.
  • -T: Set the command execution timeout.
  • -A prompts you to enter the password and pass the password to ssh (if the machine is connected by an ssh key, you do not need to add-)
  • -O: Set ssh options
  • -X additional ssh parameters can be set to multiple. Different parameters are separated by spaces.
  • -X is the same as-x, but only one parameter can be set.
  • -I: standard output and standard errors are displayed after each host is executed.
Usage example

Create a hosts file hosts.txt to store the list of machines to be operated in the format of [user @] host [: port]:

user1@127.0.0.1:1254user2@127.0.0.2127.0.0.3

Use pssh to view the uptime of all servers:

$ pssh -i -h hosts.txt 'uptime'

You can replace update with another command as needed.

Additional tools

After pssh is installed, some useful tools are attached, mainly including:

1. pscp

Role: Transfers files to multiple hosts, similar to scp

Example:

$ pscp -h hosts.txt foo.txt /home/foo.txt
2. pslurp

Role: Copy files from multiple remote machines to a Local Machine

Example:

$ pslurp -h hosts.txt /etc/hosts local_dir
3. pnuke

Role: Killing processes on remote hosts in parallel

Example:

$ pnuke -h hosts.txt -l root java
4. prsync

Purpose: Use rsync to synchronize data from a local computer to a remote host.

Example:

$ prsync -r -h hosts.txt foo /home/foo
References

Http://www.opstool.com/article/266

Http://linux.die.net/man/1/pssh


How to manage multiple servers at the same time

First, 10 servers are not much, but you are very conscious. in addition, if there are 10 direct and unified management systems, you can use multi-window tools such as cssh or some pssh batch execution tools for operation management at the same time, which does not require any cost. again, you should monitor the system and use an open-source tool to view it in a centralized manner. open-source tools such as ganglia nagios are enough. again, the system configuration can be completed by writing scripts on your own after your server is standardized, or the open-source puppet can be used for the complexity. finally, if you are very powerful or feel that your current tools are too compact, you can write some management platforms by yourself. This depends on your specific needs. END: demand drives production. There are many details that need to be considered. PS: Generally, for the sake of security, there will be a unified management Portal Server, so that your management structure will change again, and the relationship between security and efficiency will be selected.

How to manage multiple servers at the same time

First, 10 servers are not much, but you are very conscious. in addition, if there are 10 direct and unified management systems, you can use multi-window tools such as cssh or some pssh batch execution tools for operation management at the same time, which does not require any cost. again, you should monitor the system and use an open-source tool to view it in a centralized manner. open-source tools such as ganglia nagios are enough. again, the system configuration can be completed by writing scripts on your own after your server is standardized, or the open-source puppet can be used for the complexity. finally, if you are very powerful or feel that your current tools are too compact, you can write some management platforms by yourself. This depends on your specific needs. END: demand drives production. There are many details that need to be considered. PS: Generally, for the sake of security, there will be a unified management Portal Server, so that your management structure will change again, and the relationship between security and efficiency will be selected.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.