首页 > 技术文章 > 第五章 配置私有仓库Harbor

LiuQizhong 2019-09-16 18:31 原文

一、Harbor 安装(尚硅谷资料)

安装:Harbor 官方地址:官方地址:https://github.com/vmware/harbor/releases

1、解压软件包

tar xvf harbor-offline-installer-<version>.tgz https://github.com/vmware/harbor/releases/download/v1.2.0/harbor-offline-installer-v1.2.0.tgz

2、配置harbor.cfga

必选参数

  • hostname:目标的主机名或者完全限定域名:目标的主机名或者完全限定域名
  • ui_url_protocol::http或或https。默认为。默认为http
  • db_password:用于db_auth的的MySQL数据库的根密码。更改此密码进行任何生产用途数据库的根密码。更改此密码进行任何生产用途
  • max_job_workers:(默认值为:(默认值为3)作业服务中的复制工作人员的最大数量。对于每个映像复制作业,)作业服务中的复制工作人员的最大数量。对于每个映像复制作业,工作人员将存储库的所有标签同步到远程目标。增加此数字允许系统中更多的并发复制作业。但是,由于每个工工作人员将存储库的所有标签同步到远程目标。增加此数字允许系统中更多的并发复制作业。但是,由于每个工作人员都会消耗一定数量的网络作人员都会消耗一定数量的网络/ CPU / IO资源,请根据主机的硬件资源,仔细选择该属性的值资源,请根据主机的硬件资源,仔细选择该属性的值
  • customize_crt:(:(on或或off。默认为。默认为on)当此属性打开时,)当此属性打开时,prepare脚本将为注册表的令牌的生成脚本将为注册表的令牌的生成/验证创验证创建私钥和根证书建私钥和根证书
  • ssl_cert::SSL证书的路径,仅当协议设置为证书的路径,仅当协议设置为https时才应用时才应用
  • ssl_cert_keySSL密钥的路径,仅当协议设置为密钥的路径,仅当协议设置为https时才应用时才应用
  • secretkey_path:用于在复制策略中加密或解密远程注册表的密码的密钥路径:用于在复制策略中加密或解密远程注册表的密码的密钥路径

3、创建 https 证书以及配置相关目录权限

openssl genrsa -des3 -out server.key 2048
openssl req -new -key server.key -out server.csr
cp server.key server.key.org
ope nssl rsa -in server.key.org -out server.key
ope nssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
mkdir /data/cert
chmod -R 777 /data/cert

4、运行脚本进行安装

./install.sh

5、访问测试

https://reg.yourdomain.com 的管理员门户(将的管理员门户(将reg.yourdomain.com更改为您的主机名更改为您的主机名harbor.cfg

请注意,默认管理员用户名认管理员用户名/密码为密码为admin / Harbor12345

6、上传镜像进行上传测试、上传镜像进行上传测试

a、指定镜像仓库地址、指定镜像仓库地址

vim /etc/docker/daemon.json

{

"insecure-registries": ["serverip"]

}

b、下载测试镜像

docker pull hello-world

c、给镜像重新打标签

docker tag hello-world serverip/hello-world:latest

d、登录进行上传

docker login serverip

7、其它 Docker 客户端下载测试

a、指定镜像仓库地址(serverip指自身设置的地址,如我的:hub.lqz.com

vim /etc/docker/daemon.json

{

"insecure-registries": ["serverip"]

}

b、下载测试镜像

docker pull serverip/hello-world:latest

二、自身安装过程

1、编辑daemon.json文件

vim  /etc/docker/daemon.json

添加字符串:"insecure-registries":["https://hub.lqz.com"]

 

开启docker:   

systemctl restart docker

2、创建harbor文件夹,将docker.compose放入并授权

 

 

 

 

3、创建证书

vim harbor.cfg

创建证书

① 生成私钥:  openssl genrsa -des3 -out server.key 2048

密码:root123

② 创建证书的请求csr:

  openssl req -new -key server.key -out server.csr

 

③ 备份私钥

cp server.key server.key.org

④ 转换成自己的证书(退出密码)

openssl rsa -in server.key.org -out server.key

⑤ 拿证书请求去签名

openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

echo "192.168.100.168 hub.lqz.com" >> /etc/hosts

⑥ 在计算机里修改hosts文件

C:\Windows\System32\drivers\etc  hosts文件

用管理员权限向文件添加    192.168.100.168 hub.lqz.com

⑦ 用浏览器访问  hub.lqz.com

默认账号:admin;密码:Harbor12345  

可在vim harbor.cfg 文件中查看

 

三、使用镜像仓库harbor上传下载自定义镜像

1、重新启动harbor

cd  /usr/local/harbor/        

./install.sh

2、通过外网,使用docker pull 命令下载一个外部服务器中的镜像文件用与测试

docker pull nginx

3、登录harbor镜像仓库服务器

docker login hub.lqz.com

其中hub.lqz.com为自己企业镜像仓库的域名

 

4、查看镜像docker images

 

5、对下载的镜像打标签,用于后面的上传操作

docker tag docker.io/nginx:latest hub.lqz.com/library/nginx:latest

6、上传至镜像仓库,其中library为镜像仓库中默认的项目名称,如需要上传到其他项目文件中,请自行修改为对应的项目文件名

docker push hub.lqz.com/library/nginx:latest

7、登录harbor镜像仓库的UI界面,查看上传的镜像

 

8、使用镜像仓库下载镜像文件,命令为:

docker pull hub.lqz.com/library/nginx:latest

9、删除镜像

docker rmi -f hub.lqz.com/library/nginx:latest

参照链接:https://jingyan.baidu.com/article/4b52d702e62167fc5c774b3b.html

四、遇到问题:

1ssh登录错误ECDSA host key for ip has changed解决方案

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

@       WARNING: POSSIBLE DNS SPOOFING DETECTED!          @

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

The ECDSA host key for k8s-node01 has changed,

and the key for the corresponding IP address 192.168.100.85

is unknown. This could either mean that

DNS SPOOFING is happening or the IP address for the host

and its host key have changed at the same time.

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!

Someone could be eavesdropping on you right now (man-in-the-middle attack)!

It is also possible that a host key has just been changed.

The fingerprint for the ECDSA key sent by the remote host is

SHA256:HJ7t/uY0mjFJng9mYzqw7LBxVDQftfHgBJsAlGBOPjM.

Please contact your system administrator.

Add correct host key in /root/.ssh/known_hosts to get rid of this message.

Offending ECDSA key in /root/.ssh/known_hosts:1

ECDSA host key for k8s-node01 has changed and you have requested strict checking.

Host key verification failed.

lost connection

 

 

问题产生原因:

设置node节点为同一台主机(系统重装)IP地址不一样,master连接时再次访问此ip服务器时,因为ssh会自动匹配之前ssh保存的信息,由于我们的服务器做了更改,会导致本地保存的ssh信息失效,于是再次连接时就会出现上述错误。

解决方案:

删除本地known_hosts里面的缓存信息即可。命令:ssh-keygen -R "你的远程服务器ip地址"  

注意:R是大写!

 

链接:https://blog.csdn.net/yunweifun/article/details/78763026

 

 

 

2、出现端口不能连接问题

ssh: connect to host k8s-node01 port 22: No route to host

lost connection

vim修改/etc/hosts下对应的IP地址就恢复了

 

这篇随笔有很多重复的东西,但我没选择删除,因为我觉得知识就是一个不短重复积累的过程,加油啦!

 

链接:https://www.bilibili.com/video/av66617940/?p=14

推荐阅读