k8s

安装harbor1.6 企业级镜像仓库

2018-09-26  本文已影响605人  bdslinux

harbor 1.6 安装

环境

Centos: CentOS Linux release 7.5.1804
Docker: Docker version 18.06.1-ce, build e68fc7a
Docker-composer: docker-compose version 1.20.0, build ca8d3c6
Harbor: harbor-online-installer-v1.6.0.tgz 

docker-composer

$ curl -L https://github.com/docker/compose/releases/download/1.20.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
$ chmod +x /usr/local/bin/docker-compose

download harbor

选择在线安装方式,离线版本也可以,就是在安装包比较大

$ wget https://storage.googleapis.com/harbor-releases/release-1.6.0/harbor-online-installer-v1.6.0.tgz

解压并配置harbor

$ tar xf  harbor-online-installer-v1.6.0.tgz
$ cd harbor

## 修改harbor配置
$ vim harbor.cfg 
# 监听地址
hostname = 10.1.1.101
# 登录密码
harbor_admin_password = 12345
# 只允许管理员可以创建项目
project_creation_restriction = adminonly

安装harbor

因为我这里用的是在线版本安装,所以需要在线下载docker镜像会比较慢,等一段时间

cd harbor
./install.sh  
# pull images 过程中显示下面日志
Status: Downloaded newer image for goharbor/nginx-photon:v1.6.0
Creating harbor-log ... done
Creating harbor-db          ... done
Creating registry           ... done
Creating redis              ... done
Creating harbor-adminserver ... done
Creating harbor-ui          ... done
Creating harbor-jobservice  ... done
Creating nginx              ... done

✔ ----Harbor has been installed and started successfully.----

Now you should be able to visit the admin portal at http://10.1.1.101.
For more details, please visit https://github.com/goharbor/harbor .

web访问

http://10.1.1.101 
USERNAME: admin
PASSWORD: 12345 
终端访问

需要在docker启动配置 /usr/lib/systemd/system/docker.service中加入下面

ExecStart=/usr/bin/dockerd --insecure-registry 10.1.1.101

重新加载配置 重启docker

systemctl daemon-reload
systemctl restart docker

访问

docker login 10.1.1.101 

配置https验证

我这里用hub.budongshu.cn这个域名来做,请配置好主机ip的dns域名解析

生成自建ca 证书

这里所有的证书都放在目录/data/cert/ 下面

cd /data/cert/
openssl req -newkey rsa:4096 -nodes -sha256 -keyout ca.key -x509 -days 3650 -out ca.crt

生成请求

openssl x509 -req -days 3650 -in hub.budongshu.cn.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out hub.budongshu.cn.crt

证书签署

openssl x509 -req -days 365 -in demo.rancher.com.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out hub.budongshu.cn.crt

验证

openssl s_client -connect hub.budongshu.cn:443 -servername hub.budongshu.cn

更改配置

vim harbor.cfg
hostname = hub.budongshu.cn:443
ui_url_protocol = https
ssl_cert = /data/cert/hub.budongshu.cn.crt
ssl_cert_key = /data/cert/hub.budongshu.cn.key

重新加载配置 重启服务

cd /root/harbor/
./prepare
./install.sh  

注意:每次更改 harbor.cfg 配置以后,重新执行一下 install.sh 即可

web和终端访问harbor

https 访问
https://hub.budongshu.cn
username: admin
password:12345
-w1366
终端访问

在安装了Docker的计算机上,请确保--insecure-registry配置不存在,并且将上述步骤中生成的ca.crt复制到/etc/docker/certs.d/reg.yourdomain.com(或Harbor主机IP),如果该目录不存在,则创建它。

mkdir /etc/docker/certs.d/hub.budongshu.cn 
cp /data/cert/ca.crt /etc/docker/certs.d/hub.budongshu.cn/

如果你将nginx443端口映射到另一个端口,那么你应该创建/etc/docker/certs.d/reg.yourdomain.com:port(或Harbor主机IP:port)。然后运行docker命令来验证设置,例如:

$ docker login hub.budongshu.cn

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-store

Login Succeeded

上传镜像

首先要在web页面新建一个项目


-w1420

查看推送镜像命令


-w1436
docker pull nginx 
docker tag nginx hub.budongshu.cn/nginx-v1/nginx:1.8.0 
docker push hub.budongshu.cn:443/nginx-v1/nginx:1.8.0
The push refers to repository [hub.budongshu.cn:443/nginx-v1/nginx]
579c75bb43c0: Pushed
67d3ae5dfa34: Pushed
8b15606a9e3e: Pushed
1.8.0: digest: sha256:c0b69559d28fb325a64c6c8f47d14c26b95aa047312b29c699da10380e90b4d7 size: 948
-w1402

安装其他服务

sudo ./install.sh --with-notary

注意:使用notary安装,参数ui_url_protocol必须设置为“https”。

sudo ./install.sh --with-clair
sudo ./install.sh --with-notary --with-clair
image
上一篇 下一篇

猜你喜欢

热点阅读