连接跳板机、连接线上机器那些事

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"

posted @ 2016-09-23 14:37  范晓刚  阅读(1966)  评论(0编辑  收藏  举报