Harbor与Docker的部署搭建

Harbor 安装小记

场景

在搭建私有云环境时,我们需要将我们打包的镜像存储在局域网内,而不是把镜像推送到hub.docker.com;一方面是因为安全问题,另一方面在局域网内存储,网速炒鸡快。当然对于私有云搭建,在本地搭建镜像仓库那是必须的。接下来,对我安装Harbor 做一个记录。

分析

因为 Harbor 是用 docker 跑起来的,所以我们的机器上必须有 docker 环境,还有比较中要的一点,Harbor 需要使用docker-compose, 所以需要 docker-compose。
安装

**docker 安装

**

Harbor在安装前的几个注意点
由于Harbor有1.8后和前的配置不一样,决定先安装1.8,结果报错如下

[root@localhost harbor]# ./install.sh 

[Step 0]: checking installation environment ...
✖ Need to upgrade docker package to 17.06.0+. 
对docker的版本要求较高,决定先卸载之前的docker


[root@topcheer harbor]# docker --version
Docker version 1.13.1, build 7f2769b/1.13.1

[root@topcheer harbor]# ./install.sh

[Step 0]: checking installation environment ...
✖ Need to upgrade docker package to 17.06.0+.

开始卸载

[root@topcheer harbor]# yum remove docker                   docker-client                   docker-client-latest                   docker-common                   docker-latest                   docker-latest-logrotate                   docker-logrotate                   docker-selinux                   docker-engine-selinux                   docker-engine
已加载插件:fastestmirror, langpacks
参数 docker-client-latest 没有匹配
参数 docker-latest 没有匹配
参数 docker-latest-logrotate 没有匹配
参数 docker-logrotate 没有匹配
参数 docker-engine 没有匹配
正在解决依赖关系
--> 正在检查事务
---> 软件包 container-selinux.noarch.2.2.107-3.el7 将被 删除
---> 软件包 docker.x86_64.2.1.13.1-103.git7f2769b.el7.centos 将被 删除
---> 软件包 docker-client.x86_64.2.1.13.1-103.git7f2769b.el7.centos 将被 删除
---> 软件包 docker-common.x86_64.2.1.13.1-103.git7f2769b.el7.centos 将被 删除
--> 解决依赖关系完成

依赖关系解决

=====================================================================================================================================================
 Package                             架构                     版本                                                   源                         大小
=====================================================================================================================================================
正在删除:
 container-selinux                   noarch                   2:2.107-3.el7                                          @extras                    40 k
 docker                              x86_64                   2:1.13.1-103.git7f2769b.el7.centos                     @extras                    65 M
 docker-client                       x86_64                   2:1.13.1-103.git7f2769b.el7.centos                     @extras                    13 M
 docker-common                       x86_64                   2:1.13.1-103.git7f2769b.el7.centos                     @extras                   4.4 k

事务概要
=====================================================================================================================================================
移除  4 软件包

安装大小:77 M
是否继续?[y/N]:y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在删除    : 2:docker-1.13.1-103.git7f2769b.el7.centos.x86_64                                                                                 1/4
警告:/etc/sysconfig/docker-storage 已另存为 /etc/sysconfig/docker-storage.rpmsave
  正在删除    : 2:docker-client-1.13.1-103.git7f2769b.el7.centos.x86_64                                                                          2/4
  正在删除    : 2:docker-common-1.13.1-103.git7f2769b.el7.centos.x86_64                                                                          3/4
  正在删除    : 2:container-selinux-2.107-3.el7.noarch                                                                                           4/4
  验证中      : 2:docker-common-1.13.1-103.git7f2769b.el7.centos.x86_64                                                                          1/4
  验证中      : 2:docker-1.13.1-103.git7f2769b.el7.centos.x86_64                                                                                 2/4
  验证中      : 2:container-selinux-2.107-3.el7.noarch                                                                                           3/4
  验证中      : 2:docker-client-1.13.1-103.git7f2769b.el7.centos.x86_64                                                                          4/4

删除:
  container-selinux.noarch 2:2.107-3.el7                                    docker.x86_64 2:1.13.1-103.git7f2769b.el7.centos
  docker-client.x86_64 2:1.13.1-103.git7f2769b.el7.centos                   docker-common.x86_64 2:1.13.1-103.git7f2769b.el7.centos

完毕!

安装新的docker,首先要先update一下,不然后面会报错

[root@topcheer harbor]# systemctl restart docker.service
Job for docker.service failed because the control process exited with error code. See "systemctl status docker.service" and "journalctl -xe" for details.
[root@topcheer harbor]#  sudo yum update
最后在开始正式安装


[root@topcheer harbor]# yum install -y yum-utils
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.tuna.tsinghua.edu.cn
 * extras: mirrors.tuna.tsinghua.edu.cn
 * updates: mirrors.tuna.tsinghua.edu.cn
正在解决依赖关系
--> 正在检查事务
---> 软件包 yum-utils.noarch.0.1.1.31-50.el7 将被 升级
---> 软件包 yum-utils.noarch.0.1.1.31-52.el7 将被 更新
--> 解决依赖关系完成

依赖关系解决

[root@topcheer harbor]# yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
已加载插件:fastestmirror, langpacks
adding repo from: https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
grabbing file https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
[root@topcheer harbor]# yum list docker-ce --showduplicates|sort -r
已加载插件:fastestmirror, langpacks
可安装的软件包
 * updates: mirrors.tuna.tsinghua.edu.cn
Loading mirror speeds from cached hostfile
 * extras: mirrors.tuna.tsinghua.edu.cn
docker-ce.x86_64            3:19.03.4-3.el7                     docker-ce-stable
docker-ce.x86_64            3:19.03.3-3.el7                     docker-ce-stable
docker-ce.x86_64            3:19.03.2-3.el7                     docker-ce-stable
.....


[root@topcheer harbor]# yum install docker-ce-17.06.2.ce-1.el7.centos
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.tuna.tsinghua.edu.cn
 * extras: mirrors.tuna.tsinghua.edu.cn
 * updates: mirrors.tuna.tsinghua.edu.cn
正在解决依赖关系
--> 正在检查事务
---> 软件包 docker-ce.x86_64.0.17.06.2.ce-1.el7.centos 将被 安装
--> 正在处理依赖关系 container-selinux >= 2.9,它被软件包 docker-ce-17.06.2.ce-1.el7.centos.x86_64 需要
--> 正在检查事务
---> 软件包 container-selinux.noarch.2.2.107-3.el7 将被 安装
--> 解决依赖关系完成

启动docker
systemctl start docker

docker-compose 安装

$ sudo curl -L "https://github.com/docker/compose/releases/download/1.24.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
$ sudo chmod +x /usr/local/bin/docker-compose
$ docker-compose --version
docker-compose version 1.24.0, build 1110ad01

安装Harbor

离线安装版
获取并解压

$ wget https://storage.googleapis.com/harbor-releases/release-1.8.0/harbor-offline-installer-v1.8.0.tgz
$ tar xvf harbor-offline-installer-v1.8.0.tgz

解压会生成 Harbor 文件夹
修改配置文件

$ cd Harbor
$ vim /Harbor.yaml

需要配置的地方有几处,但最重要的是hostname, hostname 必须指定为域名,不能使localhost,127.0.0.1 这样的地址,别的密码、端口可可定义。如下是我的配置

# Configuration file of Harbor

# The IP address or hostname to access admin UI and registry service.
# DO NOT use localhost or 127.0.0.1, because Harbor needs to be accessed by external clients.

hostname: hub.k8s.com

# http related config
http:
  # port for http, default is 80. If https enabled, this port will redirect to https port
  port: 80

# 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

# Uncomment external_url if you want to enable external proxy
# And when it enabled the hostname will no longer used
# external_url: https://reg.mydomain.com:8433

# The initial password of Harbor admin
# It only works in first time to install harbor
# Remember Change the admin password from UI after launching Harbor.
harbor_admin_password: Harbor12345

# Harbor DB configuration
database:
  # The password for the root user of Harbor DB. Change this before any production use.
  password: root123

# The default data volume
data_volume: /data

# Harbor Storage settings by default is using /data dir on local filesystem
# Uncomment storage_service setting If you want to using external storage
# storage_service:
#   # ca_bundle is the path to the custom root ca certificate, which will be injected into the truststore
#   # of registry's and chart repository's containers.  This is usually needed when the user hosts a internal storage with self signed certificate.
#   ca_bundle:

#   # storage backend, default is filesystem, options include filesystem, azure, gcs, s3, swift and oss
#   # for more info about this configuration please refer https://docs.docker.com/registry/configuration/
#   filesystem:
#     maxthreads: 100
#   # set disable to true when you want to disable registry redirect
#   redirect:
#     disabled: false

# Clair configuration
clair:
  # The interval of clair updaters, the unit is hour, set to 0 to disable the updaters.
  updaters_interval: 12

  # Config http proxy for Clair, e.g. http://my.proxy.com:3128
  # Clair doesn't need to connect to harbor internal components via http proxy.
  http_proxy:
  https_proxy:
  no_proxy: 127.0.0.1,localhost,core,registry

jobservice:
  # Maximum number of job workers in job service
  max_job_workers: 10

chart:
  # Change the value of absolute_url to enabled can enable absolute url in chart
  absolute_url: disabled

# Log configurations
log:
  # options are debug, info, warning, error, fatal
  level: info
  # Log files are rotated log_rotate_count times before being removed. If count is 0, old versions are removed rather than rotated.
  rotate_count: 50
  # Log files are rotated only if they grow bigger than log_rotate_size bytes. If size is followed by k, the size is assumed to be in kilobytes.
  # If the M is used, the size is in megabytes, and if G is used, the size is in gigabytes. So size 100, size 100k, size 100M and size 100G
  # are all valid.
  rotate_size: 200M
  # The directory on your host that store log
  location: /var/log/harbor

#This attribute is for migrator to detect the version of the .cfg file, DO NOT MODIFY!
_version: 1.8.0

# Uncomment external_database if using external database. Currently only support POSTGRES.
# Four databases are needed to be create first by users for Harbor core, Clair, Notary server
# and Notary signer. And the tables will be generated automatically when Harbor starting up.
# NOTE: external_database is unable to custom attributes individually, you must do them in block.
# external_database:
#   harbor:
#     host: harbor_db_host
#     port: harbor_db_port
#     db_name: harbor_db_name
#     username: harbor_db_username
#     password: harbor_db_password
#     ssl_mode: disable
#   clair:
#     host: clair_db_host
#     port: clair_db_port
#     db_name: clair_db_name
#     username: clair_db_username
#     password: clair_db_password
#     ssl_mode: disable
#   notary_signer:
#     host: notary_signer_db_host
#     port: notary_signer_db_port
#     db_name: notary_signer_db_name
#     username: notary_signer_db_username
#     password: notary_signer_db_password
#     ssl_mode: disable
#   notary_server:
#     host: notary_server_db_host
#     port: notary_server_db_port
#     db_name: notary_server_db_name
#     username: notary_server_db_username
#     password: notary_server_db_password
#     ssl_mode: disable

# Uncomment external_redis if using external Redis server
# external_redis:
#   host: redis
#   port: 6379
#   password:
#   # db_index 0 is for core, it's unchangeable
#   registry_db_index: 1
#   jobservice_db_index: 2
#   chartmuseum_db_index: 3

# Uncomment uaa for trusting the certificate of uaa instance that is hosted via self-signed cert.
# uaa:
#   ca_file: /path/to/ca

执行安装

$ ./install.sh
......
Creating harbor-portal     ... done
Creating nginx             ... done

 ----Harbor has been installed and started successfully.----

Now you should be able to visit the admin portal at http://hub.k8s.com.
For more details, please visit https://github.com/goharbor/harbor .

最后出现如上提示就安装成功了。将hub.k8s.com解析到本地即可访问。

两篇文档相结合更加完善,便进行了小小调整完善,希望能够对大家有所帮助。
转载于:https://www.cnblogs.com/dalianpai/p/11795201.html
转载于:https://yq.aliyun.com/articles/704905

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值