有可视化的Web管理界面,可以方便管理Docker镜像,又提供了多个项目的镜像权限管理及控制功能
Harbor是VMware公司开源的企业级Docker Registry项目
主机 | 操作系统 | IP地址 | 软件 |
---|---|---|---|
erver | CentOS7.6 | 192.168.126.11 | docker、docker-compose、harbor-offline-v1.1.2 |
client | CentOS7.6 | 192.168.126.12 | docker |
Harbor 被部署为多个 Docker 容器,因此可以部署在任何支持 Docker 的 Linux 发行版 上。
服务端主机需要安装 Python、Docker 和 Docker Compose
1.下载harbor安装程序
cd /usr/local
rz docker-compose
chmod +x docker-compose
mv docker-compose /usr/bin
rz harbor-offline-installer-v1.2.2.tgz
tar zxvf harbor-offline-installer-v1.2.2.tgz -C /usr/local/
2.==配置Harbor参数文件==
vim /usr/local/harbor/harbor.cfg
==第5行修改==
hostname = 192.168.126.11
3.hostname = 192.168.126.16
①harbor.cfg 配置文件详解
harbor.cfg配置文件中有所需参数与可选参数这两类参数
1)所需参数,这些参数需要在配置文件harbor.cfg中设置
用户更新它们并运行install.sh脚本以启动harbour,参数将生效
具体参数如下
hostname:用于访问用户界面和register服务,指向目标机器的IP地址或域名;注,不要使用 localhost 或 127.0.0.1 为主机名!
ui_url_protocol:(http或https,默认为 http)用于访问 UI 和令牌/通知服务的协议,如果公证处于启用状态,则此参数必须为 https
max_job_workers:镜像复制作业线程
db_password:用于设置db_auth的MySQL数据库root用户的密码
customize_crt:该属性可设置为打开或关闭,默认打开;打开此属性时,准备脚本创建私钥和根证书,用于生成/验证注册表令牌;当由外部来源提供密钥和根证书时,将此属性设置为off
ssl_cert:SSL 证书的路径,仅当协议设置为https时才应用
ssl_cert_key:SSL密钥的路径,仅当协议设置为https时才应用
secretkey_path:用于在复制策略中加密或解密远程register密码的密钥路径
2)可选参数:这些参数对于更新是可选的,即用户可以将其保留为默认值,并在启动harbor后在Web UI上进行更新
如果进入harbor.cfg,只会在第一次启动harbor时生效,随后对这些参数的更新,Harbor.cfg将被忽略
注意:如果选择通过UI设置这些参数,请确保在启动harbour后立即执行此操作
具体来说,必须在注册或在harbor中创建任何新用户之前设置所需的
auth_mode,当系统中有用户时(除了默认的admin用户),auth_mode不能被修改。具体参数如下:
Email:harbor需要该参数才能向用户发送“密码重置”电子邮件,并且只有在需要该功能时才需要;请注意,在默认情况下SSL连接时没有启用;如果SMTP服务器需要SSL,但不支持STARTTLS,那么应该通过设置启用SSL email_ssl = TRUE
harbor_admin_password:管理员的初始密码,只在harbour第一次启动时生效;之后,此设置将被忽略,并且应在UI中设置管理员的密码;请注意,默认的用户名/密码是admin/Harbor12345
auth_mode:使用的认证类型,默认情况下,它是db_auth,即凭据存储在数据库中;对于LDAP身份验证,请将其设置为ldap_auth
self_registration:启用/禁用用户注册功能;禁用时,新用户只能由Admin用户创建,只有管理员用户可以在harbor中创建新用户;注意,当 auth_mode 设置为ldap_auth时,自注册功能将始终处于禁用状态,并且该标志被忽略
Token_expiration:由令牌服务创建的令牌的到期时间(分钟),默认为30分钟
project_creation_restriction:用于控制哪些用户有权创建项目的标志;默认情况下,每个人都可以创建一个项目;如果将其值设置为“adminonly”,那么只有admin可以创建项目
verify_remote_cert:打开或关闭,默认打开;此标志决定了当harbor与远程register实例通信时是否验证SSL/TLS证书;将此属性设置为off,将绕过SSL/TLS验证,这在远程实例具有自签名或不可信证书时经常使用
另外,默认情况下,harbour将镜像存储在本地文件系统上;在生产环境中,可以考虑使用其他存储后端而不是本地文件系统,如S3、Openstack Swif、Ceph等;但需要更新common/templates/registry/config.yml文件
②查看 harbor 启动镜像及容器
1.查看harbor启动镜像
Last login: Fri Dec 3 11:06:50 2021 from 192.168.126.1
[root@xjj ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest feb5d9fea6a5 2 months ago 13.3kB
vmware/harbor-log v1.2.2 36ef78ae27df 4 years ago 200MB
vmware/harbor-jobservice v1.2.2 e2af366cba44 4 years ago 164MB
vmware/harbor-ui v1.2.2 39efb472c253 4 years ago 178MB
vmware/harbor-adminserver v1.2.2 c75963ec543f 4 years ago 142MB
vmware/harbor-db v1.2.2 ee7b9fa37c5d 4 years ago 329MB
vmware/nginx-photon 1.11.13 6cc5c831fc7f 4 years ago 144MB
vmware/registry 2.6.2-photon 5d9100e4350e 4 years ago 173MB
vmware/postgresql 9.6.4-photon c562762cbd12 4 years ago 225MB
vmware/clair v2.0.1-photon f04966b4af6c 4 years ago 297MB
vmware/harbor-notary-db mariadb-10.1.10 64ed814665c6 4 years ago 324MB
vmware/notary-photon signer-0.5.0 b1eda7d10640 4 years ago 156MB
vmware/notary-photon server-0.5.0 6e2646682e3c 4 years ago 157MB
photon 1.0 e6e4e4a2ba1b 5 years ago 128MB
2.查看启动容器
[root@xjj ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d1e6ab6c5228 vmware/nginx-photon:1.11.13 "nginx -g 'daemon of…" 4 hours ago Up 4 hours 0.0.0.0:80->80/tcp, :::80->80/tcp, 0.0.0.0:443->443/tcp, :::443->443/tcp, 0.0.0.0:4443->4443/tcp, :::4443->4443/tcp nginx
620343664dbe vmware/harbor-jobservice:v1.2.2 "/harbor/harbor_jobs…" 4 hours ago Up 4 hours harbor-jobservice
ea56039af44d vmware/harbor-ui:v1.2.2 "/harbor/harbor_ui" 4 hours ago Up 4 hours harbor-ui
f726d9bb8ec6 vmware/harbor-adminserver:v1.2.2 "/harbor/harbor_admi…" 4 hours ago Up 4 hours harbor-adminserver
ee4da43c0ffb vmware/registry:2.6.2-photon "/entrypoint.sh serv…" 4 hours ago Up 4 hours 5000/tcp registry
ce8ae0a3ebcb vmware/harbor-db:v1.2.2 "docker-entrypoint.s…" 4 hours ago Up 4 hours 3306/tcp harbor-db
e1279c011475 vmware/harbor-log:v1.2.2 "/bin/sh -c 'crond &…" 4 hours ago Up 4 hours 127.0.0.1:1514->514/tcp
③此时可真机访问serverIP
192.168.126.11
用户名:admin
密码:Harbor12345
④harbor 服务端进行测试
默认情况下, Register服务器在端口 80 上侦听
[root@xjj ~]# netstat -natp | grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 108764/docker-proxy
tcp6 0 0 :::80 :::* LISTEN 108772/docker-proxy
此时可使用 Docker 命令在本地通过 127.0.0.1 来登录和推送镜像
[root@harbor harbor]# docker login -u admin -p Harbor12345 http://127.0.0.1
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/#credentials-store
Login Succeeded #登录成功
[root@harbor harbor]# docker pull cirros #cirros是测试起来很方便的镜像,小于15M
[root@xjj ~]# docker tag cirros:latest 127.0.0.1/daxiaoxu/cirros:v1 #打标签,v1便于区别
[root@xjj ~]# docker push 127.0.0.1/daxiaoxu/cirros:v1 #上传至harbor
⑤client 客户端测试
注:以上操作都是在harbor服务器本地操作,如果其他客户端想上传镜像到harbor,需要连接至harbor服务器!
因为,Docker Registry交互默认使用的是HTTPS,但是搭建私有镜像默认使用的是HTTP服务,所以与私有镜像交互时可能会出现错误
--可能会出现的错误--
[root@localhost ~]# docker login -u admin -p Harbor12345 http://192.168.126.11
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
Error response from daemon: Get https://192.168.126.11/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
#解决办法是在 Docker server 启动的时候,增加启动参数,默认使用 HTTP 访问
方法一:修改 /usr/lib/systemd/system/docker.service
[root@localhost ~]#vim /usr/lib/systemd/system/docker.service
#13行修改
ExecStart=/usr/bin/dockerd -H fd:// --insecure-registry 192.168.126.11 --containerd=/run/containerd/containerd.sock
#或修改为 ExecStart=/usr/bin/dockerd --insecure-registry 192.168.126.11
#方法二:修改 /ets/docker/daemon.json
[root@localhost ~]#cat /etc/docker/daemon.json
{
"insecure-registries": ["192.168.126.11"],
"registry-mirrors": ["https://4iv7219l.mirror.aliyuncs.com"]
}
[root@localhost ~]#systemctl daemon-reload
[root@localhost ~]#systemctl restart docker
[root@localhost ~]# docker login -u admin -p Harbor12345 http://192.168.126.11
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/#credentials-store
Login Succeeded
[root@localhost ~]# docker tag cirros:latest 192.168.126.11/daxiaoxu/cirros:v2
[root@localhost ~]# docker push 192.168.126.11/daxiaoxu/cirros:v2
The push refers to repository [192.168.126.11/daxiaoxu/cirros]
984ad441ec3d: Layer already exists
f0a496d92efa: Layer already exists
e52d19c3bee2: Layer already exists
v2: digest: sha256:483f15ac97d03dc3d4dcf79cf71ded2e099cf76c340f3fdd0b3670a40a198a22 size: 943
在 Harbor 仓库中,任何镜像在被 push 到 regsitry 之前都必须有一个自己所属的项目。
单击 +项目,填写项目名称,项目级别若设置为 私有,则不勾选。如果设置为 公共 仓库,则所有人对此项目下的镜像拥有读权限,命令行中不需要执行 Docker login 即可下载镜像,镜像操作与 Docker Hub 一致
可以使用docker-compose来管理harbor
一些有用的命令如下所示,注意,必须在与docker-compose.yml相同的目录中运行!
[root@harbor ~]# docker-compose down -v '//运行不了,您找对目录了吗?'
ERROR:
Can't find a suitable configuration file in this directory or any parent. Are you in the right directory? Supported filenames: docker-compose.yml, docker-compose.yaml [root@harbor ~]# cd /usr/local/harbor/ '//docker-compose.yml'
[root@harbor harbor]# ls
common docker-compose.yml harbor.v1.2.2.tar.gz NOTICE
docker-compose.clair.yml harbor_1_1_0_template install.sh prepare
docker-compose.notary.yml harbor.cfg LICENSE upgrade
--修改harbor.cfg配置文件--
要更改harbor的配置文件时,请按照以下不步骤:
1.请先停止现有的harbor实例再来更新harbor.cfg配置文件
[root@harbor harbor]# docker-compose down -v
Stopping harbor-jobservice ... done
Stopping nginx ... done
Stopping harbor-ui ... done
Stopping harbor-db ... done
Stopping harbor-adminserver ... done
Stopping registry ... done
Stopping harbor-log ... done
Removing harbor-jobservice ... done
Removing nginx ... done
Removing harbor-ui ... done
Removing harbor-db ... done
Removing harbor-adminserver ... done
Removing registry ... done
Removing harbor-log ... done
Removing network harbor_harbor
[root@harbor harbor]# vim harbor.cfg
...
...
2.运行prepare脚本来填充配置
[root@harbor harbor]# ./prepare
Clearing the configuration file: ./common/config/adminserver/env
Clearing the configuration file: ./common/config/ui/env
Clearing the configuration file: ./common/config/ui/app.conf
Clearing the configuration file: ./common/config/ui/private_key.pem
Clearing the configuration file: ./common/config/db/env
Clearing the configuration file: ./common/config/jobservice/env
Clearing the configuration file: ./common/config/jobservice/app.conf
Clearing the configuration file: ./common/config/registry/config.yml
Clearing the configuration file: ./common/config/registry/root.crt
Clearing the configuration file: ./common/config/nginx/nginx.conf
loaded secret from file: /data/secretkey
Generated configuration file: ./common/config/nginx/nginx.conf
Generated configuration file: ./common/config/adminserver/env
Generated configuration file: ./common/config/ui/env
Generated configuration file: ./common/config/registry/config.yml
Generated configuration file: ./common/config/db/env
Generated configuration file: ./common/config/jobservice/env
Generated configuration file: ./common/config/jobservice/app.conf
Generated configuration file: ./common/config/ui/app.conf
Generated certificate, key file: ./common/config/ui/private_key.pem, cert file: ./common/config/registry/root.crt
The configuration files are ready, please use docker-compose to start the service.
3.最后重新创建并启动harbor的实例
[root@harbor harbor]# docker-compose up -d
Creating network "harbor_harbor" with the default driver
Creating harbor-log ... done
Creating harbor-adminserver ... done
Creating registry ... done
Creating harbor-db ... done
Creating harbor-ui ... done
Creating harbor-jobservice ... done
Creating nginx ... done
#可能会启动不成功,检查防火墙是否关闭,然后重启docker再来试试
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.126.11/daxiaoxu latest feb5d9fea6a5 2 months ago 13.3kB
hello-world latest feb5d9fea6a5 2 months ago 13.3kB
192.168.126.11/daxiaoxu/cirros v1 f9cae1daf5f6 8 months ago 12.6MB
192.168.126.11/daxiaoxu/cirros v2 f9cae1daf5f6 8 months ago 12.6MB
cirros latest f9cae1daf5f6 8 months ago 12.6MB
[root@localhost ~]# docker rmi 192.168.126.11/daxiaoxu/cirros:v2 #删除本地镜像
Untagged: 192.168.126.11/daxiaoxu/cirros:v2
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest feb5d9fea6a5 2 months ago 13.3kB
192.168.126.11/daxiaoxu latest feb5d9fea6a5 2 months ago 13.3kB
192.168.126.11/daxiaoxu/cirros v1 f9cae1daf5f6 8 months ago 12.6MB
cirros latest f9cae1daf5f6 8 months ago 12.6MB
[root@localhost ~]# docker logout 192.168.126.11 #登出
Removing login credentials for 192.168.126.11
[root@localhost ~]# docker login 192.168.126.11 -u jiangjiang -p Jiang123321
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/#credentials-store
Login Succeeded
[root@localhost ~]# docker pull 192.168.126.11/daxiaoxu/cirros:v2 #从私有仓库重新下载v2
v2: Pulling from daxiaoxu/cirros
Digest: sha256:483f15ac97d03dc3d4dcf79cf71ded2e099cf76c340f3fdd0b3670a40a198a22
Status: Downloaded newer image for 192.168.126.11/daxiaoxu/cirros:v2
192.168.126.11/daxiaoxu/cirros:v2
[root@localhost ~]# docker images #有了
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.126.11/daxiaoxu latest feb5d9fea6a5 2 months ago 13.3kB
hello-world latest feb5d9fea6a5 2 months ago 13.3kB
192.168.126.11/daxiaoxu/cirros v1 f9cae1daf5f6 8 months ago 12.6MB
192.168.126.11/daxiaoxu/cirros v2 f9cae1daf5f6 8 months ago 12.6MB
cirros latest f9cae1daf5f6 8 months ago 12.6MB
[root@localhost ~]# docker tag cirros:latest 192.168.126.11/daxiaoxu/cirros:v3 #打标签v3
[root@localhost ~]# docker push 192.168.126.11/daxiaoxu/cirros:v3 #上传测试
The push refers to repository [192.168.126.11/daxiaoxu/cirros]
984ad441ec3d: Layer already exists
f0a496d92efa: Layer already exists
e52d19c3bee2: Layer already exists
v3: digest: sha256:483f15ac97d03dc3d4dcf79cf71ded2e099cf76c340f3fdd0b3670a40a198a22 size: 943
[root@xjj /usr/local/harbor]#docker-compose down -v
#把项目中的镜像数据进行打包
持久数据,如镜像,数据库等在宿主机的 /data/ 目录下,日志在宿主机的 /var/log/Harbor/ 目录下
[root@xjj harbor]# ls /data/registry/docker/registry/v2/repositories/daxiaoxu/
cirros
[root@xjj harbor]# cd /data/registry/docker/registry/v2/repositories/daxiaoxu/
[root@xjj daxiaoxu]# tar zcvf daxiaoxu.tar.gz ./*
docker-compose down -v
#如果需要重新部署,需要移除Harbor服务容器全部数据
#持久数据,如镜像,数据库等在宿主机的/data目录下,日志在宿主机的/var/log/Harbor目录下
rm -rf /data/database
rm -rf /data/registry
1、docker -harbor 镜像仓库——>是本地私有镜像仓库用于保存项目/企业/平台内部经常使用的镜像/自定义的镜像,用于给docker /K8S 使用
2、docker-harbor 服务由多个子功能模块组成,例如: UI NGINX MYSQL registry proxy adminserver jobserver , docker -harbor 使用
docker-compose的方式将以上的子功能模块以容器的形式部署/展现出来,并且进行统一的编排管理
① docker-compose 可以定义镜像拉取的方式——>1) docker-hub 公共仓库拉取 2) dockerfile 自定义构建镜像
②docker-compose可以指定镜像的挂载、镜像中服务的端口暴露、可以指定network网络、可以指定env环境变量、可以指定重启策略等等
①tar解压
②上传docker-compose 命令工具,给与执行权限
③执行install.sh 脚本
④在docker的systemd 管理服务的docker . service 启动文件中,添加insecure- registry 192.168.226.128 (harbor仓库位置) 并且重载守护进程
systemctl daemon- reload和重启容器docker restart docker让本地的docker可以识别并登陆本地私有仓库(docker login )
⑤上传镜像必要操作: docker tag source_ image name:tag 192.168.226.128/project_ name/ image_ name : TAG
再docker push 192.168.226.128/project_ name/ image_ name : TAG
①可以进行用户/角色的创建和权限管理
②认证管理:数据库/ldap
③镜像操作日志管理
④token令牌管理
版权说明 : 本文为转载文章, 版权归原作者所有 版权申明
原文链接 : https://blog.csdn.net/weixin_53560205/article/details/121704891
内容来源于网络,如有侵权,请联系作者删除!