更新时间:2022-04-08 GMT+08:00
配置通过代理机进行部署(非云主机)
背景信息
本节介绍不能访问公网的非云主机或服务器进行部署任务需要哪些配置。
前提条件
在一个主机组中添加代理机器和部署主机。
操作步骤
- 配置代理机:
- 确认代理机授信的端口是否开放。
- 为已授信的代理机配置SNAT服务。
- 配置部署主机:
- 检查黑白名单。
- 配置路由(主机可以直接连接外网时不需要配置)。
表1 路由配置方式 操作系统
路由配置方式
redhat系列
#添加静态路由 #sudo route add -net {{destination_ip}} netmask 255.255.255.255 gw {{proxy_ip}} #此处填入要接入的ip destination_ip='' #此处应填入代理机器的私网ip proxy_ip='' sudo route add -net ${destination_ip} netmask 255.255.255.255 gw ${proxy_ip} #固化route命令 content='sudo route add -net '${destination_ip}' netmask 255.255.255.255 gw '${proxy_ip} content_static='any net '${destination_ip}' netmask 255.255.255.255 gw '${proxy_ip} #给rc.local添加固化命令 if [ `grep -c "${content}" /etc/rc.local` -eq '0' ] then echo "${content}" >> /etc/rc.local else echo "existing rc.local!" fi #创建static-routes文件,并添加固化命令 if [ ! -f "/etc/sysconfig/static-routes" ] then echo "${content_static}" >> /etc/sysconfig/static-routes else if [ `grep -c "${content_static}" /etc/sysconfig/static-routes` -eq '0' ] then echo "${content_static}" >> /etc/sysconfig/static-routes else echo "existing static-routes!" fi fi
debian系列
#添加静态路由 #sudo route add -net {{destination_ip}} netmask 255.255.255.255 gw {{proxy_ip}} #此处填入要接入的ip destination_ip='' #此处应填入代理机器的私网ip proxy_ip='' sudo route add -net ${destination_ip} netmask 255.255.255.255 gw ${proxy_ip} #固化route命令 content='sudo route add -net '${destination_ip}' netmask 255.255.255.255 gw '${proxy_ip} content_static='up route add -net '${destination_ip}' netmask 255.255.255.255 gw '${proxy_ip} #给rc.local添加固化命令 if [ `grep -c "${content}" /etc/rc.local` -eq '0' ] then sed -i '/exit 0/i\'"${content}" /etc/rc.local else echo "existing rc.local!" fi #给interfaces文件添加固化命令 if [ `grep -c "${content_static}" /etc/network/interfaces` -eq '0' ] then echo "${content_static}" >> /etc/network/interfaces else echo "existing interfaces!" fi
父主题: 配置通过代理机部署Linux主机
