博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
bay——安装_Oracle 12C-单实例-Centos7 -DG.txt
阅读量:5371 次
发布时间:2019-06-15

本文共 14503 字,大约阅读时间需要 48 分钟。

 

用户和密码:

root/bayaim

bayaim/064286BAIbay
oracle/oracle
SID:orcl
sys/oracle
system/oracle
mpay/mpay
dx/dx

---------------------------------------------

linux #安装环境
export LANG=en_US
systemctl stop firewalld.service (停止防火墙,这是CentOS7的命令)
systemctl restart network //重启网卡-----------

vi /etc/yum.repos.d/rhel-source.repo

mount /dev/cdrom /mnt

 

cd /etc/sysconfig/network-scripts

[root@wwdb2 network-scripts]# cp ifcfg-eth0 ifcfg-eth0.bak

[root@wwdb2 network-scripts]# vi ifcfg-eth0.bak

把 HWADDR 删除掉,然后改一下 IPADDR

HWADDR=78:2B:CB:4A:15:93

[root@wwdb2 network-scripts]# mv ifcfg-eth0.bak ifcfg-eth0

mv: overwrite `ifcfg-eth0'? y
[root@wwdb2 network-scripts]# service network restart

[root@wwdb2 ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 78:2B:CB:4A:15:93
inet addr:10.10.10.14 Bcast:10.10.10.255 Mask:255.255.255.0
inet6 addr: fe80::7a2b:cbff:fe4a:1593/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:397 errors:0 dropped:0 overruns:0 frame:0
TX packets:223 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:50334 (49.1 KiB) TX bytes:28565 (27.8 KiB)
Interrupt:114 Memory:d6000000-d6012800

lo Link encap:Local Loopback

inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:572939 errors:0 dropped:0 overruns:0 frame:0
TX packets:572939 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:215517488 (205.5 MiB) TX bytes:215517488 (205.5 MiB)

-----------------------------------------------------------

[root@localhost bai]# vi /etc/hosts
添加:
10.20.100.21 bay214
10.20.100.22 bay224

[root@wwdb2 ~]# vi /etc/sysconfig/network

NETWORKING=yes

NETWORKING_IPV6=no
HOSTNAME=wwdb2

[root@localhost bai]# hostname prodb

[root@localhost bai]# hostname
prodb

[root@localhost bai]# cat /etc/hostname

pordb

[root@localhost network-scripts]# cd /etc/sysconfig/network-scripts

[root@localhost network-scripts]# cp ifcfg-bond-bond0 ifcfg-bond-bond0.bak
[root@localhost network-scripts]# cat /etc/resolv.conf
# Generated by NetworkManager
nameserver 114.114.114.114

----------------------------------------------------------------

>>>bayaim10.0------配置oracle:>>>>>>>>

配合主库:

sqlplus / as sysdba

select log_mode,force_logging from v$database;
如果是非归档就要关闭数据库修改
shutdown immediate
startup mount
干净地关闭数据库再启动到mount状态
alter database archivelog;
alter database force logging;
select log_mode,force_logging from v$database;
archive log list

更改归档目录

!
mkdir /u01/oradata/prod/archivelog
ls -l /u01/oradata/prod

exit

alter system set log_archive_dest_1='location=/u01/oradata/prod/archivelog';
archive log list
alter database open;

>>>bayaim10.0------配置oracle:>>>>>>>>

1.0 创建pfile
create pfile from spfile;

[oracle@pordb ~]$ cd $ORACLE_HOME\dbs

[oracle@pordb dbs]$ pwd
/u01/app/oracle/11g/dbs

SQL> alter database create standby controlfile as '/u01/app/oracle/product/11.2.0/db_1/dbs/prodb.ctl';

[oracle@localhost ~]$orapwd file=$ORACLE_HOME/dbs/orapwprodb password=oracle entries=3

应用说明:

orapwd命令是用来创建口令文件的,所以需要明白什么时候需要这个口令文件,执行下列命令查看

-------------------------------------------------------------------------------------------

linux下查找某个文件位置的方法

find / -name tnsnames.ora

还可以用locate 来查找

locate tnsnames.ora

-------------------------------------------------------------------------------------------

把pfile文件、口令文件和备控制文件传输到standby
exit
cd /u01/app/oracle/11g/dbs
ls -lrt

scp orapwbay214 bay224:/u01/app/oracle/product/11.2.0/db_1/dbs

scp initbay214.ora bay224:/u01/app/oracle/product/11.2.0/db_1/dbs
scp prodb.ctl bay224:/u01/app/oracle/product/11.2.0/db_1/dbs

[oracle@pordb dbs]$ pwd

/u01/app/oracle/11g/dbs

[root@bay214 ~]# find / -name *control*.ctl

/u01/app/oracle/oradata/bay214/control01.ctl
/u01/app/oracle/fast_recovery_area/bay214/control02.ctl

[oracle@standby dbs]$ cp prodb.ctl /u01/app/oracle/oradata/bay214/control01.ctl
[oracle@standby dbs]$ mkdir -p /u01/app/oracle/fast_recovery_area/bay214
[oracle@standby dbs]$ cp prodb.ctl /u01/app/oracle/fast_recovery_area/bay214/control02.ctl

创建完后,数据库需要重启动,新的口令文件才能生效。

------------------------->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

发现问题:

在上面,由于在建 orapw 口令文件时,设定的 entries 值为2 ,故口令文件只能存放两条的记录,最后一条会被覆盖。
test 为最后面添加的,所以口令时存在的。
$strings orapwstudy
]\[Z
ORACLE Remote Password file
INTERNAL
D0EECC16A54101ED
B898A7F877F295DD
B0BE7F5D1FD7439A
TEST
7A0F2B316C212D67
F15C7D7DFC8C7D52

这是Linux重装或则openssh-server重装引起的,执行以下命令即可
ssh-keygen -R 10.10.10.14
把IP换成你要连的服务器就可以

操作:在执行scp命令的主机上执行:

vi ~/.ssh/known_hosts

删除IP为172.16.103.176 的行即可。

该现象在虚拟机删除之后重新建立的时候尤其明显,

要是因为原始主机已经存了一份了known_hosts了,需要更新。

 

 

[oracle@wwdb2 ~]$ env | grep ORA

[oracle@wwdb2 ~]$ vi .bash_profile
[oracle@wwdb2 ~]$ source .bash_profile

[oracle@standby dbs]$ mv orapwprodb orapwstandby
[oracle@standby dbs]$ mv initprodb.ora initstandby.ora
[oracle@standby dbs]$

#chown -R oracle:oinstall /oradata1
#chmod 775 /oradata1

[oracle@wwdb2 oradata1]$ mkdir standby

----------------------------------------------------------------------

把最上面几行去掉,然后把上面标注的prod都改成standby

注意db_name的prod值不要修改

[oracle@pordb prodb]$ pwd

/u01/app/oracle/oradata/prodb

mkdir -p /u01/app/oracle/oradata/bay214

mkdir -p /u01/app/oracle/fast_recovery_area
mkdir -p /u01/app/oracle/admin/bay214/adump
mkdir -p /u01/app/oracle/admin/bay214/cdump
mkdir -p /u01/app/oracle/admin/bay214/bdump
mkdir -p /u01/app/or-acle/admin/bay214/dpdump
mkdir -p /u01/app/oracle/admin/bay214/pfile
chown -R oracle:oinstall /u01/

cd /u01/app/oracle/product/11.2.0/db_1/dbs

vi initstandby.ora

添加如下参数:

*.db_unique_name='bay214'
*.db_file_name_convert='/u01/app/oracle/oradata/bay214','/u01/app/oracle/oradata/bay214'
*.log_file_name_convert='/u01/app/oracle/oradata/bay214','/u01/app/oracle/oradata/bay214'
*.log_archive_config='dg_config=(bay214,bay214)'
*.log_archive_dest_1='location=/u01/arch valid_for=(all_logfiles,all_roles) db_unique_name=bay214'
*.log_archive_dest_2='service=bay214 lgwr async valid_for=(online_logfiles,primary_role) db_unique_name=bay214'
*.log_archive_dest_state_1=enable
*.log_archive_dest_state_2=enable
*.log_archive_max_processes=10
*.fal_server=bay214
*.fal_client=bay214
*.standby_file_management=auto

====================================================================================
startup nomount 报错 原因是 initstandby.ora 里面 的版本号输入错误:

[oracle@wwdb2 ~]$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.1.0 - Production on Thu Oct 16 14:55:28 2014

Copyright (c) 182, 2005, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup nomount
ORA-00401: the value for parameter compatible is not supported by this release
SQL> startup nomount
ORACLE instance started.

Total System Global Area 3120562176 bytes

Fixed Size 2929256 bytes
Variable Size 855641496 bytes
Database Buffers 2248146944 bytes
Redo Buffers 13844480 bytes
SQL>

==================================================================================

TNS 报错 :原因是防火墙开着:
[oracle@wwdb1 admin]$ tnsping standby

最后发现是 主机A服务器防火墙已经关闭,而主机B上防火墙没有关闭进行如下操作

防火墙关闭后一切正常。

===============配置standby库的listener和静态服务名

>>>bayaim8.0------安装oracle:>>>>>>>>

#su - oracle

$source .bash_profile
$export DISPLAY=10.20.100.114:0.0
$export LANG=en_US
$xhost +
$xclock
$./runInstaller

netmgr

netca

tnsping prod
env | grep ORA
SQL> create spfile from pfile='?/dbs/initprodb.ora';
File created.
SQL> startup nomount

standby库的配置告一段落,重新回到prod库的配置

[oracle@bay224 admin]$ pwd

/u01/app/oracle/product/11.2.0/db_1/network/admin

=========================配置prod数据库======================

Used TNSNAMES adapter to resolve the alias

Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 10.10.10.13)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = fjflww)))
TNS-12543: TNS:destination host unreachable

报这个错,其实百度又开始瞎扯淡了。。。

[root@standby admin]# service iptables stop

Flushing firewall rules: [ OK ]
Setting chains to policy ACCEPT: filter [ OK ]
Unloading iptables modules: [ OK ]
[root@standby admin]# su - oracle
[oracle@standby ~]$

配置prod库参数
sqlplus / as sysdba

alter system set log_archive_config='dg_config=(bay214,bay214)';

alter system set log_archive_dest_1='location=/u01/arch valid_for=(all_logfiles,all_roles) db_unique_name=bay214';
alter system set log_archive_dest_2='service=bay224 lgwr async valid_for=(online_logfiles,primary_role) db_unique_name=bay214';
alter system set log_archive_dest_state_1=enable;
alter system set log_archive_dest_state_2=enable;
alter system set log_archive_max_processes=10;
alter system set fal_server=bay214;
alter system set fal_client=bay214;
alter system set standby_file_management=auto;

set pagesize 450

set linesize 440
show parameter log;
show parameter fal;

还有三需要重启才生效的参数也设置一下
alter system set db_unique_name='bay214' scope=spfile;
alter system set db_file_name_convert='/u01/app/oracle/oradata/bay214','/u01/app/oracle/oradata/bay214' scope=spfile;
alter system set log_file_name_convert='/u01/app/oracle/oradata/bay214','/u01/app/oracle/oradata/bay214' scope=spfile;
shutdown immediate

startup

-------------------------------------------------

备份prod库

[oracle@prod db]$ mkdir -p /bai/backupset

创建了备份目录

登陆到rman开始备份
rman target /

RMAN>

run
{
allocate channel d1 type disk ;
allocate channel d2 type disk ;
allocate channel d3 type disk ;
backup database format '/bai/backupset/%U';
release channel d1;
release channel d2;
release channel d3;
}

 

把备份集目录传输到standby的/u01目录下

exit
scp -r /bai/backupset/* standby:/bai/backupset/

可以在standby上检查一下

ls -l /u01

[oracle@prod backupset]$ scp -r /bai/backupset/* standby:/bai/backupset/

oracle@standby's password:
-----------------------------------------------------------------

开始克隆standby库,在prod上运行

[oracle@prod backupset]$ rman target / auxiliary sys/oracle@prodbdg

Recovery Manager: Release 11.2.0.1.0 - Production on Sun Nov 29 10:14:13 2015

Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.

connected to target database: FJFLWW (DBID=3823638492)

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-00554: initialization of internal recovery manager package failed
RMAN-04006: error from auxiliary database: ORA-01031: insufficient privileges

解决: 口令文件,错误导致

------------------------------------------------------------
开始克隆standby库,在prod上运行 [ 雷哥 ]
rman target / auxiliary sys/oracle@standby
duplicate target database for standby from active database Nofilenamecheck dorecover;

 

开始克隆standby库,在prodb上运行

rman target / auxiliary sys/bayaim@bay224

connected to target database: PRODB (DBID=2396898227)

connected to auxiliary database: PRODB (not mounted)

run
{
allocate auxiliary channel d1 type disk;
allocate auxiliary channel d2 type disk;
allocate auxiliary channel d3 type disk;
duplicate target database for standby nofilenamecheck;
release channel d1;
release channel d2;
release channel d3;
}

此时:standby 上:

SQL> select name from v$controlfile;

NAME

--------------------------------------------------------------------------------
/u01/app/oracle/oradata/bay214/control01.ctl
/u01/app/oracle/fast_recovery_area/bay214/control02.ctl

查询 standby 上是否目录齐全,否则无法建立controlfile

还原了standby库!

============================配置standby数据库==============================

查询standby库状态
select status from v$instance;

现在数据库为mount状态

创建备库的standby日志

alter database add standby logfile ('/u01/app/oracle/oradata/bay214/standby01.log') size 50m;

alter database add standby logfile ('/u01/app/oracle/oradata/bay214/standby02.log') size 50m;
alter database add standby logfile ('/u01/app/oracle/oradata/bay214/standby03.log') size 50m;

 

日志大小和主库的一样都是50M,数量比主库多一组

在prod库切换几个日志
exit
sqlplus / as sysdba
set linesize 300;
set pagesize 300;
show parameter dest_1;
alter system switch logfile;
/
/

在standby库查看一下是否有归档日志了
exit
ls -l /arch

在从库上执行:

日志可以传输了就ok!

备库执行日志应用同步语句,开始运行物理DG
sqlplus / as sysdba
alter database recover managed standby database using current logfile disconnect from session;

因为有备重做日志,所以可以加using current logfile语句,实现实时应用
select sequence#, applied from v$archived_log where applied='YES' order by sequence#;

yes说明日志同步了

SQL> create spfile from pfile;

----------------------------------------------------------->>>>>>>>>>>>>>>
验证:

在prod库上执行:

conn scott/tiger
create table t(i int);
insert into t values(1);
commit;
conn / as sysdba
alter system switch logfile;
在standby库上执行:
alter database recover managed standby database cancel;
alter database open;
conn scot/tiger
select * from t;

SQL> select table_name from user_tables;
SQL> select instance_name,status from v$instance;
SQL> alter database recover managed standby database using current logfile disconnect from session;
SQL> select open_mode from v$database;
OPEN_MODE
--------------------
READ ONLY WITH APPLY

数据已经同步,物理DG搭建成功!
----------------------------------------------------->>>>>>>>>>>>>>>>

此时standby :

看一下数据库的open状态
conn / as sysdba
select open_mode from v$database;

READ ONLY

此时prod :

READ WRITE

alter database recover managed standby database using current logfile disconnect from session;

select open_mode from v$database;

启动数据同步语句后,数据库又变为mounted状态

注意:在测试数据同步的时候请不要用sys用户,不然可能同步不了,这里测试都是用scott用户

SQL> SELECT MESSAGE FROM V$DATAGUARD_STATUS;

---------------------------------------------------------------------------

完整的一次启停:

SQL> shutdown immediate

Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.

Total System Global Area 839282688 bytes

Fixed Size 2217992 bytes
Variable Size 595593208 bytes
Database Buffers 239075328 bytes
Redo Buffers 2396160 bytes
Database mounted.
SQL> alter database open read only;

Database altered.

SQL> select instance_name,status from v$instance;

INSTANCE_NAME STATUS

---------------- ------------
standby OPEN

SQL> select open_mode from v$database;

OPEN_MODE

--------------------
READ ONLY

SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;

Database altered.

SQL> select open_mode from v$database;

OPEN_MODE

--------------------
READ ONLY WITH APPLY

SQL> alter database recover managed standby database cancel;

Database altered.

SQL> select open_mode from v$database;

OPEN_MODE

--------------------
READ ONLY

SQL> select instance_name,status from v$instance;

INSTANCE_NAME STATUS

---------------- ------------
standby OPEN

SQL> conn scott/tiger

Connected.
SQL> select * from t_5;

I

----------
21212
222
4442
5655

SQL>

====================================================================================

startup nomount 报错 原因是 initstandby.ora 里面 的版本号输入错误:

 

转载于:https://www.cnblogs.com/bayaim/p/11120122.html

你可能感兴趣的文章
UML第四次作业:绘制活动图
查看>>
GOOGLE API - 翻译, 后台c# 调用前台js代码, asp.net后台调用js代码
查看>>
JVM内存的设置
查看>>
HBase API 基础操作
查看>>
【洛谷4920】[WC2015] 未来程序(提答题)
查看>>
1003. Check If Word Is Valid After Substitutions
查看>>
PHP与最丑的后台管理系统
查看>>
1024 - 河南省多校连萌(三)
查看>>
iPhone各个设备的市场占有率
查看>>
实例解析Servlet运行原理
查看>>
截取图像 opencv
查看>>
两排按钮循环
查看>>
MD5加密
查看>>
bzoj4690: Never Wait for Weights
查看>>
Cracking the coding interview--Q1.3
查看>>
angular图片裁剪
查看>>
java-Enum
查看>>
【SQLSERVER】如何设置权限用户
查看>>
install ruby and ruby gem
查看>>
编写高质量代码改善C#程序的157个建议——建议77: 正确停止线程
查看>>