一:介绍
puppet管理nginx主机,将nginx主机加入到puppet中,实现自动安装、配置、和启动服务
二:nginx模块结构
[[email protected] modules]# tree /etc/puppet/modules/nginx/ /etc/puppet/modules/nginx/ ├── files ├── manifests │ ├── conf.pp │ ├── init.pp │ └── install.pp └── templates ├── nginx.conf.erb └── vhost.erb |
三:配置解释
install.pp为安装nginx的配置文件
[[email protected] manifests]# cat install.pp class nginx::install { package {"nginx": ensure => present, } } |
conf.pp为配置nginx的配置文件
[[email protected] manifests]# cat conf.pp class nginx::conf { define nginx::vhost($port,$hostname,$rootdir,$filename=$title){ file {"/etc/nginx/conf.d": ensure => directory, owner => "root", group => "root", mode => "744", recurse => true, require => Class["nginx::install"], } file {"$filename": owner => "root", group => "root", mode => "644", path => "/etc/nginx/conf.d/${filename}", content => template("nginx/vhost.erb"), require => File["/etc/nginx/conf.d"], } } nginx::vhost{"www.puppet.com.conf": |
init.pp为nginx模块的入口文件
[[email protected] manifests]# cat init.pp class nginx { include nginx::install,nginx::conf } |
templates下面为nginx配置文件模板:
[[email protected] templates]# cat vhost.erb server { listen <%= port %>; server_name <%= hostname %>; root <%= rootdir %>; index index.php; location ~ .*\.php { location ~ \.(css|js)?$ { location ~ .*\.(mp3|jpg|jpeg|rar|png|zip|wmv|rm|doc|ppt|gif|bmp|xls|pdf|swf)$ { |
时间: 2024-08-24 02:53:02