docker harbor2.2.3安裝


簡介

Harbor是一個用於存儲和分發Docker鏡像的企業級Registry服務器,由vmware開源,其通過添加一些企業必需的功能特性,例如安全、標識和管理等,擴展了開源Docker Distribution。作為一個企業級私有Registry服務器,Harbor提供了更好的性能和安全。提升用戶使用Registry構建和運行環境傳輸鏡像的效率。Harbor支持安裝在多個Registry節點的鏡像資源復制,鏡像全部保存在私有Registry中, 確保數據和知識產權在公司內部網絡中管控,另外,Harbor也提供了高級的安全特性,諸如用戶管理,訪問控制和活動審計等。

vmware官方開源服務列表地址:https://vmware.github.io/harbor/cn/

harbor官方github地址:https://github.com/vmware/harbor

harbor官方網址:https://goharbor.io/ 

Harbor功能官方介紹

基於角色的訪問控制:用戶與Docker鏡像倉庫通過“項目”進行組織管理,一個用戶可以對多個鏡像倉庫在同一命名空間(project)里有不同的權限。

鏡像復制:鏡像可以在多個Registry實例中復制(同步)。尤其適合於負載均衡,高可用,混合雲和多雲的場景。

圖形化用戶界面:用戶可以通過瀏覽器來瀏覽,檢索當前Docker鏡像倉庫,管理項目和命名空間。

AD/LDAP 支:Harbor可以集成企業內部已有的AD/LDAP,用於鑒權認證管理。

審計管理:所有針對鏡像倉庫的操作都可以被記錄追溯,用於審計管理。

國際化:已擁有英文、中文、德文、日文和俄文的本地化版本。更多的語言將會添加進來。

RESTful API - RESTful API :提供給管理員對於Harbor更多的操控, 使得與其它管理軟件集成變得更容易。

部署簡單:提供在線和離線兩種安裝工具, 也可以安裝到vSphere平台(OVA方式)虛擬設備。

Harbor的各個組件作用

組件名 作用
nginx harbor的一個反向代理組件,代理registry、ui、token等服務。這個代理會轉發harbor web和docker client的各種請求到后端服務上。
harbor-adminserver harbor系統管理接口,可以修改系統配置以及獲取系統信息
harbor-db 存儲項目的元數據、用戶、規則、復制策略等信息
harbor-jobservice harbor里面主要是為了鏡像倉庫之前同步使用的
harbor-log 收集其他harbor的日志信息
harbor-ui 一個用戶界面模塊,用來管理registry
registry 存儲docker images的服務,並且提供pull/push服務
redis 存儲緩存信息
webhook 當registry中的image狀態發生變化的時候去記錄更新日志、復制等操作
token service 在docker client進行pull/push的時候負責token的發放

 

Harbor安裝的先決條件

1、硬件

Resource Minimum Recommended
CPU 2 CPU 4 CPU
Mem 4 GB 8 GB
Disk 40 GB 160 GB

2、軟件

Software Version Description
Docker engine Version 17.06.0-ce+ or higher For installation instructions, see Docker Engine documentation
Docker Compose Version 1.18.0 or higher For installation instructions, see Docker Compose documentation
Openssl Latest is preferred Used to generate certificate and keys for Harbor

3、端口

Port Protocol Description
443 HTTPS Harbor portal and core API accept HTTPS requests on this port. You can change this port in the configuration file.
4443 HTTPS Connections to the Docker Content Trust service for Harbor. Only required if Notary is enabled. You can change this port in the configuration file.
80 HTTP Harbor portal and core API accept HTTP requests on this port. You can change this port in the configuration file.

安裝Harbor

下載地址:https://github.com/goharbor/harbor/releases

安裝文檔:https://github.com/vmware/harbor/blob/master/docs/installation_guide.md 

 下載離線安裝包

  # cd /usr/local/src

# wget https://github.com/goharbor/harbor/releases/download/v2.2.3/harbor-offline-installer-v2.2.3.tgz

 

# tar xfz harbor-offline-installer-v2.2.3.tgz

# ln -sv /usr/local/src/harbor /usr/local/

# cd /usr/local/harbor/

  # yum install python-pip -y

安裝docker-compose

[root@docker01 harbor]# yum install -y docker-compose

生成CA私鑰

[root@docker01 ~]# openssl genrsa -out ca.key 4096
## 如果使用 FQDN 連接 Harbor 主機,則必須將其指定為 CN 屬性
[root@docker01 ~]# openssl req -x509 -new -nodes -sha512 -days 3650 \

-subj "/C=CN/ST=Beijing/L=Beijing/O=test-harbor/OU=Personal/CN=my-harbor.com" \

-key ca.key \

-out ca.crt

生成服務端證書

[root@docker01 ~]# openssl genrsa -out my-harbor.com.key 4096
Generating RSA private key, 4096 bit long modulus
..++
.......++
e is 65537 (0x10001)

##  向CA發起簽署請求
# openssl req -sha512 -new \
    -subj "/C=CN/ST=Beijing/L=Beijing/O=test-harbor/OU=Personal/CN=my-harbor.com" \
    -key my-harbor.com.key \
    -out my-harbor.com.csr

 生成x509 v3的擴展文件

# cat > v3.ext <<-EOF
    authorityKeyIdentifier=keyid,issuer
    basicConstraints=CA:FALSE
    keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
    extendedKeyUsage = serverAuth
    subjectAltName = @alt_names
    
    [alt_names]
    DNS.1=my-harbor.com
    DNS.2=my-harbor
    DNS.3=docker01
    EOF
  

# openssl x509 -req -sha512 -days 3650     -extfile v3.ext     -CA ca.crt -CAkey ca.key -CAcreateserial -in my-harbor.com.csr -out my-harbor.com.crt
Signature ok
subject=/C=CN/ST=Beijing/L=Beijing/O=test-harbor/OU=Personal/CN=my-harbor.com
Getting CA Private Key

 

# cp my-harbor.com.crt my-harbor.com.key /data/cert

 CA簽署證書

# openssl x509 -inform PEM -in my-harbor.com.crt -out my-harbor.com.cert

修改Harbor配置文件

[root@docker01 harbor]# egrep -v "^$|#" harbor.yml
hostname: my-harbor.com
http:
  port: 80
https:
  port: 443
  certificate: /data/cert/my-harbor.com.crt
  private_key: /data/cert/my-harbor.com.key
harbor_admin_password: Harbor12345
database:
  password: root123
  max_idle_conns: 50
  max_open_conns: 1000
data_volume: /data

 首次部署更新Harbor配置

[root@docker01 harbor]# ./prepare 
prepare base dir is set to /usr/local/src/harbor
Clearing the configuration file: /config/portal/nginx.conf
Clearing the configuration file: /config/log/logrotate.conf
Clearing the configuration file: /config/log/rsyslog_docker.conf
Generated configuration file: /config/portal/nginx.conf
Generated configuration file: /config/log/logrotate.conf
Generated configuration file: /config/log/rsyslog_docker.conf
Generated configuration file: /config/nginx/nginx.conf
Generated configuration file: /config/core/env
Generated configuration file: /config/core/app.conf
Generated configuration file: /config/registry/config.yml
Generated configuration file: /config/registryctl/env
Generated configuration file: /config/registryctl/config.yml
Generated configuration file: /config/db/env
Generated configuration file: /config/jobservice/env
Generated configuration file: /config/jobservice/config.yml
Generated and saved secret to file: /data/secret/keys/secretkey
Successfully called func: create_root_cert
Generated configuration file: /compose_location/docker-compose.yml
Clean up the input dir

 安裝Harbor

[root@docker01 harbor]# ./install.sh 
[Step 0]: checking if docker is installed ...

Note: docker version: 18.09.9

...

Creating redis ... done
Creating harbor-core ... done
Creating network "harbor_harbor" with the default driver
Creating nginx ... done
Creating harbor-db ... 
Creating registry ... 
Creating registryctl ... 
Creating harbor-portal ... 
Creating redis ... 
Creating harbor-core ... 
Creating nginx ... 
Creating harbor-jobservice ... 
✔ ----Harbor has been installed and started successfully.----

 查看Harbor安裝后啟動的容器

[root@docker01 harbor]# docker-compose ps
      Name                     Command               State                      Ports                   
--------------------------------------------------------------------------------------------------------
harbor-core         /harbor/entrypoint.sh            Up                                                 
harbor-db           /docker-entrypoint.sh            Up                                                 
harbor-jobservice   /harbor/entrypoint.sh            Up                                                 
harbor-log          /bin/sh -c /usr/local/bin/ ...   Up      127.0.0.1:1514->10514/tcp                  
harbor-portal       nginx -g daemon off;             Up                                                 
nginx               nginx -g daemon off;             Up      0.0.0.0:80->8080/tcp, 0.0.0.0:443->8443/tcp
redis               redis-server /etc/redis.conf     Up                                                 
registry            /home/harbor/entrypoint.sh       Up                                                 
registryctl         /home/harbor/start.sh            Up           

當前目錄下會生成docker-compose.yml文件,通過docker-compose可以啟停服務

docker-compose down -v 或 docker-compose stop  //區別,前者會remove掉容器、image、網絡,停的更干凈,后者只是停服務
docker-compose up -d                       // 重啟Harbor

運行后的Harbor修改配置

## 切到Harbor的安裝目錄
[root@docker01 ~]# cd /usr/local/harbor/          

## 停止Harbor
[root@docker01 harbor]# docker-compose stop
Stopping harbor-jobservice ... done
Stopping nginx             ... done
Stopping harbor-core       ... done
Stopping redis             ... done
Stopping registryctl       ... done
Stopping registry          ... done
Stopping harbor-portal     ... done
Stopping harbor-db         ... done
Stopping harbor-log        ... done

 

harbor.yml的必須參數解釋

參數名 子選項 說明
hostname   指定為部署Harbor主機的IP地址或者完全限定域名(FQDN),也就是訪問Harbor使用的地址。
由於對外提供訪問,所以不要指定127.0.0.1和localhost,也不要指定為0.0.0.0
http   生產環境不建議使用HTTP協議。只有在開發環境和air-gapped測試環境使用。在非air-gapped環境
使用HTTP協議,可能會遭受Man-in-the-MiddleAttack攻擊
  port HTTP協議的端口,默認為80
https   生產環境或非air-gapped環境使用
  port HTTPS協議端口,默認為443
  certificate 證書文件路徑
  private_key 私鑰文件路徑
internal_tls    
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     

網頁訪問harbor

 

 

 

Harbor的數據庫認證模式

 

 注意:自動注冊功能不建議開啟,因為開啟后登錄頁面會出現注冊的功能,不方便用戶管理

 


免責聲明!

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



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