If you maintain multiple Linux servers, there are cases where you want to run the same command(s) on all the servers. For example, you may want to install/upgrade packages, patch the kernel, and update configurations, etc. It will be a tedious job if you have to log in to each server and run the same commands manually. This post is about an administrative tool that allows you to run the same commands on many different machines at once.
ClusterSSH enables you to make the same change on multiple hosts at once. It provides a special console interface where anything you type into the console is automatically sent to as many hosts as you want.
Install ClusterSSH on Linux
To install ClusterSSH on Ubuntu, Debian or Linux Mint:
To install ClusterSSH on CentOS or RHEL, first you need to set up EPEL repository, and then run the following.
To install ClusterSSH on Fedora, simply run:
After installation, the first step is to define a cluster of hosts that you want to run commands on. To do that, create a system-wide ClusterSSH configuration file as follows.
clusters = my_cluster my_cluster2 my_cluster = host1 host2 host3 host4 my_cluster2 = host5 host6
If you want a user-specific ClusterSSH configuration, simply use ~/.csshrc instead of /etc/clusters. In the above example configuration, I define two clusters: "my_cluster" consisting of four hosts, and "my_cluster2" with two hosts. A cluster is a group of hosts which you want to log in to, and run commands on.
When you launch ClusterSSH with any user-defined cluster, it will use ssh to log in to individual hosts in the cluster, and run any user-typed commands on the hosts.
To launch ClusterSSH, run cssh command as follows.
In the above, "dev" is a login ID for all the hosts in the cluster, and "my_cluster" is the cluster name.
If you want, you can specify individual hostnames instead of the cluster name.
Once cssh command is executed, it will pop up XTerm windows for individual hosts, as well as a small window labeled "CSSH ", which is ClusterSSH console window. Whatever you type in the console window will simultaneously appear in the XTerm windows of individual hosts. Essentially, you control all XTerm windows via the single console window.
If you want to run some commands to a specific XTerm window, you can simply switch focus to the Xterm window, and type the commands as you usually would.
The following screenshot shows ClusterSSH in action, where there are five hosts in the cluster, and the console window in the upper left corner is where you are supposed to type the commands to run on all five hosts.
Subscribe to Xmodulo
You can have daily Linux tutorials and FAQs delivered to your email inbox. Simply enter your email address below to subscribe to our mailing list. You will receive hands-on guides and carefully written tutorials related to Linux, everything for free.