Nginx Tomcat 集群负载均衡设置笔记

1、Windows

下载nginx 地址:http://nginx.org/ 本文章使用的版本为1.5.4

下载完后解压,在conf目录修改nginx.conf我的配置如下:

#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;

events {
worker_connections 1024;
}

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;

client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;

client_header_buffer_size 1k;
large_client_header_buffers 4 4k;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
#tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
upstream localhost {
#根据ip计算将请求分配各那个后端tomcat,许多人误认为可以解决session问题,其实并不能。
#同一机器在多网情况下,路由切换,ip可能不同
#ip_hash;
server localhost:9097 weight=1;
server localhost:9098 weight=1;
server localhost:9097 backup;
server localhost:9098 backup;
#jvm_route $cookie_JSESSIONID|sessionid reverse; #session复制的配置
ip_hash;
}

阅读更多

CentOS 6.2 编译安装Squid 配置反向代理服务器

Linux操作系统:CentOS 6.2
squid安装:
1.下载squid源码安装包
wget http://www.squid-cache.org/Versions/v3/3.2/squid-3.2.3.tar.gz
解压缩
tar zxvf squid-3.2.3.tar.gz
进入解压后的目录
cd squid-3.2.3(目录位置依据个人设定而不同)
安装
[root@localhost squid-3.2.3]# ./configure –prefix=/usr/local/squid –enable-gnuregex –enable-icmp –enable-linux-netfilter –enable-default-err-language=”Simplify_Chinese” –enable-kill-parent-hack –enable-cache-digests –enable-dlmalloc –enable-poll –enable-async-io=240 –enable-delay-pools –with-filedescriptors=65536 –enable-snmp –enable-arp-acl –mandir=/usr/share/man/ –with-large-files
[root@localhost squid-3.2.3]#make && make install
如果你用的是centos系统的最小化安装,可能没有安装c语言编译器,需要手动安装,如安装过程中出现以下错误:
-bash: make: command not found
这是因为没有安装编译器,用以下命令安装:
yum install gcc* ;yum -y install gcc-*
安装后,再次make就可以。至此,squid就安装到服务器上,接下来配置反向代理。
Squid反向代理配置(如下所示):

http_port 80 vhost vport
cache_mem 256 MB
maximum_object_size_in_memory 2048 KB
memory_replacement_policy lru
cache_dir ufs /var/spool/squid 20480 16 256
access_log /var/log/squid/access.log
cache_log /var/log/squid/cache.log
max_open_disk_fds 0
minimum_object_size 0 KB
maximum_object_size 32768 KB
#logformat combined %>a %ui %un [%tl] “%rm %ru HTTP/%rv” %Hs %<st “%{Referer}>h””%{User-Agent}>h” %Ss:%Sh
cache_peer 125.39.127.22 parent 80 0 no-query no-digest originserver name=88181
#需要反向代理的源WEB服务器,可以添加多个 ,若只有一个源WEB服务器,可不设name
cache_peer 118.144.78.54 parent 80 0 no-query no-digest originserver name=jj
#需要反向代理的源WEB服务器,可以添加多个
cache_peer_domain evanjiang.com
#若只有一个源WEB服务器,可不设cache_peer_domain

阅读更多

CentOS 6.3下Nginx性能调优

一.Nginx优化配置
1.主配置文件优化:
# vi /usr/local/nginx/conf/nginx.conf
—————————————–
user nginx nginx;
worker_processes 8;
worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000;

error_log /usr/local/nginx/logs/nginx_error.log crit;

pid /usr/local/nginx/logs/nginx.pid;

worker_rlimit_nofile 204800;

events
{
use epoll;
worker_connections 204800;
}

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;

charset utf-8;

server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 20m;

sendfile on;
tcp_nopush on;

keepalive_timeout 60;

阅读更多