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
}

目录
相关文章
|
23天前
|
Linux 测试技术 网络安全
Linux系统之安装OneNav个人书签管理器
【10月更文挑战第19天】Linux系统之安装OneNav个人书签管理器
41 5
Linux系统之安装OneNav个人书签管理器
|
25天前
|
监控 Java Linux
Linux系统之安装Ward服务器监控工具
【10月更文挑战第17天】Linux系统之安装Ward服务器监控工具
49 5
Linux系统之安装Ward服务器监控工具
|
7天前
|
存储 安全 数据管理
如何在 Rocky Linux 8 上安装和配置 Elasticsearch
本文详细介绍了在 Rocky Linux 8 上安装和配置 Elasticsearch 的步骤,包括添加仓库、安装 Elasticsearch、配置文件修改、设置内存和文件描述符、启动和验证 Elasticsearch,以及常见问题的解决方法。通过这些步骤,你可以快速搭建起这个强大的分布式搜索和分析引擎。
20 5
|
27天前
|
JSON JavaScript Linux
Linux系统之安装cook菜谱工具
【10月更文挑战第15天】Linux系统之安装cook菜谱工具
34 2
Linux系统之安装cook菜谱工具
|
29天前
|
Ubuntu Linux 测试技术
Linux系统之Ubuntu安装cockpit管理工具
【10月更文挑战第13天】Linux系统之Ubuntu安装cockpit管理工具
109 4
Linux系统之Ubuntu安装cockpit管理工具
|
20天前
|
消息中间件 Linux RocketMQ
在Red Hat Enterprise Linux 9上使用Docker快速安装并部署
通过以上步骤,你可以在Red Hat Enterprise Linux 9上使用Docker快速安装并部署RocketMQ。这种方法不仅简化了安装过程,还提供了一个灵活的环境来管理和扩展消息队列系统。RocketMQ作为一款高性能的分布式消息系统,通过Docker可以实现快速部署和高效管理。
46 2
|
20天前
|
消息中间件 Linux RocketMQ
在Red Hat Enterprise Linux 9上使用Docker快速安装并部署
通过以上步骤,你可以在Red Hat Enterprise Linux 9上使用Docker快速安装并部署RocketMQ。这种方法不仅简化了安装过程,还提供了一个灵活的环境来管理和扩展消息队列系统。RocketMQ作为一款高性能的分布式消息系统,通过Docker可以实现快速部署和高效管理。
29 3
|
23天前
|
Ubuntu 应用服务中间件 Linux
Linux下搭建Nginx环境的搭建
Linux下搭建Nginx环境的搭建
|
4天前
|
存储 缓存 Linux
【Linux】另一种基于rpm安装yum的方式
通过本文的方法,您可以在离线环境中使用RPM包安装YUM并进行必要的配置。这种方法适用于无法直接访问互联网的服务器或需要严格控制软件源的环境。通过配置本地YUM仓库,确保了软件包的安装和更新可以顺利进行。希望本文能够为您在特定环境中部署YUM提供实用的指导。
28 0
|
9天前
|
关系型数据库 MySQL Linux
Linux-安装Mariadb
本文介绍了在 Alibaba Cloud Linux 系统上安装和配置 MariaDB 10.5 的步骤。包括下载安装、初始化数据库、启动服务、处理启动失败的常见问题(如权限问题),以及如何连接数据库、设置密码和允许外部连接。通过这些步骤,您可以顺利完成 MariaDB 的安装和基本配置。
22 0