在Chef构建时,“apache”和“nginx”端口冲突导致失败

在Chef中进行环境配置时,有关”apache”和”nginx”的端口80发生冲突的情况。

关于菜谱

以下是Apache和Nginx的配置指南。

# Install Apache
package httpd do
  action   :install
end

# ==== start service
service "httpd" do
  action   [ :enable, :start ]
  supports :reload => true
end

# Create Apache Config
template "/etc/httpd/conf/httpd.conf" do
  source   "httpd.conf.erb"
  owner    "root"
  group    "root"
  mode     00644
  notifies :reload, 'service[httpd]'
end
# Install Nginx
package nginx do
  action   :install
end

# ==== start service
service "nginx" do
  action   [ :enable, :start ]
  supports :reload => true
end

# Create Nginx Config
template "/etc/nginx/nginx.conf" do
  source   "nginx.conf.erb"
  owner    "root"
  group    "root"
  mode     00644
  notifies :reload, 'service[nginx]'
end

在生成设置文件时,端口会被更改为以下方式。

サービスポートapache10080nginx8080

厨师的执行顺序

根据Chef的运行情况来看,似乎不是按照每个菜谱来处理,也不是从上往下顺序处理菜谱内的步骤。

我自己的时候是这样的感觉。

    1. 安装nginx

安装apache

启动nginx

启动apache

修改nginx配置 => 重新加载

修改apache配置 => 重新加载

看起来在”4″时遇到了端口80被占用的问题,导致失败了,但即使是在这种情况下,”5″仍然可以执行,因此,再次重新启动应该没有问题(”6″是失败的)。

解决方案

通过调整食谱如下所示,问题得以解决。
看起来通知是最后被处理的,除此之外,其他都是按照记录顺序的。

# Install Apache
package httpd do
  action   :install
end

# Create Apache Config
template "/etc/httpd/conf/httpd.conf" do
  source   "httpd.conf.erb"
  owner    "root"
  group    "root"
  mode     00644
  notifies :reload, 'service[httpd]'
end

# ==== start service
service "httpd" do
  action   [ :enable, :start ]
  supports :reload => true
end
# Install Nginx
package nginx do
  action   :install
end

# Create Nginx Config
template "/etc/nginx/nginx.conf" do
  source   "nginx.conf.erb"
  owner    "root"
  group    "root"
  mode     00644
  notifies :reload, 'service[nginx]'
end

# ==== start service
service "nginx" do
  action   [ :enable, :start ]
  supports :reload => true
end
广告
将在 10 秒后关闭
bannerAds