Harbor仓库开启SSL
创始人
2025-06-01 04:35:26

目录

  • 一、部署docker
  • 二、安装docker-compose
  • 三、安装harbor
    • 下载离线安装包:
    • 创建CA证书(把11.0.1.5改成你自己的harbor的服务器IP)
    • 修改harbor.yaml文件
    • 将证书加为受信任的证书:
    • 开始安装harbor
    • docker登录私有仓库测试:
  • 四、其他服务器连接harbor
  • 问题记录:

一、部署docker

下载并解压:

wget https://download.docker.com/linux/static/stable/x86_64/docker-20.10.6.tgz
tar -zxf docker-20.10.6.tgz 
cp docker/* /usr/bin/

将docker注册为 Systemd 的 service

cat > /etc/systemd/system/docker.service <

为 docker.service添加可执行权限

chmod +x /etc/systemd/system/docker.service

启动docker并设置开机自启

mkdir /etc/docker
systemctl daemon-reload
systemctl enable --now docker.service

二、安装docker-compose

通过DaoCloud下载:

curl -L https://get.daocloud.io/docker/compose/releases/download/v1.28.6/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose

三、安装harbor

因为是在内网,所以我们采用离线安装包的方式。

下载离线安装包:

[root@harbor ~]# wget https://github.com/goharbor/harbor/releases/download/v1.10.17/harbor-offline-installer-v1.10.17.tgz

解压

[root@harbor ~]# tar -zxf harbor-offline-installer-v1.10.17.tgz -C /app

创建CA证书(把11.0.1.5改成你自己的harbor的服务器IP)

[root@harbor ~]# mkdir /app/harbor/certs.d
[root@harbor ~]# cd /app/harbor/certs.d
[root@harbor certs.d]# openssl req  -newkey rsa:4096 -nodes -sha256 -keyout ca.key -x509 -days 365 -out ca.crt
Generating a 4096 bit RSA private key
................................................................++
............................................................................++
writing new private key to 'ca.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:beijing
Locality Name (eg, city) [Default City]:beijing
Organization Name (eg, company) [Default Company Ltd]:DevOps
Organizational Unit Name (eg, section) []:Tec
Common Name (eg, your name or your server's hostname) []:11.0.1.5
Email Address []:

创建证书请求文件csr

[root@harbor certs.d]# openssl req -newkey rsa:4096 -nodes -sha256 -keyout 11.0.1.5.key  -out 11.0.1.5.csr
Generating a 4096 bit RSA private key
...........................++
............................................................................................................................................................................................................................................................................................++
writing new private key to '11.0.1.5.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:beijing
Locality Name (eg, city) [Default City]:beijing
Organization Name (eg, company) [Default Company Ltd]:DevOps
Organizational Unit Name (eg, section) []:Tec
Common Name (eg, your name or your server's hostname) []:11.0.1.5
Email Address []:Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:

创建证书

[root@harbor certs.d]# echo subjectAltName = IP:11.0.1.5 > extfile.cnf
[root@harbor certs.d]# openssl x509 -req -days 365 -in 11.0.1.5.csr -CA ca.crt -CAkey ca.key -CAcreateserial -extfile extfile.cnf -out 11.0.1.5.crt
Signature ok
subject=/C=CN/ST=beijing/L=beijing/O=DevOps/OU=Tec/CN=192.168.11.11/emailAddress=352972405@qq.com
Getting CA Private Key

查看已生成的证书:

[root@harbor certs.d]# ll
总用量 28
-rw-r--r-- 1 root root 1915 3月  21 20:14 11.0.1.5.crt
-rw-r--r-- 1 root root 1687 3月  21 20:13 11.0.1.5.csr
-rw-r--r-- 1 root root 3272 3月  21 20:13 11.0.1.5.key
-rw-r--r-- 1 root root 1996 3月  21 20:13 ca.crt
-rw-r--r-- 1 root root 3272 3月  21 20:13 ca.key
-rw-r--r-- 1 root root   17 3月  21 20:14 ca.srl
-rw-r--r-- 1 root root   29 3月  21 20:14 extfile.cnf

修改harbor.yaml文件

# hostname这里修改为你的IP,跟上面创建证书使用的IP一致
hostname: 11.0.1.5# http related config
http:# port for http, default is 80. If https enabled, this port will redirect to https portport: 18080# https related config
https:# https port for harbor, default is 443port: 443# The path of cert and key files for nginx# 证书路径certificate: /app/harbor/certs.d/11.0.1.5.crtprivate_key: /app/harbor/certs.d/11.0.1.5.key

将证书加为受信任的证书:

[root@harbor certs.d]# chmod 644 /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem
[root@harbor certs.d]# cat /app/harbor/certs.d/11.0.1.5.crt >> /etc/pki/tls/certs/ca-bundle.crt
[root@harbor certs.d]# chmod 444 /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem

重启docker

[root@harbor certs.d]# systemctl restart docker

开始安装harbor

[root@harbor certs.d]# cd /app/harbor
[root@harbor harbor]# ./prepare
[root@harbor harbor]# ./install.sh --with-notary --with-clair

docker登录私有仓库测试:

[root@harbor harbor]# docker login -u admin -p Harbor12345 11.0.1.5:443
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-storeLogin Succeeded

登录成功后,认证信息会保存在/root/.docker里面:

[root@harbor ~]# cat .docker/config.json 
{"auths": {"11.0.1.5:443": {"auth": "YWRtaW46SGFyYm9yMTIzNDU="}}
}
[root@harbor ~]# 

再次登录时,就不需要加用户名和密码了:

[root@harbor harbor]# docker login 11.0.1.5:443
Authenticating with existing credentials...
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-storeLogin Succeeded

四、其他服务器连接harbor

在新的服务器上/etc/docker/上创建目录:

mkdir /etc/docker/certs.d/11.0.1.5

将harbor的证书文件发送过去

scp /app/harbor/certs.d/* 11.0.1.4:/etc/docker/certs.d/11.0.1.5

同样将证书添加为受信任的证书:

[root@jenkins 11.0.1.5]# chmod 644 /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem
[root@jenkins 11.0.1.5]# cat /etc/docker/certs.d/11.0.1.5/11.0.1.5.crt >> /etc/pki/tls/certs/ca-bundle.crt
[root@jenkins 11.0.1.5]# chmod 444 /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem

重启docker

systemctl restart docker 

登录测试:

[root@jenkins 11.0.1.5]# docker login -u admin -p Harbor12345 11.0.1.5:443
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-storeLogin Succeeded

问题记录:

1、通过浏览器访问Harbor页面时,报500内部错误的话,可能是科学上网工具Ss的问题,将Ss退出或改为其他的模式。
2、docker login的时候报404,将harbor.yml的hostname改成跟证书使用的一致,如果创建证书的过程中使用的是11.0.1.5,hostname也使用这个IP。反之如果使用的是主机名,这里也改成主机名。
3、docker login的时候提示“wanted to harbor.com”类似的内容,将/etc/hosts的主机名解析注释掉。

相关内容

热门资讯

今日起招股发售价9.75港元,... 6月2日,车来了母公司元光科技启动全球发售,发售价9.75港元,预计将在6月10日在港交所挂牌。元光...
港股午评:恒生指数跌2.20%... 新京报贝壳财经讯 6月2日,港股午间收盘,恒生指数跌2.20%,恒生科技指数跌2.43%。石药集团跌...
夏乐:美债压力与美元走弱 全球... 原创 财联社 蜂网专家2025年05月29日《首席说》是财联社倾力打造的一档高端直播联线栏目。面向泛...
罗志恒:财政政策不应受3%赤字... 罗志恒系粤开证券首席经济学家、中国首席经济学家论坛理事自2008年以来,本轮积极财政政策实行了长达1...
三大利空,突袭! 三大利空,突... 时局依然不稳!今天早上,全球市场全线杀跌。日经指数一度杀跌近1.5%,中国台湾股指大跌近1%,港股三...
美国客户“疯狂”催单 这家川企... 自硬公司的精密零件产品之一:随钻用核心零部件。韩吉尔摄 “5月中旬,美国休斯敦的客户发邮件,要求尽快...
这只港股,突然暴涨超60%!发... 6月2日,亚太股市开盘后持续走弱。不过,港股方面,加密货币数字概念股大涨,连连数字涨62.67%。港...
招商基金三首席同日上任!“去管... 当同行纷纷为投研人才做“去管理化”减法时,招商基金却反其道而行之,提拔朱红裕、王景两位基金经理。这究...
2025浙江国际电子商务博览会... 这个周末,端午的粽叶飘香和六一小朋友的欢笑声撞了个满怀~跨境电商圈也跟着热闹到飞起。 从节令美食到文...
头部餐饮,火拼儿童餐 头部餐饮... 总第4234期作者 |餐饮老板内参内参君儿童餐,卷入next level端午恰逢六一,双节叠加背景下...
舆论战升级!巨子生物深夜回应,... 2025.06.02本文字数:2490,阅读时长大约4分钟作者 |第一财经 刘晓颖重组胶原蛋白成分之...
财经时评|以创新厚度重塑汽车产... 作者 远山中国汽车工业协会与工业和信息化部近期针对行业“内卷式”竞争的联合发声,为持续蔓延的价格战按...
恒生指数午盘下跌2.20%,恒... 6月2日午盘,香港恒生指数下跌2.20%,报22778.45点;恒生科技指数下跌2.43%,报504...
“以旧换新”带货1万亿,中国何... “美国想让制造业回流成为中国的样子,一个踏实劳作的‘生产者社会’;而中国想努力扩大消费成为美国的样子...
恒指半日跌2.2% 恒指半日跌... 【恒指半日跌2.2%】截至午间收盘,香港恒生指数下跌2.20%,报22778.45点;恒生科技指数下...
“成分之争”舆论战升级,巨子生... 重组胶原蛋白成分之争的舆论战再度升级。美妆博主 "大嘴博士" (郝宇)近日连续发文质疑,巨子生物(0...
汇川技术新注册《InoCube... 证券之星消息,近日汇川技术(300124)新注册了《InoCube-InoData数据分析系统V1....
博将控股多家所投企业荣登202... 博将控股多家所投企业荣登2025杭州独角兽与准独角兽榜单 2025年4月24日,由民建浙江省委会、浙...
刚刚,A50直线跳水!亚太股市... 6月2日,亚太股市开盘后持续走弱。富时中国A50期货开盘跌0.6%,截至目前跌幅1.91%。 截至...
问界、智界、享界、尊界,202... 2025鸿蒙智行:四界表现鸿蒙智行作为国内造车新势力的主流品牌,一共规划了“五界”车型,包括:问界、...
花样年控股:重组支持协议的最后... 6月1日,花样年控股(01777.HK)公告称,公司2024年4月29日所订立的重组支持协议的最终截...
蜜雪集团股价创上市以来新高 蜜... 新京报贝壳财经讯 6月2日,港股蜜雪集团盘中涨超7%,股价刷新上市新高。
美单边关税让全球经济面临更大不... 美国征收关税的对象和标准可能随意变更,其关税政策具有不可预测性。无论是外国企业,还是美国本土企业,都...
桃李面包创始人向其两儿子转让3... 5月30日晚间,桃李面包(沪市代码:603866)公告称,公司控股股东及实际控制人吴志刚通过大宗交易...
前4月东莞重大项目完成投资42... 本期看点:前4月东莞重大项目完成投资429.09亿元;长联科技募投项目提升年产至2.77万吨;广东省...
恒生指数跌幅扩大至2%,医药、... 6月2日,恒生指数跌幅扩大至2%,医药、地产、能源板块跌幅居前,美中嘉和跌超14%,石四药集团跌近1...
港股、A50飘绿,亚太市场多数... 早间,亚太市场多数下跌。港股、A50集体下跌其中,恒生指数、恒生科技指数开盘跌幅扩大, 港股生物技术...
雷军看好的两兄弟,要IPO了 ... 2021年夏,小米产业园办公室内,雷军饶有兴致地打量眼前一对兄弟,“为什么张波是创始人,董事长却是张...
圣阳股份涨1.66%,成交额9... 5月30日,圣阳股份涨1.66%,成交额9.82亿元,换手率15.03%,总市值66.67亿元。 异...