oracle网络没有负载,
监听与数据库没有内存在联系,与数据库独立,监听知道数据库的存在,但不存在长连接。
没有负载的就不容易出问题。相对很简单的。但短时间有大量连接请求时,监听可能因为负载大而反应缓慢。
客户端与数据库连接的流程:
用户发起连接,连接到监听器的1521端口,因为监听知道数据库的位置,所有监听将用户的请求转发给数据库实例,数据库实例会专门为这个连接起动一个server process,同时会将server process的地址告诉监听,监听将server process的地址告诉客户端。这时客户直接发启一个直接对serverprocess的请求。 这时客户端与oracle数据库正式建立了连接。这时客户端将用户名和密码给server process,server process拿着用户名和密码去验证用户是否存在。如果验证成功后,这个连接正式建立。此后客户端与数据库的所有操作都通过server process会话,和监听没有关系了。
监听的主要做用:客户端与数据库建立连接时,负责转发请求。
监听的端口默认是:1521
共享和专用服务器模式
Oracle数据库的几个名字:
SYS AS SYSDBA@ORCL>showparameter name;
NAME TYPE VALUE
------------------------------------ --------------------------------------------------
db_file_name_convert string
db_name string ORCL#数据库名
db_unique_name string ORCL
global_names boolean FALSE #静态注册时用到与server_names相同
instance_name string ORCL
lock_name_space string
log_file_name_convert string
service_names string ORCL #服务名
数据库名(db_name,db_unique_name)
实例名 (instance_name)
SYS ASSYSDBA@ORCL>show parameter instance_name
NAME TYPE VALUE
instance_name string ORCL
全局名global_names
服务名 (service_names)
SYS ASSYSDBA@ORCL>show parameter service_names
NAME TYPE VALUE
service_names string ORCL
Netca命令的三个文件
Listener.ora (监听器文件),启动netca后选择:监听程序配置
Tnsnames.ora (服务端,客户端使用文件) 启动netca后选择:本地net服务名配置
Sqlnet.ora (基本不用)
在服务器端,通过xmanager将图形界面映射到本地:
#xhost +
#w
#ExportDISPLAY=192.168.0.1:0.0
#su – oracle
#netca
监听器配置文件;
[oracle@oracleadmin]$ pwd
/u01/app/oracle/product/11.2.2/db_1/network/admin
[oracle@oracleadmin]$ ls
listener14111711AM1605.bak listener1808168PM2842.bak shrept.lst tnsnames1808168PM0258.bak
listener14111711AM3438.bak listener.ora tnsnames14111711AM1605.bak tnsnames1808168PM2842.bak
listener1808168PM0258.bak samples tnsnames14111711AM3438.bak tnsnames.ora
监听的配置状态信息:
[oracle@oracleadmin]$ lsnrctl status
Service"ORCL" has 1 instance(s).
Instance "ORCL", status READY, has1 handler(s) for this service...
Service"ORCLXDB" has 1 instance(s).
Instance "ORCL", status READY, has1 handler(s) for this service...
The commandcompleted successfully
1. 监听的动态注册:
默认oracle会将数据库名(service name)自动注册到监听器。
1.PMON 自动注册监听
2.强制PMON抓紧将数据库的server name 注册到监听器中。
Sql>alter system register
以上都属于动态注册~ 对应的listener.ora文件配置信息:
cat listener.ora
LISTENER =
(DESCRIPTION_LIST=
(DESCRIPTION =
(ADDRESS =(PROTOCOL = TCP)(HOST = oracle)(PORT = 1521))
)
)
ADR_BASE_LISTENER = /u01/app/oracle
ORCL =
(DESCRIPTION_LIST=
(DESCRIPTION =
(ADDRESS =(PROTOCOL = TCP)(HOST = oracle)(PORT = 1521))
)
)
ADR_BASE_ORCL = /u01/app/oracle
2.监听的静态注册:(在服务端的监听里面配置)
由于动态注册不稳定,采用静态注册方式,对应的listener.ora文件配置信息:
就在原配置文件上copy5行(下面示例第3~7行),改下global_dbname和sid_name即可~
cat listener.ora
LISTENER =
(DESCRIPTION_LIST=
(DESCRIPTION =
(ADDRESS =(PROTOCOL = TCP)(HOST = oracle)(PORT = 1521))
)
)
ADR_BASE_LISTENER = /u01/app/oracle
ORCL =
(DESCRIPTION_LIST=
(DESCRIPTION =
(ADDRESS =(PROTOCOL = TCP)(HOST = oracle)(PORT = 1521))
)
)
ADR_BASE_ORCL = /u01/app/oracle
#静态注册需要加以下内容:
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = ORCL)
(ORACLE_HOME= /u01/app/oracle/product/11.2.2/db_1)
(SID_NAME =ORCL)
)
)
注:global_dbname 与service_names一致
sid_name与instance_name一致
#以下是静态注册的信息:
[oracle@oracle admin]$ lsnrctl status #当监听器启动后,实例就已注册成功.
Services Summary...
Service "ORCL" has 1 instance(s).
Instance "ORCL", status UNKNOWN,has 1 handler(s) for this service...#UNKNOWN状态正常
The command completed successfully
#过了一段时间后,oracle又自动动态注册到监听器中:
[oracle@oracle admin]$ lsnrctl status
Services Summary...
Service "ORCL" has 2 instance(s).
Instance"ORCL", status UNKNOWN, has 1 handler(s) for this service...#静态注册
Instance "ORCL", status READY, has1 handler(s) for this service... #动态注册
Service"ORCLXDB" has 1 instance(s).
Instance "ORCL", status READY, has1 handler(s) for this service...
The commandcompleted successfully
3.双网卡双监听:
服务器一般为双网卡或多网卡,每个网卡上都配置监听可以缓解网络的压力,实现网络上的负载均衡,但这样有一定的局限性。
4.客户端tnsnames.ora配置:
ORCL =#这个名字可以任意,不区分大小写,一般与数据库名一样,这个名称是用户登录数据库时@后面的字符串
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS =(PROTOCOL = TCP)(HOST = oracle)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME= ORCL) #这个服务名字要和数据库名一样
(INSTANCE_NAME = ORCL)
)
)
使用方法:
[oracle@oracleadmin]$ sqlplus hr/hr@ORCL
SQL*Plus: Release 11.2.0.1.0 Production on 星期日 10月 14 07:41:52 2018
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0- Production
With the Partitioning, OLAP, Data Mining and RealApplication Testing options
HR @ORCL>
常见的几种连接方式:
Sqlplus hr/hr #服务器直接连接,不通过监听解析
Sqlplushr/hr@ORCL #通过监听解析连接
Sqlplus hr/hr@172.16.1.133:1521/ORCL #通过监听了,但没有通过tnsname.ora进行解析
Sqlplus / assysdba #直接通过数据库帐号密码连接
当以上连接方式无法连接数据库时的排错流程:
Lsnrctlstatus/stop/start
Alter systemregister
Tnsnames.ora
IP,端口号:服务端netstat –tulnp | gre 1521
Service_names:查看show parameter service
Tnsping:判断客户端解析是否正常
UsedTNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = oracle)(PORT = 1521))) (CONNECT_DATA =(SERVICE_NAME = ORCL) (INSTANCE_NAME = ORCL)))
OK (0 msec)