CentOS7.4 Docker Harbor + docker-registry基于Http方式安全认证私有仓库搭建

准备工作

版本

更新或下载URL

CentOS

7.4 64位

yum -y update && yum -y upgrade


 

依赖项(不分先后顺序)

docker

1.13.1, build 774336d/1.13.1

yum install -y docker

systemctl start docker.service

docker-compose

docker-compose version 1.21.2, build a133471
docker-py version: 3.3.0
CPython version: 2.7.5

pip install docker-compose

go

1.7.5

yum install -y golang

python

2.7.5

yum install -y python

python-pip

9.0.1

yum install -y epel-release python-pip

pip install --upgrade pip backports.ssl_match_hostname

openssl

OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013 yum install -y openssl

1.安装前置组件

yum -y update && yum -y upgrade && yum -y install wget python-devel libevent-devel epel-release python-pip gcc gcc-c++ xz-devel

yum -y upgrade kernel && yum -y reinstall kernel

2.创建证书存放目录

mkdir -p /data/cert
cd /data/cert/

2.1 创建 CA 根证书

openssl req  -newkey rsa:4096 \
-nodes -sha256 -keyout ca.key -x509 -days 365 \
-out ca.crt -subj "/C=CN/L=shanghai/O=baoshan/CN=harbor-registry"

2.2 生成一个证书签名, 设置访问域名为 [你的域名]

openssl req -newkey rsa:4096 \
-nodes -sha256 -keyout server.key \
-out server.csr -subj "/C=CN/L=shanghai/O=baoshan/CN=docker-hub.onechain.com"

2.3 生成主机的证书

openssl x509 -req -days 365 \
-in server.csr -CA ca.crt -CAkey ca.key \
-CAcreateserial -out server.crt

3. 安装docker

yum -y install docker

3.1 设置docker为开启启动

systemctl enable docker.service

3.2 启动 docker 服务

systemctl start docker.service

3.3 安装 docker-compose

预先安装epel-release后方可安装python-pip[在前置条件中已安装,此处可不执行]
yum -y install epel-release python-pip
pip install --upgrade pip
pip install docker-compose
pip install --upgrade backports.ssl_match_hostname

yum clean all

python-pip其他安装方法:
curl "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py"
python get-pip.py
pip -V

4.安装harbor

4.1 下载harbor离线版

wget https://github.com/vmware/harbor/releases/download/v1.1.2/harbor-offline-installer-v1.1.2.tgztar xvf harbor-offline-installer-v1.1.2.tgz

4.2 修改habor配置

hostname = docker-hub.onechain.com            # 指定私有仓库的主机名,可以是IP地址,也可以是域名   
ui_url_protocol = https                                  # 用户访问私仓时使用的协议,默认时http,配置成https
db_password = root123                             # 指定mysql数据库管理员密码
harbor_admin_password:Harbor12345           # harbor的管理员账户密码
ssl_cert = /data/cert/server.crt                  # 设置证书文件路径
ssl_cert_key = /data/cert/server.key                # 设置证书密钥文件路径

4.3 通过自带脚本一键安装(在harbor目录下)
[root@harbor harbor]# ./prepare
[root@harbor harbor]#  ./install.sh

4.4 通过浏览器访问管理  
[提前设置本地 hosts文件本地重定向至harbor服务器IP ]
vi /etc/hosts
添加
127.0.0.1 localhost docker-hub.onechain.com

4.5 开启80/443端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --zone=public --add-port=443/tcp --permanent
firewall-cmd --reload
firewall-cmd --query-port=80/tcp
firewall-cmd --query-port=443/tcp
firewall-cmd --list-all

https://docker-hub.onechain.com
用户默认为admin
密码默认为Harbor12345  [可通过安装前 harbor.cfg 配置文件修改 harbor_admin_password 指定 ]


测试登陆


发布了105 篇原创文章 · 获赞 35 · 访问量 31万+

猜你喜欢

转载自blog.csdn.net/mimica/article/details/80182751