企业级镜像仓库harbor搭建(http/https)及使用

栏目: 编程工具 · 发布时间: 5年前

内容简介:其他:关于https访问,可以看另一篇博客http://blog.51cto.com/slitobo/1931603

1.Habor简介

Habor是由VMWare公司开源的容器镜像仓库。事实上,Habor是在Docker Registry上进行了相应的企业级扩展,从而获得了更加广泛的应用,这些新的企业级特性包括:管理用户界面,基于角色的访问控制,AD/LDAP集成以及审计日志等,足以满足基本企业需求。

2.安装docker-ce

1)安装依赖包

[root@harbor opt]# yum install -y yum-utils device-mapper-persistent-data lvm2

2)下载docker-ce 仓库

[root@harbor opt]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

官方比较慢的话,可以使用阿里云的docker-ce.repo

https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

3)更新仓库

yum repolist 或者 yum makecache fast

4)安装docker-ce

[root@harbor opt]# yum install docker-ce -y

5)配置加速并启动

[root@harbor opt]# curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://f1361db2.m.daocloud.io

[root@harbor opt]# systemctl start docker

6) 确认安装完成

[root@harbor opt]# docker-compose version

企业级镜像仓库harbor搭建(http/https)及使用

3.安装docker-compose

第一种方式:yum 安装

[root@harbor opt]# yum install docker-compose -y

第二种方式:下载可执行文件:

[root@harbor opt]# curl -L " https://github.com/docker/compose/releases/download/1.23.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

[root@harbor opt]# chmod +x /usr/local/bin/docker-compose

确认安装完成:

企业级镜像仓库harbor搭建(http/https)及使用

4.安装harbor

[root@harbor opt]# cd /opt

[root@harbor opt]# wget https://storage.googleapis.com/harbor-releases/harbor-offline-installer-v1.6.1.tgz

[root@harbor opt]# tar -xf harbor-offline-installer-v1.6.1.tgz

[root@harbor opt]# cd harbor/

[root@harbor opt]# vim harbor.cfg

hostname = reg.slito.com \harbor的服务地址(ip或者域名)

ui_url_protocol = http \选择http方式

harbor_admin_password = 123456 \harbor web访问的密码

[root@harbor harbor]# ./prepare \加载配置

企业级镜像仓库harbor搭建(http/https)及使用

[root@harbor harbor]# ./install.sh \安装harbor

企业级镜像仓库harbor搭建(http/https)及使用

安装完成后,提示通过“ http://reg.slito.com ” 访问harbor,用户名是admin,密码是之前设置的123456

企业级镜像仓库harbor搭建(http/https)及使用

5.上传镜像到harbor仓库

在本机配置harbor仓库http可信

/etc/docker/daemon.json中添加“"insecure-registries":["reg.slito.com"]”,重启docker

企业级镜像仓库harbor搭建(http/https)及使用

不然会报错,默认是走https的

企业级镜像仓库harbor搭建(http/https)及使用

在node1上登录harbor仓库,上传/下载镜像

[root@node1 ~]# docker login reg.slito.com

Username: admin

Password:

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@node1 ~]# docker tag busybox reg.slito.com/library/busybox:v1

[root@node1 ~]# docker push reg.slito.com/library/busybox:v1

The push refers to repository [reg.slito.com/library/busybox]

8a788232037e: Pushed

v1: digest: sha256:915f390a8912e16d4beb8689720a17348f3f6d1a7b659697df850ab625ea29d5 size: 527

[root@node1 ~]#

在harbor中查看

企业级镜像仓库harbor搭建(http/https)及使用

6.下载harbor中的镜像

先删掉原来的镜像

[root@node1 ~]# docker rmi reg.slito.com/library/busybox:v1

重新从harbor pull

[root@node1 ~]# docker pull reg.slito.com/library/busybox:v1

确认

[root@node1 ~]# docker images | grep busybox

reg.slito.com/library/busybox v1 59788edf1f3e 8 weeks ago 1.15MB

7.配置https访问

1) 安装openssl

#yum install openssl -y

2) 创建证书的database文件index.txt和序列文件serial

[root@harbor opt]# touch /etc/pki/CA/index.txt

[root@harbor opt]# echo "01" > /etc/pki/CA/serial

企业级镜像仓库harbor搭建(http/https)及使用

3) 创建私钥,生成自签证书(用于发放给个人用户)

#(umask 077;openssl genrsa -out /etc/pki/CA/private/cakey.pem)

#openssl req -new -x509 -key /etc/pki/CA/private/cakey.pem -out /etc/pki/CA/cacert.pem

企业级镜像仓库harbor搭建(http/https)及使用

4) 客户端生成证书请求(.csr)

#cd /opt/harbor

#mkdir ssl

#cd ssl

#(umask 077;openssl genrsa -out reg.slito.com.key) \生成私钥

#openssl req -new -key reg.slito.com.key -out reg.slito.com.csr \ 生成证书请求

和上面cacert.pem生成时写的结果保持一致

企业级镜像仓库harbor搭建(http/https)及使用

5) 签发证书(本机是CA同时又是申请证书的客户端)

#cd /opt/harbor/ssl

#openssl ca -in reg.slito.com.csr -out reg.slito.com.crt -days 365

企业级镜像仓库harbor搭建(http/https)及使用 企业级镜像仓库harbor搭建(http/https)及使用

6) 修改配置文件,重新启动harbor

#cd /opt/harbor

#docker-compose down -v

#vim harbor.cfg

ui_url_protocol = https

ssl_cert = ./ssl/reg.slito.com.crt

ssl_cert_key = ./ssl/cert/reg.slito.com.key

secretkey_path = ./ssl/

#./prepare

#./install.sh

企业级镜像仓库harbor搭建(http/https)及使用

访问“ https://reg.slito.com

企业级镜像仓库harbor搭建(http/https)及使用

7) 其他主机访问harbor,pull/push镜像设置

拷贝reg.slito.com.crt到需要访问harbor仓库的主机上(/etc/docker/certs.d/reg.slito.com/),目标主机不用配置信任就可以直接访问。

#cp /opt/harbor/ssl/reg.slito.com.crt /etc/docker/certs.d/reg.slito.com/

企业级镜像仓库harbor搭建(http/https)及使用

其他:关于https访问,可以看另一篇博客http://blog.51cto.com/slitobo/1931603


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

HTML5与CSS3权威指南(上册) (第3版)

HTML5与CSS3权威指南(上册) (第3版)

陆凌牛 / 机械工业出版社 / 2015-9-1 / CNY 89.00

本书是HTML 5与CSS 3领域公认的标杆之作,被读者誉为“系统学习HTML 5与CSS 3的最佳著作”和“Web前端工程师案头必备图书之_”。 前两版累计印刷超过15次,网络书店评论超过8000条,98%以上的评论都是五星级的好评。不仅是HTML 5与CSS 3图书领域当之无愧的领头羊,而且在整个原创计算机图书领域是佼佼者。 第3版首先从技术的角度根据最新的HTML 5和CSS 3......一起来看看 《HTML5与CSS3权威指南(上册) (第3版)》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

MD5 加密
MD5 加密

MD5 加密工具

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具