在专用服务器模式中,对于每个运行数据库应用程序的用户进程都由执行Oracle 数据库服务器代码的专用服务器进程提供服务。
在共享服务器模式中,不必为每个连接都提供一个专用服务器进程。分派程序将多个传入网络会话请求引到共享服务器进程池。共享服务器进程为所有客户机请求提供服务。
Easy Connect(EZCONNECT)
本地命名(TNSNAMES)
目录命名和外部命名
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
$
cat
sqlnet.ora
NAMES.DIRECTORY_PATH= (TNSNAMES, EZCONNECT)
ADR_BASE =
/u01/app/oracle
$
cat
listener.ora
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = ora11g.example.com)(PORT = 1521))
)
)
ADR_BASE_LISTENER =
/u01/app/oracle
ENABLE_GLOBAL_DYNAMIC_ENDPOINT_LISTENER=ON
# line added by Agent
$
cat
tnsnames.ora
ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.90)(PORT = 1521))
(CONNECT_DATA =
(SERVICE_NAME = orcl.example.com)
)
)
$ lsnrctl service
LSNRCTL
for
Linux: Version 11.2.0.1.0 - Production on 11-SEP-2013 22:11:58
Copyright (c) 1991, 2009, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=ora11g.example.com)(PORT=1521)))
Services Summary...
Service
"+ASM"
has 1 instance(s).
Instance
"+ASM"
, status READY, has 1 handler(s)
for
this service...
Handler(s):
"DEDICATED"
established:0 refused:0 state:ready
LOCAL SERVER
Service
"orcl.example.com"
has 1 instance(s).
Instance
"orcl"
, status READY, has 1 handler(s)
for
this service...
Handler(s):
"DEDICATED"
established:0 refused:0 state:ready
LOCAL SERVER
Service
"orclXDB.example.com"
has 1 instance(s).
Instance
"orcl"
, status READY, has 1 handler(s)
for
this service...
Handler(s):
"D000"
established:0 refused:0 current:0 max:972 state:ready
DISPATCHER <machine: ora11g.example.com, pid: 5008>
(ADDRESS=(PROTOCOL=tcp)(HOST=ora11g.example.com)(PORT=56668))
The
command
completed successfully
|
静态注册就是实例启动时读取listener.ora文件的配置,将实例和服务注册到监听程序。无论何时启动一个数据库,默认地都有两条信息注册到监听器中:数据库服务器对应的实例和服务。
动态注册是在instance启动的时候PMON进程根据init.ora中的instance_name,service_names两个参数将实例和服务动态注册到listener中。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
SQL> show parameter _listener
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
local_listener string
//默认为空值,则找默认的监听器LISTENER
remote_listener string
//RAC中指定对端结点的监听器
SQL> show parameter service_names
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
service_names string orcl.example.com
$ cat listener.ora
# listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora
# Generated by Oracle configuration tools.
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = ora11g.example.com)(PORT = 1521))
)
)
ADR_BASE_LISTENER = /u01/app/oracle
ENABLE_GLOBAL_DYNAMIC_ENDPOINT_LISTENER = ON
|
动态注册
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
$
vi
$TNS_ADMIN
/listener
.ora
//
添加监听器
"LISTENER1"
的配置信息
LISTENER1 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.90)(PORT = 1522))
)
$
vi
$TNS_ADMIN
/tnsnames
.ora
//
添加连接到监听器
"LISTENER1"
的连接字符串
APPLE =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.90)(PORT = 1522))
)
SQL> alter system
set
local_listener=
'listener1'
;
alter system
set
local_listener=
'listener1'
*
ERROR at line 1:
ORA-02097: parameter cannot be modified because specified value is invalid
ORA-00119: invalid specification
for
system parameter LOCAL_LISTENER
ORA-00132: syntax error or unresolved network name
'listener1'
SQL> alter system
set
local_listener=
'apple'
;
//
修改默认监听程序(必须使用监听程序对应的连接字符串)
System altered.
$ lsnrctl start listener1
//
启动监听程序
"LISTENER1"
---------------省略输出---------------
STATUS of the LISTENER
------------------------
Alias listener1
Version TNSLSNR
for
Linux: Version 11.2.0.1.0 - Production
Start Date 11-SEP-2013 14:18:13
Uptime 0 days 0 hr. 0 min. 1 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File
/u01/app/oracle/product/11
.2.0
/dbhome_1//network/admin/listener
.ora
Listener Log File
/u01/app/oracle/diag/tnslsnr/ora11g/listener1/alert/log
.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.0.90)(PORT=1522)))
The listener supports no services
The
command
completed successfully
$ lsnrctl status listener1
//
查看
"LISTENER1"
监听程序的状态(动态注册一般会有几秒钟的延迟)
---------------省略输出---------------
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.0.90)(PORT=1522)))
Services Summary...
Service
"orcl.example.com"
has 1 instance(s).
Instance
"orcl"
, status READY, has 1 handler(s)
for
this service...
Service
"orclXDB.example.com"
has 1 instance(s).
Instance
"orcl"
, status READY, has 1 handler(s)
for
this service...
The
command
completed successfully
$ lsnrctl status
//
查看
"LISTENER"
监听程序的状态(
"LISTENER"
监听程序可省略指定)
---------------省略输出---------------
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=ora11g.example.com)(PORT=1521)))
Services Summary...
Service
"+ASM"
has 1 instance(s).
Instance
"+ASM"
, status READY, has 1 handler(s)
for
this service...
The
command
completed successfully
$ sqlplus
/nolog
SQL> conn hr
/hr
@apple
//
通过
"LISTENER"
监听程序连接
Connected.
|
静态注册
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
$
vi
$TNS_ADMIN
/listener
.ora
LISTENER2 =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.90)(PORT = 1523))
)
)
SID_LIST_LISTENER2 =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = orcl.example.com)
(ORACLE_HOME =
/u01/app/oracle/product/11
.2.0
/dbhome_1/
)
(SID_NAME = orcl)
)
)
$ lsnrctl start listener2
---------------省略输出---------------
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.0.90)(PORT=1523)))
Services Summary...
Service
"orcl.example.com"
has 1 instance(s).
Instance
"orcl"
, status UNKNOWN, has 1 handler(s)
for
this service...
The
command
completed successfully
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
$ sqlplus
/nolog
SQL*Plus: Release 11.2.0.1.0 Production on Wed Sep 11 16:30:14 2013
Copyright (c) 1982, 2009, Oracle. All rights reserved.
SQL> conn / as sysdba
Connected.
SQL>
shutdown
immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> conn sys
/oracle_4U
@apple as sysdba
//
无法连接通过动态注册的监听
ERROR:
ORA-12514: TNS:listener does not currently know of service requested
in
connect
descriptor
SQL> conn sys
/oracle_4U
@apear as sysdba
//
成功连接静态注册的监听,可实现远程开启数据库
Connected to an idle instance.
SQL> startup
ORACLE instance started.
Total System Global Area 459304960 bytes
Fixed Size 2214336 bytes
Variable Size 289408576 bytes
Database Buffers 159383552 bytes
Redo Buffers 8298496 bytes
Database mounted.
Database opened.
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
$
grep
-A 11 ORCL tnsnames.ora
ORCL =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.90)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.90)(PORT = 1522))
(LOAD_BALANCE =
yes
)
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl.example.com)
)
)
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
$ . oraenv
ORACLE_SID = [orcl] ? +ASM
The Oracle base
for
ORACLE_HOME=
/u01/app/oracle/product/11
.2.0
/grid
is
/u01/app/oracle
$ lsnrctl stop listener1
$ lsnrctl stop listener2
$ srvctl add listener -h
Adds a listener configuration to be managed by Oracle Restart.
Usage: srvctl add listener [-l <lsnr_name>] [-s] [-p
"[TCP:]<port>[, ...][/IPC:<key>][/NMP:<pipe_name>][/TCPS:<s_port>] [/SDP:<port>]"
] [-o <oracle_home>]
-l <lsnr_name> Listener name (default name is LISTENER)
-o <oracle_home> ORACLE_HOME path (default value is CRS_HOME)
-s Skip the checking of ports
-p
"[TCP:]<port>[, ...][/IPC:<key>][/NMP:<pipe_name>][/TCPS:<s_port>] [/SDP:<port>]"
Comma separated tcp ports or listener endpoints
-h Print usage
$ srvctl add listener -l listener1 -p 1522 -o
/u01/app/oracle/product/11
.2.0
/dbhome_1/
$ srvctl add listener -l listener2 -p 1523 -o
/u01/app/oracle/product/11
.2.0
/dbhome_1/
$ srvctl start listener -l listener1
$ srvctl start listener -l listener2
$ crs_stat -t
Name Type Target State Host
------------------------------------------------------------
ora.DATA.dg ora....up.
type
ONLINE ONLINE ora11g
ora.FRA.dg ora....up.
type
ONLINE ONLINE ora11g
ora....ER.lsnr ora....er.
type
ONLINE ONLINE ora11g
ora....R1.lsnr ora....er.
type
ONLINE ONLINE ora11g
ora....R2.lsnr ora....er.
type
ONLINE ONLINE ora11g
ora.asm ora.asm.
type
ONLINE ONLINE ora11g
ora.cssd ora.cssd.
type
ONLINE ONLINE ora11g
ora.diskmon ora....on.
type
ONLINE ONLINE ora11g
ora.orcl.db ora....se.
type
ONLINE ONLINE ora11g
|