问题实例
harbor 处在 nginx 后面时无法 push 和 从其他仓库连接上去
nginx 的配置需要添加 location /v2/
server {
listen 80;
server_name registry.bj-net.desistdaydream.ltd;
client_body_in_file_only clean;
client_body_buffer_size 64K;
client_max_body_size 40M;
sendfile on;
send_timeout 300s;
location / {
proxy_pass http://172.19.42.218/;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host:$server_port;
}
location /v2/ {
proxy_pass http://172.19.42.218/;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
harbor 主从报错,测试连接失败 failed to ping endpoint.
https://github.com/goharbor/harbor/issues/7489
https://github.com/goharbor/harbor/issues/7784
https://www.gitmemory.com/issue/goharbor/harbor/9035/537473782
Nov 26 15:36:46 172.23.0.1 core[7305]: 2019-11-26T07:36:46Z [ERROR] [/replication/adapter/native/adapter.go:143]: failed to ping registry https://registry-2.k8s.cloud.tjiptv.net: Head https://registry-2.k8s.cloud.tjiptv.net/v2/: Get https://registry-2.k8s.cloud.tjiptv.net/v2/: dial tcp: lookup registry-2.k8s.cloud.tjiptv.net on 127.0.0.11:53: no such host
Nov 26 15:36:46 172.23.0.1 core[7305]: 2019-11-26T07:36:46Z [ERROR] [/common/api/base.go:73]: POST /api/registries/ping failed with error: {"code":400,"message":""}
Nov 26 15:36:46 172.23.0.1 core[7305]: 2019/11/26 07:36:46 #033[1;44m[D] [server.go:2774] | 192.168.19.69|#033[43m 400 #033[0m| 24.810903ms| match|#033[46m POST #033[0m /api/registries/ping r:/api/registries/ping#033[0m
问题原因:harbor 核心程序的 hosts 文件没有另一个节点的域名解析
解决方式:需要修改 docker-compose 文件,给/etc/hosts 额外添加解析记录在,实例如下:
https://github.com/goharbor/harbor/issues/2221
https://github.com/goharbor/harbor/issues/2232
在 core 和 jobservice 两个容器中添加 extra_hosts 字段,该字段为 map 类型,使用 “域名:IP” 的格式来定义
core:
image: goharbor/harbor-core:v1.9.3
container_name: harbor-core
extra_hosts:
- "registry-2.k8s.cloud.tjiptv.net:10.10.9.56"
jobservice:
image: goharbor/harbor-jobservice:v1.9.3
environment:
- TZ=Asia/Shanghai
container_name: harbor-jobservice
extra_hosts:
- "registry-2.k8s.cloud.tjiptv.net:10.10.9.56"
Note:还需要修改 docker-compose 下 jobserver 的 hosts 文件,因为在同步时,是使用该容器实现的
然后执行命令停止所有容器再重新开启
docker-compose down -v
docker-compose up -d
Note:不要执行 install.sh 脚本,否则 docker-compose 文件将会被重置
反馈
此页是否对你有帮助?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.