在Debian上部署GitLab是一个相对直接的过程,但需要一些步骤来确保一切正常运行。以下是一个详细的指南,帮助你在Debian系统上安装和配置GitLab。
准备工作
-
更新系统: 首先,确保你的Debian系统已经更新到最新版本。
sudo apt update sudo apt upgrade
-
安装依赖项: 安装GitLab所需的基本依赖包。
sudo apt install curl openssh-server ca-certificates tzdata perl
-
安装Postfix: 在安装Postfix的过程中,选择“Internet Site”并按照提示完成配置。设置“mail name”为你的服务器的外部DNS域名。
安装GitLab
-
添加GitLab官方仓库: 使用以下命令导入GitLab的GPG密钥,并将GitLab存储库添加到APT源列表中。
curl https://packages.gitlab.com/gpg.key | sudo apt-key add - echo "deb [signed-by=/usr/share/keyrings/gitlab-keyring.gpg] https://packages.gitlab.com/gitlab/gitlab-ce/debian/ buster main" | sudo tee /etc/apt/sources.list.d/gitlab.list
-
下载并安装GitLab CE: 使用以下命令安装GitLab社区版(CE)。
sudo bash <(curl -s https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh) sudo apt-get install gitlab-ce
配置GitLab
-
配置外部URL: 编辑GitLab配置文件
/etc/gitlab/gitlab.rb
,找到并设置external_url
参数。sudo vim /etc/gitlab/gitlab.rb
将以下内容替换为你的服务器IP或域名:
external_url 'http://your_server_ip'
-
重新配置并重启GitLab: 保存文件并重新配置GitLab。
sudo gitlab-ctl reconfigure sudo gitlab-ctl restart
配置Nginx(可选)
如果你选择使用Nginx作为GitLab的Web服务器,可以按照以下步骤进行配置:
-
创建Nginx配置文件: 创建一个新的Nginx配置文件
gitlab.conf
。sudo vim /etc/nginx/conf.d/gitlab.conf
-
配置Nginx: 将以下内容添加到
gitlab.conf
文件中:upstream gitlab { server 127.0.0.1:8181; } server { listen 80; server_name your_gitlab_domain; server_tokens off; root /opt/gitlab/embedded/service/gitlab-rails/public; client_max_body_size 250m; access_log /var/log/gitlab/gitlab_access.log; error_log /var/log/gitlab/gitlab_error.log; location / { try_files uri = /index.html uri/ /index.html @gitlab; } location @gitlab { proxy_read_timeout 300; proxy_connect_timeout 300; proxy_redirect off; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Frame-Options SAMEORIGIN; proxy_pass http://gitlab; } }
-
引入Nginx配置文件: 在Nginx的主配置文件中引入
gitlab.conf
。sudo vim /etc/nginx/nginx.conf
在
http
块中添加以下内容:include /etc/nginx/conf.d/gitlab.conf;
-
重启Nginx: 重启Nginx以应用新的配置。
sudo systemctl restart nginx
设置防火墙规则
确保防火墙允许访问GitLab的默认端口(通常是80和443)。
sudo ufw allow 80 sudo ufw allow 443 sudo ufw reload
访问GitLab
现在,你应该可以通过在浏览器中输入你的服务器IP或域名来访问GitLab。首次访问时,系统会提示你设置一个新的密码。使用默认的管理员账户 root
登录,并使用新密码进行更改。
通过以上步骤,你应该能够在Debian系统上成功安装和配置GitLab。如果在安装过程中遇到任何问题,请参考GitLab的官方文档或寻求社区帮助。