tengine 安装配置

2015年2月12日14:56:28 评论 6,445

参考阅读:http://tengine.taobao.org/

1. 下载安装包解压安装(pcre=/opt/pcre-8.35路径是pcre包的解压路径)

# wget http://tengine.taobao.org/download/tengine-2.0.2.tar.gz

# tar -zxvf tengine-2.0.2.tar.gz

# ./configure --prefix=/usr/local/nginx --with-pcre=/opt/pcre-8.35

# make && make install

2. 下载pcre安装包,解压安装

# wget http://exim.mirror.fr/pcre/pcre-8.35.tar.gz

# tar -zxvf pcre-8.35.tar.gz

# mkdir /usr/local/pcre

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

# make && make install

3.创建nginx目录,并赋予权限

# /usr/local/nginx/sbin/nginx

# chown nobody.nobody -R /usr/local/nginx/html

# chmod 700 -R /usr/local/nginx/html

4.设置开机启动

# chmod 775 /etc/rc.d/init.d/nginx

# chkconfig nginx on

5.配置nginx(具体参数根据实际情况调整)

vim /usr/local/nginx/conf/nginx.conf
#user www www;
worker_processes auto;
worker_cpu_affinity  auto;
error_log logs/error.log;
pid logs/nginx.pid;

events {
use epoll;
worker_connections 10240;
}

http {
include mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

#access_log logs/access.log main;
limit_conn_zone $binary_remote_addr zone=limit:10m;
sendfile on;
client_max_body_size 20m;
keepalive_timeout 65;

fastcgi_connect_timeout 300s;
fastcgi_send_timeout 300s;
fastcgi_read_timeout 300s;
fastcgi_buffer_size 128k;
fastcgi_buffers 8 128k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
#send_timeout 120;
proxy_connect_timeout 300;
proxy_send_timeout 300;
proxy_read_timeout 300;
send_timeout 300;
autoindex on;

upstream xxxsrv {
server 192.168.8.3:8080 max_fails=3 fail_timeout=5s;(最大失败3次,每次超时时间5秒)
server 192.168.8.4:8080 max_fails=3 fail_timeout=5s;
session_sticky;(保持Cookie一致性,即同一客户端连接保证指向的是同一个后端服务器)
}

server {
listen 80;
server_name xx.xx.xx.xx(IP或者域名);

access_log logs/host.access.log main;
error_log logs/xxxsrv.error.log error;

location / {
##如果后端的服务器返回502、504、执行超时等错误,自动将请求转发到upstream负载均衡池中的另一台服务器,实现故障转移
proxy_next_upstream http_502 http_504 http_404 error timeout invalid_header
proxy_pass http://xxxsrv; ##为哪个backend做反向代理
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

location /nginx { ##nginx的状态页面
access_log off;
stub_status on;
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}

6. nginx管理脚本参考https://yangfannie.com/?p=91

weinxin
聂扬帆博客
一个分享IT运维相关工作经验和实战技巧的个人博客

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: