编译tengine/nginx集群tomcat
一、本次安装采用离线安装方法,需要准备的包
百度云下载地址
1. tengine-2.1.1.tar.gz
2. zlib-1.2.8.tar.gz
3. pcre-8.37.tar.gz
4. openssl-0.9.8zg.tar.gz
5. apache-tomcat-7.0.64.tar.gz
把zlib、pcre、 openssl 上传到 /usr/local/src/下
二、安装zlib
cd /usr/local/src/
tar xzvf zlib-1.2.8.tar.gz
cd zlib-1.2.8/
./configure
makle
make install
三、安装pcre
tar xzvf pcre-8.37.tar.gz
cd pcre-8.37/
./configure
make
make install
四、安装openssl
tar xzvf openssl-0.9.8zg.tar.gz
cd openssl-0.9.8zg/
./configure
make
make install
五、编译tengine-2.1.1.tar.gz 安装
把 tengine-2.1.1.tar.gz 上传到/usr/tengine-2.1.1.tar.gz
cd /usr
tar xzvf tengine-2.1.1.tar.gz
cd tenine-2.1.1
./configure --prefix=/usr/local/tengine --with-http_concat_module --without-http_trim_filter_module --with-pcre=/usr/local/src/pcre-8.37 --with-zlib=/usr/local/src/zlib-1.2.8 --with-openssl=/usr/local/src/openssl-0.9.8zg
make
make install
六、安装apache-tomcat-7.0.64.tar.gz
tar xzvf apache-tomcat-7.0.64.tar.gz
cd apache-tomcat-7.0.64/bin
./startup.sh
七、配置tengine
cd tengine/conf/
vi nginx.conf
user root root ;
worker_processes 4;
error_log logs/error.log crit;
pid logs/nginx.pid;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 65535;
events
{
use epoll;
worker_connections 65535;
}
http
{
include mime.types;
default_type application/octet-stream;
#charset gb2312;
log_format access '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 8m;
sendfile on;
tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
#limit_zone crawler $binary_remote_addr 10m;
upstream t1.zgl.com.cn {
ip_hash;
server 192.168.180.130:8080 max_fails=3 fail_timeout=10s;
server 192.168.180.131:8080 max_fails=3 fail_timeout=10s;
#server 10.58.56.64:8083 max_fails=3 fail_timeout=10s;
check interval=3000 rise=2 fall=5 timeout=180000 type=tcp;
}
server
{
listen 80;
server_name 192.168.180.130;
access_log ./logs/csc.cart.access.log access;
ssi on;
ssi_silent_errors on;
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
add_header X-Cache "$upstream_cache_status from proxy 43";
add_header Nginx-Cache "$upstream_cache_status";
proxy_redirect off;
proxy_pass http://t1.zgl.com.cn;
}
}
}
八、启动tengine
测试 /usr/local/tengine/sbin/nginx -c /usr/local/tengine/conf/nginx.conf -t
启动 /usr/local/tengine/sbin/nginx -c /usr/local/tengine/conf/nginx.conf
关闭 kill -9 `ps -ef |grep nginx|grep -v grep|awk '{print $2}'`
重启/usr/local/tengine/sbin/nginx -c /usr/local/tengine/conf/nginx.conf -s reload
九、访问192.168.180.130
十、经过压测 频繁出现 502 504错误
nginx proxy: connect() to ip:80 failed (99: Cannot assign requested address)
modify /etc/sysctl.conf:
net.ipv4.tcp_timestamps = 1
net.ipv4.tcp_tw_recycle = 0
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_max_tw_buckets = 10000
net.ipv4.ip_nonlocal_bind = 1
sysctl -p