6.Configuring the Oracle Network Environment
su - grid
装grid时自动创建了监听netca--创建新的监听vi $ORACLE_HOME/network/admin/listener.ora
启动监听时会进行回环测试,如果注释掉127.0.0.1则不能启动监听。
服务:动态配置服务alter system set service_names='orcl','easthome';alter system register;静态配置服务
listener.oralsnrctl reload客户端配置:
需要先安装oracle客户端netca 配置连接方法vi $ORACLE_HOME/network/admin/sqlnet.oraNAMES.DIRECTORY_PATH= (TNSNAMES, EZCONNECT)netca 配置本地网络服务名
vi $ORACLE_HOME/network/admin/tnsnames.oraCLIENT_SERVICE = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.7)(PORT = 1521)) (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.8)(PORT = 1521)) -- 故障转移 ) (CONNECT_DATA = (SERVICE_NAME = orcl) ) ) tns ping不检测服务名,只验证ip和端口号。一个单独的监听器可以服务于多个数据库实例以及成百上千个客户端连接。
Prompt syntax:
LSNRCTL> <command name>LSNRCTL> startLSNRCTL> stopCommand-line syntax:$ lsnrctl <command name>$ lsnrctl start$ lsnrctl stop$ lsnrctl statusSRVCTL syntax:$ srvctl -h$ srvctl start listener$ srvctl stoplistener$ srvctl start listener -l mylistener$ srvctl status listenerResolving connection Information
Easy connect naming: Uses a TCP/IP connect string CONNECT username/password@host[:port][/service_name]SQL> connect hr/hr@stu1:1521/db01$ sqlplus scott/tiger@stu1:1521/db01
Local naming: Uses a local configuration filestores connect descriptiors in tnsnames.oraSQL> connect hr/hr@db01Directory naming: Uses a centralized LDAP-compliant directory serverSQL> connect hr/hr@db01External naming: Uses a supported non-oracle naming serviceTesting Oracle Net ConnectivitySupports easy connect names resolution:tnsping stu1:1521/db01Supports local and directory naming:tnsping db011) Server(Listener) configuration files:
listener.ora: # listener.ora Network Configuration File: /u01/app/grid/product/11.2.0/grid/network/admin/listener.ora# Generated by Oracle configuration tools.SID_LIST_LISTENER =
(SID_LIST = (SID_DESC = (SID_NAME = db01) (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db) (GLOBAL_DBNAME = orcl3) --静态配置的服务名 )(SID_DESC =
(SID_NAME = +ASM) (ORACLE_HOME = /u01/app/grid/product/11.2.0/grid) (GLOBAL_DBNAME = orcl4) --静态配置的服务名 ) ) LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521)) (ADDRESS = (PROTOCOL = TCP)(HOST = stu1)(PORT = 1521)) ) )ADR_BASE_LISTENER = /u01/app/gridENABLE_GLOBAL_DYNAMIC_ENDPOINT_LISTENER=ON # line added by Agent动态配置
sqlplus / as sysdba;
alter system set service_names='orcl','easthome','db01'动态注册:
alter system register;立即出发PMON进程或者等待PMON进程自动将service_name注册到监听
lsnrctl stoplsnrctl start如果还没有看到服务,说明PMON还没有到达其工作周期静态配置
需要编辑配置文件数据库关闭时只能静态注册。动态注册可以实现基于服务的负载均衡,在RAC中。 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/grid2) Client configuration files: tnsnames.ora: # tnsnames.ora Network Configuration File: /u01/app/oracle/product/11.2.0/db/network/admin/tnsnames.ora# Generated by Oracle configuration tools.DB01 = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = stu1)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = db01) ) )3) CONNECT TO ANOTHER DATABASEtnsnames.ora:REMOTE_ORCL = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP) (HOST = host02.example.com) (PORT = 1521) ) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orcl.example.com) ) )SQL*Plus:CONNECT hr/hr@orcl;CREATE DATABASE LINK remoteCONNECT TO HR IDENTIFIED BY HRUSING 'REMOTE_ORCL';SELECT * FROM employees@remote;4. Enterprise Management
$ emctl start dbconsole
https://stu1:1158/em