如何使用shell实现frp自动部署以及生成相应客户端服务端配置文件

本文介绍了如何通过shell脚本实现frp配置文件的自动化批量生成,旨在解决手动配置繁琐且易出错的问题。主要步骤包括在relay01和02节点上安装frp,然后在堡垒机上执行脚本以完成配置。
摘要由CSDN通过智能技术生成

需求分析:
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)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

不淘气

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值