您好,登錄后才能下訂單哦!
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
添加以下內容:
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
添加如下內容:
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 寫入如下內容:
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
配置節點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.分別安裝完數據庫軟件
2.主庫dbca建庫
3.主備分別netca
4.主庫執行:
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;
驗證參數是否都在
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)
)
)
關閉主數據庫
SQL>shutdown immediate
生成spfile
SQL> create spfile from pfile;
5.在備庫段執行:
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
下面的幾個scp 在主庫執行
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;
主庫執行:
startup mount
alter database set standby database to maximize availability; (設置為最高可用性模式)
alter database open;
SQL>alter database recover managed standby database disconnect from session;
#執行此命令后,備庫會切換到自動恢復模式
一、功能切換
Switchover狀態切換
首先在primary上操作:
(1).驗證主庫是否能執行角色轉換到備庫(原主庫執行)
SQL> SELECT SWITCHOVER_STATUS FROM V$DATABASE;
SWITCHOVER_STATUS
-----------------
TO STANDBY
1 row selected
(2)開始把物理主庫改變為物理備庫(原主庫執行)
SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY;
或
SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY with session shutdown;
注:如果有活動的session可以使用此選項,否則轉換會遇到ORA-01093錯誤,也可以殺掉活動會話或等活動會話后進行轉換
(3).關閉并重啟主庫(原主庫執行)
SQL> shutdown immediate
SQL> startup nomount
SQL> alter database mount standby database; #讓備庫處于standby
SQL> alter database recover managed standby database using current logfile disconnect from session; #開始實時同步
然后在standby上操作:
(1).驗證備庫是否能執行角色轉換到主庫(原備庫執行)
SQL> SELECT SWITCHOVER_STATUS FROM V$DATABASE;
SWITCHOVER_STATUS
-----------------
TO_PRIMARY
1 row selected
(2).開始把物理備庫轉換成物理主庫(原備庫執行)
SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY;
--如果報ORA-16139: media recovery required,可能是由于未應用日志引起,可先執行
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
(3)打開備庫,然后關閉重啟.(原備庫執行)
SQL> SHUTDOWN IMMEDIATE;
SQL> STARTUP;
(4)驗證是否轉換成功(原備庫執行)
SQL> ALTER SYSTEM SWITCH LOGFILE;
啟動日志應用
(5) 應用歸檔日志(原主庫上執行)
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT FROM SESSION;
小竅門:要想順利的實現switchover,最好在每臺server上都同時設置好primary和standby的一些初始化參數,雖然其中一些參數只有在primary或者standby其中之一上起作用。
4、啟動和關閉順序
啟動順序
(1).啟從、主庫的監聽Listener
從庫DG-Standby:
$lsnrctl start
主庫DG-Primary:
$lsnrctl start
(2).啟動備庫數據庫,執行如下:
$sqlplus /nolog
SQL>conn /as sysdba
SQL> startup nomount
SQL> alter database mount standby database; #讓備庫處于standby
SQL> alter database recover managed standby database using current logfile disconnect from session; #開始實時同步
(3).啟動主庫
$sqlplus /nolog
SQL>conn /as sysdba
SQL> startup
切換standby database到read only模式
SQL> alter database recover managed standby database cancel; #首先取消備庫的自動恢復模式
SQL>alter database open read only;
如果要切換回recover manage模式(啟動日志應用或者啟動日志實時應用)
SQL> alter database recover managed standby database disconnect from session; 啟動日志應用
SQL>alter database recover managed standby database using current logfile disconnect from session; 啟動日志實時應用
(3).啟動主庫數據庫(上述第二步執行完畢后,方可執行如下命令):
SQL>startup
關閉順序
關閉的時候正好相反,先關閉主庫,然后關閉從庫。
(1). 關閉主庫
$su – oracle
SQL>sqlplus /nolog
SQL>conn /as sysdba
SQL>shutdown immediate;
(2). 關閉從庫
su – oracle
SQL>sqlplus /nolog
SQL>conn /as sysdba
SQL>alter database recover managed standby database cancel; #停止同步
SQL>shutdown immediate
應急切換
(注:模擬主庫由于故障無法正常switchover,需要執行failover,強制備庫->pridb并接管業務)
(1).備庫:
由于是failover,所以理解主庫這時候已經無法正常使用,只需備庫切換至pridb
停止應用恢復模式
alter database recover managed standby database finish;
轉換standbydb為primary db
alter database commit to switchover to primary;
重啟數據庫,恢復正常業務
SQL>shutdown immediate
SQL>startup
select open_mode,database_role from v$database;
OPEN_MODE DATABASE_ROLE
---------- ----------------
OPEN PRIMARY
注:failover將破壞dataguard模式,需要重新配置dataguard,網上也說不需要配置,但是還沒有測試成功
select dbid,name,protection_mode,protection_level from v$database;
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。