zerotier自建私有planet
自建私有planet文件生成
1、准备一台带公网IP的服务器,可以是云主机也可以是本地服务器,服务器需要能够从公网访问UDP 9993端口,确保安全组或者防火墙放行,另外开通服务器3443端口用于控制器管理页面。
我这里的公网服务器IP地址为:121.152.251.167
2、安装服务器基础组件,用于编译私有planet。
yum install wget gcc gcc-c++ git -y
yum install json-devel -y
3、安装zerotier-one,以下以linux服务器为例,其他操作系统安装参照官网,网页链接:https://www.zerotier.com/download/
curl -s https://install.zerotier.com | sudo bash
当出现以下提示表明安装成功。
Complete!
*** Enabling and starting ZeroTier service...
Created symlink from /etc/systemd/system/multi-user.target.wants/zerotier-one.service to /usr/lib/systemd/system/zerotier-one.service.
*** Waiting for identity generation...
*** Success! You are ZeroTier address [ 1bf714fee0 ].
4、下载zerotier-one官方源码,可以多种方式下载,git、wget、网页都可以,官网源码链接:https://github.com/zerotier/ZeroTierOne
git下载需要安装git程序:yum install git -y
下载源码:git clone https://github.com/zerotier/ZeroTierOne
wget下载方式:wget https://codeload.github.com/zerotier/ZeroTierOne/zip/refs/heads/dev
安装unzip用于解压:yum install unzip -y
修改代码库:mv dev dev.zip
解压代码:unzip dev.zip 解压后目录信息如下:
-rw-r--r-- 1 root root 96 Mar 20 2022 70-persistent-net.rules
-rw-r--r-- 1 root root 13466388 Jan 9 16:24 dev.zip
drwxr-xr-x 20 root root 4096 Nov 21 00:16 ZeroTierOne-dev
进入以下目录,用于编译自己的planet
cd /root/ZeroTierOne-dev/attic/world/ 修改mkworld.cpp文件
删除以下配置,以下配置为官方planet的配置
// Los Angeles
roots.push_back(World::Root());
roots.back().identity = Identity("3a46f1bf30:0:76e66fab33e28549a62ee2064d1843273c2c300ba45c3f20bef02dbad225723bb59a9bb4b13535730961aeecf5a163ace477cceb0727025b99ac14a5166a09a3");
roots.back().stableEndpoints.push_back(InetAddress("185.180.13.82/9993"));
roots.back().stableEndpoints.push_back(InetAddress("2a02:6ea0:c815::/9993"));
// Miami
roots.push_back(World::Root());
roots.back().identity = Identity("de8950a8b2:0:1b3ada8251b91b6b6fa6535b8c7e2460918f4f729abdec97d3c7f3796868fb02f0de0b0ee554b2d59fc3524743eebfcf5315e790ed6d92db5bd10c28c09b40ef");
roots.back().stableEndpoints.push_back(InetAddress("207.246.73.245/443"));
roots.back().stableEndpoints.push_back(InetAddress("2001:19f0:9002:5cb:ec4:7aff:fe8f:69d9/443"));
// Tokyo
roots.push_back(World::Root());
roots.back().identity = Identity("34e0a5e174:0:93efb50934788f856d5cfb9ca5be88e85b40965586b75befac900df77352c145a1ba7007569d37c77bfe52c0999f3bdc67a47a4a6000b720a883ce47aa2fb7f8");
roots.back().stableEndpoints.push_back(InetAddress("147.75.92.2/443"));
roots.back().stableEndpoints.push_back(InetAddress("2604:1380:3000:7100::1/443"));
// Amsterdam
roots.push_back(World::Root());
roots.back().identity = Identity("992fcf1db7:0:206ed59350b31916f749a1f85dffb3a8787dcbf83b8c6e9448d4e3ea0e3369301be716c3609344a9d1533850fb4460c50af43322bcfc8e13d3301a1f1003ceb6");
roots.back().stableEndpoints.push_back(InetAddress("195.181.173.159/443"));
roots.back().stableEndpoints.push_back(InetAddress("2a02:6ea0:c024::/443"));
删除后,增加自己的配置,其中identify从一下配置获取:cat /var/lib/zerotier-one/identity.public ,服务器地址为当前服务器的公网IP地址121.152.251.167
文件内容为:1bf714fee0:0:a4451f8c36b3ae8aaa4bdc30872f504ca9d9f6a5517dce69a625b866cdccc276494b72adabd4f224e41d039197e252ecd797314cfd95030880798aade5d7e7d4
增加的配置如下:
// PrivatePlanet
roots.push_back(World::Root());
roots.back().identity = Identity("1bf714fee0:0:a4451f8c36b3ae8aaa4bdc30872f504ca9d9f6a5517dce69a625b866cdccc276494b72adabd4f224e41d039197e252ecd797314cfd95030880798aade5d7e7d4");
roots.back().stableEndpoints.push_back(InetAddress("121.152.251.167/9993"));
执行以下命令,进行planet文件的生成:
source ./build.sh
./mkworld
mv ./world.bin ./planet
成功后如图所示,并可以在当前目录看到planet的文件。
INFO: generating and signing id==149604618 ts==1567191349589
INFO: world.bin written with 257 bytes of binary world data.
#define ZT_DEFAULT_WORLD_LENGTH 257
[root@i-50keu4wx8cwvccbyk3q0pc1xh world]# ll
total 2312
-rwxr-xr-x 1 root root 246 Nov 21 00:16 build.sh
-rw-r--r-- 1 root root 128 Jan 9 17:29 current.c25519
-rwxr-xr-x 1 root root 2329656 Jan 9 17:29 mkworld
-rw-r--r-- 1 root root 8747 Nov 21 00:16 mkworld.cpp
-rw-r--r-- 1 root root 570 Jan 9 17:29 planet
-rw-r--r-- 1 root root 128 Jan 9 17:29 previous.c25519
-rw-r--r-- 1 root root 280 Nov 21 00:16 README.md
-rw-r--r-- 1 root root 3771 Nov 21 00:16 world.c
此时,私有planet文件的生成完成,将planet文件下载后保存。
自建私有planet控制器搭建
1、zerotier私有控制台搭建,参考官方手册执行即可,官方链接:https://key-networks.com/ztncui/
To install on an EL8/9 flavour of Linux, such as RedHat Enterprise Linux 8/9 or AlmaLinux 8/9, follow these steps:
- Install zerotier-one as per instructions here: zerotier.com/download.shtml.
- sudo yum install https://download.key-networks.com/el7/ztncui/1/ztncui-release-1-1.noarch.rpm -y
- sudo yum install ztncui -y
- Optional: install TLS/SSL certificate as per instructions below, or skip this step to use the default self-signed certificate.
- Restrict access to port 3443 on the public network interface to your IP address (at least until the admin password is set).
- sudo sh -c "echo ZT_TOKEN=`sudo cat /var/lib/zerotier-one/authtoken.secret` > /opt/key-networks/ztncui/.env"
- sudo sh -c "echo HTTPS_PORT=3443 >> /opt/key-networks/ztncui/.env"
- sudo sh -c "echo NODE_ENV=production >> /opt/key-networks/ztncui/.env"
- sudo chmod 400 /opt/key-networks/ztncui/.env
- sudo chown ztncui.ztncui /opt/key-networks/ztncui/.env
- sudo systemctl restart ztncui
- Connect to port 3443 over HTTPS in your web browser - e.g. https://my.network.controller:3443
- Log in as user admin with password password.
启动程序若报以下错误:Error: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required b
参考以下链接进行解决:https://zc10.cn/archives/818
自建私有planet控制器网络创建
1、配置控制器网络,打开控制器页面https://121.152.251.167:3443,如下:
2、输入默认账号密码,用户名:admin 密码:password,首次登录需要修改密码,输入不少于10位的密码。
3、点击Add network,输入名字进行创建网络。
4、网络创建完毕后如图所示,记录下32位的网络ID :1bf714fee0898ffb
5、创建地址池用于给客户端分配地址使用
6、配置路由信息
6、控制器加入网络
Linux系统进入zerotier-one目录,将生成的planet拷贝到zerotier-one目录下。
cd /var/lib/zerotier-one/
mv planet planet.bak
systemctl stop zerotier-one
cp /root/ZeroTierOne-dev/attic/world/planet .
systemctl start zerotier-one
zerotier-cli join 1bf714fee0898ffb
7、zerotier-one控制器页面同意客户端加入,勾选如图所示:
8、分别加入Widows及Linux客户端,加入方法见最下方,实际网络测试如下:
网络测试汇总:
Linux客户端加入后,可以看到连接到了私有planet,并未有官方的planet信息。
[root@i-50krgdywk736dxe82iusi0sqo zerotier-one]# zerotier-cli listpeers
200 listpeers <ztaddr> <path> <latency> <version> <role>
200 listpeers 1bf714fee0 121.152.251.167/9993;3639;3638 6 1.12.2 PLANET
200 listpeers 1c00cd29c2 121.152.251.229/51101;13639;13639 1 1.12.2 LEAF
IP地址信息如下:
9: zt4ulz24i3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 2800 qdisc pfifo_fast state UNKNOWN group default qlen 1000
link/ether fa:eb:a1:0b:c4:08 brd ff:ff:ff:ff:ff:ff
inet 192.168.108.101/24 brd 192.168.108.255 scope global zt4ulz24i3
valid_lft forever preferred_lft forever
inet6 fe80::f8eb:a1ff:fe0b:c408/64 scope link
valid_lft forever preferred_lft forever
[root@i-50krgdywk736dxe82iusi0sqo zerotier-one]# ping 192.168.108.102
PING 192.168.108.102 (192.168.108.102) 56(84) bytes of data.
64 bytes from 192.168.108.102: icmp_seq=1 ttl=128 time=1.34 ms
64 bytes from 192.168.108.102: icmp_seq=2 ttl=128 time=0.401 ms
64 bytes from 192.168.108.102: icmp_seq=3 ttl=128 time=0.424 ms
64 bytes from 192.168.108.102: icmp_seq=4 ttl=128 time=1.55 ms
64 bytes from 192.168.108.102: icmp_seq=5 ttl=128 time=4.05 ms
Windows客户端加入后,可以看到连接到了私有PLANET
C:\Users\Administrator>zerotier-cli listpeers
200 listpeers <ztaddr> <path> <latency> <version> <role>
200 listpeers 1bf714fee0 121.152.251.167/9993;1898;1898 94 1.12.2 PLANET
200 listpeers 6428eb3a1c 121.152.251.225/33214;2080;2080 0 1.12.2 LEAF
C:\Users\Administrator>
Ethernet adapter ZeroTier One [1bf714fee0898ffb]:
Connection-specific DNS Suffix . :
Link-local IPv6 Address . . . . . : fe80::b0f0:49ed:8616:ebb4%13
IPv4 Address. . . . . . . . . . . : 192.168.108.102
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 25.255.255.254
C:\Users\Administrator> ping 192.168.108.101
Pinging 192.168.108.101 with 32 bytes of data:
Reply from 192.168.108.101: bytes=32 time=4ms TTL=64
Reply from 192.168.108.101: bytes=32 time=1ms TTL=64
Reply from 192.168.108.101: bytes=32 time<1ms TTL=64
Reply from 192.168.108.101: bytes=32 time<1ms TTL=64
不同客户端加入方法
1、Windows进入服务中,停止zerotier-one服务,将planet文件拷贝到zerotier-one目录C:\ProgramData\ZeroTier\One,启动服务,加入网络。
2、Linux系统,停止zerotier-one服务,systemctl stop zerotier-one,将planet文件拷贝到zerotier-one目录/var/lib/zerotier-one内,启动服务,加入网络。
3、Mac系统,将planet文件拷贝到zerotier-one目录/Library/Application Support/ZeroTier/One,重启加载配置,加入网络。
停止:sudo launchctl unload /Library/LaunchDaemons/com.zerotier.one.plist
启动:sudo launchctl load /Library/LaunchDaemons/com.zerotier.one.plist
文章评论