一、环境配置
1.1、安装软件包
1.1.1、配置本地源
注:能通过公网安装软件包的情况下跳过该项
mv /etc/yum.repos.d/* /tmp/
echo "[local_yum]" >> /etc/yum.repos.d/henry.repo
echo "name = henry_repo" >> /etc/yum.repos.d/henry.repo
echo "baseurl = file:///mnt/" >> /etc/yum.repos.d/henry.repo
echo "enabled = 1" >> /etc/yum.repos.d/henry.repo
echo "gpgcheck = 0" >> /etc/yum.repos.d/henry.repo
mount /dev/cdrom /mnt/
1.1.2、安装软件包
yum -y install bc binutils elfutils-libelf elfutils-libelf-devel fontconfig-devel gcc gcc-c++ glibc glibc-devel ksh libgcc libstdc++ libstdc++-devel libaio libaio-devel libXtst libX11 libXau libxcb libXi libXrender make smartmontools sysstat kmod* sysstat unixODBC unixODBC-devel libnsl lm_sensors-libs ksh make glibc-devel libaio-devel libstdc++-devel nano
需要单独安装的软件包
yum -y localinstall https://yum.oracle.com/repo/OracleLinux/OL7/latest/x86_64/getPackage/compat-libcap1-1.10-7.el7.x86_64.rpm
yum -y localinstall https://yum.oracle.com/repo/OracleLinux/OL7/latest/x86_64/getPackage/sysstat-10.1.5-20.0.3.el7_9.x86_64.rpm
yum -y localinstall https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/compat-libstdc++-33-3.2.3-72.el7.x86_64.rpm
yum -y localinstall http://vault.centos.org/5.11/os/x86_64/CentOS/pdksh-5.2.14-37.el5_8.1.x86_64.rpm
1.2、内核参数调整,执行以下代码块自动完成
export shmall=$(echo "`cat /proc/meminfo | grep "MemTotal" | awk '{print $2}'` / (`getconf PAGESIZE` / 1024)" | bc)
export shmax=$(echo "`cat /proc/meminfo | grep "MemTotal" | awk '{print $2}'` * 1024 * 0.8" | bc | sed 's#\..*$##')
echo """kernel.shmall = $shmall
kernel.shmmax = $shmax
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
fs.file-max = 6815744
fs.aio-max-nr = 1048576
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 = 104857
vm.swappiness = 0
vm.dirty_background_ratio = 3
vm.dirty_ratio = 80
vm.dirty_expire_centisecs = 500
vm.dirty_writeback_centisecs = 100
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1""" >> /etc/sysctl.conf
sysctl -p
1.3、配置ssh、关闭Selinux及防火墙
# 配置LoginGraceTime参数为0, 将timeout wait设置为无限制
sed -i '/#LoginGraceTime 2m/ s/#LoginGraceTime 2m/LoginGraceTime 0/' /etc/ssh/sshd_config && grep LoginGraceTime /etc/ssh/sshd_config
# 加快SSH登录 禁用DNS
sed -i '/#UseDNS yes/ s/#UseDNS yes/UseDNS no/' /etc/ssh/sshd_config && grep UseDNS /etc/ssh/sshd_config
sed -i 's/enforcing/disabled/g' /etc/selinux/config
setenforce 0
service firewalld stop
chkconfig firewalld off
1.4用户组及变量相关设置
1.4.1单机环境
groupadd -g 1003 oinstall
groupadd -g 1001 dba
groupadd -g 1002 oper
useradd -u 1001 -g oinstall -G dba,oper oracle
echo oracle |passwd --stdin oracle
echo """export ORACLE_SID=orcl
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=\${ORACLE_BASE}/product/11.2.0.4/db_1
export NLS_DATE_FORMAT="YYYY:MM:DDHH24:MI:SS"
export NLS_LANG=american_america.ZHS16GBK
export TNS_ADMIN=\$ORACLE_HOME/network/admin
export ORA_NLS11=\$ORACLE_HOME/nls/data
export PATH=.:\${PATH}:\$ORACLE_HOME/bin:/usr/bin:/usr/bin/X11:/usr/local/bin:
export LD_LIBRARY_PATH=\$ORACLE_HOME/lib:\$ORACLE_HOME/oracm/lib:/lib:/usr/lib:/usr/local/lib
# export CLASSPATH=\$ORACLE_HOME/JRE:\$ORACLE_HOME/jlib:\$ORACLE_HOME/rdbms/jlib:\$ORACLE_HOME/network/jlib
export CV_ASSUME_DISTID=OL7
export THREADS_FLAG=native
export TEMP=/tmp
export TMPDIR=/tmp""" >> /home/oracle/.bash_profile
1.4.2集群环境
节点1 执行
groupadd -g 1003 oinstall
groupadd -g 1001 dba
groupadd -g 1002 oper
groupadd -g 1004 backupdba
groupadd -g 1005 dgdba
groupadd -g 1006 kmdba
groupadd -g 1007 asmdba
groupadd -g 1008 asmoper
groupadd -g 1009 asmadmin
groupadd -g 1010 racdba
useradd -g oinstall -G dba,oper,backupdba,dgdba,kmdba,asmdba,racdba oracle
useradd -g oinstall -G dba,asmdba,asmoper,asmadmin,racdba grid
echo "oracle" | passwd --stdin oracle
echo "grid" | passwd --stdin grid
#节点1-Grid用户
cat >> /home/grid/.bash_profile << "EOF"
umask 022
export TMP=/tmp
export TMPDIR=$TMP
export ORACLE_BASE=/u01/app/grid
export ORACLE_HOME=/u01/app/11.2.0.4/grid
export TNS_ADMIN=$ORACLE_HOME/network/admin
export NLS_LANG=american_america.ZHS16GBK
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
export ORACLE_SID=+ASM1
export PATH=/usr/sbin:$PATH
export PATH=$ORACLE_HOME/bin:$ORACLE_HOME/OPatch:$PATH
#alias sas='sqlplus / as sysasm'
export PS1="[\`whoami\`@\`hostname\`:"'$PWD]\$ '
EOF
# 节点1-Oracle用户
echo """export ORACLE_SID=orcl1
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=\${ORACLE_BASE}/product/11.2.0.4/db_1
export NLS_DATE_FORMAT="YYYY:MM:DDHH24:MI:SS"
export NLS_LANG=american_america.ZHS16GBK
export TNS_ADMIN=\$ORACLE_HOME/network/admin
export ORA_NLS11=\$ORACLE_HOME/nls/data
export PATH=.:\${PATH}:\$ORACLE_HOME/bin:/usr/bin:/usr/bin/X11:/usr/local/bin:
export LD_LIBRARY_PATH=\$ORACLE_HOME/lib:\$ORACLE_HOME/oracm/lib:/lib:/usr/lib:/usr/local/lib
# export CLASSPATH=\$ORACLE_HOME/JRE:\$ORACLE_HOME/jlib:\$ORACLE_HOME/rdbms/jlib:\$ORACLE_HOME/network/jlib
export CV_ASSUME_DISTID=OL7
export THREADS_FLAG=native
export TEMP=/tmp
export TMPDIR=/tmp""" >> /home/oracle/.bash_profile
节点2执行
groupadd -g 1003 oinstall
groupadd -g 1001 dba
groupadd -g 1002 oper
groupadd -g 1004 backupdba
groupadd -g 1005 dgdba
groupadd -g 1006 kmdba
groupadd -g 1007 asmdba
groupadd -g 1008 asmoper
groupadd -g 1009 asmadmin
groupadd -g 1010 racdba
useradd -g oinstall -G dba,oper,backupdba,dgdba,kmdba,asmdba,racdba oracle
useradd -g oinstall -G dba,asmdba,asmoper,asmadmin,racdba grid
echo "oracle" | passwd --stdin oracle
echo "grid" | passwd --stdin grid
cat >> /home/grid/.bash_profile << "EOF"
umask 022
export TMP=/tmp
export TMPDIR=$TMP
export ORACLE_BASE=/u01/app/grid
export ORACLE_HOME=/u01/app/11.2.0.4/grid
export TNS_ADMIN=$ORACLE_HOME/network/admin
export NLS_LANG=american_america.ZHS16GBK
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
export ORACLE_SID=+ASM2
export PATH=/usr/sbin:$PATH
export PATH=$ORACLE_HOME/bin:$ORACLE_HOME/OPatch:$PATH
#alias sas='sqlplus / as sysasm'
export PS1="[\`whoami\`@\`hostname\`:"'$PWD]\$ '
EOF
# 节点2-Oracle用户
echo """export ORACLE_SID=orcl2
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=\${ORACLE_BASE}/product/11.2.0.4/db_1
export NLS_DATE_FORMAT="YYYY:MM:DDHH24:MI:SS"
export NLS_LANG=american_america.ZHS16GBK
export TNS_ADMIN=\$ORACLE_HOME/network/admin
export ORA_NLS11=\$ORACLE_HOME/nls/data
export PATH=.:\${PATH}:\$ORACLE_HOME/bin:/usr/bin:/usr/bin/X11:/usr/local/bin:
export LD_LIBRARY_PATH=\$ORACLE_HOME/lib:\$ORACLE_HOME/oracm/lib:/lib:/usr/lib:/usr/local/lib
# export CLASSPATH=\$ORACLE_HOME/JRE:\$ORACLE_HOME/jlib:\$ORACLE_HOME/rdbms/jlib:\$ORACLE_HOME/network/jlib
export CV_ASSUME_DISTID=OL7
export THREADS_FLAG=native
export TEMP=/tmp
export TMPDIR=/tmp""" >> /home/oracle/.bash_profile
1.5、创建目录及赋予权限
1.5.1、单机环境创建目录并赋予权限
mkdir -p /u01/app/oracle/product/11.2.0.4/db_1
chown -R oracle:oinstall /u01/
chmod -R 775 /u01/
1.5.2、集群环境创建目录并赋予权限
mkdir -p /u01/app/11.2.0.4/grid
mkdir -p /u01/app/grid
mkdir -p /u01/app/oracle/product/11.2.0.4/db_1
chown -R grid:oinstall /u01
chown -R oracle:oinstall /u01/app/oracle
chmod -R 775 /u01/
二、存储配置
2.1、ISCSI存储配置
注:如未使用本地创建的磁盘,使用iscsi共享磁盘,需要先连接到共享磁盘
yum install -y iscsi-initiator-utils
systemctl start iscsi
systemctl enable iscsi
#发现target(discovery)
iscsiadm -m discovery -t st -p 10.255.10.9:3260
#连接target(discovery)存储
iscsiadm -m node -T iqn.2005-10.org.freenas.ctl:orcl-rac -p 10.255.10.9 -l
#查看登录的session 相当于iscsiadm -m session -P 0
iscsiadm -m session
#扫描所有关联的target/session
iscsiadm -m node -R
iscsiadm -m session -R
#自动登录
iscsiadm -m node -T iqn.2005-10.org.freenas.ctl:orcl-rac -p 10.255.10.9,3260 --op update -n node.startup -v automatic
#扫描新添加的Iscsi存储设备
/usr/bin/scsi-rescan
#查看已经建立的iscsi连接
iscsiadm -m session -P 3
#断开iscsi连接
iscsiadm --mode node --targetname <target_name> --portal <target_portal> --logout
#断开所有iscsi连接
iscsiadm --mode node --logoutall=all
#重启iscsi
systemctl restart iscsid
#取消掉自动登录
iscsiadm --mode node --targetname iqn.2005-10.org.freenas.ctl:orcl-rac --portal 10.255.10.9:3260 --op delete
2.2、multipath+udev多路径
2.2.1、multipath配置
##安装multipath
yum install -y device-mapper*
mpathconf --enable --with_multipathd y
##查看共享盘的scsi_id
/usr/lib/udev/scsi_id -g -u /dev/sdb
/usr/lib/udev/scsi_id -g -u /dev/sdc
/usr/lib/udev/scsi_id -g -u /dev/sdd
/usr/lib/udev/scsi_id -g -u /dev/sde
/usr/lib/udev/scsi_id -g -u /dev/sdf
mv /etc/multipath.conf /etc/multipath.conf_bak
# 将iscsi_id 替换到下边的代码块中
cat <<EOF>> /etc/multipath.conf
defaults {
user_friendly_names yes
}
blacklist {
devnode "^sda"
}
multipaths {
multipath {
wwid "360002ac00000000000000018000278cf"
alias asm_crs01
}
multipath {
wwid "360002ac00000000000000019000278cf"
alias asm_crs02
}
multipath {
wwid "360002ac0000000000000001a000278cf"
alias asm_crs03
}
multipath {
wwid "360002ac0000000000000001b000278cf"
alias asm_fra
}
multipath {
wwid "360002ac0000000000000001c000278cf"
alias asm_data
}
}
EOF
#加载内核模块
modprobe dm_multipath
#删除所有不使用的多路径设备
multipath -F
#查看生成的多路径盘符
multipath -v2
#显示多路径配置状态
multipath -ll
2.2.2、Udev配置
for i in crs01 crs02 crs03 fra data; do
echo "KERNEL==\"sd*\", ENV{DEVTYPE}==\"disk\",SUBSYSTEM==\"block\", PROGRAM==\"/lib/udev/scsi_id -g -u -d \$devnode\",RESULT==\"`/usr/lib/udev/scsi_id -g -u /dev/mapper/asm_$i`\",RUN+=\"/bin/sh -c 'mknod /dev/asm-$i b \$major \$minor; chown grid:asmadmin /dev/asm-$i; chmod 0660 /dev/asm-$i'\"" >> /etc/udev/rules.d/99-oracle-asmdevices.rules
done
##重载udev
udevadm control --reload-rules
udevadm trigger --type=devices --action=change
ll /dev/asm*
2.2.3、Udev(非multipath)
注:/dev/sd[b-f] 对应下边的 b c d e f 如有更多的盘添加到代码中
for i in b c d e f;
do
echo "KERNEL==\"sd*\", ENV{DEVTYPE}==\"disk\", SUBSYSTEM==\"block\", PROGRAM==\"/lib/udev/scsi_id -g -u -d \$devnode\", RESULT==\"`/lib/udev/scsi_id -g -u -d /dev/sd$i`\", SYMLINK+=\"asm-disk$i\", OWNER=\"grid\", GROUP=\"asmadmin\", MODE=\"0660\"" >> /etc/udev/rules.d/99-oracle-asmdevices.rules
done
# 加载rules文件,重新加载udev rule
/sbin/udevadm control --reload
# 检查新的设备名称
/sbin/udevadm trigger --type=devices --action=change
三、集群环境下其他配置
3.1、主机名及解析
# 注:检查双网卡配置
#网卡1:
# 配置public IP 需要网关
网卡2:
# 配置priv IP 不要网关
# 网卡都关闭IPv6
# 节点1
hostnamectl set-hostname rac01
# 节点2
hostnamectl set-hostname rac02
echo "#public ip
10.255.10.11 rac01
10.255.10.12 rac02
#priv ip
10.10.10.11 rac01-pri
10.10.10.12 rac02-pri
#vip ip
10.255.10.13 rac01-vip
10.255.10.14 rac02-vip
#scan ip
10.255.10.10 rac-scan" >> /etc/hosts
# 测试连通性所有节点
ping -c 1 rac01; ping -c 1 rac02; ping -c 1 rac01-pri; ping -c 1 rac02-pri;
3.2、调整Network-双节点
echo "NOZEROCONF=yes" >>/etc/sysconfig/network && cat /etc/sysconfig/network
3.3、调整/dev/shm -双节点
# 修改shm大小
echo "tmpfs /dev/shm tmpfs rw,exec,size=32G 0 0">>/etc/fstab
# 重新挂载
mount -o remount /dev/shm
# 检测shm大小是否修改
df -h
3.4、关闭透明大页
cp /etc/default/grub /etc/default/grub.bak
sed -i 's/quiet/quiet\ transparent_hugepage=never/g' /etc/default/grub
#执行命令
grub2-mkconfig -o /boot/grub2/grub.cfg
#不重启生效
echo never > /sys/kernel/mm/transparent_hugepage/enabled
注:Rac集群下为所有节点配置互信
#生成密钥对
rm -rf ~/.ssh
mkdir ~/.ssh
ssh-keygen -t rsa
ssh-keygen -t dsa
注:节点1(rac01)的所有用户(oracle,grud,root)执行追加互信
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
ssh rac02 cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
ssh rac02 cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
scp ~/.ssh/authorized_keys rac02:~/.ssh/authorized_keys
注:所有节点(rac01,rac02)的所有用户(oracle,grid,root)执行互信验证,都不需要密码则互信添加完成
ssh rac01 date;
ssh rac02 date;
ssh rac01-pri date;
ssh rac02-pri date;
四、主库安装及DG配置
安装步骤省略
4.1、DG配置
sqlplus / as sysdba
shutdown immediate
startup mount
alter database archivelog;
alter database force logging;
alter database flashback on;
set wrap off;
select * from v$logfile order by group#; #查询日志组
GROUP# STATUS TYPE MEMBER
---------- -------------- -------------------- ---------------
1 ONLINE D:\APP\ADMINISTRATOR\ORADATA\ORCL\REDO01.LOG
2 ONLINE D:\APP\ADMINISTRATOR\ORADATA\ORCL\REDO02.LOG
3 ONLINE D:\APP\ADMINISTRATOR\ORADATA\ORCL\REDO03.LOG
# 当前在线日志共有3组,为备库创建的日志建议比在线日志多一组,即4组
alter database add standby logfile group 4 ('/u01/app/oracle/oradata/orcl/sredo04.log') size 50m;
alter database add standby logfile group 5 ('/u01/app/oracle/oradata/orcl/sredo05.log') size 50m;
alter database add standby logfile group 6 ('/u01/app/oracle/oradata/orcl/sredo06.log') size 50m;
alter database add standby logfile group 7 ('/u01/app/oracle/oradata/orcl/sredo07.log') size 50m;
select * from v$logfile order by group#; #查询日志组
GROUP# STATUS TYPE MEMBER
---------- ------- ------- -----------------------------------------------------
1 ONLINE /u01/app/oracle/oradata/orcl/redo01.log
2 ONLINE /u01/app/oracle/oradata/orcl/redo02.log
3 ONLINE /u01/app/oracle/oradata/orcl/redo03.log
4 STANDBY /u01/app/oracle/oradata/orcl/sredo04.log
5 STANDBY /u01/app/oracle/oradata/orcl/sredo05.log
6 STANDBY /u01/app/oracle/oradata/orcl/sredo06.log
7 STANDBY /u01/app/oracle/oradata/orcl/sredo07.log
7 rows selected.
#设置db_unique_name
alter system set db_unique_name='primary' scope=spfile;
#设置日志归档配置,用于限制日志传输的目标,只能在这两个指定的数据库进行,该配置中的顺序可以调换
alter system set log_archive_config='DG_CONFIG=(primary,standby)' scope=spfile;
#设置日志归档路径1
alter system set log_archive_dest_1='location=/u01/app/oracle/orcl_arch VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=primary' scope=spfile;
#设置日志归档路径2
alter system set log_archive_dest_2='SERVICE=standby LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLES) DB_UNIQUE_NAME=standby' scope=spfile;
#启用归档路径1
alter system set log_archive_dest_state_1='enable' scope=spfile;
#启用归档路径2
alter system set log_archive_dest_state_2='enable' scope=spfile;
#设置当前库获取归档日志的服务器listerner名称(与8成对出现,用于switchover角色切换)
alter system set fal_server='standby' scope=spfile;
#设置当前库获取归档日志的客户端名称listerner名称(与7成对出现,用于switchover角色切换)
alter system set fal_client='primary' scope=spfile;
#设置归档日志强制切换时间(s)1800表示30分钟
alter system set archive_lag_target=1800 scope=spfile;
#设置归档日志文件名命名方式
alter system set log_archive_format='%t_%s_%r.arc'scope=spfile;
#设置备库文件管理的方式为auto,结合后续的convert参数,当主库增删文件时会自动在备库也生成相应文件。
alter system set standby_file_management=auto scope=spfile;
#设置数据文件名称的映射关系(注意顺序不能变)
alter system set db_file_name_convert='standby','primary' scope=spfile;
#设置日志文件名称的映射关系(注意顺序不能变)
alter system set log_file_name_convert='standby','primary' scope=spfile;
4.2、主库监听配置
# 修改监听文件/u01/app/oracle/product/19c/db_1/network/admin/listener.ora
# listener.ora Network Configuration File: /u01/app/oracle/product/19c/db_1/network/admin/listener.ora
# Generated by Oracle configuration tools.
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521)) #host为当前主机名
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)
#新增以下内容
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = CLRExtProc)
(ORACLE_HOME = /u01/app/oracle/product/19c/db_1)
(PROGRAM = extproc)
)
(SID_DESC =
(GLOBAL_DBNAME = orcl) #改为实例名
(ORACLE_HOME = /u01/app/oracle/product/19c/db_1)
(SID_NAME = orcl) #改为实例名
)
)
# 修改主库客户端配置文件/u01/app/oracle/product/19c/db_1/network/admin/tnsnames.ora
# tnsnames.ora Network Configuration File: /u01/app/oracle/product/19c/db_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
LISTENER_ORCL =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
# 新增内容
PRIMARY =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = orcldb)(PORT = 1521)) #HOST填写主库IP或者主机名
)
(CONNECT_DATA =
(SERVICE_NAME = orcl) #实例名
)
)
STANDBY =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = orcldg)(PORT = 1521)) #HOST填写备库IP或者主机名
)
(CONNECT_DATA =
(SERVICE_NAME = orcl) #实例名
)
)
五、集群安装及DG配置
5.1、安装前环境检查
# 环境检查
./runcluvfy.sh stage -pre crsinst -n rac01,rac02 -fixup -verbose
./runcluvfy.sh stage -pre crsinst -n rac01,rac02 -verbose
./runcluvfy.sh stage -post hwos -n rac01,rac02 -verbose
安装过程省略,安装集群过程中出现问题按照下边方式处理
# 执行过程中卡 Adding Clusterware entries to inittab
# 新建一个窗口执行以下命令
# 方案1
dd if=/var/tmp/.oracle/npohasd of=/dev/null bs=1024 count=1
# 方案2
chown root:oinstall/var/tmp/.oracle/npohasd
# 重新执行root.sh之前删除旧配置
/u01/app/11.2.0.4/grid/crs/install/roothas.pl -deconfig -force -verbose
5.2、监听配置
GRID 监听
# /u01/app/11.2.0.4/grid/network/admin/listener.ora 增加以下配置
SID_LIST_LISTENER=
(SID_LIST=
(SID_DESC=
(GLOBAL_DBNAME=rac01)
(ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1) #此处为oracle的ORACLE_HOME
(SID_NAME=orcl1)
)
)
# 重载监听
lsnrctl reload
Oracle Tnsnames
# /u01/app/oracle/product/11.2.0.4/db_1/network/admin/tnsnames.ora
PRIMARY =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = orcldb)(PORT = 1521))
)
(CONNECT_DATA =
(SERVER=DEDICATED)
(SERVICE_NAME = orcl)
)
)
STANDBY =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = rac01)(PORT = 1521))
)
(CONNECT_DATA =
(SERVER=DEDICATED)
(SERVICE_NAME = orcl)
)
)
5.3、数据复制
# oracle文件权限(谨慎使用)
chmod 6751 oracle
# 用户加组
usermod -aG 组名 用户名
# 移除组下的用户
gpasswd -d 用户名 组名
# 连接主库和辅助数据库
rman target sys/Xx961024@primary auxiliary sys/Xx961024@standby
# 执行此命令为不自动回复
duplicate target database for standby from active database nofilenamecheck;
# 执行首次同步,带自动恢复
duplicate target database for standby from active database dorecover nofilenamecheck;
# 应用日志同步
alter database recover managed standby database disconnect from session;
# 开启实时同步
alter database recover managed standby database using current logfile disconnect from session;
# 停止同步
alter database recover managed standby database cancel;
# 检查日志同步情况
select name,sequence#,applied, To_Char(a.COMPLETION_TIME, 'YYYY-MM-DD HH24:MI:SS') AS COMPLETETIME from v$archived_log a where a.COMPLETION_TIME>sysdate -3/24 order by sequence#;
select name,sequence#,applied, To_Char(a.COMPLETION_TIME, 'YYYY-MM-DD HH24:MI:SS') AS COMPLETETIME from v$archived_log a where a.COMPLETION_TIME>sysdate -1 order by sequence#;
select name,sequence#,applied, To_Char(a.COMPLETION_TIME, 'YYYY-MM-DD HH24:MI:SS') AS COMPLETETIME from v$archived_log a where APPLIED='YES' order by sequence#;
# 注册归档日志 rman
catalog start with 'path';
# 创建spfile
create spfile='+DATA/oradata/spfileorcl.ora' from pfile='/u01/app/oracle/product/11.2.0.4/db_1/dbs/initorcl.ora';
# 备份initorcl1.ora文件,重新创建
spfile='+RACDATA/spfileorcl.ora'
# 重启数据库验证spfile
# 注册CRS资源管理
srvctl add database -d orcl -n orcl -o /u01/app/oracle/product/11.2.0.4/db_1 -p +DATA/oradata/spfileorcl.ora -r physical_standby -a "DATA"
# 注册节点
srvctl add instance -d orcl -i orcl1 -n rac01
srvctl add instance -d orcl -i orcl2 -n rac02
# 检查资源配置
srvctl config database -d orcl
# 为rac02节点配置自己的UNDOTBS
# 主库操作
set pagesize 1000 linesize 1000
col FILE_NAME for a65;
select file_name,bytes/1024/1024 from dba_data_files;
# 在主库添加UNDOTBS2,RAC库同步(加完可以切一下日志)
create undo tablespace undotbs2 datafile '/u01/app/oracle/oradata/orcl/undotbs02.dbf' size 100m;
# 备库(rac)操作
# 检查UNDOTBS2是否已经同步过来
select file_name from dba_data_files;
# 将数据库转换为rac模式,注:千万不能漏,漏会报错只能把本地pfile恢复重新来
alter system set cluster_database=true scope=spfile;
alter system set cluster_database_instances=2 scope=spfile;
alter system set instance_number=1 scope=spfile sid='orcl1';
alter system set instance_number=2 scope=spfile sid='orcl2';
alter system set thread=1 scope=spfile sid='orcl1';
alter system set thread=2 scope=spfile sid='orcl2';
alter system set undo_tablespace=undotbs1 scope=spfile sid='orcl1';
alter system set undo_tablespace=undotbs2 scope=spfile sid='orcl2';
# 重启数据库(rac1节点)
# 主库处理日志组问题 === 见下一个项目
# 备库查询实例状态
select INSTANCE_NAME,STATUS,INSTANCE_ROLE,DATABASE_STATUS from gv$instance;
# 主库状态检查
select database_role,switchover_status from v$database;
# 将主库切换为备库
# 切换之前做一次 alter system switch logfile;
alter database commit to switchover to physical standby with session shutdown;
# 关闭备库
srvctl stop database -d orcl
# 将新备库启动到mount状态 grid 用户执行
srvctl start database -d orcl -o mount
# 将备库(rac)切换为主库
alter database commit to switchover to primary;
# 将新主库(rac)打开 grid 用户执行
srvctl start database -d orcl -o open;
主库为备库添加日志组
show parameter standby_file_management
# 先改为手动模式
alter system set standby_file_management=manual;
# 查询日志组信息
select a.group#,member,thread#,bytes/1024/1024 MB from v$logfile a, v$log b where a.group#=b.group#;
# 查询所有日志组
select * from v$logfile;
# 查询日志组使用情况
select group#,thread#,sequence#,members,status from v$log;
# 删除日志组
alter database disable thread 2;
alter database clear logfile group xx;
alter database drop logfile group xx;
alter database rename file '/u01/app/oracle/oradata/orcl/redo01.log' to '+DATA/oradata/orcl/redo01.log';
alter database rename file '/u01/app/oracle/oradata/orcl/redo02.log' to '+DATA/oradata/orcl/redo02.log';
alter database rename file '/u01/app/oracle/oradata/orcl/redo03.log' to '+DATA/oradata/orcl/redo03.log';
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
alter database add standby logfile thread 1 '/u01/app/oracle/oradata/orcl/sredo01.log' size 50m;
alter database add standby logfile thread 1 '/u01/app/oracle/oradata/orcl/sredo02.log' size 50m;
alter database add standby logfile thread 1 '/u01/app/oracle/oradata/orcl/sredo03.log' size 50m;
alter database add logfile thread 2 '/u01/app/oracle/oradata/orcl/redo04.log' size 50m;
alter database add logfile thread 2 '/u01/app/oracle/oradata/orcl/redo05.log' size 50m;
alter database add logfile thread 2 '/u01/app/oracle/oradata/orcl/redo06.log' size 50m;
alter database add standby logfile thread 2 '/u01/app/oracle/oradata/orcl/sredo04.log' size 50m;
alter database add standby logfile thread 2 '/u01/app/oracle/oradata/orcl/sredo05.log' size 50m;
alter database add standby logfile thread 2 '/u01/app/oracle/oradata/orcl/sredo06.log' size 50m;
alter database enable thread 2;
alter system set standby_file_management=auto;
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# 备库rac添加standby日志
alter database add logfile thread 1 '+DATA/oradata/orcl/redo01.log' size 50m;
alter database add logfile thread 1 '+DATA/oradata/orcl/redo02.log' size 50m;
alter database add logfile thread 1 '+DATA/oradata/orcl/redo03.log' size 50m;
alter database add standby logfile thread 1 '+DATA/oradata/orcl/sredo01.log' size 50m;
alter database add standby logfile thread 1 '+DATA/oradata/orcl/sredo02.log' size 50m;
alter database add standby logfile thread 1 '+DATA/oradata/orcl/sredo03.log' size 50m;
alter database add logfile thread 2 '+DATA/oradata/orcl/redo04.log' size 50m;
alter database add logfile thread 2 '+DATA/oradata/orcl/redo05.log' size 50m;
alter database add logfile thread 2 '+DATA/oradata/orcl/redo06.log' size 50m;
alter database add standby logfile thread 2 '+DATA/oradata/orcl/sredo04.log' size 50m;
alter database add standby logfile thread 2 '+DATA/oradata/orcl/sredo05.log' size 50m;
alter database add standby logfile thread 2 '+DATA/oradata/orcl/sredo06.log' size 50m;
alter system set standby_file_management=auto;
增加或删除新的scan IP在集群
# 先编辑/etc/hosts 文件-双节点-root用户
#scan ip
10.255.10.10 rac-scan
10.255.10.15 rac-scan
# 停止监听
srvctl stop scan_listener
# 停止scan
srvctl stop scan
# 查看状态
srvctl status scan_listener
# 修改scan信息,-n后面接 hosts中的san ip网络名
/u01/app/11.2.0.4/grid/bin/srvctl modify scan -n rac-scan
# 添加scanIP的监听,若不执行该命令,将只有一个listener_scan1监听,执行后将根据scan ip数自动增加listener_scan2,listener_scan3.
/u01/app/11.2.0.4/grid/bin/srvctl modify scan_listener -u
# 启动scan
srvctl start scan
# 启动监听
srvctl start scan_listener
# 查看状态
srvctl status scan
闪回的使用
# 查询闪回状态
select flashback_on from v$database;
# 取消备库的自动恢复
alter database recover managed standby database cancel;
# mount模式下打开闪回
alter system set db_recovery_dest_size=5g;
alter system set db_recovery_file_dest='+DATA';
alter database flashback on;
# 创建还原点
create restore point test_sw;
# 在主库归档当前日志,确保前一步创建还原点的scn的归档日志已经传到备库
alter system archive log current;
# 将主库到备库的归档目的地状态设置为defer
alter system set log_archive_dest_state_2=defer;
select dest_name,error, status from gv$archive_dest;
# 查询闪回scn
select current_scn from v$database;
# 激活备库到read/write状态
alter database activate standby database;
shutdown immediate;
startup;
select open_mode from v$database;
# 将数据库flashback回原来保存的还原点
startup mount force;
flashback database to restore point test_sw;
# 转换成备库
alter database convert to physical standby;
# 将备库至于自动恢复状态
startup mount force;
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT;
# 将主库到备库的归档目的地状设置为enable
alter system set log_archive_dest_state_2=enable;
# 检查同步情况
set linesize 150;
set pagesize 20;
column name format a13;
column value format a20;
column unit format a30;
column TIME_COMPUTED format a30;
select name,value,unit,time_computed from v$dataguard_stats where name in ('transport lag','apply lag');
修改Ip
# 备份hosts文件
cp /etc/hosts /etc/hosts_bak
# 停止集群
srvctl stop database -d orcl
# 停止CRS 所有节点root执行
/u01/app/11.2.0.4/grid/bin/crsctl stop crs -f
# 修改hosts文件
# 启动CRS 所有节点root执行
/u01/app/11.2.0.4/grid/bin/crsctl start crs
# 检查状态
/u01/app/11.2.0.4/grid/bin/crsctl check cluster -all
评论 (0)