我刚刚创建了一个新的虚拟机(基于ubuntu precise32
),并安装了自己的软件,一切都很顺利,除了apache无法在启动时自动运行。
每次执行vagrant up
后,我都需要登录到我的虚拟机并手动启动它。
我尝试过以下方法使其能够在启动时自动运行:
sudo update-rc.d apache2 defaults
但是我得到了:
System start/stop links for /etc/init.d/apache2 already exist.
因此,它应该开始... 这是我的Vagrantfile:
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.define :stilogo do |stilogo_config|
stilogo_config.vm.box = "precise32"
stilogo_config.vm.box_url = "http://files.vagrantup.com/precise32.box"
stilogo_config.ssh.forward_agent = true
#Do alla macchina un IP statico
#stilogo_config.vm.network :private_network, ip: "192.168.56.101"
stilogo_config.vm.network :forwarded_port, guest: 80, host: 8888, auto_correct: true
stilogo_config.vm.network :forwarded_port, guest: 3306, host: 8889, auto_correct: true
stilogo_config.vm.network :forwarded_port, guest: 5432, host: 5433, auto_correct: true
stilogo_config.vm.hostname = "stilogo"
stilogo_config.vm.synced_folder "www", "/var/www", {:mount_options => ['dmode=777','fmode=777']}
stilogo_config.vm.provision :shell, :inline => "echo \"Europe/Rome\" | sudo tee /etc/timezone && dpkg-reconfigure --frontend noninteractive tzdata"
stilogo_config.vm.provider :virtualbox do |v|
v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
v.customize ["modifyvm", :id, "--memory", "512"]
end
#Installo il software che mi serve
stilogo_config.vm.provision :puppet do |puppet|
puppet.manifests_path = "puppet/manifests"
puppet.manifest_file = "phpbase.pp"
puppet.module_path = "puppet/modules"
#puppet.options = "--verbose --debug"
end
end
end
以下是 Apache 的安装步骤:
class apache
{
package
{
"apache2":
ensure => present,
require => [Exec['apt-get update'], Package['php5'], Package['php5-dev'], Package['php5-cli']]
}
service
{
"apache2":
ensure => running,
enable => true,
require => Package['apache2'],
subscribe => [
File["/etc/apache2/mods-enabled/rewrite.load"],
File["/etc/apache2/sites-available/000-default.conf"],
File["/etc/apache2/conf-enabled/phpmyadmin.conf"]
],
}
file
{
"/etc/apache2/mods-enabled/rewrite.load":
ensure => link,
target => "/etc/apache2/mods-available/rewrite.load",
require => Package['apache2'],
}
file
{
"/etc/apache2/sites-available/000-default.conf":
ensure => present,
owner => root, group => root,
source => "/vagrant/puppet/templates/vhost",
require => Package['apache2'],
}
exec
{
'echo "ServerName localhost" | sudo tee /etc/apache2/conf-enabled/fqdn.conf':
require => Package['apache2'],
}
}
这是在执行
vagrant up
和手动启动apache
后的日志。[Fri Dec 27 15:26:33.220448 2013] [mpm_prefork:notice] [pid 1379] AH00169: caught SIGTERM, shutting down
PHP Warning: Module 'memcached' already loaded in Unknown on line 0
[Fri Dec 27 15:27:55.750639 2013] [mpm_prefork:notice] [pid 1105] AH00163: Apache/2.4.6 (Ubuntu) PHP/5.5.7-1+sury.org~precise+1 configured -- resuming normal operations
[Fri Dec 27 15:27:55.750700 2013] [core:notice] [pid 1105] AH00094: Command line: '/usr/sbin/apache2'
我错过了什么?
localhost:8888
,它会显示无法联系服务器的消息。 如果我手动启动apache,它可以正常工作,也许我缺少某些东西或者我不太了解如何使用vagrant和puppet... - Christian Giupponi