在局域网的CentOS 7服务器上搭建GitLab服务。


1 安装GitLab

参考官网:https://about.gitlab.com/install/?test=capabilities#centos-7

1.1 准备工作

安装ssh服务并打开防火墙:

1
2
3
4
5
6
7
sudo yum install -y curl policycoreutils-python openssh-server perl
sudo systemctl enable sshd
sudo systemctl start sshd

sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo systemctl reload firewalld

局域网暂时不需要Email服务,所以官网的Email配置那一段代码不用管。

1.2 添加GitLab软件库到系统

1
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.rpm.sh | sudo bash

1.3 安装GitLab

1
sudo yum install -y gitlab-ee

2 配置GitLab

1
vim /etc/gitlab/gitlab.rb

2.1 修改服务的IP和端口号

将外部链接地址改为部署服务的主机地址和端口号,假如你部署的服务器IP为192.168.2.240,目标端口为888:

1
external_url 'http://192.168.2.240:888'

此外,为了避免502错误,需要修改高级设置中的端口设置:

1
2
3
### Advanced settings
# unicorn['listen'] = 'localhost'
unicorn['port'] = 888  # 检索并更改

2.2 设定最大请求数目和缓存

1
2
3
4
##! **recommend value is 1/4 of total RAM, up to 14GB.**
postgresql['shared_buffers'] = "256MB"
# ...省略很多行...
postgresql['max_connections'] = 200

2.3 刷新配置并启动GitLab

1
gitlab-ctl reconfigure && gitlab-ctl restart

耐心等待启动完毕即可,打开设定的web地址即可看到GitLab页面:

Git-Lab_webUI

3 配置root管理员的密码

在服务器root用户下,启动GitLab的控制台:

1
gitlab-rails console -e production

稍等片刻,即可打开控制台终端,依次键入如下命令即可修改管理员密码:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
--------------------------------------------------------------------------------
 Ruby:         ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux]
 GitLab:       13.10.2-ee (cc4224220e6) EE
 GitLab Shell: 13.17.0
 PostgreSQL:   12.6
--------------------------------------------------------------------------------
Loading production environment (Rails 6.0.3.4)
irb(main):001:0> user = User.where(id: 1).first
=> #<User id:1 @root>
irb(main):002:0> user.password = '12345678'
=> "12345678"
irb(main):003:0> user.password_confirmation = '12345678'
=> "12345678"
irb(main):004:0> user.save!
Enqueued ActionMailer::MailDeliveryJob (Job ID: 439b8ca7-ad69-4d2d-aa79-9640c73db314) to Sidekiq(mailers) with arguments: "DeviseMailer", "password_change", "deliver_now", {:args=>[#<GlobalID:0x00007f1143a86b18 @uri=#<URI::GID gid://gitlab/User/1>>]}
=> true
irb(main):005:0> exit

Git-Lab_console

更改完毕后,即可在web页面登录GitLab了。

4 GitLab常用命令

功能 命令
重启配置,并启动gitlab服务 sudo gitlab-ctl reconfigure
启动所有 gitlab sudo gitlab-ctl start
重新启动GitLab sudo gitlab-ctl restart
停止所有 gitlab sudo gitlab-ctl stop
查看服务状态 sudo gitlab-ctl status
查看Gitlab日志 sudo gitlab-ctl tail
修改默认的配置文件 sudo vim /etc/gitlab/gitlab.rb
检查gitlab gitlab-rake gitlab:check SANITIZE=true –trace

参考资料

  1. GitLab官网安装指南:https://about.gitlab.com/install/?test=capabilities#centos-7
  2. 手把手教你搭建gitlab服务器:https://zhuanlan.zhihu.com/p/62042884
  3. gitlab访问错误Whoops, GitLab is taking too much time to respond:https://cloud.tencent.com/developer/article/1511600
  4. gitlab入门学习:https://juejin.cn/post/6844904065973878791#heading-21