dgbroker搭建完整記錄

flzhang發表於2018-01-17

https://github.com/yoshinorim/mha4mysql-manager.git
一個表或索引或其它物件使用BUFFER CACHE,最終使用哪個CBC LATCH,由其檔案號以及資料塊號,進行HASH後使用指定的CBC LATCH

使用Shell指令碼實現自動化靜默安裝Oracle軟體

下載oracle 11g
下載地址:wget  http://v.yingsun.net/cobra/download/linux.x64_11gR2_database_1of2.zip
下載地址:wget  http://v.yingsun.net/cobra/download/linux.x64_11gR2_database_2of2.zip

一 安裝java
檢視CentOS自帶JDK是否已安裝。yum list installed |grep java

檢視yum庫中的Java安裝包 命令:yum -y list java 看看可安裝的軟體包有沒有java-1.8.0-openjdk

二 檢查和安裝需要的rpm
yum -y install binutils compat-libstdc++ compat-libstdc++-33 elfutils-libelf-devel gcc gcc-c++ glibc-devel glibc-headers ksh libaio-devel libstdc++-devel make sysstat unixODBC-devel binutils-* compat-libstdc++* elfutils-libelf* glibc* gcc-* libaio* libgcc* libstdc++* make* sysstat* unixODBC* wget unzip
unixODBC-devel
還有必須下載的包
 wget ftp://ftp.pbone.net/mirror/www.whiteboxlinux.org/whitebox/4/en/updates/i686/glibc-2.3.4-2.43.i686.rpm

 
yum -y install binutils compat-libcap1 compat-libstdc++-33 compat-libstdc++-33*i686 compat-libstdc++-33*.devel compat-libstdc++-33 compat-libstdc++-33*.devel gcc gcc-c++ glibc glibc*.i686 glibc-devel glibc-devel*.i686 ksh libaio libaio*.i686 libaio-devel libaio-devel*.devel libgcc libgcc*.i686 libstdc++ libstdc++*.i686 libstdc++-devel libstdc++-devel*.devel libXi libXi*.i686 libXtst libXtst*.i686 make sysstat unixODBC unixODBC*.i686 unixODBC-devel unixODBC-devel*.i686
安裝依賴包

rpm -q binutils compat-libcap1 compat-libstdc++-33 gcc gcc-c++ glibc glibc-devel ksh libaio libaio-devel libgcc libstdc++ libstdc++-devel libXi libXtst  make sysstat  unixODBC unixODBC-devel
檢查有沒有31個

還能用如下方式檢查,包括centos6,centos7的包
rpm -q --qf '%{NAME}-%{VERSION}-%{RELEASE} (%{ARCH})\n' binutils \
compat-libcap1 \
compat-libstdc++-33 \
elfutils-libelf \
elfutils-libelf-devel \
gcc \
gcc-c++ \
glibc \
glibc-common \
glibc-devel \
glibc-headers \
ksh \
libaio \
libaio-devel \
libgcc \
libstdc++ \
libstdc++-devel \
libXi \
libXtst \
make \
sysstat \
unixODBC \
unixODBC-devel

 
各個版本的檢查包和版本課看官方文件
https://docs.oracle.com/cd/E11882_01/install.112/e24326/toc.htm#BHCFACHG
 
三 建立使用者組和使用者
userdel -r oracle
groupadd -g 700 oinstall
groupadd -g 701 dba
useradd -g oinstall -G dba -u 700 oracle
passwd oracle

id oracle

四 設定ORACLE環境變數
su - oracle
vi ~/.bash_profile
export ORACLE_BASE=/u02/oracle
export ORACLE_HOME=/u02/oracle/product/11.2.0/dbhome_1
export ORACLE_SID=orcl
export NLS_LANG="american_america.AL32UTF8"
export NLS_DATE_FORMAT="YYYY-MM-DD HH24:Mi:SS"
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
export PATH=$ORACLE_HOME/bin:$PATH


//指令碼方式
new_export = "export ORACLE_BASE=/u02/oracle"
echo "export ORACLE_BASE=/u02/oracle" >> ~/.bash_profile
echo "export ORACLE_HOME=/u02/oracle/product/11.2.0/dbhome_1" >> ~/.bash_profile
echo "export ORACLE_SID=orcl" >> ~/.bash_profile

bash shell:指令碼中修改profile檔案更新LD_LIBRARY_PATH的示例 http://blog.csdn.net/10km/article/details/51953721

source ~/.bash_profile

檢視環境變數是否完成
env | grep ORA


五 建立安裝目錄
su - root
mkdir -p /u02/oracle
mkdir -p /u02/oracle/product/11.2.0/dbhome_1
chown -R oracle:oinstall /u02/oracle
chmod -R 775 /u02/oracle

vi /etc/oraInst.loc
inventory_loc==/home/oracle/oraInventory
inst_group=oinstall

source /etc/oraInst.loc
 
chown oracle:oinstall /etc/oraInst.loc
chmod 664 /etc/oraInst.loc

五 解壓
unzip p10404530_112030_Linux-x86-64_1of7.zip; unzip p10404530_112030_Linux-x86-64_2of7.zip

六 複製響應檔案模板
用oracle使用者複製
su - oracle
mkdir /home/oracle/etc
mkdir /home/oracle/oraInventory
cp /u02/oracle/database/response/*  /home/oracle/etc/
七 設定響應檔案
su - root
chmod 700 /home/oracle/etc/*.rsp(注意所有者,oinstall)
八 靜默安裝Oracle軟體 
su - oracle
修改安裝Oracle軟體的響應檔案/home/oracle/etc/db_install.rsp

#刪除應答檔案中的註釋行(以#開頭)
$ sed -i 's/^#.*$//g' *.rsp
刪除沒有內容的空行(^$)
$ sed -i '/^$/d' *.rsp

oracle.install.responseFileVersion=/oracle/install/rspfmt_dbinstall_response_schema_v11_2_0
oracle.install.option=INSTALL_DB_SWONLY         // 29 安裝型別

ORACLE_HOSTNAME=oracle                            // 37 主機名稱(hostname查詢)

UNIX_GROUP_NAME=oinstall                          // 42 安裝組

INVENTORY_LOCATION=/home/oracle/oraInventory            //47 INVENTORY目錄(不填就是預設值)  注意:這裡inventory目錄最好不要填寫與oracle安裝路徑一致的目錄,會報錯

SELECTED_LANGUAGES=en,zh_CN,zh_TW                       // 78 選擇語言

ORACLE_HOME=/u02/oracle/product/11.2.0/dbhome_1         // 83 oracle_home

ORACLE_BASE=/u02/oracle                                 // 88 oracle_base

oracle.install.db.InstallEdition=EE                     // 99 oracle版本

oracle.install.db.isCustomInstall=false                     //自定義安裝,否,使用預設元件

oracle.install.db.DBA_GROUP=dba                          // 143 dba使用者組

oracle.install.db.OPER_GROUP=oinstall                   // 147 oper使用者組

oracle.install.db.config.starterdb.type=GENERAL_PURPOSE         // 160 資料庫型別

oracle.install.db.config.starterdb.globalDBName=orcl              // 165 globalDBName

oracle.install.db.config.starterdb.SID=orcl                          // 170 SID

oracle.install.db.config.starterdb.memoryLimit=81920        // 200 自動管理記憶體的記憶體(M)

oracle.install.db.config.starterdb.password.ALL=oracle        // 233 設定所有資料庫使用者使用同一個密碼
SECURITY_UPDATES_VIA_MYORACLESUPPORT=false            // 376(手動寫了false)

DECLINE_SECURITY_UPDATES=true                                // 385 設定安全更新(貌似是有bug,這個一定要選true,否則會無限提醒郵件地址有問題,終止安裝。PS:不管地址對不對)


執行命令 開始預設安裝
cd /u02/oracle/database

./runInstaller  -ignorePrereq -showProgress -silent -responseFile  /home/oracle/etc/db_install.rsp
./runInstaller  -ignorePrereq -showProgress -silent -force -responseFile  /home/oracle/etc/db_install.rsp
./runInstaller  -silent -force -responseFile /home/oracle/etc/db_install.rsp
這時可以看安裝日誌
INFO: Number of threads for fast copy :1


這裡在centos7上安裝oracle11g時,不論11.1.0.1還是 11.2.0.4 都會報錯
String: Error in invoking target 'agent nmhs' of makefile '/u02/oracle/product/11.2.0/dbhome_1/sysman/lib/ins_emagent.mk'.
這個錯誤相當於圖形介面安裝時遇到的錯誤,但圖形介面安裝遇到錯誤,會停止,且提供重試的按鈕,靜默安裝就不成,具體解決方法可以參考
http://www.jb51.net/article/129719.htm

安嚮導執行倆檔案
/home/oracle/oraInventory/orainstRoot.sh
/u02/oracle/product/11.2.0/dbhome_1/root.sh

九 靜默配置網路
編輯netca.rsp檔案

$ more /u02/oracle/database/response/netca.rsp
[GENERAL]
RESPONSEFILE_VERSION="11.2"
CREATE_TYPE="CUSTOM"
[oracle.net.ca]
INSTALLED_COMPONENTS={"server","net8","javavm"}
INSTALL_TYPE=""typical""
LISTENER_NUMBER=1
LISTENER_NAMES={"LISTENER"}
LISTENER_PROTOCOLS={"TCP;1521"}
LISTENER_START=""LISTENER""
NAMING_METHODS={"TNSNAMES","ONAMES","HOSTNAME"}
NSN_NUMBER=1
NSN_NAMES={"EXTPROC_CONNECTION_DATA"}
NSN_SERVICE={"PLSExtProc"}
NSN_PROTOCOLS={"TCP;HOSTNAME;1521"}

在oracle使用者下
$ORACLE_HOME/bin/netca /silent /responsefile /home/oracle/database/response/netca.rsp

十 靜默安裝資料庫
在oracle 使用者安裝。需要配置靜默安裝資料庫響應的模板檔案,也是在安裝軟體包中解壓在database下的response 目錄下的 dbca_rsp 檔案,具體配置如下
vim dbca.rsp

//$ more /u02/soft/database/response/dbca.rsp

cp /u02/oracle/database/response/dbca.rsp /u02/oracle/database/response/dbca.rsp.bak

vi /u02/oracle/database/response/dbca.rsp

[GENERAL]

RESPONSEFILE_VERSION = "11.2.0"

OPERATION_TYPE = "createDatabase"

[CREATEDATABASE]

GDBNAME = "lanmao"           #全域性資料庫的名字 DB_NAME_DB_DOMAIN

SID = "orcl"                 # 資料庫例項,根據上面的你寫的SID 一樣的,隨便寫。

TEMPLATENAME = "General_Purpose.dbc"   #  這個可以是預設的模板,不會寫預設的,最好是預設,

                                 這裡是我們dba 寫的,所以就用上了。

SYSPASSWORD = "2011@oracle"

SYSTEMPASSWORD = "2011@oracle"

SYSMANPASSWORD = "2011@oracle"

DBSNMPPASSWORD = "2011@oracle"   # 前面這四個都可以不管,預設就行

CHARACTERSET = "ZHS16GBK"         #編碼

NATIONALCHARACTERSET=“UTF8”   #編碼

[createTemplateFromDB]

SOURCEDB = "iZ2zehy7gff0kpg1swp1czZ:1521:orcl"

SYSDBAUSERNAME = "system"

TEMPLATENAME = "My Copy TEMPLATE"

[createCloneTemplate]

SOURCEDB = "orcl"

TEMPLATENAME = "My Clone TEMPLATE"

[DELETEDATABASE]

SOURCEDB = "orcl"

[generateScripts]

TEMPLATENAME = "New Database"

GDBNAME = "orcl11.us.oracle.com"

[CONFIGUREDATABASE]

[ADDINSTANCE]

DB_UNIQUE_NAME = "orcl11g.us.oracle.com"

NODELIST=

SYSDBAUSERNAME = "sys"

[DELETEINSTANCE]

DB_UNIQUE_NAME = "orcl11g.us.oracle.com"

INSTANCENAME = "orcl11g"

SYSDBAUSERNAME = "sys"

$ORACLE_HOME/bin/dbca -silent -responseFile /db/soft/database/response/dbca.rsp
$ORACLE_HOME/bin/dbca -silent -responseFile /home/oracle/etc/dbca.rsp
/u02/oracle/database/response/dbca.rsp


十一 刪除方法
資料庫安裝成功後,要刪除執行的命令
先聽資料庫
/home/oracle/database/dbca -silent -deleteDatabase -sourcedb orcl11g -sid orcl11g -sysDBAUserName system -sysDBAPassword oracle

沒安裝成功時刪除資料庫和軟體方法
刪除/u02/oracle/oradata目錄下對應資料庫資料夾
刪除/u02/oracle/flash_recovery_area 目錄下對應資料庫資料夾
最重要/etc/oratab 刪除裡面最後的對應資料庫的記錄
--刪除 vi /home/oracle/oraInventory/ContentsXML/inventory.xml


root使用者
swapoff -a && swapon -a
rm -fr /u02/oracle/oradata
rm -fr /u02/oracle/flash_recovery_area
rm -fr /home/oracle/oraInventory
rm -fr /u02/oracle/product/11.2.0/dbhome_1


vi /etc/oratab
--vi /home/oracle/oraInventory/ContentsXML/inventory.xml
--sed -i '/^<HOME NAME="OraDb11g_home1"/d' /home/oracle/oraInventory/ContentsXML/inventory.xml

mkdir -p /u02/oracle/product/11.2.0/dbhome_1
chown -R oracle:oinstall /u02/oracle
chmod -R 775 /u02/oracle

mkdir -p /u02/oracle/oradata
mkdir -p /u02/oracle/flash_recovery_area
chown -R oracle:oinstall /u02/oracle/oradata
chmod -R 775 /u02/oracle/oradata
su - oracle
mkdir /home/oracle/oraInventory


/u02/oracle/oradiag_oracle/diag/clients/user_oracle/host_2133379358_76/alert

跟蹤錯誤sqlplus 方法
strace sqlplus / as sysdba
strace -f -o /tmp/sqlplus.log sqlplus / as sysdba
檢視為什麼出現 ORA-12547: TNS:lost contact

select open_mode from v$database;


遇到的問題
問題1
在靜默安裝oracle的時候,在安裝軟體以後,進入sqlplus後,總是報TNS connect lost,這時就在網上檢視了這個錯誤對應問題,其中說是
bin目錄裡oracle執行檔案大小為0,後來就反覆裝,發現裝的時候果然系統裝到link oracle的時候就不動了,最後看日誌的時候看這裡最終
報錯。然後就在日誌裡檢視了對應的錯誤。和日誌裡遇到的第一個錯誤。
其實判斷這個題很容易,重要的是看日誌
日誌在安裝時,已經輸出了具體位置和檔名,開啟後就能看到。裡面發現的第一個報錯資訊
INFO: collect2: error: ld returned 1 exit status
make[1]: *** [/u02/oracle/product/11.2.0/dbhome_1/sysman/lib/emdctl] Error 1
make: *** [emdctl] Error 2

INFO: End output from spawned process.
INFO: ----------------------------------
INFO: Exception thrown from action: make
Exception Name: MakefileException
Exception String: Error in invoking target 'agent nmhs' of makefile '/u02/oracle/product/11.2.0/dbhome_1/sysman/lib/ins_emagent.mk'. See '/home/oracle/oraInventory/logs/installActions2017-12-12_04-48-00PM.log' for details.
Exception Severity: 1
然後根據網上的提示就是在ins_emagent里加 -lnnet11
然後為讓這些位元組是0的檔案生效,就執行了bin目錄裡的relink all
最後oracle檔案就生成了,且在進入sqlplus就不報tns的錯誤了,最後說的是連線一個正常例項的問題。


列印日誌的時候,在這個位置會等很長時間
INFO:  - Linking Oracle
rm -f /u02/oracle/product/11.2.0/dbhome_1/rdbms/lib/oracle

INFO: gcc  -o /u02/oracle/product/11.2.0/dbhome_1/rdbms/lib/oracle -m64 -z noexecstack -L/u02/oracle/product/11.2.0/dbhome_1/rdbms/lib/ -L/u02/oracle/product/11.2.0/dbhome_1/lib/ -L/u02/oracle/product/11.2.0/dbhome_1/lib/stubs/   -Wl,-E /u02/oracle/product/11.2.0/dbhome_1/rdbms/lib/opimai.o /u02/oracle/product/11.2.0/dbhome_1/rdbms/lib/ssoraed.o /u02/oracle/product/11.2.0/dbhome_1/rdbms/lib/ttcsoi.o  -Wl,--whole-archive -lperfsrv11 -Wl,--no-whole-archive /u02/oracle/product/11.2.0/dbhome_1/lib/nautab.o /u02/oracl
INFO: e/product/11.2.0/dbhome_1/lib/naeet.o /u02/oracle/product/11.2.0/dbhome_1/lib/naect.o /u02/oracle/product/11.2.0/dbhome_1/lib/naedhs.o /u02/oracle/product/11.2.0/dbhome_1/rdbms/lib/config.o  -lserver11 -lodm11 -lcell11 -lnnet11 -lskgxp11 -lsnls11 -lnls11  -lcore11 -lsnls11 -lnls11 -lcore11 -lsnls11 -lnls11 -lxml11 -lcore11 -lunls11 -lsnls11 -lnls11 -lcore11 -lnls11 -lclient11  -lvsn11 -lcommon11 -lgeneric11 -lknlopt `if /usr/bin/ar tv /u02/oracle/product/11.2.0/dbhome_1/rdbms/lib/libknlopt.a | grep xsyeolap

......
    `cat /u02/oracle/product/11.2.0/db
INFO: home_1/lib/sysliblist` -Wl,-rpath,/u02/oracle/product/11.2.0/dbhome_1/lib -lm    `cat /u02/oracle/product/11.2.0/dbhome_1/lib/sysliblist` -ldl -lm   -L/u02/oracle/product/11.2.0/dbhome_1/lib


orapwd FILE=orapwdORCL11g.pwd PASSWORD=welcome1 ENTRIES=30

問題2 建立資料庫時報錯
排錯方法 看建立資料庫時alert方法
[oracle@iZ2zehy7gff0kpg1swp1czZ ~]$ cd $ORACLE_BASE/diag/rdbms/orcl11g/orcl11g/trace
[oracle@iZ2zehy7gff0kpg1swp1czZ trace]$ ls -alcr | grep alert
-rw-r-----  1 oracle oinstall 64209 Dec 14 14:45 alert_orcl11g.log
[oracle@iZ2zehy7gff0kpg1swp1czZ trace]$ ls -alcr | grep alert
在其中找到了pfile檔案
/u02/oracle/cfgtoollogs/dbca/orcl11g/initorcl11gTemp.ora
startup nomount pfile=/u02/oracle/cfgtoollogs/dbca/orcl11g/initorcl11gTemp.ora;

/u02/oracle/diag/rdbms/orcl11g/orcl11g/trace/orcl11g_ora_16270.trc
要根據pfile生成spfile,資料庫就能啟動到open了
create spfile from pfile='/u02/oracle/cfgtoollogs/dbca/orcl11g/initorcl11gTemp.ora'
create spfile from pfile='$ORACLE_HOME/dbs/initorcl11g.ora'


問題3 手工建庫時的問題
根據文件手工建立資料庫,但輸入建立語句後,系統提示如下錯誤
ERROR at line 1:

ORA-01092: ORACLE instance terminated. Disconnection forced

ORA-01501: CREATE DATABASE failed

ORA-01519: error while processing file '?/rdbms/admin/dtxnspc.bsq' near line 5

ORA-00604: error occurred at recursive SQL level 1

ORA-30012: undo tablespace 'UNDOTBS1' does not exist or of wrong type

這個提示實際很明顯,但特別注意的是要保證引數檔案裡的回退表空間名字和create database語句
裡的表空間名字要一樣,而不是和create database裡的回退資料檔名一樣,這很重要,這可以保證
後面的執行指令碼時沒有莫名其妙的錯誤。

手工建庫的過程如下
1 刪除已有資料庫
rm -fr oradata/orcl11g/*.*
rm -fr fast_recovery_area/orcl11g/control02.ctl

2
orapwd FILE=orapwdSORCL.pwd PASSWORD=oracle ENTRIES=30
CREATE SPFILE='spfile.ora' FROM
       PFILE='init.ora';


 CREATE DATABASE orcl11g
     USER SYS IDENTIFIED BY oracle
     USER SYSTEM IDENTIFIED BY oracle
     LOGFILE GROUP 1 ('/u02/oracle/oradata/orcl11g/redo01.log') SIZE 100M BLOCKSIZE 512,
             GROUP 2 ('/u02/oracle/oradata/orcl11g/redo02.log') SIZE 100M BLOCKSIZE 512,
             GROUP 3 ('/u02/oracle/oradata/orcl11g/redo03.log') SIZE 100M BLOCKSIZE 512
     MAXLOGFILES 5
     MAXLOGMEMBERS 5
     MAXLOGHISTORY 1
    MAXDATAFILES 100
    CHARACTER SET ZHS16GBK
    NATIONAL CHARACTER SET AL16UTF16
    EXTENT MANAGEMENT LOCAL
    DATAFILE '/u02/oracle/oradata/orcl11g/system01.dbf' SIZE 325M REUSE
    SYSAUX DATAFILE '/u02/oracle/oradata/orcl11g/sysaux01.dbf' SIZE 325M REUSE
    DEFAULT TABLESPACE users
        DATAFILE '/u02/oracle/oradata/orcl11g/users01.dbf'
        SIZE 500M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED
    DEFAULT TEMPORARY TABLESPACE tempts1
        TEMPFILE '/u02/oracle/oradata/orcl11g/temp01.dbf'
        SIZE 20M REUSE
    UNDO TABLESPACE undotbs --undotbs 必須和引數檔案中指定名字一樣
        DATAFILE '/u02/oracle/oradata/orcl11g/UNDOTBS_01.dbf' --UNDOTBS_01沒事隨便取名
        SIZE 200M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED
  
rm -fr /tmp/logsql.txt
spool /tmp/logsql.txt --這樣可以執行sql指令碼後的日誌
@?/rdbms/admin/catalog.sql
@?/rdbms/admin/catproc.sql
spool off


克隆安裝資料庫軟體
在一臺機器上克隆安裝第二個oracle 軟體
1增加swap分割槽
dd if=/dev/zero of=/home/swap1 bs=612 count=612000
mkswap /home/swap1
swapon /home/swap1

2複製dbhome_1到新位置 cp -r /u02/oracle/product/11.2.0/dbhome_1 /u03_clone/oracle/product/11.2.0/dbhome_1
3chown -R oracle:oinstall /u03_clone/oracle
su - oracle
4 登記複製後的資訊命令
cd /u03_clone/oracle/product/11.2.0/dbhome_1/clone/bin
perl clone.pl ORACLE_BASE=/u03_clone/oracle ORACLE_HOME=/u03_clone/oracle/product/11.2.0/dbhome_1  ORACLE_HOME_NAME=OraDb11g_home_clone
5 驗證是否加入產品列表目錄,軟體是否安裝成功
vi /home/oracle/oraInventory/ContentsXML/inventory.xml

dgbroker
1:主庫配置listener.ora檔案和tnsnames.ora檔案,新增GLOBAL_DBNAME引數,重啟監聽器,所有的節點都需要配置
cat $ORACLE_HOME/network/admin/listener.ora 
SID_LIST_LISTENER = 
  (SID_LIST = 
    (SID_DESC = 
      (GLOBAL_DBNAME = PRIMARY) 
      (ORACLE_HOME = /u02/oracle/product/11.2.0/dbhome_1)
   (SID_NAME = orcl11g)  
    )
 (SID_DESC = 
      (GLOBAL_DBNAME = PRIMARY_DGMGRL) 
      (ORACLE_HOME = /u02/oracle/product/11.2.0/dbhome_1)
   (SID_NAME = orcl11g)  
    )
  ) 
 
LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = iZ2zehy7gff0kpg1swp1czZ)(PORT = 1521))
    )
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
    )
  )

ADR_BASE_LISTENER = /u02/oracle
 
 
cat $ORACLE_HOME/network/admin/tnsnames.ora 
PRIMARY = 
  (DESCRIPTION = 
    (ADDRESS_LIST = 
      (ADDRESS = (PROTOCOL = TCP)(HOST = iZ2zehy7gff0kpg1swp1czZ)(PORT = 1521)) 
    ) 
    (CONNECT_DATA = 
      (SERVICE_NAME = orcl11g.localdomain) 
    ) 
  ) 
 
PHYSICAL = 
  (DESCRIPTION = 
    (ADDRESS_LIST = 
      (ADDRESS = (PROTOCOL = TCP)(HOST = iZ2zehy7gff0kpg1swp1czZ)(PORT = 1522)) 
    ) 
    (CONNECT_DATA = 
      (SERVICE_NAME = orcl11g.localdomain) 
    ) 
  )

複製主庫listener和tnsname到備庫
cd /u02/oracle/product/11.2.0/dbhome_1/network/admin
cp listener.ora tnsnames.ora /u03_clone/oracle/product/11.2.0/dbhome_1/network/admin/
 
備庫上的listener和tnsname
SID_LIST_LISTENER = 
  (SID_LIST = 
    (SID_DESC = 
      (GLOBAL_DBNAME = PHYSICAL) 
      (ORACLE_HOME = /u03_clone/oracle/product/11.2.0/dbhome_1)
   (SID_NAME = sorcl11g)         
    )
 (SID_DESC = 
      (GLOBAL_DBNAME = PHYSICAL_DGMGRL) 
      (ORACLE_HOME = /u03_clone/oracle/product/11.2.0/dbhome_1)
   (SID_NAME = sorcl11g)   
    )
  ) 
 
LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = iZ2zehy7gff0kpg1swp1czZ)(PORT = 1521))
    )
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
    )
  )

ADR_BASE_LISTENER = /u02/oracle

備庫的tnsname

PHYSICAL = 
  (DESCRIPTION = 
    (ADDRESS_LIST = 
      (ADDRESS = (PROTOCOL = TCP)(HOST = iZ2zehy7gff0kpg1swp1czZ)(PORT = 1522)) 
    ) 
    (CONNECT_DATA = 
      (SERVICE_NAME = orcl11g.localdomain) 
    ) 
  )

PRIMARY = 
  (DESCRIPTION = 
    (ADDRESS_LIST = 
      (ADDRESS = (PROTOCOL = TCP)(HOST = iZ2zehy7gff0kpg1swp1czZ)(PORT = 1521)) 
    ) 
    (CONNECT_DATA = 
      (SERVICE_NAME = orcl11g.localdomain) 
    ) 
  ) 
注意 這裡埠號和主庫的埠不應一致,因為此時環境是一個節點上有兩個ORACLE產品兩個ORACLE資料庫

2:設定DG_BROKER_START引數,所有的節點都需要配置
2.1基本配置
alter system set db_unique_name='PRIMARY' scope=spfile;

alter system set standby_file_management ='AUTO';

alter database add standby logfile group  11 '/u02/oracle/oradata/orcl11g/standbylog/standby11.log' size 50m;
alter database add standby logfile group  12 '/u02/oracle/oradata/orcl11g/standbylog/standby12.log' size 50m;
alter database add standby logfile group  13 '/u02/oracle/oradata/orcl11g/standbylog/standby13.log' size 50m;
alter database add standby logfile group  14 '/u02/oracle/oradata/orcl11g/standbylog/standby14.log' size 50m;

2.2主庫歸檔
shutdown immediate;
startup mount;
alter system set log_archive_dest_1='location=/u02/oracle/oradata/orcl11g/archivelog';
alter database archivelog;


主庫啟動broker
show parameter dg_broker_start;
!ps -ef |grep dmon 
alter system set dg_broker_start=TRUE;
!ps -ef |grep dmon 

alter database open;
在主庫重新生成pfile create pfile from spfile;

2.3 備份主庫:

  a.rman target /

  b.backup database;

2.4 在備庫上克隆主庫:
     
  a.cd /u02/oracle/product/11.2.0/dbhome_1/dbs
      cp initorcl11g.ora orapworcl11g /u03_clone/oracle/product/11.2.0/dbhome_1/dbs/
     
      修改備庫pfile上的db_unique_name=PHYSICAL
   因為在同一臺機器的不同位置安裝了另一個oracle軟體,所以還要設定資料存放位置的引數
   su - oracle
   mkdir -p /u03_clone/oracle/oradata/orcl11g/archivelog
   mkdir -p /u03_clone/oracle/flash_recovery_area
   mkdir -p /u03_clone/oracle/admin/orcl11g/adump
     
      要在同一臺機器上啟動另一產品的資料庫,必須先啟動不同的listener,然後啟動倆資料庫
      同一機器上啟動不同產品的listener 必須要有TNS_ADMIN
      開啟視窗1 export TNS_ADMIN=/u02/oracle/product/11.2.0/dbhome_1/network/admin        主庫listener
      開啟視窗2 export TNS_ADMIN=/u03_clone/oracle/product/11.2.0/dbhome_1/network/admin   備庫listener 

  b.啟動資料庫到nomount:
      在視窗1
      export ORACLE_SID=orcl11g
   echo $ORACLE_SID
      sqlplus / as sysdba
   startup open pfile=/u02/oracle/product/11.2.0/dbhome_1/dbs
   在視窗2
   export ORACLE_SID=sorcl11g
   echo $ORACLE_SID
      sqlplus / as sysdba
   startup nomount pfile=/u03_clone/oracle/product/11.2.0/dbhome_1/dbs

   在備庫還得再建立一個空的新的資料庫
   CREATE DATABASE orcl11g
     USER SYS IDENTIFIED BY oracle
     USER SYSTEM IDENTIFIED BY oracle
     LOGFILE GROUP 1 ('/u03_clone/oracle/oradata/orcl11g/redo01.log') SIZE 100M BLOCKSIZE 512,
             GROUP 2 ('/u03_clone/oracle/oradata/orcl11g/redo02.log') SIZE 100M BLOCKSIZE 512,
             GROUP 3 ('/u03_clone/oracle/oradata/orcl11g/redo03.log') SIZE 100M BLOCKSIZE 512
     MAXLOGFILES 5
     MAXLOGMEMBERS 5
     MAXLOGHISTORY 1
    MAXDATAFILES 100
    CHARACTER SET ZHS16GBK
    NATIONAL CHARACTER SET AL16UTF16
    EXTENT MANAGEMENT LOCAL
    DATAFILE '/u03_clone/oracle/oradata/orcl11g/system01.dbf' SIZE 325M REUSE
    SYSAUX DATAFILE '/u03_clone/oracle/oradata/orcl11g/sysaux01.dbf' SIZE 325M REUSE
    DEFAULT TABLESPACE users
        DATAFILE '/u03_clone/oracle/oradata/orcl11g/users01.dbf'
        SIZE 500M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED
    DEFAULT TEMPORARY TABLESPACE tempts1
        TEMPFILE '/u03_clone/oracle/oradata/orcl11g/temp01.dbf'
        SIZE 20M REUSE
    UNDO TABLESPACE undotbs
        DATAFILE '/u03_clone/oracle/oradata/orcl11g/UNDOTBS_01.dbf'
        SIZE 200M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED
  
  c.登陸rman:

rman target sys/oracle@PRIMARY auxiliary system/oracle@PHYSICAL
rman target system/oracle@PHYSICAL auxiliary system/oracle@PRIMARY
  d.開始克隆:

 duplicate target database for standby nofilenamecheck from active database;

檢視日誌
vi /u03_clone/oracle/diag/rdbms/physical/orcl11g/trace/alert_orcl11g.log
vi /u02/oracle/diag/rdbms/primary/orcl11g/trace/alert_orcl11g.log

startup nomount pfile=/u03_clone/oracle/product/11.2.0/dbhome_1/dbs/initorcl11g.ora
startup upgrade pfile=/u03_clone/oracle/product/11.2.0/dbhome_1/dbs/initorcl11g.ora
startup open pfile=/u03_clone/oracle/product/11.2.0/dbhome_1/dbs/initorcl11g.ora
@/u03_clone/oracle/product/11.2.0/dbhome_1/rdbms/admin/catalog.sql
@/u03_clone/oracle/product/11.2.0/dbhome_1/rdbms/admin/catproc.sql

@/u03_clone/oracle/product/11.2.0/dbhome_1/rdbms/admin/catupgrd.sql

startup open pfile=/u02/oracle/product/11.2.0/dbhome_1/dbs/initorcl11g.ora


測試遠端連線備庫
export ORACLE_SID=sorcl11g
export ORACLE_HOME=/u03_clone/oracle/product/11.2.0/dbhome_1
export TNS_ADMIN=/u03_clone/oracle/product/11.2.0/dbhome_1/network/admin/
export PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin
export LD_LIBRARY_PATH=$ORACLE_HOME/lib


cd $ORACLE_HOME/bin
./sqlplus / as sysdba
./lsnrctl status
startup open pfile=/u03_clone/oracle/product/11.2.0/dbhome_1/dbs/initorcl11g.ora
./sqlplus system/welcome1@PHYSICAL
rman target /

測試遠端連線主庫
export ORACLE_SID=orcl11g
export ORACLE_HOME=/u02/oracle/product/11.2.0/dbhome_1
export TNS_ADMIN=/u02/oracle/product/11.2.0/dbhome_1/network/admin/

cd $ORACLE_HOME/bin
./sqlplus / as sysdba
./lsnrctl status
startup open pfile=/u02/oracle/product/11.2.0/dbhome_1/dbs/initorcl11g.ora
./sqlplus system/oracle@PRIMARY

2.5:建立並啟用配置檔案
dgmgrl sys/oracle@PRIMARY 
create configuration dgc as primary database is PRIMARY connect identifier is PRIMARY;
add database PHYSICAL as connect identifier is PHYSICAL maintained as physical;
enable configuration
show configuration [verbose];

這次遇到的問題是在安裝了oracle軟體後,再建立資料庫時,特別最後執行catproc.sql時怎麼都執行不完,還老報錯
關閉資料庫重啟open後,還說要按upgrade方式開啟資料庫,顯然catproc.sql未完全執行完,最後發現原因實際是資料庫記憶體不足
在執行指令碼時,速度很慢,而且free -mh檢視記憶體只有幾十M可用,於是,關閉佔用記憶體的應用,重新執行指令碼很快就執行好了,而且
可以順利啟動到open狀態
http://blog.51cto.com/ylw6006/686900

在備庫上克隆主庫

https://www.cnblogs.com/vijayfly/archive/2015/12/16/5051614.html oracle11G使用DGbroker建立dg



解決問題
ORA-01034: ORACLE not available
ORA-27101: shared memory realm does not exist
Linux-x86_64 Error: 2: No such file or directory
這個錯誤最大的問題是 一個節點上安了兩個oracle軟體,在啟動第二個oracle軟體時,環境變數ORACLE_HOME還是第一個oracle軟體的
,所以啟動資料庫時,是在環境變數1的基礎上啟動的資料庫,造成啟動時資料庫會用到錯誤的環境變數ORACLE_HOME,最終啟動雖然
正常,但遠端連線時就報上面的錯誤。sqlplus system/oracle@PHYSICAL
另外出現 shared memory realm does not exist的原因還有可能是虛擬機器實體記憶體不足造成



Service "PHYSICAL.localdomain" has 1 instance(s).
  Instance "sorcl11g", status READY, has 1 handler(s) for this service...
Service "PRIMARY" has 1 instance(s).
  Instance "orcl11g", status UNKNOWN, has 1 handler(s) for this service...
Service "PRIMARY_DGMGRL" has 1 instance(s).
  Instance "orcl11g", status UNKNOWN, has 1 handler(s) for this service...
Service "orcl11g.localdomain" has 1 instance(s).
  Instance "orcl11g", status UNKNOWN, has 1 handler(s) for this service...
Service "orcl11gXDB.localdomain" has 1 instance(s).
  Instance "sorcl11g", status READY, has 1 handler(s) for this service...


Service "PHYSICAL" has 1 instance(s).
  Instance "sorcl11g", status UNKNOWN, has 1 handler(s) for this service...
Service "PHYSICAL_DGMGRL" has 1 instance(s).
  Instance "sorcl11g", status UNKNOWN, has 1 handler(s) for this service...
Service "orcl11g.localdomain" has 1 instance(s).
  Instance "sorcl11g", status UNKNOWN, has 1 handler(s) for this service...
 
 
 
 
 
 

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/750077/viewspace-2150247/,如需轉載,請註明出處,否則將追究法律責任。

相關文章