puppet管理nginx

一:介紹

puppet管理nginx主機,將nginx主機加入到puppet中,實現自動安裝、配置、和啓動服務


二:nginx模塊結構

[root@master 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的配置文件

[root@master manifests]# cat install.pp 
class nginx::install { 
    package {"nginx": 
    ensure => present, 
    } 
}


conf.pp爲配置nginx的配置文件

[root@master 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": 
    port => "80", 
    hostname => "
www.puppet.com", 
    rootdir => "/var/www/puppet", 
    } 
}


init.pp爲nginx模塊的入口文件

[root@master manifests]# cat init.pp 
class nginx { 
    include nginx::install,nginx::conf 
}


templates下面爲nginx配置文件模板:

[root@master templates]# cat vhost.erb 
server { 
listen <%= port %>; 
server_name <%= hostname %>; 
root <%= rootdir %>; 
index index.php; 

location ~ .*\.php { 
proxy_set_header Host $host; 
proxy_set_header X-Forwarded-For $remote_addr; 
proxy_headers_hash_max_size 512; 
fastcgi_index index.php; 
fastcgi_pass 127.0.0.1:9000; 
include fastcgi.conf; 


location ~ \.(css|js)?$ { 
expires 2h; 


location ~ .*\.(mp3|jpg|jpeg|rar|png|zip|wmv|rm|doc|ppt|gif|bmp|xls|pdf|swf)$ { 
expires 5d; 

}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章