harbor基于http和https的创建与使用
admin
2023-02-22 18:20:04
0

一·http方式

 harbor项目现托管在github上面,在此处以harbor v1.7.5为例演示。
  1·将harbor的二进制包下载到/usr/local/src目录下
  2·解压缩 tar xvf harbor.v.1.7.5.tar
  3·进如到解压harbor目录中,修改harbor.cfg文件

 1 ## Configuration file of Harbor
  2 
  3 #This attribute is for migrator to detect the version of the .cfg fil    e, DO NOT MODIFY!
  4 _version = 1.7.0
  5 #The IP address or hostname to access admin UI and registry service.
  6 #DO NOT use localhost or 127.0.0.1, because Harbor needs to be access    ed by external clients.
  7 #DO NOT comment out this line, modify the value of "hostname" directl    y, or the installation will fail.
  8 hostname = 192.168.238.7
  9 
 10 #The protocol for accessing the UI and token/notification service, by     default it is http.
 11 #It can be set to https if ssl is enabled on nginx.
 12 ui_url_protocol = http
 13 
 14 #Maximum number of job workers in job service  
 15 max_job_workers = 10 
 ...
 58 email_server = smtp.mydomain.com
 59 email_server_port = 25
 60 email_username = sample_admin@mydomain.com
 61 email_password = abc
 62 email_from = admin 
 63 email_ssl = false
 64 email_insecure = false
 65 
 66 ##The initial password of Harbor admin, only works for the first time     when Harbor starts. 
 67 #It has no effect after the first launch of Harbor.
 68 #Change the admin password from UI after launching Harbor.
 69 harbor_admin_password = 123456

  主要修改hostname和adminpasswd。
  4·查看install.sh文件,查看安装harbor所需环境

#!/bin/bash

#docker version: 1.11.2 
#docker-compose version: 1.7.1 
#Harbor version: 0.4.0 

  此为最低版本要求,docker的安装可以在阿里镜像站按照步骤一步步安装,但是docker-compose若是要安装最新版本就需要下载python-pip一个类似yum或apt的工具,然后在使用pip install docker-compose安装即可
  5·运行install.sh脚本安装,至此,安装完成

  • 我们上传的镜像会存放在宿主机的docker/registry/v2/repositories/
  • 需要上传和下载harbor镜像的docker服务器需要在docker的启动脚本中添加信任不可靠的镜像原
    vim /lib/systemd/system/docker.service
    ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock --insecure-registry 192.168.238.12(harbor地址)
    • 重启docker
    • 上传镜像时首先要登陆到harbor服务器
      docker login 192.168.238.7
      输入账号为admin密码为harbor.cfg中所配置密码登陆成功,然后对制作的镜像重新打tag,例如
      tag nginx:laste 192.168.238.7/NGINX/nginx:5.2
      其中NGINX必须要有这个项目方可上传
    • 在网页打开192.168.238.7,输入账号密码,创建NGINX项目
    • docker push 192.168.238.7/NGINX/nginx:5.2

        2·实现高可用的harbor

          1·配置同上新建一个harbor服务
          2·在docker的启动脚本中加上两个harbor服务器的地址
          3·在主harbor服务器的网页上做如下操作

      按照提示一步步添加另一台harbor

二·https方式

 1·如上http方式部署。只是不用在docker的启动脚本中添加受信任的地址
 2.在harbor的安装目录下创建一个certs目录
mkdir certs
 3·生成私钥和公钥(注:公钥的地址要与harbor.cfg中的hostname相同)
openssl genrsa -out harbor-ca.key
touch /root/.rnd
openssl req -x509 -new -nodes -key harbor-ca.key -subj "/CN=harbor.magedu.net" -days 7120 -out harbor-ca.crt
 4·修改harbor.cfg配置文件

  1 ## Configuration file of Harbor
  2 
  3 #This attribute is for migrator to detect the version of the .cfg fil    e, DO NOT MODIFY!
  4 _version = 1.7.0
  5 #The IP address or hostname to access admin UI and registry service.
  6 #DO NOT use localhost or 127.0.0.1, because Harbor needs to be access    ed by external clients.
  7 #DO NOT comment out this line, modify the value of "hostname" directl    y, or the installation will fail.
  8 hostname = harbor.magedu.net
  9 
 10 #The protocol for accessing the UI and token/notification service, by     default it is http.
 11 #It can be set to https if ssl is enabled on nginx.
 12 ui_url_protocol = https
13 
 14 #Maximum number of job workers in job service  
 15 max_job_workers = 10 
 16 
 17 #Determine whether or not to generate certificate for the registry's     token.
 18 #If the value is on, the prepare script creates new root cert and pri    vate key 
 19 #for generating token to access the registry. If the value is off the     default key/cert will be used.
 20 #This flag also controls the creation of the notary signer's cert.
 21 customize_crt = on
 22 
 23 #The path of cert and key files for nginx, they are applied only the     protocol is set to https
 24 ssl_cert = /usr/local/src/harbor/certs/harbor-ca.crt
 25 ssl_cert_key = /usr/local/src/harbor/certs/harbor-ca.key
 26 
 *67 #It has no effect after the first launch of Harbor.
 68 #Change the admin password from UI after launching Harbor.
 69 harbor_admin_password = 123456
*

这个域名要有dns解析或者是hosts文件
 5·docker客户端分发公钥
mkdir -p /etc/docker/certs.d/(harbor.cfg中的hostname)
将harbor的公钥拷贝过来 /etc/docker/certs.d/(harbor.cfg中的hostname)重启docker即可

相关内容

热门资讯

男子称爷爷向天津美院捐赠40件... 近日,康先生在社交平台发布视频称,其爷爷康建章于1996年向天津美术学院捐赠的40件书画作品,自己希...
以军总参谋长:在伊朗仍有一系列... △以色列国防军总参谋长扎米尔(资料图)当地时间5月6日,以色列国防军总参谋长扎米尔表示,以军与美军的...
为什么说全世界都在“占中国的便... 身边的“洋面孔”越来越多了。2025年,入境外国游客人数为3517万人次,同比增长30.5%。入境游...
伊朗消息人士:美方提议包含不可... 当地时间6日,伊朗消息人士表示,伊朗尚未回应美国方面的最新提议,因为该提议包含一些不可接受的条款。他...
中国“四大发明”的历史遗憾,会... 导语:2026年初,美国国防部发布“人工智能战略”备忘录,将AI建设重心聚焦于作战、情报和企业三大方...
2026年深圳微信商城小程序公... 在数字化转型浪潮中,微信商城小程序已成为企业连接用户、拓展业务的关键载体。然而,面对市场上众多的小程...
原创 雷... 前小米技术一号位崔宝秋,休养一年多,重走创业路。 证明自己不只是「雷军的老同学」? 2026年的具...
伊朗:若美方不作出必要让步,已... △伊朗首都德黑兰(资料图)当地时间6日,伊朗议会国家安全与外交政策委员会发言人易卜拉欣·雷扎伊在社交...
戏韵新章,薪火永续——2026... 弦歌渐歇,余韵绵长。5月4日,“一出好戏·四市联动”2026豫剧文化艺术周在主会场许昌曹魏古城圆满落...
天迈科技收购预案公布!切入工业... 【大河财立方消息】 5月6日,天迈科技披露发行股份及支付现金购买资产并募集配套资金暨关联交易预案。根...