文档章节

Using DSH (Distributed Shell) to Run Linux Command

Jackin
 Jackin
发布于 2015/11/20 16:27
字数 731
阅读 37
收藏 0

DSH is short for “Distributed Shell” or “Dancer’s Shell” it is freely available on most major distributions of Linux, but can easily be built from source if your distribution does not offer it in its package repository. You can obtain the source at.

Install DSH (Distributed Shell) in Linux

We are going to assume a Debian / Ubuntu environment for the scope of this tutorial. If you are using another distribution, please substitute the appropriate commands for your package manager.

On Debian / Ubuntu

First, let’s install the package via apt:

$ sudo apt-get install dsh

On RHEL / CentOS / Fedora

This method is for those who are not using Debian, and want to compile it from source tar balls. First you need to compile “libdshconfig” and install.

# wget http://www.netfort.gr.jp/~dancer/software/downloads/libdshconfig-0.20.10.cvs.1.tar.gz
# tar xfz libdshconfig*.tar.gz 
# cd libdshconfig-*
# ./configure ; make
# make install

Then compile dsh and install.

# wget http://www.netfort.gr.jp/~dancer/software/downloads/dsh-0.22.0.tar.gz
# tar xfz dsh-0.22.0.tar.gz
# cd dsh-*
# ./configure ; make 
# make install

The main configuration file “/etc/dsh/dsh.conf” (For Debian) and “/usr/local/etc/dsh.conf” (for Red Hat) is pretty straightforward, but since rsh is an unencrypted protocol, we are going to use SSH as the remote shell. Using the text editor of your choice, find this line:

remoteshell =rsh

And change it to:

remoteshell =ssh

There are other options you can pass in here, if you choose to do so, and there are plenty of them to find on the dsh man page. For now, we are going to accept the defaults and have a look at the next file, /etc/dsh/machines.list (for Debian).

For Red Hat based systems you need to create a file called “machines.list” in “/usr/local/etc/” directory.

The syntax here is pretty easy. All one has to do is to enter in a machine’s credentials (Hostname, IP Address, or FQDN) one per line.

Note: When accessing more than one machine simultaneously, it would behove you to set up key-based password-less SSH on all of your machines. Not only does this provide ease of access, but security wise, it hardens your machine as well.

My “/etc/dsh/machines.list” or “/usr/local/etc/machines.list” file says:

172.16.25.125
172.16.25.126

Once you have entered in the credentials of the machines you wish to access, let’s run a simple command like uptime to all of the machines.

$ dsh –aM –c uptime
Sample Output
172.16.25.125: 05:11:58 up 40 days, 51 min, 0 users, load average: 0.00, 0.01, 0.05
172.16.25.126: 05:11:47 up 13 days, 38 min, 0 users, load average: 0.00, 0.01, 0.05

So what did this command do?

Pretty simple. First, we ran dsh and passed the “–a” option to it, which says to send the “uptime” command to “ALL” of the machines listed in “/etc/dsh/machines.list“.

Next, we specified the “–M” option, which says to return the “machine name” (specified in “/etc/dsh/machines.list“) along with the output of the uptime command. (Very useful for sorting when running a command on a number of machines.)

The “–c” option stands for “command to be executed” in this case, “uptime“.

DSH can also be configured with groups of machines in the “/etc/dsh/groups/” file, where is a file with a list of machines in the same format as the “/etc/dsh/machines.list” file. When running dsh on a group, specify the groupname after the “-g” option.

For Red Hat based systems you need to create a folder called “groups” in “/usr/local/etc/” directory. In that “groups” directory you create a file called “cluster“.

For example, run the “w” command on all machines listed in the “cluster” group file “/etc/dsh/groups/cluster” or “/usr/local/etc/groups/cluster“.

$ dsh –M –g cluster –c w

DSH provides much more flexibility, and this tutorial only scratches the surface. Aside from executing commands, DSH can be used to transfer files, install software, add routes, and much more.

To a Systems Administrator tasked with the responsibility of a large network, it is invaluable.

本文转载自:http://www.tecmint.com/using-dsh-distributed-shell-to-run-linux-commands-across-multiple-machines/

共有 人打赏支持
Jackin

Jackin

粉丝 27
博文 46
码字总数 13191
作品 0
闵行
程序员
私信 提问
ubuntu从头开始搭建hadoop伪分布式环境

13年学习过一段时间的hadoop,但是工作中用到的地方比较少,有些生疏,加上现在hadoop版本也已经比较新了,所以空闲时间想继续学习一下,找到这篇文章,从头开始搭建一个hadoop环境,转过来备...

ToSun
2015/09/20
240
0
Linux Netcat command – The swiss army knife of net

Swiss Army Knife of networking netcat is a versatile tool that is able to read and write data across TCP and UDP network . Combined with other tools and redirection it can be us......

杨尚川
2015/02/11
0
0
Android : First step – Download and build

This document provides a wiki for setting up a local environment on Linux Ubuntu to work on Android source code. 1. Getting Android source code a. Prerequisites : Android build ......

我是一只鱼
2011/09/02
0
0
Docker入门教程 Part 4 Swarms

前言 本篇笔记是官方Get Started入门教程的Part 4,主要介绍 Docker 集群 Swarm 的功能和使用。前面章节都是在单主机上使用Docker,这个章节将学会在集群中使用Docker容器。 我正在学习Docke...

iotisan
2017/11/16
0
0
voltdb run sql file---run script files

Script files — You can run multiple queries or stored procedures in a single command using the file directive. The file directive takes a text file as an argument and executes......

Oscarfff
2016/08/19
8
0

没有更多内容

加载失败,请刷新页面

加载更多

EOS官方钱包keosd

EOS官方钱包的名称是keosd,它负责管理你的私钥,并且帮你进行交易的签名。 不过不幸的是,keosd钱包对普通用户并不友好,它是一个命令行程序,目前还没有像以太坊的mist那样的图形化界面,而...

汇智网教程
39分钟前
1
0
ArrayList的实现原理以及实现线程安全

一、ArrayList概述 ArrayList是基于数组实现的,是一个动态的数字,可以自动扩容。 ArrayList不是线程安全的,效率比较高,只能用于单线程的环境中,在多线程环境中可以使用Collections.syn...

一看就喷亏的小猿
56分钟前
2
0
Netty 备录 (一)

入职新公司不久,修修补补1个月的bug,来了点实战性的技术---基于netty即时通信 还好之前对socket有所使用及了解,入手netty应该不是很难吧,好吧,的确有点难,刚看这玩意的时候,可能都不知道哪里...

_大侠__
昨天
5
0
Django简单介绍和用户访问流程

Python下有许多款不同的 Web 框架。Django是重量级选手中最有代表性的一位。许多成功的网站和APP都基于Django。 Django是一个开放源代码的Web应用框架,由Python写成。 Django遵守BSD版权,初...

枫叶云
昨天
8
0
Spring Cloud Stream消费失败后的处理策略(四):重新入队(RabbitMQ)

应用场景 之前我们已经通过《Spring Cloud Stream消费失败后的处理策略(一):自动重试》一文介绍了Spring Cloud Stream默认的消息重试功能。本文将介绍RabbitMQ的binder提供的另外一种重试...

程序猿DD
昨天
7
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部