CentOS6.2(gitlab2.1+redmine1.3)(rvm+passenger+nginx) Vol.1
CentOS6.2に、gitlabとredmineを同居させる方法を紹介します。
gitlabとredmineでは要求するrubyの環境が違うのでpassenger管理の下同じサーバで稼動させるには少々工夫が要ります。
インストールするサーバはコレ(lsb_release -a)
LSB Version: :core-4.0-ia32:core-4.0-noarch:graphics-4.0-ia32:graphics-4.0-noarch:printing-4.0-ia32:printing-4.0-noarch
Distributor ID: CentOS
Description: CentOS release 6.2 (Final)
Release: 6.2
Codename: Final
結構やることが多いので、今回はgitlab2.1をnginxのpassengerで動かすとこまでです。
UBUNTUだったらコレの通りにやればさくっと入るんだけどねぇ。
UBUNTU素晴らしいなぁ。
CentOSでもこの通りにやればさくっとカジュアルにgitlab環境出来ちゃうと思います。
■依存パッケージなどのインストールと、関連ユーザ作成
必要なパッケージをまとめてインストールします。
[root@ssserver ~]# yum install -y make openssh-clients gcc libxml2 libxml2-devel libxslt libxslt-devel python-devel wget readline-devel ncurses-devel gdbm-devel glibc-devel tcl-devel openssl-devel db4-devel byacc httpd gcc-c++ curl-devel openssl-devel zlib-devel httpd-devel apr-devel apr-util-devel sqlite-devel libicu-devel pcre-devel git-core python-setuptools python-devel libicu-devel python-setuptools python-devel libicu-devel
redisの最新版を入れます。
KVSを上手に使ってみたい。(個人的に)
[root@ssserver ~]# cd /usr/local/src/ [root@ssserver src]# wget http://redis.googlecode.com/files/redis-2.4.6.tar.gz [root@ssserver src]# tar zxvf redis-2.4.6.tar.gz [root@ssserver src]# cd redis-2.4.6 [root@ssserver redis-2.4.6]# make && make install
gitlabを動かすためのgitlabhqユーザ、gitoliteを制御するためのgitユーザを作成します。
UIDはなんでもいいです指定しなくてもおk。
ここで重要なのは、gitグループにgitlabhqユーザを参加させること。
これをちゃんとやっとかないと、gitlabでリポジトリを参照出来なかったりしちゃうのです。
[root@ssserver ~]# useradd -u 4001 gitlabhq [root@ssserver ~]# useradd -u 4002 git [root@ssserver ~]# usermod -a -G git gitlabhq [root@ssserver ~]# passwd gitlabhq
■gitolite環境の構築
gitlabからgitoliteを利用するための工程。
gitlabhqにsuして、パスフレーズなしのRSA鍵を作成。
[root@ssserver ~]# su - gitlabhq [gitlabhq@ssserver ~]$ ssh-keygen -t rsa
localhostを、/home/gitlabhq/.ssh/known_hostsに登録しておきます。
yes応答するところまでやっておけばおk。
[gitlabhq@ssserver ~]$ ssh git@localhost The authenticity of host 'localhost (::1)' can't be established. RSA key fingerprint is f0:8c:11:b7:4f:7c:84:86:9c:e9:07:3c:68:27:70:7e. Are you sure you want to continue connecting (yes/no)? yes
rootに戻って、作った鍵をgitユーザのhomeにrails.pubとして設置。
[gitlabhq@ssserver ~]$ logout [root@ssserver ~]# cp -a /home/gitlabhq/.ssh/id_rsa.pub /home/git/rails.pub
gitユーザにsuして、gitoliteを取得します。
gitoliteは、リポジトリの管理や鍵管理を一元的に管理してくれます。
[root@ssserver ~]# su - git [git@ssserver ~]$ git clone git://github.com/gitlabhq/gitolite /home/git/gitolite
gitoliteインストール。
[git@ssserver ~]$ /home/git/gitolite/src/gl-system-install using default values for EUID=4002: /home/git/bin /home/git/share/gitolite/conf /home/git/share/gitolite/hooks [git@ssserver ~]$ sh -c "PATH=/home/git/bin:$PATH; gl-setup ~/rails.pub"
途中、enter応答を促されるので指示通りにすると、設定ファイルの編集画面になります。
以下のように変更します。
$REPO_UMASK = 0077; ↓ $REPO_UMASK = 0007;
再びrootに戻って、パーミッションを適切に設定します。
これも重要な工程で、適切なパーミッションが設定されていないと、gitlabでリポジトリを参照できなかったり、新しいリポジトリを作成出来なくなります。
[git@ssserver ~]$ logout [root@ssserver ~]# chmod 750 /home/git/ [root@ssserver ~]# chmod -R g+rwX /home/git/repositories/ [root@ssserver ~]# chown -R git:git /home/git/repositories/
■gitlabインストール
gitlabでコードを表示したときにシンタックスハイライトさせるために必要なpygmentsのインストール。
[root@ssserver ~]# easy_install pygments
gitlabhqユーザにsuして、RVMをインストール。
専用ユーザでRVMを入れることによって、$HOME/.rvm以下に専用ruby環境を作ることが出来ます。
[root@ssserver ~]# su - gitlabhq [gitlabhq@ssserver ~]$ bash < <(curl -s -B https://rvm.beginrescueend.com/install/rvm )
続いてRVMでruby1.9.2をインストール。
1.9.2をgitlabhqユーザのデフォルトとし、railsなどを入れる。
[gitlabhq@ssserver ~]$ rvm install 1.9.2 [gitlabhq@ssserver ~]$ rvm 1.9.2 --default [gitlabhq@ssserver ~]$ gem install rails passenger rake bundler grit
gitlab本体のセットアップ。
[gitlabhq@ssserver ~]$ git clone git://github.com/gitlabhq/gitlabhq.git [gitlabhq@ssserver ~]$ cd gitlabhq [gitlabhq@ssserver gitlabhq]$ bundle install --without development test [gitlabhq@ssserver gitlabhq]$ bundle exec rake db:setup RAILS_ENV=production [gitlabhq@ssserver gitlabhq]$ bundle exec rake db:seed_fu RAILS_ENV=production
gitlab.ymlを編集。
hostのところを、環境に合わせて設定します。
[gitlabhq@ssserver gitlabhq]$ vim config/gitlab.yml git_host: system: gitolite admin_uri: git@localhost:gitolite-admin base_path: /home/git/repositories/ host: gitlab git_user: git # port: 22 ↓ git_host: system: gitolite admin_uri: git@localhost:gitolite-admin base_path: /home/git/repositories/ host: gitlab.ssserver.com git_user: git # port: 22
gitlab本体のインストール。
最後に、管理ユーザのログイン情報が表示されるので控えておきます。
[gitlabhq@ssserver gitlabhq]$ bundle exec rails s -e production Login Email: admin@local.host Login Password: 5iveL!fe
ここまでで、gitlabをスタンドアロンで起動させることが出来るようになりました。
ブラウザから、http://サーバIPアドレス:3000にアクセスしてみて、ログインしてみましょう。
[gitlabhq@ssserver gitlabhq]$ rails s -e production => Booting WEBrick => Rails 3.1.1 application starting in production on http://0.0.0.0:3000 => Call with -d to detach => Ctrl-C to shutdown server :public is no longer used to avoid overloading Module#public, use :public_folder instead from /home/gitlabhq/.rvm/gems/ruby-1.9.2-p290/gems/resque-1.19.0/lib/resque/server.rb:12:in `<class:Server>' [20xx-xx-xx 17:47:11] INFO WEBrick 1.3.1 [20xx-xx-xx 17:47:11] INFO ruby 1.9.2 (2011-07-09) [i386-linux] [20xx-xx-xx 17:47:11] INFO WEBrick::HTTPServer#start: pid=4253 port=3000
■nginx+passengerで起動するようにする
スタンドアロンでの起動に成功したら、次はnginxのpassenger管理下で起動するようにします。
先ずは、一時的にgitlabhqユーザがsudoを使えるようにします。
[root@ssserver ~]# usermod -a -G wheel gitlabhq [root@ssserver ~]# visudo ## Allows people in group wheel to run all commands # %wheel ALL=(ALL) ALL ↓ ## Allows people in group wheel to run all commands %wheel ALL=(ALL) ALL
gitlabhqユーザで、nginx+pssengerの専用環境を設定します。
[root@ssserver ~]# su - gitlabhq [gitlabhq@ssserver ~]$ rvmsudo passenger-install-nginx-module (中略) Press Enter to continue, or Ctrl-C to abort. (中略) 。。。依存チェック
新たにnginxをインストールするか、インストール済のnginxでpassenger環境を構築するか選びます。
今回は新たにインストールしますので、1で応答します。
※既にnginxを使っている場合でも1を選択してください。
Automatically download and install Nginx? Nginx doesn't support loadable modules such as some other web servers do, so in order to install Nginx with Passenger support, it must be recompiled. Do you want this installer to download, compile and install Nginx for you? 1. Yes: download, compile and install Nginx for me. (recommended) The easiest way to get started. A stock Nginx 1.0.10 with Passenger support, but with no other additional third party modules, will be installed for you to a directory of your choice. 2. No: I want to customize my Nginx installation. (for advanced users) Choose this if you want to compile Nginx with more third party modules besides Passenger, or if you need to pass additional options to Nginx's 'configure' script. This installer will 1) ask you for the location of the Nginx source code, 2) run the 'configure' script according to your instructions, and 3) run 'make install'. Whichever you choose, if you already have an existing Nginx configuration file, then it will be preserved. Enter your choice (1 or 2) or press Ctrl-C to abort: 1 (中略)
prefixを指定します。
今回は /opt/gitlabhq_2.1.0pre としました。
Where do you want to install Nginx to? Please specify a prefix directory [/opt/nginx]: /opt/gitlabhq_2.1.0pre (中略) 。。。コンパイル、インストール
nginxのインストールが完了したら、rootに戻りgitlabhqユーザをsudoersから外します。
[gitlabhq@ssserver ~]$ logout [root@ssserver ~]# gpasswd -d gitlabhq wheel Removing user gitlabhq from group wheel
バージョンアップに柔軟に対応出来るように、以下のようにシンボリックリンクを作成します。
[root@ssserver ~]# ln -s /opt/gitlabhq_2.1.0.pre /opt/gitlabhq
起動スクリプトを作成します。
[root@ssserver ~]# vim /etc/init.d/gitlabhq #!/bin/sh # # nginx Startup script for nginx # # chkconfig: - 85 15 # processname: gitlabhq # config: /opt/gitlabhq/conf/nginx.conf # config: /etc/sysconfig/gitlabhq # pidfile: /var/run/gitlabhq.pid # description: nginx is a HTTP and reverse proxy server # ### BEGIN INIT INFO # Provides: gitlabhq # Required-Start: $local_fs $remote_fs $network # Required-Stop: $local_fs $remote_fs $network # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: start and stop gitlabhq ### END INIT INFO # Source function library. . /etc/rc.d/init.d/functions CONFFILE="/opt/gitlabhq/conf/nginx.conf" if [ -f /etc/sysconfig/gitlabhq ]; then . /etc/sysconfig/gitlabhq fi prog=gitlabhq nginx=${NGINX-/opt/gitlabhq/sbin/nginx} conffile=${CONFFILE-/opt/gitlabhq/conf/nginx.conf} lockfile=${LOCKFILE-/var/lock/subsys/gitlabhq} pidfile=${PIDFILE-/var/run/gitlabhq.pid} SLEEPMSEC=100000 RETVAL=0 start() { echo -n $"Starting $prog: " daemon --pidfile=${pidfile} ${nginx} -c ${conffile} RETVAL=$? echo [ $RETVAL = 0 ] && touch ${lockfile} return $RETVAL } stop() { echo -n $"Stopping $prog: " killproc -p ${pidfile} ${prog} RETVAL=$? echo [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile} } reload() { echo -n $"Reloading $prog: " killproc -p ${pidfile} ${prog} -HUP RETVAL=$? echo } upgrade() { oldbinpidfile=${pidfile}.oldbin configtest -q || return 6 echo -n $"Staring new master $prog: " killproc -p ${pidfile} ${prog} -USR2 RETVAL=$? echo /bin/usleep $SLEEPMSEC if [ -f ${oldbinpidfile} -a -f ${pidfile} ]; then echo -n $"Graceful shutdown of old $prog: " killproc -p ${oldbinpidfile} ${prog} -QUIT RETVAL=$? echo else echo $"Upgrade failed!" return 1 fi } configtest() { if [ "$#" -ne 0 ] ; then case "$1" in -q) FLAG=$1 ;; *) ;; esac shift fi ${nginx} -t -c ${conffile} $FLAG RETVAL=$? return $RETVAL } rh_status() { status -p ${pidfile} ${nginx} } # See how we were called. case "$1" in start) rh_status >/dev/null 2>&1 && exit 0 start ;; stop) stop ;; status) rh_status RETVAL=$? ;; restart) configtest -q || exit $RETVAL stop start ;; upgrade) upgrade ;; condrestart|try-restart) if rh_status >/dev/null 2>&1; then stop start fi ;; force-reload|reload) reload ;; configtest) configtest ;; *) echo $"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|upgrade|reload|status|help|configtest}" RETVAL=2 esac exit $RETVAL
[root@ssserver ~]# chmod +x /etc/init.d/gitlabhq [root@ssserver ~]# chkconfig gitlabhq on [root@ssserver ~]# chkconfig --list gitlabhq gitlabhq 0:off 1:off 2:on 3:on 4:on 5:on 6:off
gitlab設定ファイルを編集します。
[root@ssserver ~]# vim /opt/gitlabhq/conf/nginx.conf
実行ユーザをgitlabhqユーザに変更。
#user nobody;
↓
user gitlabhq;
エラーログを出力しないようにします。
#error_log logs/error.log;
↓
error_log /dev/null;
pidファイルの場所を指定します。
起動スクリプトで指定したパスと同じにしておかないと、起動スクリプトでstopできなくなるので注意です。
#pid logs/nginx.pid;
↓
pid /var/run/gitlabhq.pid;
待受ポートを40192(任意)に、アクセスログを出力しない、Location / の設定を変更します。
server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.htm; } ↓ server { listen 40192; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; access_log off; location / { root /home/gitlabhq/gitlabhq/public; index index.html index.htm; passenger_enabled on; }
■起動、起動後
起動してみましょう。
[root@ssserver ~]# /etc/init.d/gitlabhq start gitlabhq を起動中: [ OK ]
ps、netstatを確認してみます。
マスタプロセス、ワーカプロセスが起動していて、confで指定したポートでListenしていることが確認できたはずです。
[root@ssserver ~]# ps -ef | grep gitlabhq root 11093 1 0 23:41 ? 00:00:00 nginx: master process /opt/gitlabhq/sbin/nginx -c /opt/gitlabhq/conf/nginx.conf gitlabhq 11094 11093 0 23:41 ? 00:00:00 nginx: worker process root 11101 9066 0 23:41 pts/0 00:00:00 grep gitlabhq [root@ssserver ~]# netstat -tanp | grep 40192 tcp 0 0 0.0.0.0:40192 0.0.0.0:* LISTEN 11093/nginx
あとは、このまま http://サーバIPアドレス:40192 で使うもよし。
apacheや別のnginxなどからリバースプロキシするもよし。
※今回はpassengerではLOGを吐かない設定にしているので、リバースプロキシ側でLOGを吐くようにしたほうがいいかもです。
※そのまま使うなら、passengerでLOGを吐くようにしましょう。
です。
次回は同じ要領でredmine1.3をCentOS6.2に入れる方法を紹介します。