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

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

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

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

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

@H_301_0@

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

@H_301_0@#!/bin/bash

@H_301_0@#

@H_301_0@#适用版本CentOS 6 64位

@H_301_0@#2017.5.11

@H_301_0@. /etc/init.d/functions

@H_301_0@dir=/root/test

@H_301_0@user=www

@H_301_0@group=www

@H_301_0@del_dir() {

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

@H_301_0@case $del in

@H_301_0@Y|y)

@H_301_0@rm -rf $dir

@H_301_0@mkdir $dir

@H_301_0@cd $dir

@H_301_0@;;

@H_301_0@N|n)

@H_301_0@echo "安装终止"

@H_301_0@exit 7

@H_301_0@;;

@H_301_0@*)

@H_301_0@echo "请输入正确的值"

@H_301_0@exit 8

@H_301_0@;;

@H_301_0@esac

@H_301_0@}

@H_301_0@[ ! -d $dir ] && {

@H_301_0@mkdir $dir

@H_301_0@cd $dir

@H_301_0@} || del_dir

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

@H_301_0@wgethttp://172.2.0.68/nginx.txt

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

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

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

@H_301_0@groupadd www

@H_301_0@}

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

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

@H_301_0@}

@H_301_0@echo "###########安装pcre######################"

@H_301_0@sleep 4

@H_301_0@tar -jxvf pcre-8.31.tar.bz2

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

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

@H_301_0@make && make install

@H_301_0@#######################################

@H_301_0@cd ..

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

@H_301_0@tar -zxvf tengine-2.1.2.tar.gz

@H_301_0@cd tengine-2.1.2

@H_301_0@}

@H_301_0@./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

@H_301_0@[ $? -eq 0 ] && {

@H_301_0@make && make install

@H_301_0@} || {

@H_301_0@echo "编译出错"

@H_301_0@exit 7

@H_301_0@}

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

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

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

@H_301_0@} || {

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

@H_301_0@exit 5

@H_301_0@}

@H_301_0@echo "###启动服务####"

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

@H_301_0@[ $? -eq 0 ] && {

@H_301_0@/mnt/tengine/tengine-2.1.2/sbin/Nginx

@H_301_0@} || {

@H_301_0@echo "启动服务失败"

@H_301_0@exit 8

@H_301_0@}

@H_301_0@

@H_301_0@

@H_301_0@###########################################################################################

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

@H_301_0@user www www;

@H_301_0@worker_processes 1;

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

@H_301_0@worker_rlimit_nofile 65535;

@H_301_0@events {

@H_301_0@ use epoll;

@H_301_0@ worker_connections 4096;

@H_301_0@}

@H_301_0@http {

@H_301_0@ include mime.types;

@H_301_0@ default_type application/octet-stream;

@H_301_0@ #charset utf-8;

@H_301_0@ access_log off;

@H_301_0@ error_log logs/error.log notice;

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

@H_301_0@ '$status $body_bytes_sent "$http_referer" '

@H_301_0@ '"$http_user_agent" "$http_x_forwarded_for"$request_time"';

@H_301_0@

@H_301_0@ server_names_hash_bucket_size 128;

@H_301_0@ client_header_buffer_size 32k;

@H_301_0@ large_client_header_buffers 4 32k;

@H_301_0@ client_max_body_size 300m;

@H_301_0@ sendfile on;

@H_301_0@ tcp_nopush on;

@H_301_0@ keepalive_timeout 65;

@H_301_0@ tcp_nodelay on;

@H_301_0@ server_tokens off;

@H_301_0@ client_body_buffer_size 512k;

@H_301_0@ proxy_connect_timeout 5;

@H_301_0@ proxy_read_timeout 60;

@H_301_0@ proxy_send_timeout 5;

@H_301_0@ proxy_buffer_size 16k;

@H_301_0@ proxy_buffers 4 64k;

@H_301_0@ proxy_busy_buffers_size 128k;

@H_301_0@ proxy_temp_file_write_size 128k;

@H_301_0@

@H_301_0@ gzip on;

@H_301_0@ gzip_min_length 1k;

@H_301_0@ gzip_buffers 4 16k;

@H_301_0@ gzip_http_version 1.1;

@H_301_0@ gzip_comp_level 2;

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

@H_301_0@ gzip_vary on;

@H_301_0@

@H_301_0@ server {

@H_301_0@ listen 80;

@H_301_0@ server_name localhost;

@H_301_0@ location / {

@H_301_0@ root html;

@H_301_0@ index index.html index.htm;

@H_301_0@ }

@H_301_0@ error_page 500 502 503 504 /50x.html;

@H_301_0@ location = /50x.html {

@H_301_0@ root html;

@H_301_0@ }

@H_301_0@ }

@H_301_0@

@H_301_0@

@H_301_0@upstream backend_server {

@H_301_0@ ip_hash;

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

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

@H_301_0@}

@H_301_0@server{

@H_301_0@ listen 80;

@H_301_0@ server_name www.abc.com;

@H_301_0@ server_name abc.com;

@H_301_0@ server_name testindex.abc.com;

@H_301_0@ location / {

@H_301_0@ proxy_redirect off;

@H_301_0@ #proxy_next_upstream http_502 http_504 error timeout invalid_header;

@H_301_0@ proxy_set_header Host $host;

@H_301_0@ proxy_set_header X-Real-IP $remote_addr;

@H_301_0@ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

@H_301_0@ proxy_pass http://backend_server;

@H_301_0@ }

@H_301_0@}

@H_301_0@upstream sqzone_api{

@H_301_0@ ip_hash;

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

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

@H_301_0@}

@H_301_0@server{

@H_301_0@ listen 80;

@H_301_0@ server_name sqZone.test.com;

@H_301_0@ server_name sqapi.test.com;

@H_301_0@ server_name sqapiby.test.com;

@H_301_0@ server_name sqapiby1.test.com;

@H_301_0@ server_name sqapitixing.test.com;

@H_301_0@ server_name sqapitixingby.test.com;

@H_301_0@ server_name sqapitixingby1.test.com;

@H_301_0@ location / {

@H_301_0@ proxy_redirect off;

@H_301_0@ proxy_set_header Host $host;

@H_301_0@ proxy_set_header X-Real-IP $remote_addr;

@H_301_0@ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

@H_301_0@ proxy_pass http://sqzone_api;

@H_301_0@ }

@H_301_0@}

@H_301_0@}

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

猜你在找的CentOS相关文章