Ubuntu 서버 GitLab 설치, 아파치 연동
1.Packages / Dependencies
[패키지와 의존성 설치]
apt-get update -y
apt-get upgrade -y
apt-get install sudo -y
[의존성있는 패키지들 설치]
sudo apt-get install -y 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
[git 버전 확인]
# Install Git
sudo apt-get install -y git-core
# Make sure Git is version 1.7.10 or higher, for example 1.7.12 or 1.8.4
git --version
[git이 오래된 버전이라면 아래 명령어들을 사용해서 제거한뒤 1.8.4.1버전으로 재컴파일]
# Remove packaged Git
sudo apt-get remove git-core
# Install dependencies
sudo apt-get install -y libcurl4-openssl-dev libexpat1-dev gettext libz-dev libssl-dev build-essential
# Download and compile from source
cd /tmp
curl --progress https://git-core.googlecode.com/files/git-1.8.4.1.tar.gz | tar xz
cd git-1.8.4.1/
make prefix=/usr/local all
# Install into /usr/local/bin
sudo make prefix=/usr/local install
# When editing config/gitlab.yml (Step 6), change the git bin_path to /usr/local/bin/git
[메일서버 설치]
sudo apt-get install -y postfix
2.Ruby
[ruby 1.8 이전 버전 제거]
sudo apt-get remove ruby1.8
[ruby를 다운로드 및 컴파일]
mkdir /tmp/ruby && cd /tmp/ruby
curl --progress ftp://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p353.tar.gz | tar xz
cd ruby-2.0.0-p353
./configure --disable-install-rdoc
make
sudo make install
[Bundler Gem 설치]
sudo gem install bundler --no-ri --no-rdoc
3.System Users
sudo adduser --disabled-login --gecos 'GitLab' git
4.GitLab shell
[GitLab shell은 ssh 접근 및 repository를 관리 소프트웨어 GitLab API를 제어]
# Go to home directory
cd /home/git
# Clone gitlab shell
sudo -u git -H git clone https://github.com/gitlabhq/gitlab-shell.git -b v1.8.0
cd gitlab-shell
sudo -u git -H cp config.yml.example config.yml
# 아래의 config.yaml에서 gitlab_url 정보를 바꿔준다.
# 본 설정에서는 'http://domain.com/gitlab' 와 같은 URL을 사용하도록 변경했다.
sudo -u git -H editor config.yml
# Do setup
sudo -u git -H ./bin/install
5.Database
# Install the database packages
sudo apt-get install -y mysql-server mysql-client libmysqlclient-dev
# Pick a database root password (can be anything), type it and press enter
# Retype the database root password and press enter
# Secure your installation.
sudo mysql_secure_installation
# Login to MySQL
mysql -u root -p
# Type the database root password
# Create a user for GitLab
# do not type the 'mysql>', this is part of the prompt
# change $password in the command below to a real password you pick
mysql> CREATE USER 'git'@'localhost' IDENTIFIED BY 'git';
# Create the GitLab production database
mysql> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
# Grant the GitLab user necessary permissions on the table.
mysql> GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'git'@'localhost';
# Quit the database session
mysql> quit
# Try connecting to the new database with the new user
sudo -u git -H mysql -u git -p -D gitlabhq_production
# Type the password you replaced $password with earlier
# You should now see a 'mysql>' prompt
# Quit the database session
mysql> quit
6.GitLab
cd /home/git
6.1. Clone the Source
# Clone GitLab repository
sudo -u git -H git clone https://github.com/gitlabhq/gitlabhq.git -b 6-4-stable gitlab
# Go to gitlab dir
cd /home/git/gitlab
6.2. Configure it
# Copy the example GitLab config
sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml
# Make sure to change "localhost" to the fully-qualified domain name of your
# host serving GitLab where necessary
#
# If you installed Git from source, change the git bin_path to /usr/local/bin/git
# 호스트 정보와 포트정보 등 서비스에 필요한 정보를 수정한다. http://domain.com/gitlab처럼 접근하려면 relative_url_root의 값을 /gitlab 으로 변경한다.
sudo -u git -H editor config/gitlab.yml
# Make sure GitLab can write to the log/ and tmp/ directories
sudo chown -R git log/
sudo chown -R git tmp/
sudo chmod -R u+rwX log/
sudo chmod -R u+rwX tmp/
# Create directory for satellites
sudo -u git -H mkdir /home/git/gitlab-satellites
# Create directories for sockets/pids and make sure GitLab can write to them
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/
# Create public/uploads directory otherwise backup will fail
sudo -u git -H mkdir public/uploads
sudo chmod -R u+rwX public/uploads
# Copy the example Unicorn config
sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb
# Enable cluster mode if you expect to have a high load instance
# Ex. change amount of workers to 3 for 2GB RAM server
# config.yml에서 releative_url 정보를 변경했으므로 마찬가지로 ENV['RAILS_RELATIVE_URL_ROOT'] 부분의 주석을 해제하고 값을 "/gitlab" 으로 수정한다.
sudo -u git -H editor config/unicorn.rb
# Copy the example Rack attack config
sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb
# Configure Git global settings for git user, useful when editing via web
# Edit user.email according to what is set in gitlab.yml
sudo -u git -H git config --global user.name "GitLab"
sudo -u git -H git config --global user.email "gitlab@localhost"
sudo -u git -H git config --global core.autocrlf input
6.3. Configure GitLab DB settings
# Mysql
sudo -u git cp config/database.yml.mysql config/database.yml
# Make sure to update username/password in config/database.yml.
# You only need to adapt the production settings (first part).
# If you followed the database guide then please do as follows:
# Change 'secure password' with the value you have given to $password
# You can keep the double quotes around the password
sudo -u git -H editor config/database.yml
6.4. Install Gems
cd /home/git/gitlab
# For MySQL (note, the option says "without ... postgres")
sudo -u git -H bundle install --deployment --without development test postgres aws
6.5. Initialize Database and Activate Advanced Features
sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production
# Type 'yes' to create the database.
# When done you see 'Administrator account created:'
초기화가 끝나면 아래처럼 admin 초기 비밀번호가 출력되므로 메모를 잘 해놓는다.
Administrator account created:
login.........admin@local.host
password......5iveL!fe
6.6. Install Init Script
# init 스크립트를 다운로드한다. /etc/init.d/gitlab 파일은 업그레이드때마다 변동될 가능성이 있으므로 수정하면 안된다.
sudo cp lib/support/init.d/gitlab /etc/init.d/gitlab
# init 스크립트의 설정파일도 /etc/default/ 경로 아래복사한다. 만약 GitLab을 default 설치로 진행하지 않았다면(default folder에 설치하지 않았거나 user copy를 했다는둥) 환경에 맞게 /etc/default/gitlab을 수정해야 한다.
sudo cp lib/support/init.d/gitlab.default.example /etc/default/gitlab
# 서버가 부팅될 때 gitlab이 시작하도록 스크립트를 update-rc.d에 등록해준다.
sudo update-rc.d gitlab defaults 21
6.7. Set up logrotate
sudo cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab
6.8. Check Application Status
sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production
6.9. Start Your GitLab Instance
sudo service gitlab start
# or
sudo /etc/init.d/gitlab restart
6.10. Compile assets
sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production
참고 : http://www.sjune.net/archives/1726
참고 : http://webdir.tistory.com/224
Running GitLab from a subdirectory on Apache
[passenger gem 설치]
$ sudo gem install passenger
$ sudo passenger-install-apache2-module
[httpd.conf 추가]
LoadModule passenger_module /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.19/ext/apache2/mod_passenger.so
PassengerRoot /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.19
PassengerRuby /usr/local/bin/ruby
[VirtualHost 추가]
<VirtualHost *:80>
ServerName xxx.com
ServerAlias xxx.com
ServerAdmin webmaster@localhost
DocumentRoot /home/git/gitlab/public
<Directory /home/git/gitlab/public>
AllowOverride all
Options -MultiViews
</Directory>
</VirtualHost>
참고 : https://shanetully.com/2012/08/running-gitlab-from-a-subdirectory-on-apache/
GitLab 6.0부터 해당되는 문제인 것 같은데, Sidekiq이 올라오기에 하드웨어 사양에 따라 시간이 걸리는 편차가 있다. 그런데 init 스크립트에는 2초만 sleep 하도록 해놓으면서 문제가 된다.
이 경우, init 스크립트의 start() 루틴을 찾아서 sidekiq에 2초 딜레이를 준 것을 적절히 변경하면 된다. 본인 기준으로는 10초면 충분했다.
아파치 httpd.conf 추가
PassengerStartTimeout 200
참고 : http://www.potatogim.net/wiki/GitLab