本文参考 : https://blog.csdn.net/qq_40378034/article/details/90752212
在部署当中也出现了部分问题:yum源版本问题重新切换yum源,服务器内核问题升级了最新的内核,这些问题解决方案均在个人主页中。
[root@localhost ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
[root@localhost ~]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
[root@localhost ~]# yum install -y docker-ce docker-ce-cli containerd.io
[root@localhost ~]# sudo curl -L "https://github.com/docker/compose/releases/download/1.25.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
要是多次尝试下载失败的话,建议尝试直接切换yum源。
https://blog.csdn.net/qq_40213055/article/details/123014546
[root@localhost ~]# chmod +x /usr/local/bin/docker-compose
[root@localhost ~]# docker-compose --version
docker-compose version 1.13.0, build 1719ceb
从GitHub上https://github.com/goharbor/harbor/releases下载指定版本的安装包
当前下载安装的是Hardbor v1.1.2
[root@localhost ~]# mkdir -p /harbor
[root@localhost ~]# cd /harbor/
[root@localhost harbor]# yum -y install wget
[root@localhost harbor]# wget https://github.com/vmware/harbor/releases/download/v1.1.2/harbor-online-installer-v1.1.2.tgz
[root@localhost harbor]# ls
harbor-online-installer-v1.1.2.tgz
[root@localhost harbor]# tar -zxf harbor-online-installer-v1.1.2.tgz
[root@localhost harbor]# ls
harbor harbor-online-installer-v1.1.2.tgz
[root@localhost harbor]# cd harbor
[root@localhost harbor]# ls
common docker-compose.notary.yml docker-compose.yml harbor_1_1_0_template harbor.cfg install.sh LICENSE NOTICE prepare upgrade
[root@localhost harbor]# vi harbor.cfg
配置文件harbor.cfg详解:
# hostname设置访问地址,可以使用ip、域名,不可以设置为127.0.0.1或localhost
hostname = 10.1.5.92
# 访问协议,默认是http,也可以设置https,如果设置https,则nginx ssl需要设置on
ui_url_protocol = http
# mysql数据库root用户默认密码root123,实际使用时修改下
db_password = 123456
max_job_workers = 3
customize_crt = on
ssl_cert = /data/cert/server.crt
ssl_cert_key = /data/cert/server.key
secretkey_path = /data
admiral_url = NA
# 邮件设置,发送重置密码邮件时使用
email_identity =
email_server = smtp.mydomain.com
email_server_port = 25
email_username = sample_admin@mydomain.com
email_password = abc
email_from = admin <sample_admin@mydomain.com>
email_ssl = false
# 启动Harbor后,管理员UI登录的密码,默认是Harbor12345
harbor_admin_password = 123456
# 认证方式,这里支持多种认证方式,如LADP、本次存储、数据库认证。默认是db_auth,mysql数据库认证
auth_mode = db_auth
# LDAP认证时配置项
ldap_url = ldaps://ldap.mydomain.com
#ldap_searchdn = uid=searchuser,ou=people,dc=mydomain,dc=com
#ldap_search_pwd = password
ldap_basedn = ou=people,dc=mydomain,dc=com
#ldap_filter = (objectClass=person)
ldap_uid = uid
ldap_scope = 3
ldap_timeout = 5
# 是否开启自注册
self_registration = on
# token有效时间,默认30分钟
token_expiration = 30
# 用户创建项目权限控制,默认是everyone(所有人),也可以设置为adminonly(只能管理员)
project_creation_restriction = everyone
verify_remote_cert = on
简单使用的话只需要修改如下位置:
# 修改成自己服务器的ip
hostname = 10.1.5.92
# mysql数据库root用户默认密码root123,实际使用时修改下
db_password = 123456
# 邮件设置,发送重置密码邮件时使用
email_identity = 123@163.com
# 启动Harbor后,管理员UI登录的密码,默认是Harbor12345
harbor_admin_password = 123456
启动harbor前先启动docker
# 启动docker
[root@localhost harbor]# systemctl start docker
# 设置docker开机启动
[root@localhost harbor]# systemctl enable docker
启动Harbor:修改完配置文件后,在的当前目录执行./install.sh,Harbor服务就会根据当期目录下的docker-compose.yml开始下载依赖的镜像,检测并按照顺序依次启动各个服务
[root@localhost harbor]# ./install.sh
Harbor依赖的镜像及启动服务如下:
[root@localhost harbor]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e919b83f2467 vmware/nginx:1.11.5-patched "nginx -g 'daemon of…" 19 minutes ago Up 19 minutes 0.0.0.0:80->80/tcp, :::80->80/tcp, 443/tcp nginx
356b094794e9 vmware/harbor-jobservice:v1.1.2 "/harbor/harbor_jobs…" 19 minutes ago Up 19 minutes harbor-jobservice
74b9ec68989b vmware/harbor-ui:v1.1.2 "/harbor/harbor_ui" 19 minutes ago Up 19 minutes harbor-ui
89d33e4cdb18 vmware/registry:2.6.1-photon "/entrypoint.sh serv…" 19 minutes ago Up 19 minutes 5000/tcp registry
120b7df05cf1 vmware/harbor-db:v1.1.2 "docker-entrypoint.s…" 19 minutes ago Up 19 minutes 3306/tcp harbor-db
1c698ca700d9 vmware/harbor-adminserver:v1.1.2 "/harbor/harbor_admi…" 19 minutes ago Up 19 minutes harbor-adminserver
4a3477f6902d vmware/harbor-log:v1.1.2 "/bin/sh -c 'crond &…" 19 minutes ago Up 19 minutes 127.0.0.1:1514->514/tcp harbor-log
如果需要修改端口号:::启动完成后,访问刚设置的hostname(刚我设置的是:10.1.5.92)直接访问即可,默认是80端口,如果端口占用,可以去修改docker-compose.yml文件中,对应服务的端口映射 修改docker-compose.yml 如下:
使用admin用户登录,密码为harbor.cfg配置的密码(123456)
我们新建一个名称为harbor的项目,设置不公开。当项目设为公开后,任何人都有此项目下镜像的读权限。命令行用户不需要docker login就可以拉取此项目下的镜像。
新建项目后,使用admin用户提交本地nginx镜像到Harbor仓库
使用docker login出现如下类似问题:
[root@localhost harbor]# docker login 10.1.5.92
Username: admin
Password:
Error response from daemon: Get "https://10.1.5.92/v2/": dial tcp 10.1.5.92:443: connect: connection refused
修改 docker.service
[root@localhost harbor]# vim /usr/lib/systemd/system/docker.service
在 ExecStart=/usr/bin/dockerd -H fd:// 后面添加 --insecure-registry http://10.1.5.92:80
--insecure-registry http://10.1.5.92
[root@localhost harbor]# systemctl daemon-reload
[root@localhost harbor]# systemctl restart docker
[root@localhost harbor]# ./install.sh
再次登录即可
[root@localhost harbor]# docker login 10.1.5.92
Username: admin
Password:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
[root@localhost harbor]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
vmware/harbor-jobservice v1.1.2 4ef0a7a33734 4 years ago 163MB
vmware/harbor-ui v1.1.2 4ee8f190f366 4 years ago 183MB
vmware/harbor-adminserver v1.1.2 cdcf1bed7eb4 4 years ago 142MB
vmware/harbor-db v1.1.2 fcb8aa7a0640 4 years ago 329MB
vmware/registry 2.6.1-photon 0f6c96580032 4 years ago 150MB
vmware/nginx 1.11.5-patched 8ddadb143133 4 years ago 199MB
vmware/harbor-log v1.1.2 9c46a7b5e517 4 years ago 192MB
[root@localhost harbor]# docker tag vmware/nginx:1.11.5-patched 10.1.5.92/harbor/nginx:latest
[root@localhost harbor]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
vmware/harbor-jobservice v1.1.2 4ef0a7a33734 4 years ago 163MB
vmware/harbor-ui v1.1.2 4ee8f190f366 4 years ago 183MB
vmware/harbor-adminserver v1.1.2 cdcf1bed7eb4 4 years ago 142MB
vmware/harbor-db v1.1.2 fcb8aa7a0640 4 years ago 329MB
vmware/registry 2.6.1-photon 0f6c96580032 4 years ago 150MB
10.1.5.92/harbor/nginx latest 8ddadb143133 4 years ago 199MB
vmware/nginx 1.11.5-patched 8ddadb143133 4 years ago 199MB
vmware/harbor-log v1.1.2 9c46a7b5e517 4 years ago 192MB
[root@localhost harbor]# docker push 10.1.5.92/harbor/nginx:latest
The push refers to repository [10.1.5.92/harbor/nginx]
3569f62067e2: Pushed
3f117c44afbb: Pushed
c4a8b7411af4: Pushed
fe4c16cbf7a4: Pushed
latest: digest: sha256:3dce35afeadd7195877b17bf1514b9e388ed671afe428441fe5e0b02cdc26eeb size: 1160
上传成功后,登录Web Harbor,选择项目harbor,就可以查看刚刚上传的nginx镜像了
系统管理下的用户管理,点击创建用户。
将刚刚创建的用户添加到harbor项目成员中,点击项目,选择harbor项目,点击成员,点击添加成员,添加姓名选择角色
使用新建的用户将刚刚上传的nginx镜像拉取下来
先将刚刚nginx镜像删除
[root@localhost harbor]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
vmware/harbor-jobservice v1.1.2 4ef0a7a33734 4 years ago 163MB
vmware/harbor-ui v1.1.2 4ee8f190f366 4 years ago 183MB
vmware/harbor-adminserver v1.1.2 cdcf1bed7eb4 4 years ago 142MB
vmware/harbor-db v1.1.2 fcb8aa7a0640 4 years ago 329MB
vmware/registry 2.6.1-photon 0f6c96580032 4 years ago 150MB
10.1.5.92/harbor/nginx latest 8ddadb143133 4 years ago 199MB
vmware/nginx 1.11.5-patched 8ddadb143133 4 years ago 199MB
vmware/harbor-log v1.1.2 9c46a7b5e517 4 years ago 192MB
[root@localhost harbor]# docker rmi 10.1.5.92/harbor/nginx:latest
Untagged: 10.1.5.92/harbor/nginx:latest
Untagged: 10.1.5.92/harbor/nginx@sha256:3dce35afeadd7195877b17bf1514b9e388ed671afe428441fe5e0b02cdc26eeb
退出admin帐号,使用刚刚创建的用户登录
[root@localhost harbor]# docker logout 10.1.5.92
Removing login credentials for 10.1.5.92
[root@localhost harbor]# docker login 10.1.5.92
Username: harbor
Password:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
将harbor中的nginx镜像拉取到本地
[root@localhost harbor]# docker pull 10.1.5.92/harbor/nginx:latest
latest: Pulling from harbor/nginx
Digest: sha256:3dce35afeadd7195877b17bf1514b9e388ed671afe428441fe5e0b02cdc26eeb
Status: Downloaded newer image for 10.1.5.92/harbor/nginx:latest
10.1.5.92/harbor/nginx:latest
[root@localhost harbor]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
vmware/harbor-jobservice v1.1.2 4ef0a7a33734 4 years ago 163MB
vmware/harbor-ui v1.1.2 4ee8f190f366 4 years ago 183MB
vmware/harbor-adminserver v1.1.2 cdcf1bed7eb4 4 years ago 142MB
vmware/harbor-db v1.1.2 fcb8aa7a0640 4 years ago 329MB
vmware/registry 2.6.1-photon 0f6c96580032 4 years ago 150MB
10.1.5.92/harbor/nginx latest 8ddadb143133 4 years ago 199MB
vmware/nginx 1.11.5-patched 8ddadb143133 4 years ago 199MB
vmware/harbor-log v1.1.2 9c46a7b5e517 4 years ago 192MB
结束!