LoginSignup
8
12

More than 5 years have passed since last update.

CentOS7にGitLabをインストールする(既存nginxを使用)

Last updated at Posted at 2017-02-26

GitLabの基本的なインストールは公式サイトにとても詳しい情報がのっているので数分で終わります。
GitLabは内部でnginx、redis、postgresqlを使っていてGitLabをインストールするとそれらも同時にインストールされてしまいます。
そこで、サーバーにすでにnginxがインストールされていてそのサーバーにGitLabをインストールしたらどうなるのか?
結果はかなりおかしくなります。vargrantを使ったスペック弱な仮想環境ではありますが、ものすごく反応が遅くなります。
また、既存nginxのport番号80のサービスが上書きされてGitLabになってしまいます。
この記事では、GitLabを既存nginxを使わせるインストール方法を説明します。

サーバー状態

php7とnginxはすでにインストールされています。
http://qiita.com/inakadegaebal/items/b57cf10339978d638305
http://qiita.com/inakadegaebal/items/d59fa99d2ee66a4ffe98
sulinuxはoffにしてください。

あれこれインストール&登録

基本的には公式サイトのインストール方法を使用しています。公式のインストールをお読みの上、以下を適切に実施してください。
https://about.gitlab.com/downloads/#centos7
公式サイトではsudo使っていますが、結局rootユーザーを使うのと同じなのでここではrootユーザーで操作しています。

# yum install curl policycoreutils openssh-server openssh-clients policycoreutils-python

追加要素
「policycoreutils-python」は公式サイトには載ってないですが、後述する「gitlab-ctl reconfigure」コマンド処理で以下のエラーが出るのを解決のためいれています。

Error executing action `run` on resource 'execute[semodule -i /opt/gitlab/embedded/selinux/rhel/7/gitlab-7.2.0-ssh-keygen.pp]'

続けてインストール
firewallをそもそも使ってないとか、不要なコマンドもあるかもしれませんが、とりあえず実行で問題ないと思います。

# systemctl enable sshd
# systemctl start sshd
# yum install postfix
# systemctl enable postfix
# systemctl start postfix
# firewall-cmd --permanent --add-service=http
# systemctl reload firewalld
# curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
# yum install gitlab-ce

gitlab.rbの編集

①ポート変更(一つのサーバーであれもこれも動かせるため)
②gitlabはDefaultで同封のnginxを使うが、それをやめて既にインストール済みのnginxを使わせる
③それに合わせて、既存nginxを使用するユーザーを設定
④ip設定が必要らしい
詳細は原文を参照
https://docs.gitlab.com/omnibus/settings/nginx.html#using-a-non-bundled-web-server
最初はほとんどコメントアウトされているのでそれも解除する

# vi /etc/gitlab/gitlab.rb
----------
external_url 'http://localhost:8081'
nginx['enable'] = false
web_server['external_users'] = ['nginx']
gitlab_rails['trusted_proxies'] = ['192.168.123.109']
----------

reconfigure

gitlab.rb編集後は基本的に必要です。
その後はnginxユーザーにgitグループに追加します。
reconfigureを実行する前に必ずgitlab.rbの設定変更が必要です(nginx['enable'] = false)。そうしないと既存のnginxがかなりおかしくなります。

# gitlab-ctl reconfigure
# usermod -a -G git nginx
# chmod g+rx /home/git/

nginx.confの編集

詳細は下記
https://gitlab.com/gitlab-org/gitlab-recipes/tree/master/web-server
内容をみて、修正必要な部分は適切に修正してください。

# vi /etc/nginx/nginx.conf
----------
    ## GitLab 8.3+
    ##
    ## Lines starting with two hashes (##) are comments with information.
    ## Lines starting with one hash (#) are configuration parameters that can be uncommented.
    ##
    ##################################
    ##        CONTRIBUTING          ##
    ##################################
    ##
    ## If you change this file in a Merge Request, please also create
    ## a Merge Request on https://gitlab.com/gitlab-org/omnibus-gitlab/merge_requests
    ##
    ###################################
    ##         configuration         ##
    ###################################
    ##
    ## See installation.md#using-https for additional HTTPS configuration details.
    upstream gitlab-workhorse {
      server unix:/var/opt/gitlab/gitlab-workhorse/socket;
    }
    ## Normal HTTP host
    server {
      ## Either remove "default_server" from the listen line below,
      ## or delete the /etc/nginx/sites-enabled/default file. This will cause gitlab
      ## to be served if you visit any address that your server responds to, eg.
      ## the ip address of the server (http://x.x.x.x/)n 0.0.0.0:80 default_server;
      listen 0.0.0.0:8081 default_server;
      listen [::]:8081 default_server;
      server_name _;
      server_tokens off; ## Don't show the nginx version number, a security best practice
      root /opt/gitlab/embedded/service/gitlab-rails/public;
      ## See app/controllers/application_controller.rb for headers set
      ## Individual nginx logs for this GitLab vhost
      access_log  /var/log/nginx/gitlab_access.log;
      error_log   /var/log/nginx/gitlab_error.log;
      location / {
        client_max_body_size 0;
        gzip off;
        ## https://github.com/gitlabhq/gitlabhq/issues/694
        ## Some requests take more than 30 seconds.
        proxy_read_timeout      300;
        proxy_connect_timeout   300;
        proxy_redirect          off;
        proxy_http_version 1.1;
        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;
      }
    }
----------
# systemctl restart nginx
8
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
12