CentOS7.9服务器一键脚本部署FRP内网穿透服务端与客户端
一、 场景
如下场景,CentOS7.9服务器双网卡,分别接入内网和外网
这时想通过这台CentOS7.9的Linux服务器在外网访问内网的一些服务
可以在这台服务器上同时部署frps 和frpc来实现
二、部署脚本
frp_install.sh
#!/bin/bash
tar -zxvf frp_0.51.1_linux_amd64.tar.gz -C /usr/local/
cd /usr/local/
mv frp_0.51.1_linux_amd64 frp
mkdir -p /usr/local/frp/logs
chown -R root:root /usr/local/frp
cat > /usr/local/frp/frps.ini << EOF
[common]
bind_address = 0.0.0.0
bind_port = 9111
authentication_method = token
authenticate_heartbeats = false
authenticate_new_work_conns = false
token = Frp@2023!
log_file = /usr/local/frp/logs/frps.log
log_level = info
log_max_days = 30
EOF
cat > /usr/local/frp/frpc.ini << EOF
[common]
server_addr = 127.0.0.1
server_port = 9111
authentication_method = token
authenticate_heartbeats = false
token = Frp@2023!
log_file = /usr/local/frp/logs/frpc.log
log_level = info
log_max_days = 30
[forward_locahost_SSH]
type = tcp
local_ip = 127.0.0.1
local_port = 22
remote_port = 22122
EOF
cat > /usr/lib/systemd/system/frps.service << EOF
[Unit]
Description=Frp Server Service
After=network.target
[Service]
Type=simple
User=root
Restart=on-failure
RestartSec=5s
ExecStart=/usr/local/frp/frps -c /usr/local/frp/frps.ini
[Install]
WantedBy=multi-user.target
EOF
cat > /usr/lib/systemd/system/frpc.service << EOF
[Unit]
Description=Frp Client Service
After=network.target
[Service]
Type=simple
User=root
Restart=on-failure
RestartSec=5s
ExecStart=/usr/local/frp/frpc -c /usr/local/frp/frpc.ini
ExecReload=/usr/local/frp/frpc reload -c /usr/local/frp/frpc.ini
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable frps.service
systemctl enable frpc.service
systemctl start frps.service
sleep 2
systemctl restart frpc.service
脚本执行即可完成frps和frpc的安装
三、Tips
接下来可自行修改frpc.ini,配置模板如下
[forward_locahost_SSH]
type = tcp
local_ip = 127.0.0.1
local_port = 22
remote_port = 22122
添加类似的配置,实现端口转发
可以本公众号后台回复【frp】,即可获取frp的安装包和脚本
原文始发于微信公众号(WalkingCloud):CentOS7.9服务器一键脚本部署FRP内网穿透服务端与客户端
- 左青龙
- 微信扫一扫
- 右白虎
- 微信扫一扫
评论