Skip to content

🧑‍💻 GitLab 15.9 安装部署与代码推送指南

一、环境准备

  • 内存要求:至少 4GB
bash
free -h

示例输出:

              total        used        free      shared  buff/cache   available
Mem:          3.8Gi       210Mi       3.2Gi       9.0Mi       400Mi       3.4Gi
Swap:         2.0Gi          0B       2.0Gi
  • GitLab 安装包检查
bash
ll
# 确保安装包已下载
# gitlab-ce-15.9.3-ce.0.el7.x86_64.rpm

二、安装 GitLab

1. 安装依赖

bash
yum install -y policycoreutils-python-utils.noarch

2. 安装 GitLab RPM 包

bash
rpm -ivh --nodeps gitlab-ce-15.9.3-ce.0.el7.x86_64.rpm

3. 配置 GitLab

编辑配置文件:

bash
vim /etc/gitlab/gitlab.rb

推荐配置:

ruby
external_url 'http://gitlab.测试.cn'
gitlab_rails['smtp_enable'] = false
gitlab_rails['gitlab_email_enabled'] = false
gitlab_rails['manage_backup_path'] = true
gitlab_rails['backup_path'] = "/var/opt/gitlab/backups"
gitlab_rails['backup_archive_permissions'] = 0644
gitlab_rails['store_initial_root_password'] = true

registry['enable'] = false
puma['ssl_listen'] = nil
puma['ssl_port'] = nil
puma['ssl_verify_mode'] = 'none'
puma['exporter_enabled'] = false

postgresql['enable'] = true
postgresql['ssl'] = 'off'
redis['enable'] = true

nginx['enable'] = true
nginx['client_max_body_size'] = '250m'
nginx['redirect_http_to_https'] = false
nginx['redirect_http_to_https_port'] = 80

prometheus['enable'] = false
alertmanager['enable'] = false
node_exporter['enable'] = false
redis_exporter['enable'] = false
postgres_exporter['enable'] = false
gitlab_exporter['enable'] = false
grafana['enable'] = false
letsencrypt['enable'] = false

4. 应用配置并启动 GitLab

bash
gitlab-ctl reconfigure

dev

5. 获取默认 root 密码

bash
cat /etc/gitlab/initial_root_password

登录后建议修改 root 密码,并设置界面语言为中文(右上角头像 → Preferences → Language)


三、代码推送至 GitLab

1. 查看当前 git 状态

bash
git status
git remote -v

如果默认远程仓库是 Gitee:

bash
git remote rename origin gitee

2. 添加 GitLab 仓库为 origin

bash
git remote add origin git@gitlab.oldboylinux.cn:gitlab-instance-xxx/test.git

3. 提交并推送代码

bash
git add .
git commit -m "Initial commit"
git push --all origin

四、验证效果

dev

  • 登录 GitLab 页面:http://gitlab.测试.cn
  • 检查项目是否存在、代码是否上传成功

感谢阅读,欢迎交流!