什么是Harbor:
Harbor官方介绍这里就不照搬了,说直白点:Harbor就是私有的 Docker Hob 镜像仓库。
如何安装:
Harbor 可以安装在任何 Kubernetes 环境上,也可以安装在有 Docker 支持的系统上。我们这次主要讲述虚拟机中如何安装。
安装步骤:
一、虚拟机中安装docker-ce,这里我们使用阿里云官方镜像站的资源来安装
- 选择镜像站中的
docker-ce - 选择合适你系统的安装步骤(我们这里使用的是centos7)
# step 1: 安装必要的一些系统工具
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
# Step 2: 添加软件源信息
sudo yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# Step 3
sudo sed -i 's+download.docker.com+mirrors.aliyun.com/docker-ce+' /etc/yum.repos.d/docker-ce.repo
# Step 4: 更新并安装Docker-CE
sudo yum makecache fast
sudo yum -y install docker-ce
# Step 4: 开启Docker服务
sudo systemctl start docker
# Step 5: 设置开机自起
sudo systemctl enable docker
二、安装docker-compose
> 我们这里使用1大版本,1和2的区别主要命令上有很大差别,关于差别查看[推荐文章](https://blog.csdn.net/hanxiaotongtong/article/details/125477514)
```bash
# Step 1: 下载docker-compose执行文件
wget https://github.com/docker/compose/releases/download/v2.14.0/docker-compose-linux-x86_64
# Step 2: 将执行文件改名后移动到/usr/bin目录下(这个目录你可以选择$PATH下的任意一个目录)
mv docker-compose-linux-x86_64 /usr/bin/docker-compose
# Step 3: 检查是否安装成功(能打印出版本号说明安装OK)
docker-compose --version
# -> docker-compose version 1.25.0, build 0a186604
```
三、安装harbor离线包(在线安装形式不稳定,由于网络原因中间可能中断)
- 下载安装包
# 直接下载我们选中版本的离线包(直接在浏览器中右键选中复制链接)
wget https://github.com/goharbor/harbor/releases/download/v2.5.6/harbor-offline-installer-v2.5.6.tgz
- 准备证书(这里没有证书也可以使用IP进行访问,不是必需的) 我这里使用数字证书管理服务申请免费证书
- 解压已经下载的包
# Step 1: 解Harbor离线安装包
tar xf harbor-offline-installer-v2.5.6.tgz
# Step 2: 解压证书文件
unzip 9714287_docker.windteam.cn_nginx.zip
- 进入
harbor目录,重命令harbor配置文件
这里的harbor文件夹是
harbor-offline-installer-v2.5.6.tgz解压后得到的
# Step 1: 修改配置文件名称
mv harbor.yml.tmp harbor.yml
- 编辑
harbor.yml配置文件
# Configuration file of Harbor
# The IP address or hostname to access admin UI and registry service.
# DO NOT use localhost or 127.0.0.1, because Harbor needs to be accessed by external clients.
-hostname: reg.mydomain.com
+hostname: docker.windteam.cn
# 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: /your/certificate/path
+ certificate: /home/harbor/docker.windteam.cn.pem
- private_key: /your/private/key/path
+ private_key: /home/harbor/docker.windteam.cn.key
# # Uncomment following will enable tls communication between all harbor components
# internal_tls:
# # set enabled to true means internal tls is enabled
# enabled: true
# # put your cert and key files on dir
# dir: /etc/harbor/tls/internal
# Uncomment external_url if you want to enable external proxy
# And when it enabled the hostname will no longer used
# external_url: https://reg.mydomain.com:8433
# The initial password of Harbor admin
# It only works in first time to install harbor
# Remember Change the admin password from UI after launching Harbor.
- harbor_admin_password: Harbor12345
+ # 这里的是admin账户的密码,要在启动前改动,否则后期改动无效
+ harbor_admin_password: Aaron.1024
# Harbor DB configuration
...
- 启动harbor
# Step 1: 进入harbor目录(之前解压后的目录,我将其放在了/home下,因为这个分区的磁盘空间较大)
cd /home/harbor
# Step 2: 执行prepare命令,进入准备启动阶段,这里会检测你的环境等
./prepare
# Step 3: 准备阶段完成后,启动下载harbor,这里会下载并运行7个镜像
./install.sh
- 使用
docker ps查看是否启动(STATUS均为healthy为成功,starting说明在启动中)
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fec9daf602cc goharbor/harbor-jobservice:v2.4.1 "/harbor/entrypoint.…" 32 seconds ago Up 32 seconds (healthy) harbor-jobservice
4150f1314c77 goharbor/nginx-photon:v2.4.1 "nginx -g 'daemon of…" 32 seconds ago Up 31 seconds (healthy) 0.0.0.0:80->8080/tcp, :::80->8080/tcp, 0.0.0.0:443->8443/tcp, :::443->8443/tcp nginx
e8e2b4c293e6 goharbor/harbor-core:v2.4.1 "/harbor/entrypoint.…" 33 seconds ago Up 32 seconds (healthy) harbor-core
4ba581159770 goharbor/redis-photon:v2.4.1 "redis-server /etc/r…" 34 seconds ago Up 33 seconds (healthy) redis
e05ade0f6b01 goharbor/harbor-registryctl:v2.4.1 "/home/harbor/start.…" 34 seconds ago Up 33 seconds (healthy) registryctl
22e759590987 goharbor/harbor-db:v2.4.1 "/docker-entrypoint.…" 34 seconds ago Up 33 seconds (healthy) harbor-db
102de7c3f1f9 goharbor/registry-photon:v2.4.1 "/home/harbor/entryp…" 34 seconds ago Up 33 seconds (healthy) registry
6ca874d0ef64 goharbor/harbor-portal:v2.4.1 "nginx -g 'daemon of…" 34 seconds ago Up 33 seconds (healthy) harbor-portal
e4492e3a2ce5 goharbor/harbor-log:v2.4.1 "/bin/sh -c /usr/loc…" 35 seconds ago Up 34 seconds (healthy) 127.0.0.1:1514->10514/tcp harbor-log
- 通过域名进行访问harbor
我这里使用的是内网虚拟机,所以访问harbor这台机器上需要配置本机hosts 将域名解析到部署harbor的服务器IP上
- 绑定harbor地址,并推送私有镜像到harbor上
这里我们只是简单的演示,真事的项目中是通过Dockerfile打出的镜像来做推送
# Step 1: 在要使用harbor的主机上创建 /etc/docker/daemon.json 文件
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": [https://docker.windteam.cn"]
}
EOF
# Step 2: 重启daemon
systemctl daemon-reload
# Step 3: 重启docker
systemctl restart docker
# Step 4: 登陆harbor(注意:docker login harbor的地址)
docker login docker.windteam.cn
# Step 5: 对本地镜像进行打tag(我以centos镜像为例,因为我本地正好有这个镜像)
docker tag centos:latest docker.windteam.cn/library/mycentos:v1
# Step 6: push打好tag的镜像到harbor上的library项目中(如果是没有的项目需要创建后再推送)
docker push docker.windteam.cn/library/mycentos:v1
其他相关问题
一、机器重启后harbor镜像启动失败或只有部分start
- 在
/etc/systemd/system目录下创建harbor.service文件(名字随意),内容如下
因为我的harbor放在了
/home/harbor目录下,如果你的目录不是这个请更改为自己的目录地址
[Unit]
Description=Harbor
After=docker.service systemd-networkd.service systemd-resolved.service
Requires=docker.service
[Service]
Type=simple
Restart=on-failure
RestartSec=5
ExecStart=/usr/bin/docker-compose -f /home/harbor/docker-compose.yml up
ExecStop=/usr/bin/docker-compose -f /home/harbor/docker-compose.yml down
[Install]
WantedBy=multi-user.target
- 将
/etc/systemd/system/harbor.service文件设置为开机自启
systemctl enable harbor.service
ps: 更多Systemd(Service文件)详解可以参考这个文章:blog.csdn.net/Mr_Yang__/a…