环境:
OS:Centos 7
DB:V7
主库:192.168.1.101
备库:192.168.1.103
数据库名称(主备保持一致):HXL
1.主库上需要确保在归档模式
[root@localhost bin]# ./isql -h localhost -p 2003 -d HXL sysdba SQL> select log_mode from v$database; LOG_MODE ------------ ARCHIVELOG (1 row)
若数据库不在归档模式,需要按照如下命令进行修改为归档模式
mkdir -p /opt/ShenTong/arch
alter database archivelog '/opt/ShenTong/arch';
2.停掉主库
目的是做一致性备份,然后在备库上进行恢复
/etc/init.d/oscardb_HXLd stop
3.备库安装相同版本的数据库
需要配置归档,归档路径保持与主库一致
[root@localhost bin]# ./isql -h localhost -p 2003 -d HXL sysdba [root@localhost ~]#mkdir -p /opt/ShenTong/arch SQL>alter database archivelog '/opt/ShenTong/arch';
4.备份主库
需要在停掉的情况下做一致性备份
[root@localhost bin]# cd /opt/ShenTong/bin
./brcmd -O backup -d HXL -u SYSDBA -p szoscar55 -P 2003 -t full -k file -f /tmp/bk.osrbk -b 8192 -e /tmp/bk_log.txt -c TRUE -m TRUE
5.将备份文件拷贝到备库机器
scp /tmp/bk.osrbk [email protected]:/tmp/
scp /tmp/bk_log.txt [email protected]:/tmp/
6.停掉备库
/etc/init.d/oscardb_HXLd stop
7.备库进行恢复
[root@localhost bin]# cd /opt/ShenTong/bin
./brcmd -O restore -d HXL -u SYSDBA -p szoscar55 -P 2003 -t backup_point_last -k file -f /tmp/bk.osrbk -b 8192 -e /tmp/bk_log.txt
这里确保备库能够启动
/etc/init.d/oscardb_HXLd start
确保能够正常启动后,需要停止
/etc/init.d/oscardb_HXLd stop
8.修改配置文件,2个节点都要进行修改
除了HA_LOCAL_NET_DEV_NAME可能需要修改外,其他的不需要修改
vi /opt/ShenTong/admin/HXL.conf HOTSTANDBY_DATABASE_TYPE=2 ENABLE_HA_SINGLE_ALIVE=false HA_LOCAL_NET_DEV_NAME='enp0s3:1' ### 这个网卡设备名(enp0s3),根据每个机器的配置进行修改 HA_SERVER_IP_ADDRESS='192.168.1.188' ### 这个是对外提供服务的浮动IP HA_GATEWAY='192.168.1.1'
9.两个节点进行启动
修改完文件后,直接启动节点
/etc/init.d/oscardb_HXLd start
/etc/init.d/oscaragentd start ##若agent停止的话需要启动
10.添加节点
在主节点,登录数据库
cd /opt/ShenTong/bin ./isql -p 2003 -U sysdba/szoscar55 -d HXL alter database add node '192.168.1.101'; ###先添加本机ip alter database add node '192.168.1.103'; ###再添加备库ip
11.查看系统视图
SQL> select * from v_sys_ha_slave_info; NODE_ID | ADDRESS | SYNCLOG | STATUS | PORT | READABLE | SYNCHRONIZED | WEIGHT | START_LSN | NEXT_SEND_LSN | N EXT_FLUSH_LSN | NEXT_REDO_LSN | TRANSMISSION_TIME ---------+---------------+---------+--------+------+----------+--------------+--------+-----------+---------------+-- --------------+---------------+------------------- 1 | 192.168.1.101 | t | master | 2003 | f | f | 0 | 7766016 | 0 | 7766016 | 0 | 0 2 | 192.168.1.103 | f | slave | 2003 | t | f | 0 | 7764480 | 7766016 | 7766016 | 7766032 | 0 (2 rows)
12.vip查看
[root@localhost admin]# ip a 2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 08:00:27:7f:59:25 brd ff:ff:ff:ff:ff:ff inet 192.168.1.101/24 brd 192.168.1.255 scope global noprefixroute enp0s3 valid_lft forever preferred_lft forever inet 192.168.1.188/24 brd 192.168.1.255 scope global secondary enp0s3:1 valid_lft forever preferred_lft forever inet6 fe80::c0da:c158:92c8:285d/64 scope link noprefixroute valid_lft forever preferred_lft forever
13.数据验证
主库(192.168.1.101)创建表 cd /opt/ShenTong/bin ./isql -p 2003 -U utest/oracle -d HXL create table tb_test02 ( id number not null, name varchar2(32), createtime timestamp default sysdate, updatetime timestamp default sysdate ); insert into tb_test02(id,name) values(1,'name1'); insert into tb_test02(id,name) values(2,'name1'); insert into tb_test02(id,name) values(3,'name1'); insert into tb_test02(id,name) values(4,'name1'); insert into tb_test02(id,name) values(5,'name1'); insert into tb_test02(id,name) values(6,'name1'); insert into tb_test02(id,name) values(7,'name1'); insert into tb_test02(id,name) values(8,'name1'); insert into tb_test02(id,name) values(9,'name1'); insert into tb_test02(id,name) values(10,'name1'); 从库(192.168.1.103)上查看 cd /opt/ShenTong/bin ./isql -p 2003 -U utest/oracle -d HXL SQL> \dt List of relations schema | name | type | owner --------+------------------+-------+-------- PUBLIC | AQ$_QUEUES | table | SYSDBA PUBLIC | AQ$_QUEUE_TABLES | table | SYSDBA UTEST | TB_TEST | table | UTEST UTEST | TB_TEST01 | table | UTEST UTEST | TB_TEST02 | table | UTEST (5 rows) SQL> select * from tb_test02; ID | NAME | CREATETIME | UPDATETIME ----+-------+---------------------+--------------------- 1 | name1 | 2024-03-06 15:21:26 | 2024-03-06 15:21:26 2 | name1 | 2024-03-06 15:21:26 | 2024-03-06 15:21:26 3 | name1 | 2024-03-06 15:21:26 | 2024-03-06 15:21:26 4 | name1 | 2024-03-06 15:21:26 | 2024-03-06 15:21:26 5 | name1 | 2024-03-06 15:21:26 | 2024-03-06 15:21:26 6 | name1 | 2024-03-06 15:21:26 | 2024-03-06 15:21:26 7 | name1 | 2024-03-06 15:21:26 | 2024-03-06 15:21:26 8 | name1 | 2024-03-06 15:21:26 | 2024-03-06 15:21:26 9 | name1 | 2024-03-06 15:21:26 | 2024-03-06 15:21:26 10 | name1 | 2024-03-06 15:21:26 | 2024-03-06 15:21:26 (10 rows)
标签:03,26,06,21,部署,oscar,name1,15,主从 From: https://www.cnblogs.com/hxlasky/p/18056839