阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Puppet管理Nginx主机

137次阅读
没有评论

共计 2055 个字符,预计需要花费 6 分钟才能阅读完成。

一:介绍

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 的下载地址 :请点这里

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-20发表,共计2055字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中