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

通過dsh批量管理Linux服務器
一,安裝dsh
 
wget http://www.netfort.gr.jp/~dancer/software/downloads/libdshconfig-0.20.9.tar.gz
tar zxvf libdshconfig-0.20.9.tar.gz
cd libdshconfig-0.20.9
./configure
make && make install
 
wget http://www.netfort.gr.jp/~dancer/software/downloads/dsh-0.25.9.tar.gz
tar zxvf dsh-0.25.9.tar.gz
cd dsh-0.25.9
./configure
make && make install
 
ln -s /usr/local/lib/libdshconfig.so.1 /lib/
 
[root@localhost ~]# which dsh
/usr/local/bin/dsh
 
二,用法介紹:
 
[root@china-channel ~]# dsh –help
Distributed Shell / Dancer’s shell version 0.25.9
Copyright 2001-2005 Junichi Uekawa,
distributed under the terms and conditions of GPL version 2
 
-v –verbose                   Verbose output  詳細模式輸出
-q –quiet                     Quiet  安靜模式輸出
-M –show-machine-names      Prepend the host name on output顯示被控制主機的hostname
-H –hide-machine-names      Do not prepend host name on output  不顯示主機名(default)
-i –duplicate-input            Duplicate input given to dsh
-b –bufsize                   Change buffer size used in input duplication
-m –machine [machinename]     Execute on machine 主機名
-n –num-topology              How to divide the machines
-a –all              Execute on all machines  主機列表,默認列表在/root/.dsh/machines.list
-g –group [groupname]  Execute on group member 指定主機名組,主機名組在/root/.dsh/group/
-f –file [file]               Use the file as list of machines  選擇主機列表
-r –remoteshell [shellname]   Execute using shell (rsh/ssh)  指定遠程工具,默認爲rsh
-o –remoteshellopt [option]   Option to give to shell
-h –help                      Give out this message
-w –wait-shell                Sequentially execute shell 指定順序運行,默認是並行
-c –concurrent-shell          Execute shell concurrently
-F –forklimit [fork limit]    Concurrent with limit on number
-V –version                   Give out version information
三,創建控制的主機列表
 
[root@china-channel ~]# cat /root/.dsh/machines.list
218.85.1.2
218.85.1.3
[root@china-channel ~]# cat /root/.dsh/group/umail 
218.85.1.2
218.85.1.3
 
四,配置ssh無密碼登陸
 
[root@china-channel ~]# ssh-keygen -t rsa
回車三次。
在/root/.ssh目錄下生成id_rsa,id_rsa.pub
把id_rsa.pub拷貝到被控制機的/root/.ssh/目錄下:
 
[root@mail176 .ssh]#mv id_rsa.pub authorized_keys
[root@mail176 .ssh]#chmod 600 authorized_keys
 
對於有多個不同控制機的,可以通過cat id_rsa.pub >>authorized_keys 追加的形式
 
五,應用舉例:
 [root@china-channel AIMstor]# dsh -M -r ssh -a — free
218.85.1.2:           total       used       free     shared    buffers     cached
218.85.1.2: Mem:       8168272    8138584      29688   0   197176    3516140
218.85.1.2: -/+ buffers/cache:    4425268    3743004
218.85.1.2: Swap:     16386260    1011732   15374528
218.85.1.3:           total       used       free     shared    buffers     cached
218.85.1.3: Mem:   8168272    8103304      64968      0    543324    3085280
218.85.1.3: -/+ buffers/cache:    4474700    3693572
218.85.1.3: Swap:     16386260    1039780   15346480
 
 
[root@china-channel AIMstor]# dsh -M -r ssh -a — free|grep /cache
218.85.1.2: -/+ buffers/cache:    4423528    3744744
218.85.1.3: -/+ buffers/cache:    4462684    3705588
 
 
[root@china-channel AIMstor]# dsh -M -r ssh -a — df -h          
218.85.1.2: Filesystem            Size  Used Avail Use% Mounted on
218.85.1.2: /dev/sda3              48G   31G   15G  67% /
218.85.1.2: /dev/sda6             792G  377G  375G  51% /bk
218.85.1.2: /dev/sda2              48G  4.7G   41G  11% /opt
218.85.1.2: /dev/sda1             251M   17M  222M   7% /boot
218.85.1.2: /dev/sdb1             2.7T 1008G  1.6T  39% /mail
218.85.1.2: tmpfs                 3.9G     0  3.9G   0% /dev/shm
218.85.1.3: Filesystem            Size  Used Avail Use% Mounted on
218.85.1.3: /dev/sda3              48G   35G   11G  77% /
218.85.1.3: /dev/sda6             792G  215G  537G  29% /bk
218.85.1.3: /dev/sda2              48G  5.7G   40G  13% /opt
218.85.1.3: /dev/sdb1             2.7T  812G  1.8T  32% /mail
218.85.1.3: /dev/sda1             251M   17M  222M   7% /boot
218.85.1.3: tmpfs                 3.9G     0  3.9G   0% /dev/shm

 


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