Docker企业级仓库Harbor的安装配置与使用

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

  

  部署环境

 

  安装docker和docker-compose

yum -y install docker docker-compose

  

  下载habor包

wget https://storage.googleapis.com/harbor-releases/release-1.5.0/harbor-offline-installer-v1.5.0-rc2.tgz

  更多包下载地址

https://github.com/goharbor/harbor/releases

  

  解压

 tar -xf harbor-offline-installer-v1.5.0-rc2.tgz

  

  进入解压目录修改配置文件harbor.cfg修改

  修改主机名,可以设置为本机的IP地址

hostname = 10.13.51.55

  修改数据挂载目录,默认为目录/data

 data_volume: /opt/data

  PS:1.10版本配置文件为harbor.yml 如果不设置https还需要注释配置文件中有关https配置

 

   

  配置docker

  地址和上面配置的地址一致

#因为docker默认使用的是https连接,而harbor默认使用http连接,所以需要修改docker配置标志insecure registry不安全仓库的主机!#当然,harbor也可以设置为https,这个后续文章中再列出操作方法吧!

#vim /usr/lib/systemd/system/docker.service
ExecStart=/usr/bin/dockerd --insecure-registry=10.13.51.55
#只加上--insecure-registry这个参数即可。#重启docker:
#systemctl daemon-reload
#systemctl restart docker.service

   设置可执行权限

chmod +x install.sh prepare

  

  执行安装脚本

./install.sh

  如果安装报错

install.sh:行78: ./prepare: 权限不够

  可能是可执行文件prepare权限不够

chmod +x prepare

  执行完毕生成docker-compose.yml文件在设置的数据目录也会生成对应文件

   如果镜像harbor-log在不停重启

   使用以下命令查看日志

sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper
sudo: unable to change expired password: Authentication token manipulation error
Changing password for root.

   解决方法

# 导出harbor-log容器
mkdir -p /tmp/harbor-log
cd /tmp/harbor-log
docker export harbor-log -o harbor-log.tar

# 解压tar包
tar xvfp harbor-log.tar

# 修改shadow文件的值
sed -i 's/:90:/:99999:/g' /tmp/harbor-log/etc/shadow

# 将修改后的shadow文件挂载到harbor-log容器内
mkdir -p /opt/harbor-log-etc/
cp /tmp/harbor-log/etc/shadow /opt/harbor-log-etc/shadow

# 修改docker-composr.yml文件,harbor-log容器的volumes配置,增加以下配置
      - type: bind
        source: /opt/harbor-log-etc/shadow
        target: /etc/shadow
# 重启harbor即可
docker-compose down
docker-compose up -d

  

  

 

  会自动下载镜像以及配置环境

  查看允许了6个容器

  容器的启动与关闭,在目录里面执行

docker-compose stop/start

  

  打开浏览器输入ip地址浏览

 

 

   登录默认用户名和密码是 admin/Harbor12345

 

  配置https登录

  修改配置

ui_url_protocol = https #设置https认证

ssl_cert = /data/cert/bbd100.com_bundle.crt #设置ssl证书位置
ssl_cert_key = /data/cert/bbd100.com.key

  其余安装配置方式与http方式相同

  

  使用

  push镜像

   新建用户

  新建项目common

  把刚刚创建的用户假如common项目

  为需要上传的镜像打tag

tag nginx:1.11.5 10.13.74.222/common/nginx

  nginx为镜像名 : 后面跟tag版本  放置在服务器10.13.74.222的项目common下命名为nginx

   push提交

docker push 10.13.74.222/common/nginx

  在web界面查看

 

 

  参考:https://www.cnblogs.com/huangjc/p/6266564.html

 

posted @ 2018-04-22 09:03  minseo  阅读(485)  评论(0编辑  收藏  举报