1.让跳板要不掉线
编辑文件:~/.ssh/config
Host *
ServerAliveInterval 60
ServerAliveCountMax 6
ForwardAgent yes
CheckHostIP no
Compression yes

ControlMaster auto
ControlPath /tmp/ssh_connection_%h_%p_%r.sock
User hp106070

Host jump
Hostname login1.cm3.alibaba.org
User hp106070

Host login
Hostname login1.cm6.taobao.org
User hp106070
ProxyCommand ssh 106070@tugw1.sqa.cm6.tbsite.net nc %

2.登陆实例:
ssh jump

1.在跳板机上生成免密码登陆文件,进入~/.ssh/目录
# ssh-keygen
一路回车

2.编辑host文件,一行一个ip,比如linlanghost:
10.178.214.143
10.178.128.43

3.跳板机到线上机器免密码认证,编辑~/.ssh/sshreg.sh文件
#!/bin/bash

if [ $# -eq 0 ]; then
echo "./sshreg.sh host_file"
exit 0
else
FILE=$1
fi

pgmscp -A -b -f $FILE ~/.ssh/id_rsa.pub ~/.ssh
pgm -A -b -p 5 -f $FILE "cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys"

4.免密码认证执行首次文件拷贝
./sshreg.h linlanghost

5.编辑shell文件,gh.sh
#!/bin/bash

echo 'searching...'
hostlist=$1
batchshell="$2"

#if the shell script is a file
if [ -f "$2" ];then
batchshell=`cat "$2"`
fi
for host in $(cat "$hostlist")
do
ssh $host "$batchshell"
echo $host
done


6.查日志实例:
./gh.sh linlanghost "grep -rn 'StockOutOrderConfirmService.execute orderNo' /home/admin/linlang/logs/crk/ladygo.log"

相关文章:

  • 2022-12-23
  • 2021-09-25
  • 2021-06-25
  • 2021-06-13
  • 2021-05-28
  • 2022-12-23
  • 2021-09-15
  • 2022-01-08
猜你喜欢
  • 2022-01-06
  • 2021-09-21
  • 2021-09-19
  • 2021-10-05
  • 2021-04-06
  • 2021-10-05
  • 2021-07-03
相关资源
相似解决方案