通过 stack 部署 portainer 和 agent
前言:为什么使用portainer
1、搭建简单
2、特别适合管理swarm集群
3、不适合当做监控
环境
docker version:20.10.14
linux version: CentOS Linux release 7.9
1、 新建挂载目录
因为yml
文件中的挂载目录是必须已存在
# 集群每个节点都要有
mkdir -p /data/portainer/volumes
# manger部署,仅manger有就行
mkdir -p /data/portainer/portainer_data
cd /data/portainer
2、编辑yml文件
注意:集群部署不用restart:always
vim portainer-agent.yml
version: '3.3'
services:
agent:
image: portainer/agent
labels:
service: portainer_agent
logging:
options:
labels: "service"
max-size: "100m"
max-file: "4"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /data/portainer/volumes:/var/lib/docker/volumes
networks:
- portainer_net
deploy:
mode: global
restart_policy:
condition: on-failure
delay: 10s
max_attempts: 3
window: 120s
placement:
constraints: [node.platform.os == linux]
portainer:
image: portainer/portainer
labels:
service: portainer
logging:
options:
labels: "service"
max-size: "100m"
max-file: "4"
command: -H tcp://tasks.agent:9001 --tlsskipverify
ports:
- "19000:9000"
volumes:
- /data/portainer/portainer_data:/data
networks:
- portainer_net
deploy:
mode: replicated
replicas: 1
restart_policy:
condition: on-failure
delay: 10s
max_attempts: 3
window: 120s
placement:
constraints:
- node.hostname == node1
networks:
portainer_net:
driver: overlay
attachable: true
3、部署
[root@node1 portainer]# docker stack deploy --compose-file=portainer-agent.yml portainer
Creating network portainer_portainer_net
Creating service portainer_agent
Creating service portainer_portainer
4、查看结果
[root@node1 portainer]# docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
ofxqg8moo4gx portainer_agent global 3/3 portainer/agent:latest
n1e5xxwwxapg portainer_portainer replicated 1/1 portainer/portainer:latest *:19000->9000/tcp
5、登录使用portainer
URL:
http://192.168.199.201:19000/#/init/admin
6、如果忘记密码
如上面stack部署,建议用scale
来停止容器
docker service scale portainer_portainer=0
运行专用容器重置密码
docker run --rm -v /data/portainer/portainer_data:/data portainer/helper-reset-password
然后用上面的账号密码登录
如果出现下面的内容,说明容器没停止
2022/06/01 09:06:34 Unable to open the database, err: timeout
from:https://github.com/portainer/helper-reset-password
web可视化页面修改密码的位置如下: