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.ora
lsnrctl reload
客户端配置:
需要先安装oracle客户端
netca 配置连接方法
vi $ORACLE_HOME/network/admin/sqlnet.ora
NAMES.DIRECTORY_PATH= (TNSNAMES, EZCONNECT)
netca 配置本地网络服务名
vi $ORACLE_HOME/network/admin/tnsnames.ora
CLIENT_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> start
LSNRCTL> stop
Command-line syntax:
$ lsnrctl <command name>
$ lsnrctl start
$ lsnrctl stop
$ lsnrctl status
SRVCTL syntax:
$ srvctl -h
$ srvctl start listener
$ srvctl stoplistener
$ srvctl start listener -l mylistener
$ srvctl status listener
Resolving 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 file
stores connect descriptiors in tnsnames.ora
SQL> connect hr/hr@db01
Directory naming: Uses a centralized LDAP-compliant directory server
SQL> connect hr/hr@db01
External naming: Uses a supported non-oracle naming service
Testing Oracle Net Connectivity
Supports easy connect names resolution:
tnsping stu1:1521/db01
Supports local and directory naming:
tnsping db01
1) 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/grid
ENABLE_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 stop
lsnrctl 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/grid
2) 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 DATABASE
tnsnames.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 remote
CONNECT TO HR IDENTIFIED BY HR
USING 'REMOTE_ORCL';
SELECT * FROM employees@remote;
4. Enterprise Management
$ emctl start dbconsole
https://stu1:1158/em