Running commands across multiple servers with clusterssh


I periodically need to perform repetitive maintenance operations (e.g., patching systems) on groups of servers, which typically requires me to run a similar set of commands on multiple hosts. To make my life easier, I use the super useful clusterssh utility to interactively run commands across a group of servers.

Cluster SSH is super easy to configure, and uses the concept of a “cluster” to define a group of similar nodes. To get up and running with clusterssh, you will first need to run cssh with the “-u” option to generate a configuration file (this step is optional, but creating a config file reduces start up time):

$ cssh -u > HOME/.csshrc

Once the configuration file is created, you can open the file in a text editor, and change the settings to fit your administration preferences. Some of the settings that can be changed are ssh connection parameters, the placement of xterms on your screen, the placement of the master command window, window titles, etc. In additional to modifying look and feel type items, you also need to add one or more clusters, which are logical groupings of machines. On one of my desktops, I have a “backup” cluster that I use to connect to our master and media servers, a “web” cluster to connect to our web servers, an “app” cluster to connect to our application servers, and a “db” cluster to connect to our database servers. To define a new cluster, you can add a group description followed by an equal sign and one or more hosts, and then register that grouping using the “clusters” key word. Here are the entries from my .csshrc file:

clusters = backup web app db backup = nbmed01 nbmed02 nbmed03 nbmed04 nbmas01 nbmas02 web = web01 web02 web03 web04 web05 web06 web07 web08 app = app01 app02 db = db01 db02

After the configuration settings are adjusted and one ore more clusters are defined, you can run the cssh utility with the name of the cluster to connect to:

$ cssh web

This wil open up one xterm window per server, and create an SSH connection to the server. If you have RSA or DSA keys set up, each xterm window will display a prompt on the server. In addition to opening one xterm window per server, cssh will also create a command window to send commands to all of the servers that you are connected to (you can also type into individual xterms, which is useful for running commands on just one system). This makes patching, host files updates (when you can’t completely depend on DNS) and the such super super easy! This is some serious bling yizos! Jeah!

This article was posted by Matty on 2007-04-04 19:05:00 -0400 EDT