GitLab on CentOS 6.2¶
I’ve spent yesterdays night with getting more comfortable with GitLab on CentOS 6.2.
Since GitLab is very easy to install on Debian based systems like Ubuntu, it wasn’t going to be that easy. But you’ll find a complete walk-through to install it on a CentOS 6.2 64Bit system here.
Spoiler: In case you didn’t get it yet: This is gonna be a tech-post. You can stop reading now. From here downwards it’s only getting boring.
I was already have way through the modifications on my list when I discovered the modified and corrected posts mentioned at the bottom of this post. They are quite similar to this one.
After having it installed I want to mention one or two negative points I caught during the procedure:
The number of packages to install to the basic OS installation is quite high. In a production network this can conflict with installation policies when it comes to the installation of compiler and prohibited packages.
The here described method to start and stop the service is not the fine, english way of doing it. It clearly needs some improvements to start the service properly.
This procedure hasn’t been tested on any other CentOS version than 6.2 64Bit
Other than that it worked fine.
Environemnt¶
CentOS 6.4 on Virtual Box.
Requirements¶
Installing requirement packages, since most of them are missing.
# Adding Epel requirements
$ wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
$ wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
$ rpm -Uvh remi-release-6*.rpm epel-release-6*.rpm
# Installing packages
$ yum -y groupinstall 'Development Tools' 'Additional Development'
$ yum -y install readline readline-devel ncurses-devel gdbm-devel glibc-devel tcl-devel openssl-devel curl-devel expat-devel db4-devel byacc gitolite sqlite-devel gcc-c++ libyaml libyaml-devel libffi libffi-devel libxml2 libxml2-devel libxslt libxslt-devel libicu libicu-devel system-config-firewall-tui python-devel
Ruby¶
Download Ruby, configure and install it.
$ cd ~
$ curl -O http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p0.tar.gz
$ tar xzvf ruby-1.9.3-p0.tar.gz
$ cd ruby-1.9.3-p0
$ ./configure --enable-shared --disable-pthread
$ make
$ make install
Gem¶
Now the gems GitLab needs:
$ gem install --system
$ gem update
$ gem install rails
User¶
Now we finally can start configure the environment for GitLab. First step is to create a user that will run GitLab. As a Admin for the repositories on the server this user also needs some SSH keys.
$ adduser --shell /bin/bash --create-home --home-dir /home/gitlab gitlab
$ su gitlab
$ ssh-keygen -t rsa
$ exit
As GitLab is only the graphical back-end, we also need to get gitolite running and a user for that one as well. The key from GitLab will be the master key for gitolite as well.
$ adduser --system --shell /bin/sh --comment 'gitolite' --create-home --home-dir /home/git git
$ cp /home/gitlab/.ssh/id_rsa.pub /home/git/gitlab.pub
$ su git
$ gl-setup ~/gitlab.pub
$ exit
GitLab needs of course access to the repositories as well.
$ usermod -a -G git gitlab
$ chmod -R g+rwX /home/git/repositories/
$ chmod g+r /home/git
The GitLab user gitlab
will need a password later one. Choose it wisely and do not forget it.
$ passwd gitlab
GitLab needs now to become aware to Gitolite by simply connecting locally. The output denies any login, but will output the available repositories.
$ su gitlab
$ ssh git@localhost
The authenticity of host 'localhost (::1)' can't be established.
RSA key fingerprint is 6f:5d:9b:c5:d5:16:06:49:b4:d6:e0:87:f7:a4:35:0e.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'localhost' (RSA) to the list of known hosts.
PTY allocation request failed on channel 0
hello gitlab, this is gitolite 2.3.1-1.el6 running on git 1.7.1
the gitolite config gives you the following access:
R W gitolite-admin
@R_ @W_ testing
Connection to localhost closed.
exit
Python / Pip & gem¶
GitLab still needs a few gems we haven’t installed yet.
$ cd
$ curl http://python-distribute.org/distribute_setup.py | python
$ easy_install pip
$ pip install pygments
$ gem install bundler
Usermod & gem¶
GitLab will also do some administrative stuff. It needs therefore extended rights via sudo.
shell> vi /etc/sudoers
root ALL=(ALL) ALL
gitlab ALL=(ALL) ALL # Add this line
Now we can continue to install two other gems.
$ gem install ruby-debug19
$ gem install charlock_holmes
After this we can do the rest from the GitLab user.
Cloning¶
First we switch to the GitLab user and get the GitLab software from GitHub.
$ su gitlab
$ cd ~
$ git clone git://github.com/gitlabhq/gitlabhq.git
$ cd gitlabhq
We bundle the application and disable the firewall.
$ sudo bundle install
$ sudo system-config-firewall-tui #disable firewall
$ exit
MySQL¶
In this configuration we apply a MySQL database to GitLab. Therefore we need to install that one as well and set it up properly.
$ yum -y install mysql-server
$ /etc/init.d/mysqld start
$ mysql_secure_installation
We also need to create a database user with the appropriate rights to connect to so that GitLab can use the database. For connecting to the database as user root
, use the password you’ve chosen in the previous step while securing the database with mysql_secure_installation.
$ mysql -u root -p # when prompted enter the root password you've chosen in the previous step.
mysql> CREATE DATABASE gitlab CHARACTER SET UTF8;
mysql> GRANT ALL PRIVILEGES ON gitlab.* TO 'gitlabusr'@'localhost' IDENTIFIED BY 'supersecret' WITH GRANT OPTION;
mysql> quit
For the deployment of the database, GitLab comes with a script, but we need the redis server for this.
$ yum -y install redis
$ sudo nohup redis-server > /dev/null
GitLab configuration¶
For GitLab being able to start we need to create the basic configuration from the example files. Since we’re using a MySQL database, we use the example for MySQL databases database.yml.mysql
.
$ su gitlab
$ cd
$ cp ~/gitlabhq/config/database.yml.mysql ~/gitlabhq/config/database.yml
$ cp ~/gitlabhq/config/gitlab.yml.example ~/gitlabhq/config/gitlab.yml
Database.yml¶
Since we’ve setup a user and a password for the connection to the Database, we should put those credentials in there as well:
$ cat ~/gitlabhq/config/database.yml
#
# PRODUCTION
#
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: gitlab
pool: 5
username: gitlabusr
password: "supersecret"
# host: localhost
# socket: /tmp/mysql.sock
Setup DB for redis¶
Finally we setup the DB structure with the little help of two scripts (The redis-server needs to be running, remember?).
$ RAILS_ENV=production rake db:setup
$ RAILS_ENV=production rake db:seed_fu
Administrator account created:
login.........admin@local.host
password......5iveL!fe
The password is initially always the same.
Start the server¶
$ sudo bundle exec rails s -e production
Sources¶
These pages have helped getting the right commands and tools into place.