配置数据库的网络:
如果想做服务端需要启动【监听程序】!
如果你想做一个有用的【监听程序】:
监听指定的IP
要指定监听的段口号
监听中要拥有【数据库服务】的信息
如果想做客户端需要配置【服务命名】!
合法的【服务命名】中要包含:
监听的IP地址
监听的段口号
【数据库服务】的信息
查看监听状态:
$ lsnrctl status
----------------------------------------------------------------------
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=172.25.0.10)(PORT=1521)))
Services Summary... 监听的IP 监听的端口号
Service "demo" has 1 instance(s).
【数据库服务】
Instance "demo", status READY, has 1 handler(s) for this service...
----------------------------------------------------------------------
客户端使用简单连接:无需配置
@监听的IP:监听的端口号/【数据库服务】
$ sqlplus scott/
[email protected]:1521/demo
如何修改监听配置:
监听配置文件的路径和文件名
vi $ORACLE_HOME/network/admin/listener.ora
----------------------------------------------------------------------
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.25.0.10)(PORT = 1521))
)
)
----------------------------------------------------------------------
监听配置修改之后需要重新启动监听程序
lsnrctl stop
lsnrctl start
lsnrctl status
为什么刚刚启动监听,监听中没有数据库服务?
因为数据库的信息是pmon以60秒为周期向监听程序注册!
手工调度pmon注册数据库信息到监听程序:
sqlplus / as sysdba
alter system register;
修改监听的端口号:
lsnrctl stop
vi $ORACLE_HOME/network/admin/listener.ora
----------------------------------------------------------------------
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.25.0.10)(PORT = 7788))
)
)
----------------------------------------------------------------------
pmon默认情况下只会向1521端口注册数据库信息!
如何修改pmon注册数据库信息的端口号!使用local_listener参数!
alter system set local_listener='(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=172.25.0.10)(PORT=7788)))';
local_listener参数的另一种赋值方法:
vi $ORACLE_HOME/network/admin/tnsnames.ora
---------------------------------------------------------------------------------
LISTENER_ORCL=(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=172.25.0.10)(PORT=7788)))
---------------------------------------------------------------------------------
alter system set local_listener='LISTENER_ORCL';
由pmon将数据库信息注册到监听程序叫动态注册!
动态注册在数据库停止的状态下是无法联网的!!!
将数据库服务配置为静态注册:
vi $ORACLE_HOME/network/admin/listener.ora
-----------------------------------------------------------------------
#数据库服务
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = demo)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
(SID_NAME = demo)
)
)
#监听位置
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.25.0.10)(PORT = 7788))
)
)
-----------------------------------------------------------------------
SQL> conn sys/
[email protected]:8787/demo as sysdba
Connected to an idle instance.
无配置启动监听:如果不能联网,在操作系统级别查找原因!
监听的主机是谁? /etc/hosts --> hostname
监听的端口是哪一个? 1521
数据库服务怎样这册到监听程序? 由pmon自动向1521端口注册
修改监听的名字:如果监听的名字不再使用默认名称LISTENER那么以后再操作监听的时候必须指定名称!
vi $ORACLE_HOME/network/admin/listener.ora
-----------------------------------------------------------------------
#数据库服务
SID_LIST_L2 =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = demo) <数据库唯一名+域名>
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1) <$ORACLE_HOME>
(SID_NAME = demo) <$ORACLE_SID>
)
)
#监听位置
L2 =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.25.0.10)(PORT = 7788))
)
)
-----------------------------------------------------------------------
lsnrctl stop L2
lsnrctl start L2
lsnrctl status L2
使用主机命令查看当前启动的监听别名是什么:
ps -ef | grep tnsl
/u01/app/oracle/product/11.2.0/db_1/bin/tnslsnr L2
配置客户端的服务命名:
vi $ORACLE_HOME/network/admin/tnsnames.ora
-----------------------------------------------------------------------
teacher = #服务命名
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.25.0.10)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = 123)
)
)
orcl = #服务命名
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.25.0.10)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = 123)
)
)
-----------------------------------------------------------------------
客户端网络连接@符号后面接服务命名
conn scott/tiger@teacher
conn scott/tiger@orcl