我需要一个快速且最小的 MySQL 盒子来用于一些开发工作。我不希望这个盒子里装满完整的 LAMP 堆栈(加上 PHP 开发者在他们的努力中似乎需要的无数其他工具)。不幸的是,我没有找到。这迫使我创建一个,现在与您分享。
Vagrant 文件很简单:
# -*- mode: ruby -*-# vi: set ft=ruby :VAGRANTFILE_API_VERSION = "2"Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|config.vm.box = "2creatives-centos64"config.vm.box_url = "https://github.com/2creatives/" +"vagrant-centos/releases/download/v0.1.0/" +"centos64-x86_64-20131030.box"config.vm.network "forwarded_port", guest: 3306, host: 3306config.vm.network "private_network", ip: "192.168.24.42"config.vm.provider "virtualbox" do |vb| vb.customize ["modifyvm", :id, "--memory", "2048"]endconfig.vm.provision "ansible" do |ansible|ansible.playbook = "playbook.yml"ansible.verbose = "vv"ansible.sudo = trueendend
剧本:
---- hosts: allvars:root_db_password: passwordgather_facts: Truetasks:- name: Install MySQLyum: name=mysql-server state=installed- name: Install MySQL-pythonyum: name=MySQL-python state=installed- name: Ensure MySQL is runningservice: name=mysqld state=started enabled=true- name: Ensure IPTables is not runningservice: name=iptables state=stopped enabled=false- name: Copy the my.cnfcopy: src=my.cnf dest=/root/.my.cnf owner=root mode=0600- name: Update MySQL Root Passwordmysql_user: name=root host=$item password=$root_db_passwordwith_items:- $ansible_hostname- 192.168.24.1- 127.0.0.1- ::1- localhost- name: Annonymous Users not in MySQLmysql_user: name='' host=$item state=absentwith_items:- localhost- $inventory_hostname- name: Test Database is Removedmysql_db: name=test state=absent
最后,您会注意到我们正在将 my.cnf
的本地实例复制到虚拟机:
[client]user=rootpassword=password
正如我所说,这是非常小的。
您可以从此存储库克隆部署:https://github.com/rclayton/vagrant-mysql
另外,我要感谢 Lorin Hochstein 提供了 Ansible 配置的一部分(特别是为我节省了一些时间来删除一些默认的粗鲁内容。
理查德·克莱顿 - 关于软件和管理的不悔改的想法。