local_listener参数(2)---elaine

第五步,配置listener.oratnsnames.ora文件,内容如下:

#############################listener.ora##################################

LISTENER=

  (DESCRIPTION=

    (ADDRESS_LIST=

      (ADDRESS=(PROTOCOL=tcp)(HOST=secdb1)(PORT=1521))

      (ADDRESS=(PROTOCOL=ipc)(KEY=extproc))))

LSNR2=

  (DESCRIPTION=

    (ADDRESS_LIST=

      (ADDRESS=(PROTOCOL=tcp)(HOST=secdb1)(PORT=1526))

      (ADDRESS=(PROTOCOL=ipc)(KEY=extproc1))))

SID_LIST_LISTENER=

  (SID_LIST=

    (SID_DESC=

      (GLOBAL_DBNAME=PROD)

      (ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1)

      (SID_NAME=PROD))

    (SID_DESC=

      (SID_NAME=plsextproc)

      (ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1)

      (PROGRAM=extproc)))

############################################################################

###################################tnsnames.ora#############################

LSNR2=

      (ADDRESS=(PROTOCOL=tcp)(HOST=secdb1)(PORT=1526))

PROD=

 (description=

  (address=(protocol=tcp)(host=secdb1)(port=1521))

  (connect_data=

    (service_name=PROD)

    (server=dedicated)))

PROD_S=

 (description=

  (address=(protocol=tcp)(host=secdb1)(port=1526))

  (connect_data=

    (service_name=PROD)

    (server=SHARED)))

PROD_1526=

 (description=

  (address=(protocol=tcp)(host=secdb1)(port=1526))

  (connect_data=

    (service_name=PROD)

    (server=dedicated)))

 

第六步,修改local_listener参数

SYS@PROD>show parameter local

 

NAME                   TYPE        VALUE

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

local_listener             string

log_archive_local_first              boolean     TRUE

SYS@PROD>alter system set local_listener='LSNR2';

 

System altered.

 

SYS@PROD>show parameter local_listener

 

NAME                   TYPE        VALUE

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

local_listener              string      LSNR2

 

第七步,先停掉刚才启动的监听

LSNRCTL> stop

Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))

The command completed successfully

 

第八步,先后启动两个监听listener    lsnr2

LSNRCTL> start listener

Starting /u01/app/oracle/product/10.2.0/db_1/bin/tnslsnr: please wait...

 

TNSLSNR for Linux: Version 10.2.0.1.0 - Production

System parameter file is /u01/app/oracle/product/10.2.0/db_1/network/admin/liste ner.ora

Log messages written to /u01/app/oracle/product/10.2.0/db_1/network/log/listener .log

Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=secdb1.localdomain)(PORT =1521)))

Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=extproc)))

 

Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))

STATUS of the LISTENER

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

Alias                     listener

Version                   TNSLSNR for Linux: Version 10.2.0.1.0 - Production

Start Date                26-JUL-2012 21:40:56

Uptime                    0 days 0 hr. 0 min. 0 sec

Trace Level               off

Security                  ON: Local OS Authentication

SNMP                      OFF

Listener Parameter File   /u01/app/oracle/product/10.2.0/db_1/network/admin/list ener.ora

Listener Log File         /u01/app/oracle/product/10.2.0/db_1/network/log/listen er.log

Listening Endpoints Summary...

  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=secdb1.localdomain)(PORT=1521)))

  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=extproc)))

Services Summary...

Service "PROD" has 1 instance(s).

  Instance "PROD", status UNKNOWN, has 1 handler(s) for this service...

Service "plsextproc" has 1 instance(s).

  Instance "plsextproc", status UNKNOWN, has 1 handler(s) for this service...

The command completed successfully

 

 

LSNRCTL> start lsnr2

Starting /u01/app/oracle/product/10.2.0/db_1/bin/tnslsnr: please wait...

 

TNSLSNR for Linux: Version 10.2.0.1.0 - Production

System parameter file is /u01/app/oracle/product/10.2.0/db_1/network/admin/listener.ora

Log messages written to /u01/app/oracle/product/10.2.0/db_1/network/log/lsnr2.log

Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=secdb1.localdomain)(PORT=1526)))

Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=extproc1)))

 

Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=secdb1)(PORT=1526))

STATUS of the LISTENER

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

Alias                     lsnr2

Version                   TNSLSNR for Linux: Version 10.2.0.1.0 - Production

Start Date                26-JUL-2012 21:42:20

Uptime                    0 days 0 hr. 0 min. 0 sec

Trace Level               off

Security                  ON: Local OS Authentication

SNMP                      OFF

Listener Parameter File   /u01/app/oracle/product/10.2.0/db_1/network/admin/listener.ora

Listener Log File         /u01/app/oracle/product/10.2.0/db_1/network/log/lsnr2.log

Listening Endpoints Summary...

  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=secdb1.localdomain)(PORT=1526)))

  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=extproc1)))

The listener supports no services

The command completed successfully

 

 

第九步,等待一会后(即,等待PMON把实例注册到监听上),查看两个监听的状态

LSNRCTL> status listener

Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))

STATUS of the LISTENER

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

Alias                     listener

Version                   TNSLSNR for Linux: Version 10.2.0.1.0 - Production

Start Date                26-JUL-2012 22:27:21

Uptime                    0 days 0 hr. 1 min. 47 sec

Trace Level               off

Security                  ON: Local OS Authentication

SNMP                      OFF

Listener Parameter File   /u01/app/oracle/product/10.2.0/db_1/network/admin/listener.ora

Listener Log File         /u01/app/oracle/product/10.2.0/db_1/network/log/listener.log

Listening Endpoints Summary...

  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=secdb1.localdomain)(PORT=1521)))

  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=extproc)))

Services Summary...

Service "PROD" has 1 instance(s).

  Instance "PROD", status UNKNOWN, has 1 handler(s) for this service...

Service "plsextproc" has 1 instance(s).

  Instance "plsextproc", status UNKNOWN, has 1 handler(s) for this service...

The command completed successfully

 

LSNRCTL> status lsnr2

Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=secdb1)(PORT=1526))

STATUS of the LISTENER

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

Alias                     lsnr2

Version                   TNSLSNR for Linux: Version 10.2.0.1.0 - Production

Start Date                26-JUL-2012 22:26:56

Uptime                    0 days 0 hr. 2 min. 22 sec

Trace Level               off

Security                  ON: Local OS Authentication

SNMP                      OFF

Listener Parameter File   /u01/app/oracle/product/10.2.0/db_1/network/admin/listener.ora

Listener Log File         /u01/app/oracle/product/10.2.0/db_1/network/log/lsnr2.log

Listening Endpoints Summary...

  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=secdb1.localdomain)(PORT=1526)))

  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=extproc1)))

Services Summary...

Service "PROD" has 1 instance(s).

  Instance "PROD", status READY, has 1 handler(s) for this service...

Service "PROD_XPT" has 1 instance(s).

  Instance "PROD", status READY, has 1 handler(s) for this service...

The command completed successfully

 

 

结论:(3oracle实例在启动过程中,或使用命令ALTER SYSTEM REGISTER,或每隔一分钟,PMON进程会向监听进行动态注册。如果是先启动的监听,后起的实例,那么实例会迅速动态注册到监听上;如果是先启动的实例,再启动的监听,那么要等待PMON进程的轮询时间到了之后才能注册到监听上~~~~~为了减少等待时间,就可以使用命令alter system register进行快速注册。

《官方文档》上的原话:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~When alistener starts after the Oracle instance starts, and the listener is listed for service registration, registration does not occur until the next time the Oracle Database process monitor (PMON) discovery routine starts. By default, PMON discovery occurs every 60 seconds.

To override the 60-second delay, use the SQL ALTER SYSTEM REGISTER statement. This statement forces the PMON process to register the service immediately.

Oracle recommends that you create a script. to run this statement immediately after starting the listener. If you run this statement while the listener is up and the instance is already registered, or while the listener is down, then the statement has no effect.~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

 

 

~~新手上路,多多指教~~

   小妞elaine


 

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

转载于:http://blog.itpub.net/26863369/viewspace-737094/

static int smart_relay_context_init_event(smart_relay_context_t *smart_relay_ctx) { if ( NULL == smart_relay_ctx ) { return -1; } smart_relay_ctx->base = event_base_new(); if( NULL == smart_relay_ctx->base ) { TPLOG_ERR("error: failed when initiating base event.\n"); return -1; } // signal handler smart_relay_ctx->ev_sigint = evsignal_new(smart_relay_ctx->base, SIGINT, cb_signal_quit, smart_relay_ctx); smart_relay_ctx->ev_sigterm = evsignal_new(smart_relay_ctx->base, SIGTERM, cb_signal_quit, smart_relay_ctx); if( !smart_relay_ctx->ev_sigint || !smart_relay_ctx->ev_sigterm ) { TPLOG_ERR("error: failed when initiating signal handler.\n"); return -1; } event_add(smart_relay_ctx->ev_sigint, NULL); event_add(smart_relay_ctx->ev_sigterm, NULL); // local listener struct sockaddr_in addr; memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_addr.s_addr = inet_addr(smart_relay_ctx->local_address); addr.sin_port = htons(smart_relay_ctx->local_port); PRINTF0("new bind to addr[%s:%d]\n",smart_relay_ctx->local_address, smart_relay_ctx->local_port); smart_relay_ctx->lev = evconnlistener_new_bind(smart_relay_ctx->base, cb_local_accept, smart_relay_ctx, LEV_OPT_REUSEABLE | LEV_OPT_CLOSE_ON_EXEC, 6, (struct sockaddr *) &addr, sizeof(addr)); if( !smart_relay_ctx->lev ) { TPLOG_ERR("error: failed when binding to addr[%s:%d]\n", smart_relay_ctx->local_address, smart_relay_ctx->local_port); return -1; } evutil_make_socket_nonblocking(evconnlistener_get_fd(smart_relay_ctx->lev)); evutil_make_listen_socket_reuseable(evconnlistener_get_fd(smart_relay_ctx->lev)); return 0; }这段代码什么作用
最新发布
06-21
这段代码的作用是初始化一个基于 `libevent` 库的事件处理系统,用于实现一个智能中继(smart relay)程序的事件驱动功能。它主要包括以下几个部分:创建事件基(event base)、设置信号处理器、绑定本地监听器以接受连接请求。 --- ### 代码功能分解 1. **函数签名**: ```c static int smart_relay_context_init_event(smart_relay_context_t *smart_relay_ctx) ``` - `smart_relay_ctx`:指向 `smart_relay_context_t` 类型的指针,用于存储事件相关的上下文信息。 2. **创建事件基**: - 调用 `event_base_new()` 创建一个新的事件基(`event_base`),这是 `libevent` 的核心对象,负责管理所有事件。 - 如果创建失败,返回错误。 3. **设置信号处理器**: - 使用 `evsignal_new` 创建两个信号事件处理器,分别处理 `SIGINT` 和 `SIGTERM` 信号。 - 这些信号通常用于优雅地关闭程序。 - 将信号事件添加到事件基中,使用 `event_add`。 4. **绑定本地监听器**: - 定义并初始化一个 `struct sockaddr_in` 结构体,表示本地地址和端口。 - 调用 `evconnlistener_new_bind` 创建一个监听器,用于接受来自客户端的连接请求。 - 设置监听器选项为 `LEV_OPT_REUSEABLE | LEV_OPT_CLOSE_ON_EXEC`,确保端口可重用并在执行时关闭。 - 如果绑定失败,返回错误。 5. **设置套接字为非阻塞模式**: - 使用 `evutil_make_socket_nonblocking` 将监听器的文件描述符设置为非阻塞模式。 - 使用 `evutil_make_listen_socket_reuseable` 确保监听套接字可以重用地址。 6. **返回值**: - 如果所有操作成功,返回 `0`;否则返回 `-1`。 --- ### 示例代码 以下是一个完整的示例,展示如何使用该函数: ```c #include <stdio.h> #include <stdlib.h> #include <string.h> #include <event2/event.h> #include <event2/listener.h> #include <event2/util.h> #define TPLOG_ERR(fmt, ...) fprintf(stderr, fmt, ##__VA_ARGS__) #define PRINTF0(fmt, ...) printf(fmt, ##__VA_ARGS__) typedef struct { struct event_base *base; struct event *ev_sigint; struct event *ev_sigterm; struct evconnlistener *lev; char local_address[256]; int local_port; } smart_relay_context_t; static void cb_signal_quit(evutil_socket_t fd, short what, void *arg) { smart_relay_context_t *ctx = (smart_relay_context_t *)arg; if (ctx && ctx->base) { event_base_loopexit(ctx->base, NULL); } } static void cb_local_accept(struct evconnlistener *listener, evutil_socket_t fd, struct sockaddr *address, int socklen, void *ctx_arg) { smart_relay_context_t *ctx = (smart_relay_context_t *)ctx_arg; PRINTF0("Accepted connection from %s\n", evutil_inet_ntop(address->sa_family, &((struct sockaddr_in *)address)->sin_addr, NULL, 0)); // 处理新连接... } static int smart_relay_context_init_event(smart_relay_context_t *smart_relay_ctx) { if (NULL == smart_relay_ctx) { return -1; } smart_relay_ctx->base = event_base_new(); if (NULL == smart_relay_ctx->base) { TPLOG_ERR("error: failed when initiating base event.\n"); return -1; } // signal handler smart_relay_ctx->ev_sigint = evsignal_new(smart_relay_ctx->base, SIGINT, cb_signal_quit, smart_relay_ctx); smart_relay_ctx->ev_sigterm = evsignal_new(smart_relay_ctx->base, SIGTERM, cb_signal_quit, smart_relay_ctx); if (!smart_relay_ctx->ev_sigint || !smart_relay_ctx->ev_sigterm) { TPLOG_ERR("error: failed when initiating signal handler.\n"); return -1; } event_add(smart_relay_ctx->ev_sigint, NULL); event_add(smart_relay_ctx->ev_sigterm, NULL); // local listener struct sockaddr_in addr; memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_addr.s_addr = inet_addr(smart_relay_ctx->local_address); addr.sin_port = htons(smart_relay_ctx->local_port); PRINTF0("new bind to addr[%s:%d]\n", smart_relay_ctx->local_address, smart_relay_ctx->local_port); smart_relay_ctx->lev = evconnlistener_new_bind(smart_relay_ctx->base, cb_local_accept, smart_relay_ctx, LEV_OPT_REUSEABLE | LEV_OPT_CLOSE_ON_EXEC, 6, (struct sockaddr *)&addr, sizeof(addr)); if (!smart_relay_ctx->lev) { TPLOG_ERR("error: failed when binding to addr[%s:%d]\n", smart_relay_ctx->local_address, smart_relay_ctx->local_port); return -1; } evutil_make_socket_nonblocking(evconnlistener_get_fd(smart_relay_ctx->lev)); evutil_make_listen_socket_reuseable(evconnlistener_get_fd(smart_relay_ctx->lev)); return 0; } int main() { smart_relay_context_t ctx = {0}; strcpy(ctx.local_address, "127.0.0.1"); ctx.local_port = 8080; if (smart_relay_context_init_event(&ctx) != 0) { fprintf(stderr, "Failed to initialize event context.\n"); return EXIT_FAILURE; } event_base_dispatch(ctx.base); // 清理资源 if (ctx.ev_sigint) event_del(ctx.ev_sigint); if (ctx.ev_sigterm) event_del(ctx.ev_sigterm); if (ctx.lev) evconnlistener_free(ctx.lev); if (ctx.base) event_base_free(ctx.base); return EXIT_SUCCESS; } ``` --- ### 解释代码 1. **事件基初始化**: - `event_base_new` 创建一个事件基,它是 `libevent` 的核心对象,用于管理所有事件。 2. **信号处理器**: - 使用 `evsignal_new` 创建信号事件处理器,处理 `SIGINT` 和 `SIGTERM` 信号。 - 当收到这些信号时,调用回调函数 `cb_signal_quit`,停止事件循环。 3. **本地监听器**: - 使用 `evconnlistener_new_bind` 创建一个监听器,绑定到指定的本地地址和端口。 - 当有新的连接请求时,调用回调函数 `cb_local_accept`。 4. **套接字设置**: - 使用 `evutil_make_socket_nonblocking` 将监听器的文件描述符设置为非阻塞模式。 - 使用 `evutil_make_listen_socket_reuseable` 确保监听套接字可以重用地址。 5. **主函数**: - 初始化 `smart_relay_context_t` 实例并调用初始化函数。 - 调用 `event_base_dispatch` 启动事件循环。 --- ###
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值