文章目錄
- 1、安裝底層版本要求
- 2、安裝Harbor
- (1)校驗檔案
- (2)創建私鑰檔案、證書請求檔案、證書檔案
- 使用演算法3DES生成大小為2048的秘鑰檔案KEY
- 生成根證書請求檔案CSR
- 備份私鑰檔案
- 生成根證書CA
- 查看證書資訊
- 創建證書存放目錄與修改權限
- (3)修改Harbor組態檔
- Harbor組態檔引數詳解(重點)
- 執行安裝操作
- (4)使用瀏覽器訪問站點
- (5)上傳鏡像至Harbor
- 指定鏡像倉庫地址
- 配置登錄驗證
- 查看鏡像推送結果
- 查看對應的DockerFile
1、安裝底層版本要求
- Python 2.7或更高版本
- Docker 1.10或更高版本
- Docker Compose 1.6.0或更高版本
Docker Compose下載URL:https://github.com/docker/compose/releases/
點擊此處進行跳轉下載
此處附帶本人使用的Docker Compose安裝包,百度網盤下載鏈接如下:
- 鏈接:https://pan.baidu.com/s/1IdnR0v3EgL0lOuBgV2hCdw
- 提取碼:4t8r
[root@localhost ~]# curl -L https://github.com/docker/compose/releases/download/1.24.1/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
[root@localhost ~]# chmod +x /usr/local/bin/docker-compose
檢查部署底層要求版本是否符合
[root@localhost ~]# python3 --version
Python 3.6.8
[root@localhost ~]# docker --version
Docker version 20.10.8, build 3967b7d
[root@localhost ~]# docker-compose --version
docker-compose version 1.24.1, build 4667896b
2、安裝Harbor
Harbor下載URL:https://github.com/goharbor/harbor/releases
點擊此處進行跳轉下載
此處附帶本人使用的Harbor安裝包,百度網盤下載鏈接如下:
- 鏈接:https://pan.baidu.com/s/1zXm2y_sv6t7S_U-lXD8dqg
- 提取碼:5o2c
(1)校驗檔案
[root@localhost ~]# md5sum harbor-offline-installer-v1.10.1.tgz
e9ccca33e9a25b6b64425943c06f5fe6 harbor-offline-installer-v1.10.1.tgz
(2)創建私鑰檔案、證書請求檔案、證書檔案
使用演算法3DES生成大小為2048的秘鑰檔案KEY
[root@localhost harbor]# openssl genrsa -des
-des -des3
[root@localhost ~]# openssl genrsa -des3 -out server.key 2048
Generating RSA private key, 2048 bit long modulus (2 primes)
.....................................................................................................+++++
...............+++++
e is 65537 (0x010001)
Enter pass phrase for server.key:redhat
Verifying - Enter pass phrase for server.key:redhat
生成根證書請求檔案CSR
[root@localhost ~]# openssl req -new -key server.key -out server.csr
Enter pass phrase for server.key:
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:BJ
Locality Name (eg, city) [Default City]:BJ
Organization Name (eg, company) [Default Company Ltd]:AAA
Organizational Unit Name (eg, section) []:BBB
Common Name (eg, your name or your server's hostname) []:CCC
Email Address []:qq.com
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:nsfocus /不需要修改密碼,此處直接回車即可;
An optional company name []:nsfocus /不需要修改密碼,此處直接回車即可;
備份私鑰檔案
[root@localhost ~]# cp server.key server.key.org
[root@localhost ~]# openssl rsa -in server.key.org -out server.key
Enter pass phrase for server.key.org:nsfocus
writing RSA key
生成根證書CA
[root@localhost ~]# openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
Signature ok
subject=C = CN, ST = BJ, L = BJ, O = AAA, OU = BBB, CN = CCC, emailAddress = qq.com
Getting Private key
引數詳解:
- -new:表示生成一個新的證書簽署請求;
- -x509:專用于生成CA自簽證書;
- -key:指定生成證書用到的私鑰檔案;
- -out FILNAME:指定生成的證書的保存路徑;
- -days:指定證書的有效期限,單位為day,默認是365天;
查看證書資訊
[root@localhost harbor]# openssl x509 -in /data/cert/server.crt -noout -serial -dates -subject
serial=18C7ED02FEEEE804C2557DEA151EE2EE7748DA68
notBefore=Oct 26 13:57:09 2021 GMT
notAfter=Oct 26 13:57:09 2022 GMT
subject=C = CN, ST = BJ, L = BJ, O = AAA, OU = BBB, CN = CCC, emailAddress = qq.com
創建證書存放目錄與修改權限
[root@localhost ~]# mkdir /data/cert -pv
[root@localhost ~]# mv server.* /data/cert/
[root@localhost ~]# chmod -R 777 /data/cert/
[root@localhost ~]# cd /data/cert/
[root@localhost cert]# ll
total 16
-rwxrwxrwx. 1 root root 1220 Oct 26 21:57 server.crt
-rwxrwxrwx. 1 root root 1005 Oct 26 21:52 server.csr
-rwxrwxrwx. 1 root root 1679 Oct 26 21:55 server.key
-rwxrwxrwx. 1 root root 1751 Oct 26 21:54 server.key.org
(3)修改Harbor組態檔
[root@localhost cert]# cd harbor/
[root@localhost harbor]# ll
total 662128
drwxr-xr-x. 3 root root 20 Oct 26 22:36 common
-rw-r--r--. 1 root root 3398 Feb 10 2020 common.sh
-rw-r--r--. 1 root root 5346 Oct 26 22:50 docker-compose.yml
-rw-r--r--. 1 root root 677974489 Feb 10 2020 harbor.v1.10.1.tar.gz
-rw-r--r--. 1 root root 5878 Oct 26 22:50 harbor.yml
-rwxr-xr-x. 1 root root 2284 Feb 10 2020 install.sh
-rw-r--r--. 1 root root 11347 Feb 10 2020 LICENSE
-rwxr-xr-x. 1 root root 1749 Feb 10 2020 prepare
Harbor組態檔引數詳解(重點)
[root@localhost harbor]# vim harbor.yml
# Configuration file of Harbor
# Harbor的組態檔
# The IP address or hostname to access admin UI and registry service.
# 配置訪問管理UI和注冊表服務的IP地址或主機名
# DO NOT use localhost or 127.0.0.1, because Harbor needs to be accessed by external clients.
# 不要使用localhost或127.0.0.1,因為Harbor需要被外部客戶端訪問
hostname: 10.81.20.166
-----------------------------------------------------------------------
# http related config
# http相關配置
http:
# port for http, default is 80. If https enabled, this port will redirect to https port
# 若https埠開啟,此埠重定向至https埠
port: 80
-----------------------------------------------------------------------
# https related config
# https相關配置
https:
# https port for harbor, default is 443
port: 443
# The path of cert and key files for nginx
# nginx的cert和key檔案路徑
certificate: /data/cert/server.crt
private_key: /data/cert/server.key
# Uncomment external_url if you want to enable external proxy
# 取消注釋external_url,如果你想啟用外部代理
# And when it enabled the hostname will no longer used
# 當它啟用時,主機名將不再使用
# external_url: https://reg.mydomain.com:8433
# The initial password of Harbor admin
# Harbour admin的初始密碼
# It only works in first time to install harbor
# 只有在第一次安裝時有效
# Remember Change the admin password from UI after launching Harbor.
# 請記住在啟動Harbor UI后更改admin登錄密碼
harbor_admin_password: Harbor12345
-----------------------------------------------------------------------
# Harbor DB configuration
# Harbor資料庫配置
database:
# The password for the root user of Harbor DB. Change this before any production use.
password: root123
# The maximum number of connections in the idle connection pool. If it <=0, no idle connections are retained.
max_idle_conns: 50
# The maximum number of open connections to the database. If it <= 0, then there is no limit on the number of open connections.
# Note: the default number of connections is 100 for postgres.
max_open_conns: 100
# The default data volume
# 默認資料卷路徑
data_volume: /data
# Harbor Storage settings by default is using /data dir on local filesystem
# Uncomment storage_service setting If you want to using external storage
# 設定外部存盤則取消下面配置注釋
# storage_service:
# # ca_bundle is the path to the custom root ca certificate, which will be injected into the truststore
# 自定義CA根證書的路徑
# # of registry's and chart repository's containers. This is usually needed when the user hosts a internal storage with self signed certificate.
# ca_bundle:
# # storage backend, default is filesystem, options include filesystem, azure, gcs, s3, swift and oss
# 存盤后端的檔案系統選項有azure, gcs, s3, swift, oss
# # for more info about this configuration please refer
https://docs.docker.com/registry/configuration/
# filesystem:
# maxthreads: 100
# # set disable to true when you want to disable registry redirect
# 禁用注冊表重定向需要將下面修改為true
# redirect:
# disabled: false
-----------------------------------------------------------------------
# Clair configuration
clair:
# The interval of clair updaters, the unit is hour, set to 0 to disable the updaters.
# clair更新時間間隔,單位為小時,0表示禁用
updaters_interval: 12
jobservice:
# Maximum number of job workers in job service
# 最大作業連接數
max_job_workers: 10
notification:
# Maximum retry count for webhook job
# 最大重試次數
webhook_job_max_retry: 10
chart:
# Change the value of absolute_url to enabled can enable absolute url in chart
# 將absolute_url的值更改為enabled可以在圖表中啟用絕對url
absolute_url: disabled
-----------------------------------------------------------------------
# Log configurations
# 日志配置
log:
# options are debug, info, warning, error, fatal
# 選項有:除錯、資訊、警告、錯誤、致命
level: info
# configs for logs in local storage
# 配置本地存盤的日志
local:
# Log files are rotated log_rotate_count times before being removed. If count is 0, old versions are removed rather than rotated.
# 日志檔案在被洗掉之前會被旋轉log_rotate_count次,如果count為0,則洗掉舊版本,而不是旋轉舊版本,
rotate_count: 50
# Log files are rotated only if they grow bigger than log_rotate_size bytes. If size is followed by k, the size is assumed to be in kilobytes.
# If the M is used, the size is in megabytes, and if G is used, the size is in gigabytes. So size 100, size 100k, size 100M and size 100G
# are all valid.
rotate_size: 200M
# The directory on your host that store log
# 存盤日志的主機上的目錄
location: /var/log/harbor
# Uncomment following lines to enable external syslog endpoint.
# 取消注釋以下行以啟用外部syslog端點,
# external_endpoint:
# # protocol used to transmit log to external endpoint, options is tcp or udp
# 用于向外部終端發送日志的協議,選項為TCP或udp
# protocol: tcp
# # The host of external endpoint
# 外部端點的主機
# host: localhost
# # Port of external endpoint
# 外部端點的埠
# port: 5140
#This attribute is for migrator to detect the version of the .cfg file, DO NOT MODIFY!
#這個屬性是用來檢測,cfg檔案的版本的,不要修改!
_version: 1.10.0
# Uncomment external_database if using external database.
# 如果使用外部資料庫,取消注釋external_database,
# external_database:
# harbor:
# host: harbor_db_host
# port: harbor_db_port
# db_name: harbor_db_name
# username: harbor_db_username
# password: harbor_db_password
# ssl_mode: disable
# max_idle_conns: 2
# max_open_conns: 0
# clair:
# host: clair_db_host
# port: clair_db_port
# db_name: clair_db_name
# username: clair_db_username
# password: clair_db_password
# ssl_mode: disable
# notary_signer:
# host: notary_signer_db_host
# port: notary_signer_db_port
# db_name: notary_signer_db_name
# username: notary_signer_db_username
# password: notary_signer_db_password
# ssl_mode: disable
# notary_server:
# host: notary_server_db_host
# port: notary_server_db_port
# db_name: notary_server_db_name
# username: notary_server_db_username
# password: notary_server_db_password
# ssl_mode: disable
# Uncomment external_redis if using external Redis server
# 如果使用外部Redis服務器,取消注釋external_redis
# external_redis:
# host: redis
# port: 6379
# password:
# # db_index 0 is for core, it's unchangeable
# registry_db_index: 1
# jobservice_db_index: 2
# chartmuseum_db_index: 3
# clair_db_index: 4
# Uncomment uaa for trusting the certificate of uaa instance that is hosted via self-signed cert.
# 取消對uaa的注釋,因為它信任通過自簽名證書托管的uaa實體的證書,
# uaa:
# ca_file: /path/to/ca
# Global proxy
# 全球代理
# Config http proxy for components, e.g. http://my.proxy.com:3128
# Components doesn't need to connect to each others via http proxy.
# Remove component from `components` array if want disable proxy
# for it. If you want use proxy for replication, MUST enable proxy
# for core and jobservice, and set `http_proxy` and `https_proxy`.
# Add domain to the `no_proxy` field, when you want disable proxy
# for some special registry.
proxy:
http_proxy:
https_proxy:
# no_proxy endpoints will appended to 127.0.0.1,localhost,.local,.internal,log,db,redis,nginx,core,portal,postgresql,jobservice,registry,registryctl,clair,chartmuseum,notary-server
no_proxy:
components:
- core
- jobservice
- clair
執行安裝操作
[root@localhost harbor]# ./install.sh
[Step 0]: checking if docker is installed ...
Note: docker version: 20.10.8
[Step 1]: checking docker-compose is installed ...
Note: docker-compose version: 1.24.1
[Step 2]: loading Harbor images ...
Loaded image: goharbor/clair-adapter-photon:v1.0.1-v1.10.1
Loaded image: goharbor/harbor-jobservice:v1.10.1
Loaded image: goharbor/redis-photon:v1.10.1
Loaded image: goharbor/notary-server-photon:v0.6.1-v1.10.1
Loaded image: goharbor/clair-photon:v2.1.1-v1.10.1
Loaded image: goharbor/harbor-log:v1.10.1
Loaded image: goharbor/registry-photon:v2.7.1-patch-2819-2553-v1.10.1
Loaded image: goharbor/notary-signer-photon:v0.6.1-v1.10.1
Loaded image: goharbor/chartmuseum-photon:v0.9.0-v1.10.1
Loaded image: goharbor/harbor-registryctl:v1.10.1
Loaded image: goharbor/nginx-photon:v1.10.1
Loaded image: goharbor/harbor-migrator:v1.10.1
Loaded image: goharbor/prepare:v1.10.1
Loaded image: goharbor/harbor-portal:v1.10.1
Loaded image: goharbor/harbor-core:v1.10.1
Loaded image: goharbor/harbor-db:v1.10.1
[Step 3]: preparing environment ...
[Step 4]: preparing harbor configs ...
prepare base dir is set to /root/harbor
Clearing the configuration file: /config/log/logrotate.conf
Clearing the configuration file: /config/log/rsyslog_docker.conf
Clearing the configuration file: /config/nginx/nginx.conf
Clearing the configuration file: /config/core/env
Clearing the configuration file: /config/core/app.conf
Clearing the configuration file: /config/registry/config.yml
Clearing the configuration file: /config/registry/root.crt
Clearing the configuration file: /config/registryctl/env
Clearing the configuration file: /config/registryctl/config.yml
Clearing the configuration file: /config/db/env
Clearing the configuration file: /config/jobservice/env
Clearing the configuration file: /config/jobservice/config.yml
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/db/env
Generated configuration file: /config/jobservice/env
Generated configuration file: /config/jobservice/config.yml
loaded secret from file: /secret/keys/secretkey
Generated configuration file: /compose_location/docker-compose.yml
Clean up the input dir
Note: stopping existing Harbor instance ...
Stopping harbor-jobservice ... done
Stopping harbor-log ... done
Removing harbor-jobservice ... done
Removing nginx ... done
Removing harbor-core ... done
Removing registry ... done
Removing registryctl ... done
Removing harbor-db ... done
Removing harbor-portal ... done
Removing redis ... done
Removing harbor-log ... done
Removing network harbor_harbor
[Step 5]: starting Harbor ...
Creating network "harbor_harbor" with the default driver
Creating harbor-log ... done
Creating redis ... done
Creating harbor-portal ... done
Creating registryctl ... done
Creating harbor-db ... done
Creating registry ... done
Creating harbor-core ... done
Creating nginx ... done
Creating harbor-jobservice ... done
? ----Harbor has been installed and started successfully.----
查看容器資訊
[root@localhost harbor]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2de6fb4348a2 goharbor/harbor-jobservice:v1.10.1 "/harbor/harbor_jobs…" 46 minutes ago Up 46 minutes (healthy) harbor-jobservice
3d39a150124f goharbor/nginx-photon:v1.10.1 "nginx -g 'daemon of…" 46 minutes ago Up 46 minutes (healthy) 0.0.0.0:8003->8080/tcp, :::8003->8080/tcp, 0.0.0.0:443->8443/tcp, :::443->8443/tcp nginx
c4cb2d9fc8c8 goharbor/harbor-core:v1.10.1 "/harbor/harbor_core" 46 minutes ago Up 46 minutes (healthy) harbor-core
ab1601c5b8a9 goharbor/registry-photon:v2.7.1-patch-2819-2553-v1.10.1 "/home/harbor/entryp…" 46 minutes ago Up 46 minutes (healthy) 5000/tcp registry
b86b53dbe902 goharbor/harbor-registryctl:v1.10.1 "/home/harbor/start.…" 46 minutes ago Up 46 minutes (healthy) registryctl
5aaa8801f32d goharbor/harbor-db:v1.10.1 "/docker-entrypoint.…" 46 minutes ago Up 46 minutes (healthy) 5432/tcp harbor-db
7b906e109223 goharbor/harbor-portal:v1.10.1 "nginx -g 'daemon of…" 46 minutes ago Up 46 minutes (healthy) 8080/tcp harbor-portal
cd729f5779c5 goharbor/redis-photon:v1.10.1 "redis-server /etc/r…" 46 minutes ago Up 46 minutes (healthy) 6379/tcp redis
0e0c6c2cb8d0 goharbor/harbor-log:v1.10.1 "/bin/sh -c /usr/loc…" 46 minutes ago Up 46 minutes (healthy) 127.0.0.1:1514->10514/tcp harbor-log
(4)使用瀏覽器訪問站點
此處訪問為組態檔內定義的hostname,需要根據環境進行區分
- 登錄URL:https://10.81.20.166
- 登錄賬戶:admin/Harbor12345(若組態檔修改則使用自定義密碼登錄)

登錄成功界面如下:

(5)上傳鏡像至Harbor
點擊某個需要上傳的專案名稱

點擊[鏡像倉庫],可以查看到“推送鏡像的docker命令”,可以直接復制并修改此兩條命令即可

指定鏡像倉庫地址
[root@localhost harbor]# cat /etc/docker/daemon.json
{
"insecure-registries": ["10.81.20.166"]
}
重啟docker服務
[root@localhost harbor]# systemctl restart docker
確保下面的容器是否開啟成功,部分容器重啟服務不會自啟動,導致服務埠不可達
[root@localhost harbor]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
78db75f19def goharbor/harbor-jobservice:v1.10.1 "/harbor/harbor_jobs…" 4 minutes ago Up 4 minutes (healthy) harbor-jobservice
5c7a0713fcba goharbor/nginx-photon:v1.10.1 "nginx -g 'daemon of…" 4 minutes ago Up 4 minutes (healthy) 0.0.0.0:8003->8080/tcp, :::8003->8080/tcp, 0.0.0.0:443->8443/tcp, :::443->8443/tcp nginx
38f93397e143 goharbor/harbor-core:v1.10.1 "/harbor/harbor_core" 4 minutes ago Up 4 minutes (healthy) harbor-core
b74d02970546 goharbor/registry-photon:v2.7.1-patch-2819-2553-v1.10.1 "/home/harbor/entryp…" 4 minutes ago Up 4 minutes (healthy) 5000/tcp registry
245f015d8c91 goharbor/harbor-db:v1.10.1 "/docker-entrypoint.…" 4 minutes ago Up 4 minutes (healthy) 5432/tcp harbor-db
46bbe79a972e goharbor/harbor-registryctl:v1.10.1 "/home/harbor/start.…" 4 minutes ago Up 4 minutes (healthy) registryctl
a61ec9d2dcd7 goharbor/redis-photon:v1.10.1 "redis-server /etc/r…" 4 minutes ago Up 4 minutes (healthy) 6379/tcp redis
6982dc6079c2 goharbor/harbor-portal:v1.10.1 "nginx -g 'daemon of…" 4 minutes ago Up 4 minutes (healthy) 8080/tcp harbor-portal
0e52d040fff9 goharbor/harbor-log:v1.10.1 "/bin/sh -c /usr/loc…" 4 minutes ago Up 4 minutes (healthy) 127.0.0.1:1514->10514/tcp
配置登錄驗證
未驗證賬戶進行推送,產生報錯
[root@localhost harbor]# docker push 10.81.20.166/library/tomcat:v1.1
The push refers to repository [10.81.20.166/library/tomcat]
4831bcd1167f: Preparing
977cfcbcf0fa: Preparing
4e4de253c94d: Preparing
3891808a925b: Preparing
d402f4f1b906: Preparing
00ef5416d927: Waiting
8555e663f65b: Waiting
d00da3cd7763: Waiting
4e61e63529c2: Waiting
799760671c38: Waiting
denied: requested access to the resource is denied
驗證登錄賬戶
[root@localhost harbor]# docker login 10.81.20.166
Username: admin
Password: Harbor12345
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
驗證成功后重新推送鏡像檔案
[root@localhost harbor]# docker push 10.81.20.166/library/tomcat:v1.1
The push refers to repository [10.81.20.166/library/tomcat]
4831bcd1167f: Pushed
977cfcbcf0fa: Pushed
4e4de253c94d: Pushed
3891808a925b: Pushed
d402f4f1b906: Pushed
00ef5416d927: Pushed
8555e663f65b: Pushed
d00da3cd7763: Pushed
4e61e63529c2: Pushed
799760671c38: Pushed
v1.1: digest: sha256:709c112a87273828f4df9caa99540a1d4f59891455cdfff7ec0ec99edc49f59b size: 2422
查看鏡像推送結果

打開鏡像具體資訊

查看對應的DockerFile

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/337700.html
標籤:其他
上一篇:發布自己的 Python 代碼給別人 “pip install”(linux和windows都有)。(Linux版)
