|
一、harbor简介:
简单的说,Harbor 是一个企业级的 Docker Registry,可以实现 images 的私有存储和日志统计权限控制等功能,并支持创建多项目(Harbor 提出的概念),基于官方 Registry V2 实现的。
二、部署方法:
操作系统:Ubuntu14.04
1、安装docker:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| #安装插件
sudo apt-get install apt-transport-https ca-certificates
#添加GPG key
sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
sudo vim /etc/apt/sources.list.d/docker.list
#添加以下内容,保存退出
deb https://apt.dockerproject.org/repo ubuntu-trusty main
#跟新、清除老的repo
sudo apt-get update
sudo apt-get purge lxc-docker
#安装docker-engine
sudo apt-get install docker-engine
|
2.安装docker-com:
3.安装Harbor:
3.1、克隆源码:
3.2、修改配置:
1
2
| cd harbor/Deploy/
vim harbor.cfg
|
如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
| ## 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,一般为IP,或者域名,用于登录 Web UI 界面
hostname = 172.16.4.253
#The protocol for accessing the UI and token/notification service, by default it is http.
#It can be set to https if ssl is enabled on nginx.
# URL 访问方式,SSL 需要配置 nginx
ui_url_protocol = http
#Email account settings for sending out password resetting emails.
# 邮件相关信息配置,如忘记密码发送邮件
email_server = smtp.xxxxxx.com
email_server_port = 465
email_username = reg@mritd.me
email_password = xxxxxx
email_from = docker <reg@mritd.me>
email_ssl = true
##The password of Harbor admin, change this before any production use.
# 默认的 Harbor 的管理员密码,管理员用户名默认 admin
harbor_admin_password = Harbor12345
##By default the auth mode is db_auth, i.e. the credentials are stored in a local database.
#Set it to ldap_auth if you want to verify a user's credentials against an LDAP server.
# 指定 Harbor 的权限验证方式,Harbor 支持本地的 mysql 数据存储密码,同时也支持 LDAP
auth_mode = db_auth
#The url for an ldap endpoint.
# 如果采用了 LDAP,此处填写 LDAP 地址
ldap_url = ldaps://ldap.mydomain.com
#The basedn template to look up a user in LDAP and verify the user's password.
# LADP 验证密码的方式
ldap_basedn = uid=%s,ou=people,dc=mydomain,dc=com
#The password for the root user of mysql db, change this before any production use.
# mysql 数据库 root 账户密码
db_password = root123
#Turn on or off the self-registration feature
# 是否允许开放注册
self_registration = on
#Turn on or off the customize your certicate
# 允许自签名证书
customize_crt = on
#fill in your certicate message
# 自签名证书信息
crt_country = CN
crt_state = State
crt_location = CN
crt_organization = mritd
crt_organizationalunit = mritd
crt_commonname = mritd.me
crt_email = reg.mritd.me
#####
|
3.3、生成相关配置文件:
1
2
| cd harbor/Deploy/
./prepare
|
3.4、编译image并启动:
1
2
| cd harbor/Deploy/
docker-compose up -d
|
3.5、检查启动后的相关容器:
Proxy : 由Nginx 服务器构成的反向代理
Registry : 由Docker官方的开源registry 镜像构成的容器实例
UI : 即架构中的core services, 构成此容器的代码是Harbor项目的主体
Mysql : 由官方MySql镜像构成的数据库容器
Log : 运行着rsyslogd的容器,通过log-driver的形式收集其他容器的日志
4、访问Web Ui:
访问:http://172.16.4.253,账户密码为harbor.cfg中配置的
如果harbor.cfg中的self_registration设置为off,那么普通用户无法实现注册,只能由管理员创建用户;右上角的注册按钮也会消失。
4.2、登录:
默认账户密码:admin:Harbor12345
4.3、创建私有项目:
harbor的项目类似于Docker Hub的用户名,其下可以存很多镜像
4.4、push镜像:
在web ui中查看
著:要是不适用验证功能的话,修改registry的配置文件,把auth部分注释掉,重新启动即可
1
2
3
| sudo vim harbor/Deploy/config/registry/config.yml
sudo docker-compose stop
sudo docker-compose up -d
|
三、配置docker镜像的复制:
复制功能是image在两个或多个harbor节点之间的复制。原理图如下:
1.先配置2个harbor实例,分别为172.16.4.253和172.16.4.252
2.在172.16.4.253上上传一个镜像,该实例作为主节点
3.进入web ui的项目选项,选择复制:
4.点击新增策略,并设置策略:
创建完毕后,我们可以看到复制策略中多一个策略,复制任务里面也多一个任务,稍等一会就可以复制完成。登录172.16.4.252的web ui,会发现镜像和日志都复制过来了。
四、升级harbor:
1.删除原有容器
1
2
| cd harbor/Deploy/
sudo docker-compose down
|
2.备份
3.重新下载源码
4.如果harbor 是迁移到其他服务器,请先执行数据备份
修改 migration.cfg 文件里面的 数据库 帐号密码后
1
| sudo docker build -t migrate-tool .
|
5.运行一个临时数据库容器,(注意:/data/database 为你设置的挂载数据库的目录 /path/to/backup 数据备份的目录)本分数据
1
| sudo docker run -ti --rm -v /data/database:/var/lib/mysql -v /path/to/backup:/harbor-migration/backup migrate-tool backup
|
6.数据库还原
1
| sudo docker run -ti --rm -v /data/database:/var/lib/mysql migrate-tool up head
|
7.对比一下配置文件
如果修改了端口 必须更新 cd harbor/Deploy/config/nginx/nginx.conf 里面的端口
1
2
| diff harbor.cfg /tmp/harbor/Deploy/harbor.cfg
diff docker-compose.yaml /tmp/harbor/Deploy/docker-compose.yaml
|
8.执行 ./prepare 生成新的配置文件
1
2
| cd /harbor/Deploy/
./prepare
|
9.build 新的镜像,启动容器
1
2
| cd /harbor/Deploy/
docker-compose up --build -d
|
完成后,登录web ui,检查是否升级成功。
|
|