我想让docker从systemd cgroup驱动程序开始。由于某些原因,它仅在我的centos 7服务器上使用cgroupfs。
这是启动配置文件。
# systemctl cat docker
# /usr/lib/systemd/system/docker.service
[Unit]
Description=Docker Application Container Engine
Documentation=http://docs.docker.com
After=network.target
Wants=docker-storage-setup.service
Requires=docker-cleanup.timer
[Service]
Type=notify
NotifyAccess=all
EnvironmentFile=-/etc/sysconfig/docker
EnvironmentFile=-/etc/sysconfig/docker-storage
EnvironmentFile=-/etc/sysconfig/docker-network
Environment=GOTRACEBACK=crash
Environment=DOCKER_HTTP_HOST_COMPAT=1
Environment=PATH=/usr/libexec/docker:/usr/bin:/usr/sbin
ExecStart=/usr/bin/dockerd-current \
--add-runtime docker-runc=/usr/libexec/docker/docker-runc-current \
--default-runtime=docker-runc \
--exec-opt native.cgroupdriver=systemd \
--userland-proxy-path=/usr/libexec/docker/docker-proxy-current \
$OPTIONS \
$DOCKER_STORAGE_OPTIONS \
$DOCKER_NETWORK_OPTIONS \
$ADD_REGISTRY \
$BLOCK_REGISTRY \
$INSECURE_REGISTRY
ExecReload=/bin/kill -s HUP $MAINPID
LimitNOFILE=1048576
LimitNPROC=1048576
LimitCORE=infinity
TimeoutStartSec=0
Restart=on-abnormal
MountFlags=slave
[Install]
WantedBy=multi-user.target
# /etc/systemd/system/docker.service.d/docker-thinpool.conf
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd --storage-driver=devicemapper --storage-opt=dm.thinpooldev=/dev/mapper/docker-thinpool \
--storage-opt=dm.use_deferred_removal=true --storage-opt=dm.use_deferred_deletion=true
EOF
Run Code Online (Sandbox Code Playgroud)
当启动docker这样运行时:
# ps -fed |grep docker
root 8436 1 0 19:13 ? 00:00:00 /usr/bin/dockerd-current --storage-driver=devicemapper --storage-opt=dm.thinpooldev=/dev/mapper/docker-thinpool --storage-opt=dm.use_deferred_removal=true --storage-opt=dm.use_deferred_deletion=true
root 8439 8436 0 19:13 ? 00:00:00 /usr/bin/docker-containerd-current -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --shim docker-containerd-shim --metrics-interval=0 --start-timeout 2m --state-dir /var/run/docker/libcontainerd/containerd --runtime docker-runc
Run Code Online (Sandbox Code Playgroud)
这是码头工人信息输出
docker info
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 1
Server Version: 1.12.6
Storage Driver: devicemapper
Pool Name: docker-thinpool
Pool Blocksize: 524.3 kB
Base Device Size: 10.74 GB
Backing Filesystem: xfs
Data file:
Metadata file:
Data Space Used: 185.6 MB
Data Space Total: 1.015 GB
Data Space Available: 829.4 MB
Metadata Space Used: 77.82 kB
Metadata Space Total: 8.389 MB
Metadata Space Available: 8.311 MB
Thin Pool Minimum Free Space: 101.2 MB
Udev Sync Supported: true
Deferred Removal Enabled: true
Deferred Deletion Enabled: true
Deferred Deleted Device Count: 0
Library Version: 1.02.135-RHEL7 (2016-11-16)
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: null bridge overlay host
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Security Options: seccomp
Kernel Version: 3.10.0-514.16.1.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
Number of Docker Hooks: 2
CPUs: 1
Total Memory: 992.7 MiB
Name: master
ID: 6CFR:H7SN:MEU7:PNJH:UMSO:6MNE:43Q5:SF4K:Z25I:BKHP:53U4:63SO
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Insecure Registries:
127.0.0.0/8
Registries: docker.io (secure)
Run Code Online (Sandbox Code Playgroud)
如何使它与systemd一起运行?
谢谢SR
Gee*_*elt 30
不涉及编辑 systemd 单元或插件的解决方案是创建(或编辑)/etc/docker/daemon.json配置文件并包含以下内容:
{
"exec-opts": ["native.cgroupdriver=systemd"]
}
Run Code Online (Sandbox Code Playgroud)
保存后,重启你的docker服务。
sudo systemctl restart docker
Run Code Online (Sandbox Code Playgroud)
这种解决方案显然只有在您想在系统范围内应用此解决方案时才可行。
由于我有两个配置文件,因此我还需要在第二个配置文件中添加该条目- /etc/systemd/system/docker.service.d/docker-thinpool.conf:
--exec-opt native.cgroupdriver=systemd \
Run Code Online (Sandbox Code Playgroud)
补充一下,cgroupfs 是 docker 自己的控制组管理器。然而,对于大多数 Linux 发行版,ssytemd 现在是默认的 init 系统,systemd 与 Linux 控制组紧密集成,并且在 Kubernetes 站点中,他们建议使用 systemd(见下文),因为将 cgroupfs 与 systemd 一起使用似乎不是最佳选择
\n\n所以最好使用 systemd 来进行 cgroup 管理。kubelet 默认配置为使用 systemd。因此将 Docker 更改为使用 systemd Cgroup 驱动程序更容易、更好
\n\n这种重叠的历史在这里https://lwn.net/Articles/676831/
\n\n在 Kubernetes 站点中,他们建议使用 systemd https://kubernetes.io/docs/setup/product-environment/container-runtimes/
\n\n\n\nCgroup 驱动程序 当选择 systemd 作为 Linux 发行版的 init 系统时,init 进程会生成并使用根控制组 (cgroup) 并充当 cgroup 管理器。Systemd 与 cgroup 紧密集成,将为每个进程分配 cgroup。可以配置容器运行时和 kubelet 以使用 cgroupfs。将 cgroupfs 与 systemd 一起使用意味着将有两个不同的 cgroup 管理器。
\n\n控制组用于限制分配给进程的资源。单个 cgroup 管理器将简化正在分配的资源的视图,并且默认情况下会对可用资源和正在使用的资源有更一致的视图。当我们有两名经理时,我们最终会对这些资源有两种看法。我们在现场看到过这样的情况:配置为对 kubelet 和 Docker 使用 cgroupfs,并对节点上运行的其余进程使用 systemd 在资源压力下变得不稳定。
\n
| 归档时间: |
|
| 查看次数: |
14256 次 |
| 最近记录: |