通过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 �Chelp
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 �Cverbose                   Verbose output  详细模式输出
-q �Cquiet                     Quiet  安静模式输出
-M �Cshow-machine-names      Prepend the host name on output显示被控制主机的hostname
-H �Chide-machine-names      Do not prepend host name on output  不显示主机名(default)
-i �Cduplicate-input            Duplicate input given to dsh
-b �Cbufsize                   Change buffer size used in input duplication
-m �Cmachine [machinename]     Execute on machine 主机名
-n �Cnum-topology              How to divide the machines
-a �Call              Execute on all machines  主机列表,默认列表在/root/.dsh/machines.list
-g �Cgroup [groupname]  Execute on group member 指定主机名组,主机名组在/root/.dsh/group/
-f �Cfile [file]               Use the file as list of machines  选择主机列表
-r �Cremoteshell [shellname]   Execute using shell (rsh/ssh)  指定远程工具,默认为rsh
-o �Cremoteshellopt [option]   Option to give to shell
-h �Chelp                      Give out this message
-w �Cwait-shell                Sequentially execute shell 指定顺序运行,默认是并行
-c �Cconcurrent-shell          Execute shell concurrently
-F �Cforklimit [fork limit]    Concurrent with limit on number
-V �Cversion                   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

 


你可能感兴趣的:(自动化,管理工具,系统管理员,服务器管理,批量管理服务器)