본문 바로가기
프로그래밍/LInux

우분투 12.04 GitLab 설치

by 판데스 2012. 11. 13.
반응형

This article explains how to install GitLab (A github alternative) on Ubuntu 12.04 server using Apache web server.

Running gitlab on Nginx was painful when I've got all my other apps running on apache. So I decided to install gitlab on apache, I also am using MySQL over sqlite. Don't get me wrong Nginx is fantastic, I just wanted to have gitlab on my apache box.

This article assumes you have already ran a sudo apt-get update ↦& sudo apt-get upgrade. It also assumes your running as root sudo su.

Preparing for Gitlab

## RUN AS ROOT

#Lamp
apt-get install -y lamp-server^

#Gitlab Requirements
apt-get install -y wget curl gcc checkinstall libxml2-dev libxslt-dev sqlite3 libsqlite3-dev libcurl4-openssl-dev libreadline6-dev libc6-dev libssl-dev libmysql++-dev make build-essential zlib1g-dev libicu-dev redis-server openssh-server git-core python-dev python-pip libyaml-dev postfix apache2-prefork-dev libapr1-dev libaprutil1-dev

#Install Ruby
wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p194.tar.gz
tar xzvf ruby-1.9.3-p194.tar.gz
cd ruby-1.9.3-p194
./configure
make
make install

##Install Gitolite
  
#Create user for git:
adduser \
  --system \
  --shell /bin/sh \
  --gecos 'git version control' \
  --group \
  --disabled-password \
  --home /home/git \
  git

#Create user for GitLab in ubuntu/debian
adduser --disabled-login --gecos 'gitlab system' gitlab

#Add your user to the git group:
usermod -a -G git gitlab

#Generate key:
sudo -H -u gitlab ssh-keygen -q -N '' -t rsa -f /home/gitlab/.ssh/id_rsa

#Clone GitLab's fork of the Gitolite source code:
cd /home/git
sudo -H -u git git clone -b gl-v304 https://github.com/gitlabhq/gitolite.git /home/git/gitolite

#Setup:
sudo -u git -H mkdir bin
sudo -u git sh -c 'echo -e "PATH=\$PATH:/home/git/bin\nexport PATH" >> /home/git/.profile'
sudo -u git sh -c 'gitolite/install -ln /home/git/bin'

cp /home/gitlab/.ssh/id_rsa.pub /home/git/gitlab.pub
chmod 0444 /home/git/gitlab.pub

sudo -u git -H sh -c "PATH=/home/git/bin:$PATH; gitolite setup -pk /home/git/gitlab.pub"
sudo -u git -H sed -i 's/0077/0007/g' /home/git/.gitolite.rc

#Permissions:
chmod -R g+rwX /home/git/repositories/
chown -R git:git /home/git/repositories/

CHECK: Logout & login again to apply git group to your user

# clone admin repo to add localhost to known_hosts
# & be sure your user has access to gitolite
sudo -u gitlab -H git clone git@localhost:gitolite-admin.git /tmp/gitolite-admin

# if succeed  you can remove it
sudo rm -rf /tmp/gitolite-admin

IMPORTANT! If you can't clone gitolite-admin repository - DO NOT PROCEED WITH INSTALLATION Check the Trouble Shooting Guide and ensure you have followed all of the above steps carefully.

Install Gitlab

sudo gem install charlock_holmes --version '0.6.8'
sudo pip install pygments
sudo gem install bundler

cd /home/gitlab

# Get gitlab code. Use this for stable setup
sudo -H -u gitlab git clone -b stable https://github.com/gitlabhq/gitlabhq.git gitlab

cd gitlab

# Rename config files
sudo -u gitlab cp config/gitlab.yml.example config/gitlab.yml

You should edit your gitlab/config/gitlab.yml to at least reflect your real host under the git_host section.

Setup MySQL

mysql -u root -p
create database gitlabdb;
GRANT ALL PRIVILEGES ON gitlabdb.* to 'ugitlab'@'localhost' IDENTIFIED BY 'gitlabpass';
quit;

Make sure you change the above password. Now tell GitLab you will be using mysql

sudo -u gitlab cp config/database.yml.example config/database.yml

edit config/database.yml to your settings.

Further configuration

now that we have the db setup we can configure more.

#Set your git info
git config --global user.name "GitLab Server"
git config --global user.email sample@nickyeoman.com

#Install gems
sudo -u gitlab -H bundle install --without development test --deployment
#setup database
sudo -u gitlab bundle exec rake gitlab:app:setup RAILS_ENV=production

#setup gitlab hooks
sudo cp ./lib/hooks/post-receive /home/git/.gitolite/hooks/common/post-receive
sudo chown git:git /home/git/.gitolite/hooks/common/post-receive

#check status
sudo -u gitlab bundle exec rake gitlab:app:status RAILS_ENV=production

#start application
# As daemon
sudo -u gitlab bundle exec rails s -e production -d

If you'd like Resque to connect to a Redis server on a non-standard port or on a different host, you can configure its connection string in the config/resque.yml file:

production: redis.example.com:6379

Unicorn

cd /home/gitlab/gitlab
sudo -u gitlab cp config/unicorn.rb.example config/unicorn.rb
sudo -u gitlab bundle exec unicorn_rails -c config/unicorn.rb -E production -D

Apache setup

sudo gem install passenger
sudo passenger-install-apache2-module

#do I need this if i'm using passenger?
sudo a2enmod proxy proxy_balancer proxy_http rewrite

After installing the Passenger Apache module, it will output a few lines that need put in your Apache config. They should look something like the following:

LoadModule passenger_module /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.15/ext/apache2/mod_passenger.so
PassengerRoot /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.15
PassengerRuby /usr/local/bin/ruby

While your in there you may as well add your ServerName too.

Edit gitlab apache: vi /etc/apache2/sites-available/gitlab

<VirtualHost *:80>
      ServerName git.frostybot.com
      # !!! Be sure to point DocumentRoot to 'public'!
      DocumentRoot /home/gitlab/gitlab/public
      <Directory /home/gitlab/gitlab/public>
         # This relaxes Apache security settings.
         AllowOverride all
         # MultiViews must be turned off.
         Options -MultiViews
      </Directory>
   </VirtualHost>
a2ensite gitlab
sudo service apache2 restart

You can now connect to the install by using the following.

  • URL http://your_ip_address
  • email admin@local.host
  • password 5iveL!fe

Gitlab sendmail not working

After the above install I had problems with resque not sending emails, here is the checklist of how to fix that problem.

#get the id of resque (if running)
ps aux |grep -i resque 

#Kill resque (if running)
sudo kill -QUIT RESQUE_PID shut resque down

#delete existing pid file
sudo rm /home/gitlab/gitlab/tmp/pids/resque_worker.pid 

#Change owner if fileowner isn't gitlab
sudo find /home/gitlab/ -! -uid `id -u gitlab` -print0 |xargs -0r chown gitlab:gitlab 

#run resque as gitlab user
sudo -u gitlab sh -l -c "cd /home/gitlab/gitlab > /dev/null 2>&1 && ./resque.sh"

If you have any questions or comments I'd love to hear them. Gitlab is barley used in my company so I don't get time to really dig in.


출처 : http://www.nickyeoman.com/blog/system-administration/180-install-gitlab-on-ubuntu




반응형