部署 求助!Mina 部署中,mysql2 安装问题

Kevin_wang · December 17, 2017 · Last by Kevin_wang replied at December 20, 2017 · 1889 hits

碰到一个问题,缠了我一天多了!问下大家有没有人碰到过类似情况

环境: 阿里云 centos 6.5 ruby 2.2.5 rails 5.1.4

想配置 nginx+puma+mina 的一个 rails 环境,但是在 mina 部分出了问题,大家帮忙看看

我这边直接用 yum 装的 mysql5.6

mina 主要配置部分如下

task :remote_environment do
  invoke :'rvm:use', 'ruby-2.2.5@default'
end
desc "Deploys the current version to the server."
task :deploy do
  deploy do
    comment "Deploying #{fetch(:application_name)} to #{fetch(:domain)}:#{fetch(:deploy_to)}"
    invoke :'git:clone'
    invoke :'deploy:link_shared_paths'
    invoke :'bundle:install'
    invoke :'rails:db_migrate'
    invoke :'rails:assets_precompile'
    invoke :'deploy:cleanup'
end

在 bundle install 的时候有如下报错:

Fetching mysql2 0.4.9
 Installing mysql2 0.4.9 with native extensions
 Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

 current directory:
 /home/xxx/www/xxx/shared/vendor/bundle/ruby/2.2.0/gems/mysql2-0.4.9/ext/mysql2
 /home/xxx/.rvm/rubies/ruby-2.2.5/bin/ruby -r
 ./siteconf20171217-27165-1vu49lh.rb extconf.rb --with-mysql-config=/etc/my.cnf
 checking for rb_absint_size()... yes
 checking for rb_absint_singlebit_p()... yes
 checking for ruby/thread.h... yes
 checking for rb_thread_call_without_gvl() in ruby/thread.h... yes
 checking for rb_thread_blocking_region()... no
 checking for rb_wait_for_single_fd()... yes
 checking for rb_hash_dup()... yes
 checking for rb_intern3()... yes
 checking for rb_big_cmp()... yes
 -----
 Cannot execute mysql_config at /etc/my.cnf
 -----
 *** 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=/home/bingxin/.rvm/rubies/ruby-2.2.5/bin/$(RUBY_BASE_NAME)
  --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

这里提到

Cannot execute mysql_config at /etc/my.cnf

但是直接执行

gem install mysql2

是可以成功安装的。

这里有个问题我比较怀疑, 服务器上我是用 rvm 装的 ruby2.2.5.。但是在 mina bundle install 的时候,在 shared/vendor/bundle 中生成的 ruby 是 2.2.0 的。但是在 mina 当中的确是设置了 rvm,并且 mysql 的报错中也能看出来设置已经生效,这是什么情况???为什么是 2.2.0?。

不知道大家有没有遇到过类似情况?

我没在楼主的环境里部署过,所以我不知道怎么解决。不过有几个建议让部署难度低些:

  1. 用 Ubuntu LTS,16.04 源里有 Ruby 2.3。
  2. 不要用 RVM/rbenv,避免部署脚本和环境变量两个问题叠加。
  3. 不要用 mina,用 cap。
Reply to Rei

@Rei 好的,多谢!我会考虑你的意见😀

楼主试试 在 invoke :'bundle:install' 之前,先invoke :'rvm:use', 'ruby-2.2.5@default' 一下。

Reply to midwinter

Hi @midwinter , 首先非常感谢关注。 这个 rvm 的配置我已经加上了,在 remote_environment 里,而且我在incoke :'bundle:install'之前曾经试过用 command 打印 ruby 的版本等,可以确认 rvm 的设置已经生效

Hi @Rei 今天我又仔细找了找这个问题的原因,发现了两个事儿,一个是无论是否用 rvm,ruby 2.2.5 下的 include 目录下都会是 ruby2.2.0,这个之前还真没注意过,真是吃一堑长一智啊,有机会一定好好看看这里... 另外,以上的这个问题我试了 N 种情况,最后发现是 bundle install 的问题。凡是直接 bundle install 的话,就会报这个Cannot execute mysql_config at /etc/my.cnf的错误导致mysql2安装失败。但是如果直接gem install mysql2 -v '0.4.9'的话,则会安装成功。不知道这个问题 @Rei 你知道是什么情况吗

先看看这个

Check the mkmf.log file for more details.

@lithium4010 在 mkmf.log 里到check for rb_big_cmp(), 后面就没有了

下面是文件的最后

have_func: checking for rb_big_cmp()... -------------------- yes

"gcc -o conftest -I/home/x'x'x/.rvm/rubies/ruby-2.2.5/include/ruby-2.2.0/x86_64-linux -I/home/xxx/.rvm/rubies/ruby-2.2.5/include/ruby-2.2.0/ruby/backward -I/home/xxx/.rvm/rubies/ruby-2.2.5/include/ruby-2.2.0 -I.     -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -Wdeprecated-declarations -Wno-packed-bitfield-compat  -fPIC conftest.c  -L. -L/home/xxx/.rvm/rubies/ruby-2.2.5/lib -Wl,-R/home/xxx/.rvm/rubies/ruby-2.2.5/lib -L. -fstack-protector -rdynamic -Wl,-export-dynamic     -Wl,-rpath,'/../lib' -Wl,-R'/../lib' -lruby  -lpthread -lrt -ldl -lcrypt -lm   -lc"
checked program was:
/* begin */
 1: #include "ruby.h"
 2:
 3: /*top*/
 4: extern int t(void);
 5: int main(int argc, char **argv)
 6: {
 7:   if (argc > 1000000) {
 8:     printf("%p", &t);
 9:   }
10:
11:   return 0;
12: }
13: int t(void) { void ((*volatile p)()); p = (void ((*)()))rb_big_cmp; return 0; }
/* end */

--------------------
8 Floor has deleted

直接上服务器 bundle 能成功吗?

@lithium4010 不能,直接在用户目录下 git clone 一个项目 bundle install 都失败了,同样的错误

You need to Sign in before reply, if you don't have an account, please Sign up first.