1.Harbor简介Harbor是由VMWare公司开源的容器镜像仓库。事实上,Harbor是在Docker Registry上进行了相应的企业级扩展,从而获得了更加广泛的应用,这些新的企业级特性包括:管理用户界面,基于角色的访问控制,AD/LDAP集成以及审计日志等,足以满足基本企业需求。2.安装docker-ce1)安装依赖包[root@harbor opt]# yum install -y yum-utils device-mapper-persistent-data lvm22)下载docker-ce 仓库[root@harbor opt]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo官方比较慢的话,可以使用阿里云的docker-ce.repohttps://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo3)更新仓库yum repolist 或者 yum makecache fast4)安装docker-ce[root@harbor opt]# yum install docker-ce -y5)配置加速并启动[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 docker6) 确认安装完成 [root@harbor opt]# docker version3.安装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确认安装完成: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.cfghostname = reg.slito.com \harbor的服务地址(ip或者域名)ui_url_protocol = http \选择http方式 harbor_admin_password = 123456 \harbor web访问的密码[root@harbor harbor]# ./prepare \加载配置[root@harbor harbor]# ./install.sh \安装harbor安装完成后,提示通过“ http://reg.slito.com” 访问harbor,用户名是admin,密码是之前设置的1234565.上传镜像到harbor仓库在本机配置harbor仓库http可信/etc/docker/daemon.json中添加“"insecure-registries":["reg.slito.com"]”,重启docker不然会报错,默认是走https的在node1上登录harbor仓库,上传/下载镜像[root@node1 ~]# docker login reg.slito.comUsername: adminPassword: WARNING! Your password will be stored unencrypted in /root/.docker/config.json.Configure a credential helper to remove this warning. Seehttps://docs.docker.com/engine/reference/commandline/login/#credentials-store
[root@harbor opt]# yum install -y yum-utils device-mapper-persistent-data lvm2
[root@harbor opt]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum repolist 或者 yum makecache fast
[root@harbor opt]# yum install docker-ce -y
Login Succeeded[root@node1 ~]# docker tag busybox reg.slito.com/library/busybox:v1[root@node1 ~]# docker push reg.slito.com/library/busybox:v1The push refers to repository [reg.slito.com/library/busybox]8a788232037e: Pushed v1: digest: sha256:915f390a8912e16d4beb8689720a17348f3f6d1a7b659697df850ab625ea29d5 size: 527[root@node1 ~]# 在harbor中查看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 busyboxreg.slito.com/library/busybox v1 59788edf1f3e 8 weeks ago 1.15MB
7.配置https访问1) 安装openssl#yum install openssl -y2) 创建证书的database文件index.txt和序列文件serial [root@harbor opt]# touch /etc/pki/CA/index.txt[root@harbor opt]# echo "01" > /etc/pki/CA/serial
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.pem4) 客户端生成证书请求(.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生成时写的结果保持一致5) 签发证书(本机是CA同时又是申请证书的客户端)#cd /opt/harbor/ssl#openssl ca -in reg.slito.com.csr -out reg.slito.com.crt -days 3656) 修改配置文件,重新启动harbor#cd /opt/harbor#docker-compose down -v#vim harbor.cfgui_url_protocol = httpsssl_cert = ./ssl/reg.slito.com.crtssl_cert_key = ./ssl/cert/reg.slito.com.keysecretkey_path = ./ssl/#./prepare#./install.sh访问“https://reg.slito.com”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/
其他:关于https访问,可以看另一篇博客https://blog.51cto.com/slitobo/1931603