1、libconfig依赖的包 [root@zqdd:/root]#wget http://www.netfort.gr.jp/~dancer/software/downloads/libdshcon
1、libconfig依赖的包
[root@zqdd:/root]#wget http://www.netfort.gr.jp/~dancer/software/downloads/libdshconfig-0.20.10.cvs.1.tar.gz[root@zqdd:/root]#tar xvf libdshconfig-0.20.10.cvs.1.tar.gz -C /usr/local/[root@zqdd:/root]#cd /usr/local/libdshconfig-0.20.10.cvs.1./configure && make && make install
2、dsh
[root@zqdd:/root]#wget http://www.netfort.gr.jp/~dancer/software/downloads/dsh-0.22.0.tar.gz[root@zqdd:/root]#tar xvf dsh-0.22.0.tar.gz -C /usr/local/[root@zqdd:/usr/local]#cd dsh-0.22.0/./configure && make && make install
3、配置
vim /usr/local/etc/dsh.conf remoteshell =ssh vim /usr/local/etc/machines.list #可能没有 自己创建一个 添加要管理的主机IP192.168.0.171192.168.0.181192.168.0.85
4、dsh 使用
使用时要输入密码
[root@zqdd:/usr/local/etc]#dsh -a -c uptime192.168.0.181: Address 192.168.0.181 maps to www.sn.10086.cn, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT!192.168.0.85: Address 192.168.0.85 maps to www.sn.10086.cn, but this does not map back to the address - POSSIBLE BREAK-IN [email protected]'s password: [email protected]'s password: 192.168.0.181: 15:57:51 up 15 min, 2 users, load average: 0.00, 0.01, 0.02##################################vim /etc/ssh/ssh_configGSSAPIAuthentication no
5、开启ssh无密码验证
管理机器生成私钥和公钥
[root@zqdd:/root]#ssh-keygen Generating public/private rsa key pair.Enter file in which to save the key (/root/.ssh/id_rsa): #回车Enter passphrase (empty for no passphrase): #回车Enter same passphrase again: #回车Your identification has been saved in /root/.ssh/id_rsa.Your public key has been saved in /root/.ssh/id_rsa.pub.The key fingerprint is:70:1d:e3:b8:f0:bb:c3:33:a8:a7:f0:5f:5f:06:92:73 root@zqddThe key's randomart image is:+--[ RSA 2048]----+| o || + o || o o o || = o || S E || = . || . oo o || o o.=o o || +=. .+. |+-----------------+
拷贝公钥到被管理机器端账户下
[root@zqdd:/root]#ssh-copy-id -i .ssh/id_rsa.pub [email protected] #Address 192.168.0.181 maps to www.sn.10086.cn, but this does not map back to the address - POSSIBLE BREAK-IN [email protected]'s password: Now try logging into the machine, with "ssh '[email protected]'", and check in: .ssh/authorized_keysto make sure we haven't added extra keys that you weren't expecting.[root@zqdd:/root]#ssh-copy-id -i .ssh/id_rsa.pub [email protected] #Address 192.168.0.85 maps to www.sn.10086.cn, but this does not map back to the address - POSSIBLE BREAK-IN [email protected]'s password: Now try logging into the machine, with "ssh '[email protected]'", and check in: .ssh/authorized_keysto make sure we haven't added extra keys that you weren't expecting.[root@zqdd:/root]#ssh-copy-id -i .ssh/id_rsa.pub [email protected] #The authenticity of host '192.168.0.171 (192.168.0.171)' can't be established.RSA key fingerprint is 9c:b5:50:85:9e:37:d8:57:48:30:a7:91:56:35:e3:dc.Are you sure you want to continue connecting (yes/no)? yesWarning: Permanently added '192.168.0.171' (RSA) to the list of known [email protected]'s password: Now try logging into the machine, with "ssh '[email protected]'", and check in: .ssh/authorized_keysto make sure we haven't added extra keys that you weren't expecting.
6、使用dsh
[root@zqdd:/root]#dsh --helpDistributed Shell / Dancer's shell version 0.22.0 Copyright 2001,2002 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-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-g --group [groupname] Execute on group member-f --file [file] Use the file as list of machines-r --remoteshell [shellname] Execute using shell (rsh/ssh)-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-V --version Give out version information[root@zqdd:/root]#dsh -a -c uptime192.168.0.171: 16:19:50 up 36 min, 2 users, load average: 0.00, 0.00, 0.00192.168.0.181: 16:19:50 up 37 min, 2 users, load average: 0.02, 0.12, 0.07192.168.0.85: 16:19:48 up 36 min, 2 users, load average: 0.00, 0.00, 0.00[root@zqdd:/root]#
7、dsh 创建组
建议给一组机器这样用
mkdir /usr/local/etc/groupvim /usr/local/etc/group/mysql192.168.0.85192.168.0.181
[root@zqdd:/usr/local/etc]#dsh -g mysql -c w192.168.0.85: 16:43:21 up 59 min, 2 users, load average: 0.02, 0.09, 0.04192.168.0.85: USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT192.168.0.85: root tty1 - 15:45 54:31 0.02s 0.02s -bash192.168.0.85: root pts/0 desktop-dhbqgma 15:49 6:49 0.02s 0.02s -bash192.168.0.181: 16:43:23 up 1:00, 3 users, load average: 0.00, 0.00, 0.00192.168.0.181: USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT192.168.0.181: root tty1 - 15:43 1:00m 0.01s 0.01s -bash192.168.0.181: root pts/0 desktop-dhbqgma 16:29 13:33 0.00s 0.00s -bash[root@zqdd:/usr/local/etc]#
来自 http://www.2daygeek.com/dsh-run-execute-shell-commands-on-multiple-linux-servers-at-once/#
在浏览器上打开bash shell http://www.2daygeek.com/shellinabox-web-based-ssh-terminal-to-access-remote-linux-servers/