1. 安装Docker
yum -y install yum-utils
yum-config-manager --add-repo https://mirrors.cloud.tencent.com/docker-ce/linux/centos/docker-ce.repo
yum clean all
yum makecache
yum -y install docker-ce-20.10.17 docker-ce-cli-20.10.17
2. 下载、安装docker-compose
# 以2.10.2为例
wget https://github.com/docker/compose/releases/download/v2.10.2/docker-compose-linux-x86_64
mv docker-compose-linux-x86_64 /usr/bin/docker-compose
chmod +x /usr/bin/docker-compose
3. 添加Docker配置文件
mkdir -p /etc/docker
cat > /etc/docker/daemon.json <<-EOF
{
"registry-mirrors": [
"https://registry.docker-cn.com",
"http://hub-mirror.c.163.com",
"https://docker.mirrors.ustc.edu.cn"
],
"insecure-registries": ["harbor.raymonds.cc"], # 这个地址为harbor仓库的域名
"exec-opts": ["native.cgroupdriver=systemd"],
"max-concurrent-downloads": 10,
"max-concurrent-uploads": 5,
"log-opts": {
"max-size": "300m",
"max-file": "2"
},
"live-restore": true
}
EOF
systemctl enable --now docker
4. 下载、安装harbor
wget https://github.com/goharbor/harbor/releases/download/v2.6.0/harbor-offline-installer-v2.6.0.tgz
tar -zxvf harbor-offline-installer-v2.6.0.tgz -C /apps
cd /apps/harbor
cp harbor.yml.tmpl harbor.yml
sed -ri.bak -e 's/^(hostname:) .*/\1 '本机IP地址'/' -e 's/^(harbor_admin_password:) .*/\1 '123456'/' -e 's/^(https:)/#\1/' -e 's/ (port: 443)/# \1/' -e 's@ (certificate: .*)@# \1@' -e 's@ (private_key: .*)@# \1@' ./harbor.yml
# 修改本机地址、以及密码(当前密码填写的为 123456)
yum -y install python
sh install.sh
如果Harbor使用的网段与本地局域网有所冲突
cd /apps/harbor
docker-compose down -v
vim docker-compose.yml
# 修改最后 networks 配置,自定义一个网段与网关
networks:
harbor:
driver: bridge
ipam:
config:
- subnet: 172.192.0.0/16
gateway: 172.192.0.1
# 启动
docker-compose up -d
5. 集群创建(以两台为例)
1. 登录harbor仓库
2. 新建项目(两个Harbor仓库的项目名称要一致)
3. 系统管理 --> 仓库管理 --> 新建目标
填写仓库名称,对端Harbor仓库地址,用户名密码
4. 系统管理 --> 复制管理 --> 新建规则
填写规则名称
复制模式选择 Push-based
目标仓库选择刚刚填写的内容
5. 对端仓库相同操作