Harbor是一个开放源代码注册中心,它通过策略和基于角色的访问控制来保护工件,确保扫描图像并使其免受漏洞侵害,并将图像签名为受信任的。Harbor是CNCF毕业的项目,可提供合规性,性能和互操作性,以帮助您跨Kubernetes和Docker等云原生计算平台持续,安全地管理工件。
2、配置harbor https 相关证书openssl 生成
1、镜像下载:https://github.com/goharbor/harbor/releases
wget https://github.com/goharbor/harbor/releases/download/v2.0.2/harbor-offline-installer-v2.0.2.tgz
配置文档可以参考:https://goharbor.io/docs/2.0.0/install-config/
tar -zxvf harbor-offline-installer-v2.0.2.tgz
hostname: harbor #如果有域名,就写域名,没有域名就写IP,一定不要有大写字母,因为tag重命名或者bulid镜像不让用大写字母, 这就导致pull不了镜像。
certificate: /data/harbor/cert/ #证书地址
private_key: /ssl/private/key/path #证书地址
# port for http, default is 80. If https enabled, this port will redirect to https port
https: https:前面一定不要有空格,顶格写 ,一定一定注意,
# # https port for harbor, default is 443
# port: 443 https是需要ssl作为加密,所以443位ssl端口
# # The path of cert and key files for nginx
# certificate: /your/certificate/path
# private_key: /your/private/key/path
certificate: /your/certificate/path 证书地址
private_key: /your/private/key/path 证书地址
如果 http: 和https: 没有顶格写,结果是在你制作./install.sh hartbor后,发现 goharbor/nginx-photon:v1.9.3 中的PORTS没有端口映射,导致根本没有加载 http: 无法访问hartbor
二、配置harbor https 相关证书openssl 生成
配置ssl: https://goharbor.io/docs/2.0.0/install-config/configure-https/
openssl genrsa -out ca.key 4096
调整-subj选项中的值以反映您的组织。如果使用FQDN连接Harbor主机,则必须将其指定为通用名称(CN)属性。
- 官方文档:
- openssl req -x509 -new -nodes -sha512 -days 3650 \ 生成3650天
- -subj "/C=CN/ST=Beijing/L=Beijing/O=example/OU=Personal/CN=yourdomain.com" \
- -key ca.key \
- -out ca.crt
openssl genrsa -out yourdomain.com.key 4096
修改:把yourdomain.com 修改为harbor.yml 中hostname: harbor中的harbor。
openssl genrsa -out harbor.key 4096
调整-subj选项中的值以反映您的组织。如果使用FQDN连接Harbor主机,则必须将其指定为通用名称(CN)属性,并在密钥和CSR文件名中使用它。
- openssl req -sha512 -new \
- -subj "/C=CN/ST=Beijing/L=Beijing/O=example/OU=Personal/CN=yourdomain.com" \
- -key yourdomain.com.key \
- -out yourdomain.com.csr
修改:把yourdomain.com 修改为harbor.yml 中hostname: harbor中的harbor。
- openssl req -sha512 -new \
- -subj "/C=CN/ST=Beijing/L=Beijing/O=example/OU=Personal/CN=harbor" \
- -key harbor.key \
- -out harbor.csr
无论您使用FQDN还是IP地址连接到Harbor主机,都必须创建此文件,以便可以为您的Harbor主机生成符合主题备用名称(SAN)和x509 v3的证书扩展要求。替换DNS条目以反映您的域
- cat > v3.ext <<-EOF
- authorityKeyIdentifier=keyid,issuer
- basicConstraints=CA:FALSE
- keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
- extendedKeyUsage = serverAuth
- subjectAltName = @alt_names
- [alt_names]
- DNS.1=yourdomain.com
- DNS.2=yourdomain
- DNS.3=hostname
- EOF
- 修改:
- 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 修改为harbor.yml 中hostname: harbor中的harbor。也就是域名
- DNS.2=其他的域名
- DNS.3=hostname
- EOF
2.harbor.yml 中hostname: 192.168.1.10 添加的是IP
- 官方文档:
- cat > v3.ext <<-EOF
- authorityKeyIdentifier=keyid,issuer
- basicConstraints=CA:FALSE
- keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
- extendedKeyUsage = serverAuth
- subjectAltName = @alt_names
- EOF
- 修改:
- cat > v3.ext <<-EOF
- authorityKeyIdentifier=keyid,issuer
- basicConstraints=CA:FALSE
- keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
- extendedKeyUsage = serverAuth
- #subjectAltName = @alt_names
- subjectAltName = IP:192.168.1.10
- EOF
1.4、使用该v3.ext文件为您的Harbor主机生成证书
openssl x509 -req -sha512 -days 3650 \
> -CA ca.crt -CAkey ca.key -CAcreateserial \
1.1、生成后ca.crt,yourdomain.com.crt和yourdomain.com.key文件,必须将它们提供给港口和码头工人,和重新配置港使用它们
- 将服务器证书和密钥复制到Harbor主机上的certficates文件夹中。
- cp yourdomain.com.crt /data/cert/
- cp yourdomain.com.key /data/cert/
1.2、转换yourdomain.com.crt为yourdomain.com.cert,供Docker使用。
Docker守护程序将.crt文件解释为CA证书,并将.cert文件解释为客户端证书。
- 官方文档:
- openssl x509 -inform PEM -in yourdomain.com.crt -out yourdomain.com.cert
- 修改:
- openssl x509 -inform PEM -in harbor.crt -out harbor.cert
1.3、将服务器证书,密钥和CA文件复制到Harbor主机上的Docker证书文件夹中。您必须首先创建适当的文件夹。
如果将默认nginx端口443 映射到其他端口,请创建文件夹/etc/docker/certs.d/yourdomain.com:port或/etc/docker/certs.d/harbor_IP:port。
- 官方文档:
- cp yourdomain.com.cert /etc/docker/certs.d/yourdomain.com/
- cp yourdomain.com.key /etc/docker/certs.d/yourdomain.com/
- cp ca.crt /etc/docker/certs.d/yourdomain.com/
- 修改:
- mkdir -p /etc/docker/certs.d/harbor/
- cp harbor.cert /etc/docker/certs.d/harbor/
- cp harbor.key /etc/docker/certs.d/harbor/
- cp harbor.crt /etc/docker/certs.d/harbor/
官网说明:https://docs.docker.com/registry/storage-drivers/oss/
46 accesskeyid: 填写你的具有阿里云oss权限账户的RAM的AccessKey ID
47 accesskeysecret: 填写你的具有阿里云oss权限账户的RAM的AccessKey Secret
在主配置文件(harbor.yml)中打开"storage_service"的注释,然后加入以下内容:
endpoint: ops-docker.oss-cn-hangzhou.aliyuncs.com
Harbor将nginx实例用作所有服务的反向代理。您可以使用prepare脚本来配置nginx为使用HTTPS。该prepare在港的安装包,在同级别的install.sh脚本。
prepare base dir is set to /data/harbor/harbor
Unable to find image 'goharbor/prepare:v2.0.2' locally
v2.0.2: Pulling from goharbor/prepare
07cd1d2c25e7: Pulling fs layer
8619c71f6190: Pulling fs layer
383992c4c4a1: Pulling fs layer
prepare base dir is set to /data/harbor/harbor
Generated configuration file: /config/core/app.conf
Generated configuration file: /config/registry/config.yml
Generated configuration file: /config/registryctl/env
Generated configuration file: /config/db/env
Generated certificate, key file: /secret/core/private_key.pem, cert file: /secret/registry/root.crt
Generated configuration file: /compose_location/docker-compose.yml
✔ ----Harbor has been installed and started successfully.---- 代表成功
Now you should be able to visit the admin portal at https://jerry. 访问https://jerry.
For more details, please visit https://github.com/goharbor/harbor .
Docker-Compose是一个部署多个容器的简单但是非常必要的工具.
curl -L https://get.daocloud.io/docker/compose/releases/download/1.24.1/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
curl -L https://github.com/docker/compose/releases/download/1.24.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
docker-compose up -d 后台启动,如果容器不存在根据镜像自动创建
docker-compose down -v 停止容器并删除容器
docker-compose start 启动容器,不存在不启动,无法自动创建容器
docker-compose stop 查看日志,harbor 日志在/var/logs/harbor/
---------------------------------------------------------------------------------------------------------------
harbor-core /harbor/entrypoint.sh Restarting
harbor-db /docker-entrypoint.sh Up 5432/tcp
harbor-jobservice /harbor/entrypoint.sh Up
harbor-log /bin/sh -c /usr/local/bin/ ... Up 127.0.0.1:1514->10514/tcp
harbor-portal nginx -g daemon off; Up 8080/tcp
nginx nginx -g daemon off; Up 0.0.0.0:8088->8080/tcp, 0.0.0.0:443->8443/tcp
redis redis-server /etc/redis.conf Restarting
registry /home/harbor/entrypoint.sh Up 5000/tcp
registryctl /home/harbor/start.sh Up
上传一个镜像
$ docker tag nginx:v1 harbor/docker/nginx:v2
$ docker push nginx:v1 harbor/docker/nginx:v2
会在OSS的bucket里自动创建一个docker目录,用于存储镜像文件
- vim harbor.yml
- hostname: 192.168.1.10
- # 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: /data/cert/192.168.1.10.crt
- private_key: /data/cert/192.168.1.10.key
- 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=192.168.1.10" \
- -key ca.key \
- -out ca.crt
- openssl genrsa -out 192.168.1.10.key 4096
- openssl req -sha512 -new \
- -subj "/C=CN/ST=Beijing/L=Beijing/O=example/OU=Personal/CN=192.168.1.10" \
- -key 192.168.1.10.key \
- -out 192.168.1.10.csr
- cat > v3.ext <<-EOF
- authorityKeyIdentifier=keyid,issuer
- basicConstraints=CA:FALSE
- keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
- extendedKeyUsage = serverAuth
- subjectAltName = IP:192.168.1.10
- EOF
- openssl x509 -req -sha512 -days 3650 \
- -extfile v3.ext \
- -CA ca.crt -CAkey ca.key -CAcreateserial \
- -in 192.168.1.10.csr \
- -out 192.168.1.10.crt
- mkdir -p /data/cert/
- cp 192.168.1.10.crt /data/cert/
- cp 192.168.1.10.key /data/cert/
- openssl x509 -inform PEM -in 192.168.1.10.crt -out 192.168.1.10.cert
- mkdir -p /etc/docker/certs.d/192.168.1.10/
- cp 192.168.1.10.cert /etc/docker/certs.d/192.168.1.10/
- cp 192.168.1.10.key /etc/docker/certs.d/192.168.1.10/
- cp ca.crt /etc/docker/certs.d/192.168.1.10/