Vagrant 使用数据库cookbook与Chef创建数据库时出错

Vagrant 使用数据库cookbook与Chef创建数据库时出错,vagrant,chef-infra,chef-solo,Vagrant,Chef Infra,Chef Solo,我正在用厨师索洛提供一个流浪者的便当/centos6.7。我正在使用berkself插件作为烹饪书的依赖项 我的项目文件夹如下所示: |── Vagrantfile |── cookbooks └── my_cookbook |── Berksfile |── metadata.rb ... 在我的vagrant文件中(这是bento/centos6.7的默认值加上以下配置) 在mymetadata.rb中 depends 'mysql2_chef_ge

我正在用厨师索洛提供一个流浪者的便当/centos6.7。我正在使用
berkself插件
作为烹饪书的依赖项

我的项目文件夹如下所示:

|── Vagrantfile
|── cookbooks
    └── my_cookbook
        |── Berksfile
        |── metadata.rb
...
在我的
vagrant文件中
(这是
bento/centos6.7的默认值
加上以下配置)

在my
metadata.rb中

depends 'mysql2_chef_gem', '~> 1.1'
depends 'database', '~> 5.1'
当我提供我的流浪者机器时,我得到以下错误:

Error executing action `create` on resource 'mysql_database[my_database]'

Mysql2::Error
-------------
Lost connection to MySQL server at 'reading initial communication packet', system error: 110
PS:它在
bento/centos7.2上运行非常完美

编辑:以下是数据库创建部分:

# Install the MySQL client
mysql_client 'default' do
  action :create
end

# Configure the MySQL service
mysql_service 'default' do
  initial_root_password node['webserver']['database']['root_password']
  action [:create, :start]
end

# Install the mysql2 Ruby gem
mysql2_chef_gem 'default' do
  action :install
end

mysql_database node['webserver']['database']['db_name'] do
  connection(
    :host     => node['webserver']['database']['host'],
    :username => node['webserver']['database']['root_username'],
    :password => node['webserver']['database']['root_password']
   )
  action :create
end

编辑2:它在
便当/centos7.2
上不起作用。它没有崩溃,但MySQL似乎已经死机,运行的
sudosystemctl start mysqld
挂起

由于我使用了许多新东西(我对Chef也是新手),所以我认为问题来自不同的来源(不稳定的、糟糕的文件集成等)

事实证明,我只是没有明确说明:

登录到机器并键入mysql(没有额外参数)将失败。您需要使用mysql-S/var/run/mysql-foo/mysqld.sock通过套接字显式连接,或者使用mysql-h 127.0.0.1通过网络显式连接


你能在这里粘贴食谱中包含
mysql\u数据库
资源的部分吗?@zuazo我更新了我的问题,提供了代码。
# Install the MySQL client
mysql_client 'default' do
  action :create
end

# Configure the MySQL service
mysql_service 'default' do
  initial_root_password node['webserver']['database']['root_password']
  action [:create, :start]
end

# Install the mysql2 Ruby gem
mysql2_chef_gem 'default' do
  action :install
end

mysql_database node['webserver']['database']['db_name'] do
  connection(
    :host     => node['webserver']['database']['host'],
    :username => node['webserver']['database']['root_username'],
    :password => node['webserver']['database']['root_password']
   )
  action :create
end