Centos7通过Docker部署Harbor仓库

一、下载Harbor安装包

下载地址:https://github.com/goharbor/harbor/releases/
在这里插入图片描述

二、安装docker

由于 Harbor 是采用 docker-compose 一键部署的,所以 Harbor 服务器也需要安装 Docker

配置docker的yum源:
[root@harbor ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
[root@harbor ~]# yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
[root@harbor ~]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
[root@harbor ~]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo

安装docker:
[root@harbor ~]# yum install docker-ce-19.03.* docker-ce-cli-19.03.* -y

启动docker:
[root@harbor ~]# systemctl daemon-reload && systemctl enable --now docker

三、安装Compose

[root@harbor harbor]# curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100 12.1M  100 12.1M    0     0  2619k      0  0:00:04  0:00:04 --:--:-- 3756k

[root@harbor harbor]# chmod +x /usr/local/bin/docker-compose
[root@harbor harbor]# docker-compose -v
docker-compose version 1.29.2, build 5becea4c

四、将下载的 Harbor 离线包解压并载入 Harbor 镜像

[root@harbor harbor]# pwd
/opt/harbor
[root@harbor harbor]# ls
harbor-offline-installer-v2.5.3.tgz
解压:
[root@harbor harbor]# tar xf harbor-offline-installer-v2.5.3.tgz 
[root@harbor harbor]# ls
harbor  harbor-offline-installer-v2.5.3.tgz
[root@harbor harbor]# cd harbor
[root@harbor harbor]# ls
common.sh  harbor.v2.5.3.tar.gz  harbor.yml.tmpl  install.sh  LICENSE  prepare

harbor.v2.5.3.tar.gz(docker所用的镜像都放到这个压缩包里)
需要加载这个压缩包的镜像到本地:
[root@harbor harbor]# docker load -i harbor.v2.5.3.tar.gz 

五、修改Harbor配置文件

[root@harbor harbor]# cp harbor.yml.tmpl harbor.yml
[root@harbor harbor]# ls
common.sh  harbor.v2.5.3.tar.gz  harbor.yml  harbor.yml.tmpl  install.sh  LICENSE  prepare
[root@harbor harbor]# vim harbor.yml
第一处修改:
hostname: 192.168.126.136
# hostname:Harbor 的访问地址,可以是域名或者 IP,生产推荐使用域名,并且带有证书;
# 如果配置域名使用https,需要修改证书文件的位置:
  certificate: /your/certificate/path
  private_key: /your/private/key/path
# 如果没有证书需要将https相关配置注释
# https related config
#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

第二处修改:修改 Harbor 的数据目录
# The default data volume
data_volume: /data/harbor

第三处:登录密码,按需修改即可
harbor_admin_password: Harbor12345

六、创建 Harbor 数据目录并进行预配置

[root@harbor harbor]# mkdir /data/harbor /var/log/harbor -p

预检查
[root@harbor harbor]# ./prepare 
prepare base dir is set to /opt/harbor/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

警告:建议使用https

七、执行安装

[root@harbor harbor]# ./install.sh 
[Step 5]: starting Harbor ...
Creating network "harbor_harbor" with the default driver
Creating harbor-log ... done
Creating harbor-portal ... done
Creating redis         ... done
Creating registryctl   ... done
Creating registry      ... done
Creating harbor-db     ... done
Creating harbor-core   ... done
Creating nginx             ... done
Creating harbor-jobservice ... done
✔ ----Harbor has been installed and started successfully.----


[root@harbor harbor]# docker ps -a
CONTAINER ID        IMAGE                                COMMAND                  CREATED             STATUS                   PORTS                       NAMES
604d232dcee1        goharbor/harbor-jobservice:v2.5.3    "/harbor/entrypoint.…"   3 minutes ago       Up 3 minutes (healthy)                               harbor-jobservice
1d5fb24d525b        goharbor/nginx-photon:v2.5.3         "nginx -g 'daemon of…"   3 minutes ago       Up 3 minutes (healthy)   0.0.0.0:80->8080/tcp        nginx
55633f61f767        goharbor/harbor-core:v2.5.3          "/harbor/entrypoint.…"   3 minutes ago       Up 3 minutes (healthy)                               harbor-core
ee60376b20d4        goharbor/harbor-db:v2.5.3            "/docker-entrypoint.…"   3 minutes ago       Up 3 minutes (healthy)                               harbor-db
36237b1c2960        goharbor/registry-photon:v2.5.3      "/home/harbor/entryp…"   3 minutes ago       Up 3 minutes (healthy)                               registry
5a57c978dba1        goharbor/harbor-registryctl:v2.5.3   "/home/harbor/start.…"   3 minutes ago       Up 3 minutes (healthy)                               registryctl
8c0b09563f77        goharbor/redis-photon:v2.5.3         "redis-server /etc/r…"   3 minutes ago       Up 3 minutes (healthy)                               redis
bf20695bac91        goharbor/harbor-portal:v2.5.3        "nginx -g 'daemon of…"   3 minutes ago       Up 3 minutes (healthy)                               harbor-portal
f2a6f8392c6a        goharbor/harbor-log:v2.5.3           "/bin/sh -c /usr/loc…"   3 minutes ago       Up 3 minutes (healthy)   127.0.0.1:1514->10514/tcp   harbor-log

八、如果配置不是https协议,所有的Kubernetes节点的Docker (如果是containerd作为Runtime,可以参考下文配置 insecure-registry)都需要添加 insecure-registries 配置

Docker:

[root@k8s-master01 ~]# vim /etc/docker/daemon.json
{
  "exec-opts": ["native.cgroupdriver=systemd"],
  "insecure-registries": ["192.168.126.136"]   # harbor地址
}

 
[root@k8s-master01 ~]# systemctl daemon-reload
[root@k8s-master01 ~]# systemctl restart docker

Containerd:

vim /etc/containerd/config.toml

在这里插入图片描述

systemctl restart containerd
ctr -n k8s.io image pull CHANGE_HERE_FOR_YOUR_HARBOR_ADDRESS/kubernetes/harbor-exporter:v2.3.2 --plain-http --user admin:Harbor12345

九、访问域名或者IP

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值