需要准备工作:
1、16GB+内存的闲置电脑。可以自己淘一个便宜点mini主机或二手笔记本,预算500~1000+
2、阿里云服务器,目前有活动99元/一年,到期是可以原价续费4年,过期了可以换其他厂商服务器,做好迁移工作,这里主要利用公网IP做代理作用
一、搭建虚拟机环境
可以使用Virtual Box搭建多个虚拟机环境,平均每台虚拟机分配4G内存,设置好静态ip
例如:
192.168.56.10、192.168.56.11、192.168.56.12......
二、借助nps实现内网穿透
nps:高性能轻量级开源的内网穿透工具(https://github.com/ehang-io/nps),具体使用教程可以参考官方文档
借助阿里云服务器的公网IP可以轻松实现内网穿透到我们本地的虚拟机集群中
阿里云服务器中安装配置nps-server:(作为服务管理端)
yum install -y tar
mkdir -p /opt/nps-server
tar -zxvf ./linux_amd64_server.tar.gz -C /opt/npc-server
#启动
#配置指令开机自启,具体可以询问chatgpt,这里暂略
虚拟机中安装配置npc-client:(作为客户端注册到nps-server上)
yum install -y tar
mkdir -p /opt/npc-client
tar -zxvf ./linux_amd64_client.tar.gz -C /opt/npc-client
cd /opt/npc-client
#配置开机自启
sudo vi /etc/systemd/system/npc.service
#在文件中添加以下内容
[Unit]
Description=NPC Service
After=network.target
[Service]
#根据实际替换为阿里云服务器的服务端地址
ExecStart=/opt/unicloud/npc-client/npc -server=58.223.xx.xx:18024 -vkey=wrpypoo8h6xxxxx -type=tcp
WorkingDirectory=/opt/npc-client
Restart=always
User=root
StandardOutput=null
StandardError=null
Type=simple
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl start npc.service
sudo systemctl status npc.service
sudo systemctl enable npc.service
journalctl -u npc.service -f
三、搭建完成
远程访问:
在阿里云服务器中执行:ssh -p 端口号 root@127.0.0.1
通过不同端口号即可内网穿透访问不同的本地虚拟机