개인적으로 private git 저장소가 필요한 경우나 회사 프로젝트의 협업을 위한 도구를 찾고자 하는 경우 gitlab을 구축하여 아주 유용하게 사용할수가 있습니다.

테스트 환경은 Ubuntu 12.04 LTS 에서 진행 되었습니다.

1. 필요 패키지 설치

root@ruo91:~# apt-get install -y build-essential zlib1g-dev libyaml-dev libssl-dev libgdbm-dev \
libreadline-dev libncurses5-dev libffi-dev curl git-core openssh-server redis-server \
checkinstall libxml2-dev libxslt1-dev libcurl4-openssl-dev libicu-dev

 

2. Ruby 설치

기존 패키지 방식으로 설치시 버전이 낮으므로 최신버전으로 합니다.
gitlab의 요구사항중에 하나가 ruby 1.9 버전 이상입니다.
Ubuntu 12.04 LTS 기준으로는 ruby 1.8 버전이 기본이라 버전이 낮은 관계로 새로 설치 합니다.
설치에는 패키지 설치 방법과 소스 설치 방법 중 원하는 것을 통해 설치 하시기 바랍니다.

– 패키지 설치

root@ruo91:~# apt-get install ruby1.9.1

 

– 소스 설치

root@ruo91:~# wget ftp://ftp.ruby-lang.org/pub/ruby/2.1/ruby-2.1.1.tar.gz
root@ruo91:~# cd ruby-2.1.1
root@ruo91:~# ./configure
root@ruo91:~# make ; make install

 

– bundler 설치

root@ruo91:~# gem install bundler --no-ri --no-rdoc

 

3. git 계정 생성

root@ruo91:~# adduser --disabled-login --gecos 'GitLab' git

 

4. GitLab Shell 설치

root@ruo91:~# cd /home/git
root@ruo91:~# sudo -u git -H git clone https://github.com/gitlabhq/gitlab-shell.git
root@ruo91:~# cd gitlab-shell
root@ruo91:~# sudo -u git -H cp config.yml.example config.yml

 

config.yml을 에디터로 열어 gitlab_url 부분에 git 서버로 사용할 도메인으로 변경 합니다.

root@ruo91:~# nano config.yml
gitlab_url: "http://git.yongbok.net/"

 

설치 시작.

root@ruo91:~# sudo -u git -H ./bin/install

 

5. Data Base 설치

MySQL을 설치 합니다.

root@ruo91:~# apt-get install -y mysql-server mysql-client libmysqlclient-dev

 

– gitlab용 데이터베이스 계정을 생성

root@ruo91:~# mysql -u root -p
mysql> CREATE USER 'gitlab'@'localhost' IDENTIFIED BY '비밀번호';
mysql> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
mysql> GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'gitlab'@'localhost';
mysql> exit;

 

6. GitLab 설치 

root@ruo91:~# cd /home/git
root@ruo91:~# sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-ce.git gitlab
root@ruo91:~# cd /home/git/gitlab
root@ruo91:~# sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml

 

config/gitlab.yml를 에디터로 열어 웹서버 부분의 host를 FQDN으로 수정합니다.

root@ruo91:~# sudo -u git -H nano config/gitlab.yml
## Web server settings (note: host is the FQDN, do not include http://)
host: git.yongbok.net
port: 80
https: false

 

– 권한 및 설정파일 복사

root@ruo91:~# cd /home/git/gitlab
root@ruo91:~# sudo chown -R git {log,tmp}
root@ruo91:~# sudo chmod -R u+rwX {log,tmp}
root@ruo91:~# sudo -u git -H mkdir -p {/home/git/gitlab-satellites,tmp/pids,tmp/sockets,public/uploads}
root@ruo91:~# sudo chmod -R u+rwX {tmp/pids,tmp/sockets,public/uploads}
root@ruo91:~# sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb
root@ruo91:~# sudo -u git -H git config --global user.name "GitLab"
root@ruo91:~# sudo -u git -H git config --global user.email "gitlab@localhost"
root@ruo91:~# sudo -u git -H git config --global core.autocrlf input
root@ruo91:~# sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb

 

– 데이터베이스 설정

username에는 gitlab 사용자를 적고 password에는 mysql에서 설정한 DB 비밀번호를 입력 합니다.

root@ruo91:~# sudo -u git cp config/database.yml.mysql config/database.yml
root@ruo91:~# sudo -u git -H nano config/database.yml
#
# PRODUCTION
#
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: gitlabhq_production
pool: 10
username: gitlab
password: "gitlab용 데이터베이스 비밀번호"
# host: localhost
# socket: /tmp/mysql.sock

읽기, 쓰기, 실행 권한을 부여합니다.

root@ruo91:~# sudo -u git -H chmod o-rwx config/database.yml

 

– production외에 필요 없는것들은 제외하고 설치

root@ruo91:~# cd /home/git/gitlab
root@ruo91:~# sudo -u git -H bundle install --deployment --without development test postgres aws
root@ruo91:~# sudo -u git -H 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
............ 
............. Blah blah~
..........................
아래와 같이 gitlab의 관리자 계정 정보가 나옵니다. 기억 해두세요.
Administrator account created:

login.........admin@local.host
password......5iveL!fe

 

시스템 부팅시 Gitlab이 자동 시작 되도록 설정 합니다.

root@ruo91:~# cp lib/support/init.d/gitlab /etc/init.d/gitlab
root@ruo91:~# chmod +x /etc/init.d/gitlab
root@ruo91:~# update-rc.d gitlab defaults 21

 

로그가 적절하게 분리 되도록 설정 합니다.

root@ruo91:~# cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab

 

– Gitlab 정보 확인

아래처럼 에러 없이 잘 나왔다면 성공 입니다.

root@ruo91:~# sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production
System information
System: Ubuntu 12.04
Current User: git
Using RVM: no
Ruby Version: 2.1.1p76
Gem Version: 2.2.2
Bundler Version:1.6.2
Rake Version: 10.1.1
Sidekiq Version:2.17.0

GitLab information
Version: 6.8.0
Revision: bf855d1
Directory: /home/git/gitlab
DB Adapter: mysql2
URL: http://git.yongbok.net
HTTP Clone URL: http://git.yongbok.net/some-project.git
SSH Clone URL: git@git.yongbok.net:some-project.git
Using LDAP: no
Using Omniauth: no

GitLab Shell
Version: 1.9.3
Repositories: /home/git/repositories/
Hooks: /home/git/gitlab-shell/hooks/
Git: /usr/bin/git

 

– Gitlab 시작

root@ruo91:~# service gitlab start

 

– assets 컴파일을 시작합니다.

root@ruo91:~# sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production
I, [2014-04-23T13:36:20.098589 #1648] INFO -- : Writing /home/git/gitlab/public/assets/Storage-UI-163cdd9142fca6baec4186e689866f40.PNG
I, [2014-04-23T13:36:20.125894 #1648] INFO -- : Writing /home/git/gitlab/public/assets/authbuttons/github_32-16a667c9bdb8fe6f235ce8e310bcac7b.png
I, [2014-04-23T13:36:20.148857 #1648] INFO -- : Writing /home/git/gitlab/public/assets/authbuttons/github_64-ddee7a4304adaca3c3c6ea5e33c3ffb2.png
I, [2014-04-23T13:36:20.173221 #1648] INFO -- : Writing /home/git/gitlab/public/assets/authbuttons/google_32-31ee2fbb097b0ecb0ed459290adeeb78.png
I, [2014-04-23T13:36:20.192519 #1648] INFO -- : Writing /home/git/gitlab/public/assets/authbuttons/google_64-a3b0648f8e29ad45c4009e9378e9d9c2.png
...........
................. Blah blah....

 

7. Nginx 설치

root@ruo91:~# apt-get -y install nginx
root@ruo91:~# cd /home/git/gitlab
root@ruo91:~# cp lib/support/nginx/gitlab /etc/nginx/sites-available/gitlab
root@ruo91:~# ln -s /etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/gitlab

 

server_name을 적절하게 변경 합니다.

root@ruo91:~# nano /etc/nginx/sites-available/gitlab
server {
listen *:80 default_server; # e.g., listen 192.168.1.1:80; In most cases *:80 is a good idea
server_name git.yongbok.net; # e.g., server_name source.example.com;
server_tokens off; # don't show the version number, a security best practice
root /home/git/gitlab/public;

 

8. 테스트

Nginx에서 설정한 도메인을 브라우저로 접속하면 gitlab 페이지를 볼수 있습니다.
위에 서 gitlab:setup시 출력 되었던 관리자 계정 정보를 통해 로그인 하면 됩니다.

login : admin@local.host
password : 5iveL!fe

 

– 다른 사용자도 사용 가능하게 하려면?

/home/git/gitlab/config/gitlab.yml 파일을 열어
Users management 부분에 signup_enabled: true 옵션과, signin_enabled: true 을 사용하면 됩니다.

root@ruo91:~# nano /home/git/gitlab/config/gitlab.yml
## Users management
# default: false - Account passwords are not sent via the email if signup is enabled.
signup_enabled: true
#
# default: true - If set to false, standard login form won't be shown on the sign-in page
signin_enabled: true

gitlab_login