ubuntu

在ubuntu上部署gitlab的步骤

小樊
43
2025-07-07 21:50:58
栏目: 智能运维

在Ubuntu上部署GitLab的步骤如下:

1. 更新系统包

首先,确保你的系统包是最新的:

sudo apt update
sudo apt upgrade -y

2. 安装必要的依赖

安装GitLab所需的依赖包:

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

3. 添加GitLab仓库

添加GitLab的官方GPG密钥:

curl https://packages.gitlab.com/gpg.key | sudo apt-key add -

创建一个新的APT仓库文件 /etc/apt/sources.list.d/gitlab_gitlab-ce.list

sudo nano /etc/apt/sources.list.d/gitlab_gitlab-ce.list

在文件中添加以下内容(请根据你的Ubuntu版本选择合适的GitLab版本):

deb https://packages.gitlab.com/gitlab/gitlab-ce/ubuntu focal main

更新APT包索引:

sudo apt update

4. 安装GitLab

使用以下命令安装GitLab:

sudo EXTERNAL_URL "http://your-gitlab-domain.com" apt install gitlab-ce

http://your-gitlab-domain.com 替换为你的GitLab实例的实际域名或IP地址。

5. 配置GitLab

安装完成后,GitLab会自动启动并进行初始配置。你可以通过浏览器访问 http://your-gitlab-domain.com 来完成初始设置。

6. 配置防火墙

如果你的系统启用了防火墙,确保开放HTTP(80)和HTTPS(443)端口:

sudo ufw allow http
sudo ufw allow https

7. 配置SSL(可选)

为了提高安全性,建议为GitLab配置SSL证书。你可以使用Let’s Encrypt免费获取SSL证书:

sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d your-gitlab-domain.com

按照提示完成SSL证书的安装和配置。

8. 验证安装

访问 https://your-gitlab-domain.com 并使用默认用户名和密码登录。默认用户名是 root,密码是在安装过程中生成的。

9. 重置密码

如果你忘记了密码,可以通过SSH登录到服务器并重置密码:

sudo gitlab-rails console

在控制台中输入以下命令来重置密码:

user User.where(id: 1).first
user.password 'new_password'
user.password_confirmation 'new_password'
user.save!

new_password 替换为你想要设置的新密码。

10. 配置备份

为了确保数据安全,建议定期备份GitLab数据。你可以使用GitLab提供的备份工具:

sudo gitlab-rake gitlab:backup:create

备份文件将存储在 /var/opt/gitlab/backups 目录下。

0
看了该问题的人还看了