生成
[root@localhost ~]# cd /etc/pki/CA
[root@localhost CA]# openssl genrsa -out private/cakey.pem 2048 Generating RSA private key, 2048 bit long modulus
............................................+++
......................................................+++
e is 65537 (0x10001)
[root@localhost CA]# ls certs crl newcerts private
[root@localhost CA]# ls private/ cakey.pem
(3) 生成根证书 执行
[root@localhost CA]# openssl req -new -x509 -key private/cakey.pem -out cacert.pem You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:beijing
Locality Name (eg, city) [Default City]:beijing
Organization Name (eg, company) [Default Company Ltd]:hyzy
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) []:docker.nmgkj.com
Email Address []:
(4) 为 nginx web 服务器生成 ssl 密钥
[root@localhost CA]# mkdir /etc/pki/CA/ssl
[root@localhost CA]# cd /etc/pki/CA/ssl
[root@localhost ssl]# openssl genrsa -out nginx.key 2048Generating RSA private key, 2048 bit long modulus
...................................+++
.........+++
e is 65537 (0x10001)
注:因为 CA 中心与要申请证书的 nginx 服务器是同一个所以就在本机上执行为 nginx 服务器 生成 ssl 密钥了,否则应该是在另一台需要用到证书的服务器上生成。
查看 nginx 服务器的密钥
[root@localhost ssl]# lsnginx.key
(5) 为 nginx 生成证书签署请求 执行
[root@localhost ssl]# openssl req -new -key nginx.key -out nginx.csrYou are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:beijing
Locality Name (eg, city) [Default City]:beijing
Organization Name (eg, company) [Default Company Ltd]:hyzy
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) []:docker.nmgkj.com
Email Address []:
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
同样会提示输入一些内容,Commone Name 一定要是你要授予证书的服务器域名或主机名,
challenge password 不填。
(6) 私有 CA 根据请求来签发
[root@localhost ssl]# touch /etc/pki/CA/index.txt
[root@localhost ssl]# touch /etc/pki/CA/serial
[root@localhost ssl]# echo 00 > /etc/pki/CA/serial
[root@localhost ssl]# cat /etc/pki/CA/serial00
执行
[root@localhost ssl]# openssl ca -in nginx.csr -out nginx.crtUsing configuration from /etc/pki/tls/openssl.cnf
Check that the request matches the signature
Signature ok
Certificate Details:
Serial Number: 0 (0x0)
Validity
Not Before: Aug 10 01:45:33 2017 GMT
Not After : Aug 10 01:45:33 2018 GMT
Subject:
countryName = CN
stateOrProvinceName = beijing
organizationName = hyzy
commonName = docker.nmgkj.com
X509v3 extensions:
X509v3 Basic Constraints:
CA:FALSE
Netscape Comment:
OpenSSL Generated Certificate
X509v3 Subject Key Identifier:
21:97:A2:D4:46:42:6C:4D:BC:D2:B1:BE:29:92:29:E7:FF:20:CE:76
X509v3 Authority Key Identifier:
keyid:AB:65:D6:7B:61:0C:7D:46:D7:46:F1:7A:83:36:A5:62:B7:82:8A:2D
Certificate is to be certified until Aug 10 01:45:33 2018 GMT (365 days)
Sign the certificate? [y/n]:y
1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated
--with-http_realip_module开启 Real IP 的支持,该模块用于从客户请求的头数据中读 取 Real Ip 地址
--with-http_addition_module开启 Addtion 模块,该模块允许你追加或前置数据到相应 的主体部分
--with-http_flv_module 模块 ngx_http_flv_module 为 Flash Video(FLV)文件提供服务端伪流 媒体支持
(3)安装
[root@localhost nginx-1.11.2]# make && make install (4) 编辑/opt/nginx/conf/nginx.conf 文件
ECDSA key fingerprint is 52:70:64:73:95:ba:b5:6e:63:bb:35:da:7e:1c:5c:d7.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.107' (ECDSA) to the list of known hosts.
root@192.168.1.107's password:
cacert.pem 100% 1285 1.3KB/s 00:00
然后执行命令:
[root@localhost ~]# cat ./cacert.pem >> /etc/pki/tls/certs/ca-certificates.crt (3) 验证 docker.yy.com 下的 registry:
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/centos centos6 cf2c3ece5e41 13 months ago 194.6 MB
打标签
[root@localhost src]# docker tag centos:centos6 docker.nmgkj.com/centos:centos6
[root@localhost src]# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/centos centos6 cf2c3ece5e41 13 months ago 194.6 MB
docker.nmgkj.com/centos centos6 cf2c3ece5e41 13 months ago 194.6 MB
发布:上传镜像到本地私有仓库
[root@localhost ~]# docker push docker.nmgkj.com/centos:centos6The push refers to a repository [docker.nmgkj.com/centos]
2714f4a6cdee: Image successfully pushed
Pushing tag for rev [cf2c3ece5e41] on {https://docker.nmgkj.com/v1/repositories/centos/tags/centos6}
查看私有仓库是否有镜像
[root@localhost ~]# curl 192.168.1.107:5000/v1/search {"num_results": 1, "query": "", "results": [{"description": "", "name": "library/centos"}]}
查看镜像的存储目录和文件(在镜像服务器)
[root@localhost ~]# yum -y install tree
[root@localhost ~]# tree /opt/data/registry/repositories /opt/data/registry/repositories
Deleted: sha256:cf2c3ece5e418fd063bfad5e7e8d083182195152f90aac3a5ca4dbfbf6a1fc2a
Deleted: sha256:2714f4a6cdee9d4c987fef019608a4f61f1cda7ccf423aeb8d7d89f745c58b18
[root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE
Pulling repository docker.nmgkj.com/centos
cf2c3ece5e41: Pull complete
Status: Downloaded newer image for docker.nmgkj.com/centos:centos6
docker.nmgkj.com/centos: this image was pulled from a legacy registry. Important: This registry version will not be supported in future versions of docker.
[root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE