一、前置环境

  • docker
  • docker-compose

二、获取软件

1.下载软件
mkdir /data/{softs,server} -p && cd /data/softs
wget https://github.com/goharbor/harbor/releases/download/v2.8.3/harbor-offline-installer-v2.8.3.tgz

2.解压软件
tar -zxvf harbor-offline-installer-v2.8.3.tgz -C  /data/server/
cd /data/server/harbor/

3.加载镜像
[root@middle harbor]# docker load < harbor.v2.8.3.tar.gz
[root@middle harbor]# docker images
REPOSITORY                      TAG       IMAGE ID       CREATED      SIZE
goharbor/harbor-exporter        v2.8.3    721fe73bfd83   3 days ago   98.3MB
goharbor/redis-photon           v2.8.3    e6cc3ff25aa8   3 days ago   122MB
goharbor/trivy-adapter-photon   v2.8.3    e02c6c4159b5   3 days ago   463MB
goharbor/notary-server-photon   v2.8.3    bc666b885d14   3 days ago   114MB
goharbor/notary-signer-photon   v2.8.3    d265c727b0bd   3 days ago   111MB
goharbor/harbor-registryctl     v2.8.3    c1c179f63daf   3 days ago   142MB
goharbor/registry-photon        v2.8.3    eb8405940a0c   3 days ago   79.6MB
goharbor/nginx-photon           v2.8.3    ecedf0f68eb3   3 days ago   118MB
goharbor/harbor-log             v2.8.3    b123084379d6   3 days ago   126MB
goharbor/harbor-jobservice      v2.8.3    9c7776c2acf0   3 days ago   141MB
goharbor/harbor-core            v2.8.3    81be07cfbdfd   3 days ago   165MB
goharbor/harbor-portal          v2.8.3    8dccb7b0dc8b   3 days ago   125MB
goharbor/harbor-db              v2.8.3    b8c6a03bfbac   3 days ago   175MB

4.备份配置
cp harbor.yml.tmpl harbor.yml

三、修改配置

修改配置
[root@kubernetes-register /data/server/harbor]# vim harbor.yml

修改文件中以下内容

    # 1.修改主机名
    hostname: harbor.top
    http:
      port: 80
    # 2.https: 注释ssl相关的部分
      # port: 443
      # certificate: /your/certificate/path
      # private_key: /your/private/key/path
    # 3.修改harbor的登录密码
    harbor_admin_password: 123123
    # 4.设定harbor的数据存储目录
    data_volume: /data/server/harbor/data

四、编译安装软件

1.编译配置harbor
./prepare

2.修改 daemon.json
 vim /etc/docker/daemon.json
 写入以下内容,"harbor.top","192.168.2.103" 为要安装 `harbor` 服务的 `ip` 地址
 "insecure-registries": ["harbor.top","192.168.2.103","midddle"],

3.重启 `docker`
 `systemctl restart docker`
 注意:如果不做这一步,直接就第3步,登录会报以下错误
 [root@middle harbor]# docker login harbor.top -u haima
 Password:
 Error response from daemon: Get "https://harbor.top/v2/": dial tcp 192.168.2.103:443: connect: connection refused


4.安装并启动 harbor 
./install.sh

4.检查服务效果
[root@middle harbor]# docker ps
CONTAINER ID   IMAGE                                COMMAND                   CREATED         STATUS                   PORTS                                   NAMES
5b8ca23dfdd7   goharbor/nginx-photon:v2.8.3         "nginx -g 'daemon of…"   3 minutes ago   Up 3 minutes (healthy)   0.0.0.0:80->8080/tcp, :::80->8080/tcp   nginx
4e85e05f4048   goharbor/harbor-jobservice:v2.8.3    "/harbor/entrypoint.…"   3 minutes ago   Up 3 minutes (healthy)                                           harbor-jobservice
0784a69e19cf   goharbor/harbor-core:v2.8.3          "/harbor/entrypoint.…"   3 minutes ago   Up 3 minutes (healthy)                                           harbor-core
34000cfe49c0   goharbor/redis-photon:v2.8.3         "redis-server /etc/r…"   3 minutes ago   Up 3 minutes (healthy)                                           redis
c82022462389   goharbor/harbor-portal:v2.8.3        "nginx -g 'daemon of…"   3 minutes ago   Up 3 minutes (healthy)                                           harbor-portal
4b469f9bd8b0   goharbor/harbor-registryctl:v2.8.3   "/home/harbor/start.…"   3 minutes ago   Up 3 minutes (healthy)                                           registryctl
ed33b76c9ee9   goharbor/registry-photon:v2.8.3      "/home/harbor/entryp…"   3 minutes ago   Up 3 minutes (healthy)                                           registry
a2af3397e9a4   goharbor/harbor-db:v2.8.3            "/docker-entrypoint.…"   3 minutes ago   Up 3 minutes (healthy)                                           harbor-db
58e723b5f3c9   goharbor/harbor-log:v2.8.3           "/bin/sh -c /usr/loc…"   3 minutes ago   Up 3 minutes (healthy)   127.0.0.1:1514->10514/tcp               harbor-log

五、docker-compose 操作服务

进入目录
cd /data/server/harbor
停止
docker-compose down
启动
docker-compose up -d  

六、定制系统服务启动文件

vim /etc/systemd/system/harbor.service

写入以下内容


[Unit]
Description=Harbor
After=docker.service systemd-networkd.service systemd-resolved.service
Requires=docker.service
Documentation=http://github.com/vmware/harbor
[Service]
Type=simple
Restart=on-failure
RestartSec=5
# 需要注意 docker-compose  和 harbor 的安装位置
ExecStart=/usr/local/bin/docker-compose --file /data/server/harbor/docker-compose.yml up
ExecStop=/usr/local/bin/docker-compose --file /data/server/harbor/docker-compose.yml down
[Install]
WantedBy=multi-user.target

操作服务常用命令

加载服务配置文件
systemctl daemon-reload
启动服务
systemctl start harbor
检查状态
systemctl status harbor
设置开机自启动
systemctl enable harbor
禁止开机启动
systemctl disable harbor

八、 harbor仓库定制

查看登录页面,在宿主机浏览器中访问
http://192.168.2.103

账号:admin
密码:123123

创建 haima 用户专用的项目仓库,名称为 public ,权限为公开的
密码: Admin123

九、修改 hosts 以自己服务器的ip为准

cat >> /etc/hosts << EOF
192.168.2.100 master
192.168.2.101 node1
192.168.2.102 node2
192.168.2.103 harbor.top middle
127.0.0.1 localhost
EOF

十、harbor仓库测试

登录仓库
[root@middle harbor]# docker login harbor.top -u haima
Password:   # 输入登录密码 Admin123
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




下载镜像
docker pull busybox
定制镜像标签
docker tag busybox harbor.top/public/busybox:v0.1
推送镜像
docker push harbor.top/public/busybox:v0.1
作者:海马  创建时间:2023-07-30 14:53
最后编辑:海马  更新时间:2024-08-03 21:41