在Debian上搭建GitLab开发环境步骤
导读:在Debian上搭建GitLab开发环境步骤 1. 更新系统包 首先确保系统包为最新版本,避免依赖冲突: sudo apt update && sudo apt upgrade -y 2. 安装必要依赖 GitLab需要c...
在Debian上搭建GitLab开发环境步骤
1. 更新系统包
首先确保系统包为最新版本,避免依赖冲突:
sudo apt update &
&
sudo apt upgrade -y
2. 安装必要依赖
GitLab需要curl(下载工具)、openssh-server(SSH访问)、ca-certificates(SSL证书)、tzdata(时区设置)等依赖:
sudo apt install -y curl openssh-server ca-certificates tzdata postfix
安装postfix时,选择“Internet Site”类型并设置服务器域名(用于邮件通知)。
3. 添加GitLab官方仓库
通过官方脚本添加GitLab社区版(CE)仓库,确保获取最新版本:
curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash
4. 安装GitLab CE
使用apt安装GitLab社区版(默认安装最新稳定版):
sudo apt install -y gitlab-ce
5. 配置GitLab
编辑GitLab主配置文件,设置外部访问URL(替换为服务器IP或域名):
sudo nano /etc/gitlab/gitlab.rb
找到external_url行,修改为:
external_url 'http://your_server_ip' # 或 'http://your_domain.com'
保存退出后,重新配置GitLab以应用更改:
sudo gitlab-ctl reconfigure
6. 启动GitLab服务
启动GitLab并设置为开机自启:
sudo gitlab-ctl start
sudo systemctl enable gitlab
7. 访问GitLab
在浏览器中输入配置的external_url(如http://192.168.1.100),首次访问需设置管理员密码(默认管理员账号为root)。
8. 可选配置
- 配置防火墙:若启用UFW防火墙,允许HTTP(80)和HTTPS(443)端口:
sudo ufw allow http sudo ufw allow https sudo ufw enable - 配置邮件服务:若需邮件通知(如密码重置、合并请求),编辑
/etc/gitlab/gitlab.rb添加SMTP设置:保存后重新配置:gitlab_rails['gitlab_email_enabled'] = true gitlab_rails['gitlab_email_from'] = 'your-email@example.com' gitlab_rails['smtp_enable'] = true gitlab_rails['smtp_address'] = "smtp.example.com" gitlab_rails['smtp_port'] = 587 gitlab_rails['smtp_user_name'] = "your-email@example.com" gitlab_rails['smtp_password'] = "your-email-password" gitlab_rails['smtp_domain'] = "example.com" gitlab_rails['smtp_authentication'] = "login" gitlab_rails['smtp_enable_starttls_auto'] = true gitlab_rails['smtp_tls'] = truesudo gitlab-ctl reconfigure - 配置HTTPS:启用Let’s Encrypt免费SSL证书(需域名),编辑
/etc/gitlab/gitlab.rb:重新配置后,GitLab会自动申请并配置SSL证书。letsencrypt['enable'] = true letsencrypt['auto_renew'] = true letsencrypt['contact_emails'] = ['your-email@example.com']
9. 使用GitLab
- 创建项目:登录后点击“New project”,选择“Create blank project”或导入现有仓库。
- CI/CD配置:在项目根目录创建
.gitlab-ci.yml文件,定义构建、测试、部署流程(如示例):提交代码后,GitLab会自动触发CI/CD流水线。stages: - build - test - deploy build: stage: build script: - echo "Building the project..." test: stage: test script: - echo "Running tests..." deploy: stage: deploy script: - echo "Deploying the project..."
通过以上步骤,即可在Debian系统上完成GitLab开发环境的搭建,并支持代码托管、协作、CI/CD等核心功能。
声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!
若转载请注明出处: 在Debian上搭建GitLab开发环境步骤
本文地址: https://pptw.com/jishu/740790.html
