您好,登錄后才能下訂單哦!
groupadd oinstall
groupadd dba
groupadd oper
groupadd asmadmin
groupadd asmdba
groupadd asmoper
useradd -g oinstall -G dba,asmdba,asmadmin,asmoper grid
useradd -g oinstall -G dba,oper,asmdba oracle
passwd grid
passwd oracle
mkdir -p /u01/app/11.2.0/grid
mkdir -p /u01/app/grid
mkdir -p /u01/app/oracle
chown grid:oinstall /u01/app/11.2.0/grid
chown grid:oinstall /u01/app/grid
chown -R oracle:oinstall /u01/app/oracle
chmod -R 775 /u01/
chown -R grid:oinstall /u01
sed -i 's/kernel.shmmax/#kernel.shmmax/g' /etc/sysctl.conf
sed -i 's/kernel.shmall/#kernel.shmall/g' /etc/sysctl.conf
vi /etc/sysctl.conf
添加以下內(nèi)容:
fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 2097152
kernel.shmmax = 1073741824
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048586
sysctl -p
vi /etc/security/limits.conf
添加如下內(nèi)容:
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
oracle soft stack 10240
grid soft nproc 2047
grid hard nproc 16384
grid soft nofile 1024
grid hard nofile 65536
grid soft stack 10240
vi /etc/profile 寫入如下內(nèi)容:
if [ $USER = "oracle" ] || [ $USER = "grid" ]; then
if [ $SHELL = "/bin/ksh" ]; then
ulimit -p 16384
ulimit -n 65536
else
ulimit -u 16384 -n 65536
fi
umask 022
fi
export PATH=$PATH:/u01/app/11.2.0/grid/bin
配置節(jié)點(diǎn)rac1
grid 用戶:
vi .bash_profile
export TMP=/tmp
export TMPDIR=$TMP
export ORACLE_HOSTNAME=
export ORACLE_SID=
export ORACLE_BASE=/u01/app/grid
export ORACLE_HOME=/u01/app/11.2.0/grid
export PATH=$ORACLE_HOME/bin:$PATH
oracle用戶:
vi .bash_profile
export TMP=/tmp
export TMPDIR=$TMP
export ORACLE_HOSTNAME=
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
export ORACLE_UNQNAME=
export ORACLE_SID=
export ORACLE_TERM=xterm
export PATH=/usr/sbin:$PATH
export PATH=$ORACLE_HOME/bin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
export CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
1.分別安裝完數(shù)據(jù)庫(kù)軟件
2.主庫(kù)dbca建庫(kù)
3.主備分別netca
4.主庫(kù)執(zhí)行:
select * from v$option where parameter = 'Managed Standby';
archive log list
alter database force logging;
alter database add standby logfile group 4 ('/u01/app/oracle/oradata/redo04.log') size 50m;
alter database add standby logfile group 5 ('/u01/app/oracle/oradata/redo05.log') size 50m;
alter database add standby logfile group 6 ('/u01/app/oracle/oradata/redo06.log') size 50m;
alter database add standby logfile group 7 ('/u01/app/oracle/oradata/redo07.log') size 50m;
create pfile from spfile;
show parameter name;
alter system set db_unique_name='ora11g_primary' scope=spfile;
alter system set log_archive_config='dg_config=(ora11g_primary,ora11g_standby)';
create pfile from spfile;
shutdown immediate;
cd /u01/app/oracle/product/11.2.0/db_1/dbs
查看initora11g.org db_unique_name='ora11g_primary'是否有
startup;
alter system set log_archive_dest_1='location=/u01/app/oracle/archivelog valid_for=(ALL_LOGFILES,ALL_ROLES) db_unique_name=ora11g_primary';
alter system set log_archive_dest_2='service=ora11g_standby LGWR SYNC valid_for=(ONLINE_LOGFILES,primary_role) db_unique_name=ora11g_standby';
alter system set log_archive_dest_state_1='enable';
alter system set log_archive_dest_state_2='enable';
alter system set REMOTE_LOGIN_PASSWORDFILE='EXCLUSIVE' scope=spfile;
alter system set FAL_SERVER='ora11g_standby' scope=spfile;
alter system set FAL_client='ora11g_primary' scope=spfile;
alter system set STANDBY_FILE_MANAGEMENT='AUTO' scope=spfile;
mkdir -p $ORACLE_BASE/archivelog
create pfile from spfile;
shutdown immediate;
驗(yàn)證參數(shù)是否都在
startup mount;
alter database create standby controlfile as '/u01/standby_ctl02.ctl';
cd /u01/app/oracle/product/11.2.0/db_1/network/admin
vim listener.ora
添加
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = ora11g)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = cbfdb1)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)
ADR_BASE_LISTENER = /u01/app/oracle
vim tnsnames.ora
ORA11G_PRIMARY =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.1)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = ora11g)
)
)
ORA11G_STANDBY =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.2)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = ora11g)
)
)
關(guān)閉主數(shù)據(jù)庫(kù)
SQL>shutdown immediate
生成spfile
SQL> create spfile from pfile;
5.在備庫(kù)段執(zhí)行:
mkdir -p $ORACLE_BASE/oradata/ora11g
mkdir -p $ORACLE_BASE/admin/ora11g
mkdir -p $ORACLE_BASE/admin/ora11g/adump
mkdir -p $ORACLE_BASE/admin/ora11g/bdump
mkdir -p $ORACLE_BASE/admin/ora11g/cdump
mkdir -p $ORACLE_BASE/admin/ora11g/dpdump
mkdir -p $ORACLE_BASE/admin/ora11g/pfile
mkdir -p $ORACLE_BASE/admin/ora11g/udump
mkdir -p $ORACLE_BASE/diag/rdbms
mkdir -p $ORACLE_BASE/diag/tnslsnr
mkdir -p $ORACLE_BASE/fast_recovery_area/ORA11G
mkdir -p $ORACLE_BASE/archivelog
下面的幾個(gè)scp 在主庫(kù)執(zhí)行
scp -r $ORACLE_BASE/oradata/ora11g/*.dbf 192.168.0.2:/$ORACLE_BASE/oradata/ora11g
scp -r $ORACLE_BASE/oradata/*.log 192.168.0.2:/$ORACLE_BASE/oradata
scp -r /u01/standby_ctl01.ctl 192.168.0.2:/$ORACLE_BASE/oradata
scp -r $ORACLE_HOME/dbs/initora11g.ora 192.168.0.2: $ORACLE_HOME/dbs/
scp -r /u01/app/oracle/product/11.2.0/db_1/dbs/orapwora11g 192.168.0.2:/u01/app/oracle/product/11.2.0/db_1/dbs/
$ cd $ORACLE_BASE/oradata/ora11g
$ mv standby_ctl01.ctl control01.ctl
$ cp control01.ctl control02.ctl
cd /u01/app/oracle/product/11.2.0/db_1/dbs
修改initora11g.ora
DB_UNIQUE_NAME=ora11g_standby
LOG_ARCHIVE_DEST_1='LOCATION=/u01/app/oracle/archivelog VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=ora11g_standby'
LOG_ARCHIVE_DEST_2='SERVICE=ora11g_primary LGWR SYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=ora11g_primary'
FAL_SERVER=ora11g_primary
FAL_CLIENT=ora11g_standby
cd /u01/app/oracle/product/11.2.0/db_1/network/admin
vim listener.ora
添加
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = ora11g)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = cbfdb2)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)
ADR_BASE_LISTENER = /u01/app/oracle
vim tnsnames.ora
ORA11G_PRIMARY =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.1)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = ora11g)
)
)
ORA11G_STANDBY =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.2)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = ora11g)
)
)
startup nomount
alter database mount standby database;
主庫(kù)執(zhí)行:
startup mount
alter database set standby database to maximize availability; (設(shè)置為最高可用性模式)
alter database open;
SQL>alter database recover managed standby database disconnect from session;
#執(zhí)行此命令后,備庫(kù)會(huì)切換到自動(dòng)恢復(fù)模式
一、功能切換
Switchover狀態(tài)切換
首先在primary上操作:
(1).驗(yàn)證主庫(kù)是否能執(zhí)行角色轉(zhuǎn)換到備庫(kù)(原主庫(kù)執(zhí)行)
SQL> SELECT SWITCHOVER_STATUS FROM V$DATABASE;
SWITCHOVER_STATUS
-----------------
TO STANDBY
1 row selected
(2)開始把物理主庫(kù)改變?yōu)槲锢韨鋷?kù)(原主庫(kù)執(zhí)行)
SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY;
或
SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY with session shutdown;
注:如果有活動(dòng)的session可以使用此選項(xiàng),否則轉(zhuǎn)換會(huì)遇到ORA-01093錯(cuò)誤,也可以殺掉活動(dòng)會(huì)話或等活動(dòng)會(huì)話后進(jìn)行轉(zhuǎn)換
(3).關(guān)閉并重啟主庫(kù)(原主庫(kù)執(zhí)行)
SQL> shutdown immediate
SQL> startup nomount
SQL> alter database mount standby database; #讓備庫(kù)處于standby
SQL> alter database recover managed standby database using current logfile disconnect from session; #開始實(shí)時(shí)同步
然后在standby上操作:
(1).驗(yàn)證備庫(kù)是否能執(zhí)行角色轉(zhuǎn)換到主庫(kù)(原備庫(kù)執(zhí)行)
SQL> SELECT SWITCHOVER_STATUS FROM V$DATABASE;
SWITCHOVER_STATUS
-----------------
TO_PRIMARY
1 row selected
(2).開始把物理備庫(kù)轉(zhuǎn)換成物理主庫(kù)(原備庫(kù)執(zhí)行)
SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY;
--如果報(bào)ORA-16139: media recovery required,可能是由于未應(yīng)用日志引起,可先執(zhí)行
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
(3)打開備庫(kù),然后關(guān)閉重啟.(原備庫(kù)執(zhí)行)
SQL> SHUTDOWN IMMEDIATE;
SQL> STARTUP;
(4)驗(yàn)證是否轉(zhuǎn)換成功(原備庫(kù)執(zhí)行)
SQL> ALTER SYSTEM SWITCH LOGFILE;
啟動(dòng)日志應(yīng)用
(5) 應(yīng)用歸檔日志(原主庫(kù)上執(zhí)行)
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT FROM SESSION;
小竅門:要想順利的實(shí)現(xiàn)switchover,最好在每臺(tái)server上都同時(shí)設(shè)置好primary和standby的一些初始化參數(shù),雖然其中一些參數(shù)只有在primary或者standby其中之一上起作用。
4、啟動(dòng)和關(guān)閉順序
啟動(dòng)順序
(1).啟從、主庫(kù)的監(jiān)聽Listener
從庫(kù)DG-Standby:
$lsnrctl start
主庫(kù)DG-Primary:
$lsnrctl start
(2).啟動(dòng)備庫(kù)數(shù)據(jù)庫(kù),執(zhí)行如下:
$sqlplus /nolog
SQL>conn /as sysdba
SQL> startup nomount
SQL> alter database mount standby database; #讓備庫(kù)處于standby
SQL> alter database recover managed standby database using current logfile disconnect from session; #開始實(shí)時(shí)同步
(3).啟動(dòng)主庫(kù)
$sqlplus /nolog
SQL>conn /as sysdba
SQL> startup
切換standby database到read only模式
SQL> alter database recover managed standby database cancel; #首先取消備庫(kù)的自動(dòng)恢復(fù)模式
SQL>alter database open read only;
如果要切換回recover manage模式(啟動(dòng)日志應(yīng)用或者啟動(dòng)日志實(shí)時(shí)應(yīng)用)
SQL> alter database recover managed standby database disconnect from session; 啟動(dòng)日志應(yīng)用
SQL>alter database recover managed standby database using current logfile disconnect from session; 啟動(dòng)日志實(shí)時(shí)應(yīng)用
(3).啟動(dòng)主庫(kù)數(shù)據(jù)庫(kù)(上述第二步執(zhí)行完畢后,方可執(zhí)行如下命令):
SQL>startup
關(guān)閉順序
關(guān)閉的時(shí)候正好相反,先關(guān)閉主庫(kù),然后關(guān)閉從庫(kù)。
(1). 關(guān)閉主庫(kù)
$su – oracle
SQL>sqlplus /nolog
SQL>conn /as sysdba
SQL>shutdown immediate;
(2). 關(guān)閉從庫(kù)
su – oracle
SQL>sqlplus /nolog
SQL>conn /as sysdba
SQL>alter database recover managed standby database cancel; #停止同步
SQL>shutdown immediate
應(yīng)急切換
(注:模擬主庫(kù)由于故障無(wú)法正常switchover,需要執(zhí)行failover,強(qiáng)制備庫(kù)->pridb并接管業(yè)務(wù))
(1).備庫(kù):
由于是failover,所以理解主庫(kù)這時(shí)候已經(jīng)無(wú)法正常使用,只需備庫(kù)切換至pridb
停止應(yīng)用恢復(fù)模式
alter database recover managed standby database finish;
轉(zhuǎn)換standbydb為primary db
alter database commit to switchover to primary;
重啟數(shù)據(jù)庫(kù),恢復(fù)正常業(yè)務(wù)
SQL>shutdown immediate
SQL>startup
select open_mode,database_role from v$database;
OPEN_MODE DATABASE_ROLE
---------- ----------------
OPEN PRIMARY
注:failover將破壞dataguard模式,需要重新配置dataguard,網(wǎng)上也說(shuō)不需要配置,但是還沒(méi)有測(cè)試成功
select dbid,name,protection_mode,protection_level from v$database;
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。