GitLab 5.0 を CentOS 6.4 にインストールする
Ubuntuの手順そのままだと上手く行かない部分や省かれている箇所があったので、CentOS6用に書き直したみた。
毎回 sudo と打つのがめんどくさいので、プロンプトが#
のときはroot
、$
のときはgit
ユーザになってコマンドを実行してます。
参考元:
https://github.com/gitlabhq/gitlabhq/blob/5-0-stable/doc/install/installation.md https://github.com/gitlabhq/gitlab-recipes/blob/master/install/CentOS_6.md
1. Packages / Dependencies
主にRubyのため。epel
リポジトリはRedis
入れるのにも必要。
# rpm -ivh http://ftp-srv2.kddilabs.jp/Linux/distributions/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm # yum groupinstall "development tools" # yum install zlib-devel openssl-devel gdbm-devel readline-devel ncurses-devel libffi-devel libxml2-devel libxslt-devel libcurl-devel libicu-devel libyaml-devel
2. Ruby
# mkdir /tmp/ruby && cd /tmp/ruby # curl --progress http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p327.tar.gz | tar xz # cd ruby-1.9.3-p392 # ./configure # make && make install # gem install bundler # gem install charlock_holmes --version '0.6.9'
3. System Users
# useradd -c 'GitLab' -s /bin/bash git
Web画面から登録する各ユーザの鍵はgit
ユーザのauthorized_keys
に書き込まれるので、あらかじめ作成しておく必要がある。
# su - git $ cd /home/git $ mkdir .ssh $ touch .ssh/authorized_keys $ chmod 600 .ssh/authorized_keys $ chmod 700 .ssh
gitの設定もしておく
$ git config --global user.name "GitLab" $ git config --global user.email "gitlab@git.example.jp"
4. GitLab shell
$ cd /home/git $ git clone https://github.com/gitlabhq/gitlab-shell.git $ cd gitlab-shell/ $ git checkout v1.1.0 $ git checkout -b v1.1.0 $ cp config.yml.example config.yml $ vi config.yml $ diff config.yml{.example,} 5c5 < gitlab_url: "http://localhost/" --- > gitlab_url: "http://git.example.jp/" $ ./bin/install
5. Database
# rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm # yum --enablerepo=remi install mysql mysql-server mysql-devel mysql-libs
my.cnfはお好みで。個人的にはbind-address
だけは変えておきたい。
# vi /etc/my.cnf [mysqld] bind-address = 127.0.0.1
# /etc/init.d/mysqld start # chkconfig mysqld on
Gitlab用のDBを作成
# mysql >CREATE USER 'gitlab'@'localhost' IDENTIFIED BY 'パスワード'; >CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`; >GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'gitlab'@'localhost'; >\q
接続出来ることを確認しておく
# mysql -u gitlab -p -D gitlabhq_production
5.5 Redis (なぜか忘れられてる)
# yum install redis # /etc/init.d/redis start # chkconfig redis on
6. Gitlab
# su - git $ cd /home/git
Clone the Source
$ git clone https://github.com/gitlabhq/gitlabhq.git gitlab $ cd gitlab $ git checkout 5-0-stable
Configure it
$ cp config/gitlab.yml.example config/gitlab.yml $ vi config/gitlab.yml $ diff config/gitlab.yml{.example,} 18c18 < host: localhost --- > host: git.example.jp 30c30 < email_from: gitlab@localhost --- > email_from: gitlab@git.example.jp
もろもろ必要なディレクトリを作成
$ chown -R git log/ $ chown -R git tmp/ $ chmod -R u+rwX log/ $ chmod -R u+rwX tmp/ $ mkdir /home/git/gitlab-satellites $ mkdir tmp/pids/ $ chmod -R u+rwX tmp/pids/ $ cp config/unicorn.rb.example config/unicorn.rb
Configure GitLab DB settings
$ cp config/database.yml.mysql config/database.yml $ vi config/database.yml $ diff config/database.yml{.mysql,} 10,11c10,11 < username: root < password: "secure password" --- > username: gitlab > password: "MySQLのパスワード" 24,25c24,25 < username: root < password: "secure password" --- > username: gitlab > password: "MySQLのパスワード" 37,38c37,38 < username: root < password: --- > username: gitlab > password: "MySQLのパスワード"
Install Gems
$ cd /home/git/gitlab $ bundle install --deployment --without development test postgres
Initialize Database and Activate Advance Features
$ bundle exec rake gitlab:setup RAILS_ENV=production
Check Application Status
$ bundle exec rake gitlab:env:info RAILS_ENV=production $ bundle exec rake gitlab:check RAILS_ENV=production
Sidekiq
が起動していないと出るけど起動スクリプトから起動するので問題ない。
Install Init Script
rootに戻って
# curl --output /etc/init.d/gitlab https://raw.github.com/gitlabhq/gitlab-recipes/master/init.d/gitlab-centos # chmod +x /etc/init.d/gitlab # vi /etc/init.d/gitlab < NAME=git --- > NAME=gitlab # chkconfig gitlab on
Start Your GitLab Instance
# /etc/init.d/gitlab start
7. Nginx
# rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm # yum install nginx # chkconfig nginx on
Site Configuration
# curl --output /etc/nginx/conf.d/gitlab.conf https://raw.github.com/gitlabhq/gitlab-recipes/master/nginx/gitlab # vi /etc/nginx/conf.d/gitlab.conf
listenするIPとserver_nameを変えるくらい
upstream gitlab { server unix:/home/git/gitlab/tmp/sockets/gitlab.socket; } server { listen <IPアドレス>:80 default_server; server_name git.example.jp; root /home/git/gitlab/public; # individual nginx logs for this gitlab vhost access_log /var/log/nginx/gitlab_access.log; error_log /var/log/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; } # if a file, which is not found in the root folder is requested, # then the proxy pass the request to the upsteam (gitlab unicorn) location @gitlab { proxy_read_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694 proxy_connect_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694 proxy_redirect off; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_pass http://gitlab; } }
# /etc/init.d/nginx configtest
/home/git
のパーミッションを変え忘れると502
になるので忘れずに。
# chmod 755 /home/git
Start
# /etc/init.d/nginx start
おしまい。 Gitoliteがいらなくなって、はまりポイントは減った気がする。