7. 部署harbor镜像私有仓库(10.4.7.200主机)

7.1 下载安装harbor

  1. # 目录说明:
  2. # /opt/src : 源码、文件下载目录
  3. # 为了方便软件升级
  4. [root@hdss7-200 ~]# mkdir -p /opt/src
  5. [root@hdss7-200 ~]# cd /opt/src
  6. [root@hdss7-200 src]# wget https://github.com/goharbor/harbor/releases/download/v1.9.4/harbor-offline-installer-v1.9.4.tgz
  7. [root@hdss7-200 src]# tar xf harbor-offline-installer-v1.9.4.tgz -C /opt/
  8. [root@hdss7-200 src]# cd /opt
  9. [root@hdss7-200 opt]# mv harbor/ harbor-v1.9.4
  10. [root@hdss7-200 opt]# ln -s /opt/harbor-v1.9.4/ /opt/harbor
  11. [root@hdss7-200 opt]# ll /opt
  12. 总用量 0
  13. drwxr-xr-x. 2 root root 95 7 15 10:18 certs
  14. drwx--x--x. 4 root root 28 7 15 10:48 containerd
  15. lrwxrwxrwx. 1 root root 19 7 15 14:15 harbor -> /opt/harbor-v1.9.4/
  16. drwxr-xr-x. 2 root root 100 7 15 14:10 harbor-v1.9.4
  17. drwxr-xr-x. 2 root root 49 7 15 14:07 src
  18. # 实验环境仅修改以下配置项,生产环境需要修改密码
  19. [root@hdss7-200 opt]# vim /opt/harbor/harbor.yml
  20. hostname: harbor.od.com
  21. http:
  22. port: 180
  23. data_volume: /data/harbor
  24. location: /data/harbor/logs
  25. [root@hdss7-200 opt]# yum install -y docker-compose
  26. [root@hdss7-200 opt]# cd /opt/harbor/
  27. [root@hdss7-200 harbor]# ./install.sh
  28. ......
  29. ----Harbor has been installed and started successfully.----
  30. [root@hdss7-200 harbor]# docker-compose ps
  31. Name Command State Ports
  32. --------------------------------------------------------------------------------------
  33. harbor-core /harbor/harbor_core Up
  34. harbor-db /docker-entrypoint.sh Up 5432/tcp
  35. harbor-jobservice /harbor/harbor_jobservice ... Up
  36. harbor-log /bin/sh -c /usr/local/bin/ ... Up 127.0.0.1:1514->10514/tcp
  37. harbor-portal nginx -g daemon off; Up 8080/tcp
  38. nginx nginx -g daemon off; Up 0.0.0.0:180->8080/tcp
  39. redis redis-server /etc/redis.conf Up 6379/tcp
  40. registry /entrypoint.sh /etc/regist ... Up 5000/tcp
  41. registryctl /harbor/start.sh Up

7.2 设置harbor开机自启

[root@hdss7-200 harbor]# vim /etc/rc.d/rc.local  # 增加以下内容
# start harbor(必须进入目录启动)
cd /opt/harbor
/usr/bin/docker-compose stop
/usr/bin/docker-compose start

7.3 配置nginx反向代理harbor

7.3.1 安装Nginx反向代理

# 当前机器中Nginx功能较少,使用yum安装即可。如有多个harbor考虑源码编译且配置健康检查
# nginx配置此处忽略,仅仅使用最简单的配置。
[root@hdss7-200 harbor]# yum -y install nginx
[root@hdss7-200 harbor]# vim /etc/nginx/conf.d/harbor.conf
[root@hdss7-200 harbor]# cat /etc/nginx/conf.d/harbor.conf
server {
    listen       80;
    server_name  harbor.od.com;
    # 避免出现上传失败的情况
    client_max_body_size 1000m;

    location / {
        proxy_pass http://127.0.0.1:180;
    }
}
[root@hdss7-200 harbor]# systemctl start nginx ; systemctl enable nginx

7.3.1 配置DNS服务器解析

[root@hdss7-200 ~]# vim /var/named/od.com.zone  
# 序列号需要向前滚动一位
$ORIGIN od.com.
$TTL 600  ; 10 minutes
@       IN SOA  dns.od.com. dnsadmin.od.com. (
        2020010502 ; serial
        10800      ; refresh (3 hours)
        900        ; retry (15 minutes)
        604800     ; expire (1 week)
        86400      ; minimum (1 day)
        )
        NS   dns.od.com.
$TTL 60 ; 1 minute
dns                A    10.4.7.11
harbor             A    10.4.7.200
[root@hdss7-200 ~]# systemctl restart named.service  # reload 无法使得配置生效
[root@hdss7-200 ~]# host harbor.od.com
harbor.od.com has address 10.4.7.200

7.3.4 测试harbor

浏览器打开 harbor.od.com登录harbor仓库
初始密码:Harbor12345
新建项目: public

[root@hdss7-200 ~]# docker pull nginx:1.7.9
[root@hdss7-200 ~]# docker images | grep 1.7.9
[root@hdss7-200 ~]# docker tag [images—id] harbor.od.com/public/nginx:v1.7.9
[root@hdss7-200 ~]# docker login -u admin harbor.od.com
[root@hdss7-200 ~]# docker push harbor.od.com/public/nginx:v1.7.9
[root@hdss7-200 ~]# docker logout