码迷,mamicode.com
首页 > Web开发 > 详细

分布式网站部署

时间:2016-01-22 21:03:38      阅读:199      评论:0      收藏:0      [点我收藏+]

标签:

环境介绍:两台win2008_x64位主机+jdk7_x64位 分别为A主机IP:192.168.7.100、B主机IP:192.168.7.101

一、首先安装memcached(A主机、B主机都需要安装)

下载地址: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

<Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager"
    memcachedNodes="n1:192.168.7.100:11211,n2:192.168.7.101:11211"
    failoverNodes="n2"
    requestUriIgnorePattern=".*\.(ico|png|gif|jpg|css|js)$"
    transcoderFactoryClass="de.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory"
    />

开始配置(B主机:192.168.7.101)context.xml

<Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager"
    memcachedNodes="n1:192.168.7.100:11211,n2:192.168.7.101:11211"
    failoverNodes="n1"
    requestUriIgnorePattern=".*\.(ico|png|gif|jpg|css|js)$"
    transcoderFactoryClass="de.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory"
    />

这里要注意的是failoverNodes属性,该属性值要指向(非本机的)另外一台主机。

3、新建一个test.jsp页面,分别放到A主机和B主机的Tomcat 下的ROOT目录

<%@ page language="java" %>
<%@ page import="java.util.*" %>

<html><head><title></title></head>

<body>

<%

System.out.println(session.getId());

out.println("<br> HostA HostB, SESSION ID:" + session.getId()+"<br>");

%>

</body>

</html>

三、配置nginx

1、首先下载 nginx安装包

  http://nginx.org/

2、开始配置nginx

打开安装目录的nginx.conf。我的安装目录为(D:\nginx-1.9.9\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;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #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 {
        listen       80;
        server_name  192.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_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 Apaches document root
        # concurs with nginxs 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.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://www.cnblogs.com/lvlv/p/5151744.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!