网络知识 娱乐 早上好 如何解决Harbor主机IP变动?

早上好 如何解决Harbor主机IP变动?

在虚拟机部署了一套harbor做实验

,发现虚机的地址变了导致harbor下载镜像失败了

。建议大家再做实验的时候可以将DHCP改成STATIC地址。

以下是我的做法

修改主机hosts文件

# changeecho "192.168.10.2 harbor.example.com "  >>/etc/hosts

因为只需要内网访问,没必要去申请一个ssl证书,所以我就用openssl颁发自签名证书,实现https访问。

# 创建证书目录mkdir -p /data/cert && cd /data/cert#创建CA根证书openssl req  -newkey rsa:4096 -nodes -sha256 -keyout ca.key -x509 -days 365 -out ca.crt -subj "/C=CN/L=zhejiang/O=lisea/CN=harbor-registry"#生成证书签名,注意域名openssl req -newkey rsa:4096 -nodes -sha256 -keyout harbor.example.com.key -out server.csr -subj "/C=CN/L=zhejiang/O=lisea/CN=harbor.example.com"#生成主机证书openssl x509 -req -days 365 -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out harbor.example.com.crt

修改Harbor配置文件

#install Dir  /opt/harbor/harbor.cfgui_url_protocol = httpshostname = harbor.example.comssl_cert = /data/cert/harbor.example.com.crtssl_cert_key = /data/cert/harbor.example.com.key

重启Harbor服务

#切换到安装目录cd /opt/harbor#重新生成配置./prepare#停止harbordocker-compose down -v#启动harbordocker-compose up -d

配置docker客户端

# 更改host文件echo "192.168.10.2 harbor.example.com "  >>/etc/hosts# 修改docker.service/usr/lib/systemd/system/docker.serviceExecStart=/usr/bin/dockerd --insecure-registry harbor.example.com

测试

#登录docker login harbor.example.comUsername: adminPassword: Login Succeeded
#下载docker pull harbor.example.com/maven/service:2323: Pulling from maven/service169185f82c45: Downloading [===========>                                       ]  511.5kB/2.207MB1e929b64ace7: Pulling fs layer 6efe0b4ad774: Downloading [>                                                  ]  409.1kB/40.15MB1dbedd350ebb: Waiting

FAQ

#分析:由于未更改hosts文件导致,主机解析失败。The push refers to repository [harbor.example.com/springcloud-maven/service-eureka]Get https://harbor.example.com/v2/: dial tcp: lookup harbor.example.com: no such host