windows 아래 nginx + tomcat 클 러 스 터, session 복사 공유 실현

2221 단어
서로 다른 서버 두 대 ip1、ip2。ip1 설치 tomcat 1, 포트 8005, 8081, 8009, nginx, nginx 외부 네트워크 포트 80, ip2 설치 tomcat 2, 포트 8006, 8082, 8010.
1. apache tomcat 를 설치 합 니 다.
2. ng 을 설치 하고 압축 을 풀 어 ip1 에 설치 하 며 필요 에 따라 설정 파일 nginx. conf 를 수정 합 니 다.
4. 567913. 이때 tomcat 1, 2 가 시작 되면 사용 합 니 다.http://nginx.ip방문, ng 로 그 를 보면 ip1 서버 를 요청 할 때 도 있 고, ip2 를 요청 할 때 도 있 습 니 다.이것 은 이미 ng 부하 기능 에 이 르 렀 다.
windows nginx 명령:
닫 기: nginx. exe - s stop
시작: start nging. exe
nginx. exe 재 부팅 - s reload
주, 그러나 이때 tomcat 1, tomcat 2 가 같은 프로젝트 를 배치 하기 때문에 데이터 가 있 으 면 session 에 직접 쓰 고 사용 하 는 쿠키 가 아 닌 session 의 key (방문 주 소 는 ip 을 사용 하기 때문에 도 메 인 이름 이 적용 되 지 않 기 때문에 쿠키 를 사용 할 수 없습니다) 는 두 번 의 방문 session id 가 일치 하지 않 습 니 다.이 때 는 session 복사 나 공 유 를 해 야 합 니 다.다음 작업 이 필요 합 니 다:
3. tomcat 의 conf, server. xml 파일 수정 (두 tomcat 수정 일치):
tomcat 군집 주석 cluster 를 엽 니 다.
노드 < Engine name = "Catalina" defaultHost = "localhost" jvmRoute = "driver 1" > 을 수정 합 니 다.(tomcat 1 과 tomcat 2 가 지정 한 jvmRoute 이름 이 일치 합 니 다)
4. 프로젝트 코드 에 웹. xml 에 노드 < distributable / > 를 추가 하면 됩 니 다.
테스트:
index.jsp:
#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;
    sendfile        on;
    keepalive_timeout  65;

    upstream portal-driver{
	server ip1:8081 max_fails=0;
        server ip2:8082 max_fails=0;
    }
    

    server {
        listen       80;
        server_name  localhost;

        location /drive{
            root   html;
            index  index.html index.htm;
            proxy_pass  http://portal-driver;
       	    proxy_redirect  default;        
	  }

        location / {
            root   html;
            index  index.html index.htm;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

    }

}

여러 번 방문 하 다
Server Info 의 ip 와 포트 는 ip1, ip2 폴 링 에 있 습 니 다.하지만 아래 세 션 id 는 모두 같 습 니 다.됐다.
(채소 새 는 뿌리 지 마라.)

좋은 웹페이지 즐겨찾기