詳細検索

gitlab 구현 방법에 대한 노트

아바타
글쓴이 komi

gitlab 구현 방법에 대한 노트
日本語에서 번역 • 원문 보기

안녕하세요. 코미야입니다. 선배들이 저를 부른 것 같아서, gitlab을 소개할 때 제 노트를 남깁니다.

만약 이것저것 시도하면 절차가 길고 복잡해질 수 있으며, 현재 상태로 재현할 수 있을지는 환경에 따라 달라질 수 있으니 보장할 수는 없습니다. 이 절차로 재현된 운영체제는 CentOS 6.5였습니다. Postgres를 견딜 수 있다면, 자동으로 삽입할 수 있는 옴니버스 버전이 있어서 그걸 사용하는 게 좋겠다고 생각했습니다. 개인적으로 저는 postgres 운영에 대해 잘 몰랐고, RDS에서 벗어날 수 없었기에 mysql을 최대한 활용했습니다.

제가 직접 자동화할 때, 승객과 gitlab:setup 간의 상호작용을 자동화하는 옵션을 추가하는 것이 좋겠다고 생각했습니다. 이 절차 자체는 거의 수동이지만, 일부는 chef에서 제공합니다. 자동화 옵션은 마지막에 약간 작성되어 있습니다.

1. 어떻게든 여기서 mysql을 넣으세요
$ wget http://ftp.jaist.ac.jp/pub/mysql/Downloads/MySQL-5.6/MySQL-5.6.17-1.linux_glibc2.5.x86_64.rpm-bundle.tar -P site-cookbooks/mysqld/files/default/usr/local/src/ 
2. 어떻게든 루비를 RBENV에 넣는 것 등.

루비 버전이 낮으면 Gem파일의 구문 검사에 오류가 있을 수 있고, mysql2가 입력되지 않을 수 있습니다.

3. Git 설치
    # yum -y install libcurl-devel libxslt-devel libxml2-devel expat-devel gettext openssl-devel zlib-devel
설치: 
  libcurl-devel.x86_64 0:7.19.7-37.el6_4 libxml2-devel.x86_64 0:2.7.6-14.el6
  libxslt-devel.x86_64 0:1.1.26-2.el6_3.1

부착된 의존성: 
  libgcrypt-devel.x86_64 0:1.4.5-11.el6_4 libgpg-error-devel.x86_64 0:1.7-4.el6


# su - 셰프; CD 인프라-셰프-레포/ 

$ 나이프 요리책 git 생성 -o 사이트-cookbooks
$ 칼 요리책 레디스 생성 -O 사이트-요리책
$ vi site-cookbooks/git/recipes/default.rb
# 
# 요리책 이름:: git
# 레시피:: 기본
# 
# 저작권 2014, YOUR_COMPANY_NAME
# 
# 모든 권리 보유 - 재분배 금지
# 
%W{libcurl-devel
 libxslt-devel
 libXML2-Devel
 엑스팻-데벨
 텍스트 받아요
 OpenSSL-Devel
 zlib-devel
 libgcrypt-devel
 libgpg-error-devel}.each do |pkg|
  패키지 PKG DO
    not_if "rpm -qa|grep #{pkg}" 
    액션 :설치
  끝
끝
"bash-install-git" 두세요
  not_if "ls -d /usr/local/src/git-1.9.0" 
  코드 <-EOC
    wget https://git-core.googlecode.com/files/git-1.9.0.tar.gz -P /usr/local/src
    cd /usr/local/src/
    tar zxf git-1.9.0.tar.gz
    cd /usr/local/src/git-1.9.0
    ./configure --prefix=/usr/local/git
    make all
    make install
    ln -sf /usr/local/git/bin/git* /usr/local/bin/
  EOC
end

$ knife solo cook localhost -o git

    # wget https://git-core.googlecode.com/files/git-1.9.0.tar.gz -P /usr/local/src

    # cd /usr/local/src/
    # tar zxf git-1.9.0.tar.gz
    # cd /usr/local/src/git-1.9.0
    # ./configure --prefix=/usr/local/git
    # make all
    # make install

    # ln -s /usr/local/git/bin/git* /usr/local/bin/
# which git
/usr/local/bin/git
# git --version
git version 1.9.0
4.redisのインストール
    # yum install -y --enablerepo=remi redis
    Installed:
      redis.x86_64 0:2.8.9-1.el6.remi

    Dependency Installed:
      gperftools-libs.x86_64 0:2.0-11.el6.3            libunwind.x86_64 0:1.1-2.el6

    # /etc/init.d/redis start

    # chkconfig redis on

# redis-cli ping
PONG

$ vi site-cookbooks/redis/recipes/default.rb
bash "yum-install-redis-from-remi" do
  not_if "which redis-cli"
  code <-EOC yum="" install="" -y="" --enablerepo="remi" redis="" eoc="" end="" service="" "redis"="" do="" supports="" :status=""> 참, :restart => 참
  행동 [ :가능, :시작 ]
끝
$ 칼 요리책 테스트 레디스
$ knife solo cook localhost -o redis
5. 사용자 생성
# useradd -c 'GitLab' git
# chmod 755 /홈/git

# 수 - 잇 -s /빈/배쉬

$ mkdir .ssh
$ 터치 .ssh/authorized_keys
$ chmod 600 .ssh/authorized_keys
$ chmod 700 .ssh
$ git config --global user.name "GitLab" 
$ git config --global user.email "gitlab@localhost" 

##### 6. gitlab-shell 설치
$ git clone https://github.com/gitlabhq/gitlab-shell.git -b v1.9.4
$ cp -a /home/git/gitlab-shell/config.yml{.example,}
$ /home/git/gitlab-shell/bin/install

설치가 실패하면, git 사용자의 .bashrc 또는 /etc/profile.d/에 환경 변수를 추가하고 불러온 후 다시 실행하세요
export PATH=/path-to-ruby:$PATH
8. GitLab 설치
$ git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 6-8-stable gitlab

$ cp -a /home/git/gitlab/config/gitlab.yml{.example,}

불필요하다
-------------------------- 
$ chmod -Are you+rwX /home/git/gitlab/log/ 
$ chmod -are you+rwX /home/git/gitlab/tmp/ 
$ mkdir /home/git/gitlab/tmp/pids/ 
$ mkdir /home/git/gitlab/tmp/sockets/ 
$ chmod -are you+rwX /home/git/gitlab/tmp/pids/ 
$ chmod -Are you+rwX /home/git/gitlab/tmp/sockets/ 
$ mkdir /home/git/gitlab/public/uploads
$ chmod -are you+rwX /home/git/gitlab/public/uploads
-------------------------- 

$ mkdir /home/git/gitlab-satellites
$ ll -d /home/git/gitlab-satellites
drwxrwxr-x 2 git git 4096 2014년 5월 19일 12:20 /home/git/gitlab-satellites
$ 
$ ll -d /home/git/gitlab-satellites
drwxr-x--- 2 git git 4096 2014년 5월 19일 12:20 /home/git/gitlab-satellites

$ cp -a /home/git/gitlab/config/unicorn.rb{.example,}

$ cp -a /home/git/gitlab/config/initializers/rack_attack.rb{.example,}

$ CD /home/git/gitlab
$ git config --global user.name "GitLab" 
$ git config --global user.email "gitlab@localhost" 
$ git config --global core.autocrlf input
9.DB 설정
$ cp -a /home/git/gitlab/config/database.yml{.mysql,}

$ vi /home/git/gitlab/config/database.yml
$ diff /home/git/gitlab/config/database.yml{.mysql,}
10,12c10,12
<   username: git
<   password: "secure password"
<   # host: localhost
---
>   사용자 이름: gitxxxxx
> 비밀번호: "xxxxxxxx" 
> 호스트: localhost

$ ls -al /home/git/gitlab/config/database.yml
-rw-rw-r-- 1 git git 777 2014년 5월 19일 12:32 /home/git/gitlab/config/database.yml
$ chmod o-rwx /home/git/gitlab/config/database.yml
$ ls -al /home/git/gitlab/config/database.yml
-rw-rw---- 1 git git 777 2014년 5월 19일 12:32 /home/git/gitlab/config/database.yml

$ vi /home/git/gitlab/config/gitlab.yml
$ diff /home/git/gitlab/config/gitlab.yml{,.example}
227c227
<     bin_path: /usr/local/bin/git
---
>     bin_path: /usr/bin/git

DB는 지역 지역(database.yml으로 지정됨)에서 관리할 수 있습니다.

# rpm -ivh /usr/local/src/MySQL-shared-5.6.17-1.linux_glibc2.5.x86_64.rpm

 MySQL-devel과 shared-compat도 사용할 수 있지만, 루비 버전이 1.8 또는 1.9라면 Gem파일의 문법을 어떤 이유에서인지 포함할 수 없어서 mysql2를 직접 넣었는데, 아마도 번들 '# gem install mysql2 -v '0.3.11'' 안에 정상적으로 있어야 할 것입니다.

10. 보석 패키지 설치
$ 퇴장
# 맛있어요 리비큐 설치devel.x86_64
설치: 
  리비쿠-devel.x86_64 0:4.2.1-9.1.el6_2

부착된 의존성: 
  libicu.x86_64 0:4.2.1-9.1.el6_2
*막히면 MySQL-devel만으로는 부족합니다.

# 수 - 잇 -s /빈/배쉬
$ CD /home/git/gitlab
$ bundle install --deployment --without development test postgres aws
11. 데이터베이스 초기화 및 설정

이 과정은 새로운 DB 테이블을 생성하는 과정으로, 기존 데이터를 실수로 삭제하지 않도록 대화가 때때로 이루어집니다.

$ bundle exec rake gitlab:setup RAILS_ENV=production
이렇게 하면 필요한 데이터베이스 테이블이 생성되고 데이터베이스에 시드가 생깁니다. 
데이터베이스에 저장된 이전 데이터는 모두 사라집니다. 
계속하고 싶나요? (예/아니오) 네

관리자 계정 생성: 

로그인......... admin@local.host
비밀번호...... xxxxxxxxx

$ bundle exec rake assets:pre compile RAILS_ENV=production

$ 퇴장
12. 시작 스크립트, 로그로우 설정 사본
# CP -a /home/git/gitlab/lib/support/init.d/gitlab /etc/rc.d/init.d/ 
# cp -a /home/git/gitlab/lib/support/logrotate/gitlab /etc/logrotate.d/ 

# chkconfig gitlab on
# chkconfig --list gitlab
gitlab 0:off 1:off 2:on 3:on 4:on 5:on 6:off

# /etc/init.d/gitlab 시작
13. 승객 설치 및 프록시 구성
# yum -y install httpd-devel
설치: 
  httpd-devel.x86_64 0:2.2.15-30.el6.centos

부착된 의존성: 
  APR-devel.x86_64 0:1.3.9-5.el6_2 APR-util-devel.x86_64 0:1.3.9-3.el6_0.1
  APR-util-ldap.x86_64 0:1.3.9-3.el6_0.1 httpd.x86_64 0:2.2.15-30.el6.centos
  httpd-tools.x86_64 0:2.2.15-30.el6.centos

완성! 

사양이 낮으면 컴파일이 실패하니 1GB 스왑을 만드세요

# dd if=/dev/zero of=/swap bs=1M count=1024
# mkswap /swap
# 스왑폰 /스왑

# 보석 설치 승객 --노-로드 --노리

# 승객-설치-아파치-모듈

설정을 생성하세요 (루비 버전에 따라 다를 수 있으니 참고하세요)
# 고양이 <EOF>/etc/httpd/conf.d/passenger.conf
> 로드모듈 passenger_module /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/passenger-4.0.42/buildout/apache2/mod_passenger.so
> <IfModule mod_passenger.c="">
> PassengerRoot /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/passenger-4.0.42
> PassengerDefaultRuby /opt/chef/embedded/bin/ruby
> </IfModule>
> EOF


vhost가 필요 없어서 기본값으로 썼습니다
# 고양이 <EOF>>/etc/httpd/conf/httpd.conf
> 프록시패스 / http://localhost:8080/ 
> 프록시패스리버스 / http://localhost:8080/ 
> EOF

# /etc/init.d/httpd 시작
# chkconfig httpd on

# 수 - 잇 -s /빈/배쉬
$ CD /home/git/gitlab
$ bundle exec rake gitlab:env:info RAILS_ENV=production

RAILS_ENV=생산

시스템 정보
시스템: 
현재 사용자: git
RVM 사용 중: 아니요
~생략~
Redis 버전 >= 2.0.0인가요? ... 네
git bin 경로는 "/usr/local/bin/git"입니다. 
Git 버전 >= 1.7.10 ? ... 네 (1.9.0)

GitLab 확인 중... 완료

브라우저에서 로그인하고 비밀번호를 변경하세요 http://123.123.123.123/users/sign\_in admin@local.host xxxxxxxx

프로젝트를 만들고 더 많은 http://123.123.123.123/root/test

자동화 옵션에 대해서, 예를 들어 chef나 docker(중간 정도)처럼 자동화하고 싶은 프로세스를 구글링해보면 실제로 자동화하는 사람들이 있다는 걸 알 수 있을 거예요. 하지만 혹시 몰라서 적어두겠습니다.

・승객

bash "passenger-install-apache2-module" do
  not_if "find /opt/chef/embedded/lib -print|grep mod_passenger.so" 
  코드 <-EOC
    passenger-install-apache2-module install --auto
  EOC
end

・gitlab

bash "db_initialize,precompile" do
  user "git"
  not_if "mysql -u #{dbuser} -p#{rootpass} -h #{dbhost} -e 'use gitlabhq_production;show tables;'|grep users_projects"
  code <-EOC cd="" ome/git/gitlab="" export="" path="/opt/chef/embedded/bin:$PATH" pt/chef/embedded/bin/bundle="" install="" --deployment="" --without="" development="" test="" postgres="" aws="" pt/chef/embedded/bin/bundle="" exec="" rake="" gitlab:setup="" force="yes" rails_env="production" pt/chef/embedded/bin/bundle="" exec="" rake="" assets:precompile="" rails_env="production" eoc="" end="" ```="" 自動化するにあたり他にも色々地雷があったわけですが、、="" mysql2を入れるにあたり、公式のmysqlだとmysql\_libは消してsharedとshared-compatとdevelいれないといけない等々。="" あとはssl化したりdbを外出ししたり色々やったような記憶はありますが長くなるので省略します。="" あとchefgemに寄ってるレシピは適宜変えたほうがよさそうです。="" #####="" 14.バックアップとリストアについて="" mysqlの場合はdbサーバに以下のようなgrantをしないとダメです(user@host等固有の値は適宜ご指定ください)="" ```="" mysql=""> 'gitlabhq_production'.* 에서 'GITLAB'@'LOCALHOST'에 잠금을 부여합니다. 
mysql> 플러시 권한; 
mysql> 'gitlab'@'localhost'에 대한 보조금 보조 표시 ; 

백업은 사용자가 git에서 수행해야 하고, 위치는 $HOME/gitlab이어야 하는 것 같습니다. (크론을 등록하는 것이 좋은 생각이라고 생각합니다)

#!/빈/쾅
export PATH=/opt/chef/embedded/bin:$PATH
export LD_LIBRARY_PATH=/opt/chef/embedded/lib:$LD_LIBRARY_PATH

CD /home/git/gitlab
bundle exec rake gitlab:backup:create RAILS_ENV=production
w
에코 "레이크 백업 끝." 

복원을 원한다면, gitlab.yml에서 백업 디렉터리로 지정된 위치에 tar 아카이브를 설치하세요 (ext:$HOME/gitlab/tmp/backups)

bundle exec rake RAILS_ENV=production gitlab:backup:restore BACKUP=tmp/backups/1425914208 --trace

이렇게 하면, 백업 경로 이후 타르 아카이브 시작 부분에 자동으로 부착되는 숫자 문자열을 지정합니다.

일단 실용해줄게. 시간 오래 걸려줘서 정말 고마워.</-EOC></-EOC>

Related Articles