2017年7月11日 星期二

Oracle ADG+OGG 配置


在一般環境中很常看到 RAC+ Active Data Guard 或者 RAC +  Golden Gate 的配置

以下介紹 ADG + OGG 配置, 不從主庫這次從備庫同步到OGG的DB

*.RAC + ADG + OGG 跟這次所說的配置其實大同小異 , 這一篇看完  RAC + ADG + OGG 應該也就會建立了


環境說明

10.10.17.27 主庫
10.10.17.28 備庫(Active Data Guard)
10.10.17.30 備庫(Golden Gate)


安裝 Active Data Guard 就不再說明,這邊就直接配置 Active Data Guard  (10.10.17.28)+ Golden gate (10.10.17.30) 同步操作



10.10.17.27 28 tnsnames.ora 內容


[oracle@ora28 admin]$ cat tnsnames.ora 
# tnsnames.ora Network Configuration File: /ORA/11.2.4/db/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.


ora27 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 10.10.17.27)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SID = orcl)
    )
  )

ora28 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 10.10.17.28)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SID = orcl)
    )
  )




1.(10.10.17.28) ADG 配置 mgr

設定 mgr
GGSCI (ora28) 1> edit param mgr

PORT 7809
dynamicportlist 7501-7505

autorestart extract *,waitminutes 2,retries 5

啟動 mgr
GGSCI (ora28) 3> start mgr

Manager started.


2.(10.10.17.28) ADG 配置 Extract

GGSCI (ora28) 4> dblogin userid ogg,password ogg
Successfully logged into database.

GGSCI (ora28 as ogg@LG) 5> 

GGSCI (ora28 as ogg@LG) 5> add extract ext1, tranlog,begin now
EXTRACT added.


GGSCI (ora28 as ogg@LG) 6> edit params ext1


#因為 28 是備庫 read only , 所以這邊這邊登入27 主庫,且只讀取 archivedlog
所以說必須等到主庫switch logfile , extract 才會擷取資料丟過去 30

extract ext1
userid ogg@ora27,password ogg
tranlogoptions archivedlogonly
tranlogoptions altarchivelogdest /ORA/ARCH
exttrail /ORA/ogg/dirdat/ex
discardfile /ORA/ogg/dirrpt/exta.dsc,append, megabytes 500

table VJ.*;


GGSCI (ora28 as ogg@LG) 7>  ADD EXTTRAIL /ORA/ogg/dirdat/ex, EXTRACT ext1                                                                      
EXTTRAIL added.


GGSCI (ora28 as ogg@LG) 8> 



3.(10.10.17.28) ADG 配置 第二個 extract (data dump)

GGSCI (ora28 as ogg@LG) 8> edit params pump1        


EXTRACT dump1
RMTHOST 10.10.17.30, MGRPORT 7809 TCPBUFSIZE 5000000
PASSTHRU
RMTTRAIL /ORA/ogg/dirdat/pt
NUMFILES 3000
TABLE VJ.*;

*rmthost :為目的端的IP及Port
*rmttrail :為目的端的接收資料檔的位置

#.這邊配置 要從哪裡取資料
GGSCI (ora28 as ogg@LG) 9> add extract  dump1, exttrailsource  /ORA/ogg/dirdat/ex
EXTRACT added.

GGSCI (ora28 as ogg@LG) 10> 

#.這邊配置要把檔案傳去Target 哪一個位置
GGSCI (ora28 as ogg@LG) 10> add rmttrail /ORA/ogg/dirdat/pt, extract dump1, megabytes 10

RMTTRAIL added.



啟動 dump 跟 ext

GGSCI (ora28 as ogg@LG) 17> start dump1

Sending START request to MANAGER ...

EXTRACT DUMP1 starting


GGSCI (ora28 as ogg@LG) 24> start ext1

Sending START request to MANAGER ...
EXTRACT EXT1 starting


GGSCI (ora28 as ogg@LG) 25> info all

Program     Status      Group       Lag at Chkpt  Time Since Chkpt

MANAGER     RUNNING                                           
EXTRACT     RUNNING     DUMP1       00:00:00      00:00:08    
EXTRACT     RUNNING     EXT1        01:52:30      00:00:01    



GGSCI (ora28 as ogg@LG) 26> 



4.(10.10.17.30) OGG 配置 checkpoing table 

GGSCI (datagu) 1> dblogin userid ogg,password ogg
Successfully logged into database.

GGSCI (datagu as ogg_tar@orclogg) 2> add checkpointtable ogg.ogg_chk

 Successfully created checkpoint table ogg.ogg_chk

將 checkpoint table 設定在 golden gate 裡頭

edit params ./GLOBALS

GGSCHEMA OGG
CHECKPOINTTABLE OGG.OGG_CHK



5.(10.10.17.30) OGG 配置 Peplicat

新增Peplicat
GGSCI (ora30 as ogg@LG) 2> add replicat rep01,exttrail /ORA/ogg/dirdat/pt,checkpointtable OGG.OGG_CHK
REPLICAT added.

*.這邊設定要從哪裡讀取從target丟過來的檔案

設定參數

GGSCI (ora30 as ogg@LG) 3> edit params rep01


replicat rep01
setenv (ORACLE_SID=orcl)
userid ogg,password ogg
assumetargetdefs
reperror default,discard
discardfile /ORA/ogg/dirdat/repl.dsc,append,megabytes 50
dynamicresolution
DDL INCLUDE ALL
DDLERROR DEFAULT IGNORE RETRYOP MAXRETRIES 3 RETRYDELAY 5
map VJ.*, target VJ.*;


6.啟動 (10.10.17.30) Peplicat                              

GGSCI (ora30 as ogg@LG) 4> start rep01

Sending START request to MANAGER ...
REPLICAT REP01 starting


GGSCI (ora30 as ogg@LG) 5> info all

Program     Status      Group       Lag at Chkpt  Time Since Chkpt

MANAGER     RUNNING                                           
REPLICAT    RUNNING     REP01       00:00:00      00:00:01    


GGSCI (ora30 as ogg@LG) 6> 


看一下有無錯誤

GGSCI (ora30 as ogg@LG) 7> view report rep01

.
.
.
.
.


Database Language and Character Set:
NLS_LANGUAGE     = "AMERICAN" 
NLS_TERRITORY    = "AMERICA" 
NLS_CHARACTERSET = "AL32UTF8" 

***********************************************************************
**                     Run Time Messages                             **
***********************************************************************


2017-07-12 13:45:53  INFO    OGG-02243  Opened trail file /ORA/ogg/dirdat/pt000000000 at 2017-07-12 13:45:53.977593.


看來有正常讀取到



7.主庫27進行操作 並且執行 alter system switch logfile; 再去看看備庫30有無資料










-----------

在RAC 環境時 ext1 還需要設定

TRANLOGOPTIONS altarchivelogdest primary instance orcl1 /u02/Archive/ORCL/, altarchivelogdest instance orcl2 /u03/Archive/ORCL/

來配置 rac1 及 rac2 的位置





2017年7月7日 星期五

Redis Cluster 到底可以掛幾台node 服務才不會掛?


這次實驗是使用 Redis Cluster 最基本的架構 3Master + 3Slave


這邊可以看到每一個Slave 後面掛的是它最主要同步的Master 的 id 


要是Master 掛掉會由它對應的Slave 會去接手變成Master , 那從Slave 變成Master 它本身也會從只讀 變成 可讀寫的Master


1. 原先的三台Master 全掛

可以看到Master 掛掉後 都被相對應的Slave 接手, 寫入資料沒問題

這時再掛掉一台Master , Cluster 服務也會隨即被關閉


2. 掛掉一台Master, 在掛掉一台沒有Slave 的Master

這邊可以看到 f710feca8f66b5fa64a98be8bf57d3e1ef372264 從Slave變成Master 但這台並沒有Slave 去對應


關掉 f710feca8f66b5fa64a98be8bf57d3e1ef372264 , 這時 Cluster 服務就會關閉


3. Slave 全關閉


Slave全關後, Cluster 服務還存在, 但這時候隨便掛掉一台 Master 服務就會停掉囉






2017年7月3日 星期一

Redis 新增 node (Master,Slave)



在原本Redis 三主三備 Cluster架構中 新增一組 Master Slave


1.啟動 新的 Redis

/redis/software/redis-3.2.9/src/redis-server /redis/software/8000/redis.conf
/redis/software/redis-3.2.9/src/redis-server /redis/software/8001/redis.conf

[root@localhost 8000]# ps -ef|grep redis
root      9360     1  0 12:17 ?        00:00:03 /redis/software/redis-3.2.9/src/redis-server *:8000 [cluster]
root      9366     1  0 12:17 ?        00:00:01 /redis/software/redis-3.2.9/src/redis-server *:8001 [cluster]


2.把新的Redis node 加進去 Redis Cluster 中 
#前面是新的node , 後面是原有的node

redis-trib.rb add-node 10.22.22.174:8000 10.22.22.174:7000
redis-trib.rb add-node 10.22.22.174:8001 10.22.22.174:7000



成功畫面, 要是出現 [ERR] Node 10.22.22.174:8001 is not empty. Either the node already knows other nodes (check with CLUSTER NODES) or contains some key in database 0. 錯誤

請先刪除原有的 node.log 檔案, 再次加入就可以

加入完成會出現 兩個沒有分配 Slot 的Master 的node

以下是 8000及8001 Port 



3.分配Redis Port 8000 3000個 Slot

redis-trib.rb reshard 10.22.22.174:8000

[root@localhost 8001]# redis-trib.rb reshard 10.22.22.174:8000
>>> Performing Cluster Check (using node 10.22.22.174:8000)
M: 086e40ce9139e625cea92da35619094e2c4a059f 10.22.22.174:8000
   slots: (0 slots) master
   0 additional replica(s)
S: 661f01b51c3aa508b9a990d123e24e6e1378ff61 10.22.22.174:7001
   slots: (0 slots) slave
   replicates f4eb29d1f76b0a29bec4c529377277b6e86a326e
M: 0d09b3e355be6b528c902af6a217a369fc4f4ef1 10.22.22.174:8001
   slots: (0 slots) master
   0 additional replica(s)
M: 493d6e53aa3e263812eb72bbd858784d4d9e88ba 10.22.22.167:7000
   slots:999-5460 (4462 slots) master
   1 additional replica(s)
S: 221ffb33e53faabc8805d79ed2cc39ca720d3698 10.22.22.186:7001
   slots: (0 slots) slave
   replicates 493d6e53aa3e263812eb72bbd858784d4d9e88ba
M: f4eb29d1f76b0a29bec4c529377277b6e86a326e 10.22.22.174:7000
   slots:0-998,5461-6461,10923-16383 (7461 slots) master
   1 additional replica(s)
S: 9b01d87f22fa6131adf8e3f136f4d63680e63892 10.22.22.167:7001
   slots: (0 slots) slave
   replicates af0061956f918d9d1cdb512465e26e3f8600b5c7
M: af0061956f918d9d1cdb512465e26e3f8600b5c7 10.22.22.186:7000
   slots:6462-10922 (4461 slots) master
   1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
### 這邊輸入 要分配的 Slot 的數, 這邊分配 3000個
How many slots do you want to move (from 1 to 16384)? 3000
### 這邊輸入哪一個要接收這3000個的node
What is the receiving node ID? 086e40ce9139e625cea92da35619094e2c4a059f
Please enter all the source node IDs.
  Type 'all' to use all the nodes as source nodes for the hash slots.
  Type 'done' once you entered all the source nodes IDs.
##這邊輸入 all 代表 其他節點要自己分配掏出3000個, 也可以從單個節點索取
Source node #1:all




輸入完 Yes , 它就會自動分配了


查看一下 目前Cluster 狀態, 可以看到Port  8000 已經被分配了 Slot




4.配置 Slave

為剛剛的Port 8000 配置一個 Slave

直接登入 8001 輸入cluster replicate  Master id
redis-cli -p 8001 cluster replicate 086e40ce9139e625cea92da35619094e2c4a059f



這邊就可以看到 8001已經是 8000的Slave 了

4個Master 4個Slave


---------------
刪除 Master node

1.先把該Master node 上的 Slot 移去別的Slot

redis-trib.rb reshard 10.22.22.174:8000

[root@localhost 8000]# redis-trib.rb reshard 10.22.22.174:8000
>>> Performing Cluster Check (using node 10.22.22.174:8000)
M: 086e40ce9139e625cea92da35619094e2c4a059f 10.22.22.174:8000
   slots:0-998,5461-6461,10923-11921 (2999 slots) master
   1 additional replica(s)
S: 661f01b51c3aa508b9a990d123e24e6e1378ff61 10.22.22.174:7001
   slots: (0 slots) slave
   replicates f4eb29d1f76b0a29bec4c529377277b6e86a326e
M: 493d6e53aa3e263812eb72bbd858784d4d9e88ba 10.22.22.167:7000
   slots:999-5460 (4462 slots) master
   1 additional replica(s)
S: 221ffb33e53faabc8805d79ed2cc39ca720d3698 10.22.22.186:7001
   slots: (0 slots) slave
   replicates 493d6e53aa3e263812eb72bbd858784d4d9e88ba
M: f4eb29d1f76b0a29bec4c529377277b6e86a326e 10.22.22.174:7000
   slots:11922-16383 (4462 slots) master
   1 additional replica(s)
S: 3c09e774bee37e3c4843b791f3a51bb79bd867a5 10.22.22.174:8001
   slots: (0 slots) slave
   replicates 086e40ce9139e625cea92da35619094e2c4a059f
S: 9b01d87f22fa6131adf8e3f136f4d63680e63892 10.22.22.167:7001
   slots: (0 slots) slave
   replicates af0061956f918d9d1cdb512465e26e3f8600b5c7
M: af0061956f918d9d1cdb512465e26e3f8600b5c7 10.22.22.186:7000
   slots:6462-10922 (4461 slots) master
   1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
### 這邊輸入該Master 擁有的Slot 數
How many slots do you want to move (from 1 to 16384)? 3000
### 這邊輸入誰要接收這3000個Slot
What is the receiving node ID? f4eb29d1f76b0a29bec4c529377277b6e86a326e
Please enter all the source node IDs.
  Type 'all' to use all the nodes as source nodes for the hash slots.
  Type 'done' once you entered all the source nodes IDs.
###這Slot來源是哪一個Master 這邊輸入要移除的Master id
Source node #1:086e40ce9139e625cea92da35619094e2c4a059f
Source node #2:done

2.移除節點

redis-trib.rb del-node 10.22.22.174:8000 '086e40ce9139e625cea92da35619094e2c4a059f'  

3.移除Salve

redis-trib.rb del-node 10.22.22.174:8001 '3c09e774bee37e3c4843b791f3a51bb79bd867a5'  

>>> Removing node 3c09e774bee37e3c4843b791f3a51bb79bd867a5 from cluster 10.22.22.174:8001
>>> Sending CLUSTER FORGET messages to the cluster...
>>> SHUTDOWN the node.