码迷,mamicode.com
首页 > 其他好文 > 详细

Harbor 开机自启遇到的问题

时间:2019-07-07 14:43:25      阅读:255      评论:0      收藏:0      [点我收藏+]

标签:gis   fda   需要   seconds   path   html   安装路径   warning   network   

Harbor 是一个企业级的 Docker 私有仓库项目,它本身由多个 Docker Containers 组成,通过 docker-compose 管理 containers 之间的依赖关系。

安装

安装参见官方文档:Harbor - Installation and Configuration Guide
修改 harbor.yml 时,需要注意的有:

  1. 使用 https 时,要自己生成证书,然后在 harbor.yml 里配置好证书的路径。
    • 客户端也需要安装你生成的这个证书,否则会报错。(所以证书要做好备份)
  2. data_volume 可以指定为 /data/harbor,然后要定期备份这个文件夹。(或者直接在新机器上装个 harbor,用 harbor 自带的仓库复制功能做定期备份。)
  3. 企业的话,可能还需要配置 ldap 集成验证。

然后 sudo ./install.sh 安装 harbor(貌似必须用 sudo,因为生成出来的配置文件的 owner 都是 root,而且权限设得很严格。)
安装完成后会自动启动 harbor.

自动启动

查看 harbor 目录下的 docker-compose.yml 会发现,所有的 containers 都配置了 restart: always

version: '2.3'
services:
  log:
    image: goharbor/harbor-log:v1.8.1
    container_name: harbor-log
    restart: always
    dns_search: .
    # ......

  registry:
    image: goharbor/registry-photon:v2.7.1-patch-2819-v1.8.1
    container_name: registry
    restart: always
    # ......

这表示所有的容器在意外关闭后都会自动重启,比如 docker 重启或服务器重启。(手动 stop 不会自动重启)

但是我在手动运行 docker-compose up -d,然后重启服务器后,发现有几个 container 并没有自动重启:

[ryan@ryan-pc ~]$ docker ps -a
CONTAINER ID        IMAGE                                               COMMAND                  CREATED             STATUS                             PORTS                       NAMES
f30d802002a4        goharbor/nginx-photon:v1.8.1                        "nginx -g 'daemon of…"   13 hours ago        Exited (128) 27 minutes ago        0.0.0.0:80->80/tcp          nginx
21472ce8a993        goharbor/harbor-portal:v1.8.1                       "nginx -g 'daemon of…"   13 hours ago        Exited (128) 27 minutes ago        80/tcp                      harbor-portal
5d866bb17c58        goharbor/harbor-jobservice:v1.8.1                   "/harbor/start.sh"       13 hours ago        Exited (137) 26 minutes ago                                    harbor-jobservice
0cf0f93b5a87        goharbor/harbor-core:v1.8.1                         "/harbor/start.sh"       13 hours ago        Up 11 seconds (health: starting)                               harbor-core
cba280d9b945        goharbor/redis-photon:v1.8.1                        "docker-entrypoint.s…"   13 hours ago        Exited (137) 26 minutes ago        6379/tcp                    redis
473e46d1f746        goharbor/harbor-registryctl:v1.8.1                  "/harbor/start.sh"       13 hours ago        Up 11 seconds (health: starting)                               registryctl
51f105f1691d        goharbor/registry-photon:v2.7.1-patch-2819-v1.8.1   "/entrypoint.sh /etc…"   13 hours ago        Exited (137) 26 minutes ago        5000/tcp                    registry
c41594ec7779        goharbor/harbor-db:v1.8.1                           "/entrypoint.sh post…"   13 hours ago        Up 11 seconds (health: starting)   5432/tcp                    harbor-db
713bd4961772        goharbor/harbor-log:v1.8.1                          "/bin/sh -c /usr/loc…"   13 hours ago        Up 11 seconds (health: starting)   127.0.0.1:1514->10514/tcp   harbor-log

可以看到下列五个容器都处于 Exited 状态:

  1. goharbor/nginx-photon:v1.8.1
  2. goharbor/harbor-portal:v1.8.1
  3. goharbor/harbor-jobservice:v1.8.1
  4. goharbor/redis-photon:v1.8.1
  5. goharbor/registry-photon:v2.7.1-patch-2819-v1.8.1

搜索发现有人提过这个 issue: https://github.com/goharbor/harbor/issues/7008

于是尝试将 harbor 配成 systemd 的 service,添加配置文件 /usr/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/local/bin/docker-compose -f {{ harbor_install_path }}/harbor/docker-compose.yml up
ExecStop=/usr/local/bin/docker-compose -f {{ harbor_install_path }}/harbor/docker-compose.yml down

[Install]
WantedBy=multi-user.target

其中 {{ harbor_install_path }} 换成自己的 harbor 安装路径。
还有 docker-compose 的绝对路径,请通过 which docker-compose 查看。

然后启动该项服务:

sudo systemctl enable harbor
sudo systemctl start harbor

现在查看下 harbor.service 的情况:

● harbor.service - Harbor
   Loaded: loaded (/usr/lib/systemd/system/harbor.service; enabled; vendor preset: disabled)
   Active: active (running) since Sun 2019-07-07 12:54:27 CST; 2min 4s ago
     Docs: http://github.com/vmware/harbor
 Main PID: 9734 (docker-compose)
    Tasks: 11 (limit: 4915)
   Memory: 35.7M
   CGroup: /system.slice/harbor.service
           └─9734 /usr/bin/python /usr/bin/docker-compose -f /home/ryan/harbor/docker-compose.yml up

7月 07 12:54:30 ryan-pc docker-compose[9734]: [128B blob data]
7月 07 12:54:31 ryan-pc docker-compose[9734]: [167B blob data]
7月 07 12:54:31 ryan-pc docker-compose[9734]: registryctl    | WARNING: no logs are available with the 'syslog' log driver
7月 07 12:54:31 ryan-pc docker-compose[9734]: registry       | WARNING: no logs are available with the 'syslog' log driver
7月 07 12:54:31 ryan-pc docker-compose[9734]: harbor-db      | WARNING: no logs are available with the 'syslog' log driver
7月 07 12:54:31 ryan-pc docker-compose[9734]: redis          | WARNING: no logs are available with the 'syslog' log driver
7月 07 12:54:31 ryan-pc docker-compose[9734]: harbor-core    | WARNING: no logs are available with the 'syslog' log driver
7月 07 12:54:31 ryan-pc docker-compose[9734]: harbor-jobservice | WARNING: no logs are available with the 'syslog' log driver
7月 07 12:54:31 ryan-pc docker-compose[9734]: harbor-portal  | WARNING: no logs are available with the 'syslog' log driver
7月 07 12:54:31 ryan-pc docker-compose[9734]: nginx          | WARNING: no logs are available with the 'syslog' log driver

重启再看,发现 harbor 容器组终于全部 up 了:

[ryan@ryan-pc ~]$ docker ps -a
CONTAINER ID        IMAGE                                               COMMAND                  CREATED             STATUS                    PORTS                       NAMES
90943210e354        goharbor/nginx-photon:v1.8.1                        "nginx -g 'daemon of…"   37 seconds ago      Up 35 seconds (healthy)   0.0.0.0:80->80/tcp          nginx
bc70706d7b5f        goharbor/harbor-portal:v1.8.1                       "nginx -g 'daemon of…"   38 seconds ago      Up 36 seconds (healthy)   80/tcp                      harbor-portal
54e132bd1a10        goharbor/harbor-jobservice:v1.8.1                   "/harbor/start.sh"       38 seconds ago      Up 36 seconds                                         harbor-jobservice
28ada4a941ee        goharbor/harbor-core:v1.8.1                         "/harbor/start.sh"       39 seconds ago      Up 37 seconds (healthy)                               harbor-core
de44686f7e72        goharbor/registry-photon:v2.7.1-patch-2819-v1.8.1   "/entrypoint.sh /etc…"   39 seconds ago      Up 38 seconds (healthy)   5000/tcp                    registry
e5efdae34c13        goharbor/harbor-db:v1.8.1                           "/entrypoint.sh post…"   39 seconds ago      Up 38 seconds (healthy)   5432/tcp                    harbor-db
a5fe52e1f184        goharbor/harbor-registryctl:v1.8.1                  "/harbor/start.sh"       39 seconds ago      Up 38 seconds (healthy)                               registryctl
4a74b5f3499a        goharbor/redis-photon:v1.8.1                        "docker-entrypoint.s…"   39 seconds ago      Up 38 seconds             6379/tcp                    redis
677fd84d0a70        goharbor/harbor-log:v1.8.1                          "/bin/sh -c /usr/loc…"   40 seconds ago      Up 39 seconds (healthy)   127.0.0.1:1514->10514/tcp   harbor-log

参考

Harbor 开机自启遇到的问题

标签:gis   fda   需要   seconds   path   html   安装路径   warning   network   

原文地址:https://www.cnblogs.com/kirito-c/p/11145881.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!