[英]Chef-solo and vagrant to automatically run an MySql script after install?
[英]MySQL issues when setting up a VM with Vagrant/chef-solo on OS X
我已经在运行Mountain Lion的MBP笔记本电脑上安装了VirtualBox,Vagrant和Chef-solo。 我已经从opscode下载了食谱,并且“无用”地工作了。 VM已成功创建,并且我得到了一个工作正常的LAMP堆栈。
我遇到的困难是创建数据库和用户访问数据库。
我已经完成的工作:创建了一个包含Vagrantfile和目录Cookbook的开发文件夹。 在食谱中,我有
README.md
apache2
apt
aws
build-essential
database
hnnapp
mysql
openssl
php
postgresql
xfs
xml
“ hnnapp”包含我自己的配方以启动我的虚拟机。 我用刀初始化了文件夹,然后编辑了metadata.rb以包含
depends "apt"
depends "apache2"
depends "database"
depends "mysql"
depends "xml"
depends "openssl"
depends "php"
depends "build-essential"
在配方/ 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
最后,我的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
当我“无用的ssh”进入虚拟机时,我看到安装了apache,php和mysql。 MySQL除了测试和信息模式外没有其他数据库。 我可以使用“ mysql”进入mysql客户端,但是我没有创建任何数据库或用户的特权。 sudo mysql也不起作用。
我想找出两件事:
如果在mysql_database_user块中的动作中添加:grant,会有所不同吗?
action [:create, :grant]
我发现本教程对于用用户和特权配置mysql很有帮助,尽管我仍然对Chef-solo的目录结构有些困惑。
http://misheska.com/blog/2013/06/23/getting-started-writing-chef-cookbooks-the-berkshelf-way-part2/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.