mirror of
https://github.com/xubiaolin/docker-zerotier-planet.git
synced 2025-01-22 12:48:14 -05:00
修复加速链接以及planet的bug
This commit is contained in:
parent
62e6164c67
commit
2c413ed4e7
38
Dockerfile
38
Dockerfile
@ -1,42 +1,12 @@
|
||||
FROM alpine:latest
|
||||
|
||||
ADD ./server.sh /app/
|
||||
ADD ./init.sh /app/
|
||||
ADD ./gen_world.sh /app/
|
||||
ADD ./patch /opt/patch/
|
||||
|
||||
VOLUME ["/var/lib/zerotier-one/"]
|
||||
|
||||
|
||||
|
||||
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories &&\
|
||||
apk update &&\
|
||||
apk add git python3 nodejs npm make g++ linux-headers zerotier-one &&\
|
||||
npm config set registry http://registry.npm.taobao.org &&\
|
||||
|
||||
# 安装ztncui
|
||||
cd /opt && git clone https://github.91chi.fun/https://github.com/key-networks/ztncui.git &&\
|
||||
cd ztncui/src && npm install -g node-gyp && npm install &&\
|
||||
cp -pv ./etc/default.passwd ./etc/passwd &&\
|
||||
echo 'HTTP_PORT=3443' > .env&&\
|
||||
echo 'NODE_ENV=production' >> .env &&\
|
||||
echo 'HTTP_ALL_INTERFACES=true' >> .env &&\
|
||||
|
||||
# 添加补丁
|
||||
cd /opt && \
|
||||
git clone https://github.91chi.fun/https://github.com/zerotier/ZeroTierOne.git && \
|
||||
|
||||
cd /var/lib/zerotier-one && \
|
||||
zerotier-idtool generate identity.public identity.secret &&\
|
||||
zerotier-idtool initmoon identity.public >> moon.json &&\
|
||||
|
||||
cp /opt/patch/* . &&\
|
||||
python3 patch.py &&\
|
||||
zerotier-idtool genmoon moon.json &&\
|
||||
mkdir moons.d && cp ./*.moon ./moons.d &&\
|
||||
|
||||
rm /opt/ZeroTierOne/attic/world/mkworld.cpp &&\
|
||||
cp mkworld.cpp /opt/ZeroTierOne/attic/world/ &&\
|
||||
cd /opt/ZeroTierOne/attic/world/ && \
|
||||
sh build.sh
|
||||
RUN cd /app && sh init.sh
|
||||
|
||||
WORKDIR /app/
|
||||
CMD ["sh","./server.sh"]
|
||||
CMD /bin/sh -c "zerotier-one -d; cd /opt/ztncui/src;npm start"
|
||||
|
78
README.md
78
README.md
@ -1,69 +1,55 @@
|
||||
# Docker-zerotier-planet
|
||||
私有部署zeroteir-planet服务
|
||||
私有部署 `zeroteir-planet` 服务
|
||||
|
||||
zerotier 是一个非常好用的私有组网的软件,但是官方提供的服务器离我们比较远,自建planet服务器可以帮我们解决很多与网络有关的问题
|
||||
|
||||
|
||||
# 准备条件
|
||||
- 具有公网ip的服务器(需要开放3443/tcp端口,9992/tcp端口,9992/udp端口)
|
||||
# 一:准备条件
|
||||
- 具有公网ip的服务器(需要开放3443/tcp端口,9993/tcp端口,9993/udp端口)
|
||||
- 安装docker
|
||||
|
||||
# 开始
|
||||
# 二:开始
|
||||
## 1.下载项目源码
|
||||
```
|
||||
git clone https://github.com.cnpmjs.org/xubiaolin/docker-zerotier-planet.git
|
||||
git clone http://github.markxu.vip/https://github.com/xubiaolin/docker-zerotier-planet.git
|
||||
```
|
||||
## 2.修改项目中的patch/patch.json
|
||||
## 2.修改配置
|
||||
|
||||
将其中的ip地址修改为你服务器的ip地址,端口保留不变即可
|
||||
修改项目中的patch/patch.json,将其中的ip地址修改为你服务器的ip地址,端口保留不变即可
|
||||
|
||||
|
||||
## 3.在包含Dockerfile的目录下打包镜像
|
||||
如果您不是第一次使用该项目,您需要先执行以下命令
|
||||
## 3.一键部署
|
||||
启动时会关闭9993端口的服务,请注意
|
||||
```
|
||||
rm -rf /opt/zerotier-planet
|
||||
docker stop zerotier-planet
|
||||
docker rm zerotier-planet
|
||||
docker rmi zerotier-planet
|
||||
cd docker-zerotier-planet
|
||||
./deploy.sh
|
||||
```
|
||||
打包镜像
|
||||
```
|
||||
docker build -t zerotier-planet:latest .
|
||||
```
|
||||
打包预计需要2-5分钟,具体需要看网络与机型
|
||||
打包预计需要3-5分钟,具体需要看网络与机型
|
||||
|
||||
|
||||
# 启动项目
|
||||
**防火墙需要开放 `3443/tcp, 9993/tcp, 9993/udp` 这三个端口**
|
||||
|
||||
启动服务
|
||||
```
|
||||
docker run -d --name zerotier-planet -p 3443:3443 -p 9992:9993 -p 9992:9993/udp -v /opt/zerotier-planet:/var/lib/zerotier-one --restart unless-stopped zerotier-planet:latest
|
||||
```
|
||||
**planet 文件在`/opt/planet`, 客户端直连时需要替换客户端的planet**
|
||||
|
||||
|
||||
# 创建网络
|
||||
服务器需要开放3443端口
|
||||
然后访问http://ip:3443 即可进入管理后台
|
||||
# 三:创建网络
|
||||
访问 http://ip:3443 即可进入controller页面
|
||||
|
||||
![ui](webui.png)
|
||||
|
||||
|
||||
使用默认账号为:admin
|
||||
使用默认账号为:`admin`
|
||||
|
||||
默认密码为:password
|
||||
默认密码为:`password`
|
||||
|
||||
进入后创建一个网络,可以得到一个网络ID
|
||||
通过官方的app就可以直接连接这个网络ID了,下面的步骤为可选操作。
|
||||
# 四:客户端配置
|
||||
首先将服务器 `/opt/zerotier-planet` 目录下的 planet 文件下载到本地以备用
|
||||
|
||||
# 【可选】客户端配置
|
||||
首先将服务器/opt/zerotier-planet 目录下的planet文件下载到本地以备用
|
||||
|
||||
## linux 客户端配置
|
||||
## 4.1linux 客户端配置
|
||||
安装zerotier-one客户端
|
||||
```
|
||||
curl -s https://install.zerotier.com | sudo bash
|
||||
```
|
||||
进入/var/lib/zerotier-one目录下,
|
||||
进入`/var/lib/zerotier-one`目录下,
|
||||
删除目录下的planet文件,然后把从服务器下载的planet文件替换过来
|
||||
|
||||
重启一下zerotier-one服务
|
||||
@ -72,7 +58,15 @@ debian系使用命令
|
||||
service zerotier-one restart
|
||||
```
|
||||
|
||||
然后执行zerotier-cli join 网络ID
|
||||
执行 `zerotier-cli listpeers` 可以查看 peers
|
||||
|
||||
![linux_ok](linux_planet_ok.png)
|
||||
|
||||
如果和上图一样出现了PLANET字样,则表示成功了
|
||||
|
||||
----------------------------------------
|
||||
|
||||
执行`zerotier-cli join 网络ID`,可以加入到网络中,
|
||||
|
||||
成功后可以在管理后台上面看到一个新增的 members ,此时我们需要授权,否则将无法访问。
|
||||
|
||||
@ -80,15 +74,17 @@ service zerotier-one restart
|
||||
|
||||
其他客户端加入也是一样要进行授权操作操作
|
||||
|
||||
## windows 客户端配置
|
||||
## 4.2 windows 客户端配置
|
||||
windows
|
||||
将planet文件覆盖粘贴到C:\ProgramData\ZeroTier\One中
|
||||
将 planet 文件覆盖粘贴到`C:\ProgramData\ZeroTier\One`中
|
||||
|
||||
windows 搜索服务,并重启 zeroiter-one
|
||||
|
||||
powershell(admin)中执行zerotier-cli listpeers查看planet是否生效
|
||||
powershell(admin)中执行`zerotier-cli listpeers`查看 planet 是否生效
|
||||
![win_ok](win_planet_ok.png)
|
||||
|
||||
## 安卓客户端配置
|
||||
|
||||
## 4.3 安卓客户端配置
|
||||
[Zerotier 非官方安卓客户端发布:支持自建 Moon 节点 - V2EX](https://www.v2ex.com/t/768628)
|
||||
|
||||
# 参考链接
|
||||
|
17
deploy.sh
Normal file → Executable file
17
deploy.sh
Normal file → Executable file
@ -1,15 +1,26 @@
|
||||
#!/bin/sh
|
||||
imageName="zerotier-planet"
|
||||
|
||||
docker network create zerotier
|
||||
|
||||
echo "清除原有内容"
|
||||
rm -rf /opt/$imageName
|
||||
rm /opt/planet
|
||||
docker stop $imageName
|
||||
docker rm $imageName
|
||||
docker rmi $imageName
|
||||
|
||||
|
||||
echo "打包镜像"
|
||||
docker build -t $imageName:latest .
|
||||
docker build --network zerotier -t $imageName .
|
||||
|
||||
echo "启动服务"
|
||||
for i in $(lsof -i:9993 -t);do kill -2 $i;done
|
||||
docker run -d --network host --name $imageName -p 3443:3443 -p 9993:9993 -p 9993:9993/udp -v /opt/$imageName:/var/lib/zerotier-one --restart unless-stopped $imageName:latest
|
||||
docker run -d --network zerotier --name $imageName -p 3443:3443 -p 9993:9993 -p 9993:9993/udp --dns 223.5.5.5 --dns 223.6.6.6 --restart unless-stopped $imageName
|
||||
|
||||
sleep 10s
|
||||
echo "生成世界"
|
||||
docker exec -it $imageName sh /app/gen_world.sh
|
||||
docker cp $imageName:/opt/ZeroTierOne/attic/world/world.bin /opt/planet
|
||||
|
||||
echo "------------------"
|
||||
echo "现在已经配置好了,planet文件在/opt/planet, 客户端连接时需要替换该planet"
|
10
gen_world.sh
Normal file
10
gen_world.sh
Normal file
@ -0,0 +1,10 @@
|
||||
cd /var/lib/zerotier-one && zerotier-idtool initmoon identity.public > moon.json
|
||||
|
||||
# 添加补丁
|
||||
cd /opt/patch && python3 patch.py
|
||||
cd /var/lib/zerotier-one && zerotier-idtool genmoon moon.json && mkdir moons.d && cp ./*.moon ./moons.d
|
||||
|
||||
# 生成世界
|
||||
cd /opt/ZeroTierOne/attic/world/
|
||||
sh build.sh
|
||||
./mkworld
|
21
init.sh
Normal file
21
init.sh
Normal file
@ -0,0 +1,21 @@
|
||||
sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories
|
||||
apk update
|
||||
apk add git python3 nodejs npm make g++ linux-headers zerotier-one
|
||||
npm config set registry http://registry.npm.taobao.org && npm install -g node-gyp
|
||||
|
||||
echo "下载源码中,源码文件较大,请耐心等待;如果源码下载失败,请重新执行该脚本"
|
||||
# 下载源码
|
||||
cd /opt && git clone http://github.markxu.vip/https://github.com/key-networks/ztncui.git
|
||||
if [ "$?"-ne 0]; then echo "下载源码出错,请重试"; exit 1; fi
|
||||
|
||||
cd /opt && git clone http://github.markxu.vip/https://github.com/zerotier/ZeroTierOne.git
|
||||
if [ "$?"-ne 0]; then echo "下载源码出错,请重试"; exit 1; fi
|
||||
|
||||
# 配置ztncui
|
||||
cd /opt/ztncui/src && npm install
|
||||
cp -pv ./etc/default.passwd ./etc/passwd
|
||||
echo 'HTTP_PORT=3443' >.env
|
||||
echo 'NODE_ENV=production' >>.env
|
||||
echo 'HTTP_ALL_INTERFACES=true' >>.env
|
||||
|
||||
|
BIN
linux_planet_ok.png
Normal file
BIN
linux_planet_ok.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 15 KiB |
@ -1,51 +1,51 @@
|
||||
import os
|
||||
import json
|
||||
from re import M
|
||||
|
||||
|
||||
def patch_moon():
|
||||
patch_data = dict()
|
||||
with open("patch.json", "r") as f:
|
||||
patch_data = json.load(f)
|
||||
|
||||
moon = dict()
|
||||
with open("moon.json", "r") as f:
|
||||
def get_moon():
|
||||
with open("/var/lib/zerotier-one/moon.json", "r") as f:
|
||||
moon = json.load(f)
|
||||
|
||||
endpoint_patch = patch_data.get("stableEndpoints", [])
|
||||
if len(endpoint_patch) == 0:
|
||||
print("请配置endpoint!")
|
||||
exit(1)
|
||||
|
||||
moon["roots"][0]["stableEndpoints"] = endpoint_patch
|
||||
|
||||
with open("moon.json", "w+") as f:
|
||||
f.write(json.dumps(moon))
|
||||
return moon
|
||||
|
||||
|
||||
def patch_world():
|
||||
moon = dict()
|
||||
def get_patch():
|
||||
with open("/opt/patch/patch.json", "r") as f:
|
||||
return json.load(f)
|
||||
|
||||
file_moon = open("moon.json", "r")
|
||||
moon = json.load(file_moon)
|
||||
file_moon.close()
|
||||
|
||||
middle = '''
|
||||
//China
|
||||
def patch():
|
||||
moon = get_moon()
|
||||
patch = get_patch()
|
||||
|
||||
identity = moon["roots"][0]["identity"]
|
||||
moon["roots"][0]["stableEndpoints"] = patch["stableEndpoints"]
|
||||
|
||||
# 修改moon
|
||||
with open("/var/lib/zerotier-one/moon.json", "w") as f:
|
||||
f.write(json.dumps(moon,sort_keys=True, indent=2))
|
||||
|
||||
print("修改后的moon")
|
||||
print(moon)
|
||||
|
||||
# 修改world
|
||||
moon["roots"][0]["stableEndpoints"] = get_patch()["stableEndpoints"]
|
||||
text = f"""// Los Angeles
|
||||
roots.push_back(World::Root());
|
||||
roots.back().identity = Identity("{}");'''.format(moon["roots"][0]["identity"])
|
||||
roots.back().identity = Identity("{identity}");
|
||||
"""
|
||||
|
||||
for i in moon["roots"][0]["stableEndpoints"]:
|
||||
middle += '\n roots.back().stableEndpoints.push_back(InetAddress("{}"));'.format(i)
|
||||
for i in get_patch()["stableEndpoints"]:
|
||||
text += f'\n roots.back().stableEndpoints.push_back(InetAddress("{i}"));'
|
||||
|
||||
with open("mkworld.cpp", "r") as cpp:
|
||||
code = "".join(cpp.readlines())
|
||||
# 生成文件
|
||||
with open("/opt/patch/mkworld.cpp", "r") as cpp:
|
||||
world = "".join(cpp.readlines())
|
||||
world = world.replace("//__PATCH_REPLACE__", text)
|
||||
|
||||
with open("mknewworld.cpp", "w+") as cpp:
|
||||
code = code.replace(" //__PATCH_REPLACE__", middle)
|
||||
print(code)
|
||||
cpp.write(code)
|
||||
with open("/opt/ZeroTierOne/attic/world/mkworld.cpp", "w") as cpp:
|
||||
cpp.write(world)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
patch_moon()
|
||||
patch_world()
|
||||
patch()
|
||||
|
@ -1,6 +0,0 @@
|
||||
#!/bin/sh
|
||||
echo "开始执行"
|
||||
zerotier-one -d
|
||||
|
||||
cd /opt/ztncui/src
|
||||
npm start
|
BIN
win_planet_ok.png
Normal file
BIN
win_planet_ok.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 27 KiB |
Loading…
Reference in New Issue
Block a user