Harbor企业级私有镜像仓库搭建(保姆级教程)

        Harbor是VMware公司开源的企业级Registry项目,可以帮助用户快速搭建一个企业级的镜像仓库。harbor由python语言开发,需要使用docker-compose工具进行启动。

1、设置harbor服务器主机名为harbor.cn

[root@localhost ~]# hostnamectl set-hostname harbor.cn

2、关闭harbor服务器防火墙、禁用SELinux

[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# setenforce 0

3、设置harbor服务器ntpdate时间同步

[root@harbor ~]# ntpdate 182.92.12.11
26 Feb 01:22:20 ntpdate[1442]: adjust time server 182.92.12.11 offset -0.000552 sec
[root@harbor ~]# systemctl start ntpd
[root@harbor ~]# systemctl enable ntpd
Created symlink from /etc/systemd/system/multi-user.target.wants/ntpd.service to /usr/lib/systemd/system/ntpd.service.

4、安装docker-compose

        Harbor是通过docker-compose来部署的,这也是为什么在装harbor前需要安装docker-compose,docker-compose项目是docker官方的开源项目,负责实现对docker容器集群的快速编排。compose、machine和swarm是docker原生提供的三大编排工具。

        docker可以看做集装箱把杂乱的货物一个个整理归类,compose则是用于编排这些集装箱,最后swarm就是多提供几条船,挂掉一两条还能继续运输,提高稳定性。

        Compose使用的三个步骤:

  • 使用Dockerfile定义应用程序的环境
  • 使用docker-compose.yml定义构成应用程序的服务,这样它们可以在隔离环境中一起运行
  • 最后,执行docker-compose up命令来启动并运行整个应用程序
[root@harbor ~]# curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
[root@harbor ~]# chmod +x /usr/local/bin/docker-compose 
[root@harbor ~]# docker-compose -v
docker-compose version 1.29.2, build 5becea4c

 5、安装docker-ce并启动

[root@harbor ~]# wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo
[root@harbor ~]# yum install docker-ce
[root@harbor ~]# systemctl start docker
[root@harbor ~]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.

6、安装harbor私有镜像仓库(已经事先将harbor离线包传至opt目录)

解压文件至/usr/local目录,切换至解压目录,编辑harbor配置文件,并执行install.sh

[root@harbor opt]# tar -xf harbor-offline-installer-v1.10.10.tgz -C /usr/local/
[root@harbor opt]# cd /usr/local/harbor/
[root@harbor harbor]# vi harbor.yml
[root@harbor harbor]# ./install.sh

 

 若安装过程中出现上图错误则注释如下图配置(harbor.yml)

 

安装完成 

 

 7、开启IP转发功能

[root@harbor harbor]# vi /etc/sysctl.conf
[root@harbor harbor]# sysctl -p
net.ipv4.ip_forward = 1

8、 在宿主机打开浏览器输入harbor服务器地址(本次环境使用桥接模式),默认账户密码admin/Harbor12345

 

9、镜像上传至仓库实例 

 

docker tag SOURCE_IMAGE[:TAG] 192.168.1.17/testproject-repo/IMAGE[:TAG]

docker push 192.168.1.17/testproject-repo/IMAGE[:TAG] 

#登陆harbor仓库
[root@harbor harbor]# docker login -u admin -p Harbor12345 http://127.0.0.1/
#给镜像打上标签
[root@harbor harbor]# docker tag hello-world 127.0.0.1/testproject-repo/hello-world:latest
#将镜像推送至仓库
[root@harbor harbor]# docker push 127.0.0.1/testproject-repo/hello-world:latest

  • 3
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值