系统环境准备
CentOS Linux release 7.4.1708 (Core)
docker version:1.13.1
docker-compose version 1.21.1, build 5a3f1a3
docker-py version: 3.3.0
CPython version: 3.6.5
OpenSSL version: OpenSSL 1.0.1t 3 May 2016
修改主机名,建议修改成 reg.yourdomain.com
docker安装
安装命令:# yum install docker -y
开启docker服务:# systemctl start docker
设置docker开启自启动:# chkconfig docker on
# vim /usr/lib/systemd/system/docker.service
ExecStart=/usr/bin/dockerd-current --insecure-registry reg.cheng.com \
重启docker: systemctl daemon-reload && systemctl restart docker
docker-compose安装
下载Docker Compose二进制可执行文件
# curl -L https://github.com/docker/compose/releases/download/1.21.1/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
添加可执行权限
# chmod +x /usr/local/bin/docker-compose
OpenSSL安装
# yum -y install openssl openssl-devel
下载harbor离线安装文件
# wget https://storage.googleapis.com/harbor-releases/release-1.5.0/harbor-offline-installer-v1.5.0.tgz
# tar zxf harbor-offline-installer-v1.5.0.tgz -C /opt
证书安装
# openssl req \ -newkey rsa:4096 -nodes -sha256 -keyout ca.key \ -x509 -days 365 -out ca.crt
# openssl req \ -newkey rsa:4096 -nodes -sha256 -keyout yourdomain.com.key \ -out yourdomain.com.csr
# openssl x509 -req -days 365 -in yourdomain.com.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out yourdomain.com.crt
# cp yourdomain.com.crt /root/cert/
# cp yourdomain.com.key /root/cert/
# cp ca.crt /etc/docker/certs.d/reg.yourdomain.com
# cp yourdomain.com.crt /etc/pki/ca-trust/source/anchors/reg.yourdomain.com.crt
# update-ca-trust
配置harbor.cfg文件
hostname: reg.yourdomain.com
ui_url_protocol: http or https(我这边使用https,如果使用http后面证书部分可以忽略)
db_password = password(mysql数据库密码)
ssl_cert = /root/cert/yourdomain.com.crt
ssl_cert_key = /root/cert/yourdomain.com.key
启动harbor
# cd /opt/harbor
# ./prepare
# ./install.sh
[root@cheng harbor]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
146f85e00e03 vmware/nginx-photon:v1.5.0 "nginx -g 'daemon ..." 4 hours ago Up 33 minutes (healthy) 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp, 0.0.0.0:4443->4443/tcp nginx
80983c6fab8a vmware/harbor-jobservice:v1.5.0 "/harbor/start.sh" 4 hours ago Up 33 minutes harbor-jobservice
f1b10ff3b2f3 vmware/harbor-ui:v1.5.0 "/harbor/start.sh" 4 hours ago Up 33 minutes (healthy) harbor-ui
0eab9eef6442 vmware/harbor-db:v1.5.0 "/usr/local/bin/do..." 4 hours ago Up 33 minutes (healthy) 3306/tcp harbor-db
50ad985dda9b vmware/harbor-adminserver:v1.5.0 "/harbor/start.sh" 4 hours ago Up 33 minutes (healthy) harbor-adminserver
827a0883f325 vmware/registry-photon:v2.6.2-v1.5.0 "/entrypoint.sh se..." 4 hours ago Up 33 minutes (healthy) 5000/tcp registry
a4c156cfe376 vmware/redis-photon:v1.5.0 "docker-entrypoint..." 4 hours ago Up 33 minutes 6379/tcp redis
acb2adc81be9 vmware/harbor-log:v1.5.0 "/bin/sh -c /usr/l..." 4 hours ago Up 33 minutes (healthy) 127.0.0.1:1514->10514/tcp harbor-log
启动成功!
验证
页面访问: 登录用户名admin,默认密码Harbor12345
[图片上传失败...(image-cff177-1539240618559)]
docker登录:docker login reg.cheng.com ;然后就可以上传下载镜像了。
docker tag SOURCE_IMAGE[:TAG] reg.cheng.com/myproject/IMAGE[:TAG]
docker push reg.cheng.com/myproject/IMAGE[:TAG]
注:
如果修改配置文件需要重新执行./prepare脚本重新生成配置,再重建容器! docker-compose up -d
对于其他节点来说,需要先拷贝ca证书到每个计算节点,然后执行cp ca.crt /etc/docker/certs.d/reg.yourdomain.com,这样才能做证书验证。
注:修改docker配置后需要重启harbor
# systemctl restart docker
# docker-compose stop
# docker-compose start