在客户端配置TNS测试报错ORA-12170:TNS:连接超时
程序员文章站
2023-12-02 08:09:46
在red hat enterprise linux server releae 5.5 成功安装oracle 10g 后,在客户端配置tns后,测试是否可以连接到数据块服务...
在red hat enterprise linux server releae 5.5 成功安装oracle 10g 后,在客户端配置tns后,测试是否可以连接到数据块服务器,结果报错: ora-12170:tns:连接超时
1:首先检查网络是否能ping通,如下所示,网络是畅通的
2:检查tns配置(tns配置也没有问题)
gsp =
(description =
(address =(protocol = tcp)(host = 172.20.36.79)(port = 1521))
(connect_data=
(server = dedicated)
(service_name = gsp)
)
)
3:查看服务器监听服务是否启动
[oracle@wgods ~]$ lsnrctl status
lsnrctl for linux: version 10.2.0.1.0 - production on 14-dec-2012 15:51:13
copyright (c) 1991, 2005, oracle. all rights reserved.
connecting to (description=(address=(protocol=ipc)(key=extproc1)))
status of the listener
------------------------
alias listener
version tnslsnr for linux: version 10.2.0.1.0 - production
start date 14-dec-2012 13:15:28
uptime 0 days 2 hr. 35 min. 45 sec
trace level off
security on: local os authentication
snmp off
listener parameter file /database/oracle/product/dbhome/network/admin/listener.ora
listener log file /database/oracle/product/dbhome/network/log/listener.log
listening endpoints summary...
(description=(address=(protocol=ipc)(key=extproc1)))
(description=(address=(protocol=tcp)(host=wgods)(port=1521)))
services summary...
service "plsextproc" has 1 instance(s).
instance "plsextproc", status unknown, has 1 handler(s) for this service...
service "gsp" has 2 instance(s).
instance "gsp", status unknown, has 1 handler(s) for this service...
instance "gsp", status ready, has 1 handler(s) for this service...
service "gspxdb" has 1 instance(s).
instance "gsp", status ready, has 1 handler(s) for this service...
service "gsp_xpt" has 1 instance(s).
instance "gsp", status ready, has 1 handler(s) for this service...
the command completed successfully
4:使用tnsping命令检查,报tns-12535: tns: 操作超时,这时我们可以肯定是防火墙的问题了
c:\users\kerry>tnsping 172.20.32.79
tns ping utility for 32-bit windows: version 11.2.0.1.0 - production on 14-12月-2012 15:47:15
copyright (c) 1997, 2010, oracle. all rights reserved.
已使用的参数文件:
e:\app\kerry\product\11.2.0\dbhome_1\network\admin\sqlnet.ora
已使用 ezconnect 适配器来解析别名
尝试连接 (description=(connect_data=(service_name=))(address=(protocol=tcp)(host=172.20.32.79)(port=1521)))
tns-12535: tns: 操作超时
对于防火墙问题,我们可以有两种解决方案:
1:关闭防火墙(这种方案不怎么好,关闭防火墙,会带来许多安全隐患)
[root@wgods ~]# service iptables stop
flushing firewall rules: [ ok ]
setting chains to policy accept: filter [ ok ]
unloading iptables modules: [ ok ]
2:修改iptables,开放1521端口,允许1521端口被连接
2.1 编辑iptables文件,添加-a rh-firewall-1-input -p tcp -m state --state new -m tcp --dport 1521 -j accept记录。
[root@wgods sysconfig]# vi iptables
# generated by iptables-save v1.3.5 on fri dec 14 17:03:58 2012
*filter
:input accept [0:0]
:forward accept [0:0]
:output accept [1749:243629]
:rh-firewall-1-input - [0:0]
-a input -j rh-firewall-1-input
-a forward -j rh-firewall-1-input
-a rh-firewall-1-input -i lo -j accept
-a rh-firewall-1-input -p icmp -m icmp --icmp-type any -j accept
-a rh-firewall-1-input -p esp -j accept
-a rh-firewall-1-input -p ah -j accept
-a rh-firewall-1-input -d 224.0.0.251 -p udp -m udp --dport 5353 -j accept
-a rh-firewall-1-input -p udp -m udp --dport 631 -j accept
-a rh-firewall-1-input -p tcp -m tcp --dport 631 -j accept
-a rh-firewall-1-input -m state --state related,established -j accept
-a rh-firewall-1-input -p tcp -m state --state new -m tcp --dport 21 -j accept
-a rh-firewall-1-input -p tcp -m state --state new -m tcp --dport 25 -j accept
-a rh-firewall-1-input -p tcp -m state --state new -m tcp --dport 22 -j accept
-a rh-firewall-1-input -p tcp -m state --state new -m tcp --dport 23 -j accept
-a rh-firewall-1-input -p tcp -m state --state new -m tcp --dport 1521 -j accept
-a rh-firewall-1-input -j reject --reject-with icmp-host-prohibited
commit
# completed on fri dec 14 17:03:58 2012
~
~
~
~
~
"iptables" 24l, 1212c written
2.2 重启iptables服务
[root@wgods sysconfig]# service iptables restart
flushing firewall rules: [ ok ]
setting chains to policy accept: filter [ ok ]
unloading iptables modules: [ ok ]
applying iptables firewall rules: [ ok ]
loading additional iptables modules: ip_conntrack_netbios_ns ip_conntrack_ftp [ ok ]
2.3 保存新增的规则,以免下次重启机器后,配置规则失效
[root@wgods sysconfig]# service iptables save
saving firewall rules to /etc/sysconfig/iptables: [ ok ]
2.4 查看1521端口是否开放,允许连接(见红色部分)
[root@wgods sysconfig]# iptables -l -n
chain input (policy accept)
target prot opt source destination
rh-firewall-1-input all -- 0.0.0.0/0 0.0.0.0/0
chain forward (policy accept)
target prot opt source destination
rh-firewall-1-input all -- 0.0.0.0/0 0.0.0.0/0
chain output (policy accept)
target prot opt source destination
chain rh-firewall-1-input (2 references)
target prot opt source destination
accept all -- 0.0.0.0/0 0.0.0.0/0
accept icmp -- 0.0.0.0/0 0.0.0.0/0 icmp type 255
accept esp -- 0.0.0.0/0 0.0.0.0/0
accept ah -- 0.0.0.0/0 0.0.0.0/0
accept udp -- 0.0.0.0/0 224.0.0.251 udp dpt:5353
accept udp -- 0.0.0.0/0 0.0.0.0/0 udp dpt:631
accept tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:631
accept all -- 0.0.0.0/0 0.0.0.0/0 state related,established
accept tcp -- 0.0.0.0/0 0.0.0.0/0 state new tcp dpt:21
accept tcp -- 0.0.0.0/0 0.0.0.0/0 state new tcp dpt:25
accept tcp -- 0.0.0.0/0 0.0.0.0/0 state new tcp dpt:22
accept tcp -- 0.0.0.0/0 0.0.0.0/0 state new tcp dpt:23
accept tcp -- 0.0.0.0/0 0.0.0.0/0 state new tcp dpt:1521
reject all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
[root@wgods sysconfig]#
从客户端用pl/sql developer连接数据库,问题解决。
1:首先检查网络是否能ping通,如下所示,网络是畅通的
2:检查tns配置(tns配置也没有问题)
gsp =
(description =
(address =(protocol = tcp)(host = 172.20.36.79)(port = 1521))
(connect_data=
(server = dedicated)
(service_name = gsp)
)
)
3:查看服务器监听服务是否启动
[oracle@wgods ~]$ lsnrctl status
lsnrctl for linux: version 10.2.0.1.0 - production on 14-dec-2012 15:51:13
copyright (c) 1991, 2005, oracle. all rights reserved.
connecting to (description=(address=(protocol=ipc)(key=extproc1)))
status of the listener
------------------------
alias listener
version tnslsnr for linux: version 10.2.0.1.0 - production
start date 14-dec-2012 13:15:28
uptime 0 days 2 hr. 35 min. 45 sec
trace level off
security on: local os authentication
snmp off
listener parameter file /database/oracle/product/dbhome/network/admin/listener.ora
listener log file /database/oracle/product/dbhome/network/log/listener.log
listening endpoints summary...
(description=(address=(protocol=ipc)(key=extproc1)))
(description=(address=(protocol=tcp)(host=wgods)(port=1521)))
services summary...
service "plsextproc" has 1 instance(s).
instance "plsextproc", status unknown, has 1 handler(s) for this service...
service "gsp" has 2 instance(s).
instance "gsp", status unknown, has 1 handler(s) for this service...
instance "gsp", status ready, has 1 handler(s) for this service...
service "gspxdb" has 1 instance(s).
instance "gsp", status ready, has 1 handler(s) for this service...
service "gsp_xpt" has 1 instance(s).
instance "gsp", status ready, has 1 handler(s) for this service...
the command completed successfully
4:使用tnsping命令检查,报tns-12535: tns: 操作超时,这时我们可以肯定是防火墙的问题了
c:\users\kerry>tnsping 172.20.32.79
tns ping utility for 32-bit windows: version 11.2.0.1.0 - production on 14-12月-2012 15:47:15
copyright (c) 1997, 2010, oracle. all rights reserved.
已使用的参数文件:
e:\app\kerry\product\11.2.0\dbhome_1\network\admin\sqlnet.ora
已使用 ezconnect 适配器来解析别名
尝试连接 (description=(connect_data=(service_name=))(address=(protocol=tcp)(host=172.20.32.79)(port=1521)))
tns-12535: tns: 操作超时
对于防火墙问题,我们可以有两种解决方案:
1:关闭防火墙(这种方案不怎么好,关闭防火墙,会带来许多安全隐患)
[root@wgods ~]# service iptables stop
flushing firewall rules: [ ok ]
setting chains to policy accept: filter [ ok ]
unloading iptables modules: [ ok ]
2:修改iptables,开放1521端口,允许1521端口被连接
2.1 编辑iptables文件,添加-a rh-firewall-1-input -p tcp -m state --state new -m tcp --dport 1521 -j accept记录。
[root@wgods sysconfig]# vi iptables
# generated by iptables-save v1.3.5 on fri dec 14 17:03:58 2012
*filter
:input accept [0:0]
:forward accept [0:0]
:output accept [1749:243629]
:rh-firewall-1-input - [0:0]
-a input -j rh-firewall-1-input
-a forward -j rh-firewall-1-input
-a rh-firewall-1-input -i lo -j accept
-a rh-firewall-1-input -p icmp -m icmp --icmp-type any -j accept
-a rh-firewall-1-input -p esp -j accept
-a rh-firewall-1-input -p ah -j accept
-a rh-firewall-1-input -d 224.0.0.251 -p udp -m udp --dport 5353 -j accept
-a rh-firewall-1-input -p udp -m udp --dport 631 -j accept
-a rh-firewall-1-input -p tcp -m tcp --dport 631 -j accept
-a rh-firewall-1-input -m state --state related,established -j accept
-a rh-firewall-1-input -p tcp -m state --state new -m tcp --dport 21 -j accept
-a rh-firewall-1-input -p tcp -m state --state new -m tcp --dport 25 -j accept
-a rh-firewall-1-input -p tcp -m state --state new -m tcp --dport 22 -j accept
-a rh-firewall-1-input -p tcp -m state --state new -m tcp --dport 23 -j accept
-a rh-firewall-1-input -p tcp -m state --state new -m tcp --dport 1521 -j accept
-a rh-firewall-1-input -j reject --reject-with icmp-host-prohibited
commit
# completed on fri dec 14 17:03:58 2012
~
~
~
~
~
"iptables" 24l, 1212c written
2.2 重启iptables服务
[root@wgods sysconfig]# service iptables restart
flushing firewall rules: [ ok ]
setting chains to policy accept: filter [ ok ]
unloading iptables modules: [ ok ]
applying iptables firewall rules: [ ok ]
loading additional iptables modules: ip_conntrack_netbios_ns ip_conntrack_ftp [ ok ]
2.3 保存新增的规则,以免下次重启机器后,配置规则失效
[root@wgods sysconfig]# service iptables save
saving firewall rules to /etc/sysconfig/iptables: [ ok ]
2.4 查看1521端口是否开放,允许连接(见红色部分)
[root@wgods sysconfig]# iptables -l -n
chain input (policy accept)
target prot opt source destination
rh-firewall-1-input all -- 0.0.0.0/0 0.0.0.0/0
chain forward (policy accept)
target prot opt source destination
rh-firewall-1-input all -- 0.0.0.0/0 0.0.0.0/0
chain output (policy accept)
target prot opt source destination
chain rh-firewall-1-input (2 references)
target prot opt source destination
accept all -- 0.0.0.0/0 0.0.0.0/0
accept icmp -- 0.0.0.0/0 0.0.0.0/0 icmp type 255
accept esp -- 0.0.0.0/0 0.0.0.0/0
accept ah -- 0.0.0.0/0 0.0.0.0/0
accept udp -- 0.0.0.0/0 224.0.0.251 udp dpt:5353
accept udp -- 0.0.0.0/0 0.0.0.0/0 udp dpt:631
accept tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:631
accept all -- 0.0.0.0/0 0.0.0.0/0 state related,established
accept tcp -- 0.0.0.0/0 0.0.0.0/0 state new tcp dpt:21
accept tcp -- 0.0.0.0/0 0.0.0.0/0 state new tcp dpt:25
accept tcp -- 0.0.0.0/0 0.0.0.0/0 state new tcp dpt:22
accept tcp -- 0.0.0.0/0 0.0.0.0/0 state new tcp dpt:23
accept tcp -- 0.0.0.0/0 0.0.0.0/0 state new tcp dpt:1521
reject all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
[root@wgods sysconfig]#
从客户端用pl/sql developer连接数据库,问题解决。