centos本地gitlab部署
时间: 2025-05-27 20:33:04 浏览: 15
### 一、关闭系统服务
为了确保 GitLab 的正常运行,需要先关闭系统的防火墙和 SElinux 设置。
#### 防火墙设置
通过以下命令停止并禁用 `firewalld` 防火墙:
```bash
systemctl stop firewalld.service
systemctl disable firewalld.service
```
#### SElinux 设置
编辑 `/etc/sysconfig/selinux` 文件,将 `SELINUX=enforcing` 修改为 `SELINUX=disabled`[^3]。完成后保存文件并重启系统以使更改生效:
```bash
reboot
```
---
### 二、安装必要的依赖包
在安装 GitLab 前,需要确保系统已安装所需的依赖项。执行以下命令来安装这些工具和服务:
```bash
yum install -y curl policycoreutils openssh-server openssh-clients postfix
```
此操作会安装 `curl`(用于下载资源)、`policycoreutils` 和其他 SSH 工具以及邮件服务器 `postfix`,后者对于发送通知邮件至关重要[^3]。
---
### 三、添加 GitLab YUM 源
可以通过两种方式添加 GitLab 的 YUM 源:手动创建 `.repo` 文件或者使用官方脚本自动完成。
#### 方法 1:手动配置 YUM 源
创建一个新的 `.repo` 文件,例如 `/etc/yum.repos.d/gitlab_gitlab-ce.repo` 并填入如下内容:
```ini
[gitlab-ce]
name=gitlab-ce
baseurl=http://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/
repo_gpgcheck=0
gpgcheck=0
enabled=1
gpgkey=https://packages.gitlab.com/gpg.key
```
随后更新本地的 YUM 缓存:
```bash
yum makecache
```
#### 方法 2:使用官方脚本
如果希望简化过程,可以运行以下命令直接获取最新的 YUM 源配置:
```bash
curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
```
---
### 四、安装 GitLab 社区版
当 YUM 源成功配置后,即可开始安装 GitLab 社区版 (CE)。执行以下命令进行安装:
```bash
yum -y install gitlab-ce
```
这一步骤将会下载并安装最新版本的 GitLab CE[^2]。如果有特定需求,则可以在命令中指定完整的版本号。
---
### 五、初始化与配置 GitLab
安装完成后,需要对 GitLab 进行基本配置。打开默认配置文件 `/etc/gitlab/gitlab.rb` 并根据实际需求修改相关内容。常见的调整包括外部 URL 地址等参数:
```ruby
external_url 'http://your-domain-or-ip'
```
替换其中的占位符为你自己的域名或 IP 地址[^4]。
最后应用新的配置并通过以下命令启动服务:
```bash
gitlab-ctl reconfigure
```
---
### 六、可选步骤 —— Nginx 配置
如果你已经在本地启用了自定义的 NGINX 实例,并希望通过它代理 GitLab 请求,请按照以下模板编写相应的站点配置文件:
```nginx
upstream gitlab-workhorse {
server unix:/var/opt/gitlab/gitlab-workhole/sockets/socket;
}
server {
listen 80;
server_name your-gitlab-domain;
location / {
proxy_pass http://gitlab-workhorse;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Ssl on;
}
}
```
记得将变量名替换成适合你的环境的具体值。
---
### 总结
以上就是在 CentOS 系统上部署本地 GitLab 所需的主要步骤。从基础环境准备到最终的服务上线都进行了详细介绍。若有进一步定制化需求可根据实际情况深入探索更多高级选项。
阅读全文
相关推荐

















