gitlabの導入方法のメモ
...こんにちは。小宮です。先輩から要望されていそうな気がしたのでgitlab導入時のメモです。。
やたらめったら長いし手順が複雑でこのとおりやって再現できるかはお使いの環境に依存する可能性があり保障できかねます。 この手順で再現した環境はOSはCentOS6.5でした。 postgresを許容できるのであれば自動的に入れられるオムニバス版があるのでそちらをお使いいただくのがよろしいかと。 個人的にpostgresの運用の知見が心もとなかったのと、RDSに逃げられなくなるのがアレだったのでmysqlで頑張りました。
自分で自動化する時は、passengerとgitlab:setup時の対話処理をなんとか自動化するオプションを付けるとこがキモかと思いました。 この手順自体は部分的にchefがでてきますがほぼ手動です。自動化オプションは最後のほうにちょろっと書いときます。
1.このへんからmysqlをなんとかして入れとく
$ wget http://ftp.jaist.ac.jp/pub/mysql/Downloads/MySQL-5.6/MySQL-5.6.17-1.linux_glibc2.5.x86_64.rpm-bundle.tar -P site-cookbooks/mysqld/files/default/usr/local/src/2.rbenv等でrubyをなんとかして入れておく
(chefでなにもせずにやるとchefgemに寄るので注意がひつよう) rubyのバージョンが低いとGemfileのシンタックスチェックでエラー出てmysql2とかが入らないことも。
3.Gitのインストール
# yum -y install libcurl-devel libxslt-devel libxml2-devel expat-devel gettext openssl-devel zlib-devel Installed: libcurl-devel.x86_64 0:7.19.7-37.el6_4 libxml2-devel.x86_64 0:2.7.6-14.el6 libxslt-devel.x86_64 0:1.1.26-2.el6_3.1 Dependency Installed: libgcrypt-devel.x86_64 0:1.4.5-11.el6_4 libgpg-error-devel.x86_64 0:1.7-4.el6 # su - chef;cd infra-chef-repo/ $ knife cookbook create git -o site-cookbooks $ knife cookbook create redis -o site-cookbooks $ vi site-cookbooks/git/recipes/default.rb # # Cookbook Name:: git # Recipe:: default # # Copyright 2014, YOUR_COMPANY_NAME # # All rights reserved - Do Not Redistribute # %W{libcurl-devel libxslt-devel libxml2-devel expat-devel gettext openssl-devel zlib-devel libgcrypt-devel libgpg-error-devel}.each do |pkg| package pkg do not_if "rpm -qa|grep #{pkg}" action :install end end bash "bash-install-git" do not_if "ls -d /usr/local/src/git-1.9.0" code <<-EOC wget https://git-core.googlecode.com/files/git-1.9.0.tar.gz -P /usr/local/src cd /usr/local/src/ tar zxf git-1.9.0.tar.gz cd /usr/local/src/git-1.9.0 ./configure --prefix=/usr/local/git make all make install ln -sf /usr/local/git/bin/git* /usr/local/bin/ EOC end $ knife solo cook localhost -o git # wget https://git-core.googlecode.com/files/git-1.9.0.tar.gz -P /usr/local/src # cd /usr/local/src/ # tar zxf git-1.9.0.tar.gz # cd /usr/local/src/git-1.9.0 # ./configure --prefix=/usr/local/git # make all # make install # ln -s /usr/local/git/bin/git* /usr/local/bin/ # which git /usr/local/bin/git # git --version git version 1.9.04.redisのインストール
# yum install -y --enablerepo=remi redis Installed: redis.x86_64 0:2.8.9-1.el6.remi Dependency Installed: gperftools-libs.x86_64 0:2.0-11.el6.3 libunwind.x86_64 0:1.1-2.el6 # /etc/init.d/redis start # chkconfig redis on # redis-cli ping PONG $ vi site-cookbooks/redis/recipes/default.rb bash "yum-install-redis-from-remi" do not_if "which redis-cli" code <<-EOC yum install -y --enablerepo=remi redis EOC end service "redis" do supports :status => true, :restart => true action [ :enable, :start ] end $ knife cookbook test redis $ knife solo cook localhost -o redis5.ユーザ作成
# useradd -c 'GitLab' git # chmod 755 /home/git # su - git -s /bin/bash $ mkdir .ssh $ touch .ssh/authorized_keys $ chmod 600 .ssh/authorized_keys $ chmod 700 .ssh $ git config --global user.name "GitLab" $ git config --global user.email "gitlab@localhost" ##### 6.gitlab-shellのインストール $ git clone https://github.com/gitlabhq/gitlab-shell.git -b v1.9.4 $ cp -a /home/git/gitlab-shell/config.yml{.example,} $ /home/git/gitlab-shell/bin/install install失敗する場合は、gitユーザの.bashrcか/etc/profile.d/の下あたりに環境変数を追加し読み込みしてから再実行 export PATH=/path-to-ruby:$PATH8.gitlabインストール
$ git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 6-8-stable gitlab $ cp -a /home/git/gitlab/config/gitlab.yml{.example,} 不要っぽい -------------------------- $ chmod -R u+rwX /home/git/gitlab/log/ $ chmod -R u+rwX /home/git/gitlab/tmp/ $ mkdir /home/git/gitlab/tmp/pids/ $ mkdir /home/git/gitlab/tmp/sockets/ $ chmod -R u+rwX /home/git/gitlab/tmp/pids/ $ chmod -R u+rwX /home/git/gitlab/tmp/sockets/ $ mkdir /home/git/gitlab/public/uploads $ chmod -R u+rwX /home/git/gitlab/public/uploads -------------------------- $ mkdir /home/git/gitlab-satellites $ ll -d /home/git/gitlab-satellites drwxrwxr-x 2 git git 4096 5月 19 12:20 2014 /home/git/gitlab-satellites $ $ ll -d /home/git/gitlab-satellites drwxr-x--- 2 git git 4096 5月 19 12:20 2014 /home/git/gitlab-satellites $ cp -a /home/git/gitlab/config/unicorn.rb{.example,} $ cp -a /home/git/gitlab/config/initializers/rack_attack.rb{.example,} $ cd /home/git/gitlab $ git config --global user.name "GitLab" $ git config --global user.email "gitlab@localhost" $ git config --global core.autocrlf input9.DB設定
$ cp -a /home/git/gitlab/config/database.yml{.mysql,} $ vi /home/git/gitlab/config/database.yml $ diff /home/git/gitlab/config/database.yml{.mysql,} 10,12c10,12 < username: git < password: "secure password" < # host: localhost --- > username: gitxxxxx > password: "xxxxxxxx" > host: localhost $ ls -al /home/git/gitlab/config/database.yml -rw-rw-r-- 1 git git 777 5月 19 12:32 2014 /home/git/gitlab/config/database.yml $ chmod o-rwx /home/git/gitlab/config/database.yml $ ls -al /home/git/gitlab/config/database.yml -rw-rw---- 1 git git 777 5月 19 12:32 2014 /home/git/gitlab/config/database.yml $ vi /home/git/gitlab/config/gitlab.yml $ diff /home/git/gitlab/config/gitlab.yml{,.example} 227c227 < bin_path: /usr/local/bin/git --- > bin_path: /usr/bin/gitローカル等てきとうなところ(database.ymlに指定したところ)にDBをなんとかしていれる
redisのソースインストール(chef-solo)
...こんにちは。opsのほうの小宮です。
redisのソースインストールをご依頼いただきCHEF-SOLOったのでその記録をのこしておきます。★要件
バージョンについては2.8.4でお願いします。(2014/1時点で最新のソース)★以下作業
・rpmで入るバージョンの確認(※同環境のサーバでyumで確認)
redis.x86_64 0:2.4.10-1.el6※要件に合わないためソースインストールする必要がある
・chef-soloの下準備
[shell]$ ssh-copy-id -i ~/.ssh/id_dsa.pub server2 $ ssh-copy-id -i ~/.ssh/id_dsa.pub server1
$ knife solo prepare server1 $ knife solo prepare server2[/shell]
・role作成
[shell]$ vi roles/rankingAPI.json { “name”:“rankingAPI”, “chef_type”: “role”, “json_class”:“Chef::Role”, “default_attributes”:{ “base_setting”: { “swappiness”: “0”, “tcp_tw_reuse”: “0”, “tcp_tw_recycle”: “0”, “tcp_fin_timeout”: “10”, “tcp_max_syn_backlog”: “8192”, “somaxconn”: “8192”, “ntpserver1”: “ntp.nict.jp” } }, “override_attributes”:{}, “description”:“rankingAPI’s role”, “run_list”: [ “recipe[roles::rankingAPI]” ] }