1.架构规划:
节点 | IP地址 | hostname |
primary | 10.2.83.141 | node3 |
standby | 10.2.83.112 | dg |
2.主库安装
1)基础环境优化
**关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
**关闭selinux
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config grep SELINUX=disabled /etc/selinux/config
setenforce 0
**修改/etc/host解析
10.2.83.141 node3
10.2.83.112 dg
2)创建运行oracle用户和用户组
groupadd oinstall
groupadd dba
useradd -g oinstall -G dba oracle
3)创建相关的目录
#创建必须目录:
#ORACLE_BASE:存放各类日志
mkdir -p /u01/app/oracle
#ORACLE_HOME:存放程序的目录
mkdir -p /u01/app/oracle/product/11.2.0/db_1
#oracle存储数据的盘
mkdir /oradata
#更改权限:
chown -R oracle:oinstall /u01/
chmod -R 775 /u01/
chown -R oracle:oinstall /oradata
4)修改内核参数
vim /etc/sysctl.conf
fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 2097152
kernel.shmmax = 536870912
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
5)修改系统限制
vim /etc/security/limits.conf
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
6)修改认证
vim /etc/pam.d/login
session required pam_limits.so
7)修改profile
if [ $USER = "oracle" ]; then
if [ $SHELL = "/bin/ksh" ]; then
ulimit -p 16384
ulimit -n 65536
else
ulimit -u 16384 -n 65536
fi
fi
8)更改环境变量
su - oracle
vim .bash_profile
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1
export ORACLE_SID=orcl
export PATH=$ORACLE_HOME/bin:$PATH
LD_LIBRARY_PATH=$ORACLE_HOME/lib64
# User specific environment and startup programs
export PATH=$PATH:$ORACLE_HOME/.local/bin:$ORACLE_HOME/bin
export TNS_ADMIN=$ORACLE_HOME/db_1/instantclient
source .bash_profile
9)软件包上传至/usr/local/,并解压
修改安装包权限
chown -R oracle:oinstall ./database
10)安装相关的依赖
采用yum安装,如下:
yum install -y binutils*
yum install -y compat-libstdc*
yum install -y elfutils-libelf*
yum install -y gcc*
yum install -y glibc*
yum install -y ksh*
yum install -y libaio*
yum install -y libgcc*
yum install -y libstdc*
yum install -y make*
yum install -y sysstat*
yum install libXp* -y
yum install -y glibc-kernheaders
yum install binutils-*
yum install compat-libstdc++-*
yum install elfutils-libelf-*
yum install elfutils-libelf-devel-*
yum install elfutils-libelf-devel-static-*
yum install gcc-*
yum install gcc-c++-*
yum install glibc-*
yum install glibc-common-*
yum install glibc-devel-*
yum install glibc-headers-*
yum install kernel-headers-*
yum install ksh-*
yum install libaio-*
yum install libaio-devel-*
yum install libgcc-*
yum install libgomp-*
yum install libstdc++-*
yum install libstdc++-devel-*
yum install make-*
yum install sysstat-*
yum install unixODBC-*
yum install unixODBC-devel-*
11)图形化安装oracle需要用vnc来安装
首先在liunx服务器上安装oracle的客户端
下载客户端
yum install tigervnc-server tigervnc-server-module -y
yum -y groupinstall GNOME Desktop
配置vnc的配置文件:
vim /etc/sysconfig/vncservers
VNCSERVERS="1:root 2:oracle"
VNCSERVERARGS[1]="-geometry 800x600 -nolisten tcp"
VNCSERVERARGS[2]="-geometry 800x600 -nolisten tcp
su - oracle
vncserver :2 ###启动vnc
登陆vnc开始安装oracle
登陆注意:ip::端口
12)安装
cd /usr/local/database
执行: ./runInstaller -jreLoc /usr/lib/jvm/jre-1.8.0 (11g的在centos7 安装需要设置java参数)
如果没有这个jre ,可以yum install -y java
注意这里如果没有这个目录需要手动安装,否则会夯住无法继续安装
mkdir /u01/app/oraInventory
这里的失败项目要实际看看安装包,如果有版本比较高的可以忽略错误,否则一定要安装好,要不后面有坑。
此处报错解决,大概在84%安装进度的时候有报错:
解决:
oracle用户修改
vim /u01/app/oracle/product/11.2.0/db_1/ctx/lib/ins_ctx.mk
11行修改为:
ctxhx: $(CTXHXOBJ)
static $(LINK_CTXHX) $(CTXHXOBJ) $(INSO_LINK) /usr/lib64/stdc.a
修改完点continue,继续安装,又会报错
解决:
大概在190行修改为如下:
$(SYSMANBIN)emdctl:
$(MK_EMAGENT_NMECTL) -lnnz11
点击continue
大概在94%进度有这个提示:
用root执行:一直执行
sh /u01/app/oraInventory/orainstRoot.sh
sh /u01/app/oracle/product/11.2.0/db_1/root.sh
至此安装完毕。
注意:
11.2.0.1.0 安装需要修改,因为这个版本有bug
[oracle@dg ~]$ vi /etc/oraInst.loc
inventory_loc=/u01/app/oraInventory
inst_group=oinstall
-rw-rw-r--. 1 root root 56 Dec 2 15:17 /etc/oraInst.loc
12).DBCA 建库
13)netmgr配置网络
配置tns
至此主库安装完毕,开始安装从库,安装方法同主库,说一下和主库安装的不同点
①、从库无需建库
②、修改从库的.bash_profile
[oracle@dg ~]$ vim .bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/.local/bin:$HOME/bin
export PATH
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1
export ORACLE_SID=dg //修改为不同的sid
export PATH=$ORACLE_HOME/bin:$PATH
LD_LIBRARY_PATH=$ORACLE_HOME/lib64
# User specific environment and startup programs
export PATH=$PATH:$ORACLE_HOME/.local/bin:$ORACLE_HOME/bin
export TNS_ADMIN=$ORACLE_HOME/db_1/instantclient
③、从库配置网络同主库,也可以从主库复制
从库启动监听
lsnrctl start
至此主备库搭建完毕,下面开始构建DG架构
3.DG搭建
***********主库************
1)确认主库是否开启归档
SQL> archive log list;
Database log mode No Archive Mode
Automatic archival Disabled (未开启)
Archive destination /u01/app/oracle/product/11.2.0/db_1/dbs/arch
Oldest online log sequence 3
Current log sequence 5
关闭数据库
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
启动到mount状态
SQL> startup mount;
ORACLE instance started.
Total System Global Area 1603411968 bytes
Fixed Size 2213776 bytes
Variable Size 402655344 bytes
Database Buffers 1191182336 bytes
Redo Buffers 7360512 bytes
Database mounted.
开启归档
SQL> alter database archivelog;
Database altered.
SQL> alter database force logging;
open数据库
SQL> alter database open;
Database altered.
再次查询
SQL> select log_mode,force_logging from v$database;
LOG_MODE FOR
------------ ---
ARCHIVELOG YES (已经开启)
改变归档日志路径:
SQL> !mkdir /u01/app/oracle/oradata/oracle01/archivelog -p
SQL> !ls /u01/app/oracle/oradata/oracle01/
archivelog
SQL> alter system set log_archive_dest_1='location=/u01/app/oracle/oradata/oracle01/archivelog';
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /u01/app/oracle/oradata/oracle01/archivelog (已经更改)
Oldest online log sequence 3
Next log sequence to archive 5
Current log sequence 5
2)设置数据库闪回
确认数据库是否开启闪回
SQL> select flashback_on from v$database;
FLASHBACK_ON
------------------
NO 为YES才是开启,这种表示没有开启
设置闪回大小
SQL> alter system set db_recovery_file_dest='/u01/app/oracle';
System altered.
设置闪回路径
SQL> alter system set db_recovery_file_dest='/u01/app/oracle';
System altered.
关闭数据库
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
mount启动
SQL> startup mount
ORACLE instance started.
Total System Global Area 1603411968 bytes
Fixed Size 2213776 bytes
Variable Size 402655344 bytes
Database Buffers 1191182336 bytes
Redo Buffers 7360512 bytes
Database mounted.
开启闪回
SQL> alter database flashback on;
Database altered.
再次确认是否开启
SQL> select flashback_on from v$database;
FLASHBACK_ON
------------------
YES