本文原創作品,如需轉載請註明來源,作者:姜濤, [email protected]
構建一個有實用價值的 TimesTen 高可用系統
下圖是我們要實現的系統架構:
從上圖可以看到,系統中有一個 Oracle DB 位於 TEST_ORCL 機器上,兩個 TimesTen 的實例,分別位於 TEST_TT1 和 TEST_TT2 兩臺機器上。其中,表 T1 的更新操作在 oracle db 中,然後同步到 TimesTen 中,由 oracle db 來保證數據的安全性;而表 T2 的更新操作在 TimesTen 中,然後同步到 oracle db 裏面,由兩個 TimesTen 之間的複製來保證數據的安全性。
表 T1 和表 T2 的這種存儲方式在實際生產環境中,是一種很典型的情況。
下面將分步驟詳細描述如何安裝配置這個系統:
一、 在 test_orcl 上安裝 oracle ,建立實例 bossdb ,用戶 tzos/tzos ;在 test_tt1 和 test_tt2 上安裝 oracle 客戶端和 TimesTen 內存數據庫和 Cache Connect ,新建 TimesTen 的用戶 tzos/tzos 。
二、 在 test_tt1 和 test_tt2 上面建立 TimesTen 實例,配置文件如下:
[imdb] Driver=/home/tt/TimesTen/tt70/lib/libtten.so DataStore=/home/tt/TimesTen/imdb DatabaseCharacterSet=ZHS16GBK Authenticate=0 PermSize=64 TempSize=16 UID=tzos OracleId=bossdb OraclePwd=tzos |
三、 在 oracle 的 bossdb 裏面,建立兩個表:
create table t1(id number(2) primary key); create table t2(id number(2) primary key); |
四、 分別在 test_tt1 和 test_tt2 上爲表 T1 建立一個名爲 cache_1 的只讀 Cache Group
Command>call ttCacheUidPwdSet('tzos','tzos'); Command>call ttCacheStart; Command>CREATE READONLY CACHE GROUP cache_1 AUTOREFRESH State ON MODE INCREMENTAL INTERVAL 5 SECONDS FROM t1(id number(2) primary key,PROPAGATE);
|
五、 測試 cache_1 ,在 oracl 的 bossdb 中往 t1 中 insert 記錄,在兩個內存數據庫中查看 t1 中的數據,將跟隨發生變化
六、 分別在 test_tt1 和 test_tt2 上爲表 T2 建議一個名爲 cache_2 的 write through 的 Cache Group
Command> create asynchronous writethrough cache group cache_2 from tzos.t2(id number(2) primary key); |
七、 在 test_tt1 和 test_tt2 上分別建立 replication schema
Command>CREATE REPLICATION reptest ELEMENT e_1 TABLE t2 MASTER imdb on "test_tt1" SUBSCRIBER imdb on "test_tt2" ELEMENT e_2 TABLE t2 MASTER imdb on "test_tt2" SUBSCRIBER imdb on "test_tt1" ; Command> call ttrepstart; |
在兩個數據庫上都運行,說明兩個數據庫互爲 Master 和 Subscriber
八、 測試如下:
1、 在 test_tt1 中往 t2 中 insert 數據, test_tt2 和 test_orcl 的表中都能複製過來數據; 2、 在 test_tt2 中往 t2 中 insert 數據, test_tt1 和 test_orcl 的表中都能複製過來數據; 3、 停掉 test_tt2 的 timesten ,往 test_tt1 中的 t2 添加數據, test_orcl 中能複製到數據;再把 test_tt2 的 timesten 起來,剛纔的數據也能複製過來。反之亦然。 |