Docker+Portainer测试环境构建步骤

测试环境部署步骤

一、服务器要求

  • 服务器资源要求:

FunctionPrime ApplicationThird-party Application
CPU(Cores) 8 4
Memory(G) 64 32
Disk 1T 1T
  • 操作系统:Cent OS 7.X 以上

     

二、部署准备工作

2.1 Linux Centos7 环境下安装Docker

  • 安装条件:docker官方要求Linux内核版本至少3.8以上,建议3.10以上

    • 检查Linux内核版本: uname -r

  • 安装docker版本:

    • docker CE 社区版本: docker-ce.x86_64

  • 关闭防火墙:

    • 关闭Linux系统防火墙:

      sudo systemctl stop firewalld.service
    • 开机不自动启动防火墙

      sudo systemctl disable firewalld.servic
    • 关闭SE Linux:

      vi /etc/selinux/config
      修改:SELINUX=disable
  • 安装wget命令:

    yum install -y wget
  • 下载阿里云docker社区版 yum源

    [root@localhost /]# cd /etc/yum.repos.d/
    [root@localhost yum.repos.d]# wget http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
  • 查看docker安装包:

    yum list | grep docker 
  • 安装Docker Ce 社区版本:

    yum install -y docker-ce.x86_64 
  • 设置开机启动:

    systemctl enable docker 
  • 更新xfsprogs日志文件:

    yum -y update xfsprogs
  • 启动docker:

    systemctl start docker 
  • 查看docker详细信息:

    docker info

 

2.2 Linux Centos7 环境下安装Docker-Compose

  • 安装pip工具

    yum install -y epel-release
    yum install -y python-pip
  • 安装docker-compose

    pip install -i https://pypi.tuna.tsinghua.edu.cn/simple docker-compose==1.24.1
  • 查看docker-compose版本

    docker-compose version
  • 安装pip报错时

    [root@localhost yum.repos.d]# yum install python-pip -y 已加载插件:fastestmirror 

    One of the configured repositories failed (未知), and yum doesn't have enough cached data to continue. At this point the only safe thing yum can do is fail. There are a few ways to work "fix" this:

    1. Contact the upstream for the repository and get them to fix the problem.

    2. Reconfigure the baseurl/etc. for the repository, to point to a working     upstream. This is most often useful if you are using a newer     distribution release than is supported by the repository (and the     packages for the previous distribution release still work).

    3. Disable the repository, so yum won't use it by default. Yum will then     just ignore the repository until you permanently enable it again or use     --enablerepo for temporary usage:

          yum-config-manager --disable <repoid>

    4. Configure the failing repository to be skipped, if it is unavailable.     Note that yum will try to contact the repo. when it runs most commands,     so will have to try and fail each time (and thus. yum will be be much     slower). If it is a very temporary problem though, this is often a nice     compromise:

          yum-config-manager --save --setopt=<repoid>.skip_if_unavailable=true           Cannot retrieve metalink for repository: epel/x86_64. Please verify its path and try again
    • 解决方法

      vi /etc/yum.repos.d/epel.repo
      修改epel.repo配置文件,注释掉metalink,取消注释baseurl

      修改前:  

    • 修改后:

       

       

        

2.3 Linux Centos7 环境下安装Portainer

  • 安装docker swarm集群环境

  1. 编辑hosts

    vi /etc/hosts

    在hosts文件中增加:

    10.102.129.12 prime-manager
    10.102.129.13 prime-worker
    47.115.94.124 remote-resposity

    如果访问不到,请注意关闭防火墙:

    iptables -F
  2. 增加域名解析

    vi  /etc/resolv.conf

    新增 nameserver 114.114.114.114
  3. 修改允许通过http访问,修改daemon.json文件

    vi /etc/docker/daemon.json

    在文件中增加:

    {
    "insecure-registries": ["registry.gitlab.com", "remote-reposity:9082"]
    }
  4. 修改Prime Application和Third-party Application环境中docker.service

    1. vim /usr/lib/systemd/system/docker.service

      新增"-H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock"

      systemctl daemon-reload

      systemctl restart docke
    2.  

       

       

  5. 在Prime Application环境中执行初始化swarm环境

    docker swarm init

    如果eth0有多网卡,需要通过指令指定某个IP

  6. 在Prime Application环境中查找加入该swarm环境的命令

    docker swarm join-token worker

    例子:

    docker swarm join --token SWMTKN-1-2zc03ogw4ucqvrie5l9whsbdii722mv7pnc2ybracyw0mbd8ei-98e5isnkisyjiaytnmynvvqvz 10.102.129.12:2377
  7. 在Third-party Application环境中执行上面的命令

    docker swarm join --token SWMTKN-1-2zc03ogw4ucqvrie5l9whsbdii722mv7pnc2ybracyw0mbd8ei-98e5isnkisyjiaytnmynvvqvz 10.102.129.12:2377
  8. 验证环境是否搭建成功

    docker node ls

    如果查询结果如下,表示成功

    ID             HOSTNAME     STATUS      AVAILABILIT    MANAGER STATUS  ENGINE VERSION
    x99r2wj8cbef075lz2235xi04 *   prime-manager Ready   Active Leader 19.03.12
  9. 下载portainer镜像

    docker pull portainer/portainer
  10. 创建挂载文件

    docker volume create +portainer_data
  11. 启动portainer容器

    docker run -d -p 9000:9000 \
    --restart=always \
    --name portainer \
    -v /var/run/docker.sock:/var/run/docker.sock \
      -v protainer_data:/data \
    portainer/portainer
  12. 通过http://IP:9000访问Portainer

    • 设置admin账号密码

     

     

    • 通过Remote管理docker

      Name: 任意

      Endpoint URL: IP:2375

       

       

    • 通过Enpoints 新增需要管理的docker容器

       

posted @ 2021-10-26 09:57  菜鸟楚  阅读(304)  评论(0编辑  收藏  举报