Harbor is an open source cloud native registry that stores, signs, and scans container images for vulnerabilities.
Harbor solves common challenges by delivering trust, compliance, performance, and interoperability. It fills a gap for organizations and applications that cannot use a public or cloud-based registry, or want a consistent experience across clouds.
系统安装运行需求和建议:
1. 一台独立的linux host centos 7.4,docker 17.03.0-ce+以上版本,docker-compose 1.10.0+ .
2. 下载Harbor离线安装包进行安装
3. 自定义Harbor服务器的域名:reg.yujianbo.vip
安装步骤:
1. 安装docker
yum remove -y docker docker-common docker-selinux docker-engine yum install -y yum-utils device-mapper-persistent-data lvm2 yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo yum makecache fast yum list docker-ce.x86_64 --showduplicates | sort -r #列出可以安装的docker版本 yum -y install docker-ce-17.06.2.ce #安装指定版本的dockermkdir -p /lib/systemd/system/docker.service.d cat > /lib/systemd/system/docker.service.d/docker.conf << ‘EOF‘ [Service] ExecStart= ExecStart=/usr/bin/dockerd --default-ulimit nofile=65536 EOF #--default-ulimit有bug,暂时无法放到/etc/docker/daemon.json里 mkdir -p /etc/docker/ mkdir -p /srv/docker/ cat > /etc/docker/daemon.json << EOF { "dns": [ "114.114.114.114", "8.8.8.8" ], "data-root": "/srv/docker/", "hosts": [ "unix:///var/run/docker.sock" ], "registry-mirrors": [ "https://0sr73mco.mirror.aliyuncs.com" ], "insecure-registries": [ "reg.yujianbo.vip" ] } EOF # "hosts": ["unix:///var/run/docker.sock","tcp://127.0.0.1:2375"], #"registry-mirrors": ["https://registry.docker-cn.com"],中国docker hub专用地址,docker官方提供 systemctl daemon-reload systemctl start docker systemctl enable docker docker info docker version
2.安装docker-compose
yum -y install python-pip pip install --upgrade pip pip install docker-compose docker-compose version
3.下载Harbor离线安装包进行安装
mkdir -p /srv/harbor/ wget https://storage.googleapis.com/harbor-releases/harbor-offline-installer-v1.5.2.tgz #去https://github.com/goharbor/harbor/releases查找stable版本,当前最新stable版本是v1.5.2 tar zxf harbor-offline-installer-v1.5.2.tgz cd harbor sed -i "s#hostname = reg.mydomain.com#hostname = reg.yujianbo.vip#g" harbor.cfg #修改harbor的hostname为咱们自定义的reg.yujianbo.vip sh install.sh #开始自动安装Harbor,直到成功
安装完成后可以通过http://reg.yujianbo.vip访问Harbor,默认账号密码:admin/Harbor12345
你没有公网域名解析的话可以在/etc/hosts中指定reg.yujianbo.vip和ip地址的对应关系
4.使用Harbor push images
docker login reg.yujianbo.vip #输入账号密码 docker pull nginx #从docker hub拉取最新的nginx镜像 docker tag nginx reg.yujianbo.vip/library/nginx docker push reg.yujianbo.vip/library/nginx #将nginx镜像push到我们的harbor的默认的library项目中去
#登陆http://reg.yujianbo.vip就可以在项目library中看到我们刚刚push上去的镜像了
5.配置Harbor使用微软的活动目录active directory进行登陆认证
#ldap://10.1.1.227是微软的DC服务器的地址
#cn=test,ou=AAA,dc=local,dc=com test是普通的用户,AAA是自定义建立的OU,dc=local,dc=com是域控制器的域名
#
#LDAP基础DN,指定只有在ou=AAA,dc=local,dc=com里面创建的用户才能登陆Harbor
#LDAP用户UID的属性:sAMAccountName
下图是微软的活动目录active directory的用户管理页面,其本质上也是一个LDAP服务器,
我个人比较倾向于将所有支持LDAP的服务都统一使用微软的活动目录active directory进行认证,方便企业管理
这样每个员工之开通一个账号就可以登陆公司的所有系统了,比如gitlab,禅道,路由器,防火墙,SVN,
6.使用阿里云的OSS代替默认的本地文件存储
cat /srv/harbor/common/templates/registry/config.yml ... storage: oss: accesskeyid: 填写你的具有阿里云oss权限账户的RAM的AccessKey ID accesskeysecret: 填写你的具有阿里云oss权限账户的RAM的AccessKey ID region: oss-cn-beijing endpoint: yujianbo-harbor.oss-cn-beijing.aliyuncs.com bucket: yujianbo-harbor secure: false ...
申请一个阿里云的OSS,创建一个bucket: yujianbo-harbor;在oss的信息中可以查看到endpoint地址;
region 需要你确定你是在哪个地区开通的OSS,可以在https://help.aliyun.com/document_detail/31837.html 查询;
使用阿里云oss可以避免存储的单点故障,阿里云oss还具有共享存储的特点
使用其他的存储类型可以参考: https://docs.docker.com/registry/configuration/#storage
7.Harbor服务的维护
如果只是想简单的重启Harbor服务,可以使用如下命令
docker-compose stop
docker-compose start
如果修改的配置文件想让新的配置文件生效,需要如下操作
docker-compose down -v ... vim /srv/harbor/harbor.cfg vim /srv/harbor/common/templates/registry/config.yml ... prepare docker-compose up -d
#上面是修改Harbor的配置文件及使用阿里云oss的存储配置文件
docker-compose ps命令可以方面的查看Harbor的各个组件是否正常的启动起来
docker-compose ps Name Command State Ports --------------------------------------------------------------------------------------------------------------------- harbor-adminserver /harbor/start.sh Up (healthy) harbor-db /usr/local/bin/docker-entr ... Up (healthy) 3306/tcp harbor-jobservice /harbor/start.sh Up harbor-log /bin/sh -c /usr/local/bin/ ... Up (healthy) 127.0.0.1:1514->10514/tcp harbor-ui /harbor/start.sh Up (healthy) nginx nginx -g daemon off; Up (healthy) 0.0.0.0:443->443/tcp, 0.0.0.0:4443->4443/tcp, 0.0.0.0:80->80/tcp redis docker-entrypoint.sh redis ... Up 6379/tcp registry /entrypoint.sh serve /etc/ ... Up (healthy) 5000/tcp
8.Harbor数据持久化的路径
数据默认存储: /data/
日志默认存储:/var/log/harbor/
9.启动Harbor的https功能
cat /srv/harbor/harbor.cfg ...... #set hostname hostname = reg.yujianbo.vip #set ui_url_protocol ui_url_protocol = https ...... #The path of cert and key files for nginx, they are applied only the protocol is set to https ssl_cert = /root/cert/reg.yujianbo.vip.crt ssl_cert_key = /root/cert/reg.yujianbo.vip.key ......
只需要配置三个地方:
ui_url_protocol = https
ssl_cert = /root/cert/reg.yujianbo.vip.crt
ssl_cert_key = /root/cert/reg.yujianbo.vip.key
10.Email settings
Email settings只是在使用harbor本地认证时,忘记密码或注册账号时用到,使用LDAP认证就不需要配置这个选项了
Harbor官网:https://goharbor.io/
Harbor github地址:https://github.com/goharbor/harbor
Harbor安装配置向导:https://github.com/goharbor/harbor/blob/master/docs/installation_guide.md
原文:https://www.cnblogs.com/yjb007/p/9532873.html