深入浅出puppet(二)
# 编辑temp2.pp的配置文件如下:# vim temp2.pp
class nginx {
package{'nginx':
ensure => installed,
provider => 'rpm',
source => '/root/nginx/nginx-1.10.0-1.el7.ngx.x86_64.rpm',
}
service{'nginx':
ensure => running,
enable => false,
require=> Package['nginx'],
}
}
class nginx::web inherits nginx {
file{'ngx-web.conf':
path => '/etc/nginx/conf.d/ngx-web.conf',
ensure => file,
require=> Package['nginx'],
source => '/root/manifests/nginx/ngx-web.conf',
}
file{'nginx.conf':
path => '/etc/nginx/nginx.conf',
ensure => file,
content=> template('/root/manifests/nginx/nginx.conf.erb'), # 使用模板文件
require=> Package['nginx'],
}
Service['nginx'] {
subscribe=> ,File['nginx.conf'] ],
}
}
include nginx::web
----------------------------------------------------------------------------------------
# 编辑nginx.conf的模板文件
# cat nginx/nginx.conf.erb
usernginx;
worker_processes<%= @processorcount %>; # 进程数使用内置变量替换
error_log/var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections1024;
}
http {
include /etc/nginx/mime.types;
default_typeapplication/octet-stream;
log_formatmain'$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log/var/log/nginx/access.logmain;
sendfile on;
#tcp_nopush on;
keepalive_timeout65;
#gzipon;
include /etc/nginx/conf.d/*.conf;
}
页:
[1]