7. 部署harbor镜像私有仓库(10.4.7.200主机)
7.1 下载安装harbor
# 目录说明:
# /opt/src : 源码、文件下载目录
# 为了方便软件升级
[root@hdss7-200 ~]# mkdir -p /opt/src
[root@hdss7-200 ~]# cd /opt/src
[root@hdss7-200 src]# wget https://github.com/goharbor/harbor/releases/download/v1.9.4/harbor-offline-installer-v1.9.4.tgz
[root@hdss7-200 src]# tar xf harbor-offline-installer-v1.9.4.tgz -C /opt/
[root@hdss7-200 src]# cd /opt
[root@hdss7-200 opt]# mv harbor/ harbor-v1.9.4
[root@hdss7-200 opt]# ln -s /opt/harbor-v1.9.4/ /opt/harbor
[root@hdss7-200 opt]# ll /opt
总用量 0
drwxr-xr-x. 2 root root 95 7月 15 10:18 certs
drwx--x--x. 4 root root 28 7月 15 10:48 containerd
lrwxrwxrwx. 1 root root 19 7月 15 14:15 harbor -> /opt/harbor-v1.9.4/
drwxr-xr-x. 2 root root 100 7月 15 14:10 harbor-v1.9.4
drwxr-xr-x. 2 root root 49 7月 15 14:07 src
# 实验环境仅修改以下配置项,生产环境需要修改密码
[root@hdss7-200 opt]# vim /opt/harbor/harbor.yml
hostname: harbor.od.com
http:
port: 180
data_volume: /data/harbor
location: /data/harbor/logs
[root@hdss7-200 opt]# yum install -y docker-compose
[root@hdss7-200 opt]# cd /opt/harbor/
[root@hdss7-200 harbor]# ./install.sh
......
✔ ----Harbor has been installed and started successfully.----
[root@hdss7-200 harbor]# docker-compose ps
Name Command State Ports
--------------------------------------------------------------------------------------
harbor-core /harbor/harbor_core Up
harbor-db /docker-entrypoint.sh Up 5432/tcp
harbor-jobservice /harbor/harbor_jobservice ... Up
harbor-log /bin/sh -c /usr/local/bin/ ... Up 127.0.0.1:1514->10514/tcp
harbor-portal nginx -g daemon off; Up 8080/tcp
nginx nginx -g daemon off; Up 0.0.0.0:180->8080/tcp
redis redis-server /etc/redis.conf Up 6379/tcp
registry /entrypoint.sh /etc/regist ... Up 5000/tcp
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