1. 安装
1.1 选择线下安装
1.2 复制到cent7上
[root@master01 ~]# ls
harbor-offline-installer-v1.6.2.tgz
[root@master01 ~]# tar -zxvf harbor-offline-installer-v1.6.2.tgz
[root@master01 ~]# ls
harbor-offline-installer-v1.6.2.tgz harbor
#删除压缩文件
[root@master01 ~]# rm -f harbor-offline-installer-v1.6.2.tgz
[root@master01 ~]# mkdir -p i/apps
[root@master01 ~]# mv harbor i/apps/
#修改配置文件
[root@master01 ~]# cd i/apps/harbor/
[root@master01 harbor]# ls
common docker-compose.notary.yml harbor.cfg LICENSE prepare
docker-compose.chartmuseum.yml docker-compose.yml harbor.v1.6.2.tar.gz NOTICE
docker-compose.clair.yml ha install.sh open_source_license
[root@master01 harbor]# vi harbor.cfg
#修改
hostname = reg.mydomain.com
hostname = hub.wanfei.com #是mac系统后面要加个端口8080
1.3 启动(不是mac系统直接启动),如果出现下面错误,先 安装docker-compose
[root@master01 harbor]# ./install.sh
[Step 0]: checking installation environment ...
Note: docker version: 18.03.1
✖ Need to install docker-compose(1.7.1+) by yourself first and run this script again.
1.4 如果是mac系统要修改挂载目录在启动(不是mac系统忽略这一步)
[root@master01 harbor]# vi docker-compose.yml
#修改后
version: '2'
services:
log:
image: goharbor/harbor-log:v1.6.2
container_name: harbor-log
restart: always
volumes:
- ./log/:/var/log/docker/:z #日志服务
- ./common/config/log/:/etc/logrotate.d/:z
ports:
- 127.0.0.1:1514:10514
networks:
- harbor
registry:
image: goharbor/registry-photon:v2.6.2-v1.6.2
container_name: registry
restart: always
volumes:
- ./data/registry:/storage:z #registry服务,存放所有镜像数据
- ./common/config/registry/:/etc/registry/:z
- ./common/config/custom-ca-bundle.crt:/harbor_cust_cert/custom-ca-bundle.crt:z
networks:
- harbor
environment:
- GODEBUG=netdns=cgo
depends_on:
- log
logging:
driver: "syslog"
options:
syslog-address: "tcp://127.0.0.1:1514"
tag: "registry"
postgresql:
image: goharbor/harbor-db:v1.6.2
container_name: harbor-db
restart: always
volumes:
- ./data/database:/var/lib/postgresql/data:z #数据库数据
networks:
- harbor
env_file:
- ./common/config/db/env
depends_on:
- log
logging:
driver: "syslog"
options:
syslog-address: "tcp://127.0.0.1:1514"
tag: "postgresql"
adminserver:
image: goharbor/harbor-adminserver:v1.6.2
container_name: harbor-adminserver
env_file:
- ./common/config/adminserver/env
restart: always
volumes:
- ./data/config/:/etc/adminserver/config/:z #3个adminserver挂载
- ./data/secretkey:/etc/adminserver/key:z
- ./data/:/data/:z
networks:
- harbor
depends_on:
- log
logging:
driver: "syslog"
options:
syslog-address: "tcp://127.0.0.1:1514"
tag: "adminserver"
ui:
image: goharbor/harbor-ui:v1.6.2
container_name: harbor-ui
env_file:
- ./common/config/ui/env
restart: always
volumes:
- ./common/config/ui/app.conf:/etc/ui/app.conf:z
- ./common/config/ui/private_key.pem:/etc/ui/private_key.pem:z
- ./common/config/ui/certificates/:/etc/ui/certificates/:z
- ./data/secretkey:/etc/ui/key:z #3个ui挂载
- ./data/ca_download/:/etc/ui/ca/:z
- ./data/psc/:/etc/ui/token/:z
networks:
- harbor
depends_on:
- log
- adminserver
- registry
logging:
driver: "syslog"
options:
syslog-address: "tcp://127.0.0.1:1514"
tag: "ui"
jobservice:
image: goharbor/harbor-jobservice:v1.6.2
container_name: harbor-jobservice
env_file:
- ./common/config/jobservice/env
restart: always
volumes:
- ./data/job_logs:/var/log/jobs:z #jobservice
- ./common/config/jobservice/config.yml:/etc/jobservice/config.yml:z
networks:
- harbor
depends_on:
- redis
- ui
- adminserver
logging:
driver: "syslog"
options:
syslog-address: "tcp://127.0.0.1:1514"
tag: "jobservice"
redis:
image: goharbor/redis-photon:v1.6.2
container_name: redis
restart: always
volumes:
- ./data/redis:/var/lib/redis #redis
networks:
- harbor
depends_on:
- log
logging:
driver: "syslog"
options:
syslog-address: "tcp://127.0.0.1:1514"
tag: "redis"
proxy:
image: goharbor/nginx-photon:v1.6.2
container_name: nginx
restart: always
volumes:
- ./common/config/nginx:/etc/nginx:z
networks:
- harbor
ports:
- 8080:80 #nginx对外的80端口mac不允许
- 443:443
- 4443:4443
depends_on:
- postgresql
- registry
- ui
- log
logging:
driver: "syslog"
options:
syslog-address: "tcp://127.0.0.1:1514"
tag: "proxy"
networks:
harbor:
external: false
1.5 安装成功
✔ ----Harbor has been installed and started successfully.----
Now you should be able to visit the admin portal at http://hub.wanfei.com.
For more details, please visit https://github.com/goharbor/harbor
2. 访问
2.1 先配置host
2.2 访问http://hub.wanfei.com
2.3 查看密码
[root@master01 harbor]# vim harbor.cfg
- 按
/
搜索harbor_admin_password
发现密码是Harbor12345
2.4 新建项目
2.5 进入项目
-
成员:
- 复制:生产环境多个机房之间网速很快,跨机房网速变差,每个机房部署一个harbor,再通过一个中心的harbor,当有镜像的时候会自动的同步到这两台镜像服务器,复制规则可以针对项目
2.6 添加用户
-
创建成功后可以在项目里面添加成员
-
指定刚才创建的成员为项目的开发人员
3. idea上传镜像到harbor
3.1 Docker Toolbox添加镜像源为http访问(因为没有证书)
- 首先,我们刚打开 Docker Quickstart Terminal 进入的是 Windows 命令行界面,此时输入下述命令进入虚拟 docker bash 中去:
#后面的 default 也可以不用输入,会自动补上
docker-machine ssh default
- 然后,我们已经进入了虚拟 docker bash 中去了,此时我们需要编辑
/var/lib/boot2docker/profile
文件中的EXTRA_ARGS
信息:
sudo vi /var/lib/boot2docker/profile
- 此时,我们在
--label provider=virtualbox
的下一行添加下述代码:
--insecure-registry xxx.xxx.xxx.xxx:yyy
这里需要解释的是, xxx.xxx.xxx.xxx 是我们的私有镜像仓库的 ip 地址或域名,yyy 是你配置私有镜像仓库时设定的端口号,80端口可以不写
- 最后,不要忘了,我们还需要重启 docker 服务的:
#在虚拟 docker 环境中
sudo /etc/init.d/docker restart
#或者
#退出虚拟 docker 环境(使用 exit 命令)然后在 Windows 命令行下敲入下列命令
docker-machine restart
3.2 idea Terminal登录harbor并推送镜像到hatbor仓库
16872@DESKTOP-LF85VK5 MINGW64 /d/javaProject/idea/springcloud (master)
$ docker login hub.wanfei.com
Username: www19930327
Password:
Login Succeeded
$ docker tab hub.wanfei.com/springcloud/test .
$ docker push hub.wanfei.com/springcloud/test:latest
The push refers to repository [hub.wanfei.com/springcloud/test]
bd7a66c91889: Preparing
a78d86126896: Preparing
30125717c842: Retrying in 4 seconds
011b303988d2: Preparing
error parsing HTTP 405 response body: invalid character '<' looking for beginning of value: "<html><title>405: Method Not Allowed</title><body>405: Method Not Allowed</body></html>"
如果出现405: Method Not Allowed
错误(上面)
是因为配置的域名没有在Docker Toolbox里面添加hosts映射
- 打开 Docker Quickstart Terminal,添加host映射
docker@default:/$ sudo vi /etc/hosts
127.0.0.1 default localhost localhost.local
# The following lines are desirable for IPv6 capable hosts
# (added automatically by netbase upgrade)
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
192.168.2.41 hub.wanfei.com
idea push成功
-
Dockerfile文件
-
build.sh脚本文件
3.3 cent7 docker push镜像到harbor
配置Docker加速及私有仓库的http协议支持
vim /etc/docker/daemon.json
#添加
{
"registry-mirrors": ["https://x83mabsk.mirror.aliyuncs.com"], #这个是加速地址
"insecure-registries": ["http://hub.wanfei.com"] #这里是私有仓库地址
}
#重启docker
[root@master01 ~]# systemctl daemon-reload
[root@master01 ~]# systemctl restart docker
#登录私有仓库harbor成功
[root@master01 ~]# docker login hub.wanfei.com
Username: admin
Password:
Login Succeeded
下载镜像并将镜像push到harbor
cent7
/etc/hosts
里面添加192.168.2.41 hub.wanfei.com
#下载镜像
[root@master01 ~]# docker pull oracle/openjdk:8
[root@master01 ~]# docker tag oracle/openjdk:8 hub.wanfei.com/springcloud/openjdk:8
[root@master01 ~]# docker push hub.wanfei.com/springcloud/openjdk:8
The push refers to repository [hub.wanfei.com/springcloud/openjdk]
ef2a536cc232: Pushed
72c79bf3dbce: Pushed
8: digest: sha256:8e28e0ba6b10187a1b4f07cf09cf536c15f22c94920c0facf7ff7f17fac460a5 size: 741