生產搭建環境:
操做系統:CentOS7.5
內存大小:8GB
硬盤:100Glinux
目錄:
一、Docker安裝
二、環境準備與清理
三、調優docker
#vi /etc/sysctl.confjson
net.ipv4.ip_forward=1
net.bridge.bridge-nf-call-iptables=1
net.ipv4.neigh.default.gc_thresh1=4096
net.ipv4.neigh.default.gc_thresh2=6144
net.ipv4.neigh.default.gc_thresh3=8192
kernel.shmmax = 8589934592
kernel.shmmni = 4096
kernel.shmall = 2097152
kernel.sem = 1010 129280 1010 128
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 4194304
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576
fs.aio-max-nr = 1048576
fs.file-max = 6815744centos
#modprobe br_netfilter
#/sbin/sysctl -p緩存
1.1.2. 修改系統資源限制bash
#vi /etc/security/limits.confapp
2.2 docker 環境準備
添加用戶(可選)ide
#sudo adduser dkadm優化
爲新用戶設置密碼(密碼輸入兩次)操作系統
#passwd dkadm
爲新用戶添加sudo權限
#echo 'dkadm ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers
卸載舊版本Docker軟件
$ su - dkadm
$ sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-selinux \
docker-engine-selinux \
docker-engine \
container*
更新源信息並依賴包安裝
$ sudo yum update -y
$ sudo yum install -y yum-utils device-mapper-persistent-data \
lvm2 bash-completion
添加軟件倉庫源信息
$ sudo yum-config-manager --add-repo \
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
更新倉庫源緩存並安裝最新穩定的docker-ce版本
$ sudo yum makecache all
$ sudo yum -y install docker-ce docker-ce-selinux
列出倉庫源中可用的docker-ce版本,並安裝指定的docker-ce版本(可選)
$ sudo yum list docker-ce --showduplicates | sort -r
$ sudo yum -y install --setopt=obsoletes=0 docker-ce-<VERSION_STRING> docker-ce-selinux
若是已經安裝高版本docker,可進行降級安裝(可選)
$ sudo yum downgrade --setopt=obsoletes=0 -y docker-ce-<VERSION_STRING> docker-ce-selinux
把當前用戶加入docker組
$ sudo usermod -aG docker dkadm
啓動docker服務並設置開機啓動
$ sudo systemctl start docker
$ sudo systemctl status docker #查看docker服務運行狀態
$ sudo systemctl enable docker
$ sudo systemctl list-unit-files |grep docker
3.3 docker 優化
鏡像加速與日誌驅動配置
$ sudo vi /etc/docker/daemon.json
{
"registry-mirrors": ["https://yeuphhaz.mirror.aliyuncs.com"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m",
"max-file": "3"
}
}
使用docker info 查看docker驅動配置及其餘信息overlay2
$ sudo docker info
配置完文件重啓docker
$ sudo systemctl daemon-reload$ sudo systemctl restart docker