4 - 配置Oracle网络环境(监听配置)

第四课

4.1配置Oracle网络环境

Oracle监听(listener)是客户端连接到数据库的必经之路。
日常问题:
 我的数据库和监听都启动了,为什么我的客户端还是连不上数据库。
 为什么我的监听无法注册服务。
 为什么我能tnsping数据库,但是无法连上数据库。

监听相关配置文件:
$ORACLE_HOME/network/admin目录下
listener.ora
tnsnames.ora
sqlnet.ora

相关工具:
netca
netmgr

监听连接示意图:
在这里插入图片描述
在这里插入图片描述
当客户端成功连接到服务器之后,监听的启动和关闭不会影响已经连接的会话。
每个新的连接进来,就会产生一个对应的服务器进程。(专有服务器连接方式)
是长连接。如果中间有防火墙,可能会被防火墙干掉连接。
数据库连接故障是常见的故障之一,和监听文件的配置正确与否关系密切。
监听配置文件:

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = ouzy01)(PORT = 1521))
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
    )
  )

netstat -tunlp|grep 1521
服务注册:SQL> alter system register;
在12c中,使用LREG进程负责监听器的注册(Listener Registration)。
[oracle@ouzy01 ~]$ ps -ef|grep lreg
从12c起引入了LREG后台进程接管了这部分工作减轻PMON的工作。
一般注册时间周期为1分钟。
可以使用alter system register手工触发LREG注册(SQL窗口下。
一个监听可以同时服务多个数据库实例。

监听状态:
lsnrctl status
READY:就绪状态,代表客户端可以连接了。mount和open状态
BLOCKED:阻塞状态,客户端无法连接。nomount
UNKNOWN:静态监听 nomount状态客户端也可以连接,可以启停实例。

监听相关参数:
local_listener和remote_listener
SQL> show parameter local(单实例关注)
SQL> show parameter remote(rac多实例关注)

local_listener:
非1521的动态监听端口
本地监听,监听器和实例在同一台主机。
配置非默认端口动态监听
alter system set local_listener=listener_zydb;
alter system set local_listener=’(ADDRESS=(PROTOCOL=tcp)(HOST=ouzy01)(PORT=1522))’

服务器进程:
在这里插入图片描述
监听程序不再处理连接,所有工作都会传递到服务器进程。
ps -ef|grep LOCAL
专用服务器模式
PGA:
1.对应用程序发出的SQL语句进行语法分析。
2.排序操作。order by->磁盘排序(temp临时表空间,性能很差)

命名方法:

  1. Easy Connect 简单连接
  2. 本地命名
  3. 目录命令:集中管理,LDAP
  4. 外部命名
    在这里插入图片描述
    涉及配置文件:sqlnet.ora
    简单连接:
    只支持TCP/IP(no SSL)
    不支持连接时故障转移、源路由、负载均衡

本地连接:
支持所有协议
支持连接时故障转移、源路由、负载均衡
netmgr
在这里插入图片描述
连接时故障转移(客户端):
一个别名下将列出两个或多个监听程序地址。如果第一个地址不可用,则尝试使用第二个地址。

(ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.230.101)(PORT = 1521))
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.230.101)(PORT = 1522))
    )

在这里插入图片描述
在这里插入图片描述
负载均衡(客户端):
从地址列表中随机选择一个地址。

(ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.230.101)(PORT = 1521))
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.230.101)(PORT = 1522))
      (LOAD_BALANCE = yes)
    )

源路由:
“源路由”与Oracle Connection Manager 一起使用,后者充当Oracle Net 通信的代理服务器,使Oracle Net 通信可以安全地通过防火墙进行路由。

(ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.230.101)(PORT = 1521))
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.230.101)(PORT = 1522))
      (SOURCE_ROUTE = yes)
      (FAILOVER = false)
    )

在这里插入图片描述
在这里插入图片描述
客户端—》CMAN—》数据库
cmctl工具
在这里插入图片描述
测试Oracle网络连接:
tnsping 192.168.230.101:1521/zydb 并不验证服务名是否正确
tnsping tnszydb

用户会话:
专用服务器
共享服务器
在这里插入图片描述
在这里插入图片描述
SQL> show parameter dispat(dispatchers :分派程序)
在这里插入图片描述
不能使用共享服务器的情况:
数据库管理
备份和恢复操作
批处理和批量加载操作
数据仓库操作

配置database link:
CREATE DATABASE LINK (私有的 hr)
CREATE PUBLIC DATABASE LINK (公共的 )

create database link zylink connect to system identified by Oracle123 using 'zydb';
select * from sys.t@zylink;
create database link zylink2 connect to system identified by Oracle123 using '192.168.230.101:1521/zydb';

drop database link zylink;
drop public database link zylink;

相关视图:
DBA_DB_LINKS
不要大量使用dblink,事务,性能差。

配置静态监听:

  1. 使用netmgr配置
    在这里插入图片描述
    2.直接编辑listener.ora文件
LSNR=
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = ouzy01)(PORT = 1523))
  )

SID_LIST_LSNR =
  (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME = zytest)
      (ORACLE_HOME = /u01/app/oracle/product/12.2.0.1/db_1)
      (SID_NAME = zydb)
    )
  )

GLOBAL_DBNAME:服务名
SID_NAME:SID
使用静态监听可以远程启停实例。

总结:
动态注册的时间点:
监听先启动,实例后启动
实例先启动,监听后启动
alter system register手工注册
alter system set service_name=
RAC集群中,srvctl添加服务

监听故障处理思路:
防火墙、selinux、ip连通性、端口是否通
检查监听配置文件listener.ora,特别是主机名和IP
检查/etc/hosts文件
检查local_listener参数

连接池:
数据库连接,关闭是会非常消耗系统资源。复用这些连接。
javaweb。
dbcp,druid,c3p0等

使用jdbc连接oracle时url有2种格式

格式一:使用SID连接
jdbc:oracle:thin:@host:port:SID 
Example: jdbc:oracle:thin:@192.168.230.101:1521:zydb

格式二: 使用服务名连接
jdbc:oracle:thin:@//host:port/service_name 
Example:jdbc:oracle:thin:@//192.168.230.101:1521/zydb
如果是RAC集群,就需要使用这种连接方式。
单机->RAC   hisdb1 hisdb2

<!-- 配置数据源 -->
    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
        init-method="init" destroy-method="close">
        <!-- 基本属性 url、user、password -->
        <property name="url" value="jdbc:oracle:thin:@//192.168.230.101:1521/zydb" />
        <property name="username" value="admin" />
        <property name="password" value="123456" />

        <!-- 配置初始化大小、最小、最大 -->
        <property name="initialSize" value="10" />
        <property name="minIdle" value="10" />
        <property name="maxActive" value="20" />

        <!-- 配置获取连接等待超时的时间 -->
        <property name="maxWait" value="60000" />

    </bean>

Q1. Which two tools can be used to configure static service information in the listener.ora file? (Choose two.)
A. Oracle Net Manager
B. Oracle Enterprise Manager Cloud Control
C. Oracle Net Configuration Assistant
D. Listener Control Utility (LSNRCTL)
E. Oracle Enterprise Manager Database Express
Answer: A,B

Q2. Which two statements are true about Oracle network connections? (Choose two.)
A. A listener may listen on behalf of only one database instance at a time.
B. A server process checks a user’s authentication credentials and creates a session if the credentials are valid.
C. The listener continuously monitors a connection after the user process connects to a service handler.
D. The listener always spawns a new server process to deal with each new connection.
E. A connection request from a client is always first received by a listener running on the port that is used for the connection request for the database server.
Answer: B,E
答案解析:
A.不对,一个监听可以监听多个数据库实例
B. 正确,服务器进程将检查用户的验证身份证明(通常为口令),如果身份证明有效,则创建一个用户会话。
C.不对,当连接建立后,监听程序就不再处理连接,所有工作都会传递到服务器进程。
D.不对,如果是共享服务器,不会每次都衍生一个新的服务器进程。
E.正确,新的连接首次会连接监听器。

Q3. Your database is open and the LISTENER listener running. You stopped the wrong listener LISTENER by issuing the following command:
1snrctl > STOP
What happens to the sessions that are presently connected to the database Instance?
A. They are able to perform only queries.
B. They are not affected and continue to function normally.
C. They are terminated and the active transactions are rolled back.
D. They are not allowed to perform any operations until the listener LISTENER is started.
Answer: B

Q4. Your database is open and the listener LISTENER is up. You issue the command:
LSNRCTL> RELOAD
What is the effect of RELOAD on sessions that were originally established by LISTENER?
A. Only sessions based on static listener registrations are disconnected.
B. Existing connections are not disconnected; however, they cannot perform any operations until the listener completes the re-registration of the database instance and service handlers.
C. The sessions are not affected and continue to function normally.
D. All the sessions are terminated and active transactions are rolled back.
Answer: C

Q5. Which are two ways for a database service to be recognized by a listener in Oracle Database 12c?
A) Static registration in the listener.ora file using the service_name parameter
B) Dynamic Registration by the smon process
C) Static registration in the listener.ora file using the global_dbname parameter
D) Dynamic Registration by the pmon process
E) Dynamic Registration by the lreg process
Answer:C,E

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值