docker harbor2.2.3安装

简介

Harbor是一个用于存储和分发Docker镜像的企业级Registry服务器,由vmware开源,其通过添加一些企业必需的功能特性,例如安全、标识和管理等,扩展了开源Docker Distribution。作为一个企业级私有Registry服务器,Harbor提供了更好的性能和安全。提升用户使用Registry构建和运行环境传输镜像的效率。Harbor支持安装在多个Registry节点的镜像资源复制,镜像全部保存在私有Registry中, 确保数据和知识产权在公司内部网络中管控,另外,Harbor也提供了高级的安全特性,诸如用户管理,访问控制和活动审计等。

vmware官方开源服务列表地址:https://vmware.github.io/harbor/cn/

harbor官方github地址:https://github.com/vmware/harbor

harbor官方网址:https://goharbor.io/ 

Harbor功能官方介绍

基于角色的访问控制:用户与Docker镜像仓库通过“项目”进行组织管理,一个用户可以对多个镜像仓库在同一命名空间(project)里有不同的权限。

镜像复制:镜像可以在多个Registry实例中复制(同步)。尤其适合于负载均衡,高可用,混合云和多云的场景。

图形化用户界面:用户可以通过浏览器来浏览,检索当前Docker镜像仓库,管理项目和命名空间。

AD/LDAP 支:Harbor可以集成企业内部已有的AD/LDAP,用于鉴权认证管理。

审计管理:所有针对镜像仓库的操作都可以被记录追溯,用于审计管理。

国际化:已拥有英文、中文、德文、日文和俄文的本地化版本。更多的语言将会添加进来。

RESTful API - RESTful API :提供给管理员对于Harbor更多的操控, 使得与其它管理软件集成变得更容易。

部署简单:提供在线和离线两种安装工具, 也可以安装到vSphere平台(OVA方式)虚拟设备。

Harbor的各个组件作用

组件名 作用
nginx harbor的一个反向代理组件,代理registry、ui、token等服务。这个代理会转发harbor web和docker client的各种请求到后端服务上。
harbor-adminserver harbor系统管理接口,可以修改系统配置以及获取系统信息
harbor-db 存储项目的元数据、用户、规则、复制策略等信息
harbor-jobservice harbor里面主要是为了镜像仓库之前同步使用的
harbor-log 收集其他harbor的日志信息
harbor-ui 一个用户界面模块,用来管理registry
registry 存储docker images的服务,并且提供pull/push服务
redis 存储缓存信息
webhook 当registry中的image状态发生变化的时候去记录更新日志、复制等操作
token service 在docker client进行pull/push的时候负责token的发放

Harbor安装的先决条件

1、硬件

ResourceMinimumRecommended
CPU 2 CPU 4 CPU
Mem 4 GB 8 GB
Disk 40 GB 160 GB

2、软件

SoftwareVersionDescription
Docker engine Version 17.06.0-ce+ or higher For installation instructions, see Docker Engine documentation
Docker Compose Version 1.18.0 or higher For installation instructions, see Docker Compose documentation
Openssl Latest is preferred Used to generate certificate and keys for Harbor

3、端口

PortProtocolDescription
443 HTTPS Harbor portal and core API accept HTTPS requests on this port. You can change this port in the configuration file.
4443 HTTPS Connections to the Docker Content Trust service for Harbor. Only required if Notary is enabled. You can change this port in the configuration file.
80 HTTP Harbor portal and core API accept HTTP requests on this port. You can change this port in the configuration file.

安装Harbor

下载地址:https://github.com/goharbor/harbor/releases

安装文档:https://github.com/vmware/harbor/blob/master/docs/installation_guide.md 

 下载离线安装包

  # cd /usr/local/src

# wget https://github.com/goharbor/harbor/releases/download/v2.2.3/harbor-offline-installer-v2.2.3.tgz
# tar xfz harbor-offline-installer-v2.2.3.tgz

# ln -sv /usr/local/src/harbor /usr/local/

# cd /usr/local/harbor/

  # yum install python-pip -y

安装docker-compose

[root@docker01 harbor]# yum install -y docker-compose

生成CA私钥

[root@docker01 ~]# openssl genrsa -out ca.key 4096
## 如果使用 FQDN 连接 Harbor 主机,则必须将其指定为 CN 属性
[root@docker01 ~]# openssl req -x509 -new -nodes -sha512 -days 3650 

-subj "/C=CN/ST=Beijing/L=Beijing/O=test-harbor/OU=Personal/CN=my-harbor.com"

-key ca.key

-out ca.crt

生成服务端证书

[root@docker01 ~]# openssl genrsa -out my-harbor.com.key 4096
Generating RSA private key, 4096 bit long modulus
..++
.......++
e is 65537 (0x10001)

##  向CA发起签署请求
# openssl req -sha512 -new 
    -subj "/C=CN/ST=Beijing/L=Beijing/O=test-harbor/OU=Personal/CN=my-harbor.com" 
    -key my-harbor.com.key 
    -out my-harbor.com.csr

 生成x509 v3的扩展文件

# cat > v3.ext <<-EOF
    authorityKeyIdentifier=keyid,issuer
    basicConstraints=CA:FALSE
    keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
    extendedKeyUsage = serverAuth
    subjectAltName = @alt_names
    
    [alt_names]
    DNS.1=my-harbor.com
    DNS.2=my-harbor
    DNS.3=docker01
    EOF
  

# openssl x509 -req -sha512 -days 3650     -extfile v3.ext     -CA ca.crt -CAkey ca.key -CAcreateserial -in my-harbor.com.csr -out my-harbor.com.crt
Signature ok
subject=/C=CN/ST=Beijing/L=Beijing/O=test-harbor/OU=Personal/CN=my-harbor.com
Getting CA Private Key
# cp my-harbor.com.crt my-harbor.com.key /data/cert

 CA签署证书

# openssl x509 -inform PEM -in my-harbor.com.crt -out my-harbor.com.cert

修改Harbor配置文件

[root@docker01 harbor]# egrep -v "^$|#" harbor.yml
hostname: my-harbor.com
http:
  port: 80
https:
  port: 443
  certificate: /data/cert/my-harbor.com.crt
  private_key: /data/cert/my-harbor.com.key
harbor_admin_password: Harbor12345
database:
  password: root123
  max_idle_conns: 50
  max_open_conns: 1000
data_volume: /data

 首次部署更新Harbor配置

[root@docker01 harbor]# ./prepare 
prepare base dir is set to /usr/local/src/harbor
Clearing the configuration file: /config/portal/nginx.conf
Clearing the configuration file: /config/log/logrotate.conf
Clearing the configuration file: /config/log/rsyslog_docker.conf
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

 安装Harbor

[root@docker01 harbor]# ./install.sh 
[Step 0]: checking if docker is installed ...

Note: docker version: 18.09.9

...

Creating redis ... done
Creating harbor-core ... done
Creating network "harbor_harbor" with the default driver
Creating nginx ... done
Creating harbor-db ... 
Creating registry ... 
Creating registryctl ... 
Creating harbor-portal ... 
Creating redis ... 
Creating harbor-core ... 
Creating nginx ... 
Creating harbor-jobservice ... 
✔ ----Harbor has been installed and started successfully.----

 查看Harbor安装后启动的容器

[root@docker01 harbor]# docker-compose ps
      Name                     Command               State                      Ports                   
--------------------------------------------------------------------------------------------------------
harbor-core         /harbor/entrypoint.sh            Up                                                 
harbor-db           /docker-entrypoint.sh            Up                                                 
harbor-jobservice   /harbor/entrypoint.sh            Up                                                 
harbor-log          /bin/sh -c /usr/local/bin/ ...   Up      127.0.0.1:1514->10514/tcp                  
harbor-portal       nginx -g daemon off;             Up                                                 
nginx               nginx -g daemon off;             Up      0.0.0.0:80->8080/tcp, 0.0.0.0:443->8443/tcp
redis               redis-server /etc/redis.conf     Up                                                 
registry            /home/harbor/entrypoint.sh       Up                                                 
registryctl         /home/harbor/start.sh            Up           

当前目录下会生成docker-compose.yml文件,通过docker-compose可以启停服务

docker-compose down -v 或 docker-compose stop  //区别,前者会remove掉容器、image、网络,停的更干净,后者只是停服务
docker-compose up -d                       // 重启Harbor

运行后的Harbor修改配置

## 切到Harbor的安装目录
[root@docker01 ~]# cd /usr/local/harbor/          

## 停止Harbor
[root@docker01 harbor]# docker-compose stop
Stopping harbor-jobservice ... done
Stopping nginx             ... done
Stopping harbor-core       ... done
Stopping redis             ... done
Stopping registryctl       ... done
Stopping registry          ... done
Stopping harbor-portal     ... done
Stopping harbor-db         ... done
Stopping harbor-log        ... done

harbor.yml的必须参数解释

参数名 子选项 说明
hostname   指定为部署Harbor主机的IP地址或者完全限定域名(FQDN),也就是访问Harbor使用的地址。
由于对外提供访问,所以不要指定127.0.0.1和localhost,也不要指定为0.0.0.0
http   生产环境不建议使用HTTP协议。只有在开发环境和air-gapped测试环境使用。在非air-gapped环境
使用HTTP协议,可能会遭受Man-in-the-MiddleAttack攻击
  port HTTP协议的端口,默认为80
https   生产环境或非air-gapped环境使用
  port HTTPS协议端口,默认为443
  certificate 证书文件路径
  private_key 私钥文件路径
internal_tls    
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     

网页访问harbor

Harbor的数据库认证模式

 注意:自动注册功能不建议开启,因为开启后登录页面会出现注册的功能,不方便用户管理

原文地址:https://www.cnblogs.com/zh-dream/p/14987388.html