分布式网站部署-创新互联
一、首先安装memcached(A主机、B主机都需要安装)
我们注重客户提出的每个要求,我们充分考虑每一个细节,我们积极的做好网站设计制作、成都网站建设服务,我们努力开拓更好的视野,通过不懈的努力,创新互联赢得了业内的良好声誉,这一切,也不断的激励着我们更好的服务客户。 主要业务:网站建设,网站制作,网站设计,小程序开发,网站开发,技术开发实力,DIV+CSS,PHP及ASP,ASP.Net,SQL数据库的技术开发工程师。下载地址:http://download.csdn.net/detail/ttyyadd/9414586
下载完成后解压到本地磁盘。
打开cmd命令窗口进行到memcached.exe所在目录,然后执行下面命令进行安装
memcached.exe -d install
安装后并没有启动需要到服务管理里面找到memached服务将它启动。
二、下面开始配置tomcat6
1、首先下载所需要jar
将下载的jar放到tomcat目录下的lib文件夹下面
http://download.csdn.net/detail/ttyyadd/9414529
2、开始配置(A主机:192.168.7.100)context.xml
开始配置(B主机:192.168.7.101)context.xml
这里要注意的是failoverNodes属性,该属性值要指向(非本机的)另外一台主机。
3、新建一个test.jsp页面,分别放到A主机和B主机的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参数表示权值,权值越高被分配到的几率越大
#1.down 表示单前的server暂时不参与负载
#2.weight 默认为1.weight越大,负载的权重就越大。
#3.backup: 其它所有的非backup机器down或者忙的时候,请求backup机器。所以这台机器压力会最轻。
#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;
# }
#}
}
保存并关闭。nginx.conf 文件内容比较多,其实只需要修改红色字体部分
然后在cmd窗口进入安装目录启动nginx命令是:
start nginx
nginx其它相关命令:
1) 启动Nginx:start nginx
2) 停止Nginx:nginx -s stop
3) 修改配置后重启:nginx -s reload
到现在已经配置完成
开始访问:http://192.168.7.100/test.jsp
可以看到session id不会改变。
本文题目:分布式网站部署-创新互联
文章起源:http://scyanting.com/article/dpsdho.html