- Harbor是什么?
- Harbor的优势
- Harbor安装
- Harbor下载页面,下载最新的安装包与asc公钥。">1.去Harbor下载页面,下载最新的安装包与asc公钥。
- create directory for harbor
- download harbor installer and correspond asc file
- 发布镜像
- 附录
Harbor是什么?
Harbor是基于角色策略访问控制的开源镜像管理工具,通过扫描镜像确保镜像安全无漏洞,帮助你安全管理云原生平台。
Harbor的优势
Harbor和Registry都是Docker的镜像仓库,但是Harbor作为更多企业的选择,是因为相比较于Regisrty来说,它具有很多的优势。
- 提供分片传输机制,优化网络传输,Docker镜像是是分片的,每次传输全量文件不经济。
- 提供WEB界面,优化用户体验。
- 支持水平扩展集群,分担服务器压力。
- 支持权限控制,为不同身份的人员分配不同的权限,使操作更安全。
- 提供基于角色的访问控制机制,并通过项目来对镜像进行组织和访问权限的控制。
Harbor安装
1.去Harbor下载页面,下载最新的安装包与asc公钥。
```shellcreate directory for harbor
mkdir -p harbor/data mkdir -p harbor/logs
download harbor installer and correspond asc file
cd harbor wget -b https://github.com/goharbor/harbor/releases/download/v2.4.1/harbor-offline-installer-v2.4.1.tgz.asc wget -b https://github.com/goharbor/harbor/releases/download/v2.4.1/harbor-offline-installer-v2.4.1.tgz
<a name="yXAgL"></a>
## 2.获取 *.asc公钥文件
```shell
gpg --keyserver hkps://keyserver.ubuntu.com --recv-keys 644FF454C0B4115C
gpg: 下载密钥‘C0B4115C’,从 hkps 服务器 keyserver.ubuntu.com
gpg: /root/.gnupg/trustdb.gpg:建立了信任度数据库
gpg: 密钥 C0B4115C:公钥“Harbor-sign (The key for signing Harbor build) <jiangd@vmware.com>”已导入
gpg: 合计被处理的数量:1
gpg: 已导入:1 (RSA: 1)
3.验证下载的.asc文件
gpg -v --keyserver hkps://keyserver.ubuntu.com --verify harbor-offline-installer-v2.4.1.tgz.asc
gpg: 假定被签名的数据是‘harbor-offline-installer-v2.4.1.tgz’
gpg: 于 2021年12月16日 星期四 12时24分54秒 CST 创建的签名,使用 RSA,钥匙号 C0B4115C
gpg: 使用 PGP 信任模型
gpg: 完好的签名,来自于“Harbor-sign (The key for signing Harbor build) <jiangd@vmware.com>”
gpg: 警告:这把密钥未经受信任的签名认证!
gpg: 没有证据表明这个签名属于它所声称的持有者。
主钥指纹: 7722 D168 DAEC 4578 06C9 6FF9 644F F454 C0B4 115C
gpg: 二进制 签名,散列算法 SHA512
4.解压安装包
tar xzvf harbor-offline-installer-v2.4.1.tgz
5.配置harbor.yml
hostname: 192.168.101.181
http:
port: 8083
harbor_admin_password: your-login-pass
database:
password: your-db-pass
max_idle_conns: 50
max_open_conns: 500
data_volume: /www/pre/harbor/data
trivy:
ignore_unfixed: false
skip_update: false
insecure: false
jobservice:
max_job_workers: 10
notification:
webhook_job_max_retry: 10
chart:
absolute_url: disabled
log:
level: info
local:
rotate_count: 50
rotate_size: 200M
location: /www/pre/harbor/logs
_version: 2.4.0
6.配置Docker
6.1 开启RemoteApi
vim /usr/lib/systemd/system/docker.service
注释docker.service
第13行,并下方加上ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock
这行,暴露2375端口,如果服务器防火墙是开启状态,需要放行2375端口。
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service containerd.service
Wants=network-online.target
Requires=docker.socket containerd.service
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
#ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always
# Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229.
# Both the old, and new location are accepted by systemd 229 and up, so using the old location
# to make them work for either version of systemd.
StartLimitBurst=3
# Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230.
# Both the old, and new name are accepted by systemd 230 and up, so using the old name to make
# this option work for either version of systemd.
StartLimitInterval=60s
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Comment TasksMax if your systemd version does not support it.
# Only systemd 226 and above support this option.
TasksMax=infinity
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
OOMScoreAdjust=-500
[Install]
WantedBy=multi-user.target
6.2 配置http访问
如果不想使用https安全访问模式,需要设置insecure-registries
vim /etc/docker/daemon.json
{
"registry-mirrors":[
"https://hhfivgbp.mirror.aliyuncs.com"
],
"insecure-registries":[
"192.168.101.181:8083"
],
"live-restore":true
}
- `registry-mirrors`镜像加速地址在这里找:[https://cr.console.aliyun.com/cn-beijing/instances/mirrors](https://cr.console.aliyun.com/cn-beijing/instances/mirrors)
- `live-restore`重载docker守护进程而不重启容器。
6.3 重启docker
systemctl daemon-reload
systemctl restart docker
7.运行安装脚本
sh install.sh
[Step 0]: checking if docker is installed ...
Note: docker version: 20.10.12
[Step 1]: checking docker-compose is installed ...
Note: docker-compose version: 1.29.2
[Step 2]: loading Harbor images ...
Loaded image: goharbor/registry-photon:v2.4.1
Loaded image: goharbor/notary-signer-photon:v2.4.1
Loaded image: goharbor/harbor-core:v2.4.1
Loaded image: goharbor/redis-photon:v2.4.1
Loaded image: goharbor/harbor-jobservice:v2.4.1
Loaded image: goharbor/harbor-registryctl:v2.4.1
Loaded image: goharbor/nginx-photon:v2.4.1
Loaded image: goharbor/notary-server-photon:v2.4.1
Loaded image: goharbor/harbor-log:v2.4.1
Loaded image: goharbor/harbor-db:v2.4.1
Loaded image: goharbor/harbor-exporter:v2.4.1
Loaded image: goharbor/trivy-adapter-photon:v2.4.1
Loaded image: goharbor/chartmuseum-photon:v2.4.1
Loaded image: goharbor/prepare:v2.4.1
Loaded image: goharbor/harbor-portal:v2.4.1
[Step 3]: preparing environment ...
[Step 4]: preparing harbor configs ...
prepare base dir is set to /mnt/1068cb5c-d183-48ef-b545-5717408aba10/www/pre/harbor/harbor
WARNING:root:WARNING: HTTP protocol is insecure. Harbor will deprecate http protocol in the future. Please make sure to upgrade to https
Clearing the configuration file: /config/registry/root.crt
Clearing the configuration file: /config/registry/passwd
Clearing the configuration file: /config/registry/config.yml
Clearing the configuration file: /config/nginx/nginx.conf
Clearing the configuration file: /config/jobservice/env
Clearing the configuration file: /config/jobservice/config.yml
Clearing the configuration file: /config/portal/nginx.conf
Clearing the configuration file: /config/registryctl/env
Clearing the configuration file: /config/registryctl/config.yml
Clearing the configuration file: /config/log/logrotate.conf
Clearing the configuration file: /config/log/rsyslog_docker.conf
Clearing the configuration file: /config/core/env
Clearing the configuration file: /config/core/app.conf
Clearing the configuration file: /config/db/env
Generated configuration file: /config/portal/nginx.conf
Generated configuration file: /config/log/logrotate.conf
Generated configuration file: /config/log/rsyslog_docker.conf
Generated configuration file: /config/nginx/nginx.conf
Generated configuration file: /config/core/env
Generated configuration file: /config/core/app.conf
Generated configuration file: /config/registry/config.yml
Generated configuration file: /config/registryctl/env
Generated configuration file: /config/registryctl/config.yml
Generated configuration file: /config/db/env
Generated configuration file: /config/jobservice/env
Generated configuration file: /config/jobservice/config.yml
loaded secret from file: /data/secret/keys/secretkey
Generated configuration file: /compose_location/docker-compose.yml
Clean up the input dir
Note: stopping existing Harbor instance ...
Stopping harbor-jobservice ... done
Stopping harbor-core ... done
Stopping registry ... done
Stopping redis ... done
Stopping registryctl ... done
Stopping harbor-portal ... done
Stopping harbor-db ... done
Stopping harbor-log ... done
Removing harbor-jobservice ... done
Removing nginx ... done
Removing harbor-core ... done
Removing registry ... done
Removing redis ... done
Removing registryctl ... done
Removing harbor-portal ... done
Removing harbor-db ... done
Removing harbor-log ... done
Removing network harbor_harbor
[Step 5]: starting Harbor ...
Creating network "harbor_harbor" with the default driver
Creating harbor-log ... done
Creating harbor-portal ... done
Creating registry ... done
Creating harbor-db ... done
Creating redis ... done
Creating registryctl ... done
Creating harbor-core ... done
Creating nginx ... done
Creating harbor-jobservice ... done
✔ ----Harbor has been installed and started successfully.----
8.Harbor Web
打开浏览器访问 http://192.168.101.181:8083/,账号默认是admin,密码是harbor.yml中配置的密码。
发布镜像
安装Dockerfile使用镜像
docker pull bitnami/java:1.8.312
Dockerfile
FROM bitnami/java:1.8.312
MAINTAINER menglt@yeah.net
ENV TZ=Asia/Shanghai
ENV JAVA_OPTS="-Xms512m -Xmx1024m -Djava.security.egd=file:/dev/./urandom"
RUN ln -sf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN mkdir -p /your-project
WORKDIR /project-module
EXPOSE 4000
ADD ./target/project-module-api.jar ./
CMD sleep 60;java $JAVA_OPTS -jar project-module-api.jar
Maven插件
spring-boot-maven-plugin
<!--spring boot 默认插件-->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
docker-maven-plugin
<properties>
<docker.registry>192.168.101.181:8083</docker.registry>
<docker.host>http://192.168.101.181:2375</docker.host>
<!-- namespace对应harbor中的项目 -->
<docker.namespace>your-namespace</docker.namespace>
<docker.username>admin</docker.username>
<docker.password>your-password</docker.password>
</properties>
<!-- maven docker 打包插件 -->
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>${docker.plugin.version}</version>
<configuration>
<dockerHost>${docker.host}</dockerHost>
<registry>${docker.registry}</registry>
<authConfig>
<push>
<username>${docker.username}</username>
<password>${docker.password}</password>
</push>
</authConfig>
<images>
<image>
<name>${docker.registry}/${docker.namespace}/${project.name}:${project.version}</name>
<build>
<dockerFile>${project.basedir}/Dockerfile</dockerFile>
</build>
</image>
</images>
</configuration>
</plugin>
Maven命令
mvn install docker:build
mvn docker:push
附录
- 官网:https://goharbor.io/
- 设置storage_service https://goharbor.io/docs/2.4.0/install-config/configure-yml-file/#backend
- 设置https https://goharbor.io/docs/2.4.0/install-config/configure-https/
[