1、安装包准备:需要下载GitLab的RPM安装包,可以从清华大学镜像站下载,使用以下命令:
- wget https://mirrors.tuna.tsinghua.edu.cn/gitlabce/yum/el7/gitlabce10.5.7ce.0.el7.x86_64.rpm
2、安装GitLab:下载完成后,使用rpm
命令进行安装:

- sudo rpm i gitlabce10.5.7ce.0.el7.x86_64.rpm
如果过程中提示输入y/n
,请输入y
以继续。
3、修改配置文件:安装完成后,需要配置GitLab的服务器IP和端口,编辑/etc/gitlab/gitlab.rb
文件,将外部URL配置为你的服务器IP和端口,
- vim /etc/gitlab/gitlab.rb
找到并修改以下内容(假设服务器IP为192.168.1.100
,端口为9090
):
- external_url 'http://192.168.1.100:9090'
4、关闭防火墙或添加端口:可以选择关闭防火墙或添加相应的端口规则,关闭防火墙的命令如下:
- sudo systemctl stop firewalld
- sudo systemctl disable firewalld
如果选择添加端口规则,可以使用以下命令开放9090端口:
- sudo firewallcmd zone=public addport=9090/tcp permanent
- sudo firewallcmd reload
5、重置GitLab:执行以下命令重新配置GitLab:

- sudo gitlabctl reconfigure
该过程可能需要几分钟时间,完成后会显示“Congrats, GitLab is configured”。
6、启动GitLab:使用以下命令启动GitLab服务:
- sudo gitlabctl start
7、访问GitLab:在浏览器中输入配置的URL,例如http://192.168.1.100:9090
,即可访问GitLab,首次登录需要注册账号和密码。
8、通过域名访问:如果希望通过域名访问GitLab,可以在Windows系统的hosts文件中添加域名解析,编辑hosts文件:
- C:\Windows\System32\drivers\etc\hosts
添加以下内容(假设域名为my.gitlab.com
,IP为192.168.1.100
):
- 192.168.1.100 my.gitlab.com
9、配置Nginx:在linux服务器上安装并配置Nginx,以实现域名反向代理,安装Nginx:

- sudo yum install epelrelease
- sudo yum install nginx
启动Nginx服务:
- sudo systemctl start nginx
检查Nginx状态:
- sudo systemctl status nginx
设置Nginx开机自启:
- sudo systemctl enable nginx
编辑NGINX配置文件,添加以下内容(假设监听80端口,域名为my.gitlab.com
,代理到本地9090端口):
- server {
- listen 80;
- server_name my.gitlab.com;
- location / {
- proxy_pass http://192.168.1.100:9090;
- }
- }
重启Nginx服务:
- sudo systemctl restart nginx
10、测试访问:在浏览器中输入域名http://my.gitlab.com
,即可通过域名访问GitLab。
FAQs:常见问题解答
1、Q:如何查看GitLab的日志?
A:可以通过以下命令查看GitLab的日志:
- sudo journalctl u gitlabce.service f nopager
2、Q:如何解决内存过高的问题?
A:可以尝试修改GitLab的配置来限制资源使用,编辑/etc/gitlab/gitlab.rb
文件,找到并修改以下内容:
- gitlab_rails['unicorn']['worker_processes'] = 2 # 调整工作进程数
- gitlab_rails['unicorn']['timeout'] = 60 # 超时时间,单位秒
保存后,重新配置并重启GitLab:
- sudo gitlabctl reconfigure
- sudo gitlabctl restart