---
title: "配置terracotta高可用集群"
author: "hypercube1024"
date: "2010-09-19T10:57:50Z"
tags: []
categories: ["编程语言"]
slug: "terracotta"
draft: false
lastmod: "2010-09-19T10:57:50Z"
id: 767042
url: "https://hypercube1024.iteye.com/blog/767042"
---

由于terracotta肩负着保存session的重任，如果一旦down掉，所有的用户session将会丢失，所以terracotta要做ha。
terracotta集群配置也非常简单
1, 创建一个tc-config.xml文件，如下

```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="10.192.33.93" 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="10.192.33.94" name="Server2">
      <data>%(user.home)/terracotta/server-data</data>
      <logs>%(user.home)/terracotta/server-logs</logs>
    </server>
	
	<server host="192.168.1.100" name="Server3">
      <data>%(user.home)/terracotta/server-data</data>
      <logs>%(user.home)/terracotta/server-logs</logs>
    </server>
	
	<server host="192.168.1.101" name="Server4">
      <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>

```


2,加载配置文件，运行命令tim-get.sh upgrade <tc-config.xml-path>/tc-config.xml 
3,启动TCserver需要增加 -n 参数
./start-tc-server.sh -n Server2 &