操作系统 | 配置 | 主机名 | IP | 所需软件 |
---|---|---|---|---|
CentOS 7.9 | 2C4G | harbor | 192.168.93.165 | docker 26.1.2 docker-compose harbor-offline-v1.1.2 |
CentOS 7.9 | 2C4G | client | 192.168.93.166 | docker 26.1.2 |
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
sed -i "s/^SELINUX=.*/SELINUX=disabled/g" /etc/selinux/config
hostnamectl set-hostname harbor
hostnamectl set-hostname client
# 下载阿里云docker-compose二进制文件
[root@harbor ~]# curl -L https://mirrors.aliyun.com/docker-toolbox/linux/compose/1.21.2/docker-compose-Linux-x86_64 -o /usr/local/bin/docker-compose
# 添加可执行权限
[root@harbor ~]# chmod +x /usr/local/bin/docker-compose
[root@harbor ~]# docker-compose -v
docker-compose version 1.21.2, build a133471
[root@harbor ~]# yum -y install wget
[root@harbor ~]# wget https://github.com/goharbor/harbor/releases/download/v2.6.1/harbor-offline-installer-v2.6.1.tgz
[root@harbor ~]# tar -zxvf harbor-offline-installer-v2.0.2.tgz -C /usr/local/
# 拷贝一份Harbor的配置文件
[root@harbor ~]# cp /usr/local/harbor/harbor.yml.tmpl /usr/local/harbor/harbor.yml
[root@harbor ~]# vim /usr/local/harbor/harbor.yml
# 修改hostname,修改为自己的IP地址
hostname: 192.168.93.165
# 将https段的内容全部注释,这里不使用https访问
################################################################
#https:
# https port for harbor, default is 443
#port: 443
# The path of cert and key files for nginx
#certificate: /your/certificate/path
#private_key: /your/private/key/path
################################################################
# 对配置文件进行语法检查,将会自动拉取必要的镜像
[root@harbor ~]# /usr/local/harbor/prepare
1、hostname:用于访问用户界面和register服务。他应该是目标机器的IP地址或完全限定域名(FQDN),例如192.168.93.165或hun.kgc.cn。不要使用localhost或172.0.0.1
2.ui_rul_protocol:(http或httpds,默认为http)用于访问UI和令牌/通知服务的协议。如果公证处于启用状态,则此参数必须为https
3.max_job_workers:镜像复制作业线程
4.db_password:用于db_auth的MySQL数据库root用户的密码
5.customize_crt:该属性可设置为打开或关闭,默认打开,打开此属性时,准备脚本创建私钥和根整数,用于生成/验证注册表令牌。当由外部来源提供密钥和根证书时,将此属性设置为off
6.ssl_cert:SSL证书的路路径,仅当协议设置为https时采应用
7.ssl_cert_key:SSL密钥的路径,仅当协议设置为https时才应用
8.secretkey_path:用于在复制策略中加密或解密远程register密码的的密钥路径
1.Email:Harbor需要该参数才能向用户发送“密码重置”,并且只有在需要该功能时才需要。请注意,在默认情况下SSL连接时没有启动。如果SMTP服务器需要SSL,但不支持StartLS,那么应该通过设置启动SSL email_ssl = TRUE
2.harbour_admin_password:管理员的处理密码,只在Harbour第一次启动时生效。之后,此设置将被忽略,并且应在UI设置管理员的密码。请注意,默认的用户名/密码时admin/Harbor12345
3.auth_mode:使用的认证类型,默认情况下,它时db_auth,即凭据存储在数据库中对于LADP身份验证,请将其设置位ldap_auth
4.seif_registration:启动/禁用用户注册功能。禁用时,新用户只能由Admin用户创建只有管理员用户可以在Harbor中创建新用户。注意:当auth_mode设置为ldap_auth时,自动注册功能始终处理禁用状态,并且该标志被忽略
5.Token_enpiration:由令牌服务创建的令牌的到期时间(分钟),默认位30分钟
6.project_creation_restriction:用于控制哪些用户的权限项目的标志。默认情况下,每个人都可以创建项目。如果将其设置位"adminonly",那么只有admin可以创建项目
7.verify_remote_cert:打开或关闭,默认打开。此标志决定了当Harbour与远程register实例通信时是否验证SSL/TLS证书。将此属性设置为off将绕过SSL/TLS验证,这在远程实例具有自签名或不可信证书时经常使用。
# 需要一点时间,等待安装回显结束即可
[root@harbor ~]# sh /usr/local/harbor/install.sh
[root@harbor ~]# cd /usr/local/harbor/
[root@harbor harbor]# docker-compose ps
Name Command State Ports
--------------------------------------------------------------------------------------------------------
harbor-core /harbor/entrypoint.sh Up (healthy)
harbor-db /docker-entrypoint.sh Up (healthy) 5432/tcp
harbor-jobservice /harbor/entrypoint.sh Up (healthy)
harbor-log /bin/sh -c /usr/local/bin/ ... Up (healthy) 127.0.0.1:1514->10514/tcp
harbor-portal nginx -g daemon off; Up (healthy) 8080/tcp
nginx nginx -g daemon off; Up (healthy) 0.0.0.0:80->8080/tcp,:::80->8080/tcp
redis redis-server /etc/redis.conf Up (healthy) 6379/tcp
registry /home/harbor/entrypoint.sh Up (healthy) 5000/tcp
registryctl /home/harbor/start.sh Up (healthy)
在WEB UI界面创建新项目的操作步骤如下。
输入用户名和面膜登录界面后可以创建一个新项目。点击“+新建项目”按钮
填写项目名称为“myproject-kgc”
点击“确定”按钮,成功创建新项目后,页面效果如下
此时可使用Docker命令在本地通过127.0.0.1来登录和推送镜像。默认情况下Register服务器在端口80上侦听
[root@harbor ~]# docker login -u admin -p Harbor12345 http://127.0.0.1
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
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@harbor ~]# docker pull cirros
# push上传镜像必须要以,以下格式进行打标签
# 格式:私有仓库IP地址/项目名称/镜像标签
[root@harbor ~]# docker tag cirros:latest 127.0.0.1/myproject-kgc/cirros:v1
[root@harbor ~]# docker push 127.0.0.1/myproject-kgc/cirros:v1
The push refers to repository [127.0.0.1/myproject-kgc/cirros]
d8083b07a8e2: Pushed
b42b2edd1b7f: Pushed
032cc20cbfb2: Pushed
v1: digest: sha256:d573d48afdade1ef2c5bba38681e8c8ce0794e985409e7d5c35a2c3653c547aa size: 943
[root@client ~]# docker login -u admin -p Harbor12345 http://192.168.93.165
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
Error response from daemon: Get "https://192.168.93.165/v2/": dial tcp 192.168.93.165:443: connect: connection refused
# 解决办法1
[root@client ~]# vim /usr/lib/systemd/system/docker.service
ExecStart=/usr/bin/dockerd --insecure-registry 192.168.93.165
[root@client ~]# systemctl daemon-reload
[root@client ~]# systemctl restart docker
# 解决办法2
cat > /etc/docker/daemon.json << EOF
{
# 这个是修改为国内的镜像源,使用国内的源访问速度会快一点
"registry-mirrors": ["https://r9xxm8z8.mirror.aliyuncs.com"],
# 指定私有仓库IP地址
"insecure-registries":["192.168.93.156"]
}
EOF
[root@client ~]# systemctl daemon-reload
[root@client ~]# systemctl restart docker.service
[root@client ~]# docker login -u admin -p Harbor12345 http://192.168.93.165
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
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@client ~]# docker pull nginx
[root@client ~]# docker tag nginx:latest 192.168.93.165/myproject-kgc/nginx:v1
# 上传镜像
[root@client ~]# docker push 192.168.93.165/myproject-kgc/nginx:v1
在Web管理界面中单击系统管理-》用户管理-》+创建用户,填写用户名为“kgc-user01”,邮箱为kgc-user01@kgc.cn,全名为“课超新人”,密码为“A123a456”,注释为“管理员”
用户创建成功后,单击左侧“…”按钮可将上述创建的用户设置为管理员角色或进行删除操作。本案例不做任何设置
单击项目-》myproject-kgc-》成员-》+成员,填写上述创建的用户并分配角色为“开发人员”
此时单击左侧“…”按钮仍然可以对成员角色进行变更或者删除操作
[root@client ~]# docker rmi 192.168.93.165/myproject-kgc/nginx:v1
# 退出账号
[root@client ~]# docker logout 192.168.93.165
Removing login credentials for 192.168.93.165
# 登录账号
[root@client ~]# docker login -u kgc-user01 -p A123a456 http://192.168.93.165
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
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@client ~]# docker pull 192.168.93.165/myproject-kgc/nginx:v1
v1: Pulling from myproject-kgc/nginx
09f376ebb190: Pull complete
5529e0792248: Pull complete
9b3addd3eb3d: Pull complete
57910a8c4316: Pull complete
7b5f78f21449: Pull complete
b7923aa4e8a6: Pull complete
785625911f12: Pull complete
Digest: sha256:0db204f933b6d1def0c0c15578f61a80091f8316b04150918413fc4d5c87be69
Status: Downloaded newer image for 192.168.93.165/myproject-kgc/nginx:v1
192.168.93.165/myproject-kgc/nginx:v1
[root@harbor ~]# cd /usr/local/harbor/
[root@harbor harbor]# docker-compose stop | start | restart
[root@harbor harbor]# docker-compose down -v
Stopping harbor-jobservice ... done
Stopping nginx ... done
Stopping harbor-core ... done
Stopping harbor-portal ... done
Stopping redis ... done
Stopping registryctl ... done
Stopping registry ... done
Stopping harbor-db ... done
Stopping harbor-log ... done
Removing harbor-jobservice ... done
Removing nginx ... done
Removing harbor-core ... done
Removing harbor-portal ... done
Removing redis ... done
Removing registryctl ... done
Removing registry ... done
Removing harbor-db ... done
Removing harbor-log ... done
Removing network harbor_harbor
[root@harbor harbor]# ./prepare
[root@harbor harbor]# docker-compose up -d
# 这条命令将停止和移除Docker Compose中定义的所有容器,并且会同时删除关联的所有卷。 `-v`选项表示同时删除所有卷。
[root@harbor harbor]# docker-compose up -d
[root@harbor ~]# rm -rf /data/database/
[root@harbor ~]# rm -rf /data/registry/
# 目前,微服务架构也在潜移默化的改变应用的部署方式,其提倡将应用分割成一系列细小的服务,每个服务专注于单一业务功能,服务之间采用轻量级通信机制相互沟通。同时,数据库解决方案也在发生变化,多种持久化混合方案提倡将数据存放在最适合的数据库解决方案中,而传统的数据库解决方案将数据存放在同一个数据库服务中
# 服务数量的增加也就意味着容器数量的增多,逐渐增加的容器数量为容器部署、运行及管理带来了挑战。Docker Compose的出现解决多个容器部署的问题并提高了多个容器解决方案的可移植性
# Docker官方镜像仓库是一个用于管理公共镜像的地方,用户可以在上面找到想要的镜像,也可以把自己的镜像推送上去。但是,有时候服务器无法访问互联网,或者不希望自己的镜像放到互联网上,那么九需要用到Docker Registry私有仓库,它咳哟用来存储和管理自己的镜像。