NoPoint 【已解决】安装 redmine 过程中,安装 mysql2 依赖包遇到问题

joke1943 · 发布于 2015年1月08日 · 最后由 joke1943 回复于 2015年1月10日 · 6831 次阅读
96

这几天迁移redmine,我把redmine整体打包,数据库备份,然后在另一台服务解压,导入数据库。一步一步来,最后卡在mysql2驱动上了,苦恼。

简述安装过程和遇到的问题:

$ ruby script/rails server webrick -e production

=> Booting WEBrick
=> Rails 3.2.12 application starting in production on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
/usr/local/rvm/gems/ruby-2.1.4/gems/bundler-1.7.9/lib/bundler/rubygems_integration.rb:256:in `block in replace_gem': Please install the mysql adapter: `gem install activerecord-mysql-adapter` (mysql is not part of the bundle. Add it to Gemfile.) (LoadError)
    from /usr/local/rvm/gems/ruby-2.1.4/gems/activerecord-3.2.12/lib/active_record/connection_adapters/mysql_adapter.rb:5:in `<top (required)>'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:251:in `block in require'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:236:in `load_dependency'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:251:in `require'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/connection_specification.rb:50:in `resolve_hash_connection'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/connection_specification.rb:41:in `resolve_string_connection'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/connection_specification.rb:25:in `spec'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/connection_specification.rb:130:in `establish_connection'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/activerecord-3.2.12/lib/active_record/railtie.rb:82:in `block (2 levels) in <class:Railtie>'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/activesupport-3.2.12/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/activesupport-3.2.12/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/activesupport-3.2.12/lib/active_support/lazy_load_hooks.rb:26:in `block in on_load'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/activesupport-3.2.12/lib/active_support/lazy_load_hooks.rb:25:in `each'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/activesupport-3.2.12/lib/active_support/lazy_load_hooks.rb:25:in `on_load'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/activerecord-3.2.12/lib/active_record/railtie.rb:74:in `block in <class:Railtie>'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/railties-3.2.12/lib/rails/initializable.rb:30:in `instance_exec'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/railties-3.2.12/lib/rails/initializable.rb:30:in `run'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/railties-3.2.12/lib/rails/initializable.rb:55:in `block in run_initializers'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/railties-3.2.12/lib/rails/initializable.rb:54:in `each'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/railties-3.2.12/lib/rails/initializable.rb:54:in `run_initializers'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/railties-3.2.12/lib/rails/application.rb:136:in `initialize!'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/railties-3.2.12/lib/rails/railtie/configurable.rb:30:in `method_missing'
    from /home/chenx/home/chenx/redmine-2.2.3/config/environment.rb:14:in `<top (required)>'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:251:in `block in require'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:236:in `load_dependency'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:251:in `require'
    from /home/chenx/home/chenx/redmine-2.2.3/config.ru:3:in `block in <main>'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/rack-1.4.5/lib/rack/builder.rb:51:in `instance_eval'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/rack-1.4.5/lib/rack/builder.rb:51:in `initialize'
    from /home/chenx/home/chenx/redmine-2.2.3/config.ru:in `new'
    from /home/chenx/home/chenx/redmine-2.2.3/config.ru:in `<main>'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/rack-1.4.5/lib/rack/builder.rb:40:in `eval'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/rack-1.4.5/lib/rack/builder.rb:40:in `parse_file'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/rack-1.4.5/lib/rack/server.rb:200:in `app'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/railties-3.2.12/lib/rails/commands/server.rb:46:in `app'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/rack-1.4.5/lib/rack/server.rb:304:in `wrapped_app'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/rack-1.4.5/lib/rack/server.rb:254:in `start'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/railties-3.2.12/lib/rails/commands/server.rb:70:in `start'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/railties-3.2.12/lib/rails/commands.rb:55:in `block in <top (required)>'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/railties-3.2.12/lib/rails/commands.rb:50:in `tap'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/railties-3.2.12/lib/rails/commands.rb:50:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

这里有提示,大致意思是说mysql-adapter有问题。 然后看了一下配置database.yml文件,确定adapter是mysql2,然后gem安装mysql2

$ gem install mysql2

Building native extensions.  This could take a while...
ERROR:  Error installing mysql2:
    ERROR: Failed to build gem native extension.

    /usr/local/rvm/rubies/ruby-2.1.4/bin/ruby -r ./siteconf20150108-20748-qyfo6g.rb extconf.rb
checking for ruby/thread.h... yes
checking for rb_thread_call_without_gvl() in ruby/thread.h... yes
checking for rb_thread_blocking_region()... yes
checking for rb_wait_for_single_fd()... yes
checking for rb_hash_dup()... yes
checking for rb_intern3()... yes
checking for mysql_query() in -lmysqlclient... yes
checking for mysql.h... no
checking for mysql/mysql.h... yes
checking for errmsg.h... no
-----
errmsg.h is missing.  please check your installation of mysql and try again.
-----
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/usr/local/rvm/rubies/ruby-2.1.4/bin/ruby
    --with-mysql-dir
    --without-mysql-dir
    --with-mysql-include
    --without-mysql-include=${mysql-dir}/include
    --with-mysql-lib
    --without-mysql-lib=${mysql-dir}/lib
    --with-mysql-config
    --without-mysql-config
    --with-mysql-dir
    --without-mysql-dir
    --with-mysql-include
    --without-mysql-include=${mysql-dir}/include
    --with-mysql-lib
    --without-mysql-lib=${mysql-dir}/lib
    --with-mysqlclientlib
    --without-mysqlclientlib

extconf failed, exit code 1

Gem files will remain installed in /usr/local/rvm/gems/ruby-2.1.4/gems/mysql2-0.3.17 for inspection.
Results logged to /usr/local/rvm/gems/ruby-2.1.4/extensions/x86_64-linux/2.1.0/mysql2-0.3.17/gem_make.out

这里提示找不到errmsg.h 但是find了一下,系统里有

$ find / -name errmsg.h 

/usr/lib/errmsg.h
/usr/include/mysql/errmsg.h

迷茫了,十分苦恼,求助大家~!

问题补充: adapter用不了mysql2只能使用mysql,gem安装没问题,然后一运行,报错,同上。

2015-1-9

问题解决 由于之前成功搭建了Redmine-2.4.7,灵机一动,想到了解决方法。 将Redmine-2.4.7的 Gemfile 和 Gemfile.lock拷贝过来,替换Redmine-2.2.3目录下的 Gemfile 和 Gemfile.lock。 运行

$ruby script/rails server webrick -e production

=> Booting WEBrick
=> Rails 3.2.19 application starting in production on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_locales = false to avoid this message.
Exiting
/usr/local/rvm/gems/ruby-2.1.4/gems/activesupport-3.2.19/lib/active_support/dependencies.rb:317:in `rescue in depend_on': No such file to load -- iconv (LoadError)
    from /usr/local/rvm/gems/ruby-2.1.4/gems/activesupport-3.2.19/lib/active_support/dependencies.rb:312:in `depend_on'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/activesupport-3.2.19/lib/active_support/dependencies.rb:225:in `require_dependency'
    from /home/chenx/home/chenx/redmine-2.2.3/plugins/redmine_charts2/init.rb:11:in `block in <top (required)>'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/activesupport-3.2.19/lib/active_support/callbacks.rb:429:in `_run__2133299249465114693__prepare__2065706132915151216__callbacks'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/activesupport-3.2.19/lib/active_support/callbacks.rb:405:in `__run_callback'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/activesupport-3.2.19/lib/active_support/callbacks.rb:385:in `_run_prepare_callbacks'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/activesupport-3.2.19/lib/active_support/callbacks.rb:81:in `run_callbacks'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/actionpack-3.2.19/lib/action_dispatch/middleware/reloader.rb:74:in `prepare!'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/actionpack-3.2.19/lib/action_dispatch/middleware/reloader.rb:48:in `prepare!'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/railties-3.2.19/lib/rails/application/finisher.rb:47:in `block in <module:Finisher>'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/railties-3.2.19/lib/rails/initializable.rb:30:in `instance_exec'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/railties-3.2.19/lib/rails/initializable.rb:30:in `run'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/railties-3.2.19/lib/rails/initializable.rb:55:in `block in run_initializers'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/railties-3.2.19/lib/rails/initializable.rb:54:in `each'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/railties-3.2.19/lib/rails/initializable.rb:54:in `run_initializers'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/railties-3.2.19/lib/rails/application.rb:136:in `initialize!'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/railties-3.2.19/lib/rails/railtie/configurable.rb:30:in `method_missing'
    from /home/chenx/home/chenx/redmine-2.2.3/config/environment.rb:14:in `<top (required)>'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/activesupport-3.2.19/lib/active_support/dependencies.rb:251:in `block in require'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/activesupport-3.2.19/lib/active_support/dependencies.rb:236:in `load_dependency'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/activesupport-3.2.19/lib/active_support/dependencies.rb:251:in `require'
    from /home/chenx/home/chenx/redmine-2.2.3/config.ru:3:in `block in <main>'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/rack-1.4.5/lib/rack/builder.rb:51:in `instance_eval'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/rack-1.4.5/lib/rack/builder.rb:51:in `initialize'
    from /home/chenx/home/chenx/redmine-2.2.3/config.ru:in `new'
    from /home/chenx/home/chenx/redmine-2.2.3/config.ru:in `<main>'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/rack-1.4.5/lib/rack/builder.rb:40:in `eval'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/rack-1.4.5/lib/rack/builder.rb:40:in `parse_file'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/rack-1.4.5/lib/rack/server.rb:200:in `app'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/railties-3.2.19/lib/rails/commands/server.rb:46:in `app'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/rack-1.4.5/lib/rack/server.rb:304:in `wrapped_app'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/rack-1.4.5/lib/rack/server.rb:254:in `start'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/railties-3.2.19/lib/rails/commands/server.rb:70:in `start'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/railties-3.2.19/lib/rails/commands.rb:55:in `block in <top (required)>'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/railties-3.2.19/lib/rails/commands.rb:50:in `tap'
    from /usr/local/rvm/gems/ruby-2.1.4/gems/railties-3.2.19/lib/rails/commands.rb:50:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

仔细看了一下,大致意思是说找不依赖iconv。然后继续gem安装iconv,问题依旧。 vim打开Gemfile,在开始gem声明变量后,增加一句gem "iconv", "~> 1.0.3"

source 'https://rubygems.org'

gem "rails", "3.2.19"
gem "rake", "~> 10.1.1"
gem "jquery-rails", "~> 2.0.2"
gem "coderay", "~> 1.1.0"
gem "fastercsv", "~> 1.5.0", :platforms => [:mri_18, :mingw_18, :jruby]
gem "builder", "3.0.0"

#add 
gem "iconv", "~> 1.0.3"
#add end

.......

然后启动服务,正常了,问题解决。 感谢各位对我的回复,十分感谢!!!!

此贴已暂时被屏蔽!

以下几种情况的帖子可能会进入此节点:

  1. 标题/正文描述不清不楚;
  2. 无意义的发帖;
  3. 存在广告嫌疑;
  4. 招聘信息描述不清楚,未按照招聘节点的要求发帖,或职位信息不符合社区用户群需求;
  5. 新注册的帐号发布产品推广贴是不允许的哦,付出和回报是相等的,当然如果你的产品确实非常有意思,或是和 Ruby 有关的东西,是不会进入这个栏目的。
  6. 太过弱的提问会被直接转移到此节点,请在提问前多尝试,多搜索;
  7. 理论上,不允许发布 QQ 群、微信群之类讨论群。

如果你发现你的帖子到了此节点下面,请自我检查反省,并修改帖子内容。


招聘贴被转移到此节点原因

警告: 以后招聘贴不符合要求,直接移动到本节点,管理员不再回复,如认真阅读,继续新发同样格式的贴,将会被禁用账号!

  • 排版请按 Ruby China 的 Markdown 格式要求,具体请认真阅读: 排版指导,并参考 这篇招聘 的排版;
  • 招聘内容过少,缺少公司介绍,产品介绍,职位介绍,或待遇,工作地,联系方式等必要信息;
  • 重复发帖(一家公司每月限制只能发一次招聘);
  • 专业不对口(个别不对口,但有特点的,我们会放过);

如果你有时间,请阅读 招聘栏目详细说明


学会如何合理提问,请阅读:https://ruby-china.org/topics/24325

当你修改好以后,可以回帖 @huacnlee@Rei@lgn21st 任何一人,我们将会审核,通过以后才可恢复到其他节点。

注!多次发现广告嫌疑的帐号,将会被禁用帐号。

共收到 7 条回复
4215

参考这个,需要一些开发包。http://stackoverflow.com/questions/3608287/error-installing-mysql2-failed-to-build-gem-native-extension

这个不难解决,放宽心。

另外,以后可以谷歌搜索error部分:

ERROR: Error installing mysql2: ERROR: Failed to build gem native extension.

通常SO上有答案,而且一般都在谷歌头条。

gem里如果包含c代码都需要编译,还需要一些依赖的包,安装一下就解决了。

96

#1楼 @chenge 试了,没有作用啊

$sudo yum install mysql-devel

Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Setting up Install Process
Package mysql-devel-5.1.73-3.el6_5.x86_64 already installed and latest version
Nothing to do

会不会是mysql版本的问题,另外我这里是Rails 3.2.12 + ruby 2.1.4p265。

96

我安装Redmine是2.6.0,把配置文件database.yml改成mysql就可以了 但我部署成功,添加一个用户,包含中文名的用户,就报错了。 ActionView::Template::Error (incompatible character encodings: UTF-8 and ASCII-8BIT):

详情查看我的帖子 https://ruby-china.org/topics/23615

96

希望以后多多交流

96

#3楼 @wilask 我这里是老版本了redmine-2.2.3,本来想升级到Redmine-2.4.7但是发现多了几个表,用户认证,用户权限代码都重构了,以前的数据没法用了,所以只能迁移,放弃升级了。

De6df3

请不要重复发帖说同样的内容

96

#6楼 @huacnlee 只是重新编辑了一下而已,顺便把解决过程更新上来,方便大家参考。。。。

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册