Tag Archive : remote

/ remote

Running Command on Multiple Servers at Once

December 9, 2015 | Article | No Comments

Maintaining multiple servers is not an easy job. 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, update configuration, etc. It would be tedious if you have to log in to each server and run the same routine manually.

In this article, we will discuss a way to log in to some server and run the same command on many different machines at once.

In this article, I use:

  1. Slackware64 14.0 as client machine
  2. Ubuntu 12.10 as client machine
  3. Fedora 17 as client machine
  4. ClusterSSH

ClusterSSH

The administrative tool we have is ClusterSSH. It provides a special console interface where anything you type into the console is automatically sent to as many hosts as you want.

You might visit the official ClusterSSH site for more information.

Installation

Package Manager Way

To install ClusterSSH on Ubuntu, Debian or Linux Mint you can use following command:

sudo apt-get install clusterssh

To install ClusterSSH on CentOS or RHEL, first you need to set up EPEL repository, and then run the following:

sudo yum install clusterssh

Generic Way

Installing ClusterSSH from source is really simple. We will cover how to install ClusterSSH in generic way so we can apply it to various OS.

Clone the source code.

git clone git://github.com/duncs/clusterssh

Or you can download the source code from sourceforge: here

I will focus on the source code cloned from github.

Go to the source code root directory.

First, build the ClusterSSH. ClusterSSH use a perl-based script to configure itself.

perl Build.PL

At some points, ClusterSSH need dependencies that might not installed on your system. To install the dependencies, do following:

./Build installdeps

Once the dependencies are fulfilled, next invoke following commands:

./Build
./Build test
./Build install

Configure ClusterSSH

Once installation finished, 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 as /etc/clusters and write following:

clusters = my_cluster my_cluster2
my_cluster = host1 host2 host3 host4
my_cluster2 = host5 host6

A cluster is a group of hosts which you want to log in to, and run commands on. Here we specify two clusters: my_cluster and my_cluster2 with respective machine there. Of course the host1 is the host in hostname or IP address format.

If you want a user-specific ClusterSSH configuration, simply use ~/.csshrc instead of /etc/clusters.

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.

Launch ClusterSSH

To launch ClusterSSH, run cssh command as follows:

cssh -l userid my_cluster

Where “userid” 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.

cssh -l userid host1 host2 host3

Once cssh command is executed, it will pop up XTerm windows for individual hosts, as well as a small window labeled “CSSH [2]“, 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.

Troubleshoot

This is the troubleshoot which come to me, so I won’t cover all possible troubleshoot. You can conform on ClusterSSH page for more information.

No X11-Protocol Perl Module

If you have following error message when execute cssh:

Can't locate X11/Protocol.pm in @INC (@INC contains: /usr/local/bin/../lib/perl5 /usr/local/bin/../lib /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at /usr/local/share/perl5/App/ClusterSSH.pm line 29.
BEGIN failed--compilation aborted at /usr/local/share/perl5/App/ClusterSSH.pm line 29.
Compilation failed in require at /usr/local/bin/cssh line 11.
BEGIN failed--compilation aborted at /usr/local/bin/cssh line 11.

Then you possibly don’t install X11-Protocol perl module.

Download the packages on http://search.cpan.org/CPAN/authors/id/S/SM/SMCCAM/X11-Protocol-0.56.tar.gz

You can follow guide on how to install perl modules by:

tar -xzvf X11-Protocol-0.56.tar.gz
cd X11-Protocol-0.56
perl Makefile.PL
make
make test
make install

There are some ways for accessing Raspberry Pi: access Pi directly or indirectly. You might at least try one of thus method for connecting your Pi to your PC.

The direct access involving access without any medium. You connect screen (LCD screen, for example), keyboards, mice, etc to your Pi. This way, your Raspberry Pi act as normal computer. You operate it like you operate your PC. This method has a drawback, whenever you want to use Pi you must provide appropriate input and output device (keyboard, mouse, screen).

Another way to access Pi is using indirect access. This method involving other medium to access Pi, technically a network. In this term, your Pi is connect to a network and you can access the Pi over the network. SSH and VNC are the good example of this. This method demand us to provide good network connection if you want a good connection.

Accessing Pi over network is good, you don’t need other peripheral / device such as keyboard, mouse, or LCD screen. If you want to do thing graphically you can use VNC (Virtual Network Computing). However, using VNC is somehow slow because the application and desktop environment are rendered both on your Pi and your desktop. VNC also require better network as it sends picture / screen image over time.

There is a better solution for this problem. Instead of rendering the graphic on Pi, why don’t we render it on our local computer? This way, Pi only send us minimal packet. Using this method, we can also use keyboard and mouse on our local computer, just like indirect access do.

In this article we will discuss about other way to remote accessing your desktop without VNC. If in other article we use X.org server on Linux & Unix, on this article we still use X but in cygwin environment. For this article I use:

  1. Windows 8 on PC
  2. cygwin64
  3. Raspbian Wheezy on Raspberry Pi

Alternatively, you can use cygwin for 32-bit. However as my Windows 8 is 64-bit I will stick to it.

X Window System – Server & Client Architecture

X Window is originated at the Massachussetts Institute of Technology (MIT) In 1984. X11 is the system-level software infrastructure for the windowing GUI on Linux, *BSD, and other UNIX-like Operating System. It is designed to handle both local display, as well as across the network displays. X Window is a computer software system and network protocol that provides a basis for graphical user interfaces (GUIs) and rich input device capability for networked computers. It creates a hardware abstraction layer where software is written to use a generalized set of commands, allowing for device independence and reuse of programs on any computer that implements X.

X was designed from the beginning to be network-centric. It adopts a “client-server” model.

In the X model, the “X server” runs on the computer that has the keyboard, monitor, and mouse attached. The server’s responsibility includes tasks such as managing the display, handling input from the keyboard and mouse, and other input or output devices (i.e., a “tablet” can be used as an input device, and a video projector may be an alternative output device). Each X application (such as XTerm or Firefox) is a “client”. A client sends messages to the server such as “Please draw a window at these coordinates”, and the server sends back messages such as “The user just clicked on the OK button”.

In a home or small office environment, the X server and the X clients commonly run on the same computer. However, it is perfectly possible to run the X server on a less powerful desktop computer, and run X applications (the clients) on, say, the powerful and expensive machine that serves the office. In this scenario the communication between the X client and server takes place over the network.

This confuses some people, because the X terminology is exactly backward to what they expect. They expect the “X server” to be the big powerful machine down the hall, and the “X client” to be the machine on their desk.

It is important to remember that the X server is the machine with the monitor and keyboard, and the X clients are the programs that display the windows.

Preparations

As stated before, the X window is using client/server model. Our communication would be on top of secure connection. Specifically, SSH (Secure SHell) connection are chosen to transport data (as a tunneling). Therefore, we should configure SSH server properly.

Now on your Raspberry Pi, configure SSH server. Obviously, you MUST install your SSH server program. Edit following file /etc/ssh/ssh_config, make sure these lines are not commented.

ForwardAgent yes
ForwardX11 yes
ForwardX11Trusted yes

Now open /etc/ssh/sshd_config and edit the file so it has following line:

X11Forwarding yes

Restart the SSH Server.

On our host, make sure X11 is installed on cygwin. We won’t cover how we installed cygwin or X11.

Remote Display

Open up cygwin terminal. We need an X server. At default, cygwin will not running X at startup.

We want to create a server on our local machine. This X server will manage our local screen output as well as other X client (Raspberry Pi in this case). To initiate a server, do following (assuming we use default display :0):

export DISPLAY=:0
xinit -- $DISPLAY

A new window should appear with a black blank screen. You would see a new terminal there.

Now connect to Raspberry Pi using SSH.

ssh -X [email protected]_ip_address

user is the username we will use and the raspberry_ip_address is the Pi’s IP address. Make sure you can access and you can login to Pi.

Once you are logged in, execute this to start the X.

lxsession &
lxpanel &

Now, your window should be drawn to your Raspbian’s LXDE.

Because X on cygwin implementation is a window, you can view both your desktop and remote desktop at same time.

Social media & sharing icons powered by UltimatelySocial