ubuntu gitlab如何安装配置

265
2025/4/14 0:32:54
栏目: 智能运维
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

在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

4. 安装GitLab

更新APT包索引并安装GitLab:

sudo apt update
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 目录下。

通过以上步骤,你应该能够在Ubuntu上成功安装和配置GitLab。如果有任何问题,请参考GitLab官方文档或寻求社区支持。

辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读: Ubuntu下Mingw的安装包有哪些版本