新聞中心

一、首先安裝memcached(A主機(jī)、B主機(jī)都需要安裝)
下載地址:http://download.csdn.net/detail/ttyyadd/9414586
下載完成后解壓到本地磁盤。
打開cmd命令窗口進(jìn)行到memcached.exe所在目錄,然后執(zhí)行下面命令進(jìn)行安裝
memcached.exe -d install
安裝后并沒有啟動需要到服務(wù)管理里面找到memached服務(wù)將它啟動。
二、下面開始配置tomcat6
1、首先下載所需要jar
將下載的jar放到tomcat目錄下的lib文件夾下面
http://download.csdn.net/detail/ttyyadd/9414529
2、開始配置(A主機(jī):192.168.7.100)context.xml
開始配置(B主機(jī):192.168.7.101)context.xml
這里要注意的是failoverNodes屬性,該屬性值要指向(非本機(jī)的)另外一臺主機(jī)。
3、新建一個test.jsp頁面,分別放到A主機(jī)和B主機(jī)的Tomcat 下的ROOT目錄
<%@ page language="java" %>
<%@ page import="java.util.*" %>
<%
System.out.println(session.getId());
out.println("
HostA HostB, SESSION ID:" + session.getId()+"
");
%>
三、配置nginx
1、首先下載 nginx安裝包
http://nginx.org/
2、開始配置nginx
打開安裝目錄的nginx.conf。我的安裝目錄為(D: ginx-1.9.9conf ginx.conf)
#user nobody;
worker_processes1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections1024;
}
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;
#keepalive_timeout0;
keepalive_timeout65;
#gzip on;
upstream mysvr {
#weigth參數(shù)表示權(quán)值,權(quán)值越高被分配到的幾率越大
#1.down 表示單前的server暫時不參與負(fù)載
#2.weight 默認(rèn)為1.weight越大,負(fù)載的權(quán)重就越大。
#3.backup: 其它所有的非backup機(jī)器down或者忙的時候,請求backup機(jī)器。所以這臺機(jī)器壓力會最輕。
#server 192.168.1.116 down;
#server 192.168.1.116 backup;
server 192.168.7.100:8080 weight=1;
server 192.168.7.101:8080 weight=1;
}
server {
listen80;
server_name192.168.7.100; #charset koi8-r;
#access_log logs/host.access.log main;
location/ {
proxy_pass http://mysvr;
proxy_connect_timeout 5s;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#禁用緩存
proxy_buffering off;
}
#error_page404 /404.html;
# redirect server error pages to thestatic page /50x.html
#
error_page500 502 503 504 /50x.html;
location= /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on127.0.0.1:80
#
#location~ .php$ {
# proxy_pass http://127.0.0.1; #}
# pass the PHP scripts to FastCGI server listening on127.0.0.1:9000
#
#location~ .php$ {
# root html;
# fastcgi_pass127.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;
#}
}
# anothervirtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location/ {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen443 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;
# }
#}
}
保存并關(guān)閉。nginx.conf 文件內(nèi)容比較多,其實只需要修改紅色字體部分
然后在cmd窗口進(jìn)入安裝目錄啟動nginx命令是:
start nginx
nginx其它相關(guān)命令:
1) 啟動Nginx:start nginx
2) 停止Nginx:nginx -s stop
3) 修改配置后重啟:nginx -s reload
到現(xiàn)在已經(jīng)配置完成
開始訪問:http://192.168.7.100/test.jsp
可以看到session id不會改變。
名稱欄目:分布式網(wǎng)站部署-創(chuàng)新互聯(lián)
網(wǎng)頁鏈接:http://fisionsoft.com.cn/article/dpsdho.html