OCP课程28:管理Ⅰ之网络

课程目标:

  • 使用EM创建监听,创建网络服务别名,配置连接故障转移以及控制网络监听
  • 使用tnsping测试网络连通性
  • 专用服务器和共享服务器

1、Oracle Net服务

clipboard

Oracle Net服务在客户端或者中间件应用程序和数据库之间建立网络连接。在网络会话建立后,Oracle Net为客户端应用程序和数据库服务器扮演信使的角色。在客户端应用程序和数据库服务器之间建立和维护连接以及交换信息。Oracle Net位于需要与数据库对话的计算机上面。

在客户端计算机上面,Oracle Net是一个后台组件,服务于应用程序到数据库的连接。

在数据库服务器上面,Oracle Net包括一个称之为“Oracle Net Listener”的活动进程,它负责协调数据库和外部应用程序之间的连接。

2、Oracle Net监听

clipboard[1]

Oracle Net监听(一般简称为监听)是非本地用户连接到Oracle实例的网关,一个监听可以服务多个数据库实例及多个客户端连接。

可以通过EM访问监听,可以像控制通用参数一样控制监听的配置。也可以使用vi或者gedit等文本编辑器手工编辑监听配置文件。

如果安装了GI,则监听配置文件位于/network/admin目录下,包括listener.ora和sqlnet.ora,listener.ora配置监听,sqlnet.ora文件决定怎么样找一个连接中出现的连接字符串。

例子:查看listener.ora文件内容

[grid@oracletest1 ~]$ cat /u01/app/grid/product/11.2.0/grid/network/admin/listener.ora

# listener.ora Network Configuration File: /u01/app/grid/product/11.2.0/grid/network/admin/listener.ora

# Generated by Oracle configuration tools.

LISTENER =

  (DESCRIPTION_LIST =

    (DESCRIPTION =

      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))

      (ADDRESS = (PROTOCOL = TCP)(HOST = oracletest1)(PORT = 1521))

    )

  )

ADR_BASE_LISTENER = /u01/app/grid

ENABLE_GLOBAL_DYNAMIC_ENDPOINT_LISTENER=ON              # line added by Agent

例子:查看sqlnet.ora文件内容

[grid@oracletest1 ~]$ cat /u01/app/grid/product/11.2.0/grid/network/admin/sqlnet.ora

# sqlnet.ora Network Configuration File: /u01/app/grid/product/11.2.0/grid/network/admin/sqlnet.ora

# Generated by Oracle configuration tools.

NAMES.DIRECTORY_PATH= (TNSNAMES, EZCONNECT)

ADR_BASE = /u01/app/grid

3、创建网络连接

clipboard[2]

创建网络连接,需要如下信息:

  • 监听运行的主机地址或者主机名
  • 监听的端口
  • 监听使用的协议
  • 监听处理的服务名字

4、建立一个连接

clipboard[3]

Oracle Net名称解析完成后,连接请求就从用户或者中间层应用程序(此后称之为用户进程)发送到监听,监听接受到一个CONNECT包并检查该CONNECT包是否请求的是一个有效的Oracle Net服务名称(service name)。如果没有请求服务名称(例如tnsping),监听响应连接请求但不再需要做什么了,如果是请求的无效的服务名称,则返回一个错误。

5、用户会话

clipboard[4]

如果CONNECT包请求的是一个有效的服务名称,那么监听将会派生一个新的进程来处理这个连接,这个新的进程就是我们前面提到的服务器进程(server process),监听连接到这个进程并将用户进程的初始化信息(包括地址信息)传递给这个进程。此时,监听不再处理该连接,所有工作转交给服务器进程来处理。

服务器进程检查用户的认证信息(通常是密码),如果有效,则创建用户会话。

专有服务进程(Dedicated server process):会话建立后,服务器进程作为用户在服务器上面的代理,主要完成以下工作:

  • 解析和运行应用程序发出的SQL语句
  • 检查buffer cache是否有运行SQL语句需要的数据块
  • 如果buffer cache没有运行SQL语句需要的数据块,将会从磁盘数据文件读取必要的数据块到SGA的buffer cache
  • 管理所有的排序活动
  • 返回结果给用户进程

6、配置和管理Oracle Network的工具

EM Net Services Administration页面

Net Manager(netmgr)

Net Configuration Assistan(netca)

命令行(lsnrctl)

7、Listener Control实用程序(lsnrctl)

可以使用lsnrctl控制监听,包括启动、停止、检查状态、重载、动态配置多个监听以及修改监听密码等。

语法为:LSNRCLT>command [listener_name]

如果不指定监听名称或者没有使用set current_listener命令,则对默认监听(名称为listener)进行操作。

例子:查看lsnrctl所有可用命令

[grid@oracletest1 ~]$ lsnrctl

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 16-DEC-2015 19:46:53

Copyright (c) 1991, 2013, Oracle.  All rights reserved.

Welcome to LSNRCTL, type "help" for information.

LSNRCTL> help

The following operations are available

An asterisk (*) denotes a modifier or extended command:

start               stop                status             

services            version             reload             

save_config         trace               spawn              

change_password     quit                exit               

set*                show*              

假定监听名称为listener,则命令行语法:

clipboard[5]

交互式语法:

clipboard[6]

如果监听名称不为listener,则需要在命令后面加上监听名称或者使用SET CURRENT_LISTENER命令设置监听名称。

8、使用srvctl启动和停止监听

clipboard[7]

查看可以命令帮助:srvctl -h

启动默认监听:srvctl start listener

停止默认监听:srvctl stop listener

启动名称为mylistener的监听:srvctl start listener -l mylistener

显示默认监听状态:srvctl status listener

例子:停止和启动监听

[grid@oracletest1 ~]$ srvctl stop listener

[grid@oracletest1 ~]$ srvctl status listener

Listener LISTENER is enabled

Listener LISTENER is not running

[grid@oracletest1 ~]$ srvctl start listener

[grid@oracletest1 ~]$ srvctl status listener

Listener LISTENER is enabled

Listener LISTENER is running on node(s): oracletest1

9、使用EM管理监听

进入监听主页可以看到:

  • 监听状态
  • 监听版本以及Oracle home
  • 监听配置文件位置
  • 监听启动时间以及主机信息
  • Oracle Restart状态

clipboard[8]

clipboard[9]

点击“Net Service管理”进入Net Service管理页面。

clipboard[10]

clipboard[11]

创建一个监听

clipboard[12]

clipboard[13]

clipboard[14]

clipboard[15]

clipboard[16]

clipboard[17]

clipboard[18]

clipboard[19]

clipboard[20]

10、数据库服务注册

客户端连接到实例的时候,监听必须要获取实例的名字以及实例的ORACLE_HOME位置,有以下2种方法可以获取:

  • 动态服务注册(Dynamic Service registration):Oracle 8i以及后续的版本可以在数据库启动的时候自动注册到默认监听,不需要额外的配置,
  • 静态服务注册(Static Service registration):Oracle早期版本不能自动注册,因此需要一个包含所有数据库服务列表的监听配置文件listener.ora。现在的版本也可以在以下情况使用静态服务注册:
    • 监听不在默认端口1521
    • 应用需要静态服务注册

添加静态服务注册

clipboard[21]

clipboard[22]

输入服务名(与全局数据库名相同 .),ORACLE_HOME路径,和SID(与实例名相同),需要重载(reload)或者重启(restart)监听。

clipboard[23]

clipboard[24]

clipboard[25]

clipboard[26]

客户端连接到实例可以使用SERVICE_NAMES初始化参数,数据库将服务名注册到监听,当一个客户端请求一个服务,监听通过服务名决定哪一个实例响应服务并路由客户端到该实例。

可以为一个数据库指定多个服务名来区分不同的用户,例如:SERVICE_NAMES = sales.example.com, eurosales.example.com。

11、命名方法

clipboard[27]

Oracle Net有多种方法解析连接信息:

  • 简单连接命名:客户端连接到数据库服务器使用TCP/IP连接串,包括主机名或IP地址,端口以及服务名,格式为:CONNECT username/password@host[:port][/service_name]
  • 本地命名:使用本地配置文件tnsnames.ora中的连接串
  • 目录命名:使用兼容的LDAP目录服务器
  • 外部命名:NIS等

12、简单连接

  • 默认启用
  • 不需要客户端配置
  • 只支持TCP/IP(no  SSL)
  • 不支持高级连接选项,比如:
    • 故障切换
    • 资源路由
    • 负载均衡

clipboard[28]

使用简单连接,需要提供所有信息,使用下面的格式:

/@:/

13、本地命名

  • 要求客户端名称解析文件tnsnames.ora
  • 支持所有Oracle Net协议
  • 支持高级连接选项,比如:
    • 故障切换
    • 资源路由
    • 负载均衡

clipboard[29]

使用本地命名,用户需要为Oracle Net service提供一个别名,相比简单连接只需记住一个简短的别名,Oracle Net将别名与已知服务名的本地列表进行对比,服务名的本地列表存储在客户端的文本文件/network/admin/tnsnames.ora中,可以使用TNS_ADMIN环境变量修改这个默认位置,经常用于应用程序与数据库的连接。

clipboard[30]

14、目录命名

  • 要求LDAP,使用Oracle Internet Directory或者Microsoft Active Directory Services
  • 支持所有Oracle Net协议
  • 支持高级连接选项

clipboard[31]

使用目录命名的一个优势就是新的服务名加入到LDAP中,所有用户都可以立即使用了,如果使用本地命名,则还需要手动去更新每个用户的tnsnames.ora文件。

15、使用EM配置服务别名

clipboard[32]

clipboard[33]

clipboard[34]

clipboard[35]

clipboard[36]

clipboard[37]

16、高级连接选项

Oracle Net使用本地命名和目录命名支持下面的高级连接选项

  • 故障切换
  • 资源路由
  • 负载均衡

clipboard[38]

clipboard[39]

17、测试Oracle Net连接

使用与ping类似的tnsping工具测试Oracle Net服务别名:

  • 在客户端和服务器端确认连接
  • 不验证请求的服务是否可用
  • 支持简单连接
  • 支持本地和目录命名

该工具只验证到达监听的主机名(IP),端口和协议,不去检查监听是否处理对应的服务。

例子:使用tnsping测试

C:\Users\shilei>tnsping 192.168.230.139:1521/stone

TNS Ping Utility for 32-bit Windows: Version 11.2.0.1.0 - Production on 17-12月-

2015 08:25:43

Copyright (c) 1997, 2010, Oracle.  All rights reserved.

已使用的参数文件:

E:\app\shilei\product\11.2.0\client_2\network\admin\sqlnet.ora

已使用 EZCONNECT 适配器来解析别名

尝试连接 (DESCRIPTION=(CONNECT_DATA=(SERVICE_NAME=stone))(ADDRESS=(PROTOCOL=TCP)

(HOST=192.168.230.139)(PORT=1521)))

OK (10 毫秒)

C:\Users\shilei>tnsping asm139

TNS Ping Utility for 32-bit Windows: Version 11.2.0.1.0 - Production on 17-12月-

2015 08:25:55

Copyright (c) 1997, 2010, Oracle.  All rights reserved.

已使用的参数文件:

E:\app\shilei\product\11.2.0\client_2\network\admin\sqlnet.ora

已使用 TNSNAMES 适配器来解析别名

尝试连接 (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.1

68.230.139)(PORT = 1521)) (LOAD_BALANCE = yes)) (CONNECT_DATA = (SERVICE_NAME =

stone)))

OK (0 毫秒)

18、用户会话:专用服务器进程

clipboard[40]

使用专用服务器进程,一个服务器进程对应一个用户进程,每一个服务器进程使用系统资源,包括CPU和内存。

在大负载系统环境,专有服务器进程的内存和CPU资源限制了系统的扩展,如果在专业服务器进程架构下出现资源不足的情况,可以使用:

  • 通过增加内存和CPU提高系统性能
  • 使用共享服务器进程架构

19、用户会话:共享服务器进程

clipboard[41]

在共享服务器进程架构中,每一个服务都至少有一个调度进程,当出现连接请求,监听不会派生专用服务器进程,而是维护一个每一个服务名可用的调度器列表,以及每个调度器的连接负载(并发连接数)。连接请求会被路由到负载最小的调度器上。在一个会话期间,用户保持连接到同一个调度器。与专用服务器进程不同,单个调度器可以管理多个用户会话。实际上调度器不处理用户请求,而是将请求转发给位于SGA中共享池的队列。

20、SGA和PGA

clipboard[42]

专用服务器和共享服务器的SGA和PGA的内存结构不同,共享服务器的UGA位于SGA中:

  • SQL语句的内容和解析存储在SGA中
  • SQL语句的运行内存值存储在游标状态区,比如行数
  • 安全和资源使用信息存储在用户会话区
  • 本地变量存储在堆栈空间

如果配置了大池或者使用自动内存管理,则UGA位于大池内。

21、连接池

clipboard[43]

在这个例子中,数据库服务器配置有255个连接。其中一个客户端空闲超时。连接池可以将这个连接提供给其他客户连接,这是第256个连接。当空闲客户端需要重新建立连接,则使用其他的空闲超时客户端。

22、为什么不使用共享服务器

下列情况不能使用共享服务器:

  • 数据库管理
  • 备份和恢复操作
  • 批处理操作
  • 数据仓库操作

由于调度器的排队机制,在处理大量数据的时候性能不好,比如数据仓库或者批处理操作,RMAN的备份和恢复操作以及处理大量数据的时候就必须使用专用服务器模式。

包括启动和停止实例,创建表空间和数据文件,维护索引和表,分析统计信息以及其他DBA进行的维护维护操作不能使用共享服务器,所有的DBA会话必须选择专用服务器。

23、在数据库之间创建连接

通过创建database link模式对象在数据库之间建立连接。

语法:

clipboard[44]

其中''既可以使用简单连接,也可以使用本地命名或者目录命名,如果使用本地命名,需要先配置tnsnames.ora文件。

例子:创建database link并通过数据字典查看

SQL> conn hr/hr

Connected.

SQL> create database link remote1

  2  connect to hr identified by hr

  3  using '192.168.230.138:1521/stone';

Database link created.

SQL> select count(*) from employees@remote1;

  COUNT(*)

----------

       107

SQL> desc user_db_links;

Name                                      Null?    Type

----------------------------------------- -------- ----------------------------

DB_LINK                                   NOT NULL VARCHAR2(128)

USERNAME                                           VARCHAR2(30)

PASSWORD                                           VARCHAR2(30)

HOST                                               VARCHAR2(2000)

CREATED                                   NOT NULL DATE

SQL> select * from user_db_links;

DB_LINK    USERNAME   PASSWORD   HOST                           CREATED

---------- ---------- ---------- ------------------------------ ------------

REMOTE1    HR                    192.168.230.138:1521/stone     17-DEC-15

24、相关习题

(1)Your  database  is  open  and  the  LISTENER  listener  is  running.  The  new  DBA  of  the  system stops the listener by using the command:
   LSNRCTL> STOP
What happens to the sessions that are presently connected to the database instance?
A.  The sessions are able to perform only queries
B.  The sessions are not affected and continue to function normally
C.  The sessions are terminated and the active transactions are rolled back
D.  The sessions are not allowed to perform any operations till the listener is started

 

答案:B

 

 

(2)Your database is configured in shared server mode. However, your senior DBA asks you to modify the value of the PRIVATE_SGA limit in the profile of the users. 

What could be the reason for this?
A.  To limit the User Global Area (UGA) memory allocated to a session from the SGA
B.  To limit the amount of memory to be used for the dispatcher queue of a session in SGA
C.  To limit the amount of memory to be used for the request pool in System Global Area (SGA)
D.  To control the amount of memory allocated in SGA for the local variables for each shared server process

 

答案:A

 

 

(3)In which situation would you use static database registration for a listener?
A.  When multiple databases are to be registered with the listener
B.  When DBAs need to connect remotely to start up the database instance
C.  When users need to connect the database instance using the host naming method
D.  When the database instance that is to be registered with the listener is configured in shared server mode

 

答案;B

 

 

(4)Observe the information in the columns:
1. The SGA                   a. Text and parsed forms of all SQL statements
2. The cursor state        b. Run-time memory values for the SQL statement, such as rows retrieved
3. User-session data     c. Security and resource usage information
4. The stack space        d. Local variables for the process
Which option has the correct match between the memory areas and their contents?
A.  1-c, 2-b, 3-d, 4-a
B.  1-b, 2-c, 3-d, 4-a
C.  1-a, 2-b, 3-c, 4-d
D.  1-a, 2-b, 3-d, 4-c

 

答案:C

 

 

(5)Which naming method uses the tnsnames.ora file to store the connect descriptor used by the client while connecting to the database instance from a remote machine?
A.  Host naming method
B.  Local naming method
C.  External naming method
D.  Directory naming method

 

答案:B

 

 

(6)View the Exhibit and examine the output.
Which two statements are true regarding the LISTENER2 listener? (Choose two.)
clipboard[45]
A.  The ORCL instance is registered dynamically with the listener.
B.  The ORCL instance is registered statically in the listener.ora file.
C.  The number of current client connections handled by the service handler is two.
D.  The total number of client connections handled so far by the service handler is two.

 

答案:BD

 

 

(7)Which two statements are true regarding listeners? (Choose two.)
A.  Listeners use only the TCP/IP protocol.
B.  Multiple listener processes can run simultaneously on a host.
C.  Multiple database instances can be registered with a single listener.
D.  The listener-related errors can be traced only at the administrative level.
E.  Only one database instance can be registered with a single listener at any time.

 

答案:BC

 

 

(8)You  have  two  database  servers  SEMP  and  SACCT.  The  database  in  the  SEMP  server maintains  the  employee  information  and  the  database  in  the  SACCT  server  maintains  the accounts  payable  information.  The  employees  submit  the  expense  reports  to  the  accounts payable department. A user of the accounts payable database wants to extract the employee information from the database in the SEMP server for cross-verification.
Which schema object enables the user to access the information from the remote database?
A.  Cluster
B.  Database link
C.  Mapping table
D.  Materialized view

 

答案:B

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/28536251/viewspace-1976971/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/28536251/viewspace-1976971/

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值