使用 Puppet 安装后 Apache 无法启动

Apache won't start after installing with Puppet

我已经通过 puppetlabs/apache 安装了 Apache,但它无法启动。无论使用哪个端口,我都会抛出错误 Address already in use: AH00072: make_sock: could not bind to addressnetstat -lntp 未显示任何使用该端口的内容。我的系统是 CentOS 7,我使用的是 centos-sclo-rh 仓库中的软件包。以下是我安装的与此相关的软件包:

$ rpm -qa |grep 'http\|php' |sort
httpd24-1.1-9.el7.x86_64
httpd24-httpd-2.4.12-6.el7.1.x86_64
httpd24-httpd-devel-2.4.12-6.el7.1.x86_64
httpd24-httpd-tools-2.4.12-6.el7.1.x86_64
httpd24-mod_ssl-2.4.12-6.el7.1.x86_64
httpd24-runtime-1.1-9.el7.x86_64
rh-php56-2.0-6.el7.x86_64
rh-php56-php-cli-5.6.5-7.el7.x86_64
rh-php56-php-common-5.6.5-7.el7.x86_64
rh-php56-php-pear-1.9.5-3.el7.noarch
rh-php56-php-pecl-jsonc-1.3.6-3.el7.x86_64
rh-php56-php-process-5.6.5-7.el7.x86_64
rh-php56-php-xml-5.6.5-7.el7.x86_64
rh-php56-runtime-2.0-6.el7.x86_64

这是我的 Puppet 清单。任何帮助将不胜感激。

exec { 'create localhost cert':
  # lint:ignore:80chars
  command   => "/bin/openssl req -new -newkey rsa:4096 -days 3650 -nodes -x509 -sha256 -subj '/CN=domain.com/O=My Company Name LTD./C=US' -keyout /etc/pki/tls/private/localhost.key -out /etc/pki/tls/certs/localhost.crt",
  # lint:endignore
  creates   => '/etc/pki/tls/certs/localhost.crt',
  logoutput => true,
  before    => Class['apache'],
}

package { 'centos-release-scl-rh':
  ensure => installed,
}

$packages = [
  'httpd24',
  'rh-php56',
  'scl-utils',
]

package { $packages:
  ensure  => installed,
  before  => Class['apache'],
  require => Package['centos-release-scl-rh'],
}

user { 'webmaster':
  ensure => present,
  before => Class['apache'],
}

$scl_httpd = '/opt/rh/httpd24/root'

class { 'apache':
  apache_name           => 'httpd24-httpd',
  apache_version        => '2.4',
  conf_dir              => "${scl_httpd}/etc/httpd/conf",
  confd_dir             => "${scl_httpd}/etc/httpd/conf.d",
  default_mods          => false,
  default_ssl_vhost     => false,
  default_vhost         => false,
  dev_packages          => 'httpd24-httpd-devel',
  docroot               => "${scl_httpd}/var/www/html",
  httpd_dir             => "${scl_httpd}/etc/httpd",
  logroot               => '/var/log/httpd24',
  mod_dir               => "${scl_httpd}/etc/httpd/conf.modules.d",
  mpm_module            => 'worker',
  pidfile               => '/opt/rh/httpd24/root/var/run/httpd/httpd.pid',
  ports_file            => "${scl_httpd}/etc/httpd/conf.d/ports.conf",
  purge_configs         => true,
  serveradmin           => 'root@localhost',
  servername            => 'demobox.example.com',
  server_root           => "${scl_httpd}/etc/httpd",
  service_name          => 'httpd24-httpd',
  trace_enable          => false,
  vhost_dir             => "${scl_httpd}/etc/httpd/conf.d",
  vhost_include_pattern => '*.conf',
}

class { 'apache::dev': }

class { 'apache::mod::ssl':
  package_name => 'httpd24-mod_ssl',
}

apache::vhost { 'main-site-nonssl':
  ip            => '*',
  ip_based      => true,
  port          => '80',
  docroot       => "${scl_httpd}/var/www/main-site",
#  docroot_owner => 'webmaster',
#  docroot_group => 'webmaster',
}

apache::vhost { 'main-site-ssl':
  ip            => '*',
  ip_based      => true,
  port          => '443',
  docroot       => "${scl_httpd}/var/www/main-site",
#  docroot_owner => 'webmaster',
#  docroot_group => 'webmaster',
  ssl           => true,
  ssl_cert      => '/etc/pki/tls/certs/localhost.crt',
  ssl_key       => '/etc/pki/tls/private/localhost.key',
}

原来我把 ports.conf 放在了 conf.d 而不是 conf 中,这意味着它被包含了两次。将 ports_file => "${scl_httpd}/etc/httpd/conf.d/ports.conf", 更改为 ports_file => "${scl_httpd}/etc/httpd/conf/ports.conf", 解决了问题。