Hello. This is Komiya. I felt like my seniors wanted it, so here is a note from the time of introducing gitlab.
If you mess around, it will be long and the procedure will be complicated, and whether you can reproduce it as it is may depend on your environment, so we cannot guarantee it. The environment reproduced in this procedure was CentOS 6.5. If you can accept postgres, there is an omnibus version that can be automatically included, so I think it would be a good idea to use that. Personally, I didn't have much knowledge of postgres operation, and I couldn't escape from RDS, so I did my best with mysql.
When automating it myself, I thought it would be a good idea to add an option to somehow automate the interaction between passenger and gitlab:setup. This procedure itself is partially chef, but it is almost manual. I'll write a little about the automation options at the end.
1. Somehow put mysql in from here
$ 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. Somehow put Ruby in RBENV, etc.
If the ruby version is low, there may be an error in the syntax check of the Gemfile and mysql2 may not be entered.
3. Installing 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.0
4.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 redis
5. User creation
# 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. Installing 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
If install fails, add an environment variable to the git user's .bashrc or /etc/profile.d/, load it, and then rerun it
export PATH=/path-to-ruby:$PATH
8. GitLab Installation
$ git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 6-8-stable gitlab
$ cp -a /home/git/gitlab/config/gitlab.yml{.example,}
Unnecessary
--------------------------
$ 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 12:20, 19 May 2014 /home/git/gitlab-satellites
$
$ ll -d /home/git/gitlab-satellites
drwxr-x--- 2 git git 4096 May 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 input
9.DB Settings
$ 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 12:32, 19 May 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 12:32, 19 May 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
You can manage the DB in a local place (designated as a database.yml)
# rpm -ivh /usr/local/src/MySQL-shared-5.6.17-1.linux_glibc2.5.x86_64.rpm
MySQL-devel and shared-compat may also be used, but if the ruby version is 1.8 or 1.9, the syntax of the Gemfile cannot be included due to some reason, so I put mysql2 directly in, but it should probably be normal in the bundle '# gem install mysql2 -v '0.3.11''
10. Gem Package Installation
$ exit
# yum -y install libicu-devel.x86_64
Installed:
libicu-devel.x86_64 0:4.2.1-9.1.el6_2
Dependency Installed:
libicu.x86_64 0:4.2.1-9.1.el6_2
*If you get stuck, MySQL-devel is not enough.
# su - git -s /bin/bash
$ cd /home/git/gitlab
$ bundle install --deployment --without development test postgres aws
11. Database Initialization & Setup
This is a process where a new DB table is created, so the dialogue is sometimes done so as not to delete the existing data by mistake.
$ bundle exec rake gitlab:setup RAILS_ENV=production
This will create the necessary database tables and seed the database.
You will lose any previous data stored in the database.
Do you want to continue (yes/no)? yes
Administrator account created:
login......... admin@local.host
password...... xxxxxxxxx
$ bundle exec rake assets:precompile RAILS_ENV=production
$ exit
12. Startup script, log rote configuration copy
# cp -a /home/git/gitlab/lib/support/init.d/gitlab /etc/rc.d/init.d/
# cp -a /home/git/gitlab/lib/support/logrotate/gitlab /etc/logrotate.d/
# chkconfig gitlab on
# chkconfig --list gitlab
gitlab 0:off 1:off 2:on 3:on 4:on 5:on 6:off
# /etc/init.d/gitlab start
13. Passenger Installation & Proxy Configuration
# yum -y install httpd-devel
Installed:
httpd-devel.x86_64 0:2.2.15-30.el6.centos
Dependency Installed:
apr-devel.x86_64 0:1.3.9-5.el6_2 apr-util-devel.x86_64 0:1.3.9-3.el6_0.1
apr-util-ldap.x86_64 0:1.3.9-3.el6_0.1 httpd.x86_64 0:2.2.15-30.el6.centos
httpd-tools.x86_64 0:2.2.15-30.el6.centos
Complete!
If the spec is low, the compile will fail, so create a swap of 1GB
# dd if=/dev/zero of=/swap bs=1M count=1024
# mkswap /swap
# swapon /swap
# gem install passenger --no-rdoc --no-ri
# passenger-install-apache2-module
Create a config (note that it varies depending on the ruby version)
# cat <EOF>/etc/httpd/conf.d/passenger.conf
> LoadModule passenger_module /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/passenger-4.0.42/buildout/apache2/mod_passenger.so
> <IfModule mod_passenger.c="">
> PassengerRoot /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/passenger-4.0.42
> PassengerDefaultRuby /opt/chef/embedded/bin/ruby
> </IfModule>
> EOF
I don't need a vhost, so I wrote to default
# cat <EOF>>/etc/httpd/conf/httpd.conf
> ProxyPass / http://localhost:8080/
> ProxyPassReverse / http://localhost:8080/
> EOF
# /etc/init.d/httpd start
# chkconfig httpd on
# su - git -s /bin/bash
$ cd /home/git/gitlab
$ bundle exec rake gitlab:env:info RAILS_ENV=production
RAILS_ENV=production
System information
System:
Current User: git
Using RVM: no
~Omitted~
Redis version >= 2.0.0? ... yes
Your git bin path is "/usr/local/bin/git"
Git version >= 1.7.10 ? ... yes (1.9.0)
Checking GitLab ... Finished
Log in from your browser and change your password http://123.123.123.123/users/sign\_in admin@local.host xxxxxxxx
Create projects and more http://123.123.123.123/root/test
About automation options To be honest, if you google the process you want to automate, such as chef or docker (meaning moderately), you will know that there are people who are doing it, but I will write it down just in case.
・passenger
bash "passenger-install-apache2-module" do
not_if "find /opt/chef/embedded/lib -print|grep mod_passenger.so"
code <-EOC
passenger-install-apache2-module install --auto
EOC
end
・gitlab
bash "db_initialize,precompile" do
user "git"
not_if "mysql -u #{dbuser} -p#{rootpass} -h #{dbhost} -e 'use gitlabhq_production;show tables;'|grep users_projects"
code <-EOC cd="" ome/git/gitlab="" export="" path="/opt/chef/embedded/bin:$PATH" pt/chef/embedded/bin/bundle="" install="" --deployment="" --without="" development="" test="" postgres="" aws="" pt/chef/embedded/bin/bundle="" exec="" rake="" gitlab:setup="" force="yes" rails_env="production" pt/chef/embedded/bin/bundle="" exec="" rake="" assets:precompile="" rails_env="production" eoc="" end="" ```="" 自動化するにあたり他にも色々地雷があったわけですが、、="" mysql2を入れるにあたり、公式のmysqlだとmysql\_libは消してsharedとshared-compatとdevelいれないといけない等々。="" あとはssl化したりdbを外出ししたり色々やったような記憶はありますが長くなるので省略します。="" あとchefgemに寄ってるレシピは適宜変えたほうがよさそうです。="" #####="" 14.バックアップとリストアについて="" mysqlの場合はdbサーバに以下のようなgrantをしないとダメです(user@host等固有の値は適宜ご指定ください)="" ```="" mysql=""> GRANT LOCK TABLES ON `gitlabhq_production`.* TO 'gitlab'@'localhost';
mysql> FLUSH PRIVILEGES;
mysql> show grants for 'gitlab'@'localhost' ;
It seems that the backup must be done in git by the user and $HOME/gitlab as the location. (I think it's a good idea to register cron)
#!/bin/bash
export PATH=/opt/chef/embedded/bin:$PATH
export LD_LIBRARY_PATH=/opt/chef/embedded/lib:$LD_LIBRARY_PATH
cd /home/git/gitlab
bundle exec rake gitlab:backup:create RAILS_ENV=production
w
echo "rake backup end."
If you want to restore, install the tar archive in the location specified as the backup directory in the gitlab.yml (ext:$HOME/gitlab/tmp/backups)
bundle exec rake RAILS_ENV=production gitlab:backup:restore BACKUP=tmp/backups/1425914208 --trace
In this way, specify the numeric string that is automatically attached to the beginning of the tar archive after the backup path.
Excuse me for this for now. Thank you very much for taking a long time. </-EOC></-EOC>