美文网首页
CentOS 上搭建GitLab

CentOS 上搭建GitLab

作者: 蟠龙有悔 | 来源:发表于2019-07-30 11:09 被阅读0次

准备在公司服务器上搭建一个GitLab,公司服务器是CentOS 6.8 的,不过在这之前,先在自己环境上搭个试试,我的服务器是CentOS7.5的,已安装nginx

1. 启用虚拟内存(如果你内存足够的话不需要做这一步)

见文章:Linux启用Swap分担内存压力

2. 下载gitlab社区版的rpm资源并安装gitlab-ce

~$ curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
~$ yum -y install gitlab-ce

3. 使用已存在的nginx配置gitLab

修改/etc/gitlab/gitlab.rb中的配置参数如下:

external_url 'http://git.example.com'
nginx['enable'] = false
gitlab_rails['internal_api_url'] = 'http://git.example.com'
web_server['external_users'] = ['www-data']

将gitLab中自带的nginxunicorn关掉,unicorn可以根据cpu核数设置并发的,由于当前服务器cpu核数并不多,而且unicorn吃内存,内存本来就不多了还要吃内存,果断按官方文档的设置将其关掉

配置/etc/nginx/conf.d/gitlab.conf

upstream gitlab-workhorse {
  server unix://var/opt/gitlab/gitlab-workhorse/socket fail_timeout=0;
}

server {
  listen *:80;
  server_name gitlab.mamahaha.top;
  server_tokens off;
  root /opt/gitlab/embedded/service/gitlab-rails/public;

  client_max_body_size 250m;

  access_log  /var/log/gitlab/nginx/gitlab_access.log;
  error_log   /var/log/gitlab/nginx/gitlab_error.log;

  location / {
    # serve static files from defined root folder;.
    # @gitlab is a named location for the upstream fallback, see below
    try_files $uri $uri/index.html $uri.html @gitlab;
  }

  location @gitlab {

    ## https://github.com/gitlabhq/gitlabhq/issues/694
    ## Some requests take more than 30 seconds.
    proxy_read_timeout      3600;
    proxy_connect_timeout   300;
    proxy_redirect          off;

    # Do not buffer Git HTTP responses
    proxy_buffering off;

    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-Forwarded-Proto   $scheme;

    proxy_pass http://gitlab-workhorse;

    ## The following settings only work with NGINX 1.7.11 or newer
    #
    ## Pass chunked request bodies to gitlab-workhorse as-is
    # proxy_request_buffering off;
    # proxy_http_version 1.1;
  }

  ## Enable gzip compression as per rails guide:
  ## http://guides.rubyonrails.org/asset_pipeline.html#gzip-compression
  ## WARNING: If you are using relative urls remove the block below
  ## See config/application.rb under "Relative url support" for the list of
  ## other files that need to be changed for relative url support
  location ~ ^/(assets)/ {
    root /opt/gitlab/embedded/service/gitlab-rails/public;
    gzip_static on; # to serve pre-gzipped version
    expires max;
    add_header Cache-Control public;
  }

  error_page 502 /502.html;
}

这块配置原来采用官方配置的,但是一到登陆页就报403错误,一番排查后果断弃用,并采用网上众多网友采用的配置

重启gitlab: gitlab-ctl reconfigure、gitlab-ctl restart
重启nginx
访问网站:正常

初始账户: root 密码:5iveL!fe

参考官方文档:Using an existing Passenger/Nginx installation
官方文档的翻译版:gitlab 启用HTTPS

参考:
GitLab在CentOS7下LNMP环境的安装使用
CentOS 7.x上GitLab搭建详细教程
centos下gitlab私服完整安装部署(nginx+MySQL+redis+gitlab-ce+gitlab-shell+)
centos7安装配置gitlab(使用外部nginx)

相关文章

网友评论

      本文标题:CentOS 上搭建GitLab

      本文链接:https://www.haomeiwen.com/subject/fpherctx.html