前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >搭建 Harbor 私有镜像仓库

搭建 Harbor 私有镜像仓库

原创
作者头像
keepyan
修改2019-04-20 11:26:53
1.3K0
修改2019-04-20 11:26:53
举报

什么是 Harbor?


harbor 是 VMware 公司开源的企业级 DockerRegistry 项目,项目地址为 https://github.com/vmware/harbor。其目标是帮助用户迅速搭建一个企业级的 Docker registry 服务。它以 Docker 公司开源的 registry 为基础,提供了管理UI,基于角色的访问控制(Role Based Access Control),AD/LDAP集成、以及审计日志(Auditlogging) 等企业用户需求的功能,同时还原生支持中文。Harbor 的每个组件都是以 Docker 容器的形式构建的,使用 Docker Compose 来对它进行部署。


环境准备

1、腾讯云服务器(CentOS7.4)

2、Docker 版本:1.13.1

3、Docker-compose:1.17.0

4、Harbor:1.1.2


一:安装docker

直接yum 安装即可

 yum -y install docker
 systemctl start docker (启动docker)

二:安装docker-compose

下载指定版本的docker-compose

sudo curl -L https://github.com/docker/compose/releases/download/1.17.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose

对二进制文件赋可执行权限

chmod +x /usr/local/bin/docker-compose

测试下docker-compose是否安装成功

docker-compose --version

出现如下
docker-compose version 1.17.1, build 6d101fb

三:安装 Harbor


wget https://github.com/vmware/harbor/releases/download/v1.1.2/harbor-offline-installer-v1.1.2.tgz
ps:在线安装版(精简版)wget https://storage.googleapis.com/harbor-releases/release-1.7.0/harbor-online-installer-v1.7.5.tgz
tar -zxvf harbor-offline-installer-v1.1.2.tgz

解压缩之后,进入目录下会看到 harbor.cfg 文件,该文件就是 Harbor 的配置文件。

## Configuration file of Harbor

# hostname设置访问地址,可以使用ip、域名,不可以设置为127.0.0.1或localhost
hostname = abc.lengxiaofeng.cn   #这里我先配置我的域名(已添加到主机的解析)

# 访问协议,默认是http,也可以设置https,如果设置https,则nginx ssl需要设置on
ui_url_protocol = https #这里使用https协议

# mysql数据库root用户默认密码root123,实际使用时修改下
db_password = root123

#Maximum number of job workers in job service
max_job_workers = 3

#Determine whether or not to generate certificate for the registry's token.
#If the value is on, the prepare script creates new root cert and private key
#for generating token to access the registry. If the value is off the default key/cert will be used.
#This flag also controls the creation of the notary signer's cert.
customize_crt = on

#The path of cert and key files for nginx, they are applied only the protocol is set to https
ssl_cert = /data/abc/abc.lengxiaofeng.cn.crt  #容器中使用nginx作为前端,所以这里使用nginx证书
ssl_cert_key = /data/abc/abc.lengxiaofeng.cn.key 

#The path of secretkey storage
secretkey_path = /data

#Admiral's url, comment this attribute, or set its value to NA when Harbor is standalone
admiral_url = NA

#NOTES: The properties between BEGIN INITIAL PROPERTIES and END INITIAL PROPERTIES
#only take effect in the first boot, the subsequent changes of these properties
#should be performed on web ui

#************************BEGIN INITIAL PROPERTIES************************

#Email account settings for sending out password resetting emails.

#Email server uses the given username and password to authenticate on TLS connections to host and act as identity.
#Identity left blank to act as username.
email_identity =

email_server = smtp.mydomain.com
email_server_port = 25
email_username = sample_admin@mydomain.com
email_password = abc
email_from = admin <sample_admin@mydomain.com>
email_ssl = false

##The initial password of Harbor admin, only works for the first time when Harbor starts.
#It has no effect after the first launch of Harbor.
# 启动Harbor后,管理员UI登录的密码,默认是Harbor12345
harbor_admin_password = Harbor12345     #根据自己的需求修改

# 认证方式,这里支持多种认证方式,如LADP、本次存储、数据库认证。默认是db_auth,mysql数据库认证
auth_mode = db_auth

#The url for an ldap endpoint.
ldap_url = ldaps://ldap.mydomain.com

#A user's DN who has the permission to search the LDAP/AD server.
#If your LDAP/AD server does not support anonymous search, you should configure this DN and ldap_search_pwd.
#ldap_searchdn = uid=searchuser,ou=people,dc=mydomain,dc=com

#the password of the ldap_searchdn
#ldap_search_pwd = password

#The base DN from which to look up a user in LDAP/AD
ldap_basedn = ou=people,dc=mydomain,dc=com

#Search filter for LDAP/AD, make sure the syntax of the filter is correct.
#ldap_filter = (objectClass=person)

# The attribute used in a search to match a user, it could be uid, cn, email, sAMAccountName or other attributes de
pending on your LDAP/AD  ldap_uid = uid

#the scope to search for users, 1-LDAP_SCOPE_BASE, 2-LDAP_SCOPE_ONELEVEL, 3-LDAP_SCOPE_SUBTREE
ldap_scope = 3

#Timeout (in seconds)  when connecting to an LDAP Server. The default value (and most reasonable) is 5 seconds.
ldap_timeout = 5

# 是否开启自注册
self_registration = on

# Token有效时间,默认30分钟
token_expiration = 30

# 用户创建项目权限控制,默认是everyone(所有人),也可以设置为adminonly(只能管理员)
project_creation_restriction = everyone

#Determine whether the job service should verify the ssl cert when it connects to a remote registry.
#Set this flag to off when the remote registry uses a self-signed or untrusted certificate.
verify_remote_cert = on
#************************END INITIAL PROPERTIES************************

注:主要修改hostname ui_url_protocol ssl_cert ssl_cert_key harbor_admin_password 这几个字段,如果使用http 协议,可以不配置证书。


启动 harbor,修改完配置文件后,在的当前目录执行./install.sh,Harbor服务就会根据当期目录下的docker-compose.yml开始下载依赖的镜像,检测并按照顺序依次启动各个服务。

用户名默认admin 密码就是配置文件中设置的密码


四:停止和启动harbor

如果需要修改Harbor的配置文件harbor.cfg,因为Harbor是基于docker-compose服务编排的,我们可以使用docker-compose命令重启Harbor。不修改配置文件,重启Harbor命令:docker-compose start | stop | restart

1、停止Harbo
$ docker-compose down -v
Stopping nginx ... done
Stopping harbor-jobservice ... done
......
Removing harbor-log ... done
Removing network harbor_harbo

2、启动Harbo
$ docker-compose up -d
Creating network "harbor_harbor" with the default drive
Creating harbor-log ... 
......
Creating nginx
Creating harbor-jobservice ... done
--------------------- 

注:如果中途遇到某些容器异常退出,导致仓库无法正常访问,也可以使用docker-compose 命令来重启服务。

容器中的nginx配置文件中是配置了80端口自动重定向到443端口的,所以即使http请求也会自动跳转到https

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 什么是 Harbor?
  • harbor 是 VMware 公司开源的企业级 DockerRegistry 项目,项目地址为 https://github.com/vmware/harbor。其目标是帮助用户迅速搭建一个企业级的 Docker registry 服务。它以 Docker 公司开源的 registry 为基础,提供了管理UI,基于角色的访问控制(Role Based Access Control),AD/LDAP集成、以及审计日志(Auditlogging) 等企业用户需求的功能,同时还原生支持中文。Harbor 的每个组件都是以 Docker 容器的形式构建的,使用 Docker Compose 来对它进行部署。
    • 环境准备
      • 1、腾讯云服务器(CentOS7.4)
        • 2、Docker 版本:1.13.1
          • 3、Docker-compose:1.17.0
            • 4、Harbor:1.1.2
              • 一:安装docker
                • 直接yum 安装即可
                  • 二:安装docker-compose
                    • 三:安装 Harbor
                      • 解压缩之后,进入目录下会看到 harbor.cfg 文件,该文件就是 Harbor 的配置文件。
                        • 注:主要修改hostname ui_url_protocol ssl_cert ssl_cert_key harbor_admin_password 这几个字段,如果使用http 协议,可以不配置证书。
                          • 启动 harbor,修改完配置文件后,在的当前目录执行./install.sh,Harbor服务就会根据当期目录下的docker-compose.yml开始下载依赖的镜像,检测并按照顺序依次启动各个服务。
                            • 用户名默认admin 密码就是配置文件中设置的密码
                            • 四:停止和启动harbor
                              • 如果需要修改Harbor的配置文件harbor.cfg,因为Harbor是基于docker-compose服务编排的,我们可以使用docker-compose命令重启Harbor。不修改配置文件,重启Harbor命令:docker-compose start | stop | restart
                                • 注:如果中途遇到某些容器异常退出,导致仓库无法正常访问,也可以使用docker-compose 命令来重启服务。
                                  • 容器中的nginx配置文件中是配置了80端口自动重定向到443端口的,所以即使http请求也会自动跳转到https
                                  相关产品与服务
                                  容器镜像服务
                                  容器镜像服务(Tencent Container Registry,TCR)为您提供安全独享、高性能的容器镜像托管分发服务。您可同时在全球多个地域创建独享实例,以实现容器镜像的就近拉取,降低拉取时间,节约带宽成本。TCR 提供细颗粒度的权限管理及访问控制,保障您的数据安全。
                                  领券
                                  问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档