CentOS 6 nginx(Tengine2.1.2)源码编译一键部署脚本

前端之家收集整理的这篇文章主要介绍了CentOS 6 nginx(Tengine2.1.2)源码编译一键部署脚本前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

目标:一键部署Nginx

软件:tengine-2.1.2.tar.gz(Nginx的分支)

备注:只适用于CentOS 6 64位系统,附带线上生产环境的Nginx配置文件

软件包:链接:http://pan.baidu.com/s/1jIyZrRS 密码:q9uu


[root@salt-master home]# cat Nginx.sh

#!/bin/bash

#

#适用版本CentOS 6 64位

#2017.5.11

. /etc/init.d/functions

dir=/root/test

user=www

group=www

del_dir() {

read -p "需要删除${dir} 是否删除[Y|y/N|n]:" del

case $del in

Y|y)

rm -rf $dir

mkdir $dir

cd $dir

;;

N|n)

echo "安装终止"

exit 7

;;

*)

echo "请输入正确的值"

exit 8

;;

esac

}

[ ! -d $dir ] && {

mkdir $dir

cd $dir

} || del_dir

wget http://172.2.0.68/tengine-2.1.2.tar.gz

wgethttp://172.2.0.68/nginx.txt

wget http://172.2.0.68/pcre-8.31.tar.bz2

yum -y install gcc gcc-c++ pcre-devel openssl-devel

[ ! `grep $group /etc/group &>/dev/null` ] && {

groupadd www

}

[ ! `grep $user /etc/passwd &>/dev/null` ] && {

useradd -M -g www -s /sbin/nologin www

}

echo "###########安装pcre######################"

sleep 4

tar -jxvf pcre-8.31.tar.bz2

[ $? -eq 0 ] && cd pcre-8.31 || exit 6

./configure --prefix=/usr/local/pcre

make && make install

#######################################

cd ..

[ -e $dir/tengine-2.1.2.tar.gz ] && {

tar -zxvf tengine-2.1.2.tar.gz

cd tengine-2.1.2

}

./configure --user=www --group=www --prefix=/mnt/tengine/tengine-2.1.2 --with-http_stub_status_module --with-pcre --with-http_ssl_module --with-http_gzip_static_module --with-http_realip_module --with-http_upstream_check_module --with-ipv6

[ $? -eq 0 ] && {

make && make install

} || {

echo "编译出错"

exit 7

}

[ -f $dir/Nginx.txt ] && {

mv /mnt/tengine/tengine-2.1.2/conf/Nginx.conf /mnt/tengine/tengine-2.1.2/conf/Nginx.confbak

cat $dir/Nginx.txt >/mnt/tengine/tengine-2.1.2/conf/Nginx.conf

} || {

echo "配置文件填写错误,请检查配置文件Nginx.conf"

exit 5

}

echo "###启动服务####"

/mnt/tengine/tengine-2.1.2/sbin/Nginx -t

[ $? -eq 0 ] && {

/mnt/tengine/tengine-2.1.2/sbin/Nginx

} || {

echo "启动服务失败"

exit 8

}


###########################################################################################

[root@linux-node8 html]# cat Nginx.txt

user www www;

worker_processes 1;

pid /mnt/tengine/tengine-2.1.2/logs/Nginx.pid;

worker_rlimit_nofile 65535;

events {

use epoll;

worker_connections 4096;

}

http {

include mime.types;

default_type application/octet-stream;

#charset utf-8;

access_log off;

error_log logs/error.log notice;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '

'$status $body_bytes_sent "$http_referer" '

'"$http_user_agent" "$http_x_forwarded_for"$request_time"';

server_names_hash_bucket_size 128;

client_header_buffer_size 32k;

large_client_header_buffers 4 32k;

client_max_body_size 300m;

sendfile on;

tcp_nopush on;

keepalive_timeout 65;

tcp_nodelay on;

server_tokens off;

client_body_buffer_size 512k;

proxy_connect_timeout 5;

proxy_read_timeout 60;

proxy_send_timeout 5;

proxy_buffer_size 16k;

proxy_buffers 4 64k;

proxy_busy_buffers_size 128k;

proxy_temp_file_write_size 128k;

gzip on;

gzip_min_length 1k;

gzip_buffers 4 16k;

gzip_http_version 1.1;

gzip_comp_level 2;

gzip_types text/plain application/x-javascript text/css application/xml;

gzip_vary on;


server {

listen 80;

server_name localhost;

location / {

root html;

index index.html index.htm;

}

error_page 500 502 503 504 /50x.html;

location = /50x.html {

root html;

}

}


upstream backend_server {

ip_hash;

server 192.168.1.10:80 max_fails=2 fail_timeout=30s;

server 192.168.1.20:80 max_fails=2 fail_timeout=30s;

}

server{

listen 80;

server_name www.abc.com;

server_name abc.com;

server_name testindex.abc.com;

location / {

proxy_redirect off;

#proxy_next_upstream http_502 http_504 error timeout invalid_header;

proxy_set_header Host $host;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_pass http://backend_server;

}

}

upstream sqzone_api{

ip_hash;

server 192.168.0.10:80 max_fails=2 fail_timeout=30s;

server 192.168.0.20:80 max_fails=2 fail_timeout=30s;

}

server{

listen 80;

server_name sqZone.test.com;

server_name sqapi.test.com;

server_name sqapiby.test.com;

server_name sqapiby1.test.com;

server_name sqapitixing.test.com;

server_name sqapitixingby.test.com;

server_name sqapitixingby1.test.com;

location / {

proxy_redirect off;

proxy_set_header Host $host;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_pass http://sqzone_api;

}

}

}

原文链接:https://www.f2er.com/centos/377611.html

猜你在找的CentOS相关文章