https://github.com/goharbor/harbor
https://github.com/goharbor/harbor/blob/master/docs/user_guide.md
简单的说,Harbor 是一个企业级的 Docker Registry,可以实现 images 的私有存储和日志统计权限控制等功能,并支持创建多项目(Harbor 提出的概念),基于官方 Registry V2 实现。
Harbor提供的特性
基于角色控制 用户和仓库都是基于项目进行组织的, 而用户基于项目可以拥有不同的权限。
基于镜像的复制策略 镜像可以在多个Harbor实例之间进行复制。
支持LDAP Harbor的用户授权可以使用已经存在LDAP用户。
镜像删除 & 垃圾回收 Image可以被删除并且回收Image占用的空间。
友好UI 用户可以轻松的浏览、搜索镜像仓库以及对项目进行管理。
便于扩展 绝大部分的用户操作API, 方便用户对系统进行扩展。
轻松部署 Harbor提供了online、offline安装,除此之外还提供了virtualappliance安装。
1.环境
2.安装harbor 2.1 下载安装包 1 2 3 4 5 6 7 8 9 # 创建工作目录 mkdir ~/harbor cd ~/harbor # 离线安装方式 # wget https://github.com/goharbor/harbor/releases/download/v2.2.2/harbor-offline-installer-v2.2.2.tgz wget https://hub.fastgit.org/goharbor/harbor/releases/download/v2.2.2/harbor-offline-installer-v2.2.2.tgz tar harbor-offline-installer-v2.2.2.tgz cd harbor
2.2 修改配置文件 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 cp harbor.yml.tmpl harbor.yml vi harbor.yml hostname: 192.168.1.109 #修改 # http related config http: # port for http, default is 80. If https enabled, this port will redirect to https port port: 8800 #注释 # https related config # https: # https port for harbor, default is 443 # port: 443 # The path of cert and key files for nginx # certificate: /your/certificate/path # private_key: /your/private/key/path # 执行prepare,根据harbor.yml生成配置文件 sudo ./prepare sudo ./install.sh
浏览器访问192.168.1.109:8800
账号:admin 密码:Harbor12345
编辑 /etc/docker/daemon.json
1 2 3 4 { "insecure-registries" : [ "192.168.1.109:8800" ] , "registry-mirrors" : [ "https://c8x7u9xt.mirror.aliyuncs.com" ] }
重启docker:systemctl restart docker
2.3 支持SSL 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 vi harbor.yml hostname: 192.168.1.109 #修改 # http related config http: # port for http, default is 80. If https enabled, this port will redirect to https port port: 80 # https related config https: # https port for harbor, default is 443 port: 443 # The path of cert and key files for nginx certificate: /your/certificate/path #指定证书 private_key: /your/private/key/path #指定证书 sudo ./prepare sudo ./install.sh
制作证书脚本
https://github.com/goharbor/harbor/blob/master/docs/configure_https.md
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 # !/bin/bash openssl rand -writerand /root/.rnd cert_path=/var/harbor/cert cert_name=harbor server_ip=192.168.1.109 rm -rf $cert_path/* mkdir -p $cert_path cd $cert_path # 生成CA的key sudo openssl genrsa -out ca.key 4096 # 生成CA的crt sudo openssl req -x509 -new -nodes -sha512 -days 3650 \ -subj "/C=CN/ST=FuJian/L=FuZhou/O=test/OU=test/CN=$server_ip" \ -key ca.key \ -out ca.crt # 生成自己域名的key sudo openssl genrsa -out $cert_name.key 4096 # 生成自己域名的csr sudo openssl req -sha512 -new \ -subj "/C=CN/ST=FuJian/L=FuZhou/O=test/OU=test/CN=$server_ip" \ -key $cert_name.key \ -out $cert_name.csr # 生成一个openssl命令需要的外部配置文件 # 主要是subjectAltName,这里写的IP.1=yourip还可以写DNS.1=yourdomainname sudo cat > v3.ext <<-EOF authorityKeyIdentifier=keyid,issuer basicConstraints=CA:FALSE keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment extendedKeyUsage = serverAuth subjectAltName = @alt_names [alt_names] IP=$server_ip EOF # 通过之前准备好的v3.ext和csr生成crt sudo openssl x509 -req -sha512 -days 3650 \ -extfile v3.ext \ -CA ca.crt -CAkey ca.key -CAcreateserial \ -in $cert_name.csr \ -out $cert_name.crt # 将服务端的crt转换成客户端用的cert sudo openssl x509 -inform PEM -in $cert_name.crt -out $cert_name.cert # cp 172.19.0.1.crt /harbor/cert/# cp 172.19.0.1.key /harbor/cert/# 下面在docker client端进行测试 # 将域名的cert,key和ca.crt拷贝到docker client所在主机的 # /etc/docker/certs.d/172.19.0.1/目录 sudo mkdir -p /etc/docker/certs.d/$server_ip/ sudo cp ca.crt /etc/docker/certs.d/$server_ip/ sudo cp $cert_name.key /etc/docker/certs.d/$server_ip/ sudo cp $cert_name.cert /etc/docker/certs.d/$server_ip/ # centos7,手动进行进行证书信任 # sudo cp $cert_name .crt /etc/pki/ca-trust/source/anchors/$cert_name .crt # sudo update-ca-trust # ubuntu rm -rf /usr/local/share/ca-certificates/$cert_name.crt sudo cp $cert_name.crt /usr/local/share/ca-certificates/$cert_name.crt sudo update-ca-certificates
登录测试
1 2 3 4 sudo docker login 192.168.1.109:8800 Username: admin Password: Harbor12345 Login Succeeded
push镜像测试
1 2 3 4 # 先在harbor上创建项目test ,否则会报错 # denied: requested access to the resource is denied sudo docker tag nginx 192.168.1.109/test/nginx:test sudo docker push 192.168.1.109/test/nginx:test
3.Harbor操作 1 2 3 4 5 6 7 8 # 停止 sudo docker-compose stop # 启动 sudo docker-compose start # 删除容器,利用./install.sh可以重新安装 sudo docker-compose down # 删除数据卷 sudo rm -rf /harbor