Harbor可以通过Docker Composer的方式来部署,如果有正常运行的k8s环境,也可以使用k8s来部署Harbor,本文采用 Docker Composer的方式。 


准备

  Linux系统为Centos 7。

docker ,默认安装即可
yum -y install docker

安装 docker compose 
curl -L https://github.com/docker/compose/releases/download/1.18.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose


安装包到github下载

导入 harbor 镜像

解压harbor离线安装包

tar -xzvf harbor-offline-installer-v1.3.0.tgz

进入harbor目录

cd harbor

有如下文件:

导入harbor镜像

docker load -i harbor.v1.3.0.tar.gz

如果提示:Cannot connect to the Docker daemon. Is the docker daemon running on this host? 是因为docker服务未启动,使用systemctl start docker命令运行docker。

修改 harbor 配置

编辑 harbor.cfg文件

vi harbor.cfg


修改hostname为自己机器的ip地址

hostname = 192.168.100.101

harbor还有很多配置项可以修改,来满足一些企业级的功能特性,比如可以使用https来保证文件传输的安全。

安装与启动

执行 install.sh 脚本

./install.sh

等待安装完成:

[Step 0]: checking installation environment ...

Note: docker version: 1.12.6

Note: docker-compose version: 1.18.0

[Step 1]: loading Harbor images ...
Loaded image: vmware/harbor-adminserver:v1.3.0
Loaded image: vmware/photon:1.0
Loaded image: vmware/notary-photon:signer-0.5.1
Loaded image: vmware/postgresql:9.6.5-photon
Loaded image: vmware/harbor-db-migrator:1.3
Loaded image: vmware/harbor-ui:v1.3.0
Loaded image: vmware/harbor-log:v1.3.0
Loaded image: vmware/nginx-photon:1.11.13
Loaded image: vmware/mariadb-photon:10.2.10
Loaded image: vmware/clair:v2.0.1-photon
Loaded image: vmware/harbor-db:v1.3.0
Loaded image: vmware/harbor-jobservice:v1.3.0
Loaded image: vmware/registry:2.6.2-photon
Loaded image: vmware/notary-photon:server-0.5.1


[Step 2]: preparing environment ...
Clearing the configuration file: ./common/config/adminserver/env
Clearing the configuration file: ./common/config/ui/env
Clearing the configuration file: ./common/config/ui/app.conf
Clearing the configuration file: ./common/config/ui/private_key.pem
Clearing the configuration file: ./common/config/db/env
Clearing the configuration file: ./common/config/jobservice/env
Clearing the configuration file: ./common/config/jobservice/app.conf
Clearing the configuration file: ./common/config/registry/config.yml
Clearing the configuration file: ./common/config/registry/root.crt
Clearing the configuration file: ./common/config/nginx/cert/harbor.pem
Clearing the configuration file: ./common/config/nginx/cert/harbor-key.pem
Clearing the configuration file: ./common/config/nginx/nginx.conf
Clearing the configuration file: ./common/config/log/logrotate.conf
loaded secret from file: /data/secretkey
Generated configuration file: ./common/config/nginx/nginx.conf
Generated configuration file: ./common/config/adminserver/env
Generated configuration file: ./common/config/ui/env
Generated configuration file: ./common/config/registry/config.yml
Generated configuration file: ./common/config/db/env
Generated configuration file: ./common/config/jobservice/env
Generated configuration file: ./common/config/log/logrotate.conf
Generated configuration file: ./common/config/jobservice/app.conf
Generated configuration file: ./common/config/ui/app.conf
Generated certificate, key file: ./common/config/ui/private_key.pem, cert file: ./common/config/registry/root.crt
The configuration files are ready, please use docker-compose to start the service.

Creating harbor-log ... done
[Step 3]: checking existing instance of Harbor ...

Creating registry ... done
Creating harbor-ui ... done
Creating network "harbor_harbor" with the default driver
Creating nginx ... done
Creating harbor-adminserver ... 
Creating harbor-db ... 
Creating registry ... 
Creating harbor-ui ... 
Creating harbor-jobservice ... 
Creating nginx ... 

✔ ----Harbor has been installed and started successfully.----

Now you should be able to visit the admin portal at https://192.168.22.83. 
For more details, please visit https://github.com/vmware/harbor .
 

  在浏览器中输入ip地址:http://192.168.100.101,用户名:admin 密码:Harbor12345(可以harbor.cfg文件中设置) ,登录看到barbor的图像界面: 


 

因为Harbor开启的是HTTP服务, 而不是HTTPS, 所以要修改下Docker的配置:/etc/docker/daemon.json, 添加参数insecure-registries:

[root@harbor01 ~]# cat /etc/docker/daemon.json
 

{
  "bip":"169.254.0.1/24",  #docker网段
  "registry-mirrors": [    #镜像源
      "https://4z5sbngt.mirror.aliyuncs.com",
      "https://i3nc9nvv.mirror.aliyuncs.com",
      "https://docker.m.daocloud.io",
      "https://dockerhub.timeweb.cloud"
  ]
  "insecure-registries": ["192.168.100.101"]  #harbor私有仓库
}

  harbor 安装成功后,可以分别通过以下命令来停止启动(注意:需要在上面提到的harbor目录中执行)

docker-compose down -v
//停止

docker-compose up -d
//启动

镜像的Push和Pull


为了使用Harbor我们需要在Harbor上建立一个项目:kubernetes 

注意: 一定要先有项目 然后按照192.168.100.101/{project-name}/{image-name}[:Tag] 的方式打Tag

(a). 建好项目后, 我们先测试下能否Login Harbor

[root@harbor01 harbor]# docker login 192.168.100.101
Username: admin
Password:
Login Succeeded
1
2
3
4
(b). 然后为我们的镜像打上相应的标签, 注意标签格式: 192.168.100.101/{project-name}/{image-name}[:Tag]

[root@harbor01 ~]# docker tag docker.io/nginx:latest 192.168.100.101/kubernetes/nginx:v1.10
[root@harbor01 ~]# docker push 192.168.100.101/kubernetes/nginx:v1.10
The push refers to a repository [192.168.100.101/kubernetes/nginx]
a103d141fc98: Pushed
73e2bd445514: Pushed
2ec5c0a4cb57: Pushed
v1.10: digest: sha256:926b086e1234b6ae9a11589c4cece66b267890d24d1da388c96dd8795b2ffcfb size: 948
1
2
3
4
5
6
7
(c). 最后在另一台机器上面拉取镜像(记得配置Docker客户端insecure-registries参数, 参考上面):

~/Blogs » docker pull 192.168.100.101/kubernetes/nginx:v1.10                                                                                                    
v1.10: Pulling from kubernetes/nginx
e7bb522d92ff: Pull complete
6edc05228666: Pull complete
cd866a17e81f: Pull complete
Digest: sha256:926b086e1234b6ae9a11589c4cece66b267890d24d1da388c96dd8795b2ffcfb
Status: Downloaded newer image for 192.168.100.101/kubernetes/nginx:v1.10
 

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐