Puppet 自动安装Nginx并拷贝配置文件
Published on 2015 - 05 - 29
首先进入puppet modules文件夹
/etc/puppet/modules/
创建 Nginx文件夹
mkdir nginx
cd nginx
创建 files 与 manifests # 两个文件夹可以合并在一起,分开写是为了方便管理
mkdir {manifests,files}
cd manifests
创建配置文件
touch {base.pp,centos.pp,init.pp}
写配置文件 base.pp
cat base.pp
#以下为配置文件
class nginx::base {
case $operatingsystem {
Centos : {include nginx::centos }
Freebsd : { include nginx::freebsd }
}
}
#以上为配置文件
写配置文件 init.pp
cat init.pp
#以下为配置文件
class nginx{
include nginx::base
}
#以上为配置文件
写配置文件 centos.pp
#以下为配置文件
class nginx::centos {
package { nginx:
ensure => "installed"
}
file {"/etc/nginx/nginx.conf":
mode => 644,
owner => root,
group => root,
source => "puppet:///modules/nginx/nginx.conf",
notify => Service["nginx"],
}
service {"nginx":
ensure => running,
enable => true,
subscribe => File['/etc/nginx/nginx.conf'],
}
}
#以上为配置文件
进入 files文件夹创建要分发的nginx的配置文件
cd /etc/puppet/modules/nginx/files
touch nginx.conf
cat nginx.con
#以下为配置文件
user nginx;
worker_processes 4;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
worker_connections 2048;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /dev/null;
sendfile on;
server_name_in_redirect off;
client_body_buffer_size 6M;
client_header_buffer_size 300k;
client_max_body_size 6M;
large_client_header_buffers 4 1M;
fastcgi_intercept_errors on;
server_tokens off;
keepalive_timeout 90;
gzip on;
gzip_min_length 512;
gzip_buffers 4 8k;
gzip_comp_level 9;
gzip_types text/plain application/x-javascript text/css application/xml;
include /etc/nginx/conf.d/*.conf;
}
#以上为配置文件
进入puppet配置文件夹
cd /etc/puppet/manifests
touch {nodes.pp,site.pp}
nodes.pp内容
#以下为配置文件
node basenode {
}
node 'nx-configure-rsync' inherits basenode {
include nginx
}
#以上为配置文件
site.pp内容
#以下为配置文件
Exec { path => "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" }
Package {
allow_virtual => true,
}
import "nodes.pp"
#以上为配置文件
至此,配置完成,只写了centos的配置文件,freebsd没有写,但是配置文件中已经添加了判断freebsd,所以只需要再定义一个freebsd类就好了