安装docker compose
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum -y install docker-compose
docker-compose version
生成自建CA证书
生成CA私钥:
openssl genrsa -out /path/ca/ca.key 4096
生成ca的自签名证书:
openssl req -x509 -new -nodes -sha512 -days 3650 \
-subj "/C=CN/ST=Beijing/L=Beijing/O=example/OU=Personal/CN=ljbb.com" \
-key /path/ca/ca.key \
-out /path/ca/ca.crt
ls -al :
ca.key
ca.crt
生成harbor服务器的证书文件
生成harbor主机的私钥:
openssl genrsa -out /path/server/harbor.ljbb.com.key 4096
生成harbor主机的证书:
openssl req -sha512 -new \
-subj "/C=CN/ST=Beijing/L=Beijing/O=example/OU=Personal/CN=harbor.ljbb.com" \
-key /path/server/harbor.ljbb.com.key \
-out /path/server/harbor.ljbb.com.csr
生成x509 v3扩展文件
cat > v3.ext <<-EOF
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
extendedKeyUsage = serverAuth
subjectAltName = @alt_names
[alt_names]
DNS.1=ljbb.com
EOF
使用"v3.ext"给harbor主机签发证书
openssl x509 -req -sha512 -days 3650 \
-extfile v3.ext \
-CA ca/ca.crt -CAkey /path/ca/ca.key -CAcreateserial \
-in /pathserver/harbor.ljbb.com.csr \
-out /pathserver/harbor.ljbb.com.crt
将crt文件转换为cert客户端证书文件
openssl x509 -inform PEM -in /path/server/harbor.ljbb.com.crt -out server/harbor.oldboyedu.com.cert
准备docker客户端证书
cp /path/server/harbor.ljbb.com.{cert,key} /path/client/
cp /path/ca/ca.crt /path/client/
# 查看客户端证书
ll client/
-rw-r--r-- 1 root root 2033 Apr 12 10:09 ca.crt
-rw-r--r-- 1 root root 2122 Apr 12 10:09 harbor.ljbb.com.cert
-rw-r--r-- 1 root root 3247 Apr 12 10:09 harbor.ljbb.com.key
安装harbor
修改配置文件
echo alias yy=\'egrep -v \"\^.*#\|\^\$\"\' >> /root/.bashrc
source /root/.bashrc
pwd
/ljbb/soft/harbor
yy harbor.yml
# 修改如下内容
hostname: harbor.ljbb.com
https:
port: 443
certificate: /path/server/harbor.ljbb.com.crt
private_key: /path/server/harbor.ljbb.com.key
harbor_admin_password: 1
安装harbor服务
./install.sh
浏览器访问
浏览器访问:
harbor.ljbb.com
客户端访问
mkdir -p /etc/docker/certs.d/harbor.ljbb.com
ll /etc/docker/certs.d/harbor.ljbb.com
/path/client/ca.crt
/path/client/harbor.ljbb.com.cert
/path/client/harbor.ljbb.com.key
docker login -u admin -p 1 harbor.ljbb.com