puppet连载12:linux安装nginx、openresty

服务端在/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_addr -remote_user [time_local] "request"'
'statusbody_bytes_sent "http_referer"' '"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="{logs_path}(date -d "yesterday" +"%Y")/(date -d "yesterday" +"%m")/nginx_access_(date -d "yesterday" +"%Y%m%d").log"
ERROR_LOG="{logs_path}(date -d "yesterday" +"%Y")/(date -d "yesterday" +"%m")/nginx_access_(date -d "yesterday" +"%Y%m%d").log"

mkdir -p {logs_path}(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/

mv {logs_path}nginx_access.logACCESS_LOG
mv {logs_path}nginx_error.logERROR_LOG

kill -USR1 cat $PIDFILE

/bin/gzip -9 ACCESS_LOG /bin/gzip -9ERROR_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="{logs_path}(date -d "yesterday" +"%Y")/(date -d "yesterday" +"%m")/nginx_access_(date -d "yesterday" +"%Y%m%d").log"
ERROR_LOG="{logs_path}(date -d "yesterday" +"%Y")/(date -d "yesterday" +"%m")/nginx_access_(date -d "yesterday" +"%Y%m%d").log"

mkdir -p {logs_path}(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/

mv {logs_path}nginx_access.logACCESS_LOG
mv {logs_path}nginx_error.logERROR_LOG

kill -USR1 cat $PIDFILE

/bin/gzip -9 ACCESS_LOG /bin/gzip -9ERROR_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_addr -remote_user [time_local] "request"'
'statusbody_bytes_sent "http_referer"' '"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 {

real_nginx_user =nginx_user ? {'' => 'nginx',default => nginx_user }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 {nginx_conf: ensure => directory, recurse => true, purge => false, source => "puppet:///soft/nginx/hostname/conf.d",
notify => Exec["reload-nginx"],
require => Exec["nginxsetup"],
}
file { nginx_logrote: ensure => file, mode => 755,owner => root,group => root, source => "puppet:///soft/nginx/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 {

real_nginx_user =nginx_user ? {'' => 'nginx',default => nginx_user }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 {nginx_conf: ensure => directory, recurse => true, purge => false, source => "puppet:///soft/openresty/hostname/nginx/conf.d",
notify => Exec["reload-nginx"],
require => Exec["openrestysetup"],
}
file { nginx_logrote: ensure => file, mode => 755,owner => root,group => root, source => "puppet:///soft/openresty/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
}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 206,126评论 6 481
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 88,254评论 2 382
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 152,445评论 0 341
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 55,185评论 1 278
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 64,178评论 5 371
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,970评论 1 284
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,276评论 3 399
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,927评论 0 259
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 43,400评论 1 300
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,883评论 2 323
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,997评论 1 333
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,646评论 4 322
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,213评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,204评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,423评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,423评论 2 352
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,722评论 2 345

推荐阅读更多精彩内容