# 企业级私有仓库 Harbor
企业部署 Kuberetes 集群环境之后,我们就可以将原来在传统虚拟机上运行的业务,迁移到 kubernetes 上,让 Kubernetes 通过容器的方式来管理。而一旦我们需要将传统业务使用容器的方式运行起来,就需要构建很多镜像,那么这些镜像就需要有一个专门的位置存储起来,为我们提供镜像上传和镜像下载等功能。但我们不能使用阿里云或者 Dockerhub 等仓库,首先拉取速度比较慢,其次镜像的安全性无法保证,所以就需要部署一个私有的镜像仓库来管理这些容器镜像。同时该仓库还需要提供高可用功能,确保随时都能上传和下载可用的容器镜像。
# 1、关闭防火墙、Selinux、环境配置
| [root@harbor ~] |
| [root@harbor ~] |
| [root@harbor ~] |
| [root@harbor ~] |
| [root@harbor ~] |
| [root@harbor ~] |
| [root@harbor ~] |
| [root@harbor ~] |
# 2、Docker 安装
| [root@harbor ~] |
| [root@harbor ~] |
| [root@harbor ~] |
| [root@harbor ~] |
# 3、配置 Docker 加速
| [root@harbor ~] |
| [root@harbor ~] |
| { |
| "registry-mirrors": [ |
| "https://docker.credclouds.com", |
| "https://k8s.credclouds.com", |
| "https://quay.credclouds.com", |
| "https://gcr.credclouds.com", |
| "https://k8s-gcr.credclouds.com", |
| "https://ghcr.credclouds.com", |
| "https://do.nark.eu.org", |
| "https://docker.m.daocloud.io", |
| "https://docker.nju.edu.cn", |
| "https://docker.mirrors.sjtug.sjtu.edu.cn", |
| "https://docker.1panel.live", |
| "https://docker.rainbond.cc" |
| ], |
| "exec-opts": ["native.cgroupdriver=systemd"] |
| } |
| EOF |
| [root@harbor ~] |
# 4、安装 Harbor
| [root@harbor ~] |
| [root@harbor ~] |
| [root@harbor soft] |
| [root@harbor soft] |
| [root@harbor harbor] |
| hostname: 192.168.1.134 |
| ... |
| |
| |
| |
| |
| |
| |
| ... |
| harbor_admin_password: Harbor12345 |
| [root@harbor harbor] |
# 5、配置 Nginx 负载均衡调度
| [root@lb ~] |
| server { |
| listen 443 ssl; |
| server_name harbor.hmallleasing.com; |
| client_max_body_size 1G; |
| ssl_prefer_server_ciphers on; |
| ssl_certificate /etc/nginx/sslkey/_.hmallleasing.com_chain.crt; |
| ssl_certificate_key /etc/nginx/sslkey/_.hmallleasing.com_key.key; |
| location / { |
| proxy_pass http://192.168.1.134; |
| |
| |
| proxy_set_header X-Real-IP $remote_addr; |
| proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
| |
| proxy_connect_timeout 30; |
| proxy_send_timeout 60; |
| proxy_read_timeout 60; |
| |
| proxy_buffering on; |
| proxy_buffer_size 32k; |
| proxy_buffers 4 128k; |
| proxy_temp_file_write_size 10240k; |
| proxy_max_temp_file_size 10240k; |
| } |
| } |
| |
| server { |
| listen 80; |
| server_name s.hmallleasing.com; |
| return 302 https://$server_name$request_uri; |
| } |
# 6、推送镜像至 Harbor
| [root@harbor harbor] |
| [root@harbor harbor] |
| [root@harbor harbor] |
| [root@harbor harbor] |
# 7、Harbor 停止与启动
| |
| [root@harbor harbor] |
| /soft/harbor |
| [root@harbor harbor] |
| |
| [root@harbor harbor] |
| [root@harbor harbor] |