福州手機(jī)網(wǎng)站建設(shè)最新國(guó)內(nèi)新聞事件今天
一 摘要
本文主要介紹harbor 的安裝及使用。
二 環(huán)境信息及部署圖
2.1 環(huán)境信息
名稱 | 版本 | 備注 |
---|---|---|
操作系統(tǒng) | centos7.9 | |
容器 | docker 23.0.1 | |
harbor | 2.7 | |
代理nginx | 待補(bǔ)充 |
2.2 架構(gòu)圖
說(shuō)明:
1.harbor 核心服務(wù)里有個(gè)nginx ,也可以用該nginx 做代理
2.proxy-nginx 不是必須安裝的,我這里是因?yàn)閮?nèi)部已經(jīng)有個(gè)一個(gè)專用反向代理服務(wù)器,為了方便管理,就在原h(huán)arbor nginx 上再代理了一層。
2.3 安裝目錄結(jié)構(gòu)(不包含proxy-nginx)
/data/yunweistg1/harbor/harborsoft: 存放軟件解壓文件以及配置文件;
/data/yunweistg1/harbor/harbordata: 存放harbor 運(yùn)行時(shí)數(shù)據(jù)文件
[root@localhost harbor]# pwd
/data/yunweistg1/harbor
[root@localhost harbor]# tree -L 3
.
├── harbordata
│ ├── ca_download
│ ├── database
│ │ └── pg13
│ ├── job_logs
│ │ ├── 14588b0a2d344e858b1a88ee.log
│ │ ├── 60332bdfa0bb84f6d88db945@1695686400.log
│ │ ├── 60332bdfa0bb84f6d88db945@1695772800.log
│ │ ├── 9dffa133c54e1dc2df7c84ba.log
│ │ ├── be5bf53eb57feb447dcf7b2d.log
│ │ └── fa303561c3ca9909d0d3180d.log
│ ├── redis
│ │ └── dump.rdb
│ ├── registry
│ │ └── docker
│ ├── secret
│ │ ├── core
│ │ ├── keys
│ │ └── registry
│ └── trivy-adapter
│ ├── reports
│ └── trivy
└── harborsoft└── harbor├── common├── common.sh├── docker-compose.yml├── harbor.v2.7.1.tar.gz├── harbor.yml├── harbor.yml.tmpl├── install.sh├── LICENSE└── prepare18 directories, 15 files
[root@localhost harbor]#
三 安裝
3.1 安裝準(zhǔn)備
下載安裝包,以及安裝操作系統(tǒng)和docker\docker-compose
3.1.1 下載安裝包
harbor 官網(wǎng)地址:https://goharbor.io/
3.1.2 安裝docker 以及docker-compose
具體安裝略
3.2 安裝harbor核心服務(wù)
harbor 的安裝思路如下:
harbor.yml 是原始配置文件,根據(jù)需要修改,然后執(zhí)行.prepare 命令,會(huì)根據(jù)harbor.yml 內(nèi)容生成各子系統(tǒng)的配置文件,然后運(yùn)行install.sh 執(zhí)行安裝。
3.2.1 修改配置文件
主要配置harbor.yml
3.2.1.1 http&https
這塊大家根據(jù)需要調(diào)整,比如端口沖突,就調(diào)整端口。
重點(diǎn)說(shuō)明下 hostname 和external_url
1.官網(wǎng)解釋:若配置了external_url,可以不配置hostname ;external_url 一般與proxy_nginx 里配置的域名保持一致;
2.harbor 搭建好后,檢查pull 或者push 地址 是否是你想要的地址,這個(gè)地址 是由這兩個(gè)參數(shù)控制
# Configuration file of Harbor# The IP address or hostname to access admin UI and registry service.
# DO NOT use localhost or 127.0.0.1, because Harbor needs to be accessed by external clients.
hostname: 10.3.170.75# http related config
http:# port for http, default is 80. If https enabled, this port will redirect to https portport: 8033# https related config
#https:# https port for harbor, default is 443
# port: 443# The path of cert and key files for nginx
# certificate: /your/certificate/path
# private_key: /your/private/key/path# # Uncomment following will enable tls communication between all harbor components
# internal_tls:
# # set enabled to true means internal tls is enabled
# enabled: true
# # put your cert and key files on dir
# dir: /etc/harbor/tls/internal# Uncomment external_url if you want to enable external proxy
# And when it enabled the hostname will no longer used
external_url: https://stg1junharbor.XXXXX.com
3.2.1.2 配置 harbor容器 映射目錄
這里配置 harbor 容器的映射目錄
# The default data volume
data_volume: /data/yunweistg1/harbor/harbordata
3.2.2 安裝
然后執(zhí)行
./prepare
./install.sh
到此harbor 核心服務(wù)就完成安裝
3.3 非核心服務(wù)安裝
harbor 里有些組件是非核心服務(wù),作為可選組件安裝。比如容器漏洞掃描軟件trivy
3.3.1 安裝trivy
先關(guān)閉harbor 容器然后再安裝
docker-compose -f docker-compose.yml down -v
./install.sh --with-trivy
四 日常使用及維護(hù)
4.1 trivy 漏洞庫(kù)離線同步
主要通過(guò)在外網(wǎng)下載trivy 漏洞庫(kù),然后人工同步到內(nèi)網(wǎng)trivy
4.1.1 關(guān)閉harbor 里trivy 自動(dòng)更新配置
trivy:# 關(guān)閉在線更新skip_update: true
# 開(kāi)啟離線掃描offline_scan: true
#其余配置請(qǐng)使用默認(rèn)或者按需調(diào)整
重新執(zhí)行
./prepare
./install.sh --with-trivy
4.1.2 外網(wǎng)下載trivy 漏洞庫(kù)
通過(guò)oras 下載漏洞庫(kù),然后人工同步到內(nèi)網(wǎng)對(duì)應(yīng)目錄
下載oras 地址:https://github.com/oras-project/oras/releases
漏洞庫(kù)下載:
trivy v2
oras pull ghcr.io/aquasecurity/trivy-db:2
oras pull ghcr.io/aquasecurity/trivy-java-db:1
trivy v1
https://github.com/aquasecurity/trivy-db/releases
oras pull ghcr.io/aquasecurity/trivy-java-db:1
我用的是V2
人工同步到內(nèi)網(wǎng)
漏洞庫(kù)存放到對(duì)應(yīng)目錄
# 漏洞庫(kù)離線文件移動(dòng)至對(duì)應(yīng)目錄
tar -xzvf db.tar.gz -C /data/yunweistg1/harbor/harbordata/trivy-adapter/trivy/db
tar -xzvf javadb.tar.gz -C /data/yunweistg1/harbor/harbordata/trivy-adapter/trivy/java-db
# 授權(quán)
chown 10000:10000 -R /data/harbordata/trivy-adapter/trivy
最好重啟下harbor 容器即可。
4.2 proxy-nginx 反向代理配置
這個(gè)配置僅供參考
upstream harbor {# session stickyserver 10.3.170.75:8033 max_fails=3 fail_timeout=10s;keepalive 128;
}server {listen 80;listen 443 ssl;server_name stg1junharbor.xxxxx.com;ssl_certificate /etc/nginx/conf.d/cert/_.xxxxx.com.pem;ssl_certificate_key /etc/nginx/conf.d/cert/_.xxxxx.com.key;ssl_session_cache builtin:1000 shared:SSL:10m;ssl_protocols TLSv1 TLSv1.1 TLSv1.2;ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;ssl_prefer_server_ciphers on;charset utf-8;client_body_buffer_size 10M;client_max_body_size 10240M;location / {proxy_pass http://harbor;proxy_connect_timeout 300;proxy_send_timeout 600;proxy_read_timeout 600;proxy_max_temp_file_size 5000m;}error_page 500 502 503 504 /50x.html;location = /50x.html {root html;}
}