联系:手机/微信(+86 17813235971) QQ(107644445)
作者:惜分飞©版权所有[未经本人同意,不得以任何形式转载,否则有进一步追究法律责任的权利.]
今天想在家中访问下公司的oracle数据库,我了解的情况是那台服务器是有内外网ip,内网可以访问数据库。所以按照常理推断我只要配置下listener,外网应该也就可以正常访问
于是我就登陆到服务器上,修改listener.ora文件
SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (SID_NAME = PLSExtProc) (ORACLE_HOME = /opt/oracle/product/10.2.0/db_1) (PROGRAM = extproc) ) ) LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.11.12)(PORT = 1521)) (ADDRESS = (PROTOCOL = TCP)(HOST = 211.155.227.172)(PORT = 1521)) (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0)) ) )
lsnrctl start 不能正常启动,报错如下:
Error listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=211.155.227.172)(PORT=1521))) TNS-12542: TNS:address already in use TNS-12560: TNS:protocol adapter error TNS-00512: Address already in use Linux Error: 98: Address already in use
根据错误提示,意思是HOST=211.155.227.172这个(地址+端口+协议)已经被占用
第一反应:使用netstat -an|grep 1521没有发现该地址有1521端口启动,说明没有被占用
第二反应:防火墙,通过查看发现防火墙是关闭
通过以上两项查看都没有问题,那我修改下监听端口尝试下,然后我把监听端口改成了1522,监听能够正常启动,并且开始监听1522端口。通过实验证明1522端口是正常的,那问题出在哪里呢?为什么1521不行,我查看下ip地址的设置情况
eth0 Link encap:Ethernet HWaddr 00:E0:4D:C3:D5:18 inet addr:192.168.11.12 Bcast:192.168.11.255 Mask:255.255.252.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:5000774 errors:0 dropped:0 overruns:0 frame:0 TX packets:1610691 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:1828268348 (1.7 GiB) TX bytes:436101782 (415.8 MiB) eth0:1 Link encap:Ethernet HWaddr 00:E0:4D:C3:D5:18 inet addr:211.155.227.172 Bcast:211.155.227.175 Mask:255.255.255.240 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
发现192.168.11.12和211.155.227.172都是绑定在eth0的网卡上,因为监听在192.168.11.12启动了1521端口,所以211.155.227.172上的1521不能起来(因为同一张网卡)
我想既然是公用同一张网卡,那么监听了192.168.11.12:1521,那我用211.155.227.172:1521应该可以正常访问,除掉监听中的(ADDRESS = (PROTOCOL = TCP)(HOST = 211.155.227.172)(PORT = 1522)),然后直接在自己的电脑上修改tns,使用 211.155.227.172地址访问,果然能够访问。
通过这次事件得出结论:单网卡绑定多IP,只要监听主IP地址,其他绑定的IP均可以访问,不需要修改任何监听信息
问题应该是动态监听导致,换成静态监听后,一切正常
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = ecp)
(ORACLE_HOME = /opt/oracle/product/10.2.0/db_1)
(GLOBAL_DBNAME = ecp)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST =192.168.11.12)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = 211.155.227.172)(PORT = 1521))
)
)