portainer 集群环境_docker-swarm集群及portainer管理的搭建

简介:swarm:

Docker Swarm 是 Docker 的集群管理工具。它将 Docker 主机池转变为单个虚拟 Docker 主机。 Docker Swarm 提供了标准的 Docker API,所有任何已经与 Docker 守护程序通信的工具都可以使用 Swarm 轻松地扩展到多个主机。

portainer:

Portainer是一个轻量级的docker环境管理UI,可以用来管理docker宿主机和docker swarm集群。他的轻量级,轻量到只要个不到100M的docker镜像容器就可以完整的提供服务。直接启动即可,异常方便。而且。现在市面上开源的docker swarm管理平台比较少,尤其是这样轻量级的更加稀少

详细介绍,请自行百度,下面开始安装配置。

环境:

#把yum包更新到最新

yum update

10.10.10.101安装安装docker 18.06.1-ce 版本,加速镜像节点设为阿里云。开机自启动,打开docker2375的api端口。 防火墙开启2375-2379、9000-9001、7946、4789端口

#安装需要的软件包

yum install -y yum-utils device-mapper-persistent-data lvm2

#设置yum源

yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

#查看所有仓库中所有docker版本,并选择特定版本安装

yum list docker-ce

yum install docker-ce-18.06.1.ce-3.el7

#启动docker,设置为开机自启动

systemctl start docker

systemctl enable docker

docker version

#加速镜像节点设为阿里云

vi /etc/docker/daemon.json

{

"registry-mirrors": ["https://0lpged8c.mirror.aliyuncs.com"],

"live-restore": false

}

#重载生效

systemctl daemon-reload

systemctl restart docker

###打开docker2375的api端口

说明:swarm是通过docker api而进行docker管理的,所以需要将docker的rest api启动。

Centos docker配置文件位置:/etc/sysconfig/docker

修改配置文件中的内容如下:

OPTIONS='-H tcp://0.0.0.0:[docker_port] -H unix:///var/run/docker.sock --selinux-enabled'

将docker_port换成想要配置且未被占用的端口号,比如2375.

vi /usr/lib/systemd/system/docker.service

[Unit]

Description=Docker Application Container Engine

Documentation=https://docs.docker.com

After=network.target

[Service]

Type=notify

# the default is not to use systemd for cgroups because the delegate issues still

# exists and systemd currently does not support the cgroup feature set required

# for containers run by docker

EnvironmentFile=/etc/sysconfig/docker

ExecStart=/usr/bin/dockerd $OPTIONS

#ExecStart=/usr/bin/dockerd

ExecReload=/bin/kill -s HUP $MAINPID

# Having non-zero Limit*s causes performance problems due to accounting overhead

# in the kernel. We recommend using cgroups to do container-local accounting.

LimitNOFILE=infinity

LimitNPROC=infinity

LimitCORE=infinity

# Uncomment TasksMax if your systemd version supports it.

# Only systemd 226 and above support this version.

#TasksMax=infinity

TimeoutStartSec=0

# set delegate yes so that systemd does not reset the cgroups of docker containers

Delegate=yes

# kill only the docker process, not all processes in the cgroup

KillMode=process

[Install]

WantedBy=multi-user.target

vim /etc/sysconfig/docker

# /etc/sysconfig/docker# Modify these options if you want to change the way the docker daemon runs

OPTIONS='-H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock'

DOCKER_CERT_PATH=/etc/docker

# If you want to add your own registry to be used for docker search and docker# pull use the ADD_REGISTRY option to list a set of registries, each prepended# with --add-registry flag. The first registry added will be the first registry# searched.# ADD_REGISTRY='--add-registry registry.access.redhat.com'

# If you want to block registries from being used, uncomment the BLOCK_REGISTRY# option and give it a set of registries, each prepended with --block-registry# flag. For example adding docker.io will stop users from downloading p_w_picpaths# from docker.io# BLOCK_REGISTRY='--block-registry'

# If you have a registry secured with https but do not have proper certs# distributed, you can tell docker to not look for full authorization by# adding the registry to the INSECURE_REGISTRY line and uncommenting it.

INSECURE_REGISTRY='--insecure-registry dl.dockerpool.com:5000'

# On an SELinux system, if you remove the --selinux-enabled option, you# also need to turn on the docker_transition_unconfined boolean.# setsebool -P docker_transition_unconfined 1

# Location used for temporary files, such as those created by# docker load and build operations. Default is /var/lib/docker/tmp# Can be overriden by setting the following environment variable.# DOCKER_TMPDIR=/var/tmp

# Controls the /etc/cron.daily/docker-logrotate cron job status.# To disable, uncomment the line below.# LOGROTATE=false

重启docker服务

systemctl daemon-reload

systemctl restart docker

ps -ef | grep docker

可以看到docker进程的启动项-H tcp://0.0.0.0:2375

####防火墙开启2375-2379端口

查看防火墙状态

systemctl status firewalld

开启防火墙

systemctl start firewalld

关闭防火墙

systemctl stop firewalld

查看当前firewall状态

firewall-cmd --state

重启firewall

firewall-cmd --reload

禁止开机启动

systemctl disable firewalld.service

查看已经开放的端口:

firewall-cmd --list-ports

开启端口

firewall-cmd --zone=public --add-port=80/tcp --permanent

命令含义:

--zone #作用域

--add-port=80/tcp #添加端口,格式为:端口/通讯协议

--permanent #永久生效,没有此参数重启后失效

开启端口后需要重启防火墙

配置加入swarm集群

docker swarm init --advertise-addr 10.10.10.101

其他四台执行(10.10.10.102~10.10.10.105)

*****如果要脱离集群,按如下操作******

docker swarm leave

docker swarm leave --force

docker swarm join --token SWMTKN-1-51we7mu2o56e39w4q3abpk61wmy2e44jxavn0po3j5gsro0gc4-9fcrlj9e3k13aickfly43y7q5 10.10.10.101:2377

在10.10.10.101执行以下操作,将102、103提为manager

docker node promote 10-10-10-102

docker node promote 10-10-10-103

docker node ls

docker info

##安装swram集群版 portainer

curl -L https://downloads.portainer.io/portainer-agent-stack.yml -o portainer-agent-stack.yml

docker stack deploy --compose-file=portainer-agent-stack.yml portainer

浏览器访问10.10.10.101:9000

设置账号密码

访问其余四台

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值