一、Harbor 的优势
1、基于角色控制:有管理员与普通用户,可赋权普通用户,比如只能上传和下载,可根据项目来进行操作和管理 2、基于镜像的复制策略:也与权限相关,比如有只一些用户与组才能对此项目进行相对应的操作 3、支持 LDAP/AD:域控制,比如南京去下载北京harbor私有仓库的镜像,两端打上局域网的地址,连接在一块,数据信息的传输通过一条隧道,会通过两层加密,第一层为隧道加密,第二层为数据加密,安全可靠 4、图像删除和垃圾收集:即回收站机制 5、图形UI:具有统计功能,比如访问量与镜像下载热度 6、审计:日志,这里意义不大,主要还是借助于 ELK 7、RESTful API:定义 web 语言规范的格式,方便调用 Harbor 的接口,也便于二次开发
二Harbor的核心组件
组件 作用
Proxy 通过一个前置的反向代理统一接收浏览器、Docker客户端的请求,并将请求转发给后端不同的服务
Registry (核心组件)负责储存Docker镜像,并处理docker push/pull命令
Core services Harbor的核心功能, 包括UI、webhook、 token服务
Database 为core services提供数据库服务
Log collector 负责收集其他组件的log,供日后进行分析
可选参数
Email: Harbor需要该参数才能向用户发送“密码重置”电子邮件,并且只有在需要该功能时才需要。
请注意,在默认情况下SSL连接时没有启用。如果SMTP服务器需要SSL,但不支持STARTTLS,那么应该通过设置启用sSL email_ssl = TRUE。
harbour_admin_password:管理员的初始密码,只在Harbour第一次启动时生效。之后,此设置将被忽略,并且应u中设置管理员的密码。
请注意,默认的用户名/密码是admin/Harbor12345。
auth_mode:使用的认证类型,默认情况下,它是 db_auth,即凭据存储在数据库中。对于LDAP身份验证(以文件形式验证),请将其设置为ldap_auth。
self_registration:启用/禁用用户注册功能。禁用时,新用户只能由 Admin用户创建,只有管理员用户可以在 Harbour中创建新用户。
Token_expiration:由令牌服务创建的令牌的到期时间(分钟),默认为 30 分钟。
project_creation_restriction:用于控制哪些用户有权创建项目的标志。默认情况下,每个人都可以创建一个项目。
verify_remote_cert:打开或关闭,默认打开。此标志决定了当Harbor与远程register实例通信时是否验证SSL/TLS证书。
将此属性设置为off 将绕过SSL/TLS验证,这在远程实例具有自签名或不可信证书时经常使用。
部署harbor服务
1、下载harbor安装程序
wget http:// harbor.orientsoft.cn/harbor-1.2.2/harbor-offline-installer-v1.2.2.tgz
或者上传压缩包harbor-offline-installer-v1.2.2.tgz
tar zxvf harbor-offline-installer-v1.2.2.tgz -C /usr/local/
2、配置harbor参数文件
[root@docker1 ~]
3、启动 Harbor 启动之前先确认Docker-Compose 版本安装是否成功
上传docker-compose安装包
[root@docker1 ~]
[root@docker1 ~]
anaconda-ks.cfg docker-compose initial-setup-ks.cfg 公共 视频 文档 音乐
daemon harbor-offline-installer-v1.2.2.tgz nginx-1.12.2.tar.gz 模板 图片 下载 桌面
[root@docker1 ~]
[root@docker1 ~]
docker-compose version 1.21.1, build 5a3f1a3
[root@docker1 ~]
4、查看 Harbor 启动镜像
[root@harbor harbor]
[root@harbor harbor]
Name Command State Ports
-------------------------------------------------------------------------------------------------------------------------------------------------------------
harbor-adminserver /harbor/harbor_adminserver Up
harbor-db docker-entrypoint.sh mysqld Up 3306/tcp
harbor-jobservice /harbor/harbor_jobservice Up
harbor-log /bin/sh -c crond && rm -f ... Up 127.0.0.1:1514->514/tcp
harbor-ui /harbor/harbor_ui Up
nginx nginx -g daemon off; Up 0.0.0.0:443->443/tcp,:::443->443/tcp, 0.0.0.0:4443->4443/tcp,:::4443->4443/tcp,
0.0.0.0:80->80/tcp,:::80->80/tcp
registry /entrypoint.sh serve /etc/ ... Up 5000/tcp
[root@harbor harbor]
version: '2'
services:
log:
image: vmware/harbor-log:v1.2.2
container_name: harbor-log
restart: always
volumes:
- /var/log/harbor/:/var/log/docker/:z
ports:
- 127.0.0.1:1514:514
networks:
- harbor
registry:
image: vmware/registry:2.6.2-photon
container_name: registry
restart: always
volumes:
- /data/registry:/storage:z
- ./common/config/registry/:/etc/registry/:z
networks:
- harbor
environment:
- GODEBUG=netdns=cgo
command:
["serve", "/etc/registry/config.yml"]
depends_on:
- log
logging:
driver: "syslog"
options:
syslog-address: "tcp://127.0.0.1:1514"
tag: "registry"
mysql:
image: vmware/harbor-db:v1.2.2
container_name: harbor-db
restart: always
volumes:
- /data/database:/var/lib/mysql:z
networks:
- harbor
env_file:
- ./common/config/db/env
depends_on:
- log
logging:
driver: "syslog"
options:
syslog-address: "tcp://127.0.0.1:1514"
tag: "mysql"
adminserver:
image: vmware/harbor-adminserver:v1.2.2
container_name: harbor-adminserver
env_file:
- ./common/config/adminserver/env
restart: always
volumes:
- /data/config/:/etc/adminserver/config/:z
- /data/secretkey:/etc/adminserver/key:z
- /data/:/data/:z
networks:
- harbor
depends_on:
- log
logging:
driver: "syslog"
options:
syslog-address: "tcp://127.0.0.1:1514"
tag: "adminserver"
ui:
image: vmware/harbor-ui:v1.2.2
container_name: harbor-ui
env_file:
- ./common/config/ui/env
restart: always
volumes:
- ./common/config/ui/app.conf:/etc/ui/app.conf:z
- ./common/config/ui/private_key.pem:/etc/ui/private_key.pem:z
- /data/secretkey:/etc/ui/key:z
- /data/ca_download/:/etc/ui/ca/:z
- /data/psc/:/etc/ui/token/:z
networks:
- harbor
depends_on:
- log
- adminserver
- registry
logging:
driver: "syslog"
options:
syslog-address: "tcp://127.0.0.1:1514"
tag: "ui"
jobservice:
image: vmware/harbor-jobservice:v1.2.2
container_name: harbor-jobservice
env_file:
- ./common/config/jobservice/env
restart: always
volumes:
- /data/job_logs:/var/log/jobs:z
- ./common/config/jobservice/app.conf:/etc/jobservice/app.conf:z
- /data/secretkey:/etc/jobservice/key:z
networks:
- harbor
depends_on:
- ui
- adminserver
logging:
driver: "syslog"
options:
syslog-address: "tcp://127.0.0.1:1514"
tag: "jobservice"
proxy:
image: vmware/nginx-photon:1.11.13
container_name: nginx
restart: always
volumes:
- ./common/config/nginx:/etc/nginx:z
networks:
- harbor
ports:
- 80:80
- 443:443
- 4443:4443
depends_on:
- mysql
- registry
- ui
- log
logging:
driver: "syslog"
options:
syslog-address: "tcp://127.0.0.1:1514"
tag: "proxy"
networks:
harbor:
external: false
5、访问harbor的UI界面 打开浏览器访问 http://192.168.35.40 的管理页面,默认 的管理员用户名和密码是 admin/Harbor12345。 6、命令行登录harbor
- Harbor 服务器基于本地操作
使用 Docker 命令在本地通过 127.0.0.1 来登录和推送镜像。默认情况下,Register 服务器在端口 80 上侦听。
[root@harbor harbor]
....
Login Succeeded
[root@harbor harbor]
Using default tag: latest
latest: Pulling from library/cirros
d0b405be7a32: Pull complete
bd054094a037: Pull complete
c6a00de1ec8a: Pull complete
Digest: sha256:1e695eb2772a2b511ccab70091962d1efb9501fdca804eb1d52d21c0933e7f47
Status: Downloaded newer image for cirros:latest
docker.io/library/cirros:latest
[root@harbor harbor]
[root@harbor harbor]
The push refers to repository [127.0.0.1/mytest-test/cirros]
984ad441ec3d: Preparing
f0a496d92efa: Preparing
e52d19c3bee2: Preparing
denied: requested access to the resource is denied
[root@harbor harbor]
[root@harbor harbor]
Using default tag: latest
The push refers to repository [127.0.0.1/mytest/cirros]
984ad441ec3d: Pushed
f0a496d92efa: Pushed
e52d19c3bee2: Pushed
latest: digest: sha256:483f15ac97d03dc3d4dcf79cf71ded2e099cf76c340f3fdd0b3670a40a198a22 size: 943
- Harbor 服务器非本地操作
[root@client ~]
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
Error response from daemon: Get https://192.168.35.40/v2/: EOF
[root@client ~]
13 ExecStart=/usr/bin/dockerd -H fd:// --insecure-registry 192.168.235.156 --containerd=/run/containerd/containerd.sock
[root@client ~]
[root@client ~]
[root@harbor harbor]
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
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/
Login Succeeded
[root@client ~]
Using default tag: latest
latest: Pulling from library/cirros
Digest: sha256:1e695eb2772a2b511ccab70091962d1efb9501fdca804eb1d52d21c0933e7f47
Status: Image is up to date for cirros:latest
docker.io/library/cirros:latest
[root@client ~]
[root@harbor harbor]
[root@harbor harbor]
[root@harbor harbor]
The push refers to repository [192.168.235.156/mytest/cirros]
984ad441ec3d: Layer already exists
f0a496d92efa: Layer already exists
e52d19c3bee2: Layer already exists
1: digest: sha256:483f15ac97d03dc3d4dcf79cf71ded2e099cf76c340f3fdd0b3670a40a198a22 size: 943
7、harbor用户管理 1、创建 Harbor 用户 系统管理----用户管理----+用户----输入用户名、邮箱、全名、密码
//在客户端上操作
[root@harbor harbor]
Untagged: 192.168.23.156/mytest/cirros:latest
[root@client ~]
Removing login credentials for 192.168.235.157
[root@harbor harbor]
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
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/
Login Succeeded
[root@harbor harbor]
latest: Pulling from mytest/cirros
Digest: sha256:483f15ac97d03dc3d4dcf79cf71ded2e099cf76c340f3fdd0b3670a40a198a22
Status: Downloaded newer image for 192.168.235.156/mytest/cirros:latest
192.168.235.156/mytest/cirros:latest
8、维护管理Harbor 可以使用 docker-compose 来管理 Harbor。一些有用的命令如下所示,必须在与docker-compose.yml 相同的目录中运行。 修改 Harbor.cfg 配置文件 要更改 Harbour 的配置文件时,请先停止现有的 Harbour 实例并更新 Harbor.cfg;然后运行 prepare 脚本来填充配置;最后重新创建并启动 Harbour 的实例
|