Harbor 2.1.2 安裝部署


環境

首先需要准備好 Docker + Docker-Compose 環境,Docker 在 CentOS 7.x 的安裝教程請參考 這篇文章,后續文章假設你已經安裝好了上述環境。

安裝

標准安裝

首先從 Harbor 的官方 GitHub Relase 下載最新的安裝包,Harbor 本身的運行也是依賴於 Docker Compose ,整個壓縮包本質上就是一系列離線鏡像,執行安裝腳本就是執行 docker load 命令將需要的鏡像直接加載。

  1. 下載安裝包,請訪問 https://github.com/goharbor/harbor/releases/tag/v2.1.2 下載 tgz 壓縮包。

  2. 將文件移動到安裝文件夾,這里我建立了一個 /opt/harbor 文件夾。

  3. 運行 tar -xvf harbor-offline-installer-v1.10.1.tgz 解壓文件包。

  4. 移動到解壓完成的文件夾,編輯對應的 harbor.yml 文件,設置域名、SSL 證書等信息。

    注意⚠️:

    這一步的證書文件必須是全鏈證書(fullchain),否則后續 docker login 的時候會提示 X509 錯誤。

  5. 執行 ./install.sh --with-clair 開始安裝 Harbor。

完成上述步驟以后 Harbor 就安裝成功了。

不使用內置 NGINX

在我們的環境當中,NGINX 容器是單獨存在的,並且使用的是 docker nework create 創建的外部網絡。這個時候就不能夠使用 Harbor 安裝腳本內提供的 NGINX,需要變更 Harbor 的 Docker Compose 文件。

  1. 執行 docker-compose down 命令,停止所有 Harbor 容器。

  2. 編輯 Harbor 的 docker-compose.yml 文件,引入外部網絡,這里我以 internal-network 為例,下面是變更好的 YAML 文件。

    version: '2.3'
    services:
      log:
        image: goharbor/harbor-log:v2.1.2
        container_name: harbor-log
        restart: always
        dns_search: .
        cap_drop:
          - ALL
        cap_add:
          - CHOWN
          - DAC_OVERRIDE
          - SETGID
          - SETUID
        volumes:
          - /var/log/harbor/:/var/log/docker/:z
          - type: bind
            source: ./common/config/log/logrotate.conf
            target: /etc/logrotate.d/logrotate.conf
          - type: bind
            source: ./common/config/log/rsyslog_docker.conf
            target: /etc/rsyslog.d/rsyslog_docker.conf
        ports:
          - 127.0.0.1:1514:10514
        networks:
          - harbor
          - internal-network
      registry:
        image: goharbor/registry-photon:v2.1.2
        container_name: registry
        restart: always
        cap_drop:
          - ALL
        cap_add:
          - CHOWN
          - SETGID
          - SETUID
        volumes:
          - /data/registry:/storage:z
          - ./common/config/registry/:/etc/registry/:z
          - type: bind
            source: /data/secret/registry/root.crt
            target: /etc/registry/root.crt
          - type: bind
            source: ./common/config/shared/trust-certificates
            target: /harbor_cust_cert
        networks:
          - harbor
          - internal-network
        dns_search: .
        depends_on:
          - log
        logging:
          driver: "syslog"
          options:
            syslog-address: "tcp://127.0.0.1:1514"
            tag: "registry"
      registryctl:
        image: goharbor/harbor-registryctl:v2.1.2
        container_name: registryctl
        env_file:
          - ./common/config/registryctl/env
        restart: always
        cap_drop:
          - ALL
        cap_add:
          - CHOWN
          - SETGID
          - SETUID
        volumes:
          - /data/registry:/storage:z
          - ./common/config/registry/:/etc/registry/:z
          - type: bind
            source: ./common/config/registryctl/config.yml
            target: /etc/registryctl/config.yml
          - type: bind
            source: ./common/config/shared/trust-certificates
            target: /harbor_cust_cert
        networks:
          - harbor
          - internal-network
        dns_search: .
        depends_on:
          - log
        logging:
          driver: "syslog"
          options:
            syslog-address: "tcp://127.0.0.1:1514"
            tag: "registryctl"
      postgresql:
        image: goharbor/harbor-db:v2.1.2
        container_name: harbor-db
        restart: always
        cap_drop:
          - ALL
        cap_add:
          - CHOWN
          - DAC_OVERRIDE
          - SETGID
          - SETUID
        volumes:
          - /data/database:/var/lib/postgresql/data:z
        networks:
          harbor:
        dns_search: .
        env_file:
          - ./common/config/db/env
        depends_on:
          - log
        logging:
          driver: "syslog"
          options:
            syslog-address: "tcp://127.0.0.1:1514"
            tag: "postgresql"
      core:
        image: goharbor/harbor-core:v2.1.2
        container_name: harbor-core
        env_file:
          - ./common/config/core/env
        restart: always
        cap_drop:
          - ALL
        cap_add:
          - SETGID
          - SETUID
        volumes:
          - /data/ca_download/:/etc/core/ca/:z
          - /data/:/data/:z
          - ./common/config/core/certificates/:/etc/core/certificates/:z
          - type: bind
            source: ./common/config/core/app.conf
            target: /etc/core/app.conf
          - type: bind
            source: /data/secret/core/private_key.pem
            target: /etc/core/private_key.pem
          - type: bind
            source: /data/secret/keys/secretkey
            target: /etc/core/key
          - type: bind
            source: ./common/config/shared/trust-certificates
            target: /harbor_cust_cert
        networks:
          - harbor
          - internal-network
        dns_search: .
        depends_on:
          - log
          - registry
          - redis
          - postgresql
        logging:
          driver: "syslog"
          options:
            syslog-address: "tcp://127.0.0.1:1514"
            tag: "core"
      portal:
        image: goharbor/harbor-portal:v2.1.2
        container_name: harbor-portal
        restart: always
        cap_drop:
          - ALL
        cap_add:
          - CHOWN
          - SETGID
          - SETUID
          - NET_BIND_SERVICE
        volumes:
          - type: bind
            source: ./common/config/portal/nginx.conf
            target: /etc/nginx/nginx.conf
        networks:
          - harbor
          - internal-network
        dns_search: .
        depends_on:
          - log
        logging:
          driver: "syslog"
          options:
            syslog-address: "tcp://127.0.0.1:1514"
            tag: "portal"
    
      jobservice:
        image: goharbor/harbor-jobservice:v2.1.2
        container_name: harbor-jobservice
        env_file:
          - ./common/config/jobservice/env
        restart: always
        cap_drop:
          - ALL
        cap_add:
          - CHOWN
          - SETGID
          - SETUID
        volumes:
          - /data/job_logs:/var/log/jobs:z
          - type: bind
            source: ./common/config/jobservice/config.yml
            target: /etc/jobservice/config.yml
          - type: bind
            source: ./common/config/shared/trust-certificates
            target: /harbor_cust_cert
        networks:
          - harbor
          - internal-network
        dns_search: .
        depends_on:
          - core
        logging:
          driver: "syslog"
          options:
            syslog-address: "tcp://127.0.0.1:1514"
            tag: "jobservice"
      redis:
        image: goharbor/redis-photon:v2.1.2
        container_name: redis
        restart: always
        cap_drop:
          - ALL
        cap_add:
          - CHOWN
          - SETGID
          - SETUID
        volumes:
          - /data/redis:/var/lib/redis
        networks:
          harbor:
        dns_search: .
        depends_on:
          - log
        logging:
          driver: "syslog"
          options:
            syslog-address: "tcp://127.0.0.1:1514"
            tag: "redis"
    
    networks:
      harbor:
        external: false
      internal-network:
        external: true
    
  3. 在獨立的 NGINX 中創建對應的配置文件,在上一步的 YAML 文件內部,我為每個容器指定了 container_name,確保容器名字唯一不會因為外部原因而變動。這個配置文件我是從之前 Harbor 內部的 NGINX 拷貝出來的,直接拿去改吧改吧就能用。

    server{
        listen 80;
        server_name 你的域名;
        return 301 https://你的域名$request_uri;
    }
    
    server{
        listen 443 ssl;
        server_name 你的域名;
    
        # disable any limits to avoid HTTP 413 for large image uploads
        client_max_body_size 0;
    
        # required to avoid HTTP 411: see Issue #1486 (https://github.com/docker/docker/issues/1486)
        chunked_transfer_encoding on;
    
        # Add extra headers
        add_header Strict-Transport-Security "max-age=31536000; includeSubdomains; preload";
        add_header X-Frame-Options DENY;
        add_header Content-Security-Policy "frame-ancestors 'none'";
    
        ssl_certificate   /etc/nginx/ssl/你的域名/full.pem;      # SSL 證書文件的存放路徑
        ssl_certificate_key  /etc/nginx/ssl/你的域名/key.pem;   # SSL 密鑰文件的存放路徑
    
        ssl_protocols TLSv1.2;
        ssl_ciphers '!aNULL:kECDH+AESGCM:ECDH+AESGCM:RSA+AESGCM:kECDH+AES:ECDH+AES:RSA+AES:';
        ssl_prefer_server_ciphers on;
        ssl_session_cache shared:SSL:10m;
    
        location / {
          proxy_pass http://harbor-portal:8080/;
          proxy_set_header Host $http_host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    
          # When setting up Harbor behind other proxy, such as an Nginx instance, remove the below line if the proxy already has similar settings.
          proxy_set_header X-Forwarded-Proto $scheme;
    
          proxy_cookie_path / "/; HttpOnly; Secure";
    
          proxy_buffering off;
          proxy_request_buffering off;
        }
    
        location /c/ {
          proxy_pass http://harbor-core:8080/c/;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    
          # When setting up Harbor behind other proxy, such as an Nginx instance, remove the below line if the proxy already has similar settings.
          proxy_set_header X-Forwarded-Proto $scheme;
    
          proxy_cookie_path / "/; Secure";
    
          proxy_buffering off;
          proxy_request_buffering off;
        }
    
        location /api/ {
          proxy_pass http://harbor-core:8080/api/;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    
          # When setting up Harbor behind other proxy, such as an Nginx instance, remove the below line if the proxy already has similar settings.
          proxy_set_header X-Forwarded-Proto $scheme;
    
          proxy_cookie_path / "/; Secure";
    
          proxy_buffering off;
          proxy_request_buffering off;
        }
    
        location /chartrepo/ {
          proxy_pass http://harbor-core:8080/chartrepo/;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    
          # When setting up Harbor behind other proxy, such as an Nginx instance, remove the below line if the proxy already has similar settings.
          proxy_set_header X-Forwarded-Proto $scheme;
    
          proxy_cookie_path / "/; Secure";
    
          proxy_buffering off;
          proxy_request_buffering off;
        }
    
        location /v1/ {
          return 404;
        }
    
        location /v2/ {
          proxy_pass http://harbor-core:8080/v2/;
          proxy_set_header Host $http_host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    
          # When setting up Harbor behind other proxy, such as an Nginx instance, remove the below line if the proxy already has similar settings.
          proxy_set_header X-Forwarded-Proto $scheme;
          proxy_buffering off;
          proxy_request_buffering off;
          proxy_send_timeout 900;
          proxy_read_timeout 900;
        }
    
        location /service/ {
          proxy_pass http://harbor-core:8080/service/;
          proxy_set_header Host $http_host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    
          # When setting up Harbor behind other proxy, such as an Nginx instance, remove the below line if the proxy already has similar settings.
          proxy_set_header X-Forwarded-Proto $scheme;
    
          proxy_cookie_path / "/; Secure";
    
          proxy_buffering off;
          proxy_request_buffering off;
        }
    
        location /service/notifications {
          return 404;
        }
    }
    

這里我使用的是 acme.sh 申請的泛解析 SSL 證書。

效果


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM