- 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公钥文件```shellgpg --keyserver hkps://keyserver.ubuntu.com --recv-keys 644FF454C0B4115C
gpg: 下载密钥‘C0B4115C’,从 hkps 服务器 keyserver.ubuntu.comgpg: /root/.gnupg/trustdb.gpg:建立了信任度数据库gpg: 密钥 C0B4115C:公钥“Harbor-sign (The key for signing Harbor build) <jiangd@vmware.com>”已导入gpg: 合计被处理的数量:1gpg: 已导入: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,钥匙号 C0B4115Cgpg: 使用 PGP 信任模型gpg: 完好的签名,来自于“Harbor-sign (The key for signing Harbor build) <jiangd@vmware.com>”gpg: 警告:这把密钥未经受信任的签名认证!gpg: 没有证据表明这个签名属于它所声称的持有者。主钥指纹: 7722 D168 DAEC 4578 06C9 6FF9 644F F454 C0B4 115Cgpg: 二进制 签名,散列算法 SHA512
4.解压安装包
tar xzvf harbor-offline-installer-v2.4.1.tgz
5.配置harbor.yml
hostname: 192.168.101.181http:port: 8083harbor_admin_password: your-login-passdatabase:password: your-db-passmax_idle_conns: 50max_open_conns: 500data_volume: /www/pre/harbor/datatrivy:ignore_unfixed: falseskip_update: falseinsecure: falsejobservice:max_job_workers: 10notification:webhook_job_max_retry: 10chart:absolute_url: disabledlog:level: infolocal:rotate_count: 50rotate_size: 200Mlocation: /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 EngineDocumentation=https://docs.docker.comAfter=network-online.target firewalld.service containerd.serviceWants=network-online.targetRequires=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.sockExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sockExecReload=/bin/kill -s HUP $MAINPIDTimeoutSec=0RestartSec=2Restart=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=infinityLimitNPROC=infinityLimitCORE=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 containersDelegate=yes# kill only the docker process, not all processes in the cgroupKillMode=processOOMScoreAdjust=-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-reloadsystemctl 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.1Loaded image: goharbor/notary-signer-photon:v2.4.1Loaded image: goharbor/harbor-core:v2.4.1Loaded image: goharbor/redis-photon:v2.4.1Loaded image: goharbor/harbor-jobservice:v2.4.1Loaded image: goharbor/harbor-registryctl:v2.4.1Loaded image: goharbor/nginx-photon:v2.4.1Loaded image: goharbor/notary-server-photon:v2.4.1Loaded image: goharbor/harbor-log:v2.4.1Loaded image: goharbor/harbor-db:v2.4.1Loaded image: goharbor/harbor-exporter:v2.4.1Loaded image: goharbor/trivy-adapter-photon:v2.4.1Loaded image: goharbor/chartmuseum-photon:v2.4.1Loaded image: goharbor/prepare:v2.4.1Loaded 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/harborWARNING:root:WARNING: HTTP protocol is insecure. Harbor will deprecate http protocol in the future. Please make sure to upgrade to httpsClearing the configuration file: /config/registry/root.crtClearing the configuration file: /config/registry/passwdClearing the configuration file: /config/registry/config.ymlClearing the configuration file: /config/nginx/nginx.confClearing the configuration file: /config/jobservice/envClearing the configuration file: /config/jobservice/config.ymlClearing the configuration file: /config/portal/nginx.confClearing the configuration file: /config/registryctl/envClearing the configuration file: /config/registryctl/config.ymlClearing the configuration file: /config/log/logrotate.confClearing the configuration file: /config/log/rsyslog_docker.confClearing the configuration file: /config/core/envClearing the configuration file: /config/core/app.confClearing the configuration file: /config/db/envGenerated configuration file: /config/portal/nginx.confGenerated configuration file: /config/log/logrotate.confGenerated configuration file: /config/log/rsyslog_docker.confGenerated configuration file: /config/nginx/nginx.confGenerated configuration file: /config/core/envGenerated configuration file: /config/core/app.confGenerated configuration file: /config/registry/config.ymlGenerated configuration file: /config/registryctl/envGenerated configuration file: /config/registryctl/config.ymlGenerated configuration file: /config/db/envGenerated configuration file: /config/jobservice/envGenerated configuration file: /config/jobservice/config.ymlloaded secret from file: /data/secret/keys/secretkeyGenerated configuration file: /compose_location/docker-compose.ymlClean up the input dirNote: stopping existing Harbor instance ...Stopping harbor-jobservice ... doneStopping harbor-core ... doneStopping registry ... doneStopping redis ... doneStopping registryctl ... doneStopping harbor-portal ... doneStopping harbor-db ... doneStopping harbor-log ... doneRemoving harbor-jobservice ... doneRemoving nginx ... doneRemoving harbor-core ... doneRemoving registry ... doneRemoving redis ... doneRemoving registryctl ... doneRemoving harbor-portal ... doneRemoving harbor-db ... doneRemoving harbor-log ... doneRemoving network harbor_harbor[Step 5]: starting Harbor ...Creating network "harbor_harbor" with the default driverCreating harbor-log ... doneCreating harbor-portal ... doneCreating registry ... doneCreating harbor-db ... doneCreating redis ... doneCreating registryctl ... doneCreating harbor-core ... doneCreating nginx ... doneCreating 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.312MAINTAINER menglt@yeah.netENV TZ=Asia/ShanghaiENV JAVA_OPTS="-Xms512m -Xmx1024m -Djava.security.egd=file:/dev/./urandom"RUN ln -sf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezoneRUN mkdir -p /your-projectWORKDIR /project-moduleEXPOSE 4000ADD ./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:buildmvn 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/
[
