一.nginx tomcat集群安装简介
二.集群环境准备
192.168.139.131
192.168.139.132
192.168.139.131:8131
192.168.139.132:8132
192.168.139.131:6131
192.168.139.132:6132
第三步.安装tomcat
mv /home/wgy/apache-tomcat-7.0.67.tar.gz./local/tomcat/
3.解压缩apache-tomcat-7.0.67.tar.gz
tar -zxvf apache-tomcat-7.0.67.tar.gz
4.到apache-tomcat-7.0.67的bin目录下驱动tomcat
./startup.sh
5.停止tomcat服务,修改server.xml文件tomcat默认访问端口
[root@master bin] ./shutdown.sh
[root@master conf]# vi server.xml
<Connector port="8130" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
6.重启tomcat服务
安装成功:
7.在另外的两台机器执行相同的步骤,安装tomcat(也可以把安装成功的配置copy到其他两台机器上),这样三台服务器的tomcat安装结束
第四步.安装nginx
第五步.配置nginx负载均衡
worker_processes 1;
#全局错误日志定义,建议开启error级别日志.[ debug | info | notice | warn | error | crit ]
error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
#epoll是多路复用IO(I/O Multiplexing)中的一种方式,但是仅用于linux2.6以上内核,可以大大提高nginx的性能.Linux建议使用epoll,FreeBSD建议使用#kqueue.
events {
use epoll;
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;
sendfile on;
#tcp_nopush on;
#http连接的持续时间
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
#gzip压缩设置
gzip on; #开启gzip
gzip_min_length 1k; #最小压缩文件大小
gzip_buffers 4 16k; #压缩缓冲区
#http的协议版本(1.0/1.1),默认1.1,前端如果是squid2.5请使用1.0
gzip_http_version 1.1;
#gzip压缩比,1压缩比最小处理速度最快,9压缩比最大但处理速度最慢(传输快但比较消耗cpu)
gzip_comp_level 2;
#和http头有关系,加个vary头,给代理服务器用的,有的浏览器支持压缩,有的不支持,所以避免浪费不支持的也压缩,所以根据客户端的HTTP头来判断,是否需要压缩
gzip_vary on;
#gzip压缩类型,不用添加text/html,否则会有警告信息
gzip_types text/plain text/javascript text/css application/xmlapplication/x-javascript application/json;
#设定负载均衡的服务器列表,可以设置多个upstream,但是upstream 名称192.168.139.131不同
upstream 192.168.139.131{ip_hash;
server 192.168.139.130:8130 weight=1;
server 192.168.139.131:8131 weight=1;
server 192.168.139.132:8132 weight=1;
}
server {
listen 6131;
server_name 192.168.139.131;
#charset koi8-r;
charset utf-8
#设定本虚拟主机的访问日志。关闭日志可以减少IO,提高性能。
#access_log logs/host.access.log main;location / {
root html;
index index.html index.htm;
proxy_pass http://192.168.139.131;
proxy_redirect default;
proxy_connect_timeout 10;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
第六步.重启nginx服务
配置文件详细见:http://download.csdn.net/detail/wangguanyin98/9491234 欢迎下载