Oracle 19c单实例的ADG的搭建
一、环境的搭建
环境的基本信息:
类型 IP 主机名 ORACLE_HOME ORACLE_SID ORACLE_UNQNAME
主库 192.168.145.150 master /opt/oracle/product/19c/dbhome_1 itpuxdb itpuxdb
备库 192.168.145.151 slave /opt/oracle/product/19c/dbhome_1 itpuxdb itpuxdg
1.配置静态ip和配置yum源
配置网络源
rpm -qa|grep yum >oldyum.pkg 备份原信息
rpm -qa|grep yum|xargs rpm -e --nodeps 不检查依赖,直接删除rpm包
网易163网络源
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-3.4.3-168.el7.centos.noarch.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-langpacks-0.4.2-7.el7.noarch.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-rhn-plugin-2.0.1-10.el7.noarch.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-utils-1.1.31-54.el7_8.noarch.rpm
根据以来项安装
rpm -ivh yum-*
下载repo配置文件
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/centos/7/atomic/x86_64/repo/CentOS-Base.repo
将文件中所有的$releasever**更换为**7,否则无法使用。
sed -i 's/$releasever/7/g' /etc/yum.repos.d/CentOS-Base.repo
下载key文件
wget -O /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 http://mirrors.163.com/centos/7/os/x86_64/RPM-GPG-KEY-CentOS-7
清理yum缓存
yum -y clean all && yum -y makecache
配置静态ip
##配置Public IP
nmcli connection modify ens33 ipv4.addresses 192.168.145.150/24 ipv4.gateway 192.168.145.2 ipv4.method manual autoconnect yes
##生效
nmcli connection up ens33
nmcli connection show
vi /etc/sysconfig/network-scripts/ifcfg-ens33
添加下面的内容带该文件中
PEERDNS=no #使用指定DNS
DNS1=114.114.114.114 #国内运营商DNS
DNS2=8.8.8.8 #Google国外DNS
关闭selinux
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
setenforce 0
getenforce
关闭防火墙
使用root权限登录到Red Hat系统的终端。
停止当前运行的防火墙服务。可以使用以下命令:
systemctl stop firewalld
禁止防火墙服务在系统启动时自动启动。可以使用以下命令:
systemctl disable firewalld
确认防火墙服务已停止并禁用。可以使用以下命令验证:
systemctl status firewalld
如果输出显示 “inactive”,则表示防火墙服务已成功停止并禁用。
重新启动系统,以使更改生效。
2.下载静默的包:
二、主库和备库的搭建
1.主库的搭建
配置hosts
echo "192.168.145.150 master" >> /etc/hosts
echo "192.168.145.151 slave" >> /etc/hosts
配置目录
mkdir /opt/oracle
这个是配置目录,如果有的话就不用创建啦
准备预先安装的包
先把下载的包传到soft目录下
mkdir /soft
cd /soft
rpm -ivh oracle-database-preinstall-19c-1.0-1.el7.x86_64.rpm
注意:(这里会出现问题)
根据提示安装所需要的包:(如)
yum -y install compat-libcap1 ksh
yum -y install compat-libstdc++-33
yum -y install glibc-devel
yum -y install libaio-devel
yum -y install libstdc++-devel
修改密码:
passwd oracle
手工目录的授权
chown -R oracle:oinstall /opt/oracle
chmod -R 775 /opt/oracle
安装oracle-database-ee:
rpm -ivh oracle-database-ee-19c-1.0-1.x86_64.rpm
准备配置文件:
cd /etc/sysconfig
cp oracledb_0RCLCDB-19c.conf oracledb_itpuxdb-19c.conf
vi /etc/sysconfig/oracledb_itpuxdb-19c.conf
不要修改看一下
cd /etc/init.d
cp oracledb_ORCLCDB-19c oracledb_itpuxdb-19c
vi /etc/init.d/oracledb_itpuxdb-19c
下面是在vi里面执行
:%s/ORCLCDB/itpuxdb/g
:%s/ORCLPDB1/itpuxpdb/g
(为了全局替换)
然后在修改下面的内容:
创建数据库:
/etc/init.d/oracledb_itpuxdb-19c configure
检查环境:
su - oracle
ps -ef | grep smon
echo $ORACLE_HOME
lsnrctl status
测试停止、启动
/etc/init.d/oracledb itpuxdb-19c
Usage: /etc/init.d/oracledb_itpuxdb-19c {start|stoprestart|configure)
#/etc/init.d/oracledb_itpuxdb-19c stop
#/etc/init.d/oracledb_itpuxdb-19c start
环境变量配置
su - oracle
echo "export LANG=en_US" >>~/.bash_profile
echo "export ORACLE_BASE=/opt/oracle">>~/.bash_profile
echo "export ORACLE_HOME=/opt/oracle/product/19c/dbhome_1">> ~/.bash_profile
echo "export ORACLE_UNQNAME=itpuxdb">> ~/.bash_profile
echo "export ORACLE_SID=itpuxdb">>~/.bash_profile
echo "NLS_LANG=AMERICAN_AMERICA.ZHS16GBK;export NLS_LANG" >>~/.bash profile
echo "export PATH=$PATH:/opt/oracle/product/19c/dbhome_1/bin" >> ~/.bash_profile
source ~/.bash_profile
env | grep ORACLE
这样主库就搭建成功了。
2.备库的搭建
(前面一点都差不多,但是没有了准备配置文件:创建数据库)
配置hosts
echo "192.168.145.150 master" >> /etc/hosts
echo "192.168.145.151 slave" >> /etc/hosts
cat /etc/hosts
配置目录
mkdir /opt/oracle
这个是配置目录,如果有的话就不用创建啦
准备预先安装的包
先把下载的包传到soft目录下
mkdir /soft
rpm -ivh oracle-database-preinstall-19c-1.0-1.el7.x86 64.rpm
注意:(这里会出现问题)
根据提示安装所需要的包:(如)
yum -y install compat-libcap1 ksh
修改密码:
passwd oracle
手工目录的授权
chown -R oracle:oinstall /opt/oracle
chmod -R 775 /opt/oracle
安装oracle-database-ee:
rpm -ivh oracle-database-ee-19c-1.0-1.x86_64.rpm
检查环境:
su - oracle
ps -ef|grep smon
echo $ORACLE_HOME
lsnrctl status(这个会出错误没关系,下面会配好)
环境变量配置
su - oracle
echo "export LANG=en_US">>~/.bash_profile
echo "export ORACLE_BASE=/opt/oracle">>~/.bash_profile
echo "export ORACLE_HOME=/opt/oracle/product/19c/dbhome_1">> ~/.bash_profile
echo "export ORACLE_UNQNAME=itpuxdg">> ~/.bash_profile
echo "export ORACLE_SID=itpuxdg">>~/.bash_profile
echo "NLS_LANG=AMERICAN_AMERICA.ZHS16GBK;export NLS_LANG">>~/.bash_profile
echo "export PATH=$PATH:/opt/oracle/product/19c/dbhome_1/bin">> ~/.bash_profile
source ~/.bash_profile
env |grep ORACLE
备库的数据库环境装好了。
三、主备库的实施配置
准备备库监听配置
vi /opt/oracle/product/19c/dbhome_1/network/admin/listener.ora
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS =(PROTOCOL =TCP)(HOST =slave)(PORT = 1521))
(ADDRESS =(PROTOCOL=IPC)(KEY=EXTPROC1521))
)
)
SID_LIST_LISTENER=
(SID_LIST=
(SID_DESC=
(GLOBAL_DBNAME=itpuxdg)
(SID_NAME=itpuxdg)
(ORACLE_HOME=/opt/oracle/product/19c/dbhome_1)
)
)
:wq
然后检查监听是否配置成功
lsnrctl start
lsnrctl status
主库配置
1.打开强制日志
su - oracle
sqlplus "/as sysdba"
alter database force logging;
2.设置为归档模式
alter system set db_recovery_file_dest_size=5g;
alter system set db_recovery_file_dest='/opt/oracle';
startup mount;
alter database archivelog;
alter database open;
alter system switch logfile;
可以出去查看一下是否有归档文件
cd /opt/oracle/ITPUXDB/archivelog/
3.创建日志文件 如果主库有三个了(那就要创建四个)
select * from v$log;
select * from v$logfile;
alter database add standby logfile group 4 '/opt/oracle/oradata/ITPUXDB/stredo04.10g' size 200m;
alter database add standby logfile group 5 '/opt/oracle/oradata/ITPUXDB/stredo05.log' size 200m;
alter database add standby logfile group 6 '/opt/oracle/oradata/ITPUXDB/stredo06.log' size 200m;
alter database add standby logfile group 7 '/opt/oracle/oradata/ITPUXDB/stredo07.log' size 200m;
主备库监听tnsnames.ora:
vi /opt/oracle/product/19c/dbhome_1/network/admin/tnsnames.ora
ITPUXDB =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = master)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = itpuxdb)
)
)
ITPUXDG =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = slave)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = itpuxdg)
)
)
(主库只要加ITPUXDG,备库全加上)
测试
tnsping itpuxdb
tnsping itpuxdg
准备数据库密码文件
主库:
orapwd file='opt/oracle/product/19c/dbhome_1/dbs/orapwitpuxdb' password=ITPUX-123
备库:
cd /opt/oracle/product/19c/dbhome_1/dbs
scp 192.168.145.150:/opt/oracle/product/19c/dbhome_1/dbs/orapwitpuxdb
mv orapwitpuxdb orapwitpuxdg
登录
主库:
sqlplus "sys/ITPUX-123@itpuxdg as sysdba"
准备参数文件了
主库:
create pfile='/opt/oracle/pfile.ora' from spfile;
(等会有改参数,这个是备份一份,然后传到备库里面在改参数)
然后在把pfile传给备库
scp /opt/oracle/pfile.ora 192.168.145.151:/opt/oracle/
主库参数(重启生效):
alter system set db_unique_name='itpuxdb' scope=spfile;
alter system set LOG_ARCHIVE_CONFIG='DG_CONFIG=(itpuxdb,itpuxdg)' scope=both;
alter system set LOG_ARCHIVE_DEST_1='LOCATION=USE_DB_RECOVERY_FILE_DEST VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=itpuxdb' scope=both;
alter system set LOG_ARCHIVE_DEST_2='SERVICE=itpuxdg LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=itpuxdg' scope=both;
alter system set fal_client='itpuxdb' scope=both;
alter system set FAL_SERVER='itpuxdg' scope=both;
alter system set DB_FILE_NAME_CONVERT='ITPUXDG','ITPUXDB' scope=spfile;
alter system set LOG_FILE_NAME_CONVERT='ITPUXDG','ITPUXDB' scope=spfile;
alter system set standby_file_management=AUTO scope=both;
#重启生效:
shutdown immediate
startup
备库参数:
cd /opt/oracle
vi pfile.ora
#先把"*."前面的都删了,把itpuxdb改成itpuxdg,在添加下面的。
db_unique_name='itpuxdg'
LOG_ARCHIVE_CONFIG='DG_CONFIG=(itpuxdg,itpuxdb)'
LOG_ARCHIVE_DEST_1='LOCATION=USE_DB_RECOVERY_FILE_DEST VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=itpuxdg'
LOG_ARCHIVE_DEST_2='SERVICE=itpuxdb LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=itpuxdb' fal_client='itpuxdg'
FAL_SERVER='itpuxdb'
DB_FILE_NAME_CONVERT='ITPUXDB','ITPUXDG'
LOG_FILE_NAME_CONVERT='ITPUXDB','ITPUXDG'
standby_file_management=AUTO
备库备库创建需要的目录:
mkdir -p /opt/oracle/admin/itpuxdg/adump
mkdir -p /opt/oracle/oradata/ITPUXDG
启动到nomunt(备库);
sqlplus "sys/ITPUX-123@itpuxdg as sysdba"
startup pfile='/opt/oracle/pfile.ora' nomount;
create spfile from pfile='/opt/oracle/pfile.ora';
shutdown immediate;
startup nomount;
打开时如果出现了
ORA-00845: MEMORY_TARGET not supported on this system
那就是 memory_target大于了/dev/shm,重新调整数据库参数MEMORY_TARGET的大小,要下于/dev/shm的大小
查看/dev/shm的大小
df -h | grep shm
创建dataguard数据库(主库备库都可以)
rman target sys/ITPUX-123@itpuxdb auxiliary sys/ITPUX-123@itpuxdg
duplicate target database for standby from active database;
四、检查测试:
查看dataguard状态:
select NAME,OPEN_MODE,PROTECTION_MODE,DATABASE_ROLE,SWITCHOVER_STATUS from v$database;
启动dataguard数据同步:
sqlplus "/as sysdba"
alter database recover managed standby database disconnect from session; 开启同步
关闭dataguard数据同步:
alter database recover managed standby database cancel;
以上步骤知识了解,不要执行,从下开始再执行。
启动adg模式的备库:
上述备库的数据库是nomount状态,再执行完rman后
alter database open;
alter database recover managed standby database disconnect from session;
主库测试:
alter system switch logfile;
主备库检查dataguard状态:
select NAME,OPEN_MODE,PROTECTION_MODE,DATABASE_ROLE,SWITCHOVER_STATUS from v$database;
dataguard数据同步测试
主库:
create tablespace jiale66 datafile '/opt/oracle/oradata/ITPUXDB/jiale66.dbf' size 10m autoextend off;
create user Jiale identified by Jiale66 default tablespace jiale66;
grant dba to jiale66;
conn jiale66/jiale66;
create table jiale66.itpux01(c1 varchar2(10),c2 number);
insert into itpux01 values('itpux01','1');
insert into itpux01 values('itpux02','2');
commit;
select * from jiale66.itpux01;
alter system switch logfile;
备库检查:
select * from jiale66.itpux01;
查看dataguard状态:
select NAME,OPEN_MODE,PROTECTION_MODE,DATABASE_ROLE,SWITCHOVER_STATUS from v$database;
检查dataguard日志
tail -100f /opt/oracle/diag/rdbms/itpuxdb/itpuxdb/trace/alert_itpuxdb.log
tail -100f /opt/oracle/diag/rdbms/itpuxdg/itpuxdg/trace/alert_itpuxdg.log
iale66/jiale66;
create table jiale66.itpux01(c1 varchar2(10),c2 number);
insert into itpux01 values(‘itpux01’,‘1’);
insert into itpux01 values(‘itpux02’,‘2’);
commit;
select * from jiale66.itpux01;
alter system switch logfile;
备库检查:
select * from jiale66.itpux01;
查看dataguard状态:
select NAME,OPEN_MODE,PROTECTION_MODE,DATABASE_ROLE,SWITCHOVER_STATUS from v$database;
检查dataguard日志
tail -100f /opt/oracle/diag/rdbms/itpuxdb/itpuxdb/trace/alert_itpuxdb.log
tail -100f /opt/oracle/diag/rdbms/itpuxdg/itpuxdg/trace/alert_itpuxdg.log