Oracle RAC系列之:测试RAC数据库集群功能
OracleRAC是一个集群数据库,可以实现负载均衡和故障无缝切换。如何知道RAC数据库已经实现了这些功能呢,下面就对此进行功能测试。一、负载均衡测试RAC数据库的
Oracle RAC是一个集群数据库,可以实现负载均衡和故障无缝切换。如何知道RAC数据库已经实现了这些功能呢,下面就对此进行功能测试。
一、 负载均衡测试
RAC数据库的负载均衡是指对数据库连接的负载均衡,当一个新的会话连接到RAC数据库时,通过指定的分配算法将请求分配到集群的任一节点上,这就是RAC数据库完成的功能。负载均衡在RAC中分为两种:一种是基于客户端连接的负载均衡;一种是基于服务器端的负载均衡。
1. RAC客户端负载均衡
客户端连接的负载均衡配置起来非常简单,与RAC数据库的实例负载和监听没有任何关系,因此也就不需要在集群节点进行任何设置,只要在客户端机器上的tnsnames.ora文件中添加负载均衡策略配置即可。这里以Linux客户端为例进行介绍。
(1) 修改/etc/hosts文件
编辑/etc/hosts文件,将RAC数据库相关的IP地址信息添加进去,例如:
192.168.12.231 node-rac1
192.168.12.232 node-rac2
192.168.12.230 node-vip1
192.168.12.240 node-vip2
(2) 查看RAC数据库的service_names
[oracle@node-rac1 ~]$ sqlplus "/as sysdba"
SQL*Plus: Release 11.1.0.6.0 - Production on Sun Sep 12 22:05:53 2010
Copyright (c) 1982, 2007, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
With the Partitioning, Real Application Clusters, OLAP, Data Mining
and Real Application Testing options
NAME TYPE VALUE
---------------------- -------------- -------------
service_names string racdb
这里需要说明的是,在配置RAC负载均衡时,客户端连接的是RAC数据库的服务名,而不是实例名,也就是SERVICE_NAME必须设置为“SERVICE_NAME = racdb”
(3) 修改Oracle客户端的配置文件tnsnames.ora
RACDB=
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = node-vip2)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = node-vip1)(PORT = 1521))
(LOAD_BALANCE = yes)
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = racdb)
)
)
这个配置文件的说明如下:
LOAD_BALANCE = yes,表示启用连接负载均衡。在默认情况下“LOAD_BALANCE = no”,因此如果要配置负载均衡,必须添加设置“LOAD_BALANCE = yes”。启用负载均衡后,SQLNet会随机选择ADDRESS_LIST列表中的任意一个监听,然后将请求分发到此监听上,通过这种方式完成负载均衡。如果“LOAD_BALANCE = no”,那么SQLNet会按照ADDRESS_LIST列表中的顺序选择监听,只要这个监听正常就一直使用该监听。
SERVICE_NAME = racdb,这个“racdb“是RAC数据库的服务名,而非实例名。
(4)在客户端测试负载均衡
在客户端开启一个sqlplus连接,美国空间,执行如下操作:
[oracle@client ~]$ sqlplus system/xxxxxx@racdb
SQL*Plus: Release 11.1.0.7.0 - Production on Sun Sep 12 21:24:55 2010
Copyright (c) 1982, 2008, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
With the Partitioning, Real Application Clusters, OLAP, Data Mining
and Real Application Testing options
SQL> show parameter instance_name
NAME TYPE VALUE
--------------------- --------------- -------------------
instance_name string racdb1
继续开启第二个sqlplus连接,执行如下操作:
[oracle@client ~]$ sqlplus system/xxxxxx@racdb
SQL*Plus: Release 11.1.0.7.0 - Production on Sun Sep 12 21:31:53 2010
Copyright (c) 1982, 2008, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
With the Partitioning, Real Application Clusters, OLAP, Data Mining
and Real Application Testing options
SQL> show parameter instance_name
NAME TYPE VALUE
-------------------- -------------- ------------------
instance_name string racdb2
按照这种方法,陆续打开多个sqlplus连接,可以看到,每次连接到的实例都在racdb1和racdb2之间变化,这样就实现了RAC数据库连接的负载均衡。
2. 服务器端的负载均衡
客户端的负载均衡解决了连接数据库的负载问题,但是由于连接是由客户端发起的,它并不知道RAC数据库集群中各个节点的繁忙状态和连接信息,因此负荷较大的节点仍然会增加新的连接,这样就可能导致RAC节点无法真正做到负载均衡。不过幸运的是,从Oracle 10g开始,服务器端负载均衡就可以根据RAC中各节点的负荷及连接数情况,将新的请求分配到集群中负载较低、连接数较少的节点上来,这样就从根本上实现了数据库的负载均衡,并且使客户端连接的负载均衡与服务器端的负载均衡可以配合使用,互不影响。
每个集群节点的负载情况是由PMON进程来定期更新的。PMON进程每3秒会将集群中每个节点的负载信息及连接数写入service_register中,当节点的负载发生变化时,将会立刻通知监听程序,最后由监听程序来决定将新的客户端连接分配到哪个节点上,通过这种方式,RAC数据库实现了真正的负载均衡。
服务器端负载均衡配置也非常简单,只需在各节点的tnsnames.ora文件中添加一个对连接到各个节点进行监听的配置,然后在初始化参数中设置remote_listener即可。
(1)修改服务器端的tnsnames.ora
只需添加如下内容即可:
LISTENERS_RACDB =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = node-vip2)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = node-vip1)(PORT = 1521))
)
(2)修改参数remote_listener
查看RAC数据库的参数remote_listener:
SQL> show parameter remote_listener
NAME TYPE VALUE
--------------- ----------- -----------
remote_listener string LISTENERS_RACDB
可以看到,remote_listener已经设置为“LISTENERS_RACDB”了。
如果remote_listener的值为空,可以通过如下命令修改每个实例的remote_listener参数:
SQL> alter system set remote_listener='LISTENERS_RACDB' sid='node-rac1';
SQL> alter system set remote_listener='LISTENERS_RACDB' sid='node-rac2';
这样,虚拟主机,服务器端的负载均衡就配置完成了。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



VS Code system requirements: Operating system: Windows 10 and above, macOS 10.12 and above, Linux distribution processor: minimum 1.6 GHz, recommended 2.0 GHz and above memory: minimum 512 MB, recommended 4 GB and above storage space: minimum 250 MB, recommended 1 GB and above other requirements: stable network connection, Xorg/Wayland (Linux)

The reasons for the installation of VS Code extensions may be: network instability, insufficient permissions, system compatibility issues, VS Code version is too old, antivirus software or firewall interference. By checking network connections, permissions, log files, updating VS Code, disabling security software, and restarting VS Code or computers, you can gradually troubleshoot and resolve issues.

VS Code is available on Mac. It has powerful extensions, Git integration, terminal and debugger, and also offers a wealth of setup options. However, for particularly large projects or highly professional development, VS Code may have performance or functional limitations.

VS Code is the full name Visual Studio Code, which is a free and open source cross-platform code editor and development environment developed by Microsoft. It supports a wide range of programming languages and provides syntax highlighting, code automatic completion, code snippets and smart prompts to improve development efficiency. Through a rich extension ecosystem, users can add extensions to specific needs and languages, such as debuggers, code formatting tools, and Git integrations. VS Code also includes an intuitive debugger that helps quickly find and resolve bugs in your code.

MongoDB is suitable for handling large-scale unstructured data, and Oracle is suitable for enterprise-level applications that require transaction consistency. 1.MongoDB provides flexibility and high performance, suitable for processing user behavior data. 2. Oracle is known for its stability and powerful functions and is suitable for financial systems. 3.MongoDB uses document models, and Oracle uses relational models. 4.MongoDB is suitable for social media applications, while Oracle is suitable for enterprise-level applications.

VS Code To switch Chinese mode: Open the settings interface (Windows/Linux: Ctrl, macOS: Cmd,) Search for "Editor: Language" settings Select "Chinese" in the drop-down menu Save settings and restart VS Code

The main uses of Linux include: 1. Server operating system, 2. Embedded system, 3. Desktop operating system, 4. Development and testing environment. Linux excels in these areas, providing stability, security and efficient development tools.

Although Notepad cannot run Java code directly, it can be achieved by using other tools: using the command line compiler (javac) to generate a bytecode file (filename.class). Use the Java interpreter (java) to interpret bytecode, execute the code, and output the result.
