Harbor does not ship with any certificates. In versions up to and including 1.9.x, by default Harbor uses HTTP to serve registry requests. (可以理解在1.9版本后不再支持http,不对之处请斧正)
可以从官方发布页面下载Harbor安装程序 。下载联机安装程序或脱机安装程序。
在线安装程序:在线安装程序从Docker集线器下载Harbor映像。因此,安装程序的尺寸非常小。
脱机安装程序:如果要向其部署Harbor的主机没有与Internet的连接,请使用脱机安装程序。脱机安装程序包含预构建的映像,因此它比联机安装程序大。
tar xvf harbor-offline-installer-version.tgz
# vim /etc/hosts
192.168.0.1 harbor.cn
openssl genrsa -out ca.key 4096
openssl req -x509 -new -nodes -sha512 -days 3650
-subj “/C=CN/ST=Beijing/L=Beijing/O=example/OU=Personal/CN=harbor.cn”
-key ca.key
-out ca.crt
openssl genrsa -out harbor.cn.key 4096
openssl req -sha512 -new \
-subj "/C=CN/ST=Beijing/L=Beijing/O=example/OU=Personal/CN=harbor.cn" \
-key harbor.cn.key \
-out harbor.cn.csr
cat > v3.ext <<-EOF
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
extendedKeyUsage = serverAuth
subjectAltName = @alt_names
[alt_names]
DNS.1=harbor.cn
DNS.2=harbor
DNS.3=hostname
EOF
openssl x509 -req -sha512 -days 3650 \
-extfile v3.ext \
-CA ca.crt -CAkey ca.key -CAcreateserial \
-in harbor.cn.csr \
-out harbor.cn.crt
cp harbor.cn.crt /data/cert/
cp harbor.cn.key /data/cert/
openssl x509 -inform PEM -in harbor.cn.crt -out harbor.cn.cert
mkdir -p /etc/docker/certs.d/harbor.cn/
cp harbor.cn.cert /etc/docker/certs.d/harbor.cn/
cp harbor.cn.key /etc/docker/certs.d/harbor.cn/
cp ca.crt /etc/docker/certs.d/harbor.cn/
组织结构如下
systemctl restart docker
根据官方,练手写了个小脚本,脚本还有小漏洞,持续更新。
进入之前Harbor解压后的目录,运行
./prepare
这里将会验证环境,显示OK,进入下面步骤
浏览器,然后输入https://harbor.cn
确保可以正常访问
# vim /etc/docker/daemon.json
{
"bip": "199.2.1.1/24",
"registry-mirrors": ["https://wgaccbzr.mirror.aliyuncs.com"],
"insecure-registries": ["harbor.cn"],
"log-opts":{ "max-size" :"10m","max-file":"10"},
"fixed-cidr": "199.2.1.1/24",
"storage-driver": "overlay2",
"storage-opts": ["overlay2.override_kernel_check=true"]
}
docker login harbor.cn
如果能登陆成功,即可确认部署成功。