nginx tomcat集群实现负载均衡
nginxtomcat集群server负载均衡file
1、安装nginx
所需的prce库
wgetftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.10.tar.gz
tarzxvfpcre-8.10.tar.gz
cdpcre-8.10/
./configure
make&&makeinstall
cd../
安装nginx
wget http://nginx.org/download/nginx-0.8.54.tar.gz
wget http://nginx.org/download/nginx-1.0.2.tar.gz
tarzxvfnginx-1.0.2.tar.gz
cdnginx-1.0.2/
./configure–user=www –group=www–prefix=/usr/local/nginx–with-http_stub_status_module–with-http_ssl_module
make&&makeinstall
cd../
创建nginx日志目录
mkdir-p/home/nginx/logs
chmod w/home/nginx/logs
chown-rwww:www/home/nginx/logs
创建nginx配置文件
①、在/usr/local/nginx/conf/目录中创建nginx.conf文件:
rm-f/usr/local/nginx/conf/nginx.conf
vi/usr/local/nginx/conf/nginx.conf
输入以下内容:
userwww www;
worker_processes8;
error_log/home/nginx/logs/nginx_error.logcrit;
pid/usr/local/nginx/nginx.pid;
worker_rlimit_nofile65535;
events
{
useepoll;
worker_connections65535;
}
http
{
includemime.types;
default_typeapplication/octet-stream;
#charsetgb2312;
server_names_hash_bucket_size128;
client_header_buffer_size32k;
large_client_header_buffers432k;
client_max_body_size8m;
sendfileon;
tcp_nopushon;
keepalive_timeout60;
tcp_nodelayon;
fastcgi_connect_timeout300;
fastcgi_send_timeout300;
fastcgi_read_timeout300;
fastcgi_buffer_size64k;
fastcgi_buffers464k;
fastcgi_busy_buffers_size128k;
fastcgi_temp_file_write_size128k;
gzipon;
gzip_min_length1k;
gzip_buffers416k;
gzip_http_version1.0;
gzip_comp_level2;
gzip_typestext/plainapplication/x-javascripttext/cssapplication/xml;
gzip_varyon;
#limit_zonecrawler$binary_remote_addr10m;
#测试
server
{
listen80;
server_name www.test.com;
indexindex.htmindex.htmlindex.jsp;
root/home/htdocs/web/root/;
location~.*$
{
indexindex.jsp;
proxy_pass http://www.test.com:8080;
}
access_loglogs/sp.imichat.com.logcombined;
error_page404=/404.html;
}
}
②、在/usr/local/nginx/conf/目录中创建fcgi.conf文件:
vi/usr/local/nginx/conf/fcgi.conf
输入以下内容:
fastcgi_paramgateway_interfacecgi/1.1;
fastcgi_paramserver_softwarenginx;
fastcgi_paramquery_string$query_string;
fastcgi_paramrequest_method$request_method;
fastcgi_paramcontent_type$content_type;
fastcgi_paramcontent_length$content_length;
fastcgi_paramscript_filename$document_root$fastcgi_script_name;
fastcgi_paramscript_name$fastcgi_script_name;
fastcgi_paramrequest_uri$request_uri;
fastcgi_paramdocument_uri$document_uri;
fastcgi_paramdocument_root$document_root;
fastcgi_paramserver_protocol$server_protocol;
fastcgi_paramremote_addr$remote_addr;
fastcgi_paramremote_port$remote_port;
fastcgi_paramserver_addr$server_addr;
fastcgi_paramserver_port$server_port;
fastcgi_paramserver_name$server_name;
#phponly,requiredifphpwasbuiltwith–enable-force-cgi-redirect
fastcgi_paramredirect_status200;
启动nginx
ulimit-shn65535
/usr/local/nginx/sbin/nginx
配置开机自动启动nginx
vi/etc/rc.local
在末尾增加以下内容:
ulimit-shn65535
/usr/local/nginx/sbin/nginx
优化linux内核参数
vi/etc/sysctl.conf
在末尾增加以下内容:
#add
net.ipv4.tcp_max_syn_backlog=65536
net.core.netdev_max_backlog=32768
net.core.somaxconn=32768
net.core.wmem_default=8388608
net.core.rmem_default=8388608
net.core.rmem_max=16777216
net.core.wmem_max=16777216
net.ipv4.tcp_timestamps=0
net.ipv4.tcp_synack_retries=2
net.ipv4.tcp_syn_retries=2
net.ipv4.tcp_tw_recycle=1
#net.ipv4.tcp_tw_len=1
net.ipv4.tcp_tw_reuse=1
net.ipv4.tcp_mem=94500000915000000927000000
华为云服务器挂千牛电脑中迅雷下载服务总是自动启动并占用网络资源怎么办云服务器优惠必看建网站需要了解哪些 域名跟网站什么关系腾讯云购买了服务器怎么用腾讯云服务器怎么存网站资料申请一个商标大概用多少钱不了解服务器?一文教你告别小白