Harbor—镜像仓库

本文介绍了如何在私有环境中部署Harbor,一个由VMware开源的企业级Docker Registry管理项目。首先,详细讲解了如何通过openssl创建自签发证书,然后介绍了安装Docker和docker-compose的步骤,最后提到了Harbor的安装过程。
摘要由CSDN通过智能技术生成

1、Harbor介绍
        Docker容器应用的开发和运行离不开可靠的镜像管理,虽然Docker官方也提供了公共的镜像仓库,但是从安全和效率等方面考虑,部署我们私有环境内的Registry也是非常必要的。Harbor是由VMware公司开源的企业级的Docker Registry管理项目,它包括权限管理(RBAC)、LDAP、日志审核、管理界面、自我注册、镜像复制和中文支持等功能。
        官网地址:https://github.com/goharbor/harbor

2、Harbor镜像仓库部署
2.1、环境准备
harbor:192.168.4.5 2CPU、内存4G

关闭防火墙、selinux

2.2、自签发证书
1)创建存放证书目录

[root@harbor ~]# openssl version     # 检查是否安装了openssl
[root@harbor ~]# mkdir /opt/harbor-ca-key
[root@harbor ~]# cd /opt/harbor-ca-key/
2)创建ca证书

[root@harbor harbor-ca-key]# openssl genrsa -out ca.key 3072  # 生成3072位的ca.key的私钥
[root@harbor harbor-ca-key]# openssl req -new -x509 -days 3650 -key ca.key -out ca.pem  # 生成一个数字证书 ca.pem,3650 表示证书的有效时间是 10 年,按箭头提示填写即可,没有箭头 标注的为空:
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:guangdong
Locality Name (eg, city) [Default City]:guangzhou
Organization Name (eg, company) [Default Company Ltd]:harbor
Organizational Unit Name (eg, section) []:CA
Common Name (eg, your name or your server's hostname) []:harbor64.cn
Email Address []:jy@163.com
3)生成域名的证书 

 
[root@harbor harbor-ca-key]# openssl genrsa -out harbor.key 3072   # 生成一个 3072 位的 key,也就是私钥
 
[root@harbor harbor-ca-key]# openssl req -new -key harbor.key -out harbor.csr  #生成一个证书请求,一会签发证书时需要的,标箭头的按提示填写,没有箭头标注的为空:
 
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:guangdong
Locality Name (eg, city) [Default City]:guangzhou
Organization Name (eg, company) [Default Company Ltd]:harbor
Organizational Unit Name (eg, section) []:CA
Common Name (eg, your name or your server's hostname) []:harbor64.cn
Email Address []:jy@163.com
 
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:1234
An optional company name []:harbor
4)签发证书

[root@harbor harbor-ca-key]# openssl x509 -req -in harbor.csr -CA ca.pem -CAkey ca.key -CAcreateserial -out harbor.pem -days 3650
Signature ok
subject=/C=CN/ST=guangdong/L=guangzhou/O=harbor/OU=CA/CN=harbor64.cn/emailAddress=jy@163.com
Getting CA Private Key
 
[root@harbor harbor-ca-key]# openssl x509 -noout -text -in harbor.pem   # 查看证书是否有效
 
Certificate:
    Data:
        Version: 1 (0x0)
        Serial Number:
            ed:66:8a:c0:ca:d3:2b:9e
    Signature Algorithm: sha256WithRSAEncryption
        Issuer: C=CN, ST=guangdong, L=guangzhou, O=harbor, OU=CA, CN=harbor64.cn/emailAddress=jy@163.com
        Validity
            Not Before: Jun  5 10:33:54 2022 GMT
            Not After : Jun  2 10:33:54 2032 GMT
        Subject: C=CN, ST=guangdong, L=guangzhou, O=harbor, OU=CA, CN=harbor64.cn/emailAddress=jy@163.com
        Subject Public Key Info:
            Public Key Algorithm: rsaEncryption
                Public-Key: (3072 bit)
                Modulus:
…………………………………………………… # 显示以上内容证明有效
 
[root@harbor harbor-ca-key]# ls
ca.key  ca.pem  ca.srl  harbor.csr  harbor.key  harbor.pem

2.3、安装 Harbor
1)安装docker、docker-compose 

[root@harbor ~]# yum -y install wget
 
# 安装epel源,并将repo 配置中的地址替换为阿里云镜像站地址
[root@harbor ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
[root@harbor ~]# sed -i 's|^#baseurl=https://download.fedoraproject.org/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
[root@harbor ~]# sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*
 
# 下载阿里云的yum源文件
[root@harbor ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.cloud.tencent.com/repo/centos7_base.repo
 
 
# 配置docker源
[root@harbor ~]# wget https://download.docker.com/linux/centos/docker-ce.repo -P /etc/yum.repos.d/
 
[root@harbor ~]# yum clean all && yum makecache 
[root@harbor ~]# yum install -y docker-ce docker-compose
[root@harbor ~]# systemctl enable docker
[root@harbor ~]# systemctl restart docker
2)安装harbor

Harbor 是一个开源的云原生镜像仓库,支持 Docker 和 Kubernetes。搭建 Harbor 镜像仓库可以方便地管理和部署 Docker 镜像。 以下是 Harbor 镜像仓库的搭建步骤: 1. 安装 DockerDocker Compose 首先需要在服务器上安装 DockerDocker Compose,可以参考 Docker 官方文档进行安装。 2. 下载并解压 Harbor 安装包 在 Harbor官网上下载最新版本的 Harbor 安装包,解压到服务器上的任意目录。 3. 配置 Harbor 进入 Harbor 安装包所在目录,编辑 `harbor.cfg` 文件,配置相关参数,例如: ``` hostname = example.com ui_url_protocol = https harbor_admin_password = StrongPassword ``` 这里的 `hostname` 是 Harbor 的访问地址,`ui_url_protocol` 是访问协议,`harbor_admin_password` 是管理员密码。 4. 启动 HarborHarbor 安装包所在目录下执行以下命令启动 Harbor: ``` docker-compose up -d ``` 这会启动 Harbor 的所有组件,并且在后台运行。 5. 配置 Docker 客户端 在需要使用 Harbor 镜像仓库的客户端机器上,编辑 Docker 配置文件 `/etc/docker/daemon.json`,加入以下内容: ``` { "insecure-registries": ["example.com"] } ``` 这里的 `example.com` 是 Harbor 的访问地址。 6. 登录 Harbor 在客户端机器上执行以下命令登录 Harbor: ``` docker login example.com ``` 这里的 `example.com` 是 Harbor 的访问地址。 7. 使用 Harbor 登录成功后,就可以使用 Harbor 镜像仓库了,例如: ``` docker pull example.com/library/nginx:latest docker push example.com/library/nginx:latest ``` 这里的 `library/nginx` 是一个示例镜像,可以替换成其他镜像。 以上是 Harbor 镜像仓库的搭建步骤,希望对你有所帮助。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值