CentOS7 安装Harbor1.1.2

来源:互联网 发布:java使用命令行参数 编辑:程序博客网 时间:2024/06/11 23:56

前言

Harbor是一个用于存储和分发Docker镜像的企业级Registry服务器,通过添加一些企业必需的功能特性,例如安全、标识和管理等,扩展了开源Docker Distribution。作为一个企业级私有Registry服务器,Harbor提供了更好的性能和安全。提升用户使用Registry构建和运行环境传输镜像的效率[1]。
说白了就是方便自己将项目中使用的公共的Docker 镜像放到Harbor下进行管理,方便版本更新和维护,减少网络流量。
目前网络上关于Harbor的文章时间都比较早了,而且Harbor已经更新到1.1.2版本了,同时Docker今年3月做了版本重命名,基于这个新版本的完整安装文档没有,刚好最近搭建一个Harbor,因此总结了这个文档,与各位共勉之。


Docker版本变更

Docker在3月份的时候推出了企业版,docker的版本号也发生了翻天覆地的变化。版本也从1.13.x一跃到17.03。
版本变成了社区版(CE,Community Edition)和企业版(EE,Enterprise Edition)。

版本 举例 说明 月度版本 Edge 版本(17.03, 17.04, 17.05…) 每个月一个版本号 季度版本 Stable 版本(17.03, 17.06, 17.09…) 可以理解为第三个月的版本号

企业版(EE) 和 Stable 版本号保持一致,每个版本提供一年维护,官方说明图。
官网的图片

官方文章《ANNOUNCING DOCKER ENTERPRISE EDITION》


版本要求

名称 版本或者时间 文档时间 2017/07/08 CentOS 7(1611) Docker 17.06.0 Docker-Compose 1.14.0 Python 2.7.5(系统自带) Harbor 1.1.2

安装说明

CentOS7自己安装,这个没什么好说明的。我的IP是192.168.0.209。
其他的都会详细介绍如何安装,安装的说明基本来自于官方文档。

systemctl
这个命令需要了解一下,如果没用过CentOS7需要看看。
这篇文章《 Centos7下的systemctl命令与service和chkconfig》有详细的介绍。

接下来会安装docker,docker-compose,harbor.
python使用的是系统自带的,达到harbor的要求了。因此就没有从新安装。


1:安装Docker

我的这个安装方式是按照官网的文档进行的,因为采用了新的版本结构,而且是月度更新,因此对于Docker来讲升级就变的非常重要。因此,首先建立一个仓库,然后在进行安装。

- 建立仓库

建立本地仓库,这个目的就是为了Docker的版本升级。
安装需要的包。

# sudo yum install -y yum-utils device-mapper-persistent-data lvm2

安装yum-utils因为需要 yum-config-manager工具。
安装device-mapper-persistent-data 和 lvm2 因为需要 devicemapper 存储驱动

# sudo yum-config-manager \    --add-repo \    https://download.docker.com/linux/centos/docker-ce.repo

使用上面的命令建立Stable仓库,Stable这个仓库总是需要的,即使你想从edge或者testing仓库安装更新。

- 可选执行

启用edge仓库

# sudo yum-config-manager --enable docker-ce-edge

启用testing仓库

# sudo yum-config-manager --enable docker-ce-testing

使用–disable关闭仓库

Note:

从17.06开始,Stable版本也被push到edge和testing仓库。

- 安装Dcoker CE

更新yum的index。

#sudo yum makecache fast

安装最新版本的Docker CE

#sudo yum install docker-ce

Warning:
如果启用了多个不同的Docker仓库,在安装或者更新时没有指定一个版本,将会默认安装最新的版本,最好不要这么做!

正确的姿势是每次更新需要指定具体的版本。

#yum list docker-ce.x86_64  --showduplicates | sort -r

列出当前可用的docker版本信息

docker-ce.x86_64 17.06.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.06.0.ce-1.el7.centos docker-ce-edge
docker-ce.x86_64 17.06.0.ce-1.el7.centos @docker-ce-edge
docker-ce.x86_64 17.05.0.ce-1.el7.centos docker-ce-edge
docker-ce.x86_64 17.04.0.ce-1.el7.centos docker-ce-edge
docker-ce.x86_64 17.03.2.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.03.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.03.0.ce-1.el7.centos docker-ce-stable

列出了所有,第二列是版本的信息,第三列是仓库的信息。
利用下面的命令安装特定的版本

# sudo yum install docker-ce-17.06.0.ce-1.el7.centos

启动Docker

#sudo systemctl start docker

验证docker是否正确安装

#sudo docker run hello-world

- 更新Docker
这个操作的过程和安装的过程是一样的。
首先运行

#sudo yum makecache fast

安装指定版本的Docker

# sudo yum install docker-ce-17.06.0.ce-1.el7.centos

2:安装Docker-Compose

执行下面的命令安装compose
首先进入这个页面查看当前的版本。
https://github.com/docker/compose/releases/

下载

#curl -L https://github.com/docker/compose/releases/download/1.14.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose

实际下载了一个文件
修改文件的可执行权限

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

Test the installation.

#docker-compose --version

docker-compose version 1.14.0, build 1719ceb

3:安装Harbor

下载Harbor
选择目前最新版本1.1.2
https://github.com/vmware/harbor/releases

我选择的是online版本,两种版本基本上差不多。
https://github.com/vmware/harbor/releases/download/v1.1.2/harbor-online-installer-v1.1.2.tgz

解压

#tar xvf harbor-online-installer-v1.1.2.tgz

配置
在解压后的路径下,找到harbor.cfg进行修改

harbor.cfg中的参数包含两个类型,一个是必须设置,一个是可选设置。
必须设置的参数是必须在cfg文件中进行参数设置的,可以使用默认值,但是必须被设置,否则会无法启动。
可选设置的参数,在cfg文件中可以设置,也可以删除或者注释,不进行设置,不影响启动。

必须设置的参数

参数 描述 hostname 服务器的名称,如果访问UI和注册服务,需要通过这个。可以是IP地址(192.168.0.209),或者是完整的域名(reg.youdomain.com)。不要使用localhost或者127.0.0.1,因为服务需要被其他的机器访问。 db_password: mysql数据的密码。 customize_crt on或者off。默认是on。当这个属性是on的时候,prepare脚本为registry’s token 创建私有key和根证书。如果属性是off的时候,是有key和根证书将有外部资源提供。了解更多请看《Customize Key and Certificate of Harbor Token Service》 ssl_cert SSL证书的位置,只有当协议设置成https的时候,这个属性生效 ssl_cert_key SSL秘钥的位置,只有当协议设置成https的时候这个属性生效。 secretkey_path 加密解密的密码文件路径

还有一些可选的设置
具体描述参考官方文档,这里不进行赘述了。

安装
官方文档内容

#sudo ./install.sh

直接执行会提示

[root@192 harbor]# sudo ./install.sh [Step 0]: checking installation
environment … Note: docker version: 17.06.0 ✖ Need to install
docker-compose(1.7.1+) by yourself first and run this script again.

需要换成另外一种安装方法。

#sudo ./prepare

[root@192 harbor]# ./prepare
Generated and saved secret to file: /data/secretkey
Generated configuration file: ./common/config/nginx/nginx.conf
Generated configuration file: ./common/config/adminserver/env
Generated configuration file: ./common/config/ui/env
Generated configuration file: ./common/config/registry/config.yml
Generated configuration file: ./common/config/db/env
Generated configuration file: ./common/config/jobservice/env
Generated configuration file: ./common/config/jobservice/app.conf
Generated configuration file: ./common/config/ui/app.conf
Generated certificate, key file: ./common/config/ui/private_key.pem, cert file: ./common/config/registry/root.crt
The configuration files are ready, please use docker-compose to start the service.

然后在执行

#docker-compose up -d

启动这个后,我们是online版本,提示下载很多东西。时间有点长,慢慢等待。
● harbor-log
● harbor-adminserver
● harbor-ui
● registry
● harbor-db
● harbor-jobservice
● nginx
到这里,我们应该看清楚了,实际上harbor就是利用docker-compose进行管理Dokcer的一个UI系统。
最后输出
Creating harbor-log …
Creating harbor-log … done
Creating registry …
Creating harbor-db …
Creating harbor-adminserver …
Creating harbor-db
Creating registry
Creating registry … done
Creating harbor-ui …
Creating harbor-ui … done
Creating harbor-jobservice …
Creating nginx …
Creating harbor-jobservice
Creating harbor-jobservice … done

完成后

http://192.168.0.209/
正常访问
用户名:admin
密码:Harbor12345
可以执行如下的命令进行停止和启动

停止

#docker-compose stop

启动

#docker-compose start

结尾

到目前位置Harbor已经安装完成。
目前这个安装是没有包含Notary
如果需要包含Notary请看《官方文档》

后续有时间回写一个Harbor的简单使用教程。

参考文章

[1]https://vmware.github.io/harbor/cn/
[2]https://github.com/vmware/harbor/blob/master/docs/installation_guide.md
[3]http://blog.csdn.net/felix_yujing/article/details/54694294

原创粉丝点击