Redmine安装过程疑难杂症

Redmine安装过程疑难杂症

Redmine diagnoses on installations.

  • 2016-12-05 更新: 在 Ubuntu 14.04 + ruby 2.3.3 下安装 Redmine 3.3.1。
  • 2014-09-05 更新: 进行了一次服务器搬迁,将原来位于香港的服务器搬回内地机房,redmine也要搬过来。因此增加了一些记录。

Redmine的安装,看 RedmineInstall 就可以搞定。但由于我对Ruby不熟悉,还是碰到了一些问题,下面是个记录。

安装平台的选择

Redmine 明确标注了可以使用哪几个版本的 Ruby 。但并没有说哪个版本比较好。我的感受是 1.9.3 好像比较靠谱。

  • Ubuntu 12.04 LTS/CentOS 6.3
  • Ruby 2.0.0/Ruby 1.9.3
  • Redmine 2.3.3

Ruby on Rails 安装

如何使用RVM在Ubuntu 12.04 LTS上安装Ruby on Rails

gem --version

如果在使用gem的时候碰到这样的提示:

1gem --version
2# /usr/local/lib/ruby/1.9.1/yaml.rb:84:in `<top (required)>':
3# It seems your ruby installation is missing psych (for YAML output).
4# To eliminate this warning, please install libyaml and reinstall your ruby.

这是在编译安装 ruby 的时候没有先安装 libyaml 所致。但是,即使是你安装 libyaml 之后重新安装 ruby ,这个问题还是不能解决。

正确的方法,是安装 libyam-devel 库。下面是在 CentOS 6.3 上安装:

1yum install libyaml-devel

然后,找到你先前编译 ruby 的目录,进入 ext/psych/ 文件夹,执行:

1ruby extconf.rb make make install
2# checking for yaml.h... yes
3# checking for yaml_get_version() in -lyaml... yes
4# creating Makefile

然后再执行一次 make install 。如果你已经 clean 了原来的编译内容,那么则需要重新编译。

1make install
2# compiling to_ruby.c
3# compiling parser.c
4# compiling psych.c
5# compiling emitter.c
6# compiling yaml_tree.c
7# linking shared-object psych.so
8# /usr/bin/install -c -m 0755 psych.so /usr/local/lib/ruby/site_ruby/1.9.1/x86_64-linux
9# installing default psych libraries

再次执行 gem -v ,发现 warning 已经消失了。

bundle install

如果碰到 mysql2 问题,就像这样:

Installing mysql2 (0.3.11) with native extensions Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension. /Users/rarneson/.rvm/rubies/ruby-1.9.3-p125/bin/ruby extconf.rb checking for rb_thread_blocking_region()... yes checking for rb_wait_for_single_fd()... yes checking for mysql_query() in -lmysqlclient... no checking for main() in -lm... yes checking for mysql_query() in -lmysqlclient... no checking for main() in -lz... yes checking for mysql_query() in -lmysqlclient... no checking for main() in -lsocket... no checking for mysql_query() in -lmysqlclient... no checking for main() in -lnsl... no checking for mysql_query() in -lmysqlclient... no checking for main() in -lmygcc... no checking for mysql_query() in -lmysqlclient... no *** extconf.rb failed ***

安装这几个包以解决 mysql2 问题:

1apt-get install mysql-client libmysqlclient-dev

如果碰到 pg 问题,就像这样:

Installing pg (0.17.0) Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension. /usr/local/rvm/rubies/ruby-2.0.0-p247/bin/ruby extconf.rb checking for pg_config... no No pg_config... trying anyway. If building fails, please try again with --with-pg-config=/path/to/pg_config checking for libpq-fe.h... no Can't find the 'libpq-fe.h header *** extconf.rb failed ***

安装这个包(我没拼错,就是libpq,不是libpg):

1apt-get install libpq-dev

如果碰到 rmagick 问题,就像这样:

Installing rmagick (2.13.2) Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension. /usr/local/rvm/rubies/ruby-2.0.0-p247/bin/ruby extconf.rb checking for Ruby version >= 1.8.5... yes checking for gcc... yes checking for Magick-config... no Can't install RMagick 2.13.2. Can't find Magick-config in /usr/local/rvm/gems/ruby-2.0.0-p247/bin:/usr/local/rvm/gems/ruby-2.0.0-p247@global/bin:/usr/local/rvm/rubies/ruby-2.0.0-p247/bin:/usr/local/rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games *** extconf.rb failed ***

安装这个几个包解决它:

1apt-get install imagemagick libmagickwand-dev

碰到上面两个问题,也可以不必安装相关的库,而是在安装的时候忽略它们:

1bundle install --without postgresql rmagick

如果上面的代码不管用,可能是在配置文件中指定了它们。你可以打开 config/database.yml 中有相关配置,例如我的:

 1#test_pgsql:
 2#  adapter: postgresql
 3#  database: redmine_test
 4#  host: localhost
 5#  username: postgres
 6#  password: "postgres"
 7#
 8#test_sqlite3:
 9#  adapter: sqlite3
10#  database: db/test.sqlite3

那么,可以同样忽略它们: --without test_pgsql test_sqlite3 。我的方法更简单粗暴(像上面),就是注释它们。

如果使用ruby 1.8.7,安装 redcarpet 出错

默认安装的redcarpet是3.0,如果出错可以选择安装2.0版本:

1gem install redcarpet -v 2.0

使用测试服务器正常,但 Apache 不能访问

你使用下面的代码,可以在 http://localhost:3000/ 正常访问 redmine.

1ruby script/rails server webrick -e production

但是,你使用 Apache 却不行,这一般是因为你被 SELinux 给禁止了。

例如我在 CentOS 6.3 下碰到的情况是:

18084 type=AVC msg=audit(1409905240.973:788834): avc:  denied  { execute_no_trans } for  pid=27260 comm="httpd" path="/usr/local/l     ib/ruby/gems/1.9.1/gems/passenger-4.0.50/buildout/agents/PassengerWatchdog" dev=dm-0 ino=1578438 scontext=unconfined_u:syste     m_r:httpd_t:s0 tcontext=unconfined_u:object_r:lib_t:s0 tclass=file

这些 log 可以在 /var/log/audit/audit.log 中查到。

最简单的方法是禁用 SELinux ,执行 setenforce 0 在系统运行状态取消,这样不必重启系统。

然后编辑 /etc/sysconfig/selinux 保证系统重启后也处于禁用状态:

 1# This file controls the state of SELinux on the system.
 2# SELINUX= can take one of these three values:
 3#     enforcing - SELinux security policy is enforced.
 4#     permissive - SELinux prints warnings instead of enforcing.
 5#     disabled - No SELinux policy is loaded.
 6#SELINUX=enforcing
 7SELINUX=disabled
 8# SELINUXTYPE= can take one of these two values:
 9#     targeted - Targeted processes are protected,
10#     mls - Multi Level Security protection.
11SELINUXTYPE=targeted

然后重启 Apache 即可生效。

当然,如果愿意折腾 SELinux(毕竟比较安全) ,那么可以安装 audit2allow 来允许模块通过。

在 CentOS 上找一下这个模块在哪里:

1yum provides \*/audit2allow

在 CentOS 上安装 audit2allow :

1yum install policycoreutils-python

然后,参考下面的文章自己折腾吧!

进入 Administration-Settings 报 HTTP 500 错误

我将 redmine 整体从另一台服务器搬迁过来之后,终于配置成功。进入后台正常,但进入管理员的设置界面则出现下面的提示:

Internal error

An error occurred on the page you were trying to access.
If you continue to experience problems please contact your Redmine administrator for assistance.

If you are the Redmine administrator, check your log files for details about the error.

解决方法:

查看 redmine 的 tmp/cache 目录,查看目录结构应该如下所示:

1[root@localhost redmine]# tree tmp/cache
2tmp/cache
3└── 900
4    └── 0F0
5        └── i18n%2Flanguages_options

停止 redmine,然后删除 tmp/cache 目录下的所有文件,再启动 redmine 。

然后 管理员设置界面 Administration-Settings 就可以进入了。

这时查看 tmp/cache 目录结构,会发现先前删除的文件和文件夹自动被创建了。

[passenger_native_support.so] trying to compile for the current user (redmine) and Ruby interpreter

App 25230 stderr:  [passenger_native_support.so] trying to compile for the current user (redmine) and Ruby interpreter...
App 25230 stderr:      (set PASSENGER_COMPILE_NATIVE_SUPPORT_BINARY=0 to disable)
App 25230 stderr:      Warning: compilation didn't succeed. To learn why, read this file:
App 25230 stderr:      /tmp/passenger_native_support-1bk9vkp.log
App 25230 stderr:  [passenger_native_support.so] finding downloads for the current Ruby interpreter...
App 25230 stderr:      (set PASSENGER_DOWNLOAD_NATIVE_SUPPORT_BINARY=0 to disable)
App 25230 stderr:      Could not download https://oss-binaries.phusionpassenger.com/binaries/passenger/by_release/5.0.30/rubyext-ruby-2.3.3-x86_64-linux.tar.gz: no download tool found (curl or wget required)
App 25230 stderr:      Trying next mirror...
App 25230 stderr:      Could not download https://s3.amazonaws.com/phusion-passenger/binaries/passenger/by_release/5.0.30/rubyext-ruby-2.3.3-x86_64-linux.tar.gz: no download tool found (curl or wget required)
App 25230 stderr:  [passenger_native_support.so] will not be used (can't compile or download)
App 25230 stderr:   --> Passenger will still operate normally.
App 25230 stderr: /usr/local/lib/ruby/gems/2.3.0/gems/htmlentities-4.3.1/lib/htmlentities/mappings/expanded.rb:465: warning: key "inodot" is duplicated and overwritten on line 466
App 25230 stderr: sh: 1: svn: not found
App 25230 stderr: sh: 1: env: not found

要解决这个问题,首先要确保使用当前的 ruby 版本编译依次 native 支持:

ruby $(which passenger-config) build-native-support

但是,由于权限的原因,passenger 在启动的时候,使用的是 nobody 权限。使用 passenger_user 参数可以调整权限。例如我的个人用户是 zrong ,我在 zrong 账户下使用 passenger-config build-native-support 编译成功,就需要在 nginx 的 redmine 站点配置文件中设置 passenger_user zrong; 即可。 这个 issue 中有更详细的说明。

Missing secret_token

App 25230 stderr: [ 2016-12-05 20:47:44.2447 25312/0x007fb5363b5f40(Worker 1) utils.rb:87 ]: *** Exception RuntimeError in Rack application object (Missing `secret_token` and `secret_key_base` for 'production' environment, set these values in `config/secrets.yml`) (pr    ocess 25312, thread 0x007fb5363b5f40(Worker 1)):
App 25230 stderr:   from /usr/local/lib/ruby/gems/2.3.0/gems/railties-4.2.7.1/lib/rails/application.rb:534:in `validate_secret_key_config!'
App 25230 stderr:   from /usr/local/lib/ruby/gems/2.3.0/gems/railties-4.2.7.1/lib/rails/application.rb:246:in `env_config'
App 25230 stderr:   from /usr/local/lib/ruby/gems/2.3.0/gems/railties-4.2.7.1/lib/rails/engine.rb:514:in `call'
App 25230 stderr:   from /usr/local/lib/ruby/gems/2.3.0/gems/railties-4.2.7.1/lib/rails/application.rb:165:in `call'
App 25230 stderr:   from /usr/local/lib/ruby/gems/2.3.0/gems/railties-4.2.7.1/lib/rails/railtie.rb:194:in `public_send'
App 25230 stderr:   from /usr/local/lib/ruby/gems/2.3.0/gems/railties-4.2.7.1/lib/rails/railtie.rb:194:in `method_missing'
App 25230 stderr:   from /usr/lib/ruby/vendor_ruby/phusion_passenger/rack/thread_handler_extension.rb:97:in `process_request'
App 25230 stderr:   from /usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler/thread_handler.rb:152:in `accept_and_process_next_request'
App 25230 stderr:   from /usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler/thread_handler.rb:113:in `main_loop'
App 25230 stderr:   from /usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler.rb:416:in `block (3 levels) in start_threads'
App 25230 stderr:   from /usr/lib/ruby/vendor_ruby/phusion_passenger/utils.rb:113:in `block in create_thread_and_abort_on_exception'

需要执行下面这条指令:

sudo bundle exec rake generate_secret_token

cannot load such file -- bundler/setup (LoadError)

我的 ruby 版本是 2.3.3 ,但运行 redmine 出现这样的错误:

[ 2016-12-05 22:00:13.3781 28180/7fd216076700 age/Cor/App/Implementation.cpp:304 ]: Could not spawn process for application /opt/redmine/redmine: An error occurred while starting up the preloader. 
Error ID: 545284a9 
Error details saved to: /tmp/passenger-error-deS5EL.html 
Message from application: cannot load such file -- bundler/setup (LoadError) 
/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require' 
/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require' 
/usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:430:in `activate_gem' 
/usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:297:in `block in run_load_path_setup_code' 
/usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:435:in `running_bundler' 
/usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:296:in `run_load_path_setup_code' 
/usr/share/passenger/helper-scripts/rack-preloader.rb:100:in `preload_app' 
/usr/share/passenger/helper-scripts/rack-preloader.rb:156:in `<module:App>' 
/usr/share/passenger/helper-scripts/rack-preloader.rb:30:in `<module:PhusionPassenger>' 
/usr/share/passenger/helper-scripts/rack-preloader.rb:29:in `<main>' 

这是由于路径错乱导致。由于 passenger 安装在 /usr/bin 中,它默认使用了系统自带的 ruby 1.9.1 。这需要修改 /etc/nginx/passenger.conf

将:

passenger_ruby /usr/bin/passenger_free_ruby; 

改为:

passenger_ruby /usr/local/bin/ruby; 

当然,你也可以指定其他的 ruby 版本,passenger_root 的值保持不变。

参考