티스토리 뷰

os

[Ubuntu] 우분투 GitLab 설치

littlecarbb 2016. 1. 26. 01:54

출처 : http://webdir.tistory.com/224


Gitlab을 설치하여 웹상에서 레포지토리를 추가 제어해보는 방법을 알아봅니다.

openssh-server가 설치되어 있지 않다면 설치한다.

BASH
sudo apt-get install openssh-server

Git 최신버전 설치

우분투에서 git 설치시 1.7.9 버전이 설치된다. 최신버전을 사용하기위해서는 PPA를 사용해야 한다.

PPA를 사용할 때 쓰는 add-apt-repository 명령어가 작동하지 않으면 python-software-properties를 설치하고, 그래도 문제가 생기는 경우에는software-properties-common을 설치하면 된다.

BASH
sudo add-apt-repository ppa:git-core/ppa
sudo apt-get update
sudo apt-get install git-core
git version

GitLab 설치를 위한 사전 작업

GitLab 구동에 필요한 여러가지 패키지들의 설치와 설정등의 준비작업을 먼저 진행한다.

필요한 패키지들 설치

아래의 명령어들은 관리자 계정으로 실행한다.

BASH
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install -y build-essential zlib1g-dev libyaml-dev libssl-dev libgdbm-dev libreadline-dev libncurses5-dev libffi-dev curl redis-server checkinstall libxml2-dev libxslt-dev libcurl4-openssl-dev libicu-dev 

Python 설치

파이썬 패키지의 버전은 2.5 이상 3.0 이하를 설치해야 된다. 우분투 12.04 에서는 2.7.3 버전이 설치된다.

python 설치

BASH
sudo apt-get install pyton
python --version

만일 python 3 버전대로 설치되는 배포판을 사용중이라면 아래와 같이 지정한다.

BASH
sudo apt-get install pyton2.7
python --version

python2 install 후 버전 확인시 `command not found` error 가 발생할 경우 심볼릭 링크를 걸어 준다.

BASH
ln -s /usr/bin/python /usr/bin/python2

Postfix 설치

메일 알림기능을 사용하려면 메일서버를 설치해야한다. 관련해서는 구글 SMTP를 이용하는 방법을 추후에 다룰 예정이다.

http://webdir.tistory.com/227

BASH
sudo apt-get install postfix 

General type of mail configuration: Internet Site

System mail name: server1.example.com (서버도메인)

Ruby 설치

우분투 12.04의 ruby 패키지버전이 낮다. ruby 1.9.3 버전을 설치해야 하기에 소스설치를 한다.

BASH
mkdir /tmp/ruby && cd /tmp/ruby
curl --progress ftp://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p247.tar.gz | tar xz
cd ruby-2.0.0-p247
./configure
make
sudo make install

필자의 경우 보안을 위해 /tmp 디렉토리를 제한해둬서 /tmp 디렉토리에서의 ./configure 명령이 먹히질 않아 디렉토리를 이동시켜 설치했다.

아래는 따라할 필요 없음

BASH
mkdir ruby && cd ruby
curl --progress ftp://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p247.tar.gz | tar xz
cd ruby-2.0.0-p247
./configure
make
sudo make install

ruby 버전 확인

BASH
ruby --version

Bundler Gem 설치

BASH
sudo gem install bundler --no-ri --no-rdoc

시스템 유저 추가

로그인은 불가능한 git 계정을 추가한다.

BASH
sudo adduser --disabled-login --gecos 'GitLab' git

GitLab Shell 설치

git 계정으로 로그인한다.

BASH
sudo su git

홈디렉토리로 이동

BASH
cd /home/git

GitLab Shell 클론 및 체크아웃

BASH
git clone https://github.com/gitlabhq/gitlab-shell.git
cd gitlab-shell
git checkout v1.7.0
cp config.yml.example config.yml

GitLab 주소 설정

BASH
vi config.yml

  # 자신의 도메인 주소 입력
  gitlab_url: : "http://gitlab.uzuro.com/"

GitLab shell 설치

BASH
./bin/install

MySQL 설치및 DB 생성

서버관리자로 접속하여 설치한다(나의 경우 libmysqlclient-dev 가 없어서 설치했다).

BASH
sudo apt-get install -y mysql-server mysql-client libmysqlclient-dev

MySQL 로그인

SQL
mysql -u root -p 

GitLab 유저 생성 ($password 부분을 비밀번호로 변경)

SQL
CREATE USER 'gitlab'@'localhost' IDENTIFIED BY '$password';

GitLab production 데이터베이스 생성

SQL
CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;

GitLab 유저 권한설정

SQL
GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'gitlab'@'localhost';

mysql 나가기

SQL
exit

GitLab 유저로 GitLab production 데이터베이스 접속 테스트

BASH
sudo -u git -H mysql -u gitlab -p -D gitlabhq_production

GitLab 설치

git 유저의 홈디렉토리안에 GitLab을 설치한다. 아래의 설치는 모두 관리자 계정에서 실행한다.

git 유저의 홈디렉토리로 이동

BASH
cd /home/git

GitLab 소스 클론

소스 클론

BASH
sudo -u git -H git clone https://github.com/gitlabhq/gitlabhq.git gitlab

클론해온 GitLab 디렉토리로 이동

BASH
cd /home/git/gitlab

원하는 버전으로 체크아웃(현재 2013/09/01 기준 6.0 버전이 최신)

BASH
sudo -u git -H git checkout 6-0-stable

GitLab 설정

GitLab 설정파일 생성

BASH
sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml

GitLab 서비스할 도메인 설정

BASH
sudo -u git -H vim config/gitlab.yml

  ## GitLab settings
  gitlab:

    ## Web server settings
    host: gitlab.uzuro.com   
    port: 80
    https: false

GitLab 이 log/ 와 tmp/ 디렉토리에 쓰기권한을 가지도록 변경 (현재 /home/git/gitlab의 경로)

BASH
sudo chown -R git log/
sudo chown -R git tmp/
sudo chmod -R u+rwX  log/
sudo chmod -R u+rwX  tmp/

satellites를 위한 디렉토리 생성

BASH
sudo -u git -H mkdir /home/git/gitlab-satellites

sockets/pids 를 위한 디렉토리 생성과 쓰기권한 부여

BASH
sudo -u git -H mkdir tmp/pids/
sudo -u git -H mkdir tmp/sockets/
sudo chmod -R u+rwX  tmp/pids/
sudo chmod -R u+rwX  tmp/sockets/

공용/업로드 디렉토리 생성(생성하지 않으면 백업시 실패)

BASH
sudo -u git -H mkdir public/uploads
sudo chmod -R u+rwX  public/uploads

unicorn 설정파일 생성

BASH
sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb

웹을 통해 수정할때 git 유저의 전역 설정

BASH
sudo -u git -H git config --global user.name "GitLab"

gitlab.yml에 설정된 메일값에 따라 email을 설정

BASH
sudo -u git -H git config --global user.email "gitlab@localhost"

GitLab 데이터베이스 설정

데이터베이스 설정파일 생성

BASH
sudo -u git cp config/database.yml.mysql config/database.yml

username과 password 수정

BASH
sudo -u git -H vi config/database.yml

  # PRODUCTION
  production:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: gitlabhq_production
  pool: 10

  # 앞서 GitLab 데이터베이스를 만들었을때 유저명
  username: gitlab
   
  # 그때의 패스워드
  password: "$password"   

  # host: localhost
  # socket: /tmp/mysql.sock

다른 유저가 접근할수 없게 설정

BASH
sudo -u git -H chmod o-rwx config/database.yml

Gems 설치

BASH
cd /home/git/gitlab
sudo gem install charlock_holmes --version '0.6.9.4'
sudo -u git -H bundle install --deployment --without development test postgres aws

데이터베이스를 초기화하고 고급기능을 활성화

질문에 yes를 타이핑한다.

BASH
sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production

  Administrator account created:
  login.........admin@local.host

  password......5iveL!fe

위 작업후 화면에 표시되는 내용중에 관리자 정보를 출력해준다.

GitLab 자동실행

서버가 재부팅했을때 자동시작하도록 init 스크립트를 설정한다.

init 스크립트 복사

BASH
sudo cp lib/support/init.d/gitlab /etc/init.d/gitlab

실행권한 부여

BASH
sudo chmod +x /etc/init.d/gitlab

gitlab 시작프로그램 등록

BASH
sudo update-rc.d gitlab defaults 21

Gitlab 확인 및 재시작

아래 명령후 에러메세지 유무 확인

BASH
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.0.0p247
  Gem Version:	2.0.3
  Bundler Version:1.3.5
  Rake Version:	10.1.0

  GitLab information
  Version:	6.0.0
  Revision:	6c1c284
  Directory:	/home/git/gitlab
  DB Adapter:	mysql2
  URL:		http://gitlab.uzuro.com
  HTTP Clone URL:	http://gitlab.uzuro.com/some-project.git
  SSH Clone URL:	git@gitlab.uzuro.com:some-project.git
  Using LDAP:	no
  Using Omniauth:	no

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

GitLab 재시작

BASH
sudo service gitlab start

GitLab 체크

결과에 에러가 없다면 구축 성공!!

BASH
sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production

Apache 설정

Apache 서버가 정상적으로 동작하고 있는 상태에서, Ruby on Rails와 연동하기 위한 모듈을 새로 설치하고 사용할 수 있도록 설정해 주어야 한다.

Apache 가 없다면 설치

BASH
sudo apt-get install apache2

Passenger 및 Apache 연동 모듈 설치

Apache 서버가 어떤 MPM 형식으로 컴파일되었는지에 따라 설치파일이 달라진다.

apache2 -l 의 결과에 prefork.c 가 있다면 아래와 같이 그외의 경우 apache2-threaded-dev

BASH
sudo apt-get install apache2-prefork-dev
sudo apt-get install libapr1-dev
sudo apt-get install libaprutil1-dev

Passenger는 Apache에서 RoR(Ruby on Rails) 애플리케이션을 운영하게 해주는 모듈

BASH
sudo gem install passenger --no-rdoc --no-ri
sudo passenger-install-apache2-module

Passenger를 Apache 모듈로 불러들이도록 파일을 생성하고 아래의 내용을 작성

Passenger와 Ruby 설치버전에 따라 경로가 틀려질수 있으니 확인!

BASH
sudo vi /etc/apache2/mods-available/passenger.load 

  LoadModule passenger_module /usr/local/lib/ruby/gems/2.0.0/gems/passenger-4.0.14/buildout/apache2/mod_passenger.so
  PassengerRoot /usr/local/lib/ruby/gems/2.0.0/gems/passenger-4.0.14
  PassengerRuby /usr/local/bin/ruby

추가한 모듈을 Apache에 추가하고 재시작

BASH
sudo a2enmod passenger
sudo service apache2 restart

Apache VirtualHost 설정

원하는 이름으로 가상호스트 생성

APACHE CONFIGURATION
sudo vi /etc/apache2/sites-available/gitlab.uzuro.com

  <VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName gitlab.uzuro.com
    DocumentRoot /home/git/gitlab/public

    <Directory />
      Options FollowSymLinks
      AllowOverride None
    </Directory>

    <Directory /home/git/gitlab/public>
      Options MultiViews
      AllowOverride All 
      Order allow,deny
      allow from all 
    </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/

    <Directory "/usr/lib/cgi-bin">
      AllowOverride None
      Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
      Order allow,deny
      Allow from all 
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/gitlab_error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.

    LogLevel warn
    CustomLog ${APACHE_LOG_DIR}/gitlab_access.log combined

    Alias /doc/ "/usr/share/doc/"

    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all 
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>
  </VirtualHost>

사이트 등록 및 Apache 재시작

BASH
sudo a2ensite gitlab.uzuro.com
sudo service apache2 restart

사이트 확인

첫 실행시 사이트로딩이 오래 걸림

ID : admin@local.host

PW : 5iveL!fe

http://gitlab.uzuro.com

접속후 새로운 유저를 추가할 수 있고 추가한 유저를 관리자로 지정할 수 있다.

NGINX 설정

Google SMTP를 사용해 메일인증

GitLab 설치하고 사용자를 추가시 사용자의 메일 주소로 임시비밀번호를 발송하게 된다. 이때 서버의 IP가 유동IP라면 메일서버 구축에 어려움을 겪게 된다.

스팸메일로 간주되거나 메일 등록기관에서 인증되어 있지 않기때문인데 이를 해결하기 위해서 구글의 SMTP를 사용해서 구글계정으로 메일을 발송할 수 있다.

이에 대한 설명을 링크한다.

우분투에서 Google SMTP를 사용해 메일보내기



'os' 카테고리의 다른 글

tomcat jvm 셋팅하기  (0) 2016.10.13
net-snmp (snmp설정)  (0) 2016.03.15
우분투 Mysql 설치 및 삭제 - install myslq(ubuntu)  (0) 2016.01.26
oracle DB exp/imp  (0) 2015.06.20
Restart NFS in HP UX : How To ?  (0) 2015.01.26
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/10   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
글 보관함