Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1737023
  • 博文数量: 150
  • 博客积分: 660
  • 博客等级: 上士
  • 技术积分: 2480
  • 用 户 组: 普通用户
  • 注册时间: 2005-08-08 11:39
文章分类

全部博文(150)

文章存档

2019年(4)

2018年(36)

2017年(53)

2016年(7)

2015年(3)

2014年(3)

2013年(27)

2012年(2)

2011年(1)

2006年(1)

2005年(13)

分类: 系统运维

2017-11-27 19:15:26

docker ce 在centos7.4下的安装和配置

准备

如果已经安装了docker1.x版本,先删除

yum remove docker docker-common docker-selinux docker-engine

必须是centos7

cat /etc/centos-release
CentOS Linux release 7.4.1708 (Core)

需要centos-extras软件库

cat /etc/yum.repos.d/CentOS-Base.repo

......
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
mirrorlist=
#baseurl=
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
......

安装docker-ce

安装yum-uitils、device-mapper-persistent-data、lvm2等

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

安装软件仓库

yum-config-manager \
    --add-repo \
    
    
已加载插件:fastestmirror
adding repo from: 
grabbing file  to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo

安装

yum install docker-ce

已加载插件:fastestmirror
docker-ce-stable                                         | 2.9 kB     00:00
docker-ce-stable/x86_64/primary_db                         | 9.3 kB   00:01
Loading mirror speeds from cached hostfile
 * base: mirrors.tuna.tsinghua.edu.cn
 * epel: mirrors.tongji.edu.cn
 * extras: mirrors.aliyun.com
 * updates: mirrors.tuna.tsinghua.edu.cn
正在解决依赖关系
--> 正在检查事务
---> 软件包 docker-ce.x86_64.0.17.09.0.ce-1.el7.centos 将被 安装
--> 正在处理依赖关系 container-selinux >= 2.9,它被软件包 docker-ce-17.09.0.ce-1.el7.centos.x86_64 需要
--> 正在处理依赖关系 libltdl.so.7()(64bit),它被软件包 docker-ce-17.09.0.ce-1.el7.centos.x86_64 需要
--> 正在检查事务
---> 软件包 container-selinux.noarch.2.2.28-1.git85ce147.el7 将被 安装
---> 软件包 libtool-ltdl.x86_64.0.2.4.2-22.el7_3 将被 安装
--> 解决依赖关系完成

依赖关系解决

================================================================================
 Package            架构    版本                        源                 大小
================================================================================
正在安装:
 docker-ce          x86_64  17.09.0.ce-1.el7.centos     docker-ce-stable   21 M
为依赖而安装:
 container-selinux  noarch  2:2.28-1.git85ce147.el7     extras             29 k
 libtool-ltdl       x86_64  2.4.2-22.el7_3              base               49 k

事务概要
================================================================================
安装  1 软件包 (+2 依赖软件包)

总下载量:21 M
安装大小:76 M
Downloading packages:
(1/3): libtool-ltdl-2.4.2-22.el7_3.x86_64.rpm              |  49 kB   00:00
(2/3): container-selinux-2.28-1.git85ce147.el7.noarch.rpm  |  29 kB   00:00
warning: /var/cache/yum/x86_64/7/docker-ce-stable/packages/docker-ce-17.09.0.ce-1.el7.centos.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY
docker-ce-17.09.0.ce-1.el7.centos.x86_64.rpm 的公钥尚未安装
(3/3): docker-ce-17.09.0.ce-1.el7.centos.x86_64.rpm        |  21 MB   00:18
--------------------------------------------------------------------------------
总计                                               1.2 MB/s |  21 MB  00:18
从  检索密钥
导入 GPG key 0x621E9F35:
 用户ID     : "Docker Release (CE rpm) "
 指纹       : 060a 61c5 1b55 8a7f 742b 77aa c52f eb6b 621e 9f35
 来自       : 
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安装    : 2:container-selinux-2.28-1.git85ce147.el7.noarch            1/3
setsebool:  SELinux is disabled.
  正在安装    : libtool-ltdl-2.4.2-22.el7_3.x86_64                          2/3
  正在安装    : docker-ce-17.09.0.ce-1.el7.centos.x86_64                    3/3
  验证中      : libtool-ltdl-2.4.2-22.el7_3.x86_64                          1/3
  验证中      : docker-ce-17.09.0.ce-1.el7.centos.x86_64                    2/3
  验证中      : 2:container-selinux-2.28-1.git85ce147.el7.noarch            3/3

已安装:
  docker-ce.x86_64 0:17.09.0.ce-1.el7.centos

作为依赖被安装:
  container-selinux.noarch 2:2.28-1.git85ce147.el7
  libtool-ltdl.x86_64 0:2.4.2-22.el7_3

完毕!

安装指定的docker-ce版本

列出版本

yum list docker-ce --showduplicates | sort -r
已加载插件:fastestmirror
已安装的软件包
可安装的软件包
 * updates: mirrors.tuna.tsinghua.edu.cn
Loading mirror speeds from cached hostfile
 * extras: mirrors.aliyun.com
 * epel: mirrors.tongji.edu.cn
docker-ce.x86_64            17.09.0.ce-1.el7.centos            docker-ce-stable
docker-ce.x86_64            17.09.0.ce-1.el7.centos            @docker-ce-stable
docker-ce.x86_64            17.06.2.ce-1.el7.centos            docker-ce-stable
docker-ce.x86_64            17.06.1.ce-1.el7.centos            docker-ce-stable
docker-ce.x86_64            17.06.0.ce-1.el7.centos            docker-ce-stable
docker-ce.x86_64            17.03.2.ce-1.el7.centos            docker-ce-stable
docker-ce.x86_64            17.03.1.ce-1.el7.centos            docker-ce-stable
docker-ce.x86_64            17.03.0.ce-1.el7.centos            docker-ce-stable
 * base: mirrors.tuna.tsinghua.edu.cn

安装指定版本(例如第一个)

yum install docker-ce-17.09.0.ce-1.el7.centos

已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.tuna.tsinghua.edu.cn
 * epel: mirrors.ustc.edu.cn
 * extras: mirrors.aliyun.com
 * updates: mirrors.tuna.tsinghua.edu.cn
软件包 docker-ce-17.09.0.ce-1.el7.centos.x86_64 已安装并且是最新版本
无须任何处理

centos7.4使用devicemapper作为存储配置

依据

docker官方文档推荐 

Centos7 下Docker CE当前版本支持的存储驱动

仅为 devicemapper,vfs

稳定性考虑

aufs、overlay、devicemapper 具有最高的稳定性

经验与专业技能

如果有lvm的经验和知识,devicemapper则是首选

结论

因此综合考虑在centos7上使用devicemapper作为存储驱动

devicemapper配置过程

创建两个逻辑卷(thinpoo和thinpoolmeta)

# 设置centos pool 20%的空间作为thinpool
lvcreate --wipesignatures y -n thinpool centos -l 20%VG
  Logical volume "thinpool" created.
# 设置centos pool 2%作为metapool
lvcreate --wipesignatures y -n thinpoolmeta centos -l 2%VG
WARNING: xfs signature detected on /dev/centos/thinpoolmeta at offset 0. Wipe it? [y/n]: y
  Wiping xfs signature on /dev/centos/thinpoolmeta.
  Logical volume "thinpoolmeta" created.

转换卷

lvconvert -y \
--zero n \
-c 512K \
--thinpool centos/thinpool \
--poolmetadata centos/thinpoolmeta

  Thin pool volume with chunk size 512.00 KiB can address at most 126.50 TiB of data.
  WARNING: Converting logical volume centos/thinpool and centos/thinpoolmeta to thin pool's data and metadata volumes with metadata wiping.
  THIS WILL DESTROY CONTENT OF LOGICAL VOLUME (filesystem etc.)
  Converted centos/thinpool_tdata to thin pool.

设置thinpool空间的自动扩展

## 设置使用空间达到80%时,自动扩展20%的空间
vi /etc/lvm/profile/docker-thinpool.profile

activation {
  thin_pool_autoextend_threshold=80
  thin_pool_autoextend_percent=20
} 

应用上述lvm的profile,使生效

lvchange --metadataprofile docker-thinpool docker/thinpool

Logical volume centos/thinpool changed.

打开自动扩展监控

lvs -o+seg_monitor
  LV       VG     Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert Monitor
  goluk    centos -wi-ao---- 100.00g
  root     centos -wi-ao----  50.00g
  swap     centos -wi-ao----   8.00g
  thinpool centos twi-a-t--- 111.57g             0.00   0.01                             monitored

编辑docker服务的配置文件

mkdir /etc/docker && vi /etc/docker/daemon.json
{
    "storage-driver": "devicemapper",
    "storage-opts": [
    "dm.thinpooldev=/dev/mapper/centos-thinpool",
    "dm.use_deferred_removal=true",
    "dm.use_deferred_deletion=true"
    ]
}

启动docker

systemctl start docker

确认docker使用了上述配置

## 查看docker info 输出关于存储的配置信息

docker info
......
Server Version: 17.09.0-ce
Storage Driver: devicemapper
 Pool Name: centos-thinpool
 Pool Blocksize: 524.3kB
 Base Device Size: 10.74GB
 Backing Filesystem: xfs
 Data file:
 Metadata file:
 Data Space Used: 20.45MB
 Data Space Total: 119.8GB
 Data Space Available: 119.8GB
 Metadata Space Used: 831.5kB
 Metadata Space Total: 11.98GB
 Metadata Space Available: 11.98GB
 Thin Pool Minimum Free Space: 11.98GB
 ...... 

主要参考

 Use the Device Mapper storage driver

docker 存储驱动devicemapper利用 thinpool突破100G限制

阅读(4360) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~