1.安装指导
下载地址:Releases · goharbor/harbor · GitHub
此次下载的是v2.12.0(浏览器下载或者wget)
[root@ubuntu2204 ~]wget https://github.com/goharbor/harbor/releases/download/v2.12.0/harbor-offline-installer-v2.12.0.tgz
安装文档:Harbor docs | Download the Harbor Installer
环境要求:Harbor docs | Harbor Installation Prerequisites (goharbor.io)
注意:Next step 如果配置加密,选择https,否则选第二条http
http
官方提供了脚本
2.准备工作及harbor安装
安装docker-compose(会附带安装docker)
[root@ubuntu2204 ~]#apt update && apt install -y docker-compose
将官方离线安装包下载
[root@ubuntu2204 ~]#rz -E rz waiting to receive. [root@ubuntu2204 ~]#ls harbor-offline-installer-v2.12.0.tgz snap
创建卷组(可选)
[root@ubuntu2204 ~]#lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert ubuntu-lv ubuntu-vg -wi-ao---- <99.00g [root@ubuntu2204 ~]#vgs VG #PV #LV #SN Attr VSize VFree ubuntu-vg 1 1 0 wz--n- <198.00g 99.00g [root@ubuntu2204 ~]#lvcreate -n harbor-lv -l 100%free ubuntu-vg Logical volume "harbor-lv" created. [root@ubuntu2204 ~]#lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert harbor-lv ubuntu-vg -wi-a----- 99.00g ubuntu-lv ubuntu-vg -wi-ao---- <99.00g
挂载(可选)
[root@ubuntu2204 ~]#mkdir /data/harbor -p [root@ubuntu2204 ~]#mkfs.ext4 /dev/ubuntu-vg/harbor-lv mke2fs 1.46.5 (30-Dec-2021) 创建含有 25952256 个块(每块 4k)和 6488064 个 inode 的文件系统 文件系统 UUID:57fc5bec-dfd9-4c6b-b9ae-a8685d3ecc60 超级块的备份存储于下列块: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624, 11239424, 20480000, 23887872 正在分配组表: 完成 正在写入 inode表: 完成 创建日志(131072 个块): 完成 写入超级块和文件系统账户统计信息: 已完成 [root@ubuntu2204 ~]#blkid /dev/mapper/ubuntu--vg-ubuntu--lv: UUID="8ff51380-f669-4ec7-9344-435cc629f026" BLOCK_SIZE="4096" TYPE="ext4" /dev/sda2: UUID="f81cc5f3-9189-4a0c-b53a-f67110325cc7" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="3b07f660-02d5-4564-ace5-88dfb42355f6" /dev/sda3: UUID="tdjiqK-EK47-vWMt-8sMA-wIvP-B0Fc-rGXGe1" TYPE="LVM2_member" PARTUUID="73f41d5d-e069-4c48-9ee3-8b258466bbbf" /dev/mapper/ubuntu--vg-harbor--lv: UUID="57fc5bec-dfd9-4c6b-b9ae-a8685d3ecc60" BLOCK_SIZE="4096" TYPE="ext4" /dev/sda1: PARTUUID="3747d8f2-bf73-4d32-9007-983bb39d9867" [root@ubuntu2204 ~]#vim /etc/fstab # /etc/fstab: static file system information. # # Use 'blkid' to print the universally unique identifier for a # device; this may be used with UUID= as a more robust way to name devices # that works even if disks are added and removed. See fstab(5). # # <file system> <mount point> <type> <options> <dump> <pass> # / was on /dev/ubuntu-vg/ubuntu-lv during curtin installation /dev/disk/by-id/dm-uuid-LVM-aL2z4qRF6RP6ygmuXVQ89hX7MrChz0jPApnaIZ1WSFWWkEAhejDEX9zi7SrwDOep / ext4 defaults 0 1 # /boot was on /dev/sda2 during curtin installation /dev/disk/by-uuid/f81cc5f3-9189-4a0c-b53a-f67110325cc7 /boot ext4 defaults 0 1 /swap.img none swap sw 0 0 /dev/mapper/ubuntu--vg-harbor--lv /data/harbor ext4 defaults 0 0 [root@ubuntu2204 ~]#mount -a [root@ubuntu2204 ~]#df -h 文件系统 大小 已用 可用 已用% 挂载点 tmpfs 389M 1.6M 388M 1% /run /dev/mapper/ubuntu--vg-ubuntu--lv 97G 6.6G 86G 8% / tmpfs 1.9G 0 1.9G 0% /dev/shm tmpfs 5.0M 0 5.0M 0% /run/lock /dev/sda2 2.0G 127M 1.7G 7% /boot tmpfs 389M 0 389M 0% /run/user/0 /dev/mapper/ubuntu--vg-harbor--lv 97G 24K 92G 1% /data/harbor [root@ubuntu2204 ~]#ls /data/harbor/ lost+found
以上两步,创建卷组和挂载不做也可,基于未来扩容方便,才使用的逻辑卷;不做这两步,/data/harbor会自动生成。
解压
[root@ubuntu2204 ~]#tar xvf harbor-offline-installer-v2.12.0.tgz -C /usr/local harbor/harbor.v2.12.0.tar.gz harbor/prepare harbor/LICENSE harbor/install.sh harbor/common.sh harbor/harbor.yml.tmpl [root@ubuntu2204 ~]#cd /usr/local/ [root@ubuntu2204 local]#ls bin etc games harbor include lib man sbin share src [root@ubuntu2204 local]#cd harbor/ [root@ubuntu2204 harbor]#ls common.sh harbor.v2.12.0.tar.gz harbor.yml.tmpl install.sh LICENSE prepare [root@ubuntu2204 harbor]#cp harbor.yml.tmpl harbor.yml
修改配置文件
[root@ubuntu2204 harbor]#vim harbor.yml ........ #hostname: reg.mydomain.com #harbor要访问的域名 hostname: 10.0.0.101 ........ # https related config #禁用https #https: # https port for harbor, default is 443 # port: 443 # The path of cert and key files for nginx #certificate: /your/certificate/path #private_key: /your/private/key/path # enable strong ssl ciphers (default: false) # strong_ssl_ciphers: false ........ #harbor_admin_password: Harbor12345 harbor_admin_password: 123456
执行脚本
[root@ubuntu2204 harbor]#./install.sh [Step 0]: checking if docker is installed ... Note: docker version: 24.0.7 [Step 1]: checking docker-compose is installed ... Note: docker-compose version: 1.29.2 [Step 2]: loading Harbor images ... 910db7c25623: Loading layer [==================================================>] 40.51MB/40.51MB c8cd0a1f5b0b: Loading layer [==================================================>] 107.6MB/107.6MB 15d8ff051c07: Loading layer [==================================================>] 46.48MB/46.48MB d197fd97c185: Loading layer [==================================================>] 13.77MB/13.77MB d88ec2163d81: Loading layer [==================================================>] 66.05kB/66.05kB e63d6d00357d: Loading layer [==================================================>] 2.56kB/2.56kB b802bc40d720: Loading layer [==================================================>] 1.536kB/1.536kB 8225980335b5: Loading layer [==================================================>] 12.29kB/12.29kB 3175598f5b32: Loading layer [==================================================>] 2.746MB/2.746MB ef05ddf12dfe: Loading layer [==================================================>] 525.3kB/525.3kB Loaded image: goharbor/prepare:v2.12.0 32cd15a4ebdd: Loading layer [==================================================>] 16.27MB/16.27MB 0dd22cb0da1b: Loading layer [==================================================>] 190.2MB/190.2MB ac30f78bb9c1: Loading layer [==================================================>] 26.08MB/26.08MB 527459edc5ee: Loading layer [==================================================>] 18.6MB/18.6MB 0fe3e34fe571: Loading layer [==================================================>] 5.12kB/5.12kB eb0883932a36: Loading layer [==================================================>] 6.144kB/6.144kB 49b31970580b: Loading layer [==================================================>] 3.072kB/3.072kB 478aa400459f: Loading layer [==================================================>] 2.048kB/2.048kB c39207896960: Loading layer [==================================================>] 2.56kB/2.56kB e3a89007fad0: Loading layer [==================================================>] 7.68kB/7.68kB Loaded image: goharbor/harbor-db:v2.12.0 eb105901976e: Loading layer [==================================================>] 11.57MB/11.57MB 4c386227a4e4: Loading layer [==================================================>] 3.584kB/3.584kB 4f442ab7cc4c: Loading layer [==================================================>] 2.56kB/2.56kB 2fa6704b1ae6: Loading layer [==================================================>] 59.63MB/59.63MB 65c014dfa82d: Loading layer [==================================================>] 60.42MB/60.42MB Loaded image: goharbor/harbor-jobservice:v2.12.0 4cab912836a2: Loading layer [==================================================>] 8.614MB/8.614MB 247df5f5c893: Loading layer [==================================================>] 4.096kB/4.096kB 9ee7df405168: Loading layer [==================================================>] 18.13MB/18.13MB d628a65e4634: Loading layer [==================================================>] 3.072kB/3.072kB 1759c807e026: Loading layer [==================================================>] 36.96MB/36.96MB bee402e81ccd: Loading layer [==================================================>] 55.88MB/55.88MB Loaded image: goharbor/harbor-registryctl:v2.12.0 afc604caf53d: Loading layer [==================================================>] 11.57MB/11.57MB f9eb13f95461: Loading layer [==================================================>] 37.01MB/37.01MB e98d25e4c661: Loading layer [==================================================>] 4.608kB/4.608kB 8dd3c4f177e1: Loading layer [==================================================>] 37.8MB/37.8MB Loaded image: goharbor/harbor-exporter:v2.12.0 31e9c30e4a21: Loading layer [==================================================>] 16.27MB/16.27MB bfcf2dfddce8: Loading layer [==================================================>] 125.1MB/125.1MB 1660b90f9dc7: Loading layer [==================================================>] 3.072kB/3.072kB 93c9be43608f: Loading layer [==================================================>] 59.9kB/59.9kB d69d92256927: Loading layer [==================================================>] 61.95kB/61.95kB Loaded image: goharbor/redis-photon:v2.12.0 769c4aa8c0a4: Loading layer [==================================================>] 8.614MB/8.614MB 9cd556727275: Loading layer [==================================================>] 4.096kB/4.096kB 0edc0bc0fa32: Loading layer [==================================================>] 3.072kB/3.072kB 30823cd3e953: Loading layer [==================================================>] 18.13MB/18.13MB 31ffd46d4827: Loading layer [==================================================>] 18.92MB/18.92MB Loaded image: goharbor/registry-photon:v2.12.0 8f8c2600e204: Loading layer [==================================================>] 130.1MB/130.1MB 676f1d057a8c: Loading layer [==================================================>] 6.731MB/6.731MB 71425f9960bc: Loading layer [==================================================>] 252.9kB/252.9kB 8ce274b4eb81: Loading layer [==================================================>] 1.497MB/1.497MB Loaded image: goharbor/harbor-portal:v2.12.0 4ed6c9567d72: Loading layer [==================================================>] 11.57MB/11.57MB 68c5cae40c58: Loading layer [==================================================>] 3.584kB/3.584kB a29956692eb6: Loading layer [==================================================>] 2.56kB/2.56kB d4eac84f665a: Loading layer [==================================================>] 70.77MB/70.77MB c2d39ec31cb3: Loading layer [==================================================>] 5.632kB/5.632kB 81df0033286e: Loading layer [==================================================>] 126.5kB/126.5kB 847040daf450: Loading layer [==================================================>] 201.7kB/201.7kB cba56604cbfc: Loading layer [==================================================>] 71.89MB/71.89MB 6d8fda582e88: Loading layer [==================================================>] 2.56kB/2.56kB Loaded image: goharbor/harbor-core:v2.12.0 8dd98fe70bfa: Loading layer [==================================================>] 139.8MB/139.8MB c0691b0983da: Loading layer [==================================================>] 3.584kB/3.584kB a205646db971: Loading layer [==================================================>] 3.072kB/3.072kB 36bea9385de7: Loading layer [==================================================>] 2.56kB/2.56kB 624bbccc716a: Loading layer [==================================================>] 3.072kB/3.072kB cee989d2b0b0: Loading layer [==================================================>] 3.584kB/3.584kB 73035228c2e1: Loading layer [==================================================>] 20.48kB/20.48kB Loaded image: goharbor/harbor-log:v2.12.0 d397faf073f1: Loading layer [==================================================>] 130.1MB/130.1MB Loaded image: goharbor/nginx-photon:v2.12.0 3e1f1096c4bf: Loading layer [==================================================>] 9.106MB/9.106MB 9cc192b1539e: Loading layer [==================================================>] 4.096kB/4.096kB a4448f8ca935: Loading layer [==================================================>] 3.072kB/3.072kB 38c665e4daa5: Loading layer [==================================================>] 133.8MB/133.8MB 867c3a3ec63e: Loading layer [==================================================>] 15.55MB/15.55MB e04b98ae7085: Loading layer [==================================================>] 150.1MB/150.1MB Loaded image: goharbor/trivy-adapter-photon:v2.12.0 [Step 3]: preparing environment ... [Step 4]: preparing harbor configs ... prepare base dir is set to /usr/local/harbor WARNING:root:WARNING: HTTP protocol is insecure. Harbor will deprecate http protocol in the future. Please make sure to upgrade to https Generated configuration file: /config/portal/nginx.conf Generated configuration file: /config/log/logrotate.conf Generated configuration file: /config/log/rsyslog_docker.conf Generated configuration file: /config/nginx/nginx.conf Generated configuration file: /config/core/env Generated configuration file: /config/core/app.conf Generated configuration file: /config/registry/config.yml Generated configuration file: /config/registryctl/env Generated configuration file: /config/registryctl/config.yml Generated configuration file: /config/db/env Generated configuration file: /config/jobservice/env Generated configuration file: /config/jobservice/config.yml Generated and saved secret to file: /data/secret/keys/secretkey Successfully called func: create_root_cert Generated configuration file: /compose_location/docker-compose.yml Clean up the input dir Note: stopping existing Harbor instance ... Removing network harbor_harbor WARNING: Network harbor_harbor not found. [Step 5]: starting Harbor ... Creating network "harbor_harbor" with the default driver Creating harbor-log ... done Creating registryctl ... done Creating registry ... done Creating redis ... done Creating harbor-db ... done Creating harbor-portal ... done Creating harbor-core ... done Creating nginx ... done Creating harbor-jobservice ... done ✔ ----Harbor has been installed and started successfully.----
生成docker-compose.yml文件
[root@ubuntu2204 harbor]#ls common common.sh docker-compose.yml harbor.v2.12.0.tar.gz harbor.yml harbor.yml.tmpl install.sh LICENSE prepare
仓库服务已经启动
[root@ubuntu2204 harbor]#docker-compose ps Name Command State Ports -------------------------------------------------------------------------------------------------------- harbor-core /harbor/entrypoint.sh Up (healthy) harbor-db /docker-entrypoint.sh 14 15 Up (healthy) harbor-jobservice /harbor/entrypoint.sh Up (healthy) harbor-log /bin/sh -c /usr/local/bin/ ... Up (healthy) 127.0.0.1:1514->10514/tcp harbor-portal nginx -g daemon off; Up (healthy) nginx nginx -g daemon off; Up (healthy) 0.0.0.0:80->8080/tcp,:::80->8080/tcp redis redis-server /etc/redis.conf Up (healthy) registry /home/harbor/entrypoint.sh Up (healthy) registryctl /home/harbor/start.sh Up (healthy)
浏览器登录(admin 123456)
3.脚本安装
#!/bin/bash # #******************************************************************** #FileName: install_harbor.sh #******************************************************************** #建议提前下载Harbor文件进行离线安装,也支持在线下载安装 #docker和docker-compose无需下载,在线安装即可 HARBOR_VERSION=2.12.0 #HARBOR_VERSION=2.11.1 #HARBOR_VERSION=2.11.0 #HARBOR_VERSION=2.10.2 #HARBOR_VERSION=2.9.1 #HARBOR_VERSION=2.9.0 #HARBOR_VERSION=2.8.2 #HARBOR_VERSION=2.7.1 #HARBOR_VERSION=2.7.0 #HARBOR_VERSION=2.6.1 #HARBOR_VERSION=2.6.0 GITHUB_PROXY=https://mirror.ghproxy.com/ HARBOR_BASE=/usr/local #HARBOR_NAME=harbor.wang.org HARBOR_NAME=`hostname -I|awk '{print $1}'` #HARBOR_NAME=10.0.0.200 DOCKER_VERSION="26.1.3" #DOCKER_VERSION="24.0.0" #DOCKER_VERSION="20.10.20" #DOCKER_VERSION="19.03.14" DOCKER_URL="http://mirrors.ustc.edu.cn" #DOCKER_URL="https://mirrors.tuna.tsinghua.edu.cn" DOCKER_COMPOSE_VERSION=2.27.1 #DOCKER_COMPOSE_VERSION=2.18.1 #DOCKER_COMPOSE_VERSION=2.6.1 #DOCKER_COMPOSE_VERSION=1.29.2 DOCKER_COMPOSE_FILE=docker-compose-linux-x86_64 HARBOR_ADMIN_PASSWORD=123456 HARBOR_IP=`hostname -I|awk '{print $1}'` COLOR_SUCCESS="echo -e \\033[1;32m" COLOR_FAILURE="echo -e \\033[1;31m" END="\033[m" . /etc/os-release UBUNTU_DOCKER_VERSION="5:${DOCKER_VERSION}~3-0~${ID}-${UBUNTU_CODENAME}" color () { RES_COL=60 MOVE_TO_COL="echo -en \\033[${RES_COL}G" SETCOLOR_SUCCESS="echo -en \\033[1;32m" SETCOLOR_FAILURE="echo -en \\033[1;31m" SETCOLOR_WARNING="echo -en \\033[1;33m" SETCOLOR_NORMAL="echo -en \E[0m" echo -n "$1" && $MOVE_TO_COL echo -n "[" if [ $2 = "success" -o $2 = "0" ] ;then ${SETCOLOR_SUCCESS} echo -n $" OK " elif [ $2 = "failure" -o $2 = "1" ] ;then ${SETCOLOR_FAILURE} echo -n $"FAILED" else ${SETCOLOR_WARNING} echo -n $"WARNING" fi ${SETCOLOR_NORMAL} echo -n "]" echo } install_docker(){ if [ $ID = "centos" -o $ID = "rocky" ];then if [ $VERSION_ID = "7" ];then cat > /etc/yum.repos.d/docker.repo <<EOF [docker] name=docker gpgcheck=0 #baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/x86_64/stable/ baseurl=${DOCKER_URL}/docker-ce/linux/centos/7/x86_64/stable/ EOF else cat > /etc/yum.repos.d/docker.repo <<EOF [docker] name=docker gpgcheck=0 #baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/8/x86_64/stable/ baseurl=${DOCKER_URL}/docker-ce/linux/centos/8/x86_64/stable/ EOF fi yum clean all ${COLOR_FAILURE} "Docker有以下版本"${END} yum list docker-ce --showduplicates ${COLOR_FAILURE}"5秒后即将安装: docker-"${DOCKER_VERSION}" 版本....."${END} ${COLOR_FAILURE}"如果想安装其它Docker版本,请按ctrl+c键退出,修改版本再执行"${END} sleep 5 yum -y install docker-ce-$DOCKER_VERSION docker-ce-cli-$DOCKER_VERSION \ || { color "Base,Extras的yum源失败,请检查yum源配置" 1;exit; } else dpkg -s docker-ce &> /dev/null && $COLOR"Docker已安装,退出" 1 && exit apt update || { color "更新包索引失败" 1 ; exit 1; } apt -y install docker.io fi if [ $? -eq 0 ];then color "安装软件包成功" 0 else color "安装软件包失败,请检查网络配置" 1 exit fi mkdir -p /etc/docker tee /etc/docker/daemon.json <<-'EOF' { "registry-mirrors": ["https://si7y70hh.mirror.aliyuncs.com"], "insecure-registries": ["harbor.wang.org"] } EOF systemctl daemon-reload systemctl enable docker systemctl restart docker docker version && color "Docker 安装成功" 0 || color "Docker 安装失败" 1 echo 'alias rmi="docker images -qa|xargs docker rmi -f"' >> ~/.bashrc echo 'alias rmc="docker ps -qa|xargs docker rm -f"' >> ~/.bashrc } install_docker_compose(){ if [ $ID = "centos" -o $ID = "rocky" ];then ${COLOR_SUCCESS}"开始安装 Docker compose....."${END} sleep 1 if [ ! -e ${DOCKER_COMPOSE_FILE} ];then curl -L ${GITHUB_PROXY}https://github.com/docker/compose/releases/download/v${DOCKER_COMPOSE_VERSION}/${DOCKER_COMPOSE_FILE} -o /usr/bin/docker-compose #curl -L https://get.daocloud.io/docker/compose/releases/download/v${DOCKER_COMPOSE_VERSION}/docker-compose-$(uname -s)-$(uname -m) -o /usr/bin/docker-compose else mv ${DOCKER_COMPOSE_FILE} /usr/bin/docker-compose fi chmod +x /usr/bin/docker-compose else apt -y install docker-compose fi if docker-compose --version ;then ${COLOR_SUCCESS}"Docker Compose 安装完成"${END} else ${COLOR_FAILURE}"Docker compose 安装失败"${END} exit fi } install_harbor(){ ${COLOR_SUCCESS}"开始安装 Harbor....."${END} sleep 1 if [ ! -e harbor-offline-installer-v${HARBOR_VERSION}.tgz ] ;then wget ${GITHUB_PROXY}https://github.com/goharbor/harbor/releases/download/v${HARBOR_VERSION}/harbor-offline-installer-v${HARBOR_VERSION}.tgz || ${COLOR_FAILURE} "下载失败!" ${END} fi [ -d ${HARBOR_BASE} ] || mkdir ${HARBOR_BASE} tar xvf harbor-offline-installer-v${HARBOR_VERSION}.tgz -C ${HARBOR_BASE} cd ${HARBOR_BASE}/harbor cp harbor.yml.tmpl harbor.yml sed -ri "/^hostname/s/reg.mydomain.com/${HARBOR_NAME}/" harbor.yml sed -ri "/^https/s/(https:)/#\1/" harbor.yml sed -ri "s/(port: 443)/#\1/" harbor.yml sed -ri "/certificate:/s/(.*)/#\1/" harbor.yml sed -ri "/private_key:/s/(.*)/#\1/" harbor.yml sed -ri "s/Harbor12345/${HARBOR_ADMIN_PASSWORD}/" harbor.yml sed -i 's#^data_volume: /data#data_volume: /data/harbor#' harbor.yml #mkdir -p /data/harbor #{HARBOR_BASE}/harbor/install.sh --with-chartmuseum && ${COLOR_SUCCESS}"Harbor 安装完成"${END} || ${COLOR_FAILURE}"Harbor 安装失败"${END} ${HARBOR_BASE}/harbor/install.sh && ${COLOR_SUCCESS}"Harbor 安装完成"${END} || ${COLOR_FAILURE}"Harbor 安装失败"${END} cat > /lib/systemd/system/harbor.service <<EOF [Unit] Description=Harbor After=docker.service systemd-networkd.service systemd-resolved.service Requires=docker.service Documentation=http://github.com/vmware/harbor [Service] Type=simple Restart=on-failure RestartSec=5 ExecStart=/usr/bin/docker-compose -f ${HARBOR_BASE}/harbor/docker-compose.yml up ExecStop=/usr/bin/docker-compose -f ${HARBOR_BASE}/harbor/docker-compose.yml down [Install] WantedBy=multi-user.target EOF systemctl daemon-reload systemctl enable harbor &>/dev/null || ${COLOR}"Harbor已配置为开机自动启动"${END} if [ $? -eq 0 ];then echo color "Harbor安装完成!" 0 echo "-------------------------------------------------------------------" echo -e "请访问链接: \E[32;1mhttp://${HARBOR_IP}/\E[0m" echo -e "用户和密码: \E[32;1madmin/${HARBOR_ADMIN_PASSWORD}\E[0m" else color "Harbor安装失败!" 1 exit fi echo "$HARBOR_IP $HARBOR_NAME" >> /etc/hosts } docker info &> /dev/null && ${COLOR_FAILURE}"Docker已安装"${END} || install_docker docker-compose --version &> /dev/null && ${COLOR_FAILURE}"Docker Compose已安装"${END} || install_docker_compose install_harbor