分布式網(wǎng)站部署-創(chuàng)新互聯(lián)

環(huán)境介紹:兩臺win2008_x64位主機+jdk7_x64位 分別為A主機IP:192.168.7.100、B主機IP:192.168.7.101分布式網(wǎng)站部署

一、首先安裝memcached(A主機、B主機都需要安裝)

我們注重客戶提出的每個要求,我們充分考慮每一個細節(jié),我們積極的做好網(wǎng)站設(shè)計制作、成都網(wǎng)站建設(shè)服務(wù),我們努力開拓更好的視野,通過不懈的努力,創(chuàng)新互聯(lián)贏得了業(yè)內(nèi)的良好聲譽,這一切,也不斷的激勵著我們更好的服務(wù)客戶。 主要業(yè)務(wù):網(wǎng)站建設(shè),網(wǎng)站制作,網(wǎng)站設(shè)計,小程序開發(fā),網(wǎng)站開發(fā),技術(shù)開發(fā)實力,DIV+CSS,PHP及ASP,ASP.Net,SQL數(shù)據(jù)庫的技術(shù)開發(fā)工程師。

下載地址:http://download.csdn.net/detail/ttyyadd/9414586

下載完成后解壓到本地磁盤。

打開cmd命令窗口進行到memcached.exe所在目錄,然后執(zhí)行下面命令進行安裝

memcached.exe -d install

安裝后并沒有啟動需要到服務(wù)管理里面找到memached服務(wù)將它啟動。

二、下面開始配置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: 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暫時不參與負載
      #2.weight 默認為1.weight越大,負載的權(quán)重就越大。     
      #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;
    #    }
    #}

}

保存并關(guān)閉。nginx.conf 文件內(nèi)容比較多,其實只需要修改紅色字體部分

然后在cmd窗口進入安裝目錄啟動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不會改變。

分享標(biāo)題:分布式網(wǎng)站部署-創(chuàng)新互聯(lián)
文章出自:http://muchs.cn/article40/dpsdho.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)網(wǎng)站建設(shè)、網(wǎng)站改版、品牌網(wǎng)站制作、品牌網(wǎng)站設(shè)計、搜索引擎優(yōu)化商城網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站優(yōu)化排名