13. August 2015
Inhalt 1 Überblick Vagrant 2
Vagrant Download unter https://www.vagrantup.com/
Konguration per Vagrantle Listing 1: Vagrantle Vagrant. configure ("2") do config config. vm. box = " vivid64 " config. vm. box_url = " http :// cloud - images. ubuntu. com / vagrant / vivid / current /"\ " vivid - server - cloudimg - amd64 - vagrant - disk1. box " config. vm. provider " virtualbox " do vm vm. memory = 2048 vm. cpus = 2 config. vm. network : private_network, ip : " 10.10.10.2 "
Wichtige Vagrant Kommandos vagrant up Start und Provisioning der VM vagrant ssh Login per ssh vagrant halt Stop der VM vagrant susp Ruhezustand vagrant resume Aufwachen aus Ruhezustand vagrant destroy Löschen der VM vagrant provision Provisioning vagrant reload Neustart der VM
Chef Download unter https://www.chef.io/
Listing 2: Vagrantle config. berkshelf. enabled = true config. vm. provision " chef_zero " do chef chef. add_recipe " apt " chef. add_recipe " zip " chef. add_recipe " apache2 " chef. add_recipe " apache2 :: mod_rewrite " chef. add_recipe " apache2 :: mod_php5 " chef. add_recipe " php " chef. add_recipe " php :: module_mysql " chef. json = { " apache " => { " default_site_enabled " => true } }
Paketabhängigkeiten source " https :// supermarket. chef. io " Listing 3: Berksle cookbook " apt " cookbook " apache2 " cookbook " zip " cookbook " php ", : git => " https :// github. com / priestjim / chef - php "
Installation und Konguration MySQL Listing 4: Vagrantle config. vm. provision " chef_zero " do chef (...) chef. add_recipe " lamp :: mysql " chef. json = { (...) " mysql " => { " password " => " secret " } } Listing 5: Berksle cookbook " mysql ", "~> 6.1.0 " cookbook ' mysql2_chef_gem ' cookbook " database " cookbook " lamp ", : path => "/ Users / helge - frankzimpel / t3see / cookbooks / lamp "
Erstellen des MySQL-Rezeptes (1) name ' lamp ' version ' 0.0.1 ' Listing 6: cookbooks/lamp/metadata.rb deps ' mysql ', '~> 6.1.0 ' deps ' mysql2_chef_gem ' deps ' database '
Erstellen des MySQL-Rezeptes (2) Listing 7: cookbooks/lamp/recipes/mysql.rb mysql_password = node [' mysql '][ ' password '] mysql_service ' default ' do port ' 3306 ' version ' 5.6 ' bind_address " 0.0.0.0 " initial_root_password mysql_password action [: create, : start ]
Erstellen des MySQL-Rezeptes (3) mysql2_chef_gem ' default ' do action : install mysql_database ' wordpress ' do connection ( : host => ' 127.0.0.1 ', : username => ' root ', : password => mysql_password ) action : create Listing 8: cookbooks/lamp/recipes/mysql.rb
Installation Wordpress Listing 9: cookbooks/lamp/recipes/wordpress.rb unless File. directory? "/ var / www / html / wordpress " remote_file "/ tmp / latest - de_de. zip " do source " https :// de. wordpress. org / latest - de_de. zip " execute ' unzip ' do command ' unzip -o / tmp / latest - de_de. zip ' cwd '/ var / www / html '
Konguration Wordpress (1) Listing 10: cookbooks/lamp/recipes/wordpress.rb mysql_password = node [' mysql '][ ' password '] template "/ var / www / html / wordpress /wp - config. php " do source "wp - config. erb " variables ({ : user => ' root ', : password => mysql_password })
Konguration Wordpress (2) Listing 11: cookbooks/lamp/templates/wp-cong.erb (...) define (' DB_NAME ', ' wordpress '); define (' DB_USER ', ' <%= @user %> '); define (' DB_PASSWORD ', ' <%= @password %> '); define (' DB_HOST ', ' 127.0.0.1 '); (...)