PVE FRP MySQL 端口映射

PVE FRP MySQL 端口映射

前言

虚拟软件(PVE,VMWare,Docker,VirtualBox)如果用有线连接
除宿主机之外的主机均有可能连不上虚拟机里的MySQL,使用Wifi 就100% 能连上
目前已知的解决办法是用frp 做虚拟机和宿主机的端口映射,然后其他机器访问宿主机

服务端

# 创建安装目录
mkdir -p /opt/modules

# 下载frp
cd && wget https://github.com/fatedier/frp/releases/download/v0.24.1/frp_0.24.1_linux_amd64.tar.gz

# 解压frp
cd && tar -xf frp_0.24.1_linux_amd64.tar.gz -C /opt/modules
cd /opt/modules && mv frp_0.24.1_linux_amd64 frp

# 配置frp
cat > /opt/modules/frp/frps.ini << 'EOF'
[common]
bind_port = 7000
EOF

# 创建启动脚本
cd && cat > frp.sh << 'EOF'
#!/bin/bash

ps -ef | grep -v grep | grep frps && { echo "The frps already is running!"; exit 1; }

nohup /opt/modules/frp/frps -c /opt/modules/frp/frps.ini > /opt/modules/frp/frps.log 2>&1 &

ps -ef | grep -v grep | grep frps || echo "Fail to start frps, please check details in log!"
EOF

# 赋予脚本执行权限
cd && chmod +x frp.sh

# 启动frps
cd && ./frp.sh

客户端

# 创建安装目录
sudo mkdir -p /opt/modules

# 下载frp
cd && wget https://github.com/fatedier/frp/releases/download/v0.24.1/frp_0.24.1_linux_amd64.tar.gz

# 解压frp
cd && tar -xf frp_0.24.1_linux_amd64.tar.gz -C /opt/modules
cd /opt/modules && mv frp_0.24.1_linux_amd64 frp

# 配置frp
cat > /opt/modules/frp/frpc.ini << 'EOF'
[common]
server_addr = 192.168.0.210
server_port = 7000

[mysqld]
type = tcp
local_ip = 127.0.0.1
local_port = 3306
remote_port = 3306
EOF

# 创建启动脚本
cd && cat > frp.sh << 'EOF'
#!/bin/bash

ps -ef | grep -v grep | grep frpc && { echo "The frpc already is running!"; exit 1; }

nohup /opt/modules/frp/frpc -c /opt/modules/frp/frpc.ini > /opt/modules/frp/frpc.log 2>&1 &

ps -ef | grep -v grep | grep frpc || echo "Please start PVE frps first!"
EOF

# 赋予脚本执行权限
cd && chmod +x frp.sh

# 启动frpc,须确保宿主机的frps 已启动
cd && ./frp.sh

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值