Nginx+Tomcat+Terracotta的Web服务器集群实做
1.准备工作
两个Linux服务器,可以用VMware装一个,然后配置好再克隆一个,修改IP即可。
Host1:192.168.0.79
Host2:192.168.0.80
先配置好jdk1.6.0和tomcat6。Host1上还将配置Nginx(负载均衡),Terracotta(session集群).
2.安装Terracotta
下载Terracotta的包,
http://d2zwv9pap9ylyd.cloudfront.net/terracotta-3.4.1-installer.jar 带安装功能的包
http://d2zwv9pap9ylyd.cloudfront.net/terracotta-3.4.1.tar.gz 不带安装的包
http://d2zwv9pap9ylyd.cloudfront.net/terracotta-3.4.1-src.tar.gz 源码包
这里使用terracotta-3.4.1.tar.gz
tar zxvf terracotta-3.4.1.tar.gz
mv terracotta-3.4.1 /usr/local/terracotta
3.配置Tomcat作为Terracotta的客户端
复制/usr/local/terracotta/sessions/terracotta-session-1.1.1.jar
/usr/local/terracotta/common/terracotta-toolkit-1.1-runtime-2.1.0.jar这两个jar到Tomcat对应目录。
Tomcat 5.0 and 5.5 对应目录 CATALINAHOME/server/libTomcat6.0对应目录CATALINAHOME/server/libTomcat6.0对应目录CATALINA_HOME/lib
编辑/usr/apache-tomcat-6.0.14/conf/context.xml文件
<Context>
<!-- 增加此配置 -->
<Valve className="org.terracotta.session.TerracottaTomcat60xSessionValve" tcConfigUrl="localhost:9510"/>
</Context>
如上是Tomcat6的配置方式,其他WebServer配置方式可见参考文档的具体说明。9510端口为Terracotta的通讯端口,另外默认9520为它的管理端口稍后用到。
4.启动单Terracotta,测试。
启动Terracotta
[Host1]# /usr/local/terracotta/bin/start-tc-server.sh &
启动Tomcat
[Host1]# service tomcatd start
[Host2]# service tomcatd start
(
注意:之前Host2处的Tomcat context.xml配置需要修改为
<Valve className="org.terracotta.session.TerracottaTomcat60xSessionValve" tcConfigUrl="192.168.0.79:9510"/>
即指向启动的Terracotta
)
启 动Windows下的Terracotta开发控制台(Terracotta Developer Console),此控制台使用9520端口来监控Terracotta,这个用terracotta-3.4.1-installer.jar带安装的 软件包可以在Windows下安装或tar解压运行也可。
[PROMPT] ${TERRACOTTA_HOME}\bin\dev-console.bat
(
注意:需要配置Linux主机名才能远程监控的到。
设置主机名(如果要永久修改RedHat的hostname,就修改/etc/sysconfig/network文件,将里面的HOSTNAME这一行修改成HOSTNAME=NEWNAME)
编辑/etc/hosts
::1 localhost.localdomain localhost
192.168.0.79 Host1 #添加此行
然后service network restart,
查验hostname:
[root@localhost ~]# hostname
host1
)
通过Terracotta Developer Console查看连接的Terracotta Server和Tomcat Client是否正常。
5.安装、配置Nginx
下载http://nginx.org/en/download.html
安装Nginx: (预先需要安装:rpm -ivh pcre-devel-6.6-2.el5_1.7.i386.rpm)
[Host1]#tar zxvf nginx-0.8.54.tar.gz
[Host1]#cd nginx-0.8.54
[Host1]#./configure --with-http_stub_status_module
[Host1]#make;make install
简单配置:修改/usr/local/nginx/conf/nginx.conf
...
http {
...
upstream mysvr {
server 192.168.0.79:8080;
server 192.168.0.80:8080;
}
server {
listen 80;
server_name 192.168.0.79;
location / {
proxy_pass http://mysvr;
....
}
…
}
}
...
测试配置文件
/usr/local/nginx/sbin/nginx -t
启动Nginx
/usr/local/nginx/sbin/nginx
6.观察集群session
jsp验证页test.jsp,部署到两个Tomcat的ROOT项目下:
<%@ page session="true" %>
<html>
<head>
<title>test Host1</title> <!-- //Host2就写为"test Host1" 以示区分 -->
</head>
<body>
<%
out.println("Session Id:"+request.getSession().getId()+"<br />");
out.println("Creation Time:"+request.getSession().getCreationTime());
String name=(String)session.getAttribute("name");
if(name==null||name.equals("")){
session.setAttribute("name","Hello Host1!"); //Host2就写为"Hello Host2!"
out.println(session.getAttribute("name"));
}else{
out.println(name);
}
%>
</body>
</html>
访问test.jsp
http://192.168.0.79/test.jsp
刷新多次。发现除session的id号被Terracotta加了个类似版本编号的后缀有所区别,
例如:Session Id:2jUFdCvDTqrZViJXzvh8.3和Session Id:2jUFdCvDTqrZViJXzvh8.2,以外其他的输出都是一致的。
已达到session集群的作用。
如 果关闭Terracotta,然后注释/usr/apache-tomcat-6.0.14/conf/context.xml文件的Valve,重启两 个tomcat,再次访问,并刷新,会发现sessionid及其内容在跳变,没有集群特性。这就是Terracotta的作用。
另外有两个单点故障的点,Nginx和Terracotta,Nginx可以通过keepalived配置为热备;
Terracotta内置了热备方式,可以在Host2上也启用Terracotta,需要tc-config.xml配置,具体可参见官方文档。
参考文档:
http://www.terracotta.org/documentation/product-documentation-1page.html 5 Clustering Web Applications with Terracotta Web Sessions 章节
------------------------------------------------------------------------------------------------------------------------------------------------------
配置Terracotta双机热备。
[Host1]#/bin/start-tc-server.sh -f /usr/local/terracotta/tc-config.xml -n Server1 &
[Host2]#/bin/start-tc-server.sh -f /usr/local/terracotta/tc-config.xml -n Server2 &
tc-config.xml 样例:
<?xml version="1.0" encoding="UTF-8"?>
<!-- All content copyright Terracotta, Inc., unless otherwise indicated.
All rights reserved. -->
<tc:tc-config
xsi:schemaLocation="http://www.terracotta.org/schema/terracotta-5.xsd"
xmlns:tc="http://www.terracotta.org/config"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<servers>
<!-- Sets where the Terracotta server can be found. Replace the value
of host with the server's IP address. -->
<server host="192.168.0.79" name="Server1">
<data>%(user.home)/terracotta/server-data</data>
<logs>%(user.home)/terracotta/server-logs</logs>
</server>
<!-- If using a standby Terracotta server, also referred to as an
ACTIVE-PASSIVE configuration, add the second server here. -->
<server host="192.168.0.80" name="Server2">
<data>%(user.home)/terracotta/server-data</data>
<logs>%(user.home)/terracotta/server-logs</logs>
</server>
<!-- If using more than one server, add an <ha> section. -->
<ha>
<mode>networked-active-passive</mode>
<networked-active-passive>
<election-time>5</election-time>
</networked-active-passive>
</ha>
</servers>
<!-- Sets where the generated client logs are saved on clients. -->
<clients>
<logs>%(user.home)/terracotta/client-logs</logs>
</clients>
</tc:tc-config>
Nginx+Tomcat+Terracotta的Web服务器集群实做的更多相关文章
- Web服务器集群搭建关键步骤纪要
前言:本文记述了搭建一个小型web服务器集群的过程,由于篇幅所限,系统.软件的安装和基本配置我这里就省略了,只记叙关键配置和脚本内容.假如各位朋友想了解各软件详细配置建议查阅官方文档. 一 需求分析: ...
- Nginx+Tomcat搭建高性能负载均衡集群
一. 工具 nginx-1.8.0 apache-tomcat-6.0.33 二. 目标 实现高性能负载均衡的Tomcat集群: 三. 步骤 1.首先下载Nginx ...
- Nginx+Tomcat搭建高性能负载均衡集群(转)
转载自:http://blog.csdn.net/wang379275614/article/details/47778201 一. 工具 nginx-1.8.0 apache-tomca ...
- Nginx+Tomcat搭建高性能负载均衡集群的实现方法
一. 目标实现高性能负载均衡的Tomcat集群: 二.步骤 1.首先下载Nginx,要下载稳定版: 2.然后解压两个Tomcat,分别命名为apache-tomcat-6.0.33-1和apac ...
- 【转】Nginx+Tomcat搭建高性能负载均衡集群
最近对负载均衡比较感兴趣,研究了公司的负载均衡的配置,用的是阿里的SLB,相当于不用运维,只需要在后台进行简单的配置就能完成Tomcat的负载均衡,索性在网上找了几篇文章去尝试搭建一个集群,然而很多都 ...
- 采用软件nginx实现web服务器集群
nginx:软件负载均衡器 是高并发量http/反向代理服务器.实现windows下IIS的负载均衡 条件:2台服务器 1.cpu:Inter(R) 酷睿 i5 cpu 2.26GHz 内存:2G ...
- LVS+Keepalived+Nginx+Tomcat高可用负载均衡集群配置(DR模式,一个VIP,多个端口)
一.概述 LVS作用:实现负载均衡 Keepalived作用:监控集群系统中各个服务节点的状态,HA cluster. 配置LVS有两种方式: 1. 通过ipvsadm命令行方式配置 2. 通过Red ...
- web服务器集群
概述 集群和分布式都是从集中式进化而来的.分布式和集群会相互合作的,同时的集群和分布式.在这里重点说说集群 集群是什么? 集群能提高单位时间内处理的任务数量,提升服务器性能 有多台服务器去处理任务,但 ...
- 使用简单的 5 个步骤设置 Web 服务器集群
通过在多个处理器之间分担工作负载并采用多种软件恢复技术,能够提供高度可用的环境并提高环境的总体 RAS(可靠性.可用性和可服务性).可以得到的好处包括:更快地从意外中断中恢复运行,以及将意外中断对终端 ...
随机推荐
- 《C和指针》读书笔记——第五章 操作符和表达式
1.当/操作符的两个操作数都是整数时,它执行整除运算:其他都是执行浮点数除法. 2.逻辑移位:左边移入的位用0填充: 算数移位:左边移入的位用符号位填充: 3.位置1 :value |= 1<& ...
- uva401 - Palindromes结题报告
题目地址 : http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...
- http://phantomjs.org/page-automation.html
http://phantomjs.org/page-automation.html install brew curl -LsSf http://github.com/mxcl/homebrew/ta ...
- pdf增加水印
/// <summary> /// 为PDF添加水印或背景图片 /// </summary> /// <param name="strSourceFilePat ...
- Unity3d 协程、调用函数、委托
(一)协程 开启方法:StartCoroutine("函数名"): 结束方法StopCoroutine("函数名"),StopAllCoroutines(); ...
- How to open MS word document from the SharePoint 2010 using Microsoft.Office.Interop.dll
or this you must change the identity of word component inC:\windows\System32\comexp.mscto be interac ...
- 各个浏览器下实现Ajax的JS
var xmlhttpget; try { // Firefox, Opera 8.0+, Safari xmlhttpget = new window.XMLHttpRequest( ...
- 简单3d RPG游戏 之 005 选择敌人
选择一个敌人,按ctrl+d,复制出3个,调整一下它们的位置,不重叠,修改Tag为Enemy,禁用EnemyAI. 创建Targetting脚本,绑定到Player玩家对象 public class ...
- 【数学/扩展欧几里得/Lucas定理】BZOJ 1951 :[Sdoi 2010]古代猪文
Description “在那山的那边海的那边有一群小肥猪.他们活泼又聪明,他们调皮又灵敏.他们自由自在生活在那绿色的大草坪,他们善良勇敢相互都关心……” ——选自猪王国民歌 很久很久以前,在山的那边 ...
- 团体程序设计天梯赛-练习集L1-018. 大笨钟
L1-018. 大笨钟 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 微博上有个自称“大笨钟V”的家伙,每天敲钟催促码农们爱惜 ...