服务端在/puppet/soft 里建nginx1102setup.sh,内容:
!/bin/bash
yum -y install wget libtool expat-devel gcc gcc-c++ glibc automake autoconf libtool make libmcrypt-devel mhash-devel libxslt-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel
cd /data
wget https://ftp.pcre.org/pub/pcre/pcre-8.39.tar.gz
tar -zxvf pcre-8.39.tar.gz
cd pcre-8.39
./configure
make && make install
cd /data
wget http://zlib.net/zlib-1.2.11.tar.gz
tar -zxvf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure
make && make install
cd /data
wget https://www.openssl.org/source/openssl-1.1.0b.tar.gz
tar -zxvf openssl-1.1.0b.tar.gz
cd openssl-1.1.0b
./config
make && make install
cd /data
wget http://nginx.org/download/nginx-1.10.2.tar.gz
tar -zxvf nginx-1.10.2.tar.gz
cd nginx-1.10.2
groupadd -r nginx
useradd -r -g nginx nginx
./configure --prefix=/data/nginx --sbin-path=/data/nginx/sbin/nginx --conf-path=/data/nginx/nginx.conf --pid-path=/data/nginx/logs/nginx.pid --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module --with-http_mp4_module --with-http_stub_status_module --with-http_gzip_static_module --http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy/ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi --with-pcre=/data/pcre-8.39 --with-zlib=/data/zlib-1.2.11 --with-openssl=/data/openssl-1.1.0b
make && make install
mkdir -p /var/tmp/nginx/client
mkdir -p /data/nginx/logs
/data/nginx/sbin/nginx
firewall-cmd --add-port=80/tcp --permanent
firewall-cmd --add-port=443/tcp --permanent
firewall-cmd --reload
mkdir -p /data/soft
mv /data/nginx-1.10.2* /data/soft
mv /data/*.tar.gz /data/soft
保存,退出。 chmod +x /puppet/soft/nginx1102setup.sh
在服务端/puppet/soft 里建 openresty1136setup.sh,内容:
!/bin/bash
yum install -y gcc gcc-c++ zlib-devel pcre-devel openssl-devel readline-devel
cd /data
wget https://openresty.org/download/openresty-1.13.6.2.tar.gz
tar -zxvf openresty-1.13.6.2.tar.gz
cd openresty-1.13.6.2
./configure --prefix=/data/openresty
--user=nginx --group=nginx
--with-http_ssl_module
--with-http_flv_module
--with-http_stub_status_module
--with-http_gzip_static_module
--with-pcre
--with-http_realip_module
gmake && gmake install
firewall-cmd --add-port=80/tcp --permanent
firewall-cmd --add-port=443/tcp --permanent
firewall-cmd --reload
mkdir -p /data/soft
mv /data/openresty-1.13.6.2.tar.gz /data/soft
mkdir -p /data/openresty/nginx/conf.d
/data/openresty/nginx/sbin/nginx
保存退出, chmod +x openresty1136setup.sh
在服务端建立erb文件,/etc/puppet/modules/linuxnginx/templates/nginx.conf.erb,内容:
user <%= real_nginx_user %>;
worker_processes <%= processorcount %>;
error_log /data/nginx/logs/nginx_error.log crit;
pid /data/nginx/logs/nginx.pid;
events {
use epoll;
worker_connections 51200;
}
http {
include /data/nginx/mime.types;
default_type application/octet-stream;
log_format main 'remote_user [request"'
'body_bytes_sent "http_user_agent" "$http_x_forwarded_for"';
access_log /data/nginx/logs/nginx_access.log main;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_body_buffer_size 8m;
sendfile on;
keepalive_timeout 0;
tcp_nopush on;
tcp_nodelay on;
client_max_body_size 50m;
ssi on;
ssi_types text/shtml;
fastcgi_intercept_errors on;
proxy_intercept_errors on;
fastcgi_connect_timeout 1200;
fastcgi_send_timeout 1200;
fastcgi_read_timeout 1200;
fastcgi_buffer_size 128k;
fastcgi_buffers 8 128k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
send_timeout 1200;
proxy_connect_timeout 1200;
proxy_read_timeout 1200;
proxy_send_timeout 1200;
gzip on;
gzip_proxied any;
gzip_http_version 1.0;
gzip_vary on;
gzip_comp_level 6;
gzip_min_length 2k;
gzip_buffers 4 16k;
gzip_types text/plain text/css application/json application/x-javascript application/xml text/javascript image/jpeg image/gif image/png application/x-shockwave-flash;
gzip_disable “MSIE [1-6].(?!.*SV1)”;
include /data/nginx/conf.d/*.conf;
}
在服务端建立nginx_logrote.sh
mkdir -p /puppet/soft/nginx/huangat-test/
vi /puppet/soft/nginx/huangat-test/nginx_logrote.sh
!/bin/bash
logs_path="/data/nginx/logs/"
PIDFILE=/data/nginx/nginx.pid
ACCESS_LOG="(date -d "yesterday" +"%Y")/(date -d "yesterday" +"%Y%m%d").log"
ERROR_LOG="(date -d "yesterday" +"%Y")/(date -d "yesterday" +"%Y%m%d").log"
mkdir -p (date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/
mv ACCESS_LOG
mv ERROR_LOG
kill -USR1 cat $PIDFILE
/bin/gzip -9 ERROR_LOG
find ${logs_path} -name "*.log.gz" -mtime +30|xargs rm -f
保存退出
在服务端建conf.d文件夹,/puppet/soft/nginx/huangat-test/conf.d
mkdir -p /puppet/soft/nginx/huangat-test/conf.d
vi /puppet/soft/nginx/huangat-test/conf.d/huangat-test.conf
server {
listen 80;
server_name huangat-test;
root /var/www/huangat-test;
location /nginx_status {
stub_status on;
access_log off;
}
}
在服务端建立conf.d文件夹:mkdir -p /puppet/soft/openresty/pai2/nginx/conf.d
vi /puppet/soft/openresty/pai2/nginx/conf.d/api2.conf
server {
listen 80;
server_name api2;
root /var/www/api2;
location /nginx_status {
stub_status on;
access_log off;
}
}
在服务端建立nginx_logrote.sh
vi /puppet/soft/openresty/api2/nginx/nginx_logrote.sh
!/bin/bash
logs_path="/data/openresty/nginx/logs/"
PIDFILE=/data/openresty/nginx/nginx.pid
ACCESS_LOG="(date -d "yesterday" +"%Y")/(date -d "yesterday" +"%Y%m%d").log"
ERROR_LOG="(date -d "yesterday" +"%Y")/(date -d "yesterday" +"%Y%m%d").log"
mkdir -p (date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/
mv ACCESS_LOG
mv ERROR_LOG
kill -USR1 cat $PIDFILE
/bin/gzip -9 ERROR_LOG
find ${logs_path} -name "*.log.gz" -mtime +30|xargs rm -f
在服务端建立erb文件,/etc/puppet/modules/linuxnginx/templates/openresty.nginx.conf.erb,内容:
user <%= real_nginx_user %>;
worker_processes <%= processorcount %>;
error_log /data/openresty/nginx/logs/nginx_error.log crit;
pid /data/openresty/nginx/logs/nginx.pid;
events {
use epoll;
worker_connections 51200;
}
http {
default_type application/octet-stream;
log_format main 'remote_user [request"'
'body_bytes_sent "http_user_agent" "$http_x_forwarded_for"';
access_log /data/openresty/nginx/logs/nginx_access.log main;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_body_buffer_size 8m;
sendfile on;
keepalive_timeout 0;
tcp_nopush on;
tcp_nodelay on;
client_max_body_size 50m;
ssi on;
ssi_types text/shtml;
fastcgi_intercept_errors on;
proxy_intercept_errors on;
fastcgi_connect_timeout 1200;
fastcgi_send_timeout 1200;
fastcgi_read_timeout 1200;
fastcgi_buffer_size 128k;
fastcgi_buffers 8 128k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
send_timeout 1200;
proxy_connect_timeout 1200;
proxy_read_timeout 1200;
proxy_send_timeout 1200;
gzip on;
gzip_proxied any;
gzip_http_version 1.0;
gzip_vary on;
gzip_comp_level 6;
gzip_min_length 2k;
gzip_buffers 4 16k;
gzip_types text/plain text/css application/json application/x-javascript application/xml text/javascript image/jpeg image/gif image/png application/x-shockwave-flash;
gzip_disable “MSIE [1-6].(?!.*SV1)”;
include /data/openresty/nginx/conf.d/*.conf;
}
安装nginx1.10.2、openresty1.13.6,两者不能同时装
mkdir -p /etc/puppet/modules/linuxnginx/{manifests,templates,files}
vi /etc/puppet/modules/linuxnginx/manifests/init.pp
class linuxnginx::nginx1102 {
nginx_user ? {'' => 'nginx',default => nginx_conf = "/data/nginx/conf.d"
$nginx_logrote = "/data/nginx/conf.d/nginx_logrote.sh"
file {"/data/nginx.sh":
ensure => present,
source => "puppet:///soft/nginx1102setup.sh",
}
exec {"nginxsetup":
command => "bash /data/nginx.sh",
cwd => "/data",
user => root,
provider => shell,
logoutput => true,
timeout => 1800,
require => File["/data/nginx.sh"],
unless => "ls /data/nginx",
}
file {'nginx.conf':
ensure => present,
mode => 644,owner => root,group => root,
path => "/data/nginx/nginx.conf",
content => template('/etc/puppet/modules/linuxnginx/templates/nginx.conf.erb'),
notify => Exec["reload-nginx"],
require => Exec["nginxsetup"],
}
exec { 'reload-nginx':
command => "/data/nginx/sbin/nginx -s reload",
refreshonly => true,
}
file {hostname/conf.d",
notify => Exec["reload-nginx"],
require => Exec["nginxsetup"],
}
file { hostname/nginx_logrote.sh",
}
cron {"nginx_logrote_cron":
command => "/bin/bash $nginx_logrote > /dev/null 2>&1",
user => root,minute => '0',hour => '0',
}
}
class linuxnginx::openresty1136 {
nginx_user ? {'' => 'nginx',default => nginx_conf = "/data/openresty/nginx/conf.d"
$nginx_logrote = "/data/openresty/nginx/conf.d/nginx_logrote.sh"
file {"/data/openresty.sh":
ensure => present,
source => "puppet:///soft/openresty1136setup.sh",
}
exec {"openrestysetup":
command => "bash /data/openresty.sh",
cwd => "/data",
user => root,
provider => shell,
timeout => 1800,
logoutput => true,
require => File["/data/openresty.sh"],
unless => "ls /data/openresty",
}
file {'nginx.conf':
ensure => present,
mode => 644,owner => root,group => root,
path => "/data/openresty/nginx/conf/nginx.conf",
content => template('/etc/puppet/modules/linuxnginx/templates/openresty.nginx.conf.erb'),
notify => Exec["reload-nginx"],
require => Exec["openrestysetup"],
}
exec { 'reload-nginx':
command => "/data/openresty/nginx/sbin/nginx -s reload",
refreshonly => true,
}
file {hostname/nginx/conf.d",
notify => Exec["reload-nginx"],
require => Exec["openrestysetup"],
}
file { hostname/nginx/nginx_logrote.sh",
}
cron {"nginx_logrote_cron":
command => "/bin/bash $nginx_logrote > /dev/null 2>&1",
user => root,minute => '0',hour => '0',
}
}
vi /etc/puppet/manifests/nodes/huangat-test.pp
node 'huangat-test' {
include linuxnginx::nginx1102
}
node 'api2' {
include linuxnginx::openresty1136
}