项目地址
    https://github.com/docker/compose
    https://github.com/goharbor/harbor

    下载
    wget https://github.com/docker/compose/releases/download/1.26.0/docker-compose-Linux-x86_64

    sudo mv docker-compose-Linux-x86_64 /usr/local/bin/docker-compose
    sudo chmod +x /usr/local/bin/docker-compose

    1. [rancher@rmaster02 ~]$ docker-compose version
    2. docker-compose version 1.26.0, build d4451659
    3. docker-py version: 4.2.1
    4. CPython version: 3.7.7
    5. OpenSSL version: OpenSSL 1.1.0l 10 Sep 2019
    6. [rancher@rmaster02 ~]$
    1. [rancher@rmaster02 home]$ ll
    2. total 488972
    3. -rw-r--r-- 1 root root 500705880 Jun 7 08:57 harbor-offline-installer-v2.0.0.tgz
    4. drwx------. 2 login01 login01 62 Jan 11 13:41 login01
    5. drwx------ 4 rancher rancher 107 Jun 7 08:53 rancher
    6. [rancher@rmaster02 home]$ sudo tar xf harbor-offline-installer-v2.0.0.tgz
    7. [rancher@rmaster02 home]$ cd /home/harbor/
    8. [rancher@rmaster02 harbor]$ ll
    9. total 491056
    10. -rw-r--r-- 1 root root 3361 May 11 18:47 common.sh
    11. -rw-r--r-- 1 root root 502808042 May 11 18:48 harbor.v2.0.0.tar.gz
    12. -rw-r--r-- 1 root root 7816 May 11 18:47 harbor.yml.tmpl
    13. -rwxr-xr-x 1 root root 2523 May 11 18:47 install.sh
    14. -rw-r--r-- 1 root root 11347 May 11 18:47 LICENSE
    15. -rwxr-xr-x 1 root root 1856 May 11 18:47 prepare
    16. [rancher@rmaster02 harbor]$

    重命名 harbor.yml.tmpl 为 harbor.yml
    修改文件内容

    1. hostname: 192.168.11.101
    2. # http related config
    3. http:
    4. # port for http, default is 80. If https enabled, this port will redirect to https port
    5. port: 80
    6. # https related config
    7. #https:
    8. # https port for harbor, default is 443
    9. # port: 443
    10. # The path of cert and key files for nginx
    11. # certificate: /your/certificate/path
    12. # private_key: /your/private/key/path

    开始部署
    #开启helm仓库功能

    1. ./install.sh --with-trivy --with-chartmuseum
    1. [root@harboor harbor]# ./install.sh --with-trivy --with-clair
    2. Clair is deprecated please remove it from installation arguments !!!
    3. ./install.sh --with-trivy
    1. [root@rmaster02 ~]#
    2. [root@rmaster02 ~]# cd /home/harbor/
    3. [root@rmaster02 harbor]#
    4. [root@rmaster02 harbor]# ll
    5. total 491056
    6. -rw-r--r-- 1 root root 3361 May 11 18:47 common.sh
    7. -rw-r--r-- 1 root root 502808042 May 11 18:48 harbor.v2.0.0.tar.gz
    8. -rw-r--r-- 1 root root 7818 Jun 7 09:03 harbor.yml
    9. -rwxr-xr-x 1 root root 2523 May 11 18:47 install.sh
    10. -rw-r--r-- 1 root root 11347 May 11 18:47 LICENSE
    11. -rwxr-xr-x 1 root root 1856 May 11 18:47 prepare
    12. [root@rmaster02 harbor]# ./install.sh --with-trivy --with-clair
    13. [root@rmaster02 harbor]# docker-compose ps
    14. Name Command State Ports
    15. ------------------------------------------------------------------------------------------------------
    16. harbor-core /harbor/entrypoint.sh Up (health: starting)
    17. harbor-db /docker-entrypoint.sh Up (health: starting) 5432/tcp
    18. harbor-jobservice /harbor/entrypoint.sh Up (health: starting)
    19. harbor-log /bin/sh -c /usr/local/bin/ ... Up (health: starting) 127.0.0.1:1514->10514/tcp
    20. harbor-portal nginx -g daemon off; Up (health: starting) 8080/tcp
    21. nginx nginx -g daemon off; Up (health: starting) 0.0.0.0:80->8080/tcp
    22. redis redis-server /etc/redis.conf Up (health: starting) 6379/tcp
    23. registry /home/harbor/entrypoint.sh Up (health: starting) 5000/tcp
    24. registryctl /home/harbor/start.sh Up (health: starting)
    25. [root@rmaster02 harbor]#

    image.png

    Harbor 主机关机重启后容器是无法顺序重启的

    1. [root@harboor harbor]# docker-compose ps
    2. Name Command State Ports
    3. ---------------------------------------------------------------------------------------------------
    4. harbor-core /harbor/entrypoint.sh Up (health: starting)
    5. harbor-db /docker-entrypoint.sh 96 13 Exit 137
    6. harbor-jobservice /harbor/entrypoint.sh Exit 137
    7. harbor-log /bin/sh -c /usr/local/bin/ Up (healthy) 127.0.0.1:1514->10514/tcp
    8. ...
    9. harbor-portal nginx -g daemon off; Exit 128
    10. nginx nginx -g daemon off; Exit 128
    11. redis redis-server Exit 128
    12. /etc/redis.conf
    13. registry /home/harbor/entrypoint.sh Exit 137
    14. registryctl /home/harbor/start.sh Exit 137
    15. trivy-adapter /home/scanner/entrypoint.sh Exit 137
    16. [root@harboor harbor]#

    解决方式1 手动全部关闭容器,再手动启动一次

    1. [root@harboor harbor]# docker-compose down -v
    2. Stopping harbor-core ... done
    3. Stopping harbor-log ... done
    4. Removing nginx ... done
    5. Removing harbor-jobservice ... done
    6. Removing harbor-core ... done
    7. Removing trivy-adapter ... done
    8. Removing registryctl ... done
    9. Removing harbor-portal ... done
    10. Removing harbor-db ... done
    11. Removing registry ... done
    12. Removing redis ... done
    13. Removing harbor-log ... done
    14. Removing network harbor_harbor
    15. [root@harboor harbor]# docker-compose up -d
    16. Creating network "harbor_harbor" with the default driver
    17. Creating harbor-log ... done
    18. Creating harbor-db ... done
    19. Creating redis ... done
    20. Creating harbor-portal ... done
    21. Creating registry ... done
    22. Creating registryctl ... done
    23. Creating trivy-adapter ... done
    24. Creating harbor-core ... done
    25. Creating harbor-jobservice ... done
    26. Creating nginx ... done
    27. [root@harboor harbor]# docker-compose ps
    28. Name Command State Ports
    29. ---------------------------------------------------------------------------------------------------
    30. harbor-core /harbor/entrypoint.sh Up (health: starting)
    31. harbor-db /docker-entrypoint.sh 96 13 Up (health: starting)
    32. harbor-jobservice /harbor/entrypoint.sh Up (health: starting)
    33. harbor-log /bin/sh -c /usr/local/bin/ Up (health: starting) 127.0.0.1:1514->10514/tcp
    34. ...
    35. harbor-portal nginx -g daemon off; Up (health: starting)
    36. nginx nginx -g daemon off; Up (health: starting) 0.0.0.0:80->8080/tcp
    37. redis redis-server Up (health: starting)
    38. /etc/redis.conf
    39. registry /home/harbor/entrypoint.sh Up (health: starting)
    40. registryctl /home/harbor/start.sh Up (health: starting)
    41. trivy-adapter /home/scanner/entrypoint.sh Up (health: starting)
    42. [root@harboor harbor]#

    解决方式2 编写systemctl服务来管理harbor服务启动

    1. vi /etc/systemd/system/harbor.service
    2. #####################
    3. [Unit]
    4. Description=Harbor
    5. After=docker.service systemd-networkd.service systemd-resolved.service
    6. Requires=docker.service
    7. Documentation=http://github.com/goharbor/harbor
    8. [Service]
    9. Type=simple
    10. Restart=on-failure
    11. RestartSec=5
    12. ExecStart=/usr/local/bin/docker-compose -f /opt/harbor/docker-compose.yml up
    13. ExecStop=/usr/local/bin/docker-compose -f /opt/harbor/docker-compose.yml down
    14. [Install]
    15. WantedBy=multi-user.target
    16. #####################
    17. [root@harboor harbor]# systemctl enable harbor.service
    18. Created symlink from /etc/systemd/system/multi-user.target.wants/harbor.service to /etc/systemd/system/harbor.service.

    上述操作假定你的harbor安装在/opt/harbor下

    Harbor v2.2 及更高版本中支持Prometheus监控Harbor
    https://blog.51cto.com/lidabai/5177735
    启用harbor Prometheus监控配置

    1. # metric:
    2. # enabled: false
    3. # port: 9090
    4. # path: /metrics

    导入 grafana面板
    https://grafana.com/grafana/dashboards/?search=harbor