搭建harbor私有仓库
2-1、项目说明
Harbor是一个用于存储和分发Docker镜像的企业级Registry服务器,由VMware开源,其通过添加一些企业必需的功能特性,例如安全、标识和管理等,扩展了开源 Docker Distribution。作为一个企业级私有Registry服务器,Harbor 提供了更好的性能和安全。提升用户使用Registry构建和运行环境传输镜像的效率。Harbor支持安装在多个Registry节点的镜像资源复制,镜像全部保存在私有 Registry 中, 确保数据和知识产权在公司内部网络中管控,另外,Harbor也提供了高级的安全特性,诸如用户管理,访问控制和活动审计等
- vmware 官方开源服务: https://vmware.github.io/
- harbor 官方github 地址: https://github.com/vmware/harbor
- harbor 官方网址: https://goharbor.io/
- harbor 官方文档: https://goharbor.io/docs/
- github文档: https://github.com/goharbor/harbor/tree/master/docs
2-2、部署及测试
前提:清理存在的docker软件
[root@node1 ~]# yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-selinux \
docker-engine-selinux \
docker-engine

2-2-1、安装docker依赖
[root@node2 ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
2-2-2、安装docker的repo文件
[root@node2 ~]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
2-2-3、安装docker并启动
[root@node2 ~]# yum install -y docker-ce docker-ce-cli containerd.io
[root@node2 ~]# systemctl start docker
[root@node2 ~]# systemctl enable docker
2-2-4、修改配置文件
[root@node2 ~]# vim /etc/docker/daemon.json
{
"registry-mirrors": ["192.168.100.103"]
}
[root@node2 ~]# ystemctl daemon-reload
[root@node2 ~]# ystemctl restart docker
注:即使启用https后,103仍然需要配置该项内容,否则在用 docker login命令登录时会出错Error response from daemon: Get "https://harbor103.com/v2/": unauthorized: authentication required
2-2-5、安装docker-compose
#国内源下载docker-compose,github太慢
[root@node2 ~]# curl -L https://get.daocloud.io/docker/compose/releases/download/1.25.3/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
#授权
[root@node2 ~]# chmod +x /usr/local/bin/docker-compose
[root@node2 ~]# ll /usr/local/bin/docker-compose
-rwxr-xr-x 1 root root 17213176 Oct 16 15:31 /usr/local/bin/docker-compose
#查看是否生效
[root@node2 ~]# docker-compose --version
docker-compose version 1.25.3, build d4d1b42b
2-2-6、安装openssl
[root@node2 ~]# yum install openssl -y
2-2-7、修改hosts文件
[root@node2 ~]# echo "192.168.100.103 harbor103.org" >> /etc/hosts #客户端和服务器都配置
注:一定要带上`.org`,不要使用 `harbor103` 这样类似`hostname`的配置,否则使用`docker push`命令时会出现向`docker.io`推送镜像的情况导致出现,如下所示:
Using default tag: latest
The push refers to repository [docker.io/harbor103/test-public/alpine-amd64]
8d3ac3489996: Preparing
denied: requested access to the resource is denied
2-2-8、配置证书
#创建存放证书的目录
[root@node2 ~]# mkdir -p /data/cert
[root@node2 ~]# cd /data/cert
============================================
#生成证书颁发机构证书
#生成 CA 证书私钥
[root@node2 cert]# openssl genrsa -out ca.key 4096
#生成 CA 证书
[root@node2 cert]# openssl req -x509 -new -nodes -sha512 -days 3650 \
-subj "/C=CN/ST=Beijing/L=Beijing/O=example/OU=Personal/CN=harbor103.org" \
-key ca.key \
-out ca.crt
#注:CN改为自己设置的域名
#生成服务器证书
#生成私钥
[root@node2 cert]# openssl genrsa -out harbor103.org.key 4096
#生成证书签名请求
[root@node2 cert]# openssl req -sha512 -new \
-subj "/C=CN/ST=Beijing/L=Beijing/O=example/OU=Personal/CN=harbor103.org" \
-key harbor103.org.key \
-out harbor103.org.csr
#生成 x509 v3 扩展文件
[root@node2 cert]# cat > v3.ext <<-EOF
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
extendedKeyUsage = serverAuth
subjectAltName = @alt_names
[alt_names]
DNS.1=harbor103.org
DNS.2=harbor103
DNS.3=harbor
EOF
# 注:DNS.1是域名,DNS.2是去掉com,DNS.3是hostname,本次搭建103的hostname是harbor,该内容来自官网介绍
#使用 v3.ext 文件为您的 Harbor 主机生成证书
[root@node2 cert]# openssl x509 -req -sha512 -days 3650 \
-extfile v3.ext \
-CA ca.crt -CAkey ca.key -CAcreateserial \
-in harbor103.org.csr \
-out harbor103.org.crt[root@node2 cert]#
#将 harbor103.org.crt 转换为 harbor103.org.cert,供 Docker 使用
[root@node2 cert]# openssl x509 -inform PEM -in harbor103.org.crt -out harbor103.org.cert
#将服务器证书、密钥和 CA 文件复制到 Harbor 主机(103)上的 Docker 证书文件夹中
[root@node2 cert]# mkdir -p /etc/docker/certs.d/harbor103.org
[root@node2 cert]# cd /data/cert
[root@node2 cert]# cp harbor103.org.cert /etc/docker/certs.d/harbor103.org/
[root@node2 cert]# cp harbor103.org.key /etc/docker/certs.d/harbor103.org/
[root@node2 cert]# cp ca.crt /etc/docker/certs.d/harbor103.org/
#注:/etc/docker/certs.d/harbor103.com 该目录与域名保持一致,不要随意命名
#操作系统信任证书
[root@node2 cert]# cp harbor103.org.crt /etc/pki/ca-trust/source/anchors/harbor103.org.crt
[root@node2 cert]# update-ca-trust
#重启docker
[root@node2 cert]# systemctl restart docker
2-2-9、安装harbor
#下载地址:
官网:https://github.com/goharbor/harbor/releases
百度网盘链接:https://pan.baidu.com/s/1vBunW3IqADhGE0eke3q--g 提取码:2tve
#解压之opt下
[root@node2 ~]# tar xf harbor-offline-installer-v2.6.1.tgz -C /opt
#修改配置
[root@node2 ~]# cd /opt/harbor/
[root@node2 harbor]# cp harbor.yml.tmpl harbor.yml
[root@node2 harbor]# vim harbor.yml
hostname: harbor103.org #修改此行,指向当前主机IP 或 FQDN,建议配置IP
harbor_admin_password: 123456 #修改此行指定harbor登录用户admin的密码
data_volume: /data/harbor_data/ #指定存放数据的目录,建议放在独立的大容量快速磁盘或存储上
#注:data_volume最好使用独立的目录只保存harbor的数据
#安装
[root@node2 harbor]# ./install.sh
[Step 0]: checking if docker is installed ...
Note: docker version: 20.10.19
[Step 1]: checking docker-compose is installed ...
Note: docker-compose version: 1.25.3
[Step 2]: loading Harbor images ...
......
[Step 3]: preparing environment ...
[Step 4]: preparing harbor configs ...
......
[Step 5]: starting Harbor ...
......
----Harbor has been installed and started successfully.----

2-2-10、浏览器访问harbor 主机网站
用浏览器访问: http://192.168.100.103/
用户名: admin
密码: 即前面harbor.cfg中指定的密码



2-2-11、设置开机自启
#方法1:通过service文件实现
[root@node2 harbor]# vim /lib/systemd/system/harbor.service
[Unit]
Description=Harbor Service
After=docker.service systemd-networkd.service systemd-resolved.service
Requires=docker.service
Documentation=http://github.com/vmware/harbor
[Service]
Type=simple
Restart=on-failure
RestartSec=5
ExecStart=/usr/local/bin/docker-compose -f /opt/harbor/docker-compose.yml up
ExecStop=/usr/local/bin/docker-compose -f /opt/harbor/docker-compose.yml down
[Install]
WantedBy=multi-user.target
[root@node2 harbor]# systemctl daemon-reload
[root@node2 harbor]# systemctl restart harbor.service
#方法2: 通过 rc.local实现
[root@node2 harbor]# cat /etc/rc.local
#!/bin/bash
cd /apps/harbor
/usr/bin/docker-compose up
[root@node2 harbor]# chmod +x /etc/rc.local
2-2-12、Harbor 安全 Https 配置
#配置 Harbor 服务器使用证书
[root@node2 harbor]# vim harbor.yml
......
hostname: harbor103.org
......
# http related config
http:
# port for http, default is 80. If https enabled, this port will redirect to https port
port: 80
......
# https related config
https:
# https port for harbor, default is 443
port: 443
# The path of cert and key files for nginx
certificate: /data/cert/harbor103.org.crt #修改两行,指定证书和私钥的路径
private_key: /data/cert/harbor103.org.key
......
harbor_admin_password: 123456
......
data_volume: /data/harbor_data/
......
#使配置生效方法1:
[root@node2 harbor]# ./prepare # 根据 harbor.yml 配置生成docker-compose文件
prepare base dir is set to /opt/harbor
Clearing the configuration file: /config/portal/nginx.conf
......
[root@node2 harbor]# docker-compose down -v # 停止容器并移除存在的容器
Stopping harbor-jobservice ... done
Stopping nginx ... done
......
[root@node2 harbor]# docker-compose up -d # 启动docker容器
Creating network "harbor_harbor" with the default driver
Creating harbor-log ... done
......
#使配置生效方法2:
[root@node2 harbor]# systemctl stop harbor.service
[root@node2 harbor]# systemctl start harbor.service
=====================================================================================================
#访问http链接制动跳转到https
http://harbor.org
2-2-13、将证书发送给客户端
[root@node2 harbor]# scp /data/cert/ca.crt root@192.168.100.104:/etc/pki/ca-trust/source/anchors/
2-2-14、客户端测试推送镜像至harbor
[root@client ~]# ls /etc/pki/ca-trust/source/anchors # 查看证书是否存在
ca.crt
[root@client ~]# update-ca-trust extract #更新证书
[root@client ~]# systemctl restart podman #重启podman(docker)
[root@client ~]# docker login harbor103.org #登录
Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.
Username: admin
Password:
Login Succeeded!
[root@client ~]# docker pull alpine # 拉取dockerhub的镜像
[root@client ~]# docker tag alpine harbor103.org/test-public/alpine-testv1 # 打标签
[root@client ~]# docker push harbor103.org/test-public/alpine-testv1 #测试推送镜像到harbor私有仓库



2-2-15、参考链接
https://zhuanlan.zhihu.com/p/479716198
搭建harbor私有仓库的更多相关文章
- Centos7搭建Harbor私有仓库(二)
1 说明 前文Centos7搭建Harbor私有仓库(一)中成功搭建了Harbor,但,是以http方式搭建的,这里我们修改为https方式 以下基于镜像CentOS-7-x86_64-Minimal ...
- Centos7搭建Harbor私有仓库(一)
1 说明 前文Centos7搭建DockerRegistry介绍了DockerRegistry的搭建,但它没有UI页面,因此选择Harbor 以下基于镜像CentOS-7-x86_64-Minimal ...
- Docker-compose 搭建 Harbor私有仓库
一. 安装docker-compose 1. 下载docker-compose的最新版本 curl -L "https://github.com/docker/compose/release ...
- Docker以http访问Harbor私有仓库(一)
1 说明 前文Centos7搭建Harbor私有仓库(一)我们成功搭建Harbor,本篇我们主要配置Docker以http方式访问私有仓库 2 Docker配置 2.1 Mac系统 2.1.1 配置D ...
- Docker以https访问Harbor私有仓库(二)
1 说明 前文Centos7搭建Harbor私有仓库(二)中,我们以https方式搭建了Harbor,本篇我们主要配置Docker以https方式访问Harbor私有仓库 2 Docker配置 2.1 ...
- 搭建Harbor私有镜像仓库--v1.5.1
搭建Harbor私有镜像仓库--v1.5.1 1.介绍 Docker容器应用的开发和运行离不开可靠的镜像管理,虽然Docker官方也提供了公共的镜像仓库,但是从安全和效率等方面考虑,部署我们私有环境 ...
- Kubernetes-5:搭建企业级私有仓库Harbor
搭建企业级私有仓库Harbor 安装需求 python版本 >= 2.7 Docker引擎版本 >= 1.10 docker-compose版本 >= 1.6.0 安装环境 一.Py ...
- 创建Harbor私有仓库
前提 1.安装docker服务 参考:https://blog.csdn.net/weixin_36522099/article/details/108861134 老名字:docker.docker ...
- Docker Harbor私有仓库部署与管理 (超详细配图)
Docker Harbor私有仓库部署与管理 1.Harbor 介绍 2.Harbor部署 3.Harbor管理 1.Harbor 介绍: 什么是 Harbor ? Harbor 是 VMware 公 ...
随机推荐
- BeanUtils.copyProperties的使用方法
BeanUtils.copyProperties的使用方法 1.使用的是springframe包下的,BeanUtils.copyProperties(a,b) 把a属性拷贝给b属性 2.注意事项: ...
- 【java】学习路线3-二维数组声明与初始化、Arrays类
import java.util.Arrays;public class Learn02{ public static void main(String[] args){ Syst ...
- c++的一些笔记
--const 的一些用法 1,修饰指针 const int *p=.... 可以改变指针所指的位置,但不能改变指向位置的值. 2,修饰变量 int const * p=.... 可以改变指向位 ...
- Html飞机大战(六):移动飞机
好家伙,这篇移动主角 我们先来看看一个好东西, addEventListener() 方法 (他真的很好用) 我们直译一下,就叫他添加事件监听器方法 而可监听的对象就有很多啦 我们来了解一 ...
- alter role 导致的数据库无法登录问题
ALTER ROLE 用于更改一个数据库角色.只要改角色后续开始一个新会话,指定的值将会成为该会话的默认值,并且会覆盖 kingbase.conf中存在的值或者从命令行收到的值. 显性的更改角色的一 ...
- git hooks在业务中的使用
起因 最近公司项目发生了一起线上事故,最后排查下来是配置文件的问题.项目里application.yml文件内会用@build.time@记录打包时的时间,但是这个写法是build-helper-ma ...
- 运维利器-ClusterShell
前言 和ansible类似,但是更加高效 安装 yum install -y clustershell clush命令: clush -a 全部 等于 clush -g all clush -g 指定 ...
- C++ 二级指针与 const 关键字
可用七种不同的方式将 const 关键字用于二级指针,如下所示: //方式一:所指一级指针指向的数据为常量,以下几种为等效表示 const int ** pptc; //方式一 int const * ...
- PLSQL Developer安装详细步骤,小白,转发
下载软件可以直接在百度网盘里面下载 链接:https://pan.baidu.com/s/1bZNJ71d2-hvkM6PTbdpgAA 提取码:t9sh 然后直接参考这个链接进行安装https:// ...
- 【微服务】Nacos初体验
SpringCloud - Nacos初体验 生命不息,写作不止 继续踏上学习之路,学之分享笔记 总有一天我也能像各位大佬一样 一个有梦有戏的人 @怒放吧德德 分享学习心得,欢迎指正,大家一起学习成长 ...