前面我们介绍了RAC的客户端负载均衡配置,接下来就到了服务器端RAC负载均衡配置的具体代码介绍了,通过两方面的配置和测试之后,整个负载均衡才能完全的设置好。那么就让我们赶紧来看一下啊具体的服务器端RAC负载均衡配置内容吧。 从Oracle 10g开始,服务器端
前面我们介绍了RAC的客户端负载均衡配置,接下来就到了服务器端RAC负载均衡配置的具体代码介绍了,通过两方面的配置和测试之后,整个负载均衡才能完全的设置好。那么就让我们赶紧来看一下啊具体的服务器端RAC负载均衡配置内容吧。
从Oracle 10g开始,服务器端负载均衡可以根据RAC中各节点的负荷及连接数情况,而判定将新的客户端连接分配到负荷最小的节点上去?RAC中各节点的PMON进程每3秒会将各自节点的负荷(包括LOAD?最大LOAD?CPU使用率)及连接数更新到service_register里面,然后假如节点的负荷有发生变化,将会通知到监听程序,由监听程序再决定新的客户端连接分配至哪个节点?假如RAC中一个节点的监听失败了,PMON每一分钟会去检查一次是否已经恢复正常?
服务器端的监听配置是在各节点的tnsnames.ora里面添加一个连接到各个节点监听的条目,然后再在初始化参数里面设置remote_listeners这个参数?
1?测试客户端的TNS
修改客户端tnsnames.ora的文件,内容如下:
<ol> <li><span>RACDB = </span></li> <li><span> (DESCRIPTION = </span></li> <li><span> (ADDRESS_LIST = </span></li> <li><span> (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.170)(PORT = 1521)) </span></li> <li><span> ) </span></li> <li><span> (CONNECT_DATA = </span></li> <li><span> (SERVICE_NAME = racdb.chenxu.yo2.cn) </span></li> <li><span> ) </span></li> <li><span> ) </span></li> </ol>
测试连接:
<ol> <li><span><span>SQL> conn sys/chenxu@racdb </span><span>as</span><span> sysdba </span></span></li> <li><span>已连接? </span></li> <li><span>SQL> </span></li> <li><span>SQL> show parameter instance_name </span></li> <li><span> </span></li> <li> <span>NAME</span><span> TYPE VALUE </span> </li> <li> <span>------------------------------------ ----------- --------------------- </span><span> </span> </li> <li><span>instance_name string RACDB1 </span></li> </ol>
2?配置服务器端TNS
服务器端的监听配置是在各节点的tnsnames.ora里面添加一个连接到各个节点监听的条目(红色代码),在服务器端每个节点的tnsnames.ora里面的内容如下:
<ol> <li><span>[root@NODE01 admin]# pwd </span></li> <li><span>/orac/orahome/oracle/product/10.2.0/db_1/network/admin </span></li> <li><span>[root@NODE01 admin]# </span></li> <li><span>[root@NODE01 admin]# more tnsnames.ora </span></li> <li><span># tnsnames.ora Network Configuration File: /orac/orahome/oracle/product/10.2.0/db_1/network/admin/tnsnames.ora </span></li> <li> <span># Generated </span><span>by</span><span> Oracle configuration tools. </span> </li> <li><span> </span></li> <li><span>RACDB1 = </span></li> <li><span> (DESCRIPTION = </span></li> <li><span> (ADDRESS = (PROTOCOL = TCP)(HOST = vip01)(PORT = 1521)) </span></li> <li><span> (CONNECT_DATA = </span></li> <li><span> (SERVER = DEDICATED) </span></li> <li><span> (SERVICE_NAME = RACDB.chenxu.yo2.cn) </span></li> <li><span> (INSTANCE_NAME = RACDB1) </span></li> <li><span> ) </span></li> <li><span> ) </span></li> <li><span> </span></li> <li><span>RACDB = </span></li> <li><span> (DESCRIPTION = </span></li> <li><span> (ADDRESS = (PROTOCOL = TCP)(HOST = vip01)(PORT = 1521)) </span></li> <li><span> (ADDRESS = (PROTOCOL = TCP)(HOST = vip02)(PORT = 1521)) </span></li> <li><span> (LOAD_BALANCE = yes) </span></li> <li><span> (CONNECT_DATA = </span></li> <li><span> (SERVER = DEDICATED) </span></li> <li><span> (SERVICE_NAME = RACDB.chenxu.yo2.cn) </span></li> <li><span> ) </span></li> <li><span> ) </span></li> <li><span> </span></li> <li><span>LISTENERS_RACDB = </span></li> <li><span> (ADDRESS_LIST = </span></li> <li><span> (ADDRESS = (PROTOCOL = TCP)(HOST = vip01)(PORT = 1521)) </span></li> <li><span> (ADDRESS = (PROTOCOL = TCP)(HOST = vip02)(PORT = 1521)) </span></li> <li><span> ) </span></li> <li><span> </span></li> <li><span>RACDB2 = </span></li> <li><span> (DESCRIPTION = </span></li> <li><span> (ADDRESS = (PROTOCOL = TCP)(HOST = vip02)(PORT = 1521)) </span></li> <li><span> (CONNECT_DATA = </span></li> <li><span> (SERVER = DEDICATED) </span></li> <li><span> (SERVICE_NAME = RACDB.chenxu.yo2.cn) </span></li> <li><span> (INSTANCE_NAME = RACDB2) </span></li> <li><span> ) </span></li> <li><span> ) </span></li> </ol>
3?在初始化参数中设置参数remote_listeners
<ol> <li><span><span>SQL> conn sys/chenxu@racdb </span><span>as</span><span> sysdba </span></span></li> <li><span>已连接? </span></li> <li><span>SQL> show parameter remote_listener </span></li> <li><span> </span></li> <li> <span>NAME</span><span> TYPE VALUE </span> </li> <li> <span>------------------------------------ ----------- ------------------------ </span><span> </span> </li> <li><span>remote_listener string </span></li> <li><span>SQL> </span></li> <li> <span>SQL> </span><span>alter</span><span> system </span><span>set</span><span> remote_listener=</span><span>'LISTENERS_RACDB'</span><span> sid=</span><span>'*'</span><span>; </span> </li> <li><span>#(reset命令可以撤销设置,恢复默认值) </span></li> <li><span>系统已更改? </span></li> <li><span>SQL> </span></li> <li><span>SQL> show parameter remote_listener </span></li> <li> <span>NAME</span><span> TYPE VALUE </span> </li> <li> <span>------------------------------------ ----------- --------------------- </span><span> </span> </li> <li><span>remote_listener string LISTENERS_RACDB </span></li> </ol>
正确配置参数后,通过lsnrctl status命令看到在监听启动以后,可以看到监听器上有2个instance?
<ol> <li><span>[root@NODE01 bin]# lsnrctl status </span></li> <li> <span>LSNRCTL </span><span>for</span><span> Linux: Version 10.2.0.1.0 - Production </span><span>on</span><span> 18-</span><span>DEC</span><span>-2008 05:40:08 </span> </li> <li> <span>Copyright (c) 1991, 2005, Oracle. </span><span>All</span><span> rights reserved. </span> </li> <li> <span>Connecting </span><span>to</span><span> (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521)) </span> </li> <li> <span>STATUS </span><span>of</span><span> the LISTENER </span> </li> <li> <span>------------------------ </span><span> </span> </li> <li><span>Alias LISTENER_NODE01 </span></li> <li> <span>Version TNSLSNR </span><span>for</span><span> Linux: Version 10.2.0.1.0 - Production </span> </li> <li> <span>Start </span><span>Date</span><span> 18-</span><span>DEC</span><span>-2008 00:18:07 </span> </li> <li> <span>Uptime 0 days 5 hr. 22 </span><span>min</span><span>. 1 sec </span> </li> <li> <span>Trace </span><span>Level</span><span> </span><span>off</span><span> </span> </li> <li> <span>Security </span><span>ON</span><span>: </span><span>Local</span><span> OS Authentication </span> </li> <li> <span>SNMP </span><span>OFF</span><span> </span> </li> <li><span> </span></li> <li><span>Listener Parameter File /orac/orahome/oracle/product/10.2.0/db_1/network/admin/listener.ora </span></li> <li><span>Listener Log File /orac/orahome/oracle/product/10.2.0/db_1/network/log/listener_node01.log </span></li> <li><span>Listening Endpoints Summary... </span></li> <li><span> (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.1.170)(PORT=1521))) </span></li> <li><span> (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.1.180)(PORT=1521))) </span></li> <li> <span> (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(</span><span>KEY</span><span>=EXTPROC))) </span> </li> <li><span> </span></li> <li><span>Services Summary... </span></li> <li> <span>Service </span><span>"+ASM"</span><span> has 1 instance(s). </span> </li> <li> <span> Instance </span><span>"+ASM1"</span><span>, status BLOCKED, has 1 handler(s) </span><span>for</span><span> this service... </span> </li> <li> <span>Service </span><span>"+ASM_XPT"</span><span> has 1 instance(s). </span> </li> <li> <span> Instance </span><span>"+ASM1"</span><span>, status BLOCKED, has 1 handler(s) </span><span>for</span><span> this service... </span> </li> <li> <span>Service </span><span>"RACDB.chenxu.yo2.cn"</span><span> has 2 instance(s). </span> </li> <li> <span> Instance </span><span>"RACDB1"</span><span>, status READY, has 2 handler(s) </span><span>for</span><span> this service... </span> </li> <li> <span> Instance </span><span>"RACDB2"</span><span>, status READY, has 1 handler(s) </span><span>for</span><span> this service... </span> </li> <li> <span>Service </span><span>"RACDBXDB.chenxu.yo2.cn"</span><span> has 2 instance(s). </span> </li> <li> <span> Instance </span><span>"RACDB1"</span><span>, status READY, has 1 handler(s) </span><span>for</span><span> this service... </span> </li> <li> <span> Instance </span><span>"RACDB2"</span><span>, status READY, has 1 handler(s) </span><span>for</span><span> this service... </span> </li> <li> <span>Service </span><span>"RACDB_XPT.chenxu.yo2.cn"</span><span> has 2 instance(s). </span> </li> <li> <span> Instance </span><span>"RACDB1"</span><span>, status READY, has 2 handler(s) </span><span>for</span><span> this service... </span> </li> <li> <span> Instance </span><span>"RACDB2"</span><span>, status READY, has 1 handler(s) </span><span>for</span><span> this service... </span> </li> <li><span>The command completed successfully </span></li> </ol>
这时在客户端用sqlplus连接服务器数据库可能会出现如下错误:
<ol> <li><span>ERROR: </span></li> <li><span>ORA-12545: 因目标主机或对象不存在,连接失败 </span></li> </ol>
4?解决ORA-12545连接失败问题
配置客户端的Hosts文件
通过在客户端的Hosts文件中加入对两个服务名的名字解析可以解决ORA-12545问题?在windows下Hosts文件在C:\WINDOWS\system32\drivers\etc目录下,在linux修改/etc/hosts文件的内容?添加如下内容:
<ol> <li><span>192.168.1.170 node01 </span></li> <li><span>192.168.1.171 node02 </span></li> <li><span>其中node01?node02为服务器节点的主机名? </span></li> <li><span>[root@NODE01 bin]# hostname </span></li> <li><span>NODE01 </span></li> </ol>
5?通过客户端测试RAC负载均衡配置
<ol> <li><span>开启sqlplus_1: </span></li> <li> <span>SQL> conn sys/chenxu@racdb </span><span>as</span><span> sysdba </span> </li> <li><span>已连接? </span></li> <li><span>SQL> show parameter instance_name </span></li> <li> <span>NAME</span><span> TYPE VALUE </span> </li> <li> <span>------------------------------------ ----------- --------------- </span><span> </span> </li> <li><span>instance_name string RACDB1 </span></li> </ol>
开启sqlplus_2:
<ol> <li><span><span>SQL> conn sys/chenxu@racdb </span><span>as</span><span> sysdba </span></span></li> <li><span>已连接? </span></li> <li><span>SQL> show parameter instance_name </span></li> <li> <span>NAME</span><span> TYPE VALUE </span> </li> <li> <span>------------------------------------ ----------- ------------- </span><span> </span> </li> <li><span>instance_name string RACDB2 </span></li> </ol>
可以看到客户端能够连接到实例RACDB2,说明基于服务器端RAC负载均衡配置成功?

oracle asm指的是“自动存储管理”,是一种卷管理器,可自动管理磁盘组并提供有效的数据冗余功能;它是做为单独的Oracle实例实施和部署。asm的优势:1、配置简单、可最大化推动数据库合并的存储资源利用;2、支持BIGFILE文件等。

方法:1、利用“select*from user_indexes where table_name=表名”语句查询表中索引;2、利用“select*from all_indexes where table_name=表名”语句查询所有索引。

在oracle中,可以利用“TO_SINGLE_BYTE(String)”将全角转换为半角;“TO_SINGLE_BYTE”函数可以将参数中所有多字节字符都替换为等价的单字节字符,只有当数据库字符集同时包含多字节和单字节字符的时候有效。

在Oracle中,可利用lsnrctl命令查询端口号,该命令是Oracle的监听命令;在启动、关闭或重启oracle监听器之前可使用该命令检查oracle监听器的状态,语法为“lsnrctl status”,结果PORT后的内容就是端口号。

在oracle中,可以利用“drop sequence sequence名”来删除sequence;sequence是自动增加数字序列的意思,也就是序列号,序列号自动增加不能重置,因此需要利用drop sequence语句来删除序列。

方法:1、利用“LOWER(字段值)”将字段转为小写,或者利用“UPPER(字段值)”将字段转为大写;2、利用“REGEXP_LIKE(字符串,正则表达式,'i')”,当参数设置为“i”时,说明进行匹配不区分大小写。

在oracle中,可以利用“select ... From all_tab_columns where table_name=upper('表名') AND owner=upper('数据库登录用户名');”语句查询数据库表的数据类型。

方法:1、利用“alter system set sessions=修改后的数值 scope=spfile”语句修改session参数;2、修改参数之后利用“shutdown immediate – startup”语句重启服务器即可生效。


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver CS6
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Atom editor mac version download
The most popular open source editor

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

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.
