现在的位置: 首页 > 综合 > 正文

dsh批量管理linux服务器

2018年05月16日 ⁄ 综合 ⁄ 共 2387字 ⁄ 字号 评论关闭
一,安装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 /lib64/
二,用法介绍:
 
[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                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@rong2 .dsh]# cat machines.list 
192.168.0.2

 

四:配置ssh无密码登陆
在/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@rong2 .dsh]# dsh -H -r ssh -a -- ifconfig eth0 
eth0      Link encap:Ethernet  HWaddr 00:0C:29:E4:87:99  
          inet addr:192.168.0.2  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fee4:8799/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:5411 errors:0 dropped:0 overruns:0 frame:0
          TX packets:4678 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:1827959 (1.7 MiB)  TX bytes:601719 (587.6 KiB)
          Interrupt:59 Base address:0x2000

本文出自 “Mr_Z” 博客,请务必保留此出处http://zhangrong.blog.51cto.com/2196532/1004678

【上篇】
【下篇】

抱歉!评论已关闭.