找了好多资料才弄好,做笔记预防下次忘记怎么弄了
1、创建容器
2、添加存储卷
容器地址:/var/lib/zerotier-one
主机地址改为你自己设置的
我的是:/docker/ZeroTier
3、网络选择:host
4、重启策略选择:总是启动
5、运行时&资源 勾选:特权模式
6、部署容器
7、进入容器详情,进入控制台
输入:zerotier-cli join 233ccaac27511111 并确认。 233ccaac27511111对应的是你 zerotier 上的网络 ID
设置IP地址
返回勾选Authorized
进入路由表设置
现在已经可以用内网地址访问Portainer,但是还不能访问内网的其他网段
8、修改Portainer主机的/etc/sysctl.conf
在末尾添加
net.ipv4.ip_forward=1
net.ipv6.conf.all.forwarding=1
net.bridge.bridge-nf-call-iptables=1
net.bridge.bridge-nf-call-ip6tables=1
执行sysctl -p马上生效
现在还是不能访问内网其他网址,还要进行下面的设置
重启Portainer主机
在SSH执行下面命令
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
执行之后,只会临时起效,重启之后就失效了。
永久保存:
1、建立rc-local.service文件
sudo vim /etc/systemd/system/rc-local.service
2、输入如下内容
[Unit]
Description=/etc/rc.local Compatibility
ConditionPathExists=/etc/rc.local
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99
[Install]
WantedBy=multi-user.target
3、创建rc.local
sudo vim /etc/rc.local
4、输入如下内容
#!/bin/sh
#
# rc.local
#
echo "自启动成功" > /usr/local/test.log
# 这里写要自动运行的命令或者脚本
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
exit 0
5、添加rc.local可执行权限
sudo chmod +x /etc/rc.local
6、启动服务
sudo systemctl enable rc-local
7、启动服务查看启动状态
sudo systemctl start rc-local.service
sudo systemctl status rc-local.service
如果这里启动失败了需要回头更改rc.local文件
把第一行改为#!/bin/bash
8、重启,若在/usr/local下能够看到 test.log文件说明自启动已经成功了!