docker、harbor的systemd启动守护进程脚本


/lib/systemd/system/docker.service
--------------------------------------------
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target docker.socket firewalld.service
Wants=network-online.target
Requires=docker.socket

[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd -H fd://
ExecReload=/bin/kill -s HUP $MAINPID
LimitNOFILE=1048576
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNPROC=infinity
LimitCORE=infinity
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
# restart the docker process if it exits prematurely
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s

[Install]
WantedBy=multi-user.target


/lib/systemd/system/docker.socket
-------------------------------------------
[Unit]
Description=Docker Socket for the API

[Socket]
# If /var/run is not implemented as a symlink to /run, you may need to
# specify ListenStream=/var/run/docker.sock instead.
ListenStream=/run/docker.sock
SocketMode=0660
SocketUser=root
SocketGroup=docker



/lib/systemd/system/harbor.service
-------------------------------------------------
[Unit]
Description=Harbor
After=docker.service systemd-networkd.service systemd-resolved.service
Requires=docker.service
Documentation=http://github.com/vmware/harbor
[Service]
Type=simple
Restart=on-failure
RestartSec=5
ExecStart=/usr/bin/docker-compose -f /usr/local/harbor/docker-compose.yml up
ExecStop=/usr/bin/docker-compose -f /usr/local/harbor/docker-compose.yml down
[Install]
WantedBy=multi-user.target

[Install]
WantedBy=sockets.target


PS:

========================================================

1.>以上脚本都需要在/etc/systemd/system目录下创建对应服务的软连接,即

     cd etc/systemd/system

     ln –s /etc/systemd/system/docker.service docker.service

     ln –s /etc/systemd/system/docker.socket docker.socket

     ln –s /etc/systemd/system/habor.service harbor.service

2.>重新加载下后台服务

    systemctl daemon-reload

3.>使用systemd对服务进行管控操作

   systemd  start|stop|restart|enable  docker|harbor

posted @ 2021-03-10 20:46  lexunix  阅读(384)  评论(0)    收藏  举报