2013年4月30日火曜日

GitHub 5.0 on CentOS6 behind a proxy


前回ubuntuでGitLabを立てたんですが、CentOSにすることにしたので書きとめる。

元記事:how-to-install-gitlab-5-0-on-centos-6


動作環境:


Install Applications

とりあえずpathにproxyを設定
[root@centos ~]# export http_proxy=http://proxy.yourcompany.com:8080
[root@centos ~]# export https_proxy=http://proxy.yourcompany.com:8080

epel, remiのrepositoryを登録
[root@centos ~]# rpm -Uvh http://ftp.jaist.ac.jp/pub/Linux/Fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm
[root@centos ~]# rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

Development Toolsをinstall
[root@centos ~]# yum -y groupinstall "Development Tools"

その他のApplicationをinstall
[root@centos ~]# yum -y install libxslt-devel libyaml-devel libxml2-devel gdbm-devel libffi-devel zlib zlib-devel openssl-devel libyaml-devel readline readline-devel curl-devel openssl-devel pcre-devel git memcached-devel valgrind-devel mysql-devel ImageMagick-devel ImageMagick libicu libicu-devel libffi-devel make bzip2 autoconf automake libtool bison redis sudo

Start Redis

Redisのサービスを起動します。
[root@centos ~]# chkconfig --levels 35 redis on
[root@centos ~]# service redis start

Corkscrew

corkscrewをdownloadしてinstallします。
[root@centos ~]# mkdir temp
[root@centos ~]# cd temp
[root@centos temp]# wget "http://www.agroman.net/corkscrew/corkscrew-2.0.tar.gz"
[root@centos temp]# tar zxvf corkscrew-2.0.tar.gz
[root@centos temp]# cd corkscrew-2.0
[root@centos corkscrew-2.0]# ./configure
[root@centos corkscrew-2.0]# make
[root@centos corkscrew-2.0]# make install

git用のproxy scriptを作成します。
[root@centos corkscrew-2.0]# vi /usr/local/bin/git-proxy.sh
# -----
#/bin/bash
CORKSCREW=`which corkscrew`
$CORKSCREW proxy.yourcompany.com 8080 $1 $2
# -----
[root@centos corkscrew-2.0]# chmod 755 /usr/local/bin/git-proxy.sh
[root@gitlab corkscrew-2.0]# cd ~

User

最終的にApatchで動作させることから、homeディレクトリにgitlabをinstallすると、なにかと都合が悪いことので、/data/appsにinstallします。
[root@centos ~]# mkdir /data
[root@centos ~]# mkdir /data/apps
[root@centos ~]# adduser git --home-dir=/data/apps/git
[root@centos ~]# passwd git

gitにloginして、SSH鍵を生成します。
[root@centos ~]# su - git
[git@centos ~]$ mkdir -p /data/apps/git/.ssh
[git@centos ~]$ chmod -R 700 /data/apps/git/.ssh
[git@centos ~]$ echo "" > /data/apps/git/.ssh/authorized_keys
[git@centos ~]$ chmod -R 600 /data/apps/git/.ssh/authorized_keys
[git@centos ~]$ ssh-keygen -q -b 4096 -N '' -t rsa -f /data/apps/git/.ssh/id_rsa
[git@centos ~]$ cat /data/apps/git/.ssh/id_rsa.pub >> /data/apps/git/.ssh/authorized_keys

Ruby

ruby-1.9.3-p392をinstallします。checkinstallなしで、ゴリゴリinstall。
[git@centos ~]$ mkdir temp
[git@centos ~]$ mkdir ruby
[git@centos ~]$ cd temp
[git@centos temp]$ wget -c "http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p392.tar.gz"
[git@centos temp]$ tar -xf ruby-1.9.3-p392.tar.gz
[git@centos temp]$ cd ruby-1.9.3-p392
[git@centos ruby-1.9.3-p392]$ ./configure --prefix=/data/apps/git/ruby
[git@centos ruby-1.9.3-p392]$ make
[git@centos ruby-1.9.3-p392]$ make install

rubyのpathをbashrcに設定します。
あわせてgitコマンドをproxy経由にするよう設定します。
[git@centos ruby-1.9.3-p392]$ cd ~
[git@centos ~]$ vi .bashrc
# -----
PATH=$HOME/ruby/bin:$PATH:$HOME/bin
export HTTP_PROXY=http://proxy.yourcompany.com:8080/
export HTTPS_PROXY=http://proxy.yourcompany.com:8080/
export GIT_PROXY_COMMAND=/usr/local/bin/git-proxy.sh
# -----
[git@centos ~]$ source .bashrc

Rubyのpathが正しく設定されているか確認。
[git@gitlab ~]$ which ruby
~/ruby/bin/ruby
[git@gitlab ~]$ ruby --version
ruby 1.9.3p392 (2013-02-22 revision 39386) [x86_64-linux]

gemのproxyを設定します。
[git@gitlab ~]$ vi ~/.gemrc
# -----
http_proxy: http://proxy.yourcompany.com:8080
# -----

bundlerをinstall
[git@gitlab ~]$ gem install bundler

Gitlab-Shell

Gitlab-Shellをinstallします。checkout v1.1.0にします。
[git@centos ~]$ mkdir gitlab-shell
[git@centos ~]$ git clone https://github.com/gitlabhq/gitlab-shell.git gitlab-shell/
[git@centos ~]$ cd gitlab-shell
[git@centos gitlab-shell]$ git checkout v1.1.0
[git@centos gitlab-shell]$ git checkout -b v1.1.0
[git@centos gitlab-shell]$ cp config.yml.example config.yml

config.ymlの設定を変更する。
[git@centos gitlab-shell]$ vi config.yml
# -----
# GitLab user. git by default
user: git

# Url to gitlab instance. Used for api calls
gitlab_url: "http://git.yourdomain.com/"

# Repositories path
repos_path: "/data/apps/git/repositories"

# File used as authorized_keys for gitlab user
auth_file: "/data/apps/git/.ssh/authorized_keys"
# -----

で、install。
[git@centos gitlab-shell]$ ./bin/install
mkdir -p /data/apps/git/repositories: true
mkdir -p /data/apps/git/.ssh: true
touch /data/apps/git/.ssh/authorized_keys: true
chmod -R ug+rwX,o-rwx /data/apps/git/repositories: true
find /data/apps/git/repositories -type d -print0 | xargs -0 chmod g+s: true
[git@gitlab gitlab-shell]$ exit

MySQL

MySQLをinstallしてService起動。
[root@centos ~]# yum install -y mysql-server mysql-devel
[root@centos ~]# chkconfig --levels 35 mysqld on
[root@centos ~]# service mysqld start

Databaseの設定を行う。
[root@centos ~]# mysql
mysql> CREATE USER 'gitlab'@'localhost' IDENTIFIED BY 'gitlab';
mysql> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'gitlab'@'localhost';
mysql> \q

GitLab

gitlabをinstall
[root@centos ~]# su - git
[git@centos ~]$ mkdir gitlab
[git@centos ~]$ git clone https://github.com/gitlabhq/gitlabhq.git gitlab
[git@centos ~]$ cd gitlab
[git@centos gitlab]$ git checkout 5-0-stable
[git@centos gitlab]$ cp config/gitlab.yml.example config/gitlab.yml

gitlab.ymlのrepos_path, auth_fileを修正。
[git@centos ~]$ vi config/gitlab.yml
# -------- Make the following edits --------
  ## GitLab settings
  gitlab:
    ## Web server settings
    host: git.yourdomain.com

  # GitLab Satellites
  satellites:
    # Relative paths are relative to Rails.root (default: tmp/repo_satellites/)
    path: /data/apps/git/gitlab-satellites/

  ## GitLab Shell settings
  gitlab_shell:
    # REPOS_PATH MUST NOT BE A SYMLINK!!!
    repos_path: /data/apps/git/repositories/
    hooks_path: /data/apps/git/gitlab-shell/hooks/

# -------- Save and close the file --------

permission変更、gitlab-satellitesのフォルダ生成等、細かいことをする。
[git@centos gitlab]$ chown -R git log/
[git@centos gitlab]$ chown -R git tmp/
[git@centos gitlab]$ chmod -R u+rwX log/
[git@centos gitlab]$ chmod -R u+rwX tmp/
[git@centos gitlab]$ mkdir /data/apps/git/gitlab-satellites/
[git@centos gitlab]$ mkdir tmp/pids/
[git@centos gitlab]$ chmod -R u+rwX tmp/pids/

unicornの設定を変更する。
[git@centos gitlab]$ cp config/unicorn.rb.example config/unicorn.rb
[git@centos gitlab]$ vi config/unicorn.rb
# -------- Make the following edits --------
#listen "#{app_dir}/tmp/sockets/gitlab.socket"
listen "127.0.0.1:65527"  
# -------- Save and close the file --------

database.ymlをいじる。
[git@centos gitlab]$ cp config/database.yml.mysql config/database.yml
[git@centos gitlab]$ vi config/database.yml
# -------- Make the following edits --------
production:
  database: gitlabhq_production
  username: gitlab
  password: **********
  host: localhost
  # socket: /tmp/mysql.sock
# -------- Save and close the file --------

charlocks_holmesをinstall
[git@centos gitlab]$ gem install charlock_holmes --version '0.6.9'

gitlabをinstall and setup..
[git@centos gitlab]$ bundle install --deployment --without development test postgres
[git@centos gitlab]$ bundle exec rake gitlab:setup RAILS_ENV=production
[git@centos gitlab]$ exit

Init Script

init scriptをdownloadします。
[root@centos ~]# curl --proxy http://proxy.yourcompany.com:8080 --output /etc/init.d/gitlab https://raw.github.com/gitlabhq/gitlab-recipes/5-0-stable/init.d/gitlab
[root@centos ~]# chmod +x /etc/init.d/gitlab

init scriptのAPP_ROOTを変更します
[root@centos ~]# vi /etc/init.d/gitlab
# -------- Make the following edits --------
APP_ROOT="/data/apps/git/gitlab"
# -------- Save and close the file --------

GitLabをServiceで起動します。
[root@centos ~]# /etc/init.d/gitlab start
[root@centos ~]# chkconfig --add gitlab
[root@centos ~]# chkconfig --levels 35 gitlab on

GitLabのインストール状況を確認します。
まずは gitユーザにswitch
[root@centos ~]# su - git
[git@centos ~]$ cd gitlab

checkでerrorが出ないようにあらかじめgit configを設定。
[git@centos gitlab]$ git config --global user.name "GitLab"
[git@centos gitlab]$ git config --global user.email "gitlab@localhost"

checkを実行
[git@centos gitlab]$ bundle exec rake gitlab:check RAILS_ENV=production

Errorが出なければここまで成功なんですが、init scriptでErrorが出てます。。。
Errorを無視します。
Init script up-to-date? ... no
  Try fixing it:
  Redownload the init script
  For more information see:
  doc/install/installation.md in section "Install Init Script"
  Please fix the error above and rerun the checks.

80と65527(確認用)のポートを開ける。
[root@centos ~]# vi /etc/sysconfig/iptables
# -------- Make the following edits --------
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 65527 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
# -------- Save and close the file --------
[root@centos ~]# /etc/init.d/iptables restart
ブラウザで直接65527ポートをのぞいて動作確認する。

上記の画面が表示されたら、65527のポートを閉めちゃいます。


Apatch

httpdをinstall
[root@centos ~]# yum -y install httpd 

VirtualHostとして動かすよう設定する
[root@centos ~]# vi /etc/httpd/conf/httpd.conf
# -------- Make the following edits --------
<Virtualhost *:80>
        ServerName git.yourdomain.com
        DocumentRoot /data/apps/git/gitlab/public
        CustomLog logs/git.yourdomain.com combined
        ErrorLog logs/git.yourdomain.com-error.log
        ProxyPass /  http://127.0.0.1:65527/
        ProxyPassReverse /  http://127.0.0.1:65527/
        ProxyPreserveHost On
</Virtualhost>
# -------- Save and close the file --------

「Permission denied: proxy: HTTP: attempt to connect to 127.0.0.1:65527 (localhost) failed」ってErrorが出ないように、以下を設定する。
[root@centos ~]# /usr/sbin/setsebool httpd_can_network_connect true

ApatchをService起動
[root@centos ~]# chkconfig --levels 35 httpd on
[root@centos ~]# service httpd start

Reference

  • how-to-install-gitlab-5-0-on-centos-6
  • 0 件のコメント: