1、需求
为了方便为客户演示demo,公司在公网部署了一台测试服务器,不过由于配置较低,并且由于最近的演示站点增加,导致经常出现内存耗尽,从而致使高负载。在考虑节省成本的情况下,打算把测试服迁移到内网服务器上。首先想到的就是内网穿透神器Frp。
2、思路
停掉公网测试服务器的80和443端口,将测试网站及数据库全部迁移至内网服务器,然后通过frp将内网的80与443端口映射至公网测试服。
3、实现步骤
3.1、frp服务端配置
# wget https://github.com/fatedier/frp/releases/download/v0.36.2/frp_0.36.2_linux_amd64.tar.gz
# tar -xvf frp_0.36.2_linux_amd64.tar.gz
# mv frp_0.36.2_linux_amd64 /usr/local/frp
# vi /usr/local/frp/frps.ini
[common]
bind_port = 7000
dashboard_port = 7500
dashboard_user = admin
dashboard_pwd = ******
log_file = /var/log/frps.log
log_level = info
log_max_days = 7
vhost_http_port = 80
vhost_https_port = 443
token = jeRgfgf
使用systemd管理frp服务
# cp /usr/local/frp/systemd/frps.service /etc/systemd/system/
# vi /etc/systemd/system/frps.ini
[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
# systemctl daemon-reload
# systemctl start frps && systemctl enable frps
3.2、客服端配置
# wget https://github.com/fatedier/frp/releases/download/v0.36.2/frp_0.36.2_linux_amd64.tar.gz
# tar -xvf frp_0.36.2_linux_amd64.tar.gz
# mv frp_0.36.2_linux_amd64 /usr/local/frp
# vi /usr/local/frp/frpc.ini
[common]
server_addr = **********
server_port = 7000
token = jeRgfgf
[mysql]
type = tcp
local_ip = 127.0.0.1
local_port = 3306
remote_port = 3306
[apiygj01]
type = http
local_ip = 127.0.0.1
local_port = 80
custom_domains = apidev.test.com
[apiygj02]
type = https
local_ip = 127.0.0.1
local_port = 443
custom_domains = apidev.test.com
[demo01]
type = http
local_ip = 127.0.0.1
local_port = 80
custom_domains = demo.test.com
[demo02]
type = https
local_ip = 127.0.0.1
local_port = 443
custom_domains = demo.test.com
使用systemd管理frp服务
# cp /usr/local/frp/systemd/frpc.service /etc/systemd/system/
# vi /etc/systemd/system/frpc.ini
[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
# systemctl daemon-reload
# systemctl start frpc && systemctl enable frpc