企业级镜像仓库harbor搭建(http/https)及使用-创新互联

1.Harbor简介
Harbor是由VMWare公司开源的容器镜像仓库。事实上,Harbor是在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 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

创新互联建站是创新、创意、研发型一体的综合型网站建设公司,自成立以来公司不断探索创新,始终坚持为客户提供满意周到的服务,在本地打下了良好的口碑,在过去的十多年时间我们累计服务了上千家以及全国政企客户,如成都LED显示屏等企业单位,完善的项目管理流程,严格把控项目进度与质量监控加上过硬的技术实力获得客户的一致赞美。

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访问,可以看另一篇博客https://blog.51cto.com/slitobo/1931603

另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


分享文章:企业级镜像仓库harbor搭建(http/https)及使用-创新互联
转载源于:http://myzitong.com/article/dgejsc.html