通過dsh批量管理Linux服務器(三)【感謝作者的無私分享】

通過dsh批量管理Linux服務器(三)

First and foremost, you need to install dsh. The downloads page for the project is a nightmare (http://www.netfort.gr.jp/~dancer/software/downloads/list.cgi), but you basically want the latest version of libdshconfig and dsh. At the time of this writing, that would be 0.20.13 and 0.25.9 respectively.

I just dropped them into /tmp for the time being:

cd /tmp
wget http://www.netfort.gr.jp/~dancer/software/downloads/libdshconfig-0.20.13.tar.gz
wget http://www.netfort.gr.jp/~dancer/software/downloads/dsh-0.25.9.tar.gz

Then go through the normal install from source process, starting with libdshconfig

cd /tmp
tar -zxvf libdshconfig-0.20.13.tar.gz
cd libdshconfig-0.20.13
./configure
make
sudo make install
cd /tmp
tar -zxvf dsh-0.25.9.tar.gz
 cd dsh-0.25.9
 ./configure
 make
 sudo make install

now you should be able to run dsh and have it return an error that no machine was specified:

josh.prewitt$ dsh
dsh: no machine specified

Configuring DSH

You will want to setup RSA keys for your user on each of the machines that you want to log in to remotely so that you are not prompted for a password. (This is outside the scope of this article, there are about a gazillion different articles online that will teach that). Once the keys are in place, you will want to create group files. You will need to mkdir -p ~/.dsh/group and then create a text file in the group directory that lists the machines you want to connect to. Here is an example:

josh.prewitt$ pwd
/Users/josh.prewitt/.dsh/group
josh.prewitt$ cat web 
[email protected]
[email protected]
[email protected]

This sets the user and the host that you want in the “web” group.

Next up is a very important configuration change. dsh wants to use rsh by default instead of ssh. You will need to edit /usr/local/etc/dsh.conf as an Administrator to change that. Just change the line:

remoteshell =rsh

to read:

remoteshell =ssh

Save the file, and you are ready to go.

Actually using DSH

Ok, now for the magic. Assuming you have a group named ‘web’, you could run:

dsh -c -g web -M 'uname -a'

This will return the results of uname -a for each server. The -c flag does it concurrently instead of going to each machine one at a time. The -M flag tells it to list the machine name by the response.

Other stuff

I prefer to always see the machine name, so instead of always specifying -M, I created a new file at ~/,dsh/dsh.conf and included the line “showmachinenames=1″. You can set other options here too. For example, say you use a non standard ssh port. You could specify on the command line with -o:

dsh -c -g web -o "-p 2222" 'uname -a'

OR, you can set dsh to always use a different port by adding the line “remoteshellopt=-p 2222″ to your configuration file.

Other sources if my article didn’t make sense:


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章