groupadd oinstall
創(chuàng)新互聯(lián)2013年開創(chuàng)至今,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項(xiàng)目成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站制作、外貿(mào)網(wǎng)站建設(shè)網(wǎng)站策劃,項(xiàng)目實(shí)施與項(xiàng)目整合能力。我們以讓每一個夢想脫穎而出為使命,1280元梨樹做網(wǎng)站,已為上家服務(wù),為梨樹各地企業(yè)和個人服務(wù),聯(lián)系電話:13518219792
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ù)庫軟件
2.主庫dbca建庫
3.主備分別netca
4.主庫執(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ù)庫
SQL>shutdown immediate
生成spfile
SQL> create spfile from pfile;
5.在備庫段執(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
下面的幾個scp 在主庫執(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;
主庫執(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í)行此命令后,備庫會切換到自動恢復(fù)模式
一、功能切換
Switchover狀態(tài)切換
首先在primary上操作:
(1).驗(yàn)證主庫是否能執(zhí)行角色轉(zhuǎn)換到備庫(原主庫執(zhí)行)
SQL> SELECT SWITCHOVER_STATUS FROM V$DATABASE;
SWITCHOVER_STATUS
-----------------
TO STANDBY
1 row selected
(2)開始把物理主庫改變?yōu)槲锢韨鋷欤ㄔ鲙靾?zhí)行)
SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY;
或
SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY with session shutdown;
注:如果有活動的session可以使用此選項(xiàng),否則轉(zhuǎn)換會遇到ORA-01093錯誤,也可以殺掉活動會話或等活動會話后進(jìn)行轉(zhuǎn)換
(3).關(guān)閉并重啟主庫(原主庫執(zhí)行)
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; #開始實(shí)時同步
然后在standby上操作:
(1).驗(yàn)證備庫是否能執(zhí)行角色轉(zhuǎn)換到主庫(原備庫執(zhí)行)
SQL> SELECT SWITCHOVER_STATUS FROM V$DATABASE;
SWITCHOVER_STATUS
-----------------
TO_PRIMARY
1 row selected
(2).開始把物理備庫轉(zhuǎn)換成物理主庫(原備庫執(zhí)行)
SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY;
--如果報ORA-16139: media recovery required,可能是由于未應(yīng)用日志引起,可先執(zhí)行
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
(3)打開備庫,然后關(guān)閉重啟.(原備庫執(zhí)行)
SQL> SHUTDOWN IMMEDIATE;
SQL> STARTUP;
(4)驗(yàn)證是否轉(zhuǎn)換成功(原備庫執(zhí)行)
SQL> ALTER SYSTEM SWITCH LOGFILE;
啟動日志應(yīng)用
(5) 應(yīng)用歸檔日志(原主庫上執(zhí)行)
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT FROM SESSION;
小竅門:要想順利的實(shí)現(xiàn)switchover,最好在每臺server上都同時設(shè)置好primary和standby的一些初始化參數(shù),雖然其中一些參數(shù)只有在primary或者standby其中之一上起作用。
4、啟動和關(guān)閉順序
啟動順序
(1).啟從、主庫的監(jiān)聽Listener
從庫DG-Standby:
$lsnrctl start
主庫DG-Primary:
$lsnrctl start
(2).啟動備庫數(shù)據(jù)庫,執(zhí)行如下:
$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; #開始實(shí)時同步
(3).啟動主庫
$sqlplus /nolog
SQL>conn /as sysdba
SQL> startup
切換standby database到read only模式
SQL> alter database recover managed standby database cancel; #首先取消備庫的自動恢復(fù)模式
SQL>alter database open read only;
如果要切換回recover manage模式(啟動日志應(yīng)用或者啟動日志實(shí)時應(yīng)用)
SQL> alter database recover managed standby database disconnect from session; 啟動日志應(yīng)用
SQL>alter database recover managed standby database using current logfile disconnect from session; 啟動日志實(shí)時應(yīng)用
(3).啟動主庫數(shù)據(jù)庫(上述第二步執(zhí)行完畢后,方可執(zhí)行如下命令):
SQL>startup
關(guān)閉順序
關(guān)閉的時候正好相反,先關(guān)閉主庫,然后關(guān)閉從庫。
(1). 關(guān)閉主庫
$su – oracle
SQL>sqlplus /nolog
SQL>conn /as sysdba
SQL>shutdown immediate;
(2). 關(guān)閉從庫
su – oracle
SQL>sqlplus /nolog
SQL>conn /as sysdba
SQL>alter database recover managed standby database cancel; #停止同步
SQL>shutdown immediate
應(yīng)急切換
(注:模擬主庫由于故障無法正常switchover,需要執(zhí)行failover,強(qiáng)制備庫->pridb并接管業(yè)務(wù))
(1).備庫:
由于是failover,所以理解主庫這時候已經(jīng)無法正常使用,只需備庫切換至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ù)庫,恢復(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)上也說不需要配置,但是還沒有測試成功
select dbid,name,protection_mode,protection_level from v$database;