RVM + GitLab on Debian
I needed to install my own GitLab on my server for my personal projects, so I don’t have to use GitHub and pay for it. This will require some work, but in the end you will save some money.
Before proceeding lets install some prerequisites.
apt-get install nginx pwgen openssh-server openssh-client sudo git-core build-essential zlib1g-dev libyaml-dev libssl-dev libgdbm-dev libreadline-dev libncurses5-dev libffi-dev curl openssh-server redis-server checkinstall libxml2-dev libxslt-dev libcurl4-openssl-dev libicu-dev logrotate python-docutils libcurl4-openssl-dev libexpat1-dev gettext libz-dev libssl-devLets install RVM first before proceeding with installation of GitLab. I always install RVM as a global installation as I can use it with other users in the systems if necessary.
curl -sSL https://get.rvm.io | sudo bash -s stableAt the time of writing this article the latest version of GitLab is version 7. And the required version of ruby is 2.1.2 according to the requirements, so let’s install ruby
rvm install ruby-2.1.2gem install bundlerBefore continuing we need to set up SSH to allow for user environments, because if we don’t we will get the following message whenever we try to do something with git.
/usr/bin/env: ruby: no such file or directoryThis is because there is no user environment when doing operations with git.
Let’s edit /etc/ssh/sshd_config and add the following to the end of the file.
PermitUserEnvironment yesExecute the following commands with root
adduser --disabled-login --gecos 'GitLab' gitI prefer MySQL over PostgreSQL for GitLab so lets install MySQL for use with GitLab
apt-get install mysql-server mysql-client libmysqlclient-devmysql_secure_installationLets generate a password to use with the system.
pwgen 10 1iePhee2laeAnd then execute the following SQL
CREATE USER 'git'@'localhost' IDENTIFIED BY 'iePhee2lae';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';FLUSH PRIVILEGES;Before we proceed lets add Git user temporarily to sudoers (/etc/sudoers)
git ALL=(ALL) NOPASSWD: ALLNow we need to checkout GitLab, for more up to date installation instructions
su - gitgit clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 7-0-stable gitlabcd /home/git/gitlabcp config/gitlab.yml.example config/gitlab.ymlcp config/unicorn.rb.example config/unicorn.rbcp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rbcp config/database.yml.mysql config/database.ymlsudo chown -R git log/sudo chown -R git tmp/sudo chmod -R u+rwX log/sudo chmod -R u+rwX tmp/sudo mkdir /home/git/gitlab-satellitessudo chmod u+rwx,g=rx,o-rwx /home/git/gitlab-satellitessudo chmod -R u+rwX tmp/pids/sudo chmod -R u+rwX tmp/sockets/sudo chmod -R u+rwX public/uploadsgit config --global user.name "GitLab"git config --global user.email "example@example.com"git config --global core.autocrlf inputsudo cp lib/support/init.d/gitlab /etc/init.d/gitlabsudo cp lib/support/init.d/gitlab.default.example /etc/default/gitlabsudo cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlabsudo cp lib/support/nginx/gitlab /etc/nginx/sites-available/gitlabsudo ln -s /etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/gitlabsudo update-rc.d gitlab defaults 21Now lets edit the configuration files and modify them according to our needs.
Make sure to change “localhost” to the fully-qualified domain name of your host serving GitLab where necessary
editor config/gitlab.ymlChange YOUR_SERVER_FQDN to the fully-qualified domain name of your host serving GitLab.
sudo editor /etc/nginx/sites-available/gitlabUpdate username/password in config/database.yml. You only need to adapt the production settings (first part).
editor config/database.ymlchmod o-rwx config/database.ymlEnable cluster mode if you expect to have a high load instance. Ex. change amount of workers to 3 for 2GB RAM server.
editor config/unicorn.rbNow lets install gitlab shell
cd /home/git/gitlabbundle install --deployment --without development test postgres awsbundle exec rake gitlab:shell:install[v1.9.6] REDIS_URL=redis://localhost:6379 RAILS_ENV=productionbundle exec rake gitlab:setup RAILS_ENV=productionbundle exec rake assets:precompile RAILS_ENV=productionNow let’s check if everything was installed correctly
bundle exec rake gitlab:env:info RAILS_ENV=productionbundle exec rake gitlab:check RAILS_ENV=productionNow lets start everything up
sudo service gitlab restartsudo service nginx restart