一、背景介绍
为便于项目管理,内网安装redmine在团队内部试用
二、安装说明
1、参考文档:
http://www.redmine.org/projects/redmine/wiki/Redmine_on_CentOS_installation_HOWTO
http://blog.fity.cn/post/365/
http://jicki.blog.51cto.com/1323993/1336591
http://ruby-china.org/topics/5321
http://www.imagemagick.org/script/install-source.php#unix
2、安装nginx
具体安装过程略
3、安装Ruby
#安装依赖包
yum -y install zlib-devel curl-devel openssl-devel httpd-devel apr-devel apr-util-devel mysql-devel
#安装ruby
mkdir -p /usr/local/src/ruby
cd /usr/local/src/ruby/
wget http://cache.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p353.tar.gz
tar -zxvf ruby-2.0.0-p353.tar.gz
cd ruby-2.0.0-p353
./configure
make
make install
#配置路径
vi /etc/profile
export PATH="$PATH:/usr/local/bin"
4、安装RubyGems
cd /usr/local/src/ruby wget http://production.cf.rubygems.org/rubygems/rubygems-1.4.2.tgz tar zxvf rubygems-1.4.2.tgz cd rubygems-1.4.2 ruby setup.rb gem -v #RubyGems 镜像设置为taobao源 gem sources --remove https://rubygems.org/ gem sources -a http://ruby.taobao.org/ gem sources -l
5、安装rvm(http://rvm.io/) ,ruby版本管理工具,参照:http://ruby-china.org/wiki/rvm-guide
curl -L get.rvm.io | bash -s stable source /etc/profile.d/rvm.sh sed -i -e 's/ftp\.ruby-lang\.org\/pub\/ruby/ruby\.taobao\.org\/mirrors\/ruby/g' /usr/local/rvm/config/db
6、安装rake、rails和相关gems
yum install ruby-devel ruby-irb ruby-rdoc ruby-ri curl-devel ImageMagick ImageMagick-devel ImageMagick-c++-devel mysql-devel sqlite-devel gem install rake #报错 Fetching: rake-10.1.1.gem (100%) Successfully installed rake-10.1.1 1 gem installed Installing ri documentation for rake-10.1.1... ERROR: While executing gem ... (NoMethodError) undefined method `map' for Gem::Specification:Class #执行 升级至2.2.2 gem update --system #再重新执行 gem install rake gem install rdoc gem install rails -v=3.2.15 gem install sqlite3-ruby gem install bundler gem install rmagick gem install mysql2 //或gem install mysql,安装mysql适配器 bundle install --without development test
如何卸载高版本的rails http://www.cnblogs.com/cyttina/p/3467479.html
7、安装redmine
#下载redmine
mkdir -p /usr/local/src/redmine
cd /usr/local/src/redmine
#下载安装文件
wget http://rubyforge.org/frs/download.php/77242/redmine-2.4.0.tar.gz
tar zxvf redmine-2.4.0.tar.gz
#复制到web目录
mkdir -p /home/wwwroot/redmine
cp -av redmine-2.4.0/* /home/wwwroot/redmine
#创建redmine 所需的数据库
create database redmine character set utf8;
grant all privileges on redmine.* to 'redmineuser'@'localhost' identified by 'xxx';
#配置Redmine 数据库连接
cd /home/wwwroot/redmine/config
cp database.yml.example database.yml
vi database.yml
bundle install
rake generate_secret_token
RAILS_ENV=production rake db:migrate
RAILS_ENV=production rake redmine:load_default_data
8、使用unicorn部署rails应用
#安装unicorn
gem install unicorn
unicorn配置文件,保存路径:/home/wwwroot/redmine/config/unicorn.rb
worker_processes 4
app_root = File.expand_path("../..", __FILE__)
working_directory app_root
# Listen on fs socket for better performance
listen "/tmp/unicorn.sock", :backlog => 64
listen 4096, :tcp_nopush => false
# Nuke workers after 30 seconds instead of 60 seconds (the default)
timeout 30
# App PID
pid "#{app_root}/tmp/pids/unicorn.pid"
# By default, the Unicorn logger will write to stderr.
# Additionally, some applications/frameworks log to stderr or stdout,
# so prevent them from going to /dev/null when daemonized here:
stderr_path "#{app_root}/log/unicorn.stderr.log"
stdout_path "#{app_root}/log/unicorn.stdout.log"
# To save some memory and improve performance
preload_app true
GC.respond_to?(:copy_on_write_friendly=) and
GC.copy_on_write_friendly = true
# Force the bundler gemfile environment variable to
# reference the Сapistrano "current" symlink
before_exec do |_|
ENV["BUNDLE_GEMFILE"] = File.join(app_root, 'Gemfile')
end
before_fork do |server, worker|
# 参考 http://unicorn.bogomips.org/SIGNALS.html
# 使用USR2信号,以及在进程完成后用QUIT信号来实现无缝重启
old_pid = app_root + '/tmp/pids/unicorn.pid.oldbin'
if File.exists?(old_pid) && server.pid != old_pid
begin
Process.kill("QUIT", File.read(old_pid).to_i)
rescue Errno::ENOENT, Errno::ESRCH
# someone else did our job for us
end
end
# the following is highly recomended for Rails + "preload_app true"
# as there's no need for the master process to hold a connection
defined?(ActiveRecord::Base) and
ActiveRecord::Base.connection.disconnect!
end
after_fork do |server, worker|
# 禁止GC,配合后续的OOB,来减少请求的执行时间
GC.disable
# the following is *required* for Rails + "preload_app true",
defined?(ActiveRecord::Base) and
ActiveRecord::Base.establish_connection
end
nginx配置文件
user nginx;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
gzip on;
upstream ruby_backend {
server unix:/tmp/unicorn.sock fail_timeout=0;
}
server {
listen 80;
server_name redmine.xxx.com;
root /home/wwwroot/redmine/public;
try_files $uri/index.html $uri.html $uri @unicorn;
location @unicorn {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_buffering on;
proxy_pass http://ruby_backend;
}
}
server {
listen 80;
server_name redmine.xxx.com;
root /home/wwwroot/redmine/public;
location ~ ^/(assets)/ {
root /home/wwwroot/redmine/public;
#gzip_static on; # to serve pre-gzipped version
expires max;
add_header Cache-Control public;
}
}
}
9、启动unicorn服务,在/home/wwwroot/redmine目录运行
# 后台启动
bundle exec unicorn_rails -c config/unicorn.rb -E production -D
# 前台启动
bundle exec unicorn_rails -c config/unicorn.rb -E production
三、升级至2.5.0
== Upgrading
1. Uncompress the program archive in a new directory
2. Copy your database settings (RAILS_ROOT/config/database.yml) and your configuration file (RAILS_ROOT/config/configuration.yml) into the new config directory Note: before Redmine 1.2, SMTP configuration was stored in config/email.yml. It should now be stored in config/configuration.yml.
3. Copy the RAILS_ROOT/files directory content into your new installation This directory contains all the attached files.
4. Copy the folders of the installed plugins and themes into new installation Plugins must be stored in the [redmine_root]/plugins directory Themes must be stored in the [redmine_root]/public/themes directory WARNING: plugins from your previous Redmine version may not be compatible with the Redmine version you’re upgrading to.
5. Install the required gems by running: bundle install –without development test If ImageMagick is not installed on your system, you should skip the installation of the rmagick gem using: bundle install –without development test rmagick Only the gems that are needed by the adapters you’ve specified in your database configuration file are actually installed (eg. if your config/database.yml uses the ‘mysql2’ adapter, then only the mysql2 gem will be installed). Don’t forget to re-run `bundle install` when you change config/database.yml for using other database adapters. If you need to load some gems that are not required by Redmine core (eg. fcgi), you can create a file named Gemfile.local at the root of your redmine directory. It will be loaded automatically when running `bundle install`.
6. Generate a session store secret Redmine stores session data in cookies by default, which requires a secret to be generated. Under the new application directory run: rake generate_secret_token DO NOT REPLACE OR EDIT ANY OTHER FILES.
7. Migrate your database If you are upgrading to Rails 2.3.14 as part of this migration, you need to upgrade the plugin migrations before running the plugin migrations using: rake db:migrate:upgrade_plugin_migrations RAILS_ENV=”production” Please make a backup before doing this! Under the new application directory run: rake db:migrate RAILS_ENV=”production” If you have installed any plugins, you should also run their database migrations using: rake db:migrate_plugins RAILS_ENV=”production”
8. Clear the cache and the existing sessions by running: rake tmp:cache:clear rake tmp:sessions:clear
9. Restart the application server (e.g. mongrel, thin, passenger)
10. Finally go to “Administration -> Roles & permissions” to check/set permissions for new features, if any
升级后的启动脚本
# 后台启动
unicorn_rails -c /home/wwwroot/redmine-2.5.0/config/unicorn.rb -E production -D
# 前台启动
unicorn_rails -c /home/wwwroot/redmine-2.5.0/config/unicorn.rb -E production
四、参考资料
1、unicorn简介
http://ruby-china.org/topics/4709
2、rails unicorn nginx 部署
http://blog.58share.com/?p=201
3、github网站使用unicorn部署的介绍
https://github.com/blog/517-unicorn
4、自动化代码部署、代码回滚、命令执行软件之capistrano http://dl528888.blog.51cto.com/2382721/1270670
五、配置说明
1、安装主题
Redmine自带的主题比较素,推荐安装Pepper主题:https://github.com/koppen/redmine-pepper-theme
#先安装git
yum install git
cd /home/wwwroot/redmine/public/themes/
git clone https://github.com/koppen/redmine-pepper-theme.git pepper