Harbor仓库搭建
一、安装Docker
#移除自带的yum源 mv /etc/yum.repos.d/* /tmp/ #docker依赖三个yum源:Base,Extras,docker-ce wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo wget -O /etc/yum.repos.d/docker-ce.repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo #清理yum缓存 yum clean all #安装docker yum install docker-ce -y 启动docker并设置开机自启 systemctl start docker systemctl enable docker #查看docker版本 docker version
二、安装docker compose
yum install docker-compose -y
三、下载Harbor安装包并解压缩
官网地址:https://goharbor.io/
下载地址:https://github.com/goharbor/harbor/releases/
选择离线版本下载: harbor-offline-installer-v2.4.1.tgz
wget https://github.com/goharbor/harbor/releases/download/v2.4.1/harbor-offline-installer-v2.4.1.tgz tar xvf harbor-offline-installer-v2.4.1.tgz -C /opt/ #添加版本号方便区分 mv /opt/harbor /opt/harbor-v2.4.1 #创建软连接方便版本升级 ln -s /opt/harbor-v2.4.1 /opt/harbor
四、修改harbor配置文件
cd /opt/harbor cp harbor.yml.tmpl harbor.yml vim harbor.yml hostname: 192.168.5.232 #修改此行,指向当前主机IP 或 FQDN,线上环境最好用FQDN http: port: 180 data_volume: /data/harbor location: /data/harbor/logs harbor_admin_password: 123456 #修改此行指定harbor登录用户admin的密码,默认用户/密码:admin/Harbor12345 mkdir -p /data/harbor /data/harbor/logs /opt/harbor/install.sh #执行安装脚本 #安装完毕默认已启动,启停命令如下: /usr/bin/docker-compose start /usr/bin/docker-compose stop #加入开机自启动 vim /etc/rc.d/rc.local cd /opt/harbor /usr/docker-compose stop /usr/docker-compose start
五、安装Nginx反向代理harbor
yum install nginx -y vim /etc/nginx/conf.d/harbor.conf server { listen 80; server_name 192.168.5.232; # 避免出现上传失败的情况 client_max_body_size 1000m; location / { proxy_pass http://127.0.0.1:180; } } #启动nginx,并加入开机自启 systemctl start nginx systemctl enable nginx
六、登陆harbor的web页面,并创建项目
用浏览器访问 http://192.168.5.323/
七、命令行登录harbor并上传镜像到仓库
#编辑/etc/docker/daemon.json { "registry-mirrors": ["https://kroknwmp.mirror.aliyuncs.com"], "insecure-registries":["http://192.168.5.232"] } #重启docker systemctl restart docker #启动harbor
cd /opt/harbor /usr/bin/docker-compose start #命令行登陆harbor docker login 192.168.5.232 #上传镜像到harbor docker tag alpine:latest 192.168.5.232/public/alpine:latest docker push 192.168.5.232/public/alpine:latest