mkdir -p /etc/puppet/modules/nginx-proxy/{manifests,files,templates}
vi /etc/puppet/fileserver.conf
...
[nginx]
path /etc/puppet/modules/nginx-proxy/files
allow *
vi /etc/puppet/manifests/modules.pp
....
import "nginx-proxy"
vi /etc/puppet/manifests/nodes/akin2.com/pp
...
include nginx-proxy::base,nginx-proxy::install
...
vi /etc/puppet/modules/nginx-proxy/manifests/init.pp
import "*"
vi /etc/puppet/modules/nginx-proxy/manifests/base.pp
class nginx-proxy::base {
package { ["patch","make","gcc","gcc-c++","libtool","libart_lgpl","libart_lgpl-devel","autoconf","libjpeg","libjpeg-devel","libpng","libpng-devel","fontconfig","fontconfig-devel","freetype","freetype-devel","libxml2","libxml2-devel","zlib","zlib-devel","glibc","glibc-devel","glib2","glib2-devel","bzip2","bzip2-devel","ncurses","ncurses-devel","curl","curl-devel","e2fsprogs","e2fsprogs-devel","krb5-devel","libidn","libidn-devel","openssl","openssl-devel","openldap","openldap-devel","nss_ldap","openldap-clients","openldap-servers"]:
ensure => installed,
}
file { "/tmp/nginx-1.3.0.tar.gz":
source => "puppet:///nginx/nginx-1.3.0.tar.gz",
}
file { "/tmp/pcre-8.12.tar.gz":
source => "puppet:///nginx/pcre-8.12.tar.gz",
}
user { "nginx":
ensure => present,
comment => "nginx",
uid => "555",
gid => "nginx",
managehome => true,
home => "/home/nginx",
require => Group["nginx"],
}
group { "nginx":
ensure => present,
gid => "555",
}
}
vi /etc/puppet/modules/nginx-proxy/manifests/install.pp
class nginx-proxy::install {
exec { "build-pcre":
creates => "/usr/local/lib/pkgconfig/libpcre.pc" //判断,如果有了,就跳过
cwd => "/tmp",
command => "tar zxvf pcre-8.12.tar.gz && cd pcre-8.12/ && ./configure && make && make install",
logoutput =>on_failure,
timeout =>0,
}
exec { "buid-nginx":
creates => "/usr/local/nginx", //判断,如果有了,就跳过
cwd => "/tmp",
command => "tar zxvf nginx-1.3.0.tar.gz && cd nginx-1.3.0/ && ./configure --user=webadm --group=webadm --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module && make && make install",
logoutput => on_failure,
timeout =>0,
require => Class["nginx-proxy::base"],
}
}
vi /etc/puppet/modules/nginx-proxy/manifests/config.pp
class nginx-proxy::config {
define nginx_conf($process) {
file { "/usr/local/nginx/conf/nginx.conf":
content => template('nginx-proxy/nginx.conf.erb'),
require => Class["nginx-proxy::install"],
}
}
define nginx_vhost($domain,$proxy,$ip){
file { "/usr/local/nginx/conf/conf":
ensure => directory,
}
file { "/usr/local/nginx/conf/conf/$domain.conf":
content => template("nginx-proxy/proxy.conf.erb"),
require => File["/usr/local/nginx/conf/conf"],
}
}
file { "/etc/init.d/nginx":
source => "puppet:///nginx/nginx",
mode => 755,
ensure => present,
owner => "root",
}
}
vi /etc/puppet/modules/nginx-proxy/manifests/server.pp
class nginx-proxy::server {
service { "nginx":
ensure => running,
enable => true,
hasstatus => false, #如果脚本里面没有stats的话,加这个,要不会报错!
subscribe => [Class[nginx-proxy::base],Class[nginx-proxy::install],Class[nginx-proxy::config]],
}
}
vi /etc/puppet/manifests/nodes/akin2.com.pp
...
include nginx-proxy::base,nginx-proxy::install
nginx-proxy::config::nginx_conf { "akin2":
process => 4,
}
nginx-proxy::config::nginx_vhost { "akin2":
domain => '_',
proxy => 'akin2',
ip => "192.168.14.250:80",
}
include nginx-proxy::config
include nginx-proxy::server
..
vi /etc/puppet/modules/nginx-proxy/templates/nginx.conf.erb
user nginx nginx;
worker_processes <%= process %>;
error_log /usr/local/nginx/logs/nginx_error.log crit;
pid /usr/local/nginx/logs/nginx.pid;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 51200;
events
{
use epoll;
worker_connections 51200;
}
http
{
include mime.types;
default_type application/octet-stream;
#charset gb2312;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 8m;
sendfile on;
tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
#limit_zone crawler $binary_remote_addr 10m;
#proxy
include conf/*.conf;
}
vi /etc/puppet/modules/nginx-proxy/templates/proxy.conf.erb
upstream <%= proxy %> {
server <%= ip %>;
}
server
{
listen 80;
server_name <%= domain %>;
阅读(1883) | 评论(0) | 转发(0) |