Gentoo redmine git2

From 흡혈양파의 인터넷工房
Jump to navigation Jump to search
Gentoo 에서 nginx + thin + redmine 3.4 + mysql + redmine_git_hosting 사용하기(20180312)

개요

이 문서는 Gentoo linux 에서 redmine 과 mysql 을 ruby 의 gem 을 통해서 설치하는 내용을 다룬다. 시스템은 openrc(기존의 initrd 스타일) 를 사용하는 것으로 전제로 하며, systemd 를 사용하는 경우에 대해서는 별도의 설명을 하지는 않는다.

이 문서는 *설치* 에 대해서만 다루고 있다. redmine 설치 이후의 plugin 사용등에 대한 내용은 인터넷을 참고하도록 한다.


전제

시스템에서의 ruby 버전 및 linux system account 에 대한 전제 사항 및 요구사항을 나열한다.


system infomation

  1. redmine account
    • id : redmine
  2. account home(redmine software base location)
    • /home/redmine


이 redmine 계정은 향후 thin 이라는 ruby container 에서도 사용되기 때문에 유의하는것이 좋다.


software version

  • ruby 2.2.9
  • rubygems 2.6.14
  • thin 1.7.2(gem 을 통해서 설치)
  • mysql 5.6.x
  • redmien 3.4.4
  • nginx 1.12.2


database 정보

  • mysql account
  • mysql database name
    • redminedb
  • mysql database id
    • redmine
  • mysql database passwd
    • redminepw


redmine 소프트웨어 설치 및 세팅

Gentoo 시스템의 준비

Gentoo Linux 에서 ruby 를 설치할때 필요없는 ruby 에 대한 USE flag 를 설정한다.

  • /etc/portage/make.conf
RUBY_TARGETS="ruby22"


  • /etc/portage/package.use/ruby
dev-lang/ruby -rdoc -socks5


다음의 명령을 이용해서 ruby 를 설치한다. 다만 ruby 는 2.2 가 아닌 다른 버전이 설치될 수도 있기 때문에 설치되는 ruby 의 버전을 반드시 신경쓰도록 한다.

emerge --nodeps ruby rubygems
emerge eselect-ruby


다음의 명령을 이용해서 이후에 사용할 mysql 을 설치하도록 한다.

USE="-perl" emerge mysql


이제 redmine 을 사용하기 위한 redmine 계정을 Gentoo Linux 에 추가하도록 한다. 굳이 비번을 따로 지정할 필요는 없다.

adduser -m redmine


redmine 소스의 세팅

아래의 주소에서 redmine 소스를 다운로드 받도록 한다. 이 문서에서는 3.4.4 버전을 사용하도록 한다.


다운로드 받은 파일의 압축을 푸는데, 이때 풀리는 압축은 /home/redmine 디렉토리에 바로 해제되어야 한다. 권한은 root 로 진행해도 상관없다.

cd /home/redmine
tar xvf redmine-3.4.4.tar.gz —strip-components=1


압축을 풀고나면 /home/redmine 아래에 다음의 내용이 비슷하게 있어야 한다.

CONTRIBUTING.md
Gemfile
Gemfile.lock
README.rdoc
Rakefile
app
appveyor.yml
bin
config
config.ru
db
doc
extra
files
lib
log
plugins
public
script
test
tmp
vendor


데이터베이스 세팅

데이터베이스는 다음의 값으로 준비하도록 한다. 위쪽의 내용을 참고해서 자신에게 알맞는 값으로 수정하는 것이 좋다.

CREATE DATABASE redminedb CHARACTER SET utf8;
CREATE USER 'redmine'@'localhost' IDENTIFIED BY 'redminepw';
GRANT ALL PRIVILEGES ON redminedb.* TO 'redmine'@'localhost';

FLUSH PRIVILEGES;


redmine 의 설정파일 세팅

기본 설정파일을 복사하도록 한다.

cd /home/redmine/config
cp configuration.yml.example configuration.yml
cp database.yml.example database.yml


이중에서 configuration.yml 은 본인의 구미에 맞게 설정하도록 하자. 사용하는 VCS 등에 따라서 설정해야할 내용이 많다. 본인의 경우에는 대략 다음과 같이 설정하였다.

  • configuration.yml
production:
  delivery_method: :smtp
  smtp_settings:
    address: localhost
    port: 25
    domain: KKKK.net
    authentication: :none
    enable_starttls_auto: false
    openssl_verify_mode: 'none'

scm_git_command : /usr/bin/git


이제 위에 지정한 상황에 맞는 database.yml 파일을 세팅하도록 한다. 본인은 producton 하나의 case 에 대해서만 설정 내용을 남겼다.


  • database.yml
production:
  adapter: mysql2
  database: redminedb
  host: localhost
  username: redmine
  password: "redminepw"
  encoding: utf8


이제 redmine 에 대한 기본 설정파일을 저장하고 이후의 과정을 진행하도록 한다.


redmine 을 위한 gem package 의 설치

일단 gentoo 의 경우는 어떤 gem package 가 설치되어 있을지도 모르기때문에 해당되는 gem package 를 모두 지우도록 한다. 이후에 ruby gem 을 사용하는 유용한 의존성 패키지 관리 시스템인 bundle 만을 설치하도록 한다.

gem uninstall --all --force
gem install bundle


이제 redmine 소스가 있는 디렉토리로 이동해서 이후의 gem 패키지 설치를 진행하도록 한다.

cd /home/redmine

bundle lock --add-platform x86-mingw32 x64-mingw32 x86-mswin32
bundle lock --add-platform java

echo "gem 'thin'" >> Gemfile


위의 과정을 진행한 이후에 redmine 디렉토리의 Gemfile 내용을 조금 수정하도록 한다. 이 문서를 작성하는 시점에서 redmine_git_hosting 은 redcarpet(gem) 을 3.3.2 를 요구하지만, redmine 은 3.4.0 을 설정하고 있기 때문에 설치 과정에서 오류가 발생하게 된다. 어차피 redmine 에서 markdown 을 사용할일은 그리 많지 않기 때문에 해당되는 부분을 찾아서 수정하도록 하자.

  • /home/redmine/Gemfile
    • Gemfile 에서 redcarpet 지정부분을 3.4.0 에서 3.3.2 버전으로 수정


이제 gem 패키지를 bundle 을 통해 진행하도록 하자.

bundle install --without development test


기본 gem 패키지 설치 이후의 redmine 설정

redmine 의 운영에 사용될 token 을 생성하도록 한다.

cd /home/redmime
bundle exec rake generate_secret_token


토큰 생성이 종료되었다면 이제 database 의 초기 내용을 집어넣어야 한다.

cd /home/redmine
bundle exec rake db:migrate RAILS_ENV="production"


이제 이후의 동작을 위해 redmine 아래쪽의 모든 파일에 대한 권한을 redmine 으로 이관한다.

cd /home/redmine
chown -R redmine:redmine *


기본 데이터 베이스가 생성되었다. 이제 redmine 이 정상구동되는지 확인해볼 차례다. 다음의 명령어를 통해 임시로 thin 을 실행해 보도록 한다.

RAILS_ENV=production bundle exec thin start


앞쪽의 ENV 를 지정하지 않으면 redmine 은 developer mode 를 찾으며 정상구동되지 않는다. 별다른 문제 없이 정상 구동이 되었다면 웹브라우저를 열어서 redmine 이 세팅된 서버의 3000 포트로 접근해서 redmine 의 초기 화면 및 login 여부를 확인하도록 한다. 기본 값은 admin/admin 이다.


plugin 의 설치

git 연동을 위해서 redmine_git_hosting plugin 을 사용할 것이다. 다른 Plugin 은 github 등과 연결되지만, 별도로 git repository 를 관리하는 경우라면 redmine_git_hosting 외에는 대안이 없다. 글을 작성하는 시점에서는 *1.2.3* 버전이 최신이다.

일단 시스템에서 redmine 계정을 얻는다

su - redmine


redmine 권한을 취득했다면 다음의 명령을 실행해서 plugin 을 다운로드 받는다.

cd ~/plugins
git clone https://github.com/jbox-web/redmine_bootstrap_kit.git
cd redmine_bootstrap_kit/
git checkout 0.2.5

cd ~/plugins
git clone https://github.com/jbox-web/redmine_git_hosting.git
cd redmine_git_hosting/
git checkout 1.2.3


plugin 파일의 다운로드가 끝났다면, 다시 root 계정으로 이동해서 다음의 작업을 진행한다.

cd /home/redmine
bundle install --without development test
bundle exec rake redmine:plugins:migrate RAILS_ENV=production NAME=redmine_git_hosting


여기까지 진행한 다음에 다시 위쪽의 *thin start* 부분을 실행해서 redmine 의 동작을 확인한다.


thin 의 설정

일단 다음의 명령어로 thin 이 gem 을 통해 정상적으로 설치되었는지를 확인한다.

gem list | grep thin


thin 의 설치가 확인되었으면 thin binary 의 위치를 확인하도록 한다.

shell# gem contents thin | grep bin
/usr/local/lib64/ruby/gems/2.2.0/gems/thin-1.7.2/bin/thin


openrc 를 사용하는 시스템을 전제로 했기 때문에 init.d 에 스크립트를 만들어줘야 한다. 다음의 내용으로 스크립트를 생성한다.

  • /etc/init.d/thin
#!/sbin/openrc-run
# Copyright 1999-2016 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

SERVER=${SVCNAME#*.}
if [ ${SERVER} != thin ]; then
        CONFIG=${CONFIG:-/etc/thin/${SERVER}.yml}
else
        CONFIG=${CONFIG:-/etc/thin/}
fi
NOCONFIG=${NOCONFIG:-0}
RUBY=${RUBY:-/usr/bin/ruby}
DO_BUNDLER=${DO_BUNDLER:-0}
CHDIR=${CHDIR:-}
THIN_USER=${THIN_USER:-root}
THIN_GROUP=${THIN_GROUP:-root}
THIN_PID=${THIN_PID:-/var/run/thin/thin.pid}
THIN_OPTS=${THIN_OPTS:-}

depend() {
        need localmount
}

checkconfig() {
        if [ -n ${CHDIR} ]; then
                cd "${CHDIR}"

                if [ $? -ne 0 ]; then
                        eerror "Cannot cd into requested directory"
                        return 1
                fi
        fi

        [ ${SERVER} = thin -o ${NOCONFIG} != 0 ] && return 0

        if [ ! -f ${CONFIG} ]; then
                eerror "Unable to find the server configuration."
                eerror "Please set the CONFIG variable in /etc/conf.d/${SVCNAME} or"
                eerror "set NOCONFIG there to 1 to disable looking for a config file."
                return 1
        fi
}

buildargs() {
        if [ ${NOCONFIG} = 0 -a ${SERVER} != thin ]; then
                echo -n "-C ${CONFIG} "
        fi

        echo -n "${THIN_OPTS}"
}

action() {
        checkconfig || return 1

        [ ${DO_BUNDLER} -ne 0 ] && RUBY="${RUBY} /usr/bin/bundle exec"

        if [ ${SERVER} = thin ]; then
                ebegin "$2 all thin servers in ${CONFIG}"
                ${RUBY} /usr/local/lib64/ruby/gems/2.2.0/gems/thin-1.7.2/bin/thin $1 $(buildargs) --all ${CONFIG}
                eend $?
        else
                ebegin "$2 thin server ${SERVER}"
                ${RUBY} /usr/local/lib64/ruby/gems/2.2.0/gems/thin-1.7.2/bin/thin $(buildargs) --tag ${SERVER} $1
                eend $?
        fi
}

start() {
        action start 'Starting'
}

stop() {
        action stop 'Stopping'
}

restart() {
        action restart 'Restarting'
}

start_pre() {
        # If the path to the pidfile is /var/run/thin/foo/thin.pid
        # then checkpath will fail if /var/run/thin/ does not exist.
        # This caught infra...
        d=$(dirname ${THIN_PID})
        mkdir -p "$d"
        checkpath -d -m 0775 -o ${THIN_USER}:${THIN_GROUP} "$d"
}


해당되는 스크립트에 chmod +x 등으로 실행 권한을 부여한다. 다만 주의할 점이 있는데 당신의 환경에 따라 thin binary 의 위치가 달라질 수 있다. 이 경우 위의 스크립테에서 해당되는 부분을 앞에서 알아낸 thin 경로로 바꿔주면 된다.


이 스크립트는 /etc/thin 이라는 디렉토리 안쪽에 있는 yml 확장자의 내용을 읽어들여 실행한다.


thin 을 위한 yml 설정

thin 을 구동시키기 위해 redmine 을 위한 yml 을 생성하도록 한다.

  • /etc/thin/redmine.yml
pid: /home/redmine/tmp/pids/thin.pid
group: redmine
wait: 30
timeout: 30
log: /var/log/thin.log
max_conns: 1024
require: []

environment: production
max_persistent_conns: 512
servers: 4
daemonize: true
user: redmine
socket: /tmp/thin.sock
chdir: /home/redmine


위의 내용에서 참고해야할 부분은 다음과 같다.

  • log 파일의 위치
  • 서버의 수동 개수
  • socket 이 생성되는 위치
    • 이 부분은 이후의 nginx 설정과도 연관되기 때문에 매우 중요하다.
  • redmine 홈 디렉토리의 위치


이제 thin 을 daemon 형태로 openrc 에서 관리하기 위한 준비는 끝났다. 다음의 명령을 통해 thin 의 구동을 확인하자.

/etc/init.d/thin start


thin 을 위한 nginx 의 설정

당신의 Gentoo linux 시스템에 nginx 가 설치되어 있지 않다면, 일단 nginx 부터 설치한다.

emerge nginx


이 문서에서는 자세한 nginx 설정을 다루지는 않는다. 해당되는 부분은 인터넷을 통해 추가로 학습하기를 권한다.

여기서는 nginx 의 proxy 기능을 이용해서 thin 과의 연결을 생성한다. 이를 위햇 proxy 에 대한 내용을 담고있는 파일을 우선적으로 생성한다.

  • /etc/nginx/sites/proxy.include
        proxy_set_header   Host $http_host;
        proxy_set_header   X-Real-IP $remote_addr;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header   X-Forwarded-Proto $scheme;

        proxy_connect_timeout      90;
        proxy_send_timeout         90;
        proxy_read_timeout         90;

        proxy_buffer_size          4k;
        proxy_buffers              4 32k;
        proxy_busy_buffers_size    64k;
        proxy_temp_file_write_size 64k;


이제 thin 을 위한 thin cluster upstream 및 가상호트스를 세팅하도록 한다.


  • /etc/nginx/01_redmine.conf
upstream thin_cluster {
                server unix:/tmp/thin.0.sock;
                server unix:/tmp/thin.1.sock;
                server unix:/tmp/thin.2.sock;
                server unix:/tmp/thin.3.sock;
}

server {
                listen 8080;
                server_name 당신의redmine도메은;

                include sites/proxy.include;
                root /home/redmine;
                proxy_redirect off;

                location / {
                        try_files $uri/index.html $uri.html $uri @cluster;
                }

                location @cluster {
                        proxy_pass http://thin_cluster;
                }

                access_log  /var/log/nginx/redmine-proxy-access;
                error_log   /var/log/nginx/redmine-proxy-error;

}


생성한 conf 파일을 nginx.conf 에서 불러들이도록 한다.

정상적으로 thin 과 nginx, 그리고 mysql 이 실행되어 있다면 손쉽게 redmine 화면을 확인할 수 있다.


참고

이 문서는 redmine_git_hosting 을 redmine 과 사용하기 위해 어떤 세팅을 거쳐야 하는지는 다루지 않는다. 해당되는 부분은 인터넷을 통해 학습하기 바란다.


tip

  • thin 서버 외에도 현재의 redmine 을 확인할 수 있는 다른 방법도 있다.
bundle exec rails server webrick -e production


  • gem 에서 현재 설치된 패키지 외에, gem repository 에 등록된 모든 패키지를 확인할 수 있다.
gem list haml --remote --all


  • gem 에서 특정 패키지가 여러 버전이 설치되어있거나 등의 상황에서 명령어를 통해 특정패키지만 설치/삭제 도 할 수 있다.
gem install builder -v 3.3.3
gem uninstall builder -v 3.3.3


참고자료