harbor安装和使用

前言

  • 事先安装docker和docker composer
  • 下载tar包并解压:https://github.com/goharbor/harbor/releases
  • 修改配置harbor.yaml中的hostname,如:harbor.cn(记得添加本地host指向:192.168.xx.xxx harbor.cn)
  • 生产自签证书,配置https
  1. Step1 - 生成根证书私钥(无加密):
  2. Step2 -生成自签名证书(使用已有私钥ca.key自行签发根证书)生成ca.crt:
    1
    2
    3
    4
    openssl req -x509 -new -nodes -sha512 -days 3650 \
    -subj "/C=CN/ST=Beijing/L=Beijing/O=ccx/OU=plat/CN=192.168.100.110" \
    -key ca.key \
    -out ca.crt
  3. 生成服务器端自己域名的key:
    1
    openssl genrsa -out harbor.cn.key 4096
  4. 生成服务器端自己域名的CSR签名请求:
    1
    2
    3
    4
    openssl req -sha512 -new \
    -subj "/C=CN/ST=Beijing/L=Beijing/O=ccx/OU=plat/CN=192.168.100.242" \
    -key harbor.cn.key \
    -out harbor.cn.csr
  5. 生成一个 openssl 命令需要的外部配置文件 externalfile.ext。
    这个文件可以随意命名,但是要记住,后面对的命令还要用到。、
    文件内容中主要是subjectAltName这一项
    如果配IP就写IP.1=192.168.xxx.xxx
    如果配域名就写 DNS.1=xxx.xxx.cn
    1
    2
    3
    4
    5
    6
    7
    8
    9
    cat > vim externalfile.ext <<-EOF
    authorityKeyIdentifier=keyid,issuer
    basicConstraints=CA:FALSE
    keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
    extendedKeyUsage = serverAuth
    subjectAltName = @alt_names
    [alt_names]
    DNS.1=harbor.cn
    EOF
  6. 通过外部配置文件 externalfile.ext和 csr 生成 crt:
    1
    2
    3
    4
    5
    6
    openssl x509 -req -sha512 -days 3650 -extfile externalfile.ext \
    -CA ca.crt \
    -CAkey ca.key \
    -CAcreateserial \
    -in harbor.cn.csr \
    -out harbor.cn.crt
  7. 将服务端的 crt 转换成客户端用的 cert:
    1
    openssl x509 -inform PEM -in harbor.cn.crt -out harbor.cn.cert
    至此,所有证书文件就创建好了:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    [root@dev cert_harbor]# ll
    total 32
    -rw-r--r-- 1 root root 2017 Feb 23 13:44 ca.crt
    -rw-r--r-- 1 root root 3243 Feb 23 13:42 ca.key
    -rw-r--r-- 1 root root 17 Feb 23 13:53 ca.srl
    -rw-r--r-- 1 root root 232 Feb 23 13:52 externalfile.ext
    -rw-r--r-- 1 root root 2049 Feb 23 13:54 harbor.cn.cert
    -rw-r--r-- 1 root root 2049 Feb 23 13:53 harbor.cn.crt
    -rw-r--r-- 1 root root 1700 Feb 23 13:49 harbor.cn.csr
    -rw-r--r-- 1 root root 3247 Feb 23 13:47 harbor.cn.key
  • 为各个docker客户端分发证书
  1. 在Docker主机上执行:
    1
    mkdir -p /etc/docker/certs.d/harbor.cn/
  2. 在Harbor主机,执行:
    1
    scp ./harbor.cn.cert ./harbor.cn.key vagrant@192.168.xxx.xxx:/etc/docker/certs.d/harbor.cn/
  3. 在Docker主机修改 /etc/docker/daemon.json,主要是增加”insecure-registries”:[“http://harbor.cn"]
    1
    2
    3
    4
    5
    6
    vim /etc/docker/daemon.json
    {
    "insecure-registries":["http://harbor.cn"],
    }
    systemctl daemon-reload
    systemctl resatrt docker
打赏
  • 版权声明: 本博客所有文章除特别声明外,均采用 Apache License 2.0 许可协议。转载请注明出处!
  • © 2015-2020 谭家俊
  • Powered by Hexo Theme Ayer
  • PV: UV:

请我喝杯咖啡吧~

微信