局域网网站建设软件,网站无法连接到服务器,淘宝网页设计培训,melogin点击进入一、 安装的前提条件
硬件 资源 最低 推荐 cpu2C4C内存4G8G硬盘40G160G
软件 软件 版本 描述 dockerv17.0.6-ce 安装参考官方文档 Install Docker Engine | Docker Documentation docker-composev1.18.0 安装参考官方文档 Overview | Docker Documentation Openssllatest…一、 安装的前提条件
硬件 资源 最低 推荐 cpu2C4C内存4G8G硬盘40G160G
软件 软件 版本 描述 dockerv17.0.6-ce 安装参考官方文档 Install Docker Engine | Docker Documentation docker-composev1.18.0 安装参考官方文档 Overview | Docker Documentation Openssllatest用于为harbor生成证书和密钥
二、安装配置
生成harbor自签证书和密钥
docker 在docker login 时默认使用 https 的方式连接到镜像仓库修改docker连接方式需要重启docker生产环境不允许所以要提前为harbor 准备证书和密钥。
1.生成 CA 证书私钥
$ openssl genrsa -out ca.key 1024
2.生成 CA 证书
$ openssl req -x509 -new -nodes -sha512 -days 3650 -subj /CUS/STTestState/LTestCity/OTestOrg/OUTestOU/CNTest -key ca.key -out ca.crt 3.生成私钥
$ openssl genrsa -out test.harbor.com.key 1024
4.生成证书签名请求
$ openssl req -sha512 -new \-subj /CUS/STTestState/LTestCity/OTestOrg/OUTestOU/CNTest \-key test.harbor.com.key \-out test.harbor.com.csr
5.生成 x509 v3扩展文件
$ cat v3.ext
authorityKeyIdentifierkeyid,issuer
basicConstraintsCA:FALSE
keyUsage digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
extendedKeyUsage serverAuth
subjectAltName alt_names[alt_names]
DNS.1test.harbor.com
DNS.2test.harbor
DNS.3harbor
6.使用该v3.ext文件为的Harbor主机生成证书
$ openssl x509 -req -sha512 -days 3650 -extfile v3.ext -CA ca.crt -CAkey ca.key -CAcreateserial -in test.harbor.com.csr -out test.harbor.com.crt
7.提供证书给Harbor和Docker
将服务器的证书和密钥复制到harbor主机证书文件夹中/etc/docker/certs.d/
将crt文件 解释为CA证书cert
$ openssl x509 -inform PEM -in test.harbor.com.crt -out test.harbor.com.cert
将服务器证书、密钥和CA文件复制到Docker证书文件夹中
$ cp test.harbor.com.cert /etc/docker/certs.d/test.harbor.com/
$ cp test.harbor.com.key /etc/docker/certs.d/test.harbor.com/
$ cp ca.crt /etc/docker/certs.d/test.harbor.com/
安装配置Harbor
安装目录为 /opt/harbor 目录 1. 将离线安装包mv至安装目录并解压
$ mv /tmp/harbor-offline-installer-v2.3.5.tgz /opt/harbor
$ cd /opt/harbor tar -vxf harbor-offline-installer-v2.3.5.tgz
harbor/harbor.v2.3.5.tar.gz
harbor/prepare
harbor/LICENSE
harbor/install.sh
harbor/common.sh
harbor/harbor.yml.tmpl
2.copy原来的配置文件harbor.yml.tmpl 为harbor.yml并修改harbor的配置文件 $ cd harbor cp harbor.yml.tmpl harbor.yml
修改的地方有
$ vim harbor.yml
hostname: test.harbor.com
http:port: 80
https:port: 443certificate: /path/test.harbor.com.certprivate_key: /path/test.harbor.com.key
harbor_admin_password: xxxxx
database:password: xxxxx
data_volume: /opt/harbor/data3.修改完后启动harbor配置文件修改后都得先执行 ./prepare 安装执行 ./install
$ ./prepare
$ ./install
docker-compose 常用命令
# docker-compose 命令需要在模板文件docker-compose.yml所在目录执行才有效
docker-compose up -d # 启动服务(后台运行)
docker-compose start # 启动服务
docker-compose stop # 停止正在运行的服务
docker-compose down # 停止和删除容器、网络、卷、镜像等参数 -v 会将数据卷一起删除
docker-compose restart # 重启服务
docker-compose ps # 查看服务
docker-compose top # 查看服务中运行的进程
三、Harbor 加入开机自启
$ vim /usr/lib/systemd/system/harbor.service
[Unit]
DescriptionHarbor
Afterdocker.service systemd-networkd.service systemd-resolved.service
Requiresdocker.service
Documentationhttp://github.com/vmware/harbor
[Service]
Typesimple
Restarton-failure
RestartSec5
# docker-compose.yml文件为harbor启动文件应使用绝对路径
ExecStart/bin/docker-compose -f /opt/harbor/harbor/docker-compose.yml up -d
ExecStop/bin/docker-compose -f /opt/harbor/harbor/docker-compose.yml down
[Install]
WantedBymulti-user.target$ chmod x /usr/lib/systemd/system/harbor.service
$ systemctl daemon-reload
$ systemctl start harbor
$ systemctl enable harbor
$ systemctl status harbor
四、测试连接Harbor私有仓库
不建议添加为Docker私有仓库地址因为需要重启docker才可生效要登录harbor仓库中时可进行以下操作
$ vim /etc/hosts
10.40.x.x test.harbor.com
$ docker login test.harbor.com
$ docker pull images