centos8安装gitlab
时间: 2025-05-08 18:19:36 浏览: 24
### 在 CentOS 8 上安装配置 GitLab
#### 准备工作
在开始之前,确保服务器已经更新到最新的状态,并关闭可能影响服务运行的防火墙和SELinux设置。可以通过以下命令来实现:
```bash
sudo systemctl stop firewalld && sudo systemctl disable firewalld
sudo setenforce 0
sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config
```
#### 添加 GitLab YUM 源
编辑 `/etc/yum.repos.d/gitlab-ce.repo` 文件,添加清华大学镜像源的内容[^1]:
```bash
[root@localhost ~]# vim /etc/yum.repos.d/gitlab-ce.repo
[gitlab-ce]
name=Gitlab CE Repository
baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever/
gpgcheck=0
enabled=1
```
保存退出后刷新缓存:
```bash
yum makecache
```
#### 安装 GitLab 软件包
执行以下命令以安装最新版本的 `gitlab-ce` 软件包[^2]:
```bash
sudo EXTERNAL_URL="http://gitlab.example.com" dnf install -y gitlab-ce
```
如果需要指定特定的历史版本,则可以替换 `{VERSION}` 参数为所需的版本号。
#### 配置外部 URL 和初始化
定义 GitLab 的访问地址(例如 http://your-domain-or-ip),通过设置变量 `EXTERNAL_URL` 来完成此操作。这一步非常重要,因为它决定了用户将来如何访问您的实例。
#### 启动并重新加载 GitLab 服务
一旦安装成功,首次启动 GitLab 并应用初始配置:
```bash
sudo gitlab-ctl reconfigure
```
等待几分钟直到进程结束。之后可通过浏览器输入设定好的域名或者 IP 地址验证是否正常运作[^3]。
#### SSL 设置 (可选)
为了增强安全性,建议启用 HTTPS 协议。这里提供一种基于 OpenSSL 手动生成自签名证书的方法作为参考:
##### 创建SSL目录结构及相关文件
```bash
mkdir -p /etc/gitlab/ssl
chmod 700 /etc/gitlab/ssl
cd /etc/gitlab/ssl
openssl genrsa -out yourdomain.key 2048 # 替换为实际使用的主机名或IP
openssl req -new -key yourdomain.key -out yourdomain.csr
openssl x509 -req -days 365 -in yourdomain.csr -signkey yourdomain.key -out yourdomain.crt
cat yourdomain.crt yourdomain.key > yourdomain.pem
chown root:root *.key *.crt *.pem
chmod 400 *.key *.crt *.pem
```
最后调整 Nginx 或其他反向代理的相关部分指向新生成的 PEM 文件路径即可。
---
阅读全文
相关推荐














