harbor仓库部署
1.Harbor简介
Harbor是一个用于存储和分发Docker镜像的企业级Registry服务器,可以用来构建企业内部的Docker镜像仓库。
它在Docker的开源项目 Distribution的基础上,添加了一些企业需要的功能特性,如镜像同步复制、漏洞扫描和权限管理等。
它的主要功能包括:
- 基于角色的访问控制:用户和存储库通过“项目”进行组织,用户可以对项目下的图像具有不同的权限。
- 基于策略的映像复制:可以在多个注册表实例之间复制(同步)映像,并在出现错误时自动重试。非常适合负载平衡、高可用性、多数据中心、混合和多云方案。
- 漏洞扫描:Harbor定期扫描图像并警告用户漏洞。
- LDAP/AD 支持:Harbor 与现有的企业 LDAP/AD 集成,用于用户身份验证和管理。
- 图像删除和垃圾回收:可以删除图像,并且可以回收其空间。
- 公证:可以确保图像的真实性。
- 图形用户门户:用户可以轻松浏览、搜索存储库和管理项目。
- 审计:跟踪对存储库的所有操作。
- RESTful API:支持大多数管理操作的RESTful API,易于与外部系统集成。
- 易于部署:提供在线和离线安装程序。
Docker compose
Harbor在物理机上部署是非常难的,而为了简化Harbor的应用,Harbor官方直接把Harbor做成了在容器中运行的应用,而且这个容器在Harbor中依赖类似redis、mysql、pgsql等很多存储系统,所以它需要编排很多容器协同起来工作,因此VMWare Harbor在部署和使用时,需要借助于Docker的单机编排工具(Docker compose)来实现。
2.所需的部署条件
需要安装docker,有docker-compose命令
安装docker
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# wget https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repo
[root@localhost yum.repos.d]# sed -i 's@https://download.docker.com@https://mirrors.tuna.tsinghua.edu.cn/docker-ce@g' docker-ce.repo
[root@localhost yum.repos.d]# dnf -y install docker-ce
配置镜像加速器
[root@localhost yum.repos.d]# sudo mkdir -p /etc/docker
[root@localhost yum.repos.d]# sudo tee /etc/docker/daemon.json <<-'EOF'
> {
> "registry-mirrors": ["https://6wh26kc0.mirror.aliyuncs.com"]
> }
> EOF
{
"registry-mirrors": ["https://6wh26kc0.mirror.aliyuncs.com"]
}
[root@localhost yum.repos.d]# sudo systemctl daemon-reload
[root@localhost yum.repos.d]# sudo systemctl restart docker
[root@localhost yum.repos.d]# systemctl enable docker
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /usr/lib/systemd/system/docker.service.
安装docker-compose
//修改名称
[root@localhost ~]# hostnamectl set-hostname harbor.example.com
[root@localhost ~]# bash
[root@harbor ~]# hostname
harbor.example.com
//安装docker-compose命令
[root@harbor ~]# ls -a
. .bash_history .bash_profile .config .tcshrc anaconda-ks.cfg
.. .bash_logout .bashrc .cshrc .wget-hsts
[root@harbor ~]# DOCKER_CONFIG=${DOCKER_CONFIG:-$HOME/.docker}
[root@harbor ~]# mkdir -p $DOCKER_CONFIG/cli-plugins
[root@harbor ~]# ls -a
. .bash_history .bash_profile .config .docker .wget-hsts
.. .bash_logout .bashrc .cshrc .tcshrc anaconda-ks.cfg
[root@harbor ~]# cd .docker/
[root@harbor .docker]# ls
cli-plugins
[root@harbor .docker]# curl -SL https://github.com/docker/compose/releases/download/v2.7.0/docker-compose-linux-x86_64 -o $DOCKER_CONFIG/cli-plugi