概述
harbor是什么呢?英文單詞的意思是:港灣。港灣用來存放集裝箱(貨物的),而docker的由來正是借鑒了集裝箱的原理,所以harbor是用于存放docker的鏡像,作為鏡像倉庫使用。官方的說法是:Harbor是一個用于存儲和分發(fā)Docker鏡像的企業(yè)級Registry服務器。
harbor鏡像倉庫是由VMware開源的一款企業(yè)級鏡像倉庫,它包括權限管理(RBAC)、LDAP、日志審核、管理界面、自我注冊、鏡像復制等諸多功能。
一、harbor特性
1、基于角色的訪問控制:用戶和存儲庫是通過“項目”組織的,用戶可以對多個鏡像倉庫統(tǒng)一命名空間擁有不同的權限。
2、鏡像復制:可以基于具有多個Registry實例之間復制(同步)圖像和圖表。如果出現(xiàn)任何錯誤,Harbor會自動重試復制。非常適合于負載平衡、高可用性、多數(shù)據(jù)中心、混合和多云場景。
3、LDAP/AD支持:Harbor與現(xiàn)有企業(yè)LDAP/AD集成,用于用戶身份驗證和管理,并支持將LDAP組導入Harbor并為其分配適當?shù)捻椖拷巧?br />
鏡像刪除和垃圾收集:鏡像可以刪除,其空間可以回收。
4、國際化:對多國語言支持(已擁有中文、英文、德文、日語和俄文);
5、圖形化用戶界面:用戶可以輕松瀏覽、搜索存儲庫和管理項目。
6、審計管理:跟蹤到存儲庫的所有操作。
7、RESTful API:用于大多數(shù)管理操作的RESTful API,易于與外部系統(tǒng)集成。一個嵌入式的Swagger用戶界面可用于探索和測試API。
簡單部署:提供在線和離線安裝程序。此外,可以安裝到vSphere平臺的(OVA方式)虛擬設備。
二、Harbor 組件
1、proxy:Harbor的組件,如注冊表、UI和令牌服務,都位于反向代理之后。代理將來自瀏覽器和Docker客戶機的請求轉發(fā)到各種后端服務。
2、Registry:負責存儲Docker鏡像和處理Docker推/拉命令。由于Harbor需要對映像進行訪問權限控制,Registry將引導客戶機訪問令牌服務,以便為每個pull或push請求獲取有效的令牌(token)。
3、Core Service:Harbor的核心功能,主要提供以下服務:
1)UI:提供圖像化的圖形用戶界面,幫助人戶管理鏡像和對用戶授權。
2)webhook: 為了及時獲取registry上images的狀態(tài)變化的情況,在Registry上配置webhook,把狀態(tài)變化傳遞UI模塊;
3)Token令牌服務:負責根據(jù)用戶在項目中的角色為每個docker push/pull命令頒發(fā)令牌。如果從Docker客戶機發(fā)送的請求中沒有令牌,注冊表將把請求重定向到令牌服務。
4、Datebase:為了給core services提供數(shù)據(jù)庫舒服,負責儲存用戶權限、審計日志、Docker image分組信息等數(shù)據(jù)。
5、Job Services:提供鏡像遠程負責功能,能把本地鏡像同步到其他harbor實例當中。
6、Log Collector:為了幫助監(jiān)控Harbor運行,負責手機其他組件的log,供日后分析。
三、部署環(huán)境
centos-7.6 192.168.8.130
Docker version 1.19.3
docker-compose version 1.24.2
harbor-offline-installer-v1.8.6.tgz
四、安裝docker-compose
方式1:
[root@centos130 ~]# curl -L https://github.com/docker/compose/releases/download/1.24.1/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
[root@centos130 ~]# chmod +x /usr/local/bin/docker-compose
方式2:
[root@centos130 ~]# wget https://bootstrap.pypa.io/get-pip.py
[root@centos130 ~]# python get-pip.py
[root@centos130 ~]# pip install docker-compose
五、卸載docker-compose
#二進制:
[root@centos130 ~]rm /usr/local/bin/docker-compose
#pip:
[root@centos130 ~]pip uninstall docker-compose
六、安裝docker
[root@centos130 ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
添加一個穩(wěn)定的源
[root@centos130 ~]# yum-config-manager --add-repo \
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
[root@centos130 ~]# yum makecache fast
安裝最新穩(wěn)定版本的docker-ce
[root@centos130 ~]# yum install -y docker-ce docker-ce-cli containerd.io vim
[root@centos130 ~]# mkdir /etc/docker && vim /etc/docker/daemon.json
{
"registry-mirrors": ["https://yxrgrke0.mirror.aliyuncs.com"],
"insecure-registries": ["192.168.8.130:5000"],
"insecure-registries": ["centos130:80"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m",
"max-file": "3"
}
}
啟動docker
[root@centos130 ~]# systemctl daemon-reload
[root@centos130 ~]# systemctl enable docker && systemctl start docker
[root@centos130 ~]# systemctl status docker
七、安裝harbor
harbor下載地址:
harbor github 地址 https://github.com/goharbor/harbor
http://harbor.orientsoft.cn/
[root@centos130 ~]# wget https://storage.googleapis.com/harbor-releases/release-1.8.6/harbor-offline-installer-v1.8.6.tgz
[root@centos130 ~]# tar -xf harbor-offline-installer-v1.8.6.tgz -C /usr/local/
[root@centos130 ~]# cd /usr/local/harbor/
[root@centos130 ~]# vim harbor.yml
hostname = centos130
#這里只是簡單的測試,所以只編輯這一行,其他的默認不做修改
#禁止用戶注冊
self_registration = off
#設置只有管理員可以創(chuàng)建項目
project_creation_restriction = adminonly
八、執(zhí)行安裝腳本
[root@centos130 ~]# ./instsll.sh
說明:安裝報錯 找不到docker-proxy 、 docker-runc
執(zhí)行
[root@centos130 ~]# ln -s /usr/libexec/docker/docker-runc-current /usr/bin/docker-runc
[root@centos130 ~]# ln -s /usr/libexec/docker/docker-proxy-current /usr/bin/docker-proxy
查看啟動的鏡像文件
[root@centos130 ~]# docker-compose ps
Harbor容器的stop與start:
[root@centos130 ~]# cd /usr/local/harbor/
[root@centos130 ~]# docker-compose stop
[root@centos130 ~]# docker-compose start
九、登錄harbor
到此便安裝完成了,直接打開瀏覽器登陸,并創(chuàng)建my項目:
默認用戶密碼是:admin/Harbor12345
Shell命令行終端登錄harbor倉庫
[root@centos130 ~]# harbor上傳鏡像
[root@centos130 ~]# docker login centos130:80
[root@centos130 ~]# docker login -u admin -p Harbor12345 centos130:80 #賬號密碼: admin/Harbor12345
Username: admin
Password:
Login Succeeded
測試鏡像上傳
[root@centos130 ~]# docker pull nginx
[root@centos130 ~]# docker tag nginx:latest centos130:80/my/nginx:latest
[root@centos130 ~]# docker images
[root@centos130 ~]# docker push centos130:80/my/nginx:latest
The push refers to repository [centos130:80/my/nginx]
55a77731ed26: Pushed
71f2244bc14d: Pushed
f2cb0ecef392: Pushed
latest: digest: sha256:3936fb3946790d711a68c58be93628e43cbca72439079e16d154b5db216b58da size: 948
說明: 格式為: userip/項目名/image名字:版本號 (項目名需要在webui 提前建好)
[root@centos130 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos130:80/my/nginx:latest latest 5a3221f0137b 5 days ago 126MB
nginx latest 5a3221f0137b 5 days ago 126MB
刪除本地nginx鏡像,測試下載
[root@centos130 ~]# docker pull centos130:80/my/nginx:latest
十、harbor修改端口號
1、修改docker-compose.yml文件映射為1180端口:
修改配置文件
[root@centos130 ~]# cat /usr/local/harbor/docker-compose.yml
version: '2.3'
services:
log:
image: goharbor/harbor-log:v1.8.6
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
- ./common/config/log/:/etc/logrotate.d/:z
ports:
- 127.0.0.1:1514:10514
networks:
- harbor
registry:
image: goharbor/registry-photon:v2.7.1-patch-2819-v1.8.6
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
networks:
- harbor
dns_search: .
depends_on:
- log
logging:
driver: "syslog"
options:
syslog-address: "tcp://127.0.0.1:1514"
tag: "registry"
registryctl:
image: goharbor/harbor-registryctl:v1.8.6
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
networks:
- harbor
dns_search: .
depends_on:
- log
logging:
driver: "syslog"
options:
syslog-address: "tcp://127.0.0.1:1514"
tag: "registryctl"
postgresql:
image: goharbor/harbor-db:v1.8.6
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:v1.8.6
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/psc/:/etc/core/token/: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
networks:
harbor:
dns_search: .
depends_on:
- log
- registry
logging:
driver: "syslog"
options:
syslog-address: "tcp://127.0.0.1:1514"
tag: "core"
portal:
image: goharbor/harbor-portal:v1.8.6
container_name: harbor-portal
restart: always
cap_drop:
- ALL
cap_add:
- CHOWN
- SETGID
- SETUID
- NET_BIND_SERVICE
networks:
- harbor
dns_search: .
depends_on:
- log
- core
logging:
driver: "syslog"
options:
syslog-address: "tcp://127.0.0.1:1514"
tag: "portal"
jobservice:
image: goharbor/harbor-jobservice:v1.8.6
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
networks:
- harbor
dns_search: .
depends_on:
- redis
- core
logging:
driver: "syslog"
options:
syslog-address: "tcp://127.0.0.1:1514"
tag: "jobservice"
redis:
image: goharbor/redis-photon:v1.8.6
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"
proxy:
image: goharbor/nginx-photon:v1.8.6
container_name: nginx
restart: always
cap_drop:
- ALL
cap_add:
- CHOWN
- SETGID
- SETUID
- NET_BIND_SERVICE
volumes:
- ./common/config/nginx:/etc/nginx:z
networks:
- harbor
dns_search: .
ports:
- 1180:80
- 443:443
- 4443:4443
depends_on:
- postgresql
- registry
- core
- portal
- log
logging:
driver: "syslog"
options:
syslog-address: "tcp://127.0.0.1:1514"
tag: "proxy"
networks:
harbor:
external: false
2、修改/etc/docker/daemon.json文件將80修改為1180端口:
修改daemon配置
[root@centos130 ~]# cat /etc/docker/daemon.json
{
"registry-mirrors": ["https://yxrgrke0.mirror.aliyuncs.com"],
"insecure-registries": ["192.168.8.130:5000"],
"insecure-registries": ["centos130:1180"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m",
"max-file": "3"
}
}
3、修改/usr/locat/harbor/harbor.yml文件的hostname
修改hostname配置
cat /usr/locat/harbor/harbor.yml
hostname: centos130:1180
4、停止harbor,重新啟動并生成配置文件
重新初始化
[root@centos130 ~]# cd /usr/locat/harbor/
[root@centos130 ~]# docker-compose stop
[root@centos130 ~]# ./install.sh
5、重新啟動docker
[root@centos130 ~]# systemctl daemon-reload
[root@centos130 ~]# systemctl restart docker.service
驗證
[root@centos130 ~]# docker login centos130:1180
Username: admin
Password: Harbor12345
到此這篇關于使用docker-compose安裝harbor的文章就介紹到這了,更多相關docker compose安裝harbor內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!