OCM培训课程- Server config 之网络配置
最新学讯:近期OCP认证正在报名中,因考试人员较多请尽快报名获取最近考试时间,报名费用请联系在线老师,甲骨文官方认证,报名从速!
我要咨询OCM培训课程- Server config 之网络配置
OCM考试大纲关于network配置的要求
一 Server Configuration
﹡ Create and manage multiple network configuration files
﹡ Create and configure a listener
﹡ Set up network tracing
Oracle网络配置主要包括对listener、本地命名服务的配置,下述内容概括了网络配置的主要知识点:
1、 怎么创建第一个listener
创建数据库之前,最好先创建listener。可以通过oui、netca、netmgr等Oracle提供图形化工具,也可以通过编辑listener.ora文件来创建listener(使用图形化工具也是对listener.ora文件作了修改)。创建第一个listener后(采用默认1521端口),listener.ora内容如下:
LISTENER=
(DESCRIPTION=
(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.155.2)(PORT=1521))
(ADDRESS=(PROTOCOL=ipc)(KEY=extproc))))
# 上面部分定义listener名称、服务器地址和端口
SID_LIST_LISTENER=
(SID_LIST=
(SID_DESC=
(SID_NAME=plsextproc)
(ORACLE_HOME=/oracle10g)
(PROGRAM=extproc)))
# 上面部分定义需要静态注册的服务,静态注册和动态注册的区别见后面,这里是提供给C、C++等程序访问数据库的外部程序接口进行静态注册,这类接口不能采用动态注册。
2、怎么为listener增加IP
为了满足网络冗余功能,如在服务器具有多块网卡的情况下,可以为一个listener绑定多个ip。同样可以通过netca、netmgr等图形化工具,或直接通过编辑listener.ora来实现。增加ip后的listener.ora文件内容为:
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.155.2)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.155.10)(PORT = 1521))
)
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
)
)
# 192.168.155.10是为listener新增加的ip
SID_LIST_LISTENER =
(SID_LIST =
4 (SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = /u01/app/oracle/product/10.2.0/db_1)
(PROGRAM = extproc)
)
)
3、怎么为listener配置多个监听端口(同一IP)
在同一IP地址上为listener增加端口1525:
修改listener.ora
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.155.100)(PORT = 1525)) - 增加新的监听端口
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.155.100)(PORT = 1521))
)
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
)
)
修改tnsnames.ora
OA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.155.100)(PORT = 1525)) - 服务能解析到新端口
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.155.100)(PORT = 1521))
)
(LOAD_BALANCE = YES) - 可选
(FAILOVER = YES) - 可选
(CONNECT_DATA =
(SERVICE_NAME = oa.Oracle.com)
)
)
由于采用了非默认端口(1525),如果要实现动态注册设置local_listener参数,先在tnsnames.ora中配置(如果采用静态注册,则只需要在listener.ora中修改SID_LIST_LISTENERNAME,加入service配置):
LOCAL_LISTENER =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.155.100)(PORT = 1525))
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.155.100)(PORT = 1521))
)
)
然后修改local_listener参数:
Sql> alter system set local_listener=LOCAL_LISTENER scope=both;
4、 增加新的listener
可以通过创建多个listener,实现listener冗余。可以通过图形化工具或编辑listener.ora实现,增加后listener.ora内容为:
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.155.2)(PORT = 1521))
)
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
)
)
LISTENER1 =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.155.10)(PORT = 1521))
)
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
)
)
#新增listener1,ip为192.168.155.10
SID_LIST_LISTENER =
(SID_LIST =
4 (SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = /u01/app/oracle/product/10.2.0/db_1)
(PROGRAM = extproc)
)
)
5、 管理远程服务器上的listener
注:这个知识点OCM应该不会考,但最近安全检查时,常碰到关于给listner设置密码,防止远程非法关掉listener的情况。通过下面的例子说明如何远程关闭listener。Oracle 10g已经从产品层面防止了该隐患。
要求:在主机host1上,远程关闭主机host2上的listner。
1) 在host1上的listener.ora文件中定义host2上的listener: LISTENER_HOST2 = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = host2)(PORT = 1521)(IP = FIRST)) ) )
2) 在host1上的tnsnames.ora文件对前面定义的host2上的listener做命名解析: Listener_host2 = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = host2)(PORT = 1521)) )
3) 在host1上关闭host2上的listener 在host1上: Lsnrctl > set curr listener_host2 Lsnrctl> status Lsnrctl> stop 如果在listener上没有设置密码,将会被直接关闭。在host2上为listener设置密码:
lsnrctl> set curr listener
lsnrctl> set password
lsnrctl> save_config
1.5 开启listener trace功能
1) 开启trace
lsnrctl> trace admin listener_name
在$ORACLE_HOME/network/trace/listener_name.trc将产生,记录listener对远程连接的处理情况。
2) 关闭trace
lsnrctl> trace off;
6、 动态注册与静态注册
Oracle实例启动后需要把service通知listener,这个过程称为注册。注册分为两种方式:动态注册和静态注册。
1) 动态注册
实例通过PMON进程,自动将service注册到listener,service定义在service_names参数中。PMON进程每隔一分钟自动检查是否新的service需要注册,如果希望手工立即注册,可以执行如下命令:
sql> alter system register;
采用动态注册,则不再需要listener.ora文件。
下面是配置service动态注册的例子:
修改service_names参数:
sql> alter system set service_names='orcl,erp'; -- 新增加service的名称为erp
修改tnsnames.ora,对service做解析,增加以下部分:
ERP =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = hostname)(PORT = 1521))
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = erp)
)
)
将erp服务注册到listener:
sql> alter system register;
查看注册到listener的service:
$ lsnrctl status
Service "erp" has 1 instance(s).
Instance "orcl", status READY, has 4 handler(s) for this service...
#状态READY代表是采用了动态注册方式。
2)静态注册
将要注册的service增加到listener.ora中,listener启动时读取listener.ora中定义的service并将其注册。
如listener.ora增加erp服务:
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = erp) -- global_dbname这里代表service名称
(ORACLE_HOME = /u01/app/oracle/product/10.2.0/db_1)
(SID = orcl)
)
)
在tnsnames.ora解析erp服务,方法同动态注册。
启动listener:
$ lsnrctl stop;
当前注册到listener的服务状态:
Service "erp" has 1 instance(s).
Instance "erp", status UNKNOWN, has 1 handler(s) for this service...
服务状态unknonw,代表服务是静态注册到listener。