ClusterSSH - Manage multiple ssh session at the same Time

May 16, 2014 | By
| Reply More

Most of server administrator run SSH for maintaining his servers. When he manages a lot of servers, then he may need to open multiple SSH sessions. If the maintenance activity is using the same commands on each server, typing commands one-by-one for each server may consume more times. Is it possible to run commands on one server and duplicate them to another server? On Linux, you can. We will use ClusterSSH command to solve this situation.

What is ClusterSSH

ClusterSSH is an application which can manage multiple SSH session at the same time. With ClusterSSH, you can perform same commands on the server group (cluster) at the same time. This will ensure that all servers are kept in sync.

Installation

Using package manager

On Debian / Ubuntu based Linux :

$ sudo apt-get install clusterssh

On RedHat / CentOS based Linux :

# yum -y install clusterssh

Using tarball

To make sure that you installed the latest version, you can download ClusterSSH source file and compile it manually. At the moment this article is written, the latest version of ClusterSSH is 3.28. The source can be downloaded from SourceForge sites.

Once you have the download, here are the steps how to install it.

1. Extract the source file
2. Go to the folder where the source file was extracted
3. Type :

$ ./configure
$ make
# make install

4. Done

Please note, that ClusterSSH use Perl and it’s library to run. On my Zorin Linux (Ubuntu based) I found some errors when compile ClusterSSH.

Cannot find X include files via /include
Cannot find X includes files anywhere

Error Library X11

To solve this error, I ran :

$ sudo apt-get install libx11-dev

Once the installation of libx11-dev finished, I tried to compile it again and it worked !

Can’t locate Tk.pm

Error Tk module

ClusterSSH needs some Perl module. The solution for this error is by installing Tk.pm module. The easiest way to install it is using CPAN.

$ cpan -i Tk

After installing Tk.pm is done, try to type cssh via console.

Can’t locate X11/Protocol.pm

Error X11 Protocol

If you experiencing this error, you can install X11/Protocol.pm module via CPAN.

$ cpan -i X11::Protocol

After installing Tk.pm is done, try to type cssh via console.

How to use ClusterSSH

To run ClusterSSH, you can type

$ cssh -l username server_ip_address

But the power of ClusterSSH is to manage multiple SSH session. You can also type :

$ cssh -l username server_ip_address_1 server_ip_address_2 server_ip_address_n

But this might not a good way it you have a lot of servers. Another way to run multiple SSH session is put the address of each server in CSSH configuration file. There are two types of configuration files. First is global configuration file. This file is located in /etc/clusters. Second is .csshrc which located in users home directory.

In this article, we are using .csshrc file to configure ClusterSSH. For example, we add cluster name (group name) called servers. Then we add the member of its group. Here’s the .csshrc file look like :

clusters=servers
servers=10.0.6.12 10.0.14.6 10.0.6.149

To run the cluster, type :

$ cssh -l pungki.arianto servers -T “Server Farm”

Where :
1. pungki.arianto is the login name of those servers
2. -T “Server Farm” will give tags Server Farms to each SSH window.

ClusterSSH in action

The next step, you need to enter password for each server. You will see an administration console which has header Server Farm (3). When you want to run command(s) to all servers, you need to type it in the administration console box. You may not see what you type in the box, but you will see it appear on every servers.

If you don’t want to echo your command to all servers, you can disable host(s) that you want to exclude. Just click Hosts menu in administration console and choose which server you want to exclude.

Important

The advantage of echoing all commands to all servers is to ensure that all servers are kept synced. And of course we will save time from repeating the same commands to all servers. But when you execute the wrong commands, it will impact to all servers. Please make sure that you’re typing a correct command before hit Enter button.

Conclusion

ClusterSSH can help administrators to run the same command across servers at the same time, as long its used with care. As usual, we can always to type man cssh or cssh -h to display its manual page and explore more detail.

Filed Under : LINUX HOWTO, OPEN SOURCE TOOLS

Tagged With : ,

Free Linux Ebook to Download

Leave a Reply

Commenting Policy:
Promotion of your products ? Comment gets deleted.
All comments are subject to moderation.