// 停止firewall
systemctl stop firewalld.service
// 禁止firewall开机启动
systemctl disable firewalld.service
// 查看默认防火墙状态(关闭后显示notrunning,开启后显示running)
firewall-cmd --state
安装
yum install -y iptables
// 服务管理
// 查看iptables状态
service iptables status
// iptables服务重启
service iptables restart
// iptables服务禁用
service iptables stop
// 查看规则
iptables -L -n --line-number
// 删除规则 INPUT大写,2表示序号
iptables -D INPUT 2
开放端口
// TCP端口2376 用于安全的Docker客户端通信
iptables -I INPUT -p tcp --dport 2376 -j ACCEPT
// TCP端口2377 集群管理端口,只需要在管理器节点上打开
iptables -I INPUT -p tcp --dport 2377 -j ACCEPT
// TCP与UDP端口7946 节点之间通讯端口(容器网络发现)
iptables -I INPUT -p tcp --dport 7946 -j ACCEPT
iptables -I INPUT -p udp --dport 7946 -j ACCEPT
// UDP端口4789 overlay网络通讯端口(容器入口网络)
iptables -I INPUT -p udp --dport 4789 -j ACCEPT
// portainer 的endpoint端口
iptables -I INPUT -p tcp --dport 9001 -j ACCEPT
// 修改文件 /lib/systemd/system/docker.service,允许使用 TCP 连接 Docker
ExecStart=/usr/bin/dockerd -H unix:// -H tcp://0.0.0.0:2375
// 初始化集群
docker swarm init
// 显示manager节点的TOKEN
docker swarm join-token manager
// 加入到集群
docker swarm join --token <token> <manager ip>:2377
// 创建自定义 Overlay 网络
docker network create --driver overlay swarm-network
// 创建服务
// --name 服务名称
docker service create \
--with-registry-auth \
--name api-service \
--network swarm-network \
-p 8000:8000 \
--replicas 2 \
api:test
// 滚动升级服务
// 参数含义解释:
// –-image 指定要更新的镜像
// -–update-parallelism 指定最大同步更新的任务数
// -–update-delay 指定更新间隔
docker service update \
--with-registry-auth \
--image api:test \
--update-delay 2s \
--update-parallelism 5 api-service
// 查看当前集群的信息。
docker info
// 查看集群节点
docker node ls
// 查看服务
docker service ls
// 删除服务
docker service rm <服务名称>
// 查看服务日志
docker service logs <服务名称>
// 扩展集群服务
docker service scale helloworld=2
// 查看服务运行在哪个节点上
docker service ps <服务名称>
// 查看服务部署的具体信息:
docker service inspect --pretty <服务名称>
docker service create \
--with-registry-auth \
--name shequn-api \
-p 8000:8000 \
--replicas 2 \
--network swarm-network \
cloud-lm720/api:test
node必须开放 4789 端口 参考: https://blog.csdn.net/weixin_33722405/article/details/94662896
最佳方案: 防火墙换成 iptables 并且修改配置项:
IPTABLES_SAVE_ON_STOP="yes"
IPTABLES_SAVE_ON_RESTART="yes"
参考: https://blog.csdn.net/qq_14869093/article/details/102566291
本文为放下原创文章,转载无需和我联系,但请注明来自LW放下http://www.putyy.com
最新评论