ubuntu

ubuntu如何配置gitlab环境

小樊
37
2025-10-27 07:09:57
栏目: 智能运维

Ubuntu配置GitLab环境详细步骤

1. 环境准备

1.1 系统要求

1.2 基础配置

1.3 安装依赖包

GitLab运行需依赖SSH(远程访问)、CA证书(HTTPS加密)、时区数据(时间同步)等工具,通过以下命令安装:

sudo apt install -y curl openssh-server ca-certificates tzdata perl

注:openssh-server用于GitLab的SSH协议访问(默认端口22);postfix为邮件服务(可选,若需邮件通知需额外配置)。

2. 添加GitLab官方包存储库

GitLab未包含在Ubuntu默认源中,需通过官方脚本添加专用存储库,以获取最新稳定版本的安装包。

curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash

注:若需安装企业版(GitLab EE),将gitlab-ce替换为gitlab-ee即可。

3. 安装GitLab Community Edition(CE)

3.1 指定外部URL

GitLab需通过外部URL访问(如服务器IP或域名),修改默认配置以适配你的环境:

EXTERNAL_URL="http://your_server_ip"  # 替换为实际IP或域名(如http://192.168.1.100)

注:若使用域名,需提前解析到服务器IP,并配置SSL证书(可选但推荐)。

3.2 安装GitLab CE

通过apt命令安装GitLab CE,系统会自动解决依赖关系:

sudo apt install gitlab-ce -y

注:若需指定版本(如17.5.2),可使用sudo apt install gitlab-ce=17.5.2-ce.0(需提前查询可用版本)。

4. 配置GitLab

4.1 重新配置GitLab

安装完成后,需运行reconfigure命令应用配置(如外部URL、服务端口等),生成必要的系统文件:

sudo gitlab-ctl reconfigure

此命令会自动配置SSH端口、Web服务端口、数据库连接等,耗时约1-2分钟。

4.2 启动GitLab服务

启动GitLab相关服务(包括Web服务器、数据库、Git服务等),并设置为开机自启动:

sudo gitlab-ctl start  # 启动服务
sudo systemctl enable gitlab-runsvdir.service  # 开机自启动

4.3 查看服务状态

确认GitLab各组件是否正常运行(应显示run状态):

sudo gitlab-ctl status

示例输出:

run: alertmanager: (pid 1234) 1m; run: log: (pid 1235) 1m
run: gitaly: (pid 1236) 1m; run: log: (pid 1237) 1m
run: gitlab-exporter: (pid 1238) 1m; run: log: (pid 1239) 1m
run: gitlab-workhorse: (pid 1240) 1m; run: log: (pid 1241) 1m
run: logrotate: (pid 1242) 1m; run: log: (pid 1243) 1m
run: postgres: (pid 1244) 1m; run: log: (pid 1245) 1m
run: prometheus: (pid 1246) 1m; run: log: (pid 1247) 1m
run: redis: (pid 1248) 1m; run: log: (pid 1249) 1m
run: sidekiq: (pid 1250) 1m; run: log: (pid 1251) 1m
run: unicorn: (pid 1252) 1m; run: log: (pid 1253) 1m

4.4 查看GitLab版本

确认安装的GitLab版本,确保符合预期:

gitlab-ce --version

示例输出:

gitlab-ce 17.5.2-ce.0

5. 访问GitLab

5.1 浏览器访问

在浏览器中输入配置的外部URL(如http://your_server_ip),进入GitLab登录页面。

5.2 可选配置

6. 常用维护命令

注意事项

0
看了该问题的人还看了