#冲刺创作新星# Install Harbor on Centos 原创

GabrielWu
发布于 2022-10-17 10:11
浏览
0收藏

Harbor install

Install Docker

curl https://download.docker.com/linux/centos/docker-ce.repo -o /etc/yum.repos.d/docker-ce.repo
yum install docker-ce -y
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://v27k018o.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

Install Composer

wget https://github.com/docker/compose/releases/download/1.29.2/docker-compose-Linux-x86_64 -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 --version

Download the Harbor installation package and unzip it to the specified directory

https://github.com/goharbor/harbor/releases

wget https://github.com/goharbor/harbor/releases/download/v2.3.0/harbor-offline-installer-v2.3.0.tgz
mkdir -p /data/app
tar -zxvf harbor-offline-installer-v2.3.0.tgz -C /data/app

Generate SSL Certificate

#CA

openssl genrsa -out ca.key 4096
openssl req -x509 -new -nodes -sha512 -days 3650 \
-subj "/C=CN/ST=Zhuhai/L=Zhuhai/O=BW/OU=BW/CN=sohopay.com" \
-key ca.key \
-out ca.crt

#domain cert

openssl genrsa -out harbor.sohopay.com.key 4096
openssl req -sha512 -new \
-subj "/C=CN/ST=Zhuhai/L=Zhuhai/O=BW/OU=BW/CN=harbor.sohopay.com" \
-key harbor.sohopay.com.key \
-out harbor.sohopay.com.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.sohopay.com
DNS.2=harbor.sohopay
DNS.3=harbor
EOF
openssl x509 -req -sha512 -days 3650 \
    -extfile v3.ext \
    -CA ca.crt -CAkey ca.key -CAcreateserial \
    -in harbor.sohopay.com.csr \
    -out harbor.sohopay.com.crt
    
openssl x509 -inform PEM -in harbor.sohopay.com.crt -out harbor.sohopay.com.cert

Copy the certificate to the specified directory

mkdir -p /data/cert
cp harbor.sohopay.com.crt /data/cert/
cp harbor.sohopay.com.key /data/cert/
mkdir -p /etc/docker/certs.d/harbor.sohopay.com/
cp harbor.sohopay.com.cert /etc/docker/certs.d/harbor.sohopay.com/
cp harbor.sohopay.com.key /etc/docker/certs.d/harbor.sohopay.com/
cp ca.crt /etc/docker/certs.d/harbor.sohopay.com/
systemctl restart docker

Modify the harbor config file

cp /data/app/harbor/harbor.yml.tmpl /data/app/harbor/harbor.yml

#vim /data/app/harbor/harbor.yml

hostname: harbor.sohopay.com
certificate: /data/cert/harbor.sohopay.com.crt
private_key: /data/cert/harbor.sohopay.com.key
harbor_admin_password: P@ssw0rd

Run preparation script

cd /data/app/harbor/
./prepare

Run the installation script

cd /data/app/harbor/
./install.sh

Verification

docker-compose ps

Browser login

https://harbor-ip
User name: admin Password: P@ssw0rd

docker cli login harbor

#Modify the startup parameters of ExecStart in /usr/lib/systemd/system/docker.service to increase:

  --insecure-registry  harbor.sohopay.com

Restart docker

systemctl daemon-reload && systemctl restart docker.service

Log in to harbor

docker login -u admin -p P@ssw0rd harbor.sohopay.com

Shutdown Harbor

cd /data/app/harbor
docker-compose down -v

Startup Harbor

cd /data/app/harbor
docker-compose up -d

Start on boot

cat > /etc/rc.d/init.d/harbor.sh << EOF
#!/bin/bash
# chkconfig: 2345 85 15
# description: docker-compose init start

/usr/local/bin/docker-compose -f /data/app/harbor/docker-compose.yml up -d
EOF
chmod +x /etc/rc.d/init.d/harbor.sh

Garbage Collection

cd /data/app/harbor
docker-compose stop
docker run -it --name gc --rm --volumes-from registry vmware/registry:2.6.2-photon garbage-collect --dry-run /etc/registry/config.yml
docker run -it --name gc --rm --volumes-from registry vmware/registry-photon:v2.6.2-v1.5.0 garbage-collect /etc/registry/config.yml
docker-compose start

Image Scanners

cd /data/app/harbor
./prepare --with-trivy
# restart harbor service
docker-compose -f docker-compose.yml up -d

©著作权归作者所有,如需转载,请注明出处,否则将追究法律责任
分类
1
收藏
回复
举报
回复
    相关推荐