配置Harbor详细步骤

配置Harbor详细步骤

虚拟软件:VMware 17

Linux操作系统:RockyLinux-8.8-x86_64(最小化安装)

在这里插入图片描述

一张网卡(网络适配器) 自定义(VMnet0)

快照 0 : 打一个快照,初始化状态,没有做任何配置

修改主机名

[root@localhost ~]# hostnamectl set-hostname harbor     # 把主机名改为harbor
[root@localhost ~]# echo -e  "192.168.1.30\tharbor" >> /etc/hosts

修改网卡命名

[root@localhost ~]# vi /etc/default/grub

在这里插入图片描述

“ 爱情海 ” 颜色区域为追加内容

[root@localhost ~]# grub2-mkconfig -o /boot/grub2/grub.cfg           # 重新生成网卡命名
Generation grub conf iguration file ...
done
[root@localhost ~]# reboot                                           # 重启生效

添加网卡

第一张网卡:在集群中提供服务的ip

第二张网卡:NAT模式,可以连接互联网,用来下载软件,有和真机相同的网段,可以使用 MobaXterm 来远程控制

在这里插入图片描述

在这里插入图片描述

查询IP地址

[root@harbor ~]# ip a s

在这里插入图片描述

NAT模式的那张网卡(eth1),已经自动分配了一个ip地址(192.168.91.130),我们可以使用该网址,用 MobaXterm 来远程控制

在这里插入图片描述

配置ip地址

配置eth0的ip地址

[root@harbor ~]# nmcli connection show

在这里插入图片描述

删除不是绿色的网卡

[root@harbor ~]# nmcli connection delete 69d86ec6-907a-3839-bdef-21f415b8ce27
[root@harbor ~]# nmcli connection delete ens33
添加新的网络命名
[root@harbor ~]# nmcli connection add type ethernet ifname eth0 con-name eth0

解析:nmcli connection 添加 类型 以太网设备 网卡设备名为eth0 nmcli命令的命名为eth0

[root@harbor ~]# nmcli connection modify eth0 ipv4.method manual ipv4.addresses 192.168.1.30/24          autoconnect yes

解析:nmcli connection 修改 外号 ipv4.方法 手工配置 ipv4.地址 192.168.1.30/24 是否开机自启 是

激活
[root@harbor ~]# nmcli connection up eth0
查询结果
[root@harbor ~]# ip a s

在这里插入图片描述

禁用SELinux

[root@harbor ~]# sed -ri "s,^(SELINUX=).*,\1disabled," /etc/selinux/config

卸载firewalld

[root@harbor ~]# yum -y remove firewalld

配置Yum软件源

Rocky-AppStream.repo Rocky-BaseOS.repo 使用本地源

创建挂载点目录 RockyLinuxApp
[root@harbor ~]# mkdir /mnt/RockyLinuxApp
[root@harbor ~]# mount /dev/cdrom /mnt/RockyLinuxApp/
mount: /mnt/RockyLinuxApp: WARNING: device write-protected, mounted read-only.
[root@harbor ~]# ls /mnt/RockyLinuxApp/
AppStream  BaseOS  EFI  images  isolinux  LICENSE  media.repo  TRANS.TBL
开机自动挂载
[root@harbor ~]# echo -e "/dev/cdrom\t/mnt/RockyLinuxApp\tiso9660\tdefaults\t0\t0" >> /etc/fstab
修改yum配置文件
[root@harbor ~]# rm -rf /etc/yum.repos.d/*
[root@harbor ~]# vi /etc/yum.repos.d/Rocky-App.repo
[appstream]
name=Rocky Linux - AppStream
baseurl=file:///mnt/RockyLinuxApp/AppStream
gpgcheck=1
enabled=1
countme=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rockyofficial

[baseos]
name=Rocky Linux - BaseOS
baseurl=file:///mnt/RockyLinuxApp/BaseOS
gpgcheck=1
enabled=1
countme=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rockyofficial
重置yum
[root@harbor ~]# yum clean all
25 个文件已删除
[root@harbor ~]#
[root@harbor ~]# yum repoinfo
Rocky Linux - AppStream                      96 MB/s | 8.4 MB     00:00
Rocky Linux - BaseOS                         80 MB/s | 2.6 MB     00:00
仓库ID            : appstream
仓库名称          : Rocky Linux - AppStream
软件仓库修订版      : 8.8
软件仓库发行版标签      : [cpe:/o:rocky:rocky:8]:  ,  , 8, L, R, c, i, k, n, o, u, x, y
更新的软件仓库       : 2023年05月18日 星期四 07时32分04秒
软件仓库的软件包          : 6,879
软件仓库的可用软件包: 5,509
软件仓库大小          : 9.4 G
软件仓库基本 URL       : file:///mnt/RockyLinuxApp/AppStream
软件仓库过期时间        : 172,800 秒 (最近 2024年02月06日 星期二 17时32分05秒)
仓库文件名      : /etc/yum.repos.d/Rocky-App.repo

仓库ID            : baseos
仓库名称          : Rocky Linux - BaseOS
软件仓库修订版      : 8.8
软件仓库发行版标签      : [cpe:/o:rocky:rocky:8]:  ,  , 8, L, R, c, i, k, n, o, u, x, y
更新的软件仓库       : 2023年05月18日 星期四 07时28分52秒
软件仓库的软件包          : 1,734
软件仓库的可用软件包: 1,732
软件仓库大小          : 1.4 G
软件仓库基本 URL       : file:///mnt/RockyLinuxApp/BaseOS
软件仓库过期时间        : 172,800 秒 (最近 2024年02月06日 星期二 17时32分07秒)
仓库文件名      : /etc/yum.repos.d/Rocky-App.repo
软件包总数:8,613

安装一些常用软件

[root@harbor ~]# yum -y install vim                 # 编辑器
[root@harbor ~]# yum -y install bash-completion     # Tab键补全功能

配置docker的yum源

[root@harbor ~]# yum -y install yum-utils           # yum管理工具
[root@harbor ~]# yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
[root@harbor ~]# yum clean all                      # 清空缓存
[root@harbor ~]# yum repoinfo                       # 重新加载
关机拍摄快照

在这里插入图片描述

安装docker及compose

[root@harbor ~]# yum install -y docker-ce docker-compose-plugin
[root@harbor ~]# systemctl enable --now docker
配置镜像加速器
[root@harbor ~]# vim /etc/docker/daemon.json
{
    "registry-mirrors": ["https://harbor:443"],
    "insecure-registries":["harbor:443"]
}
[root@docker ~]# systemctl restart docker

下载harbor软件包

官方下载:https://github.com/goharbor/harbor/tags

在这里插入图片描述

在这里插入图片描述

[root@harbor ~]# ls
anaconda-ks.cfg  harbor-offline-installer-v2.9.2.tgz
导入harbor镜像/

usr/local 该目录用于存放用户自编译安装的软件

[root@harbor ~]# tar -zxvf harbor-offline-installer-v2.9.2.tgz  -C /usr/local/
[root@harbor ~]# cd /usr/local/harbor
[root@harbor harbor]# docker load -i harbor.v2.9.2.tar.gz
生成CA证书
[root@harbor harbor]# mkdir tls
[root@harbor harbor]# cd tls
[root@harbor tls]# openssl genrsa -out ca.key 4096
[root@harbor tls]# openssl req -x509 -new -nodes -sha512 -days 3650 -subj "/C=CN/ST=Beijing/L=Beijing/O=example/OU=Personal/CN=harbor" -key ca.key  -out ca.crt
修改配置文件
[root@harbor tls]# cd cd /usr/local/harbor/
[root@harbor harbor]# cp harbor.yml.tmpl harbor.yml
[root@harbor harbor]# vim harbor.yml
05:    hostname: harbor
08:    # http:
10:      # port: 80
17:    certificate: /usr/local/harbor/tls/ca.crt
18:    private_key: /usr/local/harbor/tls/ca.key
预安装环境检查,生成项目文件

harbor是通过容器安装,有很多个容器,这些容器之前据说有启动顺序,所以官方写了一个 compose 文件给我们

[root@harbor harbor]# /usr/local/harbor/prepare
[root@Harbor harbor]# ls
common  common.sh  docker-compose.yml  harbor.v2.7.0.tar.gz  harbor.yml  harbor.yml.tmpl  install.sh  LICENSE  prepare  tls
创建并启动项目
[root@harbor harbor]# docker compose -f docker-compose.yml up -d
开机自启
[root@harbor harbor]# chmod 0755 /etc/rc.d/rc.local
[root@harbor harbor]# echo "/usr/bin/docker compose -p harbor start" >>/etc/rc.d/rc.local
查看一下项目状态
[root@harbor harbor]# docker compose -p harbor ps

在这里插入图片描述

使用浏览器访问

https://192.168.91.130 使用NAT模式的那张网卡ip

在这里插入图片描述

点高级,继续访问

在这里插入图片描述

用户名:admin

密码:Harbor12345

在这里插入图片描述

关机拍摄快照

在这里插入图片描述

容器管理命令说明
docker login登录私有镜像仓库
docker logout退出登录

使用其它服务器登入私有仓库

相同网段的机器

# 添加主机配置
[root@yunOS ~]# echo -e  "192.168.1.30\tharbor" >> /etc/hosts
# 添加私有仓库配置
[root@yunOS ~]# vim /etc/docker/daemon.json
{
    "registry-mirrors": [
    "https://76fe091e4e32401789b46cd8089ed320.mirror.swr.myhuaweicloud.com",
    "https://harbor:443
    ],
    "insecure-registries":["harbor:443"]
}
[root@yunOS ~]# systemctl restart docker

# 登录 harbor 仓库
[root@yunOS ~]# docker login harbor:443
Username: admin
Password: ********
... ...
Login Succeeded
# 退出登录
[root@yunOS ~]# docker logout harbor:443
Removing login credentials for harbor:443

上传镜像

需要先在 harbor 上面创建一个存放镜像的项目

在这里插入图片描述

在这里插入图片描述

如果没有登入,就先登入一下

[root@yunOS ~]# docker login harbor:443
Username: admin
Password: ********

先在华为云下载一个镜像

[root@yunOS ~]# docker pull busybox:latest
[root@yunOS ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
busybox      latest    a9d583973f65   2 years ago   1.23MB

[root@yunOS ~]# docker tag busybox:latest harbor:443/myimg/busybox:latest

[root@yunOS ~]# docker images
REPOSITORY                 TAG       IMAGE ID       CREATED       SIZE
busybox                    latest    a9d583973f65   2 years ago   1.23MB
harbor:443/myimg/busybox   latest    a9d583973f65   2 years ago   1.23MB

[root@yunOS ~]# docker push harbor:443/myimg/busybox:latest
The push refers to repository [harbor:443/myimg/busybox]
2983725f2649: Pushed
latest: digest: sha256:410a07f17151ffffb513f942a01748dfdb921de915ea6427d61d60b0357c1dcd size: 527

在这里插入图片描述

使用之前的机器下载harbor仓库的镜像测试
[root@harbor ~]# docker pull harbor:443/myimg/busybox:latest
latest: Pulling from myimg/busybox
8b3d7e226fab: Pull complete
Digest: sha256:410a07f17151ffffb513f942a01748dfdb921de915ea6427d61d60b0357c1dcd
Status: Downloaded newer image for harbor:443/myimg/busybox:latest
harbor:443/myimg/busybox:latest
[root@harbor ~]# docker images
REPOSITORY                      TAG       IMAGE ID       CREATED       SIZE
··············· 忽略其它镜像 ··············
harbor:443/myimg/busybox        latest    a9d583973f65   2 years ago   1.23MB
  • 46
    点赞
  • 42
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

芸开发

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值