背景:
在安全隔离的内网环境中,部署于内网的应用如需调用公网第三方接口(如支付、短信),可通过正向代理服务实现访问。
GoProxy
下载:
https://github.com/snail007/goproxy/releases
使用文档:
支持
linux、windows、mac
darwin 是 mac 版的二进制版本
(执行文件可以改名)
hehemnt client -P 123.123.123.123:8005 -T tls -C proxy.crt -K proxy.key --k default
proxy client -P 123.123.123.123:8005 -T tls -C proxy.crt -K proxy.key --k default
可以写个启动脚本
#!/bin/bash
HOME=/data/soft/mnt
SERVER=123.123.123.123:8005
checkpid(){
APP_PID=`ps -ef|grep $HOME|grep hehemnt|awk '{print $2}'`
}
#用于等待进程启停
wait_for_pid ()
{
try=0
case "$1" in
'created')
while test $try -lt 7 ; do
printf .
try=`expr $try + 1`
sleep 1
done
checkpid
if [ "$APP_PID" != "" ] ; then
try=''
fi
;;
'removed')
while test $try -lt 35 ; do
checkpid
if [ "${APP_PID}" = "" ] ; then
try=''
break
fi
printf .
try=`expr $try + 1`
sleep 1
done
;;
esac
}
created_pid_status(){
wait_for_pid created
if [ -n "$try" ] ; then
echo -e "\n\e[00;31mhehemnt start failed!\e[00m"
exit 1
else
echo -e "\n\e[00;32mhehemnt startup!\e[00m"
fi
}
start(){
checkpid
if [ ! -n "${APP_PID}" ]; then
printf "Starting hehemnt"
nohup hehemnt client -P $SERVER -T tls -C proxy.crt -K proxy.key --k default> $HOME/client.log 2>&1 &
created_pid_status
else
echo -e "\e[00;31mhehemnt is already running (pid: ${APP_PID})\e[00m"
fi
}
stop(){
checkpid
if [ ! -n "${APP_PID}" ]; then
echo -e "\e[00;31mhehemnt not runing\e[00m"
else
kill -9 $APP_PID
wait_for_pid removed
if [ -n "$try" ] ; then
echo -e "\e[00;31mhehemnt stop failed!\e[00m"
exit 1
else
echo -e "\e[00;32mhehemnt stop!\e[00m"
fi
fi
}
status(){
checkpid
if [ ! -n "${APP_PID}" ]; then
echo -e "\e[00;31mhehemnt not runing\e[00m"
else
echo -e "\e[00;31mhehemnt is already running (pid: ${APP_PID})\e[00m"
fi
}
restart(){
stop
sleep 1s
start
}
case $1 in
start) start;;
stop) stop;;
restart) restart;;
status) status;;
*) echo "USAGE: $0 [app-name] [start|stop|status|restart|log]";;
esac