Chinaunix首页 | 论坛 | 博客
  • 博客访问: 7598595
  • 博文数量: 1768
  • 博客积分: 18684
  • 博客等级: 上将
  • 技术积分: 16342
  • 用 户 组: 普通用户
  • 注册时间: 2010-06-02 10:28
个人简介

啥也没写

文章分类

全部博文(1768)

文章存档

2024年(14)

2023年(44)

2022年(39)

2021年(46)

2020年(43)

2019年(27)

2018年(44)

2017年(50)

2016年(47)

2015年(15)

2014年(21)

2013年(43)

2012年(143)

2011年(228)

2010年(263)

2009年(384)

2008年(246)

2007年(30)

2006年(38)

2005年(2)

2004年(1)

分类: LINUX

2012-05-25 17:02:15

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 %>;
        location / {
                proxy_pass       
nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx

start() {
    [ -x $nginx ] || exit 5
    [ -f $NGINX_CONF_FILE ] || exit 6
    echo -n $"Starting $prog: "
    daemon $nginx -c $NGINX_CONF_FILE
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}
stop() {
    echo -n $"Stopping $prog: "
    killproc $prog -QUIT
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}
reload() {
    configtest || return $?
    echo -n $"Reloading $prog: "
    killproc $nginx -HUP
    RETVAL=$?
    echo
}
restart() {
    configtest || return $?
    stop
    sleep 1
    start
}
configtest() {
  $nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
    status $prog
}

case "$1" in
    start)
        $1
        ;;
    stop)
        $1
        ;;
    restart)
        $1
        ;;
    status)
        rh_status
        ;;
    configtest)
        $1
        ;;
    *)
        echo $"Usage: $0 {start|stop|reload|configtest|status}"
        exit 2
esac
 
 
 
阅读(1876) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~