中标麒麟7.4为gitlab添加Registry

1. 使用gitlab提供的registry的考虑

GitLab 完全能胜任 Docker 镜像 & 通用包仓库,功能可用、社区文档丰富。但在企业级镜像治理、安全合规、高可用场景,Harbor / Artifactory 仍是更主流的选择。我计划先用 GitLab Registry 跑通整条流水线,日后规模扩大再 harbor-migrate 也不复杂------只需重新 docker tag && docker push 即可。

当前:

  • 团队 < 50 人,镜像数量 < 100 GB;
  • 不需要漏洞扫描、签名、多集群复制;
  • 希望"一站式"代码+构建+存储,快速落地

我就考虑使用gitlab的仓库了。

2. 配置文件内打开

寻找到你的gitlab.rb文件。一般在/etc/gitlab/gitlab.rb内。如果找不到可以使用find命令搜索:sudo find -name gitlab.rb。注:使用sudo的原因是麒麟系统权限设置非常死,不实用管理员权限搜索不到。

使用命令:sudo vi /etc/gitlab/gitlab.rb修改内容,我的版本是gitlab17,不是很新,仅供参考。

在文档内搜索"registry_external_url",找到如下内容的位置。我们需要改的其实不多。

复制代码
################################################################################
## Container Registry settings
##! Docs: https://docs.gitlab.com/ee/administration/packages/container_registry.html 
################################################################################

# registry_external_url 'https://registry.example.com '

### Settings used by GitLab application
# gitlab_rails['registry_enabled'] = true
# gitlab_rails['registry_host'] = "registry.gitlab.example.com"
# gitlab_rails['registry_port'] = "5005"
# gitlab_rails['registry_path'] = "/var/opt/gitlab/gitlab-rails/shared/registry"

# Notification secret, it's used to authenticate notification requests to GitLab application
# You only need to change this when you use external Registry service, otherwise
# it will be taken directly from notification settings of your Registry
# gitlab_rails['registry_notification_secret'] = nil

###! **Do not change the following 3 settings unless you know what you are
###!   doing**
# gitlab_rails['registry_api_url'] = "http://127.0.0.1:5000 "
# gitlab_rails['registry_key_path'] = "/var/opt/gitlab/gitlab-rails/certificate.key"
# gitlab_rails['registry_issuer'] = "omnibus-gitlab-issuer"

我计划通过5050端口提供服务。修改如下:

复制代码
registry_external_url 'http://你的gitlabIP地址:5050'

### Settings used by GitLab application
gitlab_rails['registry_enabled'] = true
gitlab_rails['registry_host'] = "你的gitlabIP地址"
gitlab_rails['registry_port'] = "5050"
gitlab_rails['registry_path'] = "/var/opt/gitlab/gitlab-rails/shared/registry"

# Notification secret, it's used to authenticate notification requests to GitLab application
# You only need to change this when you use external Registry service, otherwise
# it will be taken directly from notification settings of your Registry
# gitlab_rails['registry_notification_secret'] = nil

###! **Do not change the following 3 settings unless you know what you are
###!   doing**
gitlab_rails['registry_api_url'] = "http://127.0.0.1:5050 "
# gitlab_rails['registry_key_path'] = "/var/opt/gitlab/gitlab-rails/certificate.key"
# gitlab_rails['registry_issuer'] = "omnibus-gitlab-issuer"

注意:改成你的IP地址;把修改部分前面的#注释符号去掉;我将registry_external_url从https改成了http,https还需要证书,内网环境我不需要真么复杂。

对文件进行保存。

3. (原神) 启动

这实际上是对gitlab进行的配置,自然是重启gitlab。

bash 复制代码
# 重新加载配置
sudo gitlab-ctl reconfigure
# 重启gitlab
sudo gitlab-ctl restart
# 检查gitlab运行状态
sudo gitlab-ctl status

4. 预防性检查

4.1 仓库权限检查

首先仓库文件的存储位置/var/opt/gitlab/gitlab-rails/shared/registry。因为众所周知的麒麟系统文件系统权限管理比较严格,检查一下是否拥有读写权限。
sudo ls -la /var/opt/gitlab/gitlab-rails/shared/你可以看到这个文件夹被正确的划分到git用户组,registry用户下。

目前这个文件夹权限不存在问题。如果你更改了默认的存储地址,请使用上述方法检查权限。

4.2 服务启动检查

  1. 使用端口检测是否正常启动

  2. 使用gitlab-ctl status检查启动情况

  3. 在gitlab页面检查启动情况

  4. 使用docker检查启动情况

bash 复制代码
docker login 我的ip:5050 -u root -p <your_gitlab_root_password>

哎嘿,报错了你说奇不奇怪。

5. 解决http和https问题

docker默认使用https协议访问了 IP:5050,我们刚才在gitlab.rb中设置为http。在docker运行主机添加如下:

bash 复制代码
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "insecure-registries": ["我的ip:5050"]
}
EOF

sudo systemctl daemon-reload
sudo systemctl restart docker

再次检查

bash 复制代码
docker login 我的ip:5050 -u root -p <your_gitlab_root_password>

#出现Login Succeeded,登录成功

注意,比如我要用k8s部署项目,那么k8s也要访问这个仓库。同样对面机器也要执行上述命令,完成对该端口的http访问。

相关推荐
霸道流氓气质17 天前
GitLab CI/CD 完全指南
linux·ci/cd·gitlab
sbjdhjd17 天前
从零搭建企业级 CI/CD(下):Jenkins+GitLab+Harbor 全链路实战指南
git·servlet·ci/cd·云原生·云计算·gitlab·jenkins
用什么都重名18 天前
Git 合并两个无共同历史的分支:从报错到解决全记录
git·gitlab
master33618 天前
GitLab (Docker) 常用命令及解决方案清单
docker·容器·gitlab
qq_3564086618 天前
GitLab 单机私有化部署文档(基于 Docker 环境)
docker·gitlab
lisanmengmeng20 天前
gitlab 免密配置
linux·服务器·gitlab
求知若渴,虚心若愚。20 天前
Jenkins 自动化流水线(CICD)
运维·自动化·gitlab
mnasd22 天前
Gitlab + Jenkins 实现 CICD
运维·gitlab·jenkins
鹤鸣的日常22 天前
前端运行时动态环境变量方案
前端·react.js·docker·前端框架·vue·gitlab
starvapour22 天前
Ubuntu部署gitlab频繁出现502的问题
linux·ubuntu·gitlab