Oracle主备安装构建保障高可用的体系(oracle 主备安装)

作为数据库管理员,我们需要确保业务系统在面临任何灾难(如服务器故障、网络中断等)时都能够快速地响应,不受影响。因此,构建高可用性(HA)体系已成为数据库管理的重要任务之一。Oracle数据库通过主备(或称为主从)模式来实现高可用性,本文将介绍Oracle主备安装的过程。

1. 搭建环境

在进行Oracle主备安装前,首先需要搭建好系统环境。本文以CentOS 7为例,安装好系统后需要进行以下配置:

(1)关闭防火墙

$ systemctl stop firewalld.service

$ systemctl disable firewalld.service

(2)关闭SELinux:

$ setenforce 0

$ sed -i ‘s/^SELINUX=.*/SELINUX=disabled/’ /etc/selinux/config

(3)配置主机名:

$ hostnamectl set-hostname oracle-primary

(4)安装必要的软件包:

$ yum install -y bc binutils compat-libcap1 compat-libstdc++-33 gcc gcc-c++ glibc glibc-devel ksh libo libo-devel libstdc++ libstdc++-devel make sysstat

2. 安装Oracle数据库

在搭建好环境后,我们可以开始安装Oracle数据库。Oracle提供了官方的安装向导,可以帮助我们完成安装过程。具体步骤如下:

(1)下载安装包(这里以Oracle Database 19c为例),并将其解压到指定目录:

$ unzip linuxx64_193000_db_home.zip -d /opt/oracle/product/19c/dbhome_1

$ chown -R oracle:oinstall /opt/oracle

(2)创建新用户并设置密码:

$ useradd -m -s /bin/bash oracle

$ passwd oracle

(3)在oracle用户下启动安装向导:

$ su – oracle

$ /opt/oracle/product/19c/dbhome_1/runInstaller

(4)根据向导提示完成安装。

安装完成后,我们需要创建一个新的Oracle数据库实例。在本文的主备模式中,我们可以将主机上的数据库实例作为主实例,在备机上复制该数据库实例并作为备实例。因此,在主机上创建数据库实例是必须的。

3. 配置主备模式

在主机上创建好数据库实例后,我们需要对其进行配置,以使其能够支持主备模式。具体步骤如下:

(1)创建备机所需的参数文件,并根据需要进行修改:

$ cd $ORACLE_HOME/dbs

$ cp init.ora standby_init.ora

$ vi standby_init.ora

(2)修改参数文件监听地址:

$ vi listener.ora

# 修改为本机IP地址

LISTENER =

(DESCRIPTION_LIST =

(DESCRIPTION =

(ADDRESS_LIST =

(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.100)(PORT = 1521))

)

)

)

# 修改为本机主机名和IP地址

SID_LIST_LISTENER =

(SID_LIST =

(SID_DESC =

(GLOBAL_DBNAME = orcl)

(SID_NAME = orcl)

(ORACLE_HOME = /opt/oracle/product/19c/dbhome_1)

)

)

(3)在主机上启动监听程序:

$ lsnrctl start

(4)创建并启动归档进程:

$ sqlplus / as sysdba

SQL> alter system set log_archive_dest_1=’LOCATION=/opt/oracle/archivelog/ VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=orcl’ scope=spfile;

SQL> shutdown immediate;

SQL> startup mount;

SQL> alter database archivelog;

SQL> alter database open;

(5)配置日志传输服务:

$ sqlplus / as sysdba

SQL> alter system set log_archive_dest_2=’SERVICE=orcl ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=orcl’ scope=spfile;

SQL> alter system set log_archive_config=’DG_CONFIG=(orcl,orcl_dg)’ scope=spfile;

SQL> alter system set fal_server=standby_db unique name=’orcl’ scope=spfile;

SQL> alter system set standby_file_management=auto scope=spfile;

SQL> alter system set remote_login_passwordfile=exclusive scope=spfile;

(6)在备机上创建数据库实例:

$ mkdir /opt/oracle/diag/rdbms/orcl

$ mkdir /opt/oracle/diag/rdbms/orcl/orcl_dg

$ cp $ORACLE_HOME/dbs/standby_init.ora $ORACLE_HOME/dbs/init.ora

$ vi $ORACLE_HOME/dbs/init.ora

# 修改为备机主机名和IP地址

orcl.__db_cache_size=4294967296

orcl.__java_pool_size=16777216

orcl.__large_pool_size=16777216

orcl.__oracle_base=’/opt/oracle’#ORACLE_BASE set from environment

orcl.__pga_aggregate_target=8589934592

orcl.__sga_target=19327352832

orcl.__shared_io_pool_size=0

orcl.__shared_pool_size=5153960755

orcl.__streams_pool_size=0

*.audit_file_dest=’/opt/oracle/admin/orcl/adump’

*.audit_trl=’db’

*.compatible=’19.0.0′

*.control_files=’/opt/oracle/oradata/orcl/control01.ctl’,’/opt/oracle/FRA/orcl/control02.ctl’

*.db_block_size=8192

*.db_domn=”

*.db_name=’orcl’

*.db_recovery_file_dest=’/opt/oracle/FRA’

*.db_recovery_file_dest_size=3758096384

*.db_unique_name=’orcl’

*.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)’

*.fal_client=’orcl’

*.fal_server=’orcl’

*.local_listener=’LISTENER_ORCL’

*.log_archive_dest_1=’LOCATION=/opt/oracle/archivelog’

*.log_archive_dest_2=’SERVICE=orcl ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=orcl_dg’

*.log_archive_format=’%t_%s_%r.arc’

*.memory_target=32210157568

*.open_cursors=2000

*.pga_aggregate_target=8G

*.processes=2000

*.remote_login_passwordfile=’EXCLUSIVE’

*.sga_max_size=22G

*.sga_target=20G

*.standby_log_files=0

*.undo_tablespace=’UNDOTBS1′

# 修改为主机IP地址

ORCL =

(DESCRIPTION =

(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.100)(PORT = 1521))

(CONNECT_DATA =

(SERVER = DEDICATED)

(SERVICE_NAME = orcl)

(UR = A)

)

)

# 修改为备机主机名和IP地址

orcl_dg =

(DESCRIPTION =

(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.101)(PORT = 1521))

(CONNECT_DATA =

(SERVER = DEDICATED)

(SERVICE_NAME = orcl)

(UR = A)

)

)

$ sqlplus / as sysdba

SQL> startup nomount;

(7)在主机上执行备机配置脚本:

$ su – oracle

$ /opt/oracle/product/19c/dbhome_1/bin/dgmgrl -sysdba

DGMGRL> connect sys/oracle@orcl

DGMGRL> CREATE CONFIGURATION ‘orcl_dg_config’ AS PRIMARY DATABASE IS ‘orcl’ CONNECT IDENTIFIER IS ORCL;

DGMGRL> ADD DATABASE ‘orcl_dg’ AS CONNECT IDENTIFIER IS orcl_dg MNTNED AS LOGICAL;

DGMGRL> SHOW CONFIGURATION;

DGMGRL> EXIT;

(8)在备机上执行主机配置脚本:

$ su – oracle

$ /opt/oracle/product/19c/dbhome_1/bin/dgmgrl -sysdba

DGMGRL> connect sys/oracle@orcl_dg

DGMGRL> CREATE CONFIGURATION ‘orcl_dg_config’ AS PRIMARY DATABASE IS ‘orcl_dg’ CONNECT IDENTIFIER IS ORCL_DG;

DGMGRL> ADD DATABASE ‘orcl’ AS CONNECT IDENTIFIER IS orcl MNTNED AS LOGICAL;

DGMGRL> SHOW CONFIGURATION;

DGMGRL> EXIT;

(9)在主机上启动日志传输:

SQL> ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE_2=ENABLE scope=both sid=’*’;

SQL> ALTER SYSTEM SET LOG_ARCHIVE_DEST_2=’SERVICE=orcl_dg

版权声明:本文采用知识共享 署名4.0国际许可协议 [BY-NC-SA] 进行授权
文章名称:《Oracle主备安装构建保障高可用的体系(oracle 主备安装)》
文章链接:https://zhuji.vsping.com/191449.html
本站资源仅供个人学习交流,请于下载后24小时内删除,不允许用于商业用途,否则法律问题自行承担。