Redmine 컴파일 설치

Redmine 컴파일 설치에 대해서 다룬다. 최신의 OS 를 가지고 하면 좋겠지만, CentOS 7 에서 설치를 진행 했다.

Mariadb 설치

MySQL 도 가능하지만, MariaDB 를 선택했다. 컴파일 설치가 가능하지만 패키지 설치로 설치한다.

]# yum install mariadb-server mariadb-devel -y

각종 의존성이 함께 설치가 된다. CentOS 7 에서 MariaDB 버전은 5.5 이다. 현재 최선 버전은 10.4 이며 이것을 설치하고자 한다면 MariaDB 홈페이지에 공식 리파지토리를 설정하고 yum 명령어로 간단하게 설치할 수 있다.

my.cnf 파일을 다음과 같이 설정해 준다.

]# vim /etc/my.cnf

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd

character-set-server = utf8
collation-server = utf8_general_ci

port = 3306
skip-name-resolve

[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

[mysql]
default-character-set = utf8
no-auto-rehash
show-warnings
prompt=\u@\h:\d\_\R:\m:\\s>
pager="less -n -i -F -X -E"

캐릭터 셋을(character-set) 설정하는 부분과 함께 mysql 콘솔에 대한 설정이 전부다. 이제 서버를 시작해주고 보안 설정을 해준다.

]# systemctl start mariadb.service
]# systemctl enable mariadb.service
]# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): <- 그냥 엔터
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] Y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] Y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] Y
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] Y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] Y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!
]#

mysql_secure_installation 명령어를 이용하면 root 관리자 비밀번호와 간단한 보안설정도 함께 할 수 있다. 이제 redmine 을위한 데이터베이스를 생성하고 접속 계정을 만들어 준다.

> use mysql;
Database changed
> CREATE DATABASE redmine CHARACTER SET utf8 COLLATE utf8_general_ci;
Query OK, 1 row affected (0.00 sec)
> CREATE USER 'redmine'@'localhost' IDENTIFIED BY 'HS79aB';
Query OK, 0 rows affected (0.00 sec)
> CREATE USER 'redmine'@'127.0.0.1' IDENTIFIED BY 'HS79aB';
Query OK, 0 rows affected (0.00 sec)
> GRANT ALL PRIVILEGES ON redmine.* TO 'redmine'@'localhost';
Query OK, 0 rows affected (0.00 sec)
> GRANT ALL PRIVILEGES ON redmine.* TO 'redmine'@'127.0.0.1';
Query OK, 0 rows affected (0.00 sec)
> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

로컬에서만 접속되도록 하였다. 이로서 redmine 설치를 위한 Mariadb 설치 설정은 모두 끝났다.

Ruby 2.7 컴파일 설치

Redmine 4.2 를 사용하기 위해서는 Ruby 2.7 이 필요로 한다. 컴파일 설치를 해야 하는데, 먼저 다음과 같이 컴파일 환경을 만들어 준다.

]# yum -y install gcc g++ cpp gcc-c++ openssl-devel readline-devel zlib-devel curl-devel libyaml-devel libxslt-devel libyaml-devel libxml2-devel pcre-devel git make bzip2 libffi-devel autoconf bison jemalloc-devel automake patch glibc-devel gpg libtool gdbm-devel ImageMagick ImageMagick-devel

한가지, Ruby 는 jemalloc 를 사용하도록 할 것이다. CentOS 7 공식 패키지 저장소에는 이를 제공하지 않는다. EPEL 서드파티 레드햇 저장소를 활요하면 설치가 가능하다.

]# yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
]# yum install jemalloc-devel
]# yum-config-manager --disable epel

설치를 다하고나면 epel 저장소를 비활성화 해준다.

이제 Ruby 2.7 버전을 다운로드하고 다음과 같이 컴파일 설치 해준다.

]# curl -LO https://cache.ruby-lang.org/pub/ruby/2.7/ruby-2.7.3.tar.gz
]# tar xvzf ruby-2.7.3.tar.gz
]# cd ruby-2.7.3
]# configure --prefix=/opt/ruby-2.7.3 --with-jemalloc
]# make
]# make install

Ruby 설치가 정상적으로 되었다면 이제 계정에서 Ruby 를 사용할 수 있도록 쉘 설정을 해준다.

]# vim $HOME/.bash_profile
# Ruby
RUBY_ROOT=/opt/ruby-2.7.3
RUBY_BIN=$RUBY_ROOT/bin
RUBY_INC=$RUBY_ROOT/include
RUBY_LIB=$RUBY_ROOT/lib

export LD_LIBRARY_PATH=$RUBY_LIB:/usr/local/lib:$LD_LIBRARY_PATH
export CPATH=$RUBY_INC:$CPATH

PATH=$RUBY_BIN:$PATH:$HOME/bin

export PATH
]# source $HOME/.bash_profile
]# ruby -v
ruby 2.7.3p183 (2021-04-05 revision 6847ee089d) [x86_64-linux]

이렇게 root 계정에서 ruby 가 인식이 된다.

Redmine 설치

Redmine 을 설치하기 위해서는 먼저 gem 을 설치해줘야 한다. gem 은 Ruby 에서 사용하는 플랫폼을 작성해주는 프로그램이다. 그런데, 여기서 또 생각해봐야 하는것이 이것을 이제 일반계정으로 만들것인지 아니면 전역적인 시스템에 설치할 것인지하는 것을 고려해야 한다.

나는 이것을 redmine 이라는 일반 계정을 생성해서 설치하기로 했다. ruby 는 전역적으로 설치했지만 redmine 은 계정을 생성해 시스템과 분리되도록 하였다.

gem 설치

이제 gem 을 설치해 준다. gem 은 Ruby 설치 디렉토리에 함께 설치 됨으로 root 계정으로 실행을 해준다.

]# curl -LO https://rubygems.org/rubygems/rubygems-3.2.17.tgz
]# tar xvzf rubygems-3.2.17.tgz
]# cd rubygems-3.2.17
]# ruby setup.rb
RubyGems installed the following executables:
        /opt/ruby-2.7.3/bin/gem
        /opt/ruby-2.7.3/bin/bundle
        /opt/ruby-2.7.3/bin/bundler

Ruby Interactive (ri) documentation was installed. ri is kind of like man 
pages for Ruby libraries. You may access it like this:
  ri Classname
  ri Classname.class_method
  ri Classname#instance_method
If you do not wish to install this documentation in the future, use the
--no-document flag, or set it as the default in your ~/.gemrc file. See
'gem help env' for details.

gem 을 이용해서 다음과 같이 bundler, chef ruby-shadow 설치를 진행해 준다.

]# gem install bundler chef ruby-shadow

또, mysql2 확장을 설치해준다. 일종의 드라이버라고 보면 된다.

]# gem install mysql2
Building native extensions. This could take a while...
Successfully installed mysql2-0.5.3
Parsing documentation for mysql2-0.5.3
Installing ri documentation for mysql2-0.5.3
Done installing documentation for mysql2 after 0 seconds
1 gem installed

계정 생성

다음과 같이 redmine 계정을 생성해 준다.

]# useradd -m -U -r -d /opt/redmine redmine
]# su - redmine
]$ vim $HOME/.bash_profile
# Ruby
RUBY_ROOT=/opt/ruby-2.7.3
RUBY_BIN=$RUBY_ROOT/bin
RUBY_INC=$RUBY_ROOT/include
RUBY_LIB=$RUBY_ROOT/lib

export LD_LIBRARY_PATH=$RUBY_LIB:/usr/local/lib:$LD_LIBRARY_PATH
export CPATH=$RUBY_INC:$CPATH

PATH=$RUBY_BIN:$PATH:$HOME/bin

export PATH
]$ source $HOME/.bash_profile

redmine 계정도 ruby 를 인식 시켜준다.

redmine 설치

이제 redmine 계정에 redmine 4.2 를 다운로드하고 설치해 준다.

]$ curl -LO https://www.redmine.org/releases/redmine-4.2.1.tar.gz
]$ tar xvzf redmine-4.2.1.tar.gz
]$ cd redmine-4.2.1
]$ cp config/configuration.yml.example config/configuration.yml
]$ cp config/database.yml.example config/database.yml
]$ vim config/database.yml
production:
  adapter: mysql2
  database: redmine
  host: localhost
  username: redmine
  password: "HS79aB"
  # Use "utf8" instead of "utfmb4" for MySQL prior to 5.7.7
  encoding: utf8

이제 구동에 필요한 패키지들을 설치해 준다.

]$ bundle install --without development test postgresql sqlite 

쿠키 암호화를 위한 시크릿 토큰을 생성해 준다.

]$ bundle exec rake generate_secret_token

데이터베이스를 생성해 준다.

]$ RAILS_ENV=production bundle exec rake db:migrate

기본 언어를 한국어로 설정해 준다.

]$ RAILS_ENV=production bundle exec rake redmine:load_default_data

Select language: ar, az, bg, bs, ca, cs, da, de, el, en, en-GB, es, es-PA, et, eu, fa, fi, fr, gl, he, hr, hu, id, it, ja, ko, lt, lv, mk, mn, nl, no, pl, pt, pt-BR, ro, ru, sk, sl, sq, sr, sr-YU, sv, th, tr, uk, vi, zh, zh-TW [en] ko
====================================
Default configuration data loaded.

이제 모든게 완료 됐다. Redmine 을 다음과 같이 구동할 수 있다.

]$ bundle exec rails server webrick -e production -b 0.0.0.0 &
=> Rails 5.2.5 application starting in production on http://0.0.0.0:3000
=> Run rails server -h for more startup options
[2021-05-16 18:18:18] INFO  WEBrick 1.6.1
[2021-05-16 18:18:18] INFO  ruby 2.7.3 (2021-04-05) [x86_64-linux]
[2021-05-16 18:18:18] INFO  WEBrick::HTTPServer#start: pid=32410 port=3000

이제 브라우져에서 3000 포트로 접속을 시도해 본다. 만일 안된다면 CentOS 7 의 firewalld 서비스를 중지 시키고 다시해본다.

nginx 연동

redmine 의 자체 웹서버를 이용하는게 아니라 nginx 를 이용하는 방법이 있다. 이를 위해서 passenger 라는 프로그램이 필요한데, 이를 먼저 설치해 준다.

먼저 root 계정으로 gem 를 이용해서 passenger 를 설치해 준다.

]# gem install passenger

이제 passenger 프로그램을 이용해서 passenger-nginx 모듈을 설치해주는데, 이게 passenger 가 알아서 nginx 를 다운로드 받아서 컴파일 설치까지 해준다.

]# passenger-install-nginx-module
Please specify a prefix directory [/opt/nginx]:
The Nginx configuration file (/opt/nginx/conf/nginx.conf)
must contain the correct configuration options in order for Phusion Passenger
to function correctly.

This installer has already modified the configuration file for you! The
following configuration snippet was inserted:

  http {
      ...
      passenger_root /opt/ruby-2.7.3/lib/ruby/gems/2.7.0/gems/passenger-6.0.8;
      passenger_ruby /opt/ruby-2.7.3/bin/ruby;
      ...
  }

After you start Nginx, you are ready to deploy any number of Ruby on Rails
applications on Nginx.

Press ENTER to continue.

명령어를 실행하면 이것저것 물어보는데, 설치 모듈에는 python 을 빼고 ruby 만 되도록 했고 설치는 커스텀이 아닌 그냥 1번으로 설치를 진행 했다. 디렉토리는 /opt/nginx 기본값을 사용했다.

컴파일이 모두 정상적으로 진행이 되면 위와같이 설정 안내가 간단하게 나온다.

nginx.conf 파일 설정

기본적인 설정만 되어 있어서 redmine 을 위한 설정을 다음과 같이 해준다.

]# mkdir -p /opt/nginx/run/passenger-instreg
]# vim /opt/nginx/conf/nginx.conf
# redmine 계정을 이용함으로 프로세스가 redmine 으로 동작하도록 한다.
user  redmine;
worker_processes  auto;

error_log  logs/error.log;

pid        run/nginx.pid;

events {
    use epoll;
    worker_connections  1024;
    multi_accept on;
}

http {
    passenger_root /opt/ruby-2.7.3/lib/ruby/gems/2.7.0/gems/passenger-6.0.8;
    passenger_ruby /opt/ruby-2.7.3/bin/ruby;
    passenger_instance_registry_dir /opt/nginx/run/passenger-instreg;

    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    tcp_nopush        on;
    tcp_nodelay        on;
    keepalive_timeout  65;

    server {
        listen       80;
        server_name  192.168.96.11;

        # 파일 전송 사이즈
        client_max_body_size 64M; 

        #body와 header의 버퍼 크기 설정
        client_body_buffer_size 10K; 
        client_header_buffer_size 1k; 
        large_client_header_buffers 2 1k; 

        # 페이지 로딩이 일정시간 넘어가면 서버와의 연결을 끊도록 설정
        client_body_timeout 12; 
        client_header_timeout 12; 
        send_timeout 10;

        # 정적 파일 압축 기능 사용 설정
        gzip on;
        # 압축율(1~9)
        gzip_comp_level 6;
        # 압축 대상 최소 크기
        gzip_min_length 1024;
        # 압축 대상 컨텐츠. MIME 타입으로 설정
        gzip_types text/plain text/css application/x-javascript application/json text/javascript text/xml application/xml image/png image/jpeg image/jpg image/gif;
        # 클라이언트 캐쉬 설정.
        location ~* .(jpg|jpeg|png|gif|ico|css|js)$ { 
                expires 7d; 
                access_log off; 
        }

        access_log  logs/redmine.access.log;
        error_log  logs/redmine.error.log;
        # redmine 홈 디렉토리
        root /opt/redmine/redmine-4.2.1/public;
        # passenger 기능 활성화
        passenger_enabled on;
    }

}
# vim: syntax=nginx ts=4 sw=4 sts=4 sr noet
]# /opt/nginx/sbin/nginx -t
nginx: the configuration file /opt/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /opt/nginx/conf/nginx.conf test is successful
]# /opt/nginx/sbin/nginx

systemd 등록

nginx 를 systemd 에 등록 해보자. 다음과 같이 파일을 작성 한다.

]# vim /etc/systemd/system/nginx.service
# Stop dance for nginx
# =======================
#
# ExecStop sends SIGSTOP (graceful stop) to the nginx process.
# If, after 5s (--retry QUIT/5) nginx is still running, systemd takes control
# and sends SIGTERM (fast shutdown) to the main process.
# After another 5s (TimeoutStopSec=5), and if nginx is alive, systemd sends
# SIGKILL to all the remaining processes in the process group (KillMode=mixed).
#
# nginx signals reference doc:
# http://nginx.org/en/docs/control.html
#
[Unit]
Description=A high performance web server and a reverse proxy server
After=network.target

[Service]
Type=forking
PIDFile=/opt/nginx/run/nginx.pid
ExecStartPre=/opt/nginx/sbin/nginx -t -q -g 'daemon on; master_process on;'
ExecStart=/opt/nginx/sbin/nginx -g 'daemon on; master_process on;'
ExecReload=/opt/nginx/sbin/nginx -g 'daemon on; master_process on;' -s reload
ExecStop=/opt/nginx/sbin/nginx -g 'daemon on; master_process on;' -s stop
TimeoutStopSec=5
KillMode=mixed

[Install]
WantedBy=multi-user.target

이제 systemd 유닛을 활성화 해주고 시작해준다.

]# systemctl enable nginx.service
]# systemctl start nginx.service

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다