puppet连载12:linux安装nginx、openresty

简介: 服务端在/puppet/soft 里建nginx1102setup.sh,内容:!/bin/bashyum -y install wget libtool expat-devel gcc gcc-c++ glibc automake autocon...

服务端在/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
}

目录
相关文章
|
9天前
|
缓存 Linux 测试技术
安装【银河麒麟V10】linux系统--并挂载镜像
安装【银河麒麟V10】linux系统--并挂载镜像
58 0
|
9天前
|
Linux C语言
linux yum安装ffmpeg 图文详解
linux yum安装ffmpeg 图文详解
27 0
|
9天前
|
NoSQL Linux Redis
linux 下和win下安装redis 并添加开机自启 图文详解
linux 下和win下安装redis 并添加开机自启 图文详解
15 0
|
9天前
|
Linux
linux yum 安装rar和unrar
linux yum 安装rar和unrar
34 0
|
21天前
|
Java Linux Maven
Linux中安装MAVEN环境配置
Linux中安装MAVEN环境配置
47 3
|
22天前
|
存储 负载均衡 索引
linux7安装elasticsearch-7.4.0集群配置
linux7安装elasticsearch-7.4.0集群配置
109 0
|
26天前
|
Linux 数据安全/隐私保护 虚拟化
Linux技术基础(1)——操作系统的安装
本文是龙蜥操作系统(Anolis OS) 8.4 的安装指南,用户可以从[龙蜥社区下载页面](https://openanolis.cn/download)获取ISO镜像。安装方法包括物理机的光驱和USB闪存方式,以及虚拟机中的VMware Workstation Pro设置。安装过程涉及选择语言、配置安装目标、选择软件集合和内核,设置Root密码及创建新用户。安装完成后,可通过文本模式或图形化界面验证系统版本,如Anolis OS 8.4,标志着安装成功。
|
21天前
|
消息中间件 Java Linux
Linux下RabbitMQ安装与使用
Linux下RabbitMQ安装与使用
32 1
|
2天前
|
关系型数据库 MySQL Linux
Linux联网安装MySQL Server
Linux联网安装MySQL Server
10 0
|
17天前
|
Ubuntu Linux 虚拟化
【Linux】ubuntu安装samba服务器
【Linux】ubuntu安装samba服务器