需求分析:
1.之前手动去生成frp的配置文件,需要改的地方多,繁琐容易出错
2.通过shell脚本实现自动化批量生成所需要的配置文件
操作步骤:
1.在相应的relay01与02节点分别安装frp (对应节点服务器)
2.将此脚本copy到自己的家目录下 (堡垒机)
3.执行脚本
#!/bin/bash
#Author:teng
read -p "请输入英文节点名:>>>" node
cd
home_path=`pwd`
kscinfo_path=$home_path/kscinfo/
relay_out_ip=`$kscinfo_path/./kscinfo.py -l -e node=$node |grep relay |awk -F "|" '{ip[x++]=$6};END{for(i=0;i<NR;i++)print ip[i] }'` #获取relay IP
cache_out_ip=`$kscinfo_path/./kscinfo.py -l -e node=$node |grep cache |awk -F "|" '{ip[x++]=$6};END{for(i=0;i<NR;i++)print ip[i] }'` #获取cache IP
cache_ilo_ip=`$kscinfo_path/./kscinfo.py -l -e node=$node |grep cache |awk -F "|" '{ip[x++]=$7};END{for(i=0;i<NR;i++)print ip[i] }'`
cache_in_ip=`$kscinfo_path/./kscinfo.py -l -e node=$node |grep cache |awk -F "|" '{ip[x++]=$8};END{for(i=0;i<NR;i++)print ip[i] }'`
cache_num=`$kscinfo_path/./kscinfo.py -l -e node=$node |grep cache |wc -l`
gw=`$kscinfo_path/./kscinfo.py -l -e node=$node |grep relay01 |awk -F "|" '{print$8}'|cut -d . -f 1,2,3`
frp_server_path=/root/frp_0.33.0_linux_amd64 #frp安装包位置
back_file_dir=$home_path/frp_test #frp文件生成位置
frp_package=$home_path/package/frp_0.33.0_linux_amd64.tar.gz
password='k*******cdn'
source /etc/init.d/functions
[ -d $back_file_dir ] || mkdir -p $back_file_dir #判断目录是否存在,不存在就创建
#relay IP
for i in $relay_out_ip
do
echo $i>>$back_file_dir/relay_out_ip.txt
done
array2=($(cat $back_file_dir/relay_out_ip.txt)) #将获取到的值存入到数组中
echo "" > $back_file_dir/relay_out_ip.txt #清理
#out_ip数组
for i in $cache_out_ip
do
echo $i>>$back_file_dir/out_ip.txt
done
array=($(cat $back_file_dir/out_ip.txt)