在CentOS上使用GitLab镜像仓库前,需完成以下基础准备:
安装依赖包:确保系统具备必要的工具和库,执行以下命令安装:
sudo yum install -y curl policycoreutils-python openssh-server postfix
curl
:用于下载脚本和镜像;policycoreutils-python
:用于配置SELinux策略;openssh-server
:支持SSH访问;postfix
:用于发送邮件通知(可选择配置SMTP替代)。启动基础服务:
sudo systemctl enable sshd && sudo systemctl start sshd # 启动SSH服务 sudo systemctl enable postfix && sudo systemctl start postfix # 启动Postfix服务
配置防火墙:允许HTTP(80)和HTTPS(443)流量通过,若使用SSH端口(默认22)需一并开放:
sudo firewall-cmd --permanent --add-service=http sudo firewall-cmd --permanent --add-service=https sudo firewall-cmd --permanent --add-service=ssh # 可选 sudo firewall-cmd --reload # 重新加载防火墙规则
添加GitLab官方YUM仓库:通过官方脚本添加GitLab社区版(CE)仓库,确保软件包来源可信:
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
通过YUM包管理器快速安装GitLab CE:
sudo yum install -y gitlab-ce
安装完成后,GitLab会自动初始化配置,但需进一步调整以满足镜像仓库需求。
编辑GitLab主配置文件/etc/gitlab/gitlab.rb
,设置关键参数:
your-gitlab-domain.com
替换为你的域名或IP地址(如http://192.168.1.100
):external_url 'http://your-gitlab-domain.com'
gitlab_rails['registry_enabled'] = true # 开启Registry gitlab_rails['registry_host'] = "registry.your-gitlab-domain.com" # Registry访问域名 gitlab_rails['registry_port'] = 5000 # Registry默认端口 gitlab_rails['registry_path'] = "/var/opt/gitlab/gitlab-rails/shared/registry" # Registry存储路径
gitlab_rails['gitlab_shell_ssh_port'] = 2222 # 修改为实际端口
配置完成后,执行以下命令使配置生效并启动GitLab:
sudo gitlab-ctl reconfigure # 应用配置文件更改 sudo gitlab-ctl restart # 重启GitLab服务
首次启动时,GitLab会自动创建管理员账户(root),需通过命令重置密码:
sudo gitlab-rake "gitlab:password:reset[root]"
打开浏览器,输入external_url
设置的地址(如http://your-gitlab-domain.com
),使用管理员账户(root)及重置后的密码登录。
my-mirror-repo
),选择“Private”(私有)或“Public”(公开),点击“Create project”。registry.your-gitlab-domain.com
),确保与gitlab_rails['registry_host']
一致。docker login registry.your-gitlab-domain.com
),输入GitLab账号密码登录;docker tag my-image:latest registry.your-gitlab-domain.com/your-username/my-mirror-repo:latest
);docker push registry.your-gitlab-domain.com/your-username/my-mirror-repo:latest
)。docker pull registry.your-gitlab-domain.com/your-username/my-mirror-repo:latest
通过以上步骤,即可在CentOS上成功使用GitLab的镜像仓库功能,实现容器镜像的存储、管理与分发。