重庆思庄Oracle、Redhat认证学习论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1340|回复: 0
打印 上一主题 下一主题

[Oracle] 主备切换及IP互换

[复制链接]
跳转到指定楼层
楼主
发表于 2023-1-3 17:53:39 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
实验课题:主备切换及IP互换.
应用场景:当服务器系统版本配置跟不上业务需求,此时就需要给该库搭建配置较高的备库,然后主备切换再进行IP互换,使得客户端访问新主库时不修改任何参数.这种需求在实际生产中是常有的.
1、原始数据
主库IP192.168.133.150(需改为192.168.133.151)
备库IP192.168.133.151(需改为192.168.133.150)
[oracle@oel~]$ cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4localhost4.localdomain4
::1         localhost localhost.localdomainlocalhost6 localhost6.localdomain6
192.168.133.150oel
[oracle@oeldg~]$ cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4localhost4.localdomain4
::1         localhost localhost.localdomainlocalhost6 localhost6.localdomain6
192.168.133.151oeldg
主库
SQL>show parameter convert
NAME                                 TYPE        VALUE
----------------------------------------------- ------------------------------
db_file_name_convert                 string
log_file_name_convert                string
备库
SQL>show parameter convert
NAME                                 TYPE        VALUE
----------------------------------------------- ------------------------------
db_file_name_convert                 string          /u01/app/oracle/oradata/orcl15
                                                                        0/, /u01/app/oracle/oradata/or
                                                                       cl151/
log_file_name_convert                string          /u01/app/oracle/oradata/orcl15
                                                                        0/, /u01/app/oracle/oradata/or
                                                                       cl151/, /u01/app/oracle/fast_r
                                                                       ecovery_area/orcl150/,/u01/ap
                                                                       p/oracle/fast_recovery_area/or
                                                                       cl151/
2convert参数
因后续涉及switchover切换,先在主库设置convert参数.
SQL>alter system set db_file_name_convert='/u01/app/oracle/oradata/orcl151/','/u01/app/oracle/oradata/orcl150/'scope=spfile;
SQL>alter system set log_file_name_convert='/u01/app/oracle/fast_recovery_area/orcl151/','/u01/app/oracle/fast_recovery_area/orcl150/','/u01/app/oracle/oradata/orcl151/','/u01/app/oracle/oradata/orcl150/'scope=spfile;
SQL>shutdown immediate
SQL>startup
3switchover切换
主切备
SQL>alter database commit to switchover to physical standby with session shutdown;
SQL>shutdown abort
SQL>startup mount
备切主
SQL>alter database commit to switchover to primary with session shutdown;
SQL>alter database open;
4、生成pfile
主备库生成pfile文件,以便后续修改.
5IP互换
说明:IP互换前,主备库停数据库、监听.
5.1、新主库IP修改
[root@oeldg~]# vi /etc/sysconfig/network-scripts/ifcfg-ens33
……
IPADDR=192.168.133.150
……
说明:将IPADDR=192.168.133.151修改为IPADDR=192.168.133.150
5.2、新备库IP修改
[root@oel~]# vi /etc/sysconfig/network-scripts/ifcfg-ens33
……
IPADDR=192.168.133.151
……
IPADDR=192.168.133.150修改为IPADDR=192.168.133.151
5.3、重启网卡
说明:主备库重启网卡.
[root@oeldg~]# systemctl restart network.service
Connectionwas reset.
注意:此时需要用修改后的IP重新连接服务器,主机oeldg对应的192.168.133.151此时变成192.168.133.150去连接.
6、修改hosts
使用新IP登陆主备库,修改/etc/hosts文件
6.1、新主库
[root@oeldg~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4localhost4.localdomain4
::1         localhost localhost.localdomainlocalhost6 localhost6.localdomain6
192.168.133.150oeldg
192.168.133.151修改为192.168.133.150
6.2、新备库
[root@oel~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4localhost4.localdomain4
::1         localhost localhost.localdomainlocalhost6 localhost6.localdomain6
192.168.133.151oel
192.168.133.150修改为192.168.133.151
7TNS文件
修改tnsnames.ora文件.
7.1、主库
[oracle@oeldgadmin]$ cat tnsnames.ora
#tnsnames.ora Network Configuration File:/u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora
#Generated by Oracle configuration tools.
ORCL150 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST =192.168.133.150)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl150)
    )
  )
ORCL151 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST =192.168.133.151)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl151)
    )
  )
说明:不做修改.
7.2、备库
[oracle@oeladmin]$ cat tnsnames.ora
#tnsnames.ora Network Configuration File:/u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora
#Generated by Oracle configuration tools.
ORCL150 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST =192.168.133.150)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl150)
    )
  )
ORCL151 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST =192.168.133.151)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl151)
    )
  )
说明:不做修改.
8、监听文件
修改监听listener.ora文件
8.1、新主库
[oracle@oeldgadmin]$ cat listener.ora
#listener.ora Network Configuration File:/u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
#Generated by Oracle configuration tools.
SID_LIST_LISTENER=
   (SID_LIST =
      (SID_DESC =
         (GLOBAL_DBNAME = orcl150)
         (ORACLE_HOME =/u01/app/oracle/product/11.2.0/db_1)
         (SID_NAME = orcl150)
      )
   )

LISTENER=
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST =192.168.133.150)(PORT = 1521))
      (ADDRESS = (PROTOCOL = IPC)(KEY =EXTPROC1521))
    )
  )
ADR_BASE_LISTENER= /u01/app/oracle
说明:将GLOBAL_DBNAME= orcl151修改为GLOBAL_DBNAME = orcl150HOST= 192.168.133.151修改为HOST = 192.168.133.150SID_NAME= orcl151修改为SID_NAME = orcl150
8.2、新备库
[oracle@oeladmin]$ cat listener.ora
#listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
#Generated by Oracle configuration tools.
SID_LIST_LISTENER =
   (SID_LIST =
      (SID_DESC =
         (GLOBAL_DBNAME = orcl151)
         (ORACLE_HOME =/u01/app/oracle/product/11.2.0/db_1)
         (SID_NAME = orcl151)
      )
   )
LISTENER=
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST =192.168.133.151)(PORT = 1521))
      (ADDRESS = (PROTOCOL = IPC)(KEY =EXTPROC1521))
    )
  )
ADR_BASE_LISTENER= /u01/app/oracle
说明:蓝色为新增,将HOST =192.168.133.150修改为HOST = 192.168.133.151
9、修改pfile
在主备库修改pfile文件后以该文件生成spfile启动数据库.
以下为新主库修改的参数.
*.log_archive_dest_1='location=/u01/app/oracle/fast_recovery_area/archivelogvalid_for=(all_logfiles,all_roles) db_unique_name=orcl150'
*.db_unique_name='ORCL150'
*.log_archive_dest_2='service=ORCL151lgwr async valid_for=(online_logfiles,primary_role) db_unique_name=orcl151'
注意:备库*.audit_trail='db'参数需要设置为none.
10、启动服务
启动主备库监听、数据库.
[oracle@oeldgadmin]$ lsnrctl start
[oracle@oeladmin]$ lsnrctl start
SQL>startup nomountpfile='/u01/app/oracle/product/11.2.0/db_1/dbs/initorcl151.ora';
SQL>create spfile from pfile;
SQL>shutdown immediate
SQL>startup
SQL>alter database recover managed standby database using current logfiledisconnect from session;

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 支持支持 反对反对
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|手机版|小黑屋|重庆思庄Oracle、Redhat认证学习论坛 ( 渝ICP备12004239号-4 )

GMT+8, 2024-11-25 19:31 , Processed in 0.088050 second(s), 20 queries .

重庆思庄学习中心论坛-重庆思庄科技有限公司论坛

© 2001-2020

快速回复 返回顶部 返回列表