今天在做ORACLE数据库和torquebox的连接
在配置好driver之后 rake的时候发现如下异常:
java.sql.SQLRecoverableException: IO Error: The Network Adapter could not establish the connection>
数据库链接失败..
打开sqlplus 链接一切正常..
反复修改database.yaml后,仍然报错。
于是netstat查看端口
发现列表中并没有1521端口。
可能是防火墙把端口屏蔽掉了
于是
iptables -I INPUT -p tcp --dport 1521 -j ACCEPT
iptables -I FORWARD -p tcp --dport 1521 -j ACCEPT 开放1521端口,再试..
仍然不行...
查看下oracle监听服务:
lsnrctl status结果如下:LSNRCTL for Linux: Version 11.2.0.2.0 - Production on 01-AUG-2012 16:07:46
Copyright (c) 1991, 2011, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC_FOR_XE)))
TNS-12541: TNS:no listener
TNS-12560: TNS:protocol adapter error
TNS-00511: No listener
Linux Error: 111: Connection refused
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=wodeoraclefuwuqi)(PORT=1521)))
TNS-12541: TNS:no listener
TNS-12560: TNS:protocol adapter error
TNS-00511: No listener
Linux Error: 111: Connection refused
找到问题原因了,上网google,发现这个问题和IP有关系,之前在调整apache虚拟服务器的时候,为了测试把/etc/hosts里的这一行:
127.0.0.1 localhost.localdomain localhost删掉了,重新加上, 然后
lsnrctl start之后
lsnrctl status结果如下:
LSNRCTL for Linux: Version 11.2.0.2.0 - Production on 01-AUG-2012 16:11:35
Copyright (c) 1991, 2011, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC_FOR_XE)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 11.2.0.2.0 - Production
Start Date 01-AUG-2012 16:11:27
Uptime 0 days 0 hr. 0 min. 8 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Default Service XE
Listener Parameter File /u01/app/oracle/product/11.2.0/xe/network/admin/listener.ora
Listener Log File /u01/app/oracle/diag/tnslsnr/sstdevel/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC_FOR_XE)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=wodeoraclefuwuqi)(PORT=1521)))
Services Summary...
Service "PLSExtProc" has 1 instance(s).
Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
重新进入rails目录 rake db:migrate 搞定!
本文解决了一个在使用ORACLE数据库和torquebox连接时遇到的异常问题,通过排查防火墙设置、监听服务状态和IP配置,最终定位到问题原因在于删除了/etc/hosts文件中的本地主机配置项,导致数据库连接失败。通过重新添加该配置并启动监听服务,成功解决了问题。
1029

被折叠的 条评论
为什么被折叠?



