Linux-docker安装配置以及优化

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/yan7895566/article/details/82834216

安装最新版docker
curl -sSL https://get.docker.io | bash

优化docker

1.添加内核参数
默认配置下,如果在 CentOS 使用 Docker CE 看到下面的这些警告信息:
WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled
请添加内核配置参数以启用这些功能。
$ sudo tee -a /etc/sysctl.conf <<-EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
然后重新加载  sysctl.conf  即可
$ sudo sysctl -p

2.配置direct-lvm模式(需手动添加一块存储)
systemctl stop docker                #先停掉docker服务
pvcreate /dev/sdb && vgcreate docker /dev/sdb    #创建PV,创建VG

创建thinpool
创建pool
lvcreate --wipesignatures y -n thinpool docker -l 95%VG 
lvcreate --wipesignatures y -n thinpoolmeta docker -l 1%VG

数据LV大小为VG的95%,元数据LV大小为VG的1%,剩余的空间用来自动扩展。
将pool转换为thinpool
lvconvert -y --zero n -c 512K --thinpool docker/thinpool --poolmetadata docker/thinpoolmeta

配置thinpool
vim /etc/lvm/profile/docker-thinpool.profile    #配置池的自动扩展
activation {
    thin_pool_autoextend_threshold=80
    thin_pool_autoextend_percent=20
}
lvchange --metadataprofile docker-thinpool docker/thinpool    #应用配置变更
lvs -o+seg_monitor                        #状态监控检查

配置Docker(这一步可以省略,用下面3方法配置)
vim /etc/systemd/system/docker.service                #修改服务配置文件
--storage-driver=devicemapper --storage-opt=dm.thinpooldev=/dev/mapper/docker-thinpool --storage-opt dm.use_deferred_removal=true
ExecStart后加入storage相关配置参数,如果配置了$OPTIONS也可以在对应的EnvironmentFile中加入。

清除graphdriver
rm -rf /var/lib/docker/*
如果不删除,则会遇到以下的错误导致docker服务起不来
Error starting daemon: error initializing graphdriver: 
devmapper: Base Device UUID and Filesystem verification failed: devicemapper: 
Error running deviceCreate (ActivateDevice) dm_task_run failed

启动docker服务
systemctl daemon-reload && systemctl start docker && systemctl enable docker

3.配置阿里云镜像加速地址和配置direct-lvm模式
cat /etc/docker/daemon.json 
{"storage-driver": "devicemapper",
  "storage-opts": [ 
  "dm.thinpooldev=/dev/mapper/docker-thinpool",
  "dm.use_deferred_removal=true" ],
 "registry-mirrors": ["https://5f2jam6c.mirror.aliyuncs.com"]
}

猜你喜欢

转载自blog.csdn.net/yan7895566/article/details/82834216