手机版
你好,游客 登录 注册
背景:
阅读新闻

Puppet管理Nginx主机

[日期:2014-10-27] 来源:Linux社区  作者:yangke [字体:大 中 小]

一:介绍

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;
}
}

Puppet 学习系列:

Puppet 学习一:安装及简单实例应用 http://www.linuxidc.com/Linux/2013-08/88710.htm

Puppet学习二:简单模块配置和应用 http://www.linuxidc.com/Linux/2013-08/88711.htm

相关阅读:

有关Puppet agent端三种备份恢复方案探讨研究 http://www.linuxidc.com/Linux/2013-07/87885.htm
选择更安全的方式注册你的Puppet节点 http://www.linuxidc.com/Linux/2013-07/87884.htm
通过配置SSH深刻理解Puppet的语法及工作机制 http://www.linuxidc.com/Linux/2013-07/87882.htm
Puppet利用Nginx多端口实现负载均衡 http://www.linuxidc.com/Linux/2013-02/79794.htm
CentOS(5和6)下Puppet的C/S模式实例 http://www.linuxidc.com/Linux/2011-12/50502.htm

Puppet 的详细介绍:请点这里
Puppet 的下载地址:请点这里

本文永久更新链接地址:http://www.linuxidc.com/Linux/2014-10/108527tm

linux
相关资讯       Puppet  Nginx管理 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款