puppet管理nginx

一:介绍

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

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

}

时间: 2024-08-24 02:53:02

puppet管理nginx的相关文章

ansible管理nginx配置文件

#生产环境中大多时候是需要管理配置文件的,安装软件包只是在初始化环境的时候用一下.下面我们来写个管理nginx配置文件的playbook 一.创建相关目录 mkdir  -p /etc/ansible/nginx_config/roles/{new,old}/{files,handlers,vars,tasks} #其中new为更新时用到的,old为回滚时用到的,files下面为nginx.conf和vhosts目录,handlers为重启nginx服务的命令. #关于回滚,需要在执行playb

如何使用service命令来管理nginx

如何使用service命令来管理nginx??? 如: service nginx start service nginx restart service nginx stop service nginx  reload 如果要是使用 service 来管理nginx 需要把nginx 安装成为一个linux下的服务 1. 先创建一个文件nginx,里面写入以下shell脚本 如: #!/bin/bash # nginx Startup script for the Nginx HTTP Ser

php管理nginx虚拟主机shell脚本

使用php作为shell脚本是一件很方便的事情.理所当然,我们可以使用php脚本来管理 nginx虚拟主机,下面是笔者的 脚本 文件供各位参考 代码如下 复制代码 #!/usr/bin/php -q<?php start: fwrite(STDOUT,"===========Vhost Script===========\n");fwrite(STDOUT,"= Choose an operation \n");fwrite(STDOUT,"= 1.

4.3-ansible实例-管理nginx配置文件

Ansible 管理配置文件 * 生产环境中大多时候是需要管理配置文件的,安装软件包只是在初始化环境的时候用一下.下面我们来写个管理nginx配置文件的playbook 1.mkdir  -p /etc/ansible/nginx_config/roles/{new,old}/{files,handlers,vars,tasks} 说明:其中new为更新时用到的,old为回滚时用到的,files下面为nginx.conf和vhosts目录,handlers为重启nginx服务的命令 关于回滚,需

【saltstack学习笔记之十】使用sls安装nginx并管理nginx的配置文件

1.需求 使用sls安装nginx并管理nginx的配置文件,当nginx配置文件被修改时,自动更新配置文件,并重启nginx. 2.配置 1.在master端上写好nginx.sls文件 mkdir -p /srv/salt/nginx cd /srv/salt/nginx vim init.sls nginx: pkg: - installed service: - running - enable: True - reload: True - watch: - pkg: nginx - f

Linux普通账户使用和管理Nginx

说明 由于项目需要,客户要求使用系统上存在的普通账户使用和管理nginx,下面是主要的配置步骤- 创建账户 useradd duser Nginx编译安装 #下载并解压缩nginx包 tar zxvf nginx-1.12.2.tar.gz cd nginx-1.12.2 #编译安装 ./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-

Puppet利用Nginx多端口实现负载均衡

随着公司应用需求的增加,需要不断的扩展,服务器数量也随之增加,当服务器数量不断增加,我们会发现一台puppetmaster压力大,解析缓慢,而且时不时出现"time out"之类的报错,那这时有什么优化的办法吗?其实不然,我们可以利用Nginx多端口实现负载均衡,这样在很大程度上优化了puppet的处理能力. [51CTO原创稿件]随着公司应用需求的增加,需要不断的扩展,服务器数量也随之增加,当服务器数量不断增加,我们会发现一台puppetmaster压力大,解析缓慢,而且时不时出现&

使用logrotate管理nginx日志文件

本文转载自:http://linux008.blog.51cto.com/2837805/555829 描述:linux日志文件如果不定期清理,会填满整个磁盘.这样会很危险,因此日志管理是系统管理员日常工作之一.我们可以使用"logrotate"来管理linux日志文件,它可以实现日志的自动滚动,日志归档等功能.下面以nginx日志文件来讲解下logrotate的用法. 配置:1.在/etc/logrotate.d目录下创建一个nginx的配置文件"nginx"配置

Puppet master nginx 扩展提升性能(puppet自动化系列4)

puppet使用SSL(https)协议来进行通讯,默认情况下,puppet server端使用基于Ruby的WEBRick HTTP服务器.由于WEBRick HTTP服务器在处理agent端的性能方面并不是很强劲,因此需要扩展puppet,搭建nginx或者其他强劲的web服务器来处理客户的https请求. 需要解决的问题: 扩展传输方式:提高性能并增加Master和agent之间的并发连接数量. 扩展SSL:采用良好的SSL证书管理方法来加密Master和agent之间的通讯. Nginx