Docker虚拟化技术

环境搭建-CentOS下安装Harbor镜像仓库

2018-07-11  本文已影响143人  Statmoon

  harbor的官方安装指南介绍了harbor有三种安装方式,分别是在线安装、离线安装和OVA安装,由于网络环境受限,本文主要采用离线安装的方式。
  官方文档上面说明需要依赖Python 2.7或以上版本,Docker引擎1.10以上,还有Docker Compose 1.6.0或以上版本。
  CentOS 7.2自带Python 2.7.5

Python version.png
  Docker也已经提前安装:
Docker version.png
  所以剩下需要安装Docker Compose

安装Docker Compose

  下载Docker Compose

  下载1.21.2版本的Docker Compose,参考文档

sudo curl -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
docker-compose.png
  修改docker-compose为可执行文件:

chmod +x docker-compose
image.png
  测试是否安装成功

  运行命令【docker-compose version】测试安装是否成功: 测试.png

安装Harbor

  下载离线安装包

  在GitHub上找到下载地址并下载,我这里下载的1.5.1版本,整个文件800多MB:

image.png
  解压安装包

tar xvf harbor-offline-installer-v1.5.1.tgz
image.png
  修改配置文件【harbor.cfg】

vi harbor.cfg

  必需的参数有:

  1. hostname:目标主机的主机名,用于访问UI和注册服务。不能使用localhost和127.0.0.1,因为harbor需要被外部客户端访问,我这里修改成了IP地址。
    hostname.png
  2. ui_url_protocol:用于访问UI和令牌/通知服务的协议,默认为http,如果在Nginx上启用了SSL认证可以设置成https,我这里用的默认的http。
    ui_url_protocol.png
  3. max_job_workers:作业服务中的最大复制worker数,这里默认写的50,考虑到我的服务器的性能,我这里修改成了5。
    max_job_workers.png
  4. customize_crt:设置为on,prepare脚本创建用于生成/验证注册表令牌的私钥和根证书。如果设置成off,密钥和根证书将由外部源提供,我设置的是on。
    customize_crt.png
  5. ssl_cert:SSL证书的位置,只有协议设置成https的时候,这个属性才会生效。
  6. ssl_cert_key:SSL秘钥的位置,只有协议设置成https的时候,这个属性才会生效。
  7. secretkey_path:密码存放的路径,这里最好别修改,否则后面会报错,我修改成了【/data/admin/】。
    secretkey_path.png
  8. log_rotate_count:日志文件保留的数量,达到最大值后会循环删除之前的日志。
  9. log_rotate_size:每个日志的大小,我为了节省空间设置日志最多保留5个,每个最大200MB。
    log.png
  10. db_password:用于DB身份验证的MySQL数据库的根密码。
  运行【prepare】更新参数

./prepare
prepare.png
  开始安装

  执行【install.sh】进行安装

[root@localhost harbor]# ./install.sh 

[Step 0]: checking installation environment ...

Note: docker version: 17.03.2

Note: docker-compose version: 1.21.2

[Step 1]: loading Harbor images ...
52ef9064d2e4: Loading layer [==================================================>] 135.9 MB/135.9 MB
4a6862dbadda: Loading layer [==================================================>] 23.25 MB/23.25 MB
58b7d0c522b2: Loading layer [==================================================>]  24.4 MB/24.4 MB
9cd4bb748634: Loading layer [==================================================>] 7.168 kB/7.168 kB
c81302a14908: Loading layer [==================================================>] 10.56 MB/10.56 MB
7848e9ba72a3: Loading layer [==================================================>] 24.39 MB/24.39 MB
Loaded image: vmware/harbor-ui:v1.5.1
f1691b5a5198: Loading layer [==================================================>] 73.15 MB/73.15 MB
a529013c99e4: Loading layer [==================================================>] 3.584 kB/3.584 kB
d9b4853cff8b: Loading layer [==================================================>] 3.072 kB/3.072 kB
3d305073979e: Loading layer [==================================================>] 4.096 kB/4.096 kB
c9e17074f54a: Loading layer [==================================================>] 3.584 kB/3.584 kB
956055840e30: Loading layer [==================================================>] 9.728 kB/9.728 kB
Loaded image: vmware/harbor-log:v1.5.1
185db06a02d0: Loading layer [==================================================>] 23.25 MB/23.25 MB
835213979c70: Loading layer [==================================================>]  20.9 MB/20.9 MB
f74eeb41c1c9: Loading layer [==================================================>]  20.9 MB/20.9 MB
Loaded image: vmware/harbor-jobservice:v1.5.1
9bd5c7468774: Loading layer [==================================================>] 23.25 MB/23.25 MB
5fa6889b9a6d: Loading layer [==================================================>]  2.56 kB/2.56 kB
bd3ac235b209: Loading layer [==================================================>]  2.56 kB/2.56 kB
cb5d493833cc: Loading layer [==================================================>] 2.048 kB/2.048 kB
557669a074de: Loading layer [==================================================>]  22.8 MB/22.8 MB
f02b4f30a9ac: Loading layer [==================================================>]  22.8 MB/22.8 MB
Loaded image: vmware/registry-photon:v2.6.2-v1.5.1
5d3b562db23e: Loading layer [==================================================>] 23.25 MB/23.25 MB
8edca1b0e3b0: Loading layer [==================================================>] 12.16 MB/12.16 MB
ce5f11ea46c0: Loading layer [==================================================>]  17.3 MB/17.3 MB
93750d7ec363: Loading layer [==================================================>] 15.87 kB/15.87 kB
36f81937e80d: Loading layer [==================================================>] 3.072 kB/3.072 kB
37e5df92b624: Loading layer [==================================================>] 29.46 MB/29.46 MB
Loaded image: vmware/notary-server-photon:v0.5.1-v1.5.1
0a2f8f90bd3a: Loading layer [==================================================>] 401.3 MB/401.3 MB
41fca4deb6bf: Loading layer [==================================================>] 9.216 kB/9.216 kB
f2e28262e760: Loading layer [==================================================>] 9.216 kB/9.216 kB
68677196e356: Loading layer [==================================================>]  7.68 kB/7.68 kB
2b006714574e: Loading layer [==================================================>] 1.536 kB/1.536 kB
Loaded image: vmware/mariadb-photon:v1.5.1
a8c4992c632e: Loading layer [==================================================>] 156.3 MB/156.3 MB
0f37bf842677: Loading layer [==================================================>] 10.75 MB/10.75 MB
9f34c0cd38bf: Loading layer [==================================================>] 2.048 kB/2.048 kB
91ca17ca7e16: Loading layer [==================================================>] 48.13 kB/48.13 kB
5a7e0da65127: Loading layer [==================================================>]  10.8 MB/10.8 MB
Loaded image: vmware/clair-photon:v2.0.1-v1.5.1
0e782fe069e7: Loading layer [==================================================>] 23.25 MB/23.25 MB
67fc1e2f7009: Loading layer [==================================================>] 15.36 MB/15.36 MB
8db2141aa82c: Loading layer [==================================================>] 15.36 MB/15.36 MB
Loaded image: vmware/harbor-adminserver:v1.5.1
3f87a34f553c: Loading layer [==================================================>] 4.772 MB/4.772 MB
Loaded image: vmware/nginx-photon:v1.5.1
Loaded image: vmware/photon:1.0
ad58f3ddcb1b: Loading layer [==================================================>] 10.95 MB/10.95 MB
9b50f12509bf: Loading layer [==================================================>]  17.3 MB/17.3 MB
2c21090fd212: Loading layer [==================================================>] 15.87 kB/15.87 kB
38bec864f23e: Loading layer [==================================================>] 3.072 kB/3.072 kB
6e81ea7b0fa6: Loading layer [==================================================>] 28.24 MB/28.24 MB
Loaded image: vmware/notary-signer-photon:v0.5.1-v1.5.1
897a26fa09cb: Loading layer [==================================================>] 95.02 MB/95.02 MB
16e3a10a21ba: Loading layer [==================================================>] 6.656 kB/6.656 kB
85ecac164331: Loading layer [==================================================>] 2.048 kB/2.048 kB
37a2fb188706: Loading layer [==================================================>]  7.68 kB/7.68 kB
Loaded image: vmware/postgresql-photon:v1.5.1
bed9f52be1d1: Loading layer [==================================================>] 11.78 kB/11.78 kB
d731f2986f6e: Loading layer [==================================================>]  2.56 kB/2.56 kB
c3fde9a69f96: Loading layer [==================================================>] 3.072 kB/3.072 kB
Loaded image: vmware/harbor-db:v1.5.1
7844feb13ef3: Loading layer [==================================================>] 78.68 MB/78.68 MB
de0fd8aae388: Loading layer [==================================================>] 3.072 kB/3.072 kB
3f79efb720fd: Loading layer [==================================================>]  59.9 kB/59.9 kB
1c02f801c2e8: Loading layer [==================================================>] 61.95 kB/61.95 kB
Loaded image: vmware/redis-photon:v1.5.1
454c81edbd3b: Loading layer [==================================================>] 135.2 MB/135.2 MB
e99db1275091: Loading layer [==================================================>] 395.4 MB/395.4 MB
051e4ee23882: Loading layer [==================================================>] 9.216 kB/9.216 kB
6cca4437b6f6: Loading layer [==================================================>] 9.216 kB/9.216 kB
1d48fc08c8bc: Loading layer [==================================================>]  7.68 kB/7.68 kB
0419724fd942: Loading layer [==================================================>] 1.536 kB/1.536 kB
543c0c1ee18d: Loading layer [==================================================>] 655.2 MB/655.2 MB
4190aa7e89b8: Loading layer [==================================================>] 103.9 kB/103.9 kB
Loaded image: vmware/harbor-migrator:v1.5.0


[Step 2]: preparing environment ...
Clearing the configuration file: ./common/config/adminserver/env
Clearing the configuration file: ./common/config/ui/env
Clearing the configuration file: ./common/config/ui/app.conf
Clearing the configuration file: ./common/config/ui/private_key.pem
Clearing the configuration file: ./common/config/db/env
Clearing the configuration file: ./common/config/jobservice/env
Clearing the configuration file: ./common/config/jobservice/config.yml
Clearing the configuration file: ./common/config/registry/config.yml
Clearing the configuration file: ./common/config/registry/root.crt
Clearing the configuration file: ./common/config/nginx/nginx.conf
Clearing the configuration file: ./common/config/log/logrotate.conf
loaded secret from file: /data/admin/secretkey
Generated configuration file: ./common/config/nginx/nginx.conf
Generated configuration file: ./common/config/adminserver/env
Generated configuration file: ./common/config/ui/env
Generated configuration file: ./common/config/registry/config.yml
Generated configuration file: ./common/config/db/env
Generated configuration file: ./common/config/jobservice/env
Generated configuration file: ./common/config/jobservice/config.yml
Generated configuration file: ./common/config/log/logrotate.conf
Generated configuration file: ./common/config/jobservice/config.yml
Generated configuration file: ./common/config/ui/app.conf
Generated certificate, key file: ./common/config/ui/private_key.pem, cert file: ./common/config/registry/root.crt
The configuration files are ready, please use docker-compose to start the service.


[Step 3]: checking existing instance of Harbor ...


[Step 4]: starting Harbor ...
Creating network "harbor_harbor" with the default driver
Creating harbor-log ... done
Creating harbor-db          ... done
Creating redis              ... done
Creating registry           ... 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://192.168.242.132 . 
For more details, please visit https://github.com/vmware/harbor .

  安装完成,访问一下【http://192.168.242.132】试试,502错误,why?


502.png   通过命令【docker ps】查看一下容器,发现有8个容器,其中harbor-adminserver节点一直处于Restarting状态。 容器.png

  查看adminserver的日志

tail -n 50 /var/log/harbor/adminserver.log
  看到如下错误:failed to initialize the system: read /etc/adminserver/key: is a directory image.png
  这是因为【/usr/local/harbor/docker-compose.yml】中【secretkey】的设置和【harbor.cfg】的设置不同,【docker-compose.yml】的配置: docker-compose.yml.png
  将【harbor.cfg】中的【secretkey_path】改回【/data】,然后执行【docker-compose down】,停止并删出所有的容器。
image.png

  然后删除目录【/data/secretkey】

rm -rf /data/secretkey

  重新运行【prepare】

./prepare
image.png

  最后再创建容器并启动

docker-compose up –d
image.png

  再运行【docker ps】看下容器状态


image.png

  都正常了,访问【http://192.168.242.132】看一下,能正常访问了:


image.png
  使用admin账号登录
image.png
  搭建成功。
上一篇下一篇

猜你喜欢

热点阅读