2015年(68)
分类: Oracle
2015-08-31 19:03:24
一、服务端配置
需配置的文件$ORACLE_HOME/network/admin/listener.ora
listener.ora的配置主要有2部分
LISTENER 包含了监听协议、IP地址、端口等信息,如
---------------------------------------------------------------------------------------------------------------
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.30.254.32)(PORT = 1521))
)
)
---------------------------------------------------------------------------------------------------------------
SID_LIST_LISTENER 用于提供对外的数据库服务列表。同一个SID可以提供多个服务名供客户端访问,如
---------------------------------------------------------------------------------------------------------------
SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = /home/oracle/oracle/product/10.2.0/db_2)
(PROGRAM = extproc)
)
(SID_DESC =
(GLOBAL_DBNAME = market)
(ORACLE_HOME = /home/oracle/oracle/product/10.2.0/db_2)
(SID_NAME = demo)
)
(SID_DESC =
(GLOBAL_DBNAME = sales)
(ORACLE_HOME = /home/oracle/oracle/product/10.2.0/db_2)
(SID_NAME = demo)
)
)
---------------------------------------------------------------------------------------------------------------
GLOBAL_DBNAME为设置的服务名,服务名可以为实例所连接的数据库定义一个或多个服务名将不同的用户连接区分开来。监听器先将GLOBAL_DBNAM与客户端连接请求的SERVICE_NAME相匹配,如果客户端使用SID则不检测GLOBAL_DBNAM设置而用SID_NAME进行匹配。
上面我新添加了2个名为market和sales的服务名(PLSExtProc为默认的服务名),启动后在输出信息的最后部分可看到相关的服务信息。
[oracle@server_32admin]$ lsnrctl start
-----------略-----------
Services Summary...
Service "PLSExtProc" has 1instance(s).
Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) forthis service...
Service "market" has 1instance(s).
Instance "demo", status UNKNOWN, has 1 handler(s) for thisservice...
Service "sales" has 1instance(s).
Instance "demo", status UNKNOWN, has 1 handler(s) for thisservice...
二、客户端配置
要连接orcle服务器,需先要安装好oracle客户端软件,然后配置网络服务名文件tnsnames.ora。在这里我用的是windows,直接用oracle客户端软件的NetManager工具来配置连接。
//打开Net Manager并选中"服务命名"
//点击左边绿色的加号开始添加一下服务命名
//采用TCP/IP协议
//输入数据库IP地址和端口
//服务名为刚才添加的sales
//测试连接,成功后点完成
//可以看到在左边的服务命名上已经成功添加了sales-32,保存完成配置并退出
//打开toad,在Database下选择服务命名刚建好的SALES-32连接到数据库,plsql developer的连接也是一样的。
三、动态监听器注册服务
当实例启动后,后台进程PMON会将从spfile文件中参数service_names定义的服务名注册到监听,那么原来的SID_LIST部分就不再需要了,简化了listener.ora的配置,现在简化了的listener.ora配置类似于:
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = /home/oracle/oracle/product/10.2.0/db_2)
(PROGRAM = extproc)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.30.254.32)(PORT = 1521))
)
)
---------------------------------------------------------------------------------------------------------------
service_names是在spfile中定义,我们可以通过alter system 来更改服务名
sys@DEMO> alter system set service_names='hr'scope=both;
System altered.
sys@DEMO> show parameter service_names
NAME TYPE VALUE
--------------------- -------------------- --------------------
service_names string hr
[oracle@server_32 admin]$ lsnrctl status
------- 略-------
Services Summary...
Service "PLSExtProc" has 1instance(s).
Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) forthis service...
Service "demo" has 1 instance(s).
Instance "demo", status READY, has 1 handler(s) for thisservice...
Service "demoXDB" has 1instance(s).
Instance "demo", status READY, has 1 handler(s) for thisservice...
Service "demo_XPT" has 1instance(s).
Instance "demo", status READY, has 1 handler(s) for thisservice...
Service "hr" has 1 instance(s).
Instance "demo", status READY,has 1 handler(s) for this service...
The command completed successfully
动态注册的服务名,监听器确切知道实例的状态,所以status都是READY的。然后客户端的连接和上面的没什么不同。