Установка Redmine 3.4 на Centos 7 + Nginx
Инструкция по установку Redmine на Centos 7 + Nginx. Redmine будет работать на URL /redmine.
Установка RVM
Установка ключей:
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
Установка скрипта rvm
yum install which git svn -y
curl -sSL https://get.rvm.io | bash
Установка Ruby
rvm install 2.3.0
gem install bundler -v 1.17.3
Установка Redmine
Установите зависимости:
yum install ImageMagick-devel mysql-devel psmisc -y
Создайте пользователя redmine
groupadd redmine
useradd -g redmine redmine
Скачайте и распокуйте redmine в папку /srv
cd /srv
wget http://www.redmine.org/releases/redmine-3.4.11.tar.gz
tar xvf redmine-3.4.11.tar.gz
chown -R redmine:redmine redmine-3.4.11
cd redmine-3.4.11
Настройте redmine:
su redmine
cp config/configuration.yml.example config/configuration.yml
cp config/database.yml.example config/database.yml
Конфигурация БД. Выполните nano config/database.yml и пропишите свои параметры mysql.
production:
adapter: mysql2
database: redmine
host: localhost
username: root
password: ""
encoding: utf8
Допишите в конце файла nano config/environment.rb следующее содержание:
RedmineApp::Application.routes.default_scope = "/redmine"
# Initialize the Rails application
Rails.application.initialize!
Redmine::Utils::relative_url_root = "/redmine"
Создайте симлинк в папке publib. Папка public - это web root. Он указывается в nginx. Т.к. redmine работает на /redmine, то нужно создать симлинк redmine на папку public, чтобы от туда nginx смог раздать файлы js и css
cd public
ln -s . redmine
cd ..
Установите redmine:
bundle _1.17.3_ install --path vendor/bundle --without development test
bundle _1.17.3_ exec rake generate_secret_token
RAILS_ENV=production bundle _1.17.3_ exec rake db:migrate
RAILS_ENV=production bundle _1.17.3_ exec rake redmine:plugins:migrate
RAILS_ENV=production bundle _1.17.3_ exec rake tmp:cache:clear
Создайте скрипт запуска редмайн nano /etc/init.d/redmine
#!/bin/bash
#
### BEGIN INIT INFO
# Provides: redmine
# Required-Start: $local_fs $network $syslog $remote_fs
# Required-Stop: $local_fs $network $syslog $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start up the redmine web server
# Description: Redmine
### END INIT INFO
SCREEN_NAME="redmine"
BASE_DIR="/srv/redmine-3.4.11"
screen -wipe > /dev/null 2>&1
screen_exists(){
ch=`ps -ef | grep SCREEN | grep $1`
if [ -n "$ch" ]; then
return 0
else
return 1
fi
return 1
}
screen_create() {
ch=`ps -ef | grep SCREEN | grep $1`
if [ -n "$ch" ]; then
return 0
else
screen -A -m -d -S $1
fi
return 1
}
screen_destroy() {
ch=`ps -ef | grep SCREEN | grep $1 | awk '{print $2}'`
if [ -n "$ch" ]; then
kill $ch
else
return 0
fi
return 1
}
screen_send() {
CMD=$1
CMD="/usr/bin/screen -R $SCREEN_NAME -p 0 -X stuff '$CMD'$'\n'"
/bin/bash -c "$CMD"
}
screen_wait() {
let ret=0
TIMEOUT=$1
sleep 1
while [ $TIMEOUT -gt 0 ]; do
a=`cat ${BASE_DIR}/loop.run`
if [ "$a" == "0" ]; then
let ret=1
break
fi
echo $TIMEOUT
sleep 1
let TIMEOUT=${TIMEOUT}-1
done
}
service_start(){
screen_exists $SCREEN_NAME
ch=$?
if [ -n "$ch" ]; then
screen_create $SCREEN_NAME
screen_send "/bin/bash /etc/bashrc"
screen_send "/etc/profile.d/rvm.sh"
screen_send "sudo -u redmine service redmine loop"
else
echo "please stop $SERVICE_NAME"
fi
}
service_stop() {
echo "Terminate $SERVICE_NAME"
echo 0 > ${BASE_DIR}/loop.run
chown redmine:redmine ${BASE_DIR}/loop.run
killall ruby > /dev/null
screen_wait 10
screen_destroy $SCREEN_NAME
}
service_loop() {
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
RAILS_ENV=production
export RAILS_ENV
RAILS_GEM_VERSION=4.2.0 # this should match the result of typing 'rails -v'
export RAILS_GEM_VERSION
RAILS_ROOT=/redmine
export RAILS_ROOT
echo "Start $SERVICE_NAME"
echo 1 > ${BASE_DIR}/loop.run
while [ 1 ]; do
pushd $BASE_DIR
CMD="ruby bin/rails server webrick -e production -b 0.0.0.0 -p 3000 "
echo exec $CMD
$CMD
popd
a=`cat ${BASE_DIR}/loop.run`
echo $a
if [ "$a" == "1" ]; then
sleep 5
else
echo "exit"
echo 0 > ${BASE_DIR}/loop.run
break
fi
done
}
RETVAL=0
case "$1" in
start)
service_start
;;
stop)
service_stop
;;
restart)
service_stop
service_start
;;
loop)
service_loop
;;
a)
screen -D -r $SCREEN_NAME
;;
*)
echo "Usage: $0 {start|stop|restart|a}"
RETVAL=1
esac
exit $RETVAL
Добавьте redmine в автозапуск
chkconfig --add redmine
chkconfig redmine on
Интеграция Nginx
server {
listen 80;
server_name www.example.com;
root /var/www/html;
index index.html;
location /redmine {
try_files $uri @redmine;
root /srv/redmine-3.4.11/public;
}
location @redmine {
proxy_set_header HOST $host;
proxy_set_header Referer $http_referer;
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_set_header X-Forwarded-Port $server_port;
proxy_pass http://127.0.0.1:3000;
}
# Root access
location / {
root /var/www/html;
}
location ~* ^.+\.(css|js|jpg|jpeg|png|bmp|ico|svg)$ {
expires max;
}
}