用ssh和互信链接建立批量执行
main server: 192.168.100.101
sub sever1: 192.168.100.102
sub server2: 192.168.100.103
main server执行脚本:/data/release/run.sh
#!/bin/sh if [ -z "$1" ]; then echo "need para!" exit fi port=22 target=/data/release/run.sh srvs=(192.168.100.102 192.168.100.103) for srv in ${srvs[*]} do ssh -f -p $port $srv $target \"$1\" & done
sub server执行脚本:/data/release/run.sh
#!/bin/sh if [ -z "$1" ]; then echo "need para!" exit fi cd /data/release #echo "web1 $1" $1
互信连接建立:
1. 创建密钥对
[root@VM_165_58_tlinux ~]# ssh-keygen
2. 传送公钥到sub server
ssh-copy-id -p 22 -i /root/.ssh/id_rsa.pub root@192.168.100.102