Harbor是一个用于存储和分发Docker镜像的企业级Registry服务器,通过添加一些企业必需的功能特性,例如安全、标识和管理等,扩展了开源Docker Distribution。作为一个企业级私有Registry服务器,Harbor提供了更好的性能和安全。提升用户使用Registry构建和运行环境传输镜像的效率。Harbor支持安装在多个Registry节点的镜像资源复制,镜像全部保存在私有Registry中, 确保数据和知识产权在公司内部网络中管控。另外,Harbor也提供了高级的安全特性,诸如用户管理,访问控制和活动审计等。
基于角色的访问控制 :用户与Docker镜像仓库通过“项目”进行组织管理,一个用户可以对多个镜像仓库在同一命名空间(project)里有不同的权限。
镜像复制 :镜像可以在多个Registry实例中复制(同步)。尤其适合于负载均衡,高可用,混合云和多云的场景。
图形化用户界面 :用户可以通过浏览器来浏览,检索当前Docker镜像仓库,管理项目和命名空间。
AD/LDAP 支持 :Harbor可以集成企业内部已有的AD/LDAP,用于鉴权认证管理。
审计管理 :所有针对镜像仓库的操作都可以被记录追溯,用于审计管理。
国际化 :已拥有英文、中文、德文、日文和俄文的本地化版本。更多的语言将会添加进来。
RESTful API :RESTful API 提供给管理员对于Harbor更多的操控, 使得与其它管理软件集成变得更容易。
部署简单 :提供在线和离线两种安装工具, 也可以安装到vSphere平台(OVA方式)虚拟设备。
Harbor在架构上主要由6个组件构成:
各个组件之间的关系如下图所示:
192.168.1.18
Master、Harbor、Jenkins
CentOS 7.5.1804
Docker 19.03.13
Docker-Compose 1.18.0
2核+CPU,2GB+内存
Harbor部署依赖于docker和docker-compose。
安装Docker
一文搞懂Docker与Docker Engine的安装:https://blog.csdn.net/qq_44895681/article/details/105540702?…
安装Docker-compose
一文学会Docker Compose安装:https://blog.csdn.net/qq_44895681/article/details/105540333
[root@k8s-master ~]# wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo
[root@k8s-master ~]# yum -y install epel-release
[root@k8s-master ~]# yum -y install docker-compose
[root@k8s-master ~]# docker-compose version
docker-compose version 1.18.0, build 8dd22a9
docker-py version: 2.6.1
CPython version: 3.6.8
OpenSSL version: OpenSSL 1.0.2k-fips 26 Jan 2017
部署Harbor仓库
企业实战(5) Docker私有镜像仓库Harbor的部署与使用详解:https://blog.csdn.net/qq_44895681/article/details/105558611
下载
版本全,速度慢:https://github.com/goharbor/harbor/releases
下载Harbor v2.3.2并解压
[root@k8s-master ~]# wget https://github.com/goharbor/harbor/releases/download/v2.3.2/harbor-offline-installer-v2.3.2.tgz
[root@k8s-master ~]# ll harbor-offline-installer-v2.3.2.tgz
-rw-r--r-- 1 root root 605477475 9月 15 11:12 harbor-offline-installer-v2.3.2.tgz
[root@k8s-master ~]# tar -xvf harbor-offline-installer-v2.3.2.tgz
harbor/harbor.v2.3.2.tar.gz
harbor/prepare
harbor/LICENSE
harbor/install.sh
harbor/common.sh
harbor/harbor.yml.tmpl
[root@k8s-master ~]# cd harbor/
[root@k8s-master harbor]# ls
common.sh harbor.v2.3.2.tar.gz harbor.yml.tmpl install.sh LICENSE prepare
修改harbor配置文件
[root@k8s-master harbor]# cp harbor.yml.tmpl harbor.yml
[root@k8s-master harbor]# vim harbor.yml
...
5 hostname: 192.168.1.18 //设置访问地址,可以是ip、主机名,不可以设置为127.0.0.1或localhost
7 # http related config
8 http: //启用http
9 # port for http, default is 80. If https enabled, this port will redirect to https port
10 port: 80 //http默认端口为80
//将https注释掉,以关闭https支持
12 # https related config
13 #https: //注释
14 # https port for harbor, default is 443
15 # port: 443 //注释
16 # The path of cert and key files for nginx
17 # certificate: /your/certificate/path //注释
18 # private_key: /your/private/key/path //注释
...
33 # Remember Change the admin password from UI after launching Harbor.
34 harbor_admin_password: Harbor12345 //harbor登录密码
...
46 # The default data volume
47 data_volume: /opt/harbor/data //修改harbor仓库数据目录
...
[root@k8s-master harbor]# mkdir -p /opt/harbor/data //创建harbor仓库目录(安装Harbor时会自动创建)
[root@k8s-master harbor]# ls /opt/harbor/
data
[root@k8s-master harbor]# ./prepare //执行官方自带脚本更新配置文件
prepare base dir is set to /root/harbor
Unable to find image 'goharbor/prepare:v2.3.2' locally
v2.3.2: Pulling from goharbor/prepare
4fc7e8c5dda0: Pull complete
e101789e272e: Pull complete
3356ca67bae9: Pull complete
3d33c71b0e90: Pull complete
ab76e2d8736b: Pull complete
9d7f4a6ec28e: Pull complete
2f6837c65c74: Pull complete
bc8d1bca5b85: Pull complete
Digest: sha256:e6ae1e30c8897ca54bcc89682dbb10c2dbd08d6c9bba647eacdef6fa776d6428
Status: Downloaded newer image for goharbor/prepare:v2.3.2
WARNING:root:WARNING: HTTP protocol is insecure. Harbor will deprecate http protocol in the future. Please make sure to upgrade to https
Generated configuration file: /config/portal/nginx.conf
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/registryctl/config.yml
Generated configuration file: /config/db/env
Generated configuration file: /config/jobservice/env
Generated configuration file: /config/jobservice/config.yml
Generated and saved secret to file: /data/secret/keys/secretkey
Successfully called func: create_root_cert
Generated configuration file: /compose_location/docker-compose.yml
Clean up the input dir
在这里插入图片描述 开始安装Harbor
[root@k8s-master harbor]# ./install.sh //执行harbor安装脚本
[Step 0]: checking if docker is installed ...
Note: docker version: 19.03.13
[Step 1]: checking docker-compose is installed ...
Note: docker-compose version: 1.18.0
[Step 2]: loading Harbor images ...
Loaded image: goharbor/redis-photon:v2.3.2
Loaded image: goharbor/nginx-photon:v2.3.2
Loaded image: goharbor/harbor-portal:v2.3.2
Loaded image: goharbor/trivy-adapter-photon:v2.3.2
Loaded image: goharbor/chartmuseum-photon:v2.3.2
Loaded image: goharbor/notary-signer-photon:v2.3.2
Loaded image: goharbor/harbor-core:v2.3.2
Loaded image: goharbor/harbor-log:v2.3.2
Loaded image: goharbor/harbor-registryctl:v2.3.2
Loaded image: goharbor/harbor-exporter:v2.3.2
Loaded image: goharbor/notary-server-photon:v2.3.2
Loaded image: goharbor/prepare:v2.3.2
Loaded image: goharbor/harbor-db:v2.3.2
Loaded image: goharbor/harbor-jobservice:v2.3.2
Loaded image: goharbor/registry-photon:v2.3.2
[Step 3]: preparing environment ...
[Step 4]: preparing harbor configs ...
prepare base dir is set to /root/harbor
WARNING:root:WARNING: HTTP protocol is insecure. Harbor will deprecate http protocol in the future. Please make sure to upgrade to https
Clearing the configuration file: /config/portal/nginx.conf
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/passwd
Clearing the configuration file: /config/registry/config.yml
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/portal/nginx.conf
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/registryctl/config.yml
Generated configuration file: /config/db/env
Generated configuration file: /config/jobservice/env
Generated configuration file: /config/jobservice/config.yml
Creating harbor-log ... done
Generated configuration file: /compose_location/docker-compose.yml
Clean up the input dir
Creating redis ... done
Creating harbor-core ... done
Creating network "harbor_harbor" with the default driver
Creating nginx ... done
Creating registryctl ...
Creating redis ...
Creating registry ...
Creating harbor-portal ...
Creating harbor-db ...
Creating harbor-core ...
Creating harbor-jobservice ...
Creating nginx ...
✔ ----Harbor has been installed and started successfully.----
[root@k8s-master harbor]# docker-compose ps //查看运行中的harbor相关容器
Name Command State Ports
--------------------------------------------------------------------------------------
harbor-core /harbor/entrypoint.sh Up
harbor-db /docker-entrypoint.sh 96 13 Up
harbor-jobservice /harbor/entrypoint.sh Up
harbor-log /bin/sh -c /usr/local/bin/ ... Up 127.0.0.1:1514->10514/tcp
harbor-portal nginx -g daemon off; Up
nginx nginx -g daemon off; Up 0.0.0.0:80->8080/tcp
redis redis-server /etc/redis.conf Up
registry /home/harbor/entrypoint.sh Up
registryctl /home/harbor/start.sh Up
[root@k8s-master harbor]# ls /opt/harbor/data/ //Harbor仓库数据目录
ca_download database job_logs redis registry secret
说明:
这几个容器通过Docker link的形式连接在一起,在容器之间通过容器名字互相访问。对终端用户而言,只需要暴露proxy (即Nginx)的服务端口。
docker-compose up -d (相当于 build + start ):构建(容器)并启动(容器)整个project的所有service
docker-compose down -v(相当于 stop + rm ):停止并移除整个project的所有services
docker-compose start [serviceName]:启动已存在但停止的所有service
docker-compose stop [serviceName]:停止运行的service
docker-compose restart [serviceName]: 重启服务
docker-compose images:列出所用的镜像
docker-compose ps:查看正在运行的镜像
docker-compose down -v:停止并移除整个project的所有services
[root@localhost harbor]# docker-compose down -v
Stopping harbor-jobservice ... done
Stopping nginx ... done
Stopping harbor-ui ... done
Stopping harbor-adminserver ... done
Stopping redis ... done
Stopping harbor-db ... done
Stopping registry ... done
Stopping harbor-log ... done
Removing harbor-jobservice ... done
Removing nginx ... done
Removing harbor-ui ... done
Removing harbor-adminserver ... done
Removing redis ... done
Removing harbor-db ... done
Removing registry ... done
Removing harbor-log ... done
Removing network harbor_harbor
docker-compose up -d :构建(容器)并启动(容器)整个project的所有service
[root@localhost 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 redis ... done
Creating harbor-ui ... done
Creating harbor-jobservice ... done
Creating nginx ... done
启动完成后,我们访问刚才设置的hostname即:http://192.168.1.18,默认是80端口。
输入用户名:admin,默认密码:Harbor12345 登录Harbor。
新建私有项目
上传(push)镜像
[root@k8s-master harbor]# docker tag java-demo:v1.0 192.168.1.18/cicd/java-demo:v1.0 //根据每次上传的镜像版本打相应的标签,做好标识
[root@k8s-master harbor]# docker images | grep java
java-demo v1.0 96dbaacabd81 22 months ago 406MB
192.168.1.18/cicd/java-demo v1.0 96dbaacabd81 22 months ago 406MB
[root@k8s-master harbor]# docker push 192.168.1.18/cicd/java-demo:v1.0
The push refers to repository [192.168.1.18/cicd/java-demo]
85d053b8761f: Pushed
c7cfd67e17c7: Pushed
ceead5ca823f: Pushed
2353c173a26a: Pushed
071d8bd76517: Pushed
v1.0: digest: sha256:4e43b2bcd81adf6d00b46a5c7efd384fc9f5b059c75255c8c89404ed4818bae3 size: 1371
下载(pull)镜像
[root@k8s-node2 ~]# docker login 192.168.1.18 //node2主机登录到Harbor仓库下载镜像
Username: admin
Password: //登录Harbor的密码
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@k8s-node2 ~]# docker pull 192.168.1.18/cicd/java-demo:v1.0
v1.0: Pulling from cicd/java-demo
a02a4930cb5d: Pull complete
12ac6c660ca4: Pull complete
675ab56ce773: Pull complete
10f8e813c167: Pull complete
2347739fbd10: Pull complete
Digest: sha256:4e43b2bcd81adf6d00b46a5c7efd384fc9f5b059c75255c8c89404ed4818bae3
Status: Downloaded newer image for 192.168.1.18/cicd/java-demo:v1.0
192.168.1.18/cicd/java-demo:v1.0
[root@k8s-node2 ~]# docker images | grep java
192.168.1.18/cicd/java-demo v1.0 96dbaacabd81 22 months ago 406MB
Docker login Harbor报错解决:https://blog.csdn.net/qq_44895681/article/details/105573702