【发布时间】:2013-09-16 05:11:13
【问题描述】:
我在运行 Mountain Lion 的 MBP 笔记本电脑上安装了 VirtualBox、Vagrant 和 chef-solo。我已经从 opscode 下载了食谱,并且“vagrant up”正在工作。 VM 已成功创建,我得到了一个主要工作的 LAMP 堆栈。
我被困在哪里是创建一个数据库和用户来访问数据库。
我做了什么: 创建了一个开发文件夹,其中包含 Vagrantfile 和目录说明书。在我的食谱中
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"
在 recipes/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
当我“vagrant ssh”进入虚拟机时,我看到安装了 apache、php 和 mysql。 MySQL 除了测试和信息模式之外没有其他数据库。我可以使用 'mysql' 进入 mysql 客户端,但我没有创建任何数据库或用户的权限。 sudo mysql 也不起作用。
我想知道两件事:
- 我这样做是否正确?将正确的命令放入正确的文件中?
- 我的脚本中有哪些错误。
【问题讨论】:
标签: mysql macos vagrant chef-solo