在Linux中搭建GitLab服务器需要经过以下几个步骤:
sudo apt-get update
sudo apt-get install -y curl openssh-server ca-certificates tzdata perl
sudo yum update
sudo yum install -y curl policycoreutils openssh-server perl
使用官方提供的脚本添加GitLab仓库。
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/el/$releasever/gitlab-ce.repo -o /etc/yum.repos.d/gitlab-ce.repo
根据你的操作系统选择相应的安装命令。
sudo EXTERNAL_URL="http://your_server_ip" apt-get install gitlab-ce
sudo yum install -y gitlab-ce
编辑GitLab的配置文件 /etc/gitlab/gitlab.rb
,设置外部URL和其他配置。
external_url 'http://your_server_ip'
运行以下命令以应用配置更改并重启GitLab服务。
sudo gitlab-ctl reconfigure
sudo gitlab-ctl restart
打开浏览器并访问 http://your_server_ip
,你应该会看到GitLab的登录页面。默认情况下,用户名是 root
,密码是在安装过程中生成的。
如果你忘记了密码,可以通过SSH登录到服务器并重置密码。
sudo gitlab-rails console
在控制台中输入以下命令来重置密码:
user = User.where(id: 1).first
user.password = 'new_password'
user.password_confirmation = 'new_password'
user.save!
确保你的防火墙允许HTTP(80)和HTTPS(443)流量。
sudo ufw allow 80
sudo ufw allow 443
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
为了提高安全性,建议配置SSL证书。你可以使用Let’s Encrypt免费获取SSL证书。
sudo apt-get install certbot python3-certbot-nginx # Ubuntu
sudo yum install certbot python3-certbot-nginx # CentOS
sudo certbot --nginx -d your_domain.com
按照提示完成配置。
如果你需要使用GitLab Runner来运行CI/CD任务,可以按照官方文档进行配置。
通过以上步骤,你应该能够在Linux服务器上成功搭建GitLab服务器。