以下を参考に進める予定
最近だとRPMパッケージが提供されているのでそっちを使った方が楽らしい(CentOS6以上)
- Git(v2.0.1)
- Ruby(v2.1.2p95)
- Redis(v2.8.12)
- Mysql(v5.0.95)
- Apache(v2.2.3)
- GitLab(v7.0.0)
以降の作業は基本的にroot権限で作業する。
GitLabに必要なものを予め入れておく
# パッケージの更新
yum update -y
# 依存ライブラリのインストール
yum -y install openssl-devel curl-devel httpd-devel gcc-c++ zlib-devel gdbm-devel readline-devel ncurses-devel libffi-devel libxml2-devel libxslt-devel libcurl-devel libyaml-devel logrotate expect
古いgitが入っている場合は削除しておく
# gitが入っているか確認
which git
# /usr/bin/git
# バージョンを確認
/usr/bin/git --version
# git version 1.7.12.4
# 削除する
yum -y remove git
改めてソースからインストールする
cd /usr/local/src
wget https://github.com/git/git/archive/v2.0.1.zip
unzip v2.0.1
cd git-2.0.1/
make configure
./configure
make
make prefix=/usr/local install
正常にインストールされたか確認
# コマンド確認
which git
# /usr/local/bin/git
# バージョン確認
git --version
# git version 2.0.1
古いRubyが入っているか確認
# バージョン確認
ruby --version
# ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
# rvmで入っていたので今回は削除
rvm seppuku
改めてソースからインストール
cd /usr/local/src
wget http://cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.2.tar.gz
tar zxf ruby-2.1.2.tar.gz
cd ruby-2.1.2
./configure --disable-install-rdoc
make
make install
正常にインストールされたか確認
ruby --version
# ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]
Bundlerをインストールしておく
gem install bundler --no-ri --no-rdoc
adduser -r --shell /bin/bash --comment "GitLab" --create-home --home-dir /home/git git
cd /usr/local/src
wget http://download.redis.io/releases/redis-2.8.12.tar.gz
tar xzf redis-2.8.12.tar.gz
cd redis-2.8.12
make
make install
# 対話式シェルでセットアップ
cd utils
sh install_server.sh
まずはyumでインストールして起動設定を行う
# インストール
yum -y install mysql-server mysql mysql-devel mysql-libs
# 起動設定
chkconfig mysqld on
service mysqld start
インストール確認
mysql --version
# mysql Ver 14.12 Distrib 5.0.95, for redhat-linux-gnu (x86_64) using readline 5.1
DBの初期設定と、GitLab用のDB作成を行う。
mysql_secure_installation
mysql -u root
$ CREATE USER 'git'@'localhost' IDENTIFIED BY 'git1234';
$ SET storage_engine=INNODB;
$ CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
$ GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'git'@'localhost';
$ \q
sudo -u git -H mysql -u git -pgit1234 -D gitlabhq_production
$ \q
GitLabに必要だがCentOS5に標準で入ってるバージョンだと古くて使えないので、 ソースから最新のものを入れ直す
# 既存のものを削除
yum -y remove libicu*
# 手動でソースから入れる
cd /usr/local/src
wget http://download.icu-project.org/files/icu4c/53.1/icu4c-53_1-src.tgz
tar zxf icu4c-53_1-src.tgz
cd icu/source
./configure
make
make install
以下を実行してインストールする
cd /home/git
sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 7-0-stable gitlab
必要な初期設定を行う
cd /home/git/gitlab
# gitlabの設定(**適切なホスト名を設定しておく**)
# gitのパスが/usr/bin/gitになってるので/usr/local/binに直しておく
sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml
sudo -u git -H vi config/gitlab.yml
# 利用されるディレクトリに適切なパーミッションを設定
sudo chown -R git log/
sudo chown -R git tmp/
sudo chmod -R u+rwX log/
sudo chmod -R u+rwX tmp/
sudo -u git -H mkdir /home/git/gitlab-satellites
sudo chmod u+rwx,g=rx,o-rwx /home/git/gitlab-satellites
sudo chmod -R u+rwX tmp/pids/
sudo chmod -R u+rwX tmp/sockets/
sudo chmod -R u+rwX public/uploads
# unicornの設定
sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb
sudo -u git -H vi config/unicorn.rb
sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb
# gitの設定
sudo -u git -H git config --global user.name "GitLab"
sudo -u git -H git config --global user.email "example@example.com"
sudo -u git -H git config --global core.autocrlf input
# DBの設定(**接続先の設定をしておく**)
sudo -u git cp config/database.yml.mysql config/database.yml
sudo -u git -H vi config/database.yml
sudo -u git -H chmod o-rwx config/database.yml
# 必要な依存ライブラリのインストール
sudo -u git -H bundle install --deployment --without development test postgres aws
# GitLab-Shellをインストール
sudo -E -u git -H bundle exec rake gitlab:shell:install[v1.9.6] REDIS_URL=redis://localhost:6379 RAILS_ENV=production
# GitLab-Shellの設定変更(**適切なURLを設定しておく**)
sudo -u git -H vi /home/git/gitlab-shell/config.yml
# DBへ初期データの流し込み
sudo -E -u git -H bundle exec rake gitlab:setup RAILS_ENV=production
# GitLabの起動スクリプト設置
sudo cp lib/support/init.d/gitlab /etc/init.d/gitlab
# 起動設定
chkconfig gitlab on
# ログローテートの設定
sudo cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab
# GitLabの情報を閲覧(ここで設定に問題ないか確認しておく)
sudo -E -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production
# GitLab起動
/etc/init.d/gitlab start
いつも通りyumで導入して起動設定
# インストール
yum -y install httpd
# 起動設定&起動
chkconfig httpd on
service httpd start
apacheユーザがGitLabにアクセスできるよう権限の変更を行う。
# apacheユーザをgitグループに追加
usermod -G git apache
# 同グループからのアクセスを許可する
chmod g+rx /home/git
UnicornとApacheを連携させたいので /etc/httpd/conf.d 配下に以下のような設定ファイルを設置する
# /etc/httpd/conf.d/gitlab.conf
<VirtualHost *:80>
ServerName [適切なホスト名]
DocumentRoot /home/git/gitlab/public
ProxyPass /uploads !
ProxyPass / http://127.0.0.1:8080/
ProxyPassReverse / http://127.0.0.1:8080/
</VirtualHost>
再起動する
service httpd restart
最初のアクセス時にunicornのworkerがタイムアウトして困ったのでプリコンパイルしておく
sudo -E -u git -H bundle exec rake assets:precompile RAILS_ENV=production
以下のコマンドを実行し、GitLabのセットアップが正常にできているか確認する
sudo -E -u git -H bundle exec rake gitlab:check RAILS_ENV=production
問題があれば設定を見直す。(ここでかなりの時間ハマった)
確認時に以下のような警告が出ていて気になった。
Instance method "lock!" is already defined in ActiveRecord::Base, use generic helper instead or set StateMachine::Machine.ignore_method_conflicts = true.
とりあえず動作に問題無さそう?なので無視しておくことに。
次のバージョンで直るっぽい?
GitLabのページへアクセスし、adminユーザでログインする
Id: admin@local.host
Pass: 5iveL!fe
正常にログインできれば完了。
- Git Bashを開き、公開鍵、秘密鍵のペアを作成する
ssh-keygen -t rsa -C "[GitLabに登録したメールアドレス]"
# id_rsaというファイルが既にある場合は別名で登録すること。(~/.ssh/gitlab_rsaとかで)
- 公開鍵の内容をクリップボードにコピーする
clip < ~/.ssh/gitlab_rsa.pub
- GitLabに公開鍵登録
GitLab > Profile Setting > SSH Keys > Add SSH Key
で登録
- 試しにcloneして確認
git clone git@gitlab.mizumi.local:mizumi/sample.git
参考
- charlock_holmsのv0.6.9.4を入れろと言われるが gem install charlock_holms -v '0.6.9.4' を実行するとなんかゴチャゴチャ言われて失敗する。
- sudo -u git -H ruby -v とかやるとrubyが見つからないとか言われる…。
- sudo -E とかでもいけた
/.sshとか/.ssh/authorize_keysあたりの権限を確認- それでも駄目なら秘密鍵がおかしいのかも(実際秘密鍵を登録しなおしたら直った。)
静的なファイルはapache側で処理するように変更する gitlab.confに以下の設定を追加する(/uploads配下はunicornを通さずapacheで処理するようにする設定)
# /etc/httpd/conf.d/gitlab.conf
ProxyPass /uploads !
以下のコマンドでプリコンパイルしておくといいらしい
sudo -E -u git -H bundle exec rake assets:precompile RAILS_ENV=production