测试开发技术网站
博客
设计
设计
开发
Python
测试
unittest
运维
Linux基础应用
CI/CD
CI/CD
数据库
数据库
云计算
云计算
云原生
云原生
爬虫
爬虫
数据分析
数据分析
人工智能
人工智能
登录
注册
Harbor----使用 Harbor 安装包安装部署 Harbor
收藏本文
作者:redrose2100 类别: 日期:2022-08-09 09:44:23 阅读:1533 次 消耗积分:0 分
[TOC] # 一、Harbor安装准备条件 这里以 harbor 2.5.3 版本为例 ## 1.1 硬件要求 Harbor 安装对硬件资源CPU、内存和硬盘的要求如下表: |资源|最小要求|推荐配置| |:--:|:--:|:--:| |CPU|2 CPU|4 CPU| |Mem|4 GB|8 GB| |Disk|40 GB|160 GB| 使用如下命令分别查看服务器的物理CPU和逻辑CPU个数 ```bash # 查看物理CPU个数 cat /proc/cpuinfo |grep "physical id"|sort |uniq|wc -l # 查看逻辑CPU个数 cat /proc/cpuinfo |grep "processor"|wc -l # 查看内存 free -h # 查看地盘 df -h ``` ## 1.2 软件要求 harbor 2.5.3 版本对docker、docker-compose等软件的要求 |软件|版本号| |:--:|:--:| |docker|17.06.0 及以上| |docker-compose|1.18.0 及以上| |openssl| ## 1.3 网络端口要求 harbor 2.5.3 版本对网络端口的要求如下表 |端口|协议|描述| |:--:|:--:|:--:| |443|https|https端口,可以从配置文件中修改| |4443|https|当notary打开时使用,否则不需要使用,可以通过配置文件修改| |80|http|http端口,可以从配置文件中修改| # 二、下载 Harbor 的安装包文件 ## 2.1 Harbor 安装包分类 Harbor 的安装文件分为在线安装包和离线安装包 * 在线安装包: 在线安装包从 docker Hub 下载镜像,因此安装包文件比较小,适用于安装服务器能联网的场景下 * 离线安装包: 离线安装包包含了预先编译好的镜像文件,因此安装文件较大,适用于安装服务器未联网的场景下 ## 2.2 下载并解压安装包 (1) 打开 [Harbor发布网站](https://github.com/goharbor/harbor/releases "Harbor发布网站") 挑选合适的版本,比如这里选择 v2.5.3 版本,点击 【v2.5.3】,进入发布附件页面,如下: ![](http://blog.redrose2100.com/static/upload/20220809_083854.png) (2) 选择版本,如果服务器能联网,则右键复制链接,如果服务器不能联网,则只能点击下载,然后手工将安装包上传至服务器 ![](http://blog.redrose2100.com/static/upload/20220809_085745.png) (3) 如服务器能联网,则到服务器直接使用wget 下载,命令如下: ```bash # 下载在线安装版 wget https://github.com/goharbor/harbor/releases/download/v2.5.3/harbor-online-installer-v2.5.3.tgz # 下载离线安装版 wget https://github.com/goharbor/harbor/releases/download/v2.5.3/harbor-offline-installer-v2.5.3.tgz ``` (4) 解压 ```bash # 解压在线安装版 tar -zxvf harbor-online-installer-v2.5.3.tgz # 解压离线安装版 tar -zxvf harbor-offline-installer-v2.5.3.tgz ``` # 三、配置安装 Harbor ## 3.1 安装基于 http 协议访问的默认的 Harbor 默认安装命令没有启用 Notary, Trivy 和 Chart Repository Service。 * Notary:镜像签名认证 * Trivy: 容器漏洞扫描 * Chart Repository Service: Helm chart 仓库服务 一般在内网的情况下,可以直接使用 http 的方式访问,这种方式安装部署方式相对比较简单,在 harbor 压缩包解压后有一个 harbor 文件夹,进入 ```bash [root@redrose2100 online]# ls harbor harbor-online-installer-v2.5.3.tgz [root@redrose2100 online]# cd harbor [root@redrose2100 harbor]# ls common.sh harbor.yml.tmpl install.sh LICENSE prepare [root@redrose2100 harbor]# ``` 可以发现 harbor 文件夹中有一个 harbor.yml。tmpl文件,将其文件名修改为 harbor.yml ```bash [root@redrose2100 harbor]# mv harbor.yml.tmpl harbor.yml [root@redrose2100 harbor]# ls common.sh harbor.yml install.sh LICENSE prepare [root@redrose2100 harbor]# ``` 然后编辑通过 vi harbor.yml 编辑 harbor.yml 文件 ### 3.1.1 配置域名 配置 harbor 的域名,如果内部的不用域名,可以直接设置主机名或者IP ```bash # 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: harbor.redrose2100.com ``` ### 3.1.2 配置 http 的端口 默认是 80,这里修改为 10001 ```bash # http related config http: # port for http, default is 80. If https enabled, this port will redirect to https port port: 10001 ``` ### 3.1.3 注释 https 配置 暂时可以先将 https 配置注释 ```bash # 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 #private_key: /your/private/key/path ``` ### 3.1.4 配置 admin 用户的密码 默认密码是Harbor12345,这里可以修改自己的密码 ```bash # 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 ``` ### 3.1.5 执行安装 harbor 的脚本 其他配置暂时保持默认配置,执行瑞安脚本即可 ```bash ./install.sh ``` 安装完成后,在浏览器打开 http://harbor.redrose210.com 即可打开 harbor 的页面了 ![](http://blog.redrose2100.com/static/upload/20220810_065809.png) ### 3.1.6 修改 docker 配置文件 安装完成 harbor 后,因为此时使用的是 http 协议,此时需要在 docker 的配置文件 /etc/docker/daemon.json 中增加如下内容: ```bash "insecure-registries":["harbor.redrose2100.com"], ``` 完整的内容如下所示: ```bash [root@redrose2100 harbor]# cat /etc/docker/daemon.json { "exec-opts":["native.cgroupdriver=systemd"], "registry-mirrors":[ "https://ooe7wn09.mirror.aliyuncs.com", "https://registry.docker-cn.com", "http://hub-mirror.c.163.com", "https://docker.mirrors.ustc.edu.cn" ], "insecure-registries":["harbor.redrose2100.com"], "dns": ["114.114.114.114", "8.8.8.8"] } ``` 然后重启 docker ```bash systemctl restart docker ``` 再重启 harbor , 在 harbor 文件夹中执行如下两条命令 ```bash # 停止 harbor docker-compose down -v # 启动 harbor docker-compose up -d ``` ### 3.1.7 验证 harbor ```bash # 修改 hello-world 镜像的 tag 值 docker tag hello-world:latest harbor.redrose2100.com/redrose2100/hello-world:latest # 登录 harbor docker login harbor.redrose2100.com -u admin -p xxxx(harbor的密码) # 推送镜像 docker push harbor.redrose2100.com/redrose2100/hello-world:latest ``` 然后到页面上,可以发现,此时镜像已经推送到 harbor 了 ![](http://blog.redrose2100.com/static/upload/20220810_071204.png) 至此,最简单的基于http协议访问的默认的harbor已经安装完成了 ## 3.2 配置 https 访问 Harbor 在生产环境,需要从CA获取证书,在测试环境,可以通过openssl生成CA证书以及通过CA生成服务端证书和客户端证书 如下假设harbor的域名为: harbor.redrose2100.com ### 3.2.1 配置生成CA证书 (1) 首先创建一个目录,用于存放生成的证书等文件 ```bash mkdir ssl cd ssl ``` (2) 生成 CA 证书 私钥 ```bash openssl genrsa -out ca.key 4096 ``` (3) 生成 CA 证书,注意修改域名 ```bash openssl req -x509 -new -nodes -sha512 -days 3650 \ -subj "/C=CN/ST=Beijing/L=Beijing/O=example/OU=Personal/CN=harbor.redrose2100.com" \ -key ca.key \ -out ca.crt ``` ### 3.2.2 生成服务端证书 (1) 生成服务端证书私钥,注意替换自己的域名 ```bash openssl genrsa -out harbor.redrose2100.com.key 4096 ``` (2) 生成证书签名 ```bash openssl req -sha512 -new \ -subj "/C=CN/ST=Beijing/L=Beijing/O=example/OU=Personal/CN=harbor.redrose2100.com" \ -key harbor.redrose2100.com.key \ -out harbor.redrose2100.com.csr ``` (3) 生成 v3 扩展文件,注意替换为自己的域名 ```bash cat > v3.ext <<-EOF authorityKeyIdentifier=keyid,issuer basicConstraints=CA:FALSE keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment extendedKeyUsage = serverAuth subjectAltName = @alt_names [alt_names] DNS.1=harbor.redrose2100.com EOF ``` (4) 为 harbor 主机生成证书 ```bash openssl x509 -req -sha512 -days 3650 \ -extfile v3.ext \ -CA ca.crt -CAkey ca.key -CAcreateserial \ -in harbor.redrose2100.com.csr \ -out harbor.redrose2100.com.crt ``` ### 3.2.3 为 harbor 和 docker 颁发证书 (1) 将服务端证书拷贝至 /data/cert/目录下 ```bash mkdir -p /data/cert/ cp harbor.redrose2100.com.crt /data/cert/ cp harbor.redrose2100.com.key /data/cert/ ``` (2) 将 crt文件转换为cert文件,为docker使用 ```bash openssl x509 -inform PEM -in harbor.redrose2100.com.crt -out harbor.redrose2100.com.cert ``` (3) 将 harbor.redrose2100.com.cert harbor.redrose2100.com.key ca.crt 文件拷贝到docker的证书目录下,注意替换为自己的域名 ```bash mkdir -p /etc/docker/certs.d/harbor.redrose2100.com/ cp harbor.redrose2100.com.cert /etc/docker/certs.d/harbor.redrose2100.com/ cp harbor.redrose2100.com.key /etc/docker/certs.d/harbor.redrose2100.com/ cp ca.crt /etc/docker/certs.d/harbor.redrose2100.com/ ``` 这里需要注意的是,如果nginx中对https没有使用默认的443端口,修改为其他端口了,则此时的需要创建的目录为:/etc/docker/certs.d/yourdomain.com:port, 或者 /etc/docker/certs.d/harbor_IP:port (4) 重启docker ```bash systemctl restart docker ``` ### 3.2.4 修改 harbor.yml 配置文件 修改配置,开启 https 配置,如下前面部署 http 模式的时候将https的部分注释了,这里要将 https 的配置放开注释,而且修改证书的文件路径,如下所示 ```bash # https related config https: # https port for harbor, default is 443 port: 8443 # The path of cert and key files for nginx certificate: /data/cert/harbor.redrose2100.com.crt private_key: /data/cert/harbor.redrose2100.com.key ``` 然后执行如下命令更新 harbor ```bash ./install.sh ``` ### 3.2.5 Nginx 配置 https 修改 nginx.conf 配置,增加监听 443 端口的,跳转到harbor的8443端口,此外在这里需要指定证书文件的路径 ```bash server { listen 443 ssl; server_name harbor.redrose2100.com; ssl_certificate /data/cert/harbor.redrose2100.com.crt; ssl_certificate_key /data/cert/harbor.redrose2100.com.key; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE; ssl_session_cache shared:SSL:1m; ssl_session_timeout 5m; location / { client_max_body_size 1024M; client_body_buffer_size 1024M; proxy_redirect off; proxy_pass https://172.22.27.162:8443; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } ``` 然后将 http 的跳转到 https ```bash server { listen 80; server_name harbor.redrose2100.com; return 301 https://harbor.redrose2100.com$request_uri; } ``` 然后重新加载配置文件 ```bash nginx -s reload ``` 此时在浏览器就可以 通过 http://harbor.redrose2100.com 和 https://harbor.redrose2100.com 访问,当使用 http://harbor.redrose2100.com 时会发现自动跳转到 https://harbor.redrose2100.com ### 3.2.6 Nginx 配置可能遇到额问题 注意,如果出现类似如下错误: ```bash nginx: [emerg] unknown directive "ssl_certificate" in /usr/local/nginx/conf/nginx.conf ``` 或者类似如下错误; ```bash error: SSL modules require the OpenSSL library. ``` 说明 nginx 没有安装ssl,此时进入nginx的源码目录,执行如下命令 ```bash ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-openssl=/usr/local/src/openssl-1.1.1o ``` 其中: * /usr/local/src/openssl-1.1.1o 目录 为openssl 源码包的解压目录 然后使用 make 编译,注意,不要使用 make install,否则会覆盖 ```bash make ``` 然后备份原有的nginx 命令,并将新编译的nginx拷贝的nginx命令所在的目录 ```bash # 将原有的命令重命名备份 mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bark # 将新编译的nginx命令拷贝到nginx命令的目录下 cp objs/nginx /usr/local/nginx/sbin/ ``` 然后执行 nginx -V ,如下,出现 --with-http_ssl_module 表示安装成功 ```bash [root@redrose2100 nginx-1.21.4]# nginx -V nginx version: nginx/1.21.4 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) built with OpenSSL 1.1.1o 3 May 2022 TLS SNI support enabled configure arguments: --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-openssl=/usr/local/src/openssl-1.1.1o [root@redrose2100 nginx-1.21.4]# ``` 然后再次执行如下命令重新加载nginx配置 ```bash nginx -s reload ``` ## 3.3 安装镜像签名 安装签名时,只需要在执行 ./install.sh 的命令的时候带上 --with-notary 参数即可 ```bash ./install.sh --with-notary ``` ## 3.4 安装扫描器 安装扫描器时,只需要在执行 ./install.sh 的命令的时候带上 --with-trivy 参数即可 ```bash ./install.sh --with-trivy ``` ## 3.5 安装 Chart Repository 服务 安装 Chart Repository 服务时,只需要在执行 ./install.sh 的命令的时候带上 --with-chartmuseum 参数即可 ```bash ./install.sh --with-chartmuseum ``` ## 3.6 同时安装签名、扫描器、Chart Repository 服务 同时安装签名、扫描器、Chart Repository 服务时只需要将三个参数都带上即可 ```bash ./install.sh --with-notary --with-trivy --with-chartmuseum ```
始终坚持开源开放共享精神,同时感谢您的充电鼓励和支持!
版权所有,转载本站文章请注明出处:redrose2100, http://blog.redrose2100.com/article/337
上一篇:
Docker----Dockerfile 中构建 Python 应用镜像无法使用 pip 安装第三方库
下一篇:
Harbor----通过 Harbor 源码进行编译 Harbor
搜索
个人成就
出版书籍
《Pytest企业级应用实战》
测试开发技术全栈公众号
测试开发技术全栈公众号
DevOps技术交流微信群
加微信邀请进群
常用网站链接
开源软件洞察
云原生技术栈全景图
Python语言官方文档
Golang官方文档
Docker官方文档
Jenkins中文用户手册
Scrapy官方文档
VUE官方文档
Harbor官方文档
openQA官方文档
云原生开源社区
开源中国
Kubernetes中文文档
Markdown语法官方教程
Kubernetes中文社区
Kubersphere官方文档
BootStrap中文网站
JavaScript中文网
NumPy官方文档
Pandas官方文档
GitLink确实开源网站
数据库排名网站
编程语言排名网站
SEO综合查询网站
数学加减法练习自动生成网站
Kickstart Generator
文章分类
最新文章
最多阅读
特别推荐
×
Close
登录
注册
找回密码
登录邮箱:
登录密码:
图片验证码:
注册邮箱:
注册密码:
邮箱验证码:
发送邮件
注册邮箱:
新的密码:
邮箱验证码:
发送邮件