用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
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步