简体   繁体   English

在OS X上使用Vagrant / chef-solo设置VM时的MySQL问题

[英]MySQL issues when setting up a VM with Vagrant/chef-solo on OS X

I've installed VirtualBox, Vagrant and chef-solo on my MBP laptop running Mountain Lion. 我已经在运行Mountain Lion的MBP笔记本电脑上安装了VirtualBox,Vagrant和Chef-solo。 I've downloaded recipes from opscode and have 'vagrant up' working. 我已经从opscode下载了食谱,并且“无用”地工作了。 The VM is successfully create and I get a mostly working LAMP stack. VM已成功创建,并且我得到了一个工作正常的LAMP堆栈。

Where I am stuck is creating a database and user to access the database. 我遇到的困难是创建数据库和用户访问数据库。

What I've done: Created a development folder that includes Vagrantfile and the directory cookbooks. 我已经完成的工作:创建了一个包含Vagrantfile和目录Cookbook的开发文件夹。 In cookbooks I have 在食谱中,我有

README.md
apache2
apt
aws
build-essential
database
hnnapp
mysql
openssl
php
postgresql
xfs
xml

'hnnapp' contains my own recipe to launch my virtual machine. “ hnnapp”包含我自己的配方以启动我的虚拟机。 I used knife to initialize the folder and then edited metadata.rb to include 我用刀初始化了文件夹,然后编辑了metadata.rb以包含

depends "apt"
depends "apache2"
depends "database"
depends "mysql"
depends "xml"
depends "openssl"
depends "php"
depends "build-essential"

and in recipes/default.rb I have include 在配方/ default.rb中,我包括

include_recipe "apt"
include_recipe "apache2"
include_recipe "xml"
include_recipe "openssl"
include_recipe "database::mysql"
include_recipe "mysql"
include_recipe "mysql::client"
include_recipe "mysql::server"
include_recipe "mysql::ruby"
include_recipe "php"
include_recipe "php::module_mysql"
include_recipe "apache2::mod_php5"
include_recipe "apache2::mod_rewrite"

apache_site "default" do
    enable true
end

mysql_database node['hnnapp']['database'] do
    connection  ({:host => 'localhost', :username => 'root', :password => node['mysql']['server_root_password']})
    action :create
end

mysql_database_user node['hnnapp']['db_username'] do
    connection  ({:host => 'localhost', :username => 'root', :password => node['mysql']['server_root_password']})
    password node['hnnapp']['db_password']
    database_name node['hnnapp']['database']
    privileges [:select, :update, :insert, :cretae, :delete]
    action :create
end

Finally, my Vagrantfile includes 最后,我的Vagrantfile包括

config.vm.provision :chef_solo do |chef|
    chef.add_recipe "hnnapp"
    chef.json = {
      "hnnapp" => {
        "db_password" => "test", 
        "db_username" => "testuser",
        "database" => 'testdatabase'
      },
      "mysql" => {
        "server_root_password" => "098f6bcd4621d373cade4e832627b4f6",
        "server_debian_password" => "098f6bcd4621d373cade4e832627b4f6",
        "server_repl_password" => "098f6bcd4621d373cade4e832627b4f6"
      }
    }
  end

When I 'vagrant ssh' into the VM I see apache, php and mysql is installed. 当我“无用的ssh”进入虚拟机时,我看到安装了apache,php和mysql。 MySQL has no other databases except for test and information schema. MySQL除了测试和信息模式外没有其他数据库。 I can use 'mysql' to get into mysql client, but I have no privileges to create any databases or users. 我可以使用“ mysql”进入mysql客户端,但是我没有创建任何数据库或用户的特权。 sudo mysql doesn't work either. sudo mysql也不起作用。

I'd like to find out two things: 我想找出两件事:

  1. Am I going about this the right way? 我要这样做正确吗? Putting the right commands in the right files? 将正确的命令放在正确的文件中?
  2. What mistakes do I have in my scripts. 我的脚本中有什么错误。

Does it make any difference if you add :grant to your actions in the mysql_database_user block? 如果在mysql_database_user块中的动作中添加:grant,会有所不同吗?

action [:create, :grant]

I found this tutorial quite helpful with provisioning mysql with a user and privileges, although I am still a bit confused with the directory structure of chef-solo. 我发现本教程对于用用户和特权配置mysql很有帮助,尽管我仍然对Chef-solo的目录结构有些困惑。

http://misheska.com/blog/2013/06/23/getting-started-writing-chef-cookbooks-the-berkshelf-way-part2/ http://misheska.com/blog/2013/06/23/getting-started-writing-chef-cookbooks-the-berkshelf-way-part2/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM