Centos7部署配置Gitlab

GitLab是由GitLabInc.开发,使用MIT许可证的基于网络的Git仓库管理工具,且具有wiki和issue跟踪功能。使用Git作为代码管理工具,并在此基础上搭建起来的web服务。
本文将详细介绍如何在Centos7中部署Gitlab。

Centos7部署配置Gitlab_第1张图片


一、安装依赖软件

[root@localhost ~] yum -y install policycoreutils openssh-server openssh-clients postfix

二、开启postfix
postfix支持gitlab发信功能,设置postfix开机自启

[root@localhost ~] systemctl enable postfix && systemctl start postfix

三、安装Gitlab
下载rpm包并安装,这里我选择的是Centos 7系统Gitlab下载地址中本文发布时最新的Gitlab

[root@localhost ~] wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-11.3.4-ce.0.el7.x86_64.rpm
......
[root@localhost ~] rpm -ivh gitlab-ce-11.3.4-ce.0.el7.x86_64.rpm
警告:gitlab-ce-11.3.4-ce.0.el7.x86_64.rpm: 头V4 RSA/SHA1 Signature, 密钥 ID f27eab47: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:gitlab-ce-11.3.4-ce.0.el7        ################################# [100%]
It looks like GitLab has not been configured yet; skipping the upgrade script.

       *.                  *.
      ***                 ***
     *****               *****
    .******             *******
    ********            ********
   ,,,,,,,,,***********,,,,,,,,,
  ,,,,,,,,,,,*********,,,,,,,,,,,
  .,,,,,,,,,,,*******,,,,,,,,,,,,
      ,,,,,,,,,*****,,,,,,,,,.
         ,,,,,,,****,,,,,,
            .,,,***,,,,
                ,*,.
  


     _______ __  __          __
    / ____(_) /_/ /   ____ _/ /_
   / / __/ / __/ /   / __ `/ __ \
  / /_/ / / /_/ /___/ /_/ / /_/ /
  \____/_/\__/_____/\__,_/_.___/
  

Thank you for installing GitLab!
GitLab was unable to detect a valid hostname for your instance.
Please configure a URL for your GitLab instance by setting `external_url`
configuration in /etc/gitlab/gitlab.rb file.
Then, you can start your GitLab instance by running the following command:
  sudo gitlab-ctl reconfigure

For a comprehensive list of configuration options please see the Omnibus GitLab readme
https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md

四、设置服务器IP和端口
修改配置文件gitlab.rb

[root@localhost ~] vim  /etc/gitlab/gitlab.rb

修改external_url为服务器IP和指定端口,这里我设置成8069

## GitLab URL
##! URL on which GitLab will be reachable.
##! For more details on configuring external_url see:
##! https://docs.gitlab.com/omnibus/settings/configuration.html#configuring-the-external-url-for-gitlab
# external_url 'http://gitlab.example.com'
external_url 'http://172.27.9.249:8069' //服务器ip和端口

五、重置并启动GitLab

[root@localhost ~] gitlab-ctl reconfigure
......
[root@localhost ~] gitlab-ctl restart
ok: run: alertmanager: (pid 6459) 0s
ok: run: gitaly: (pid 6470) 0s
ok: run: gitlab-monitor: (pid 6494) 1s
ok: run: gitlab-workhorse: (pid 6499) 0s
ok: run: logrotate: (pid 6507) 0s
ok: run: nginx: (pid 6517) 1s
ok: run: node-exporter: (pid 6597) 0s
ok: run: postgres-exporter: (pid 6599) 0s
ok: run: postgresql: (pid 6620) 0s
ok: run: prometheus: (pid 6628) 0s
ok: run: redis: (pid 6640) 1s
ok: run: redis-exporter: (pid 6644) 0s
ok: run: sidekiq: (pid 6651) 0s
ok: run: unicorn: (pid 6665) 0s
[root@localhost ~] 

六、浏览器访问GitLab
输入服务器IP和指定端口进行访问,可能出现两种情况
1、访问失败
可能是因为防火墙的缘故,可以关闭防火墙或者打通8069端口,这里直接关闭防火墙

[root@localhost ~] systemctl stop firewalld.service

2、发生502报错


Centos7部署配置Gitlab_第2张图片

有三种原因可以进行逐一排查。
(1)权限问题
Gitlab文件需要给予读写的权限

[root@localhost ~] chmod -R 755 /var/log/gitlab

(2)端口问题
Gitlab的默认启动端口是80,8080,这里我设置成了8069端口,不用再更改;unicorn worker的工作端口默认为8080,如果你的8080端口被占用的,这一项需要更改

[root@localhost ~] vim /etc/gitlab/gitlab.rb

更改端口参数

external_url 'http://172.27.9.249:8069' //指定访问端口
......
unicorn['port'] = 8001    //unicorn worker的工作端口

重启Gitlab

[root@localhost ~] gitlab-ctl reconfigure
[root@localhost ~] gitlab-ctl restart

(3)内存不足的问题
安装gitlab的时候,已经说明需要有4G左右的内存

访问成功后,由于是第一次访问GitLab,系统会重定向页面到重定向到重置密码页面,你可以直接设置新密码然后登录


Centos7部署配置Gitlab_第3张图片

登录成功,部署完毕!


Centos7部署配置Gitlab_第4张图片

如果你喜欢本文章,还请点个关注和喜欢,我会为大家不断地带来Python学习笔记。

你可能感兴趣的:(Centos7部署配置Gitlab)