虚拟机环境中,执行SQL,提示未登录错误,
正常关库报错,
正常启库还是错,
看一下监听状态,
配置文件信息,
/etc/sysconfig/network
NETWORK=yes
HOSTNAME=localhost.localdomain
/etc/hosts文件信息,
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
看主机名,才发现有些不同,原来用户名叫bisal,现在叫做bogon,
[oracle@bisal Desktop]$ hostname
bogon
看下DNS配置,
[oracle@bisal Desktop]$ vi /etc/resolv.conf
# Generated by NetworkManager domain localdomain search localdomain nameserver 192.168.249.2
执行nslookup,发现IP地址被解析为了bogon,
[oracle@bisal Desktop]$ nslookup 192.168.149.0 Server: 192.168.249.2 Address: 192.168.249.2#53
Non-authoritative answer: 0.149.168.192.in-addr.arpa name = bogon.
Authoritative answers can be found from:
linux系统启动时,会经历BOIS自检,系统引导,启动内核,初始化系统这几步 ,其中初始化系统时,会依次执行/etc/rc.sysinit,/etc/rc.d/rc* 等脚本文件,其中在rc.sysinit有这样一段代码,
if [ "$HOSTNAME" = "localhost" -o "$HOSTNAME" = "localhost.localdomain" ]; then ipaddr=$(ip addr show to 0.0.0.0/0 scope global | awk '/[[:space:]]inet / { print gensub("/.*","","g",$2) }') for ip in $ipaddr ; do HOSTNAME= eval $(ipcalc -h $ip 2/dev/null) [ -n "$HOSTNAME" ] && { hostname ${HOSTNAME} ; break; } done fi
这段代码先判断了主机名,如果主机名是localhost或者localhost.localdomain,则获取主机IP地址并执行DNS逆向解析,将解析到的结果赋值给HOSTNAME。如果执行以下命令,确实返回bogon,
ipcalc -h IP
数据库无法正常操作,原因就是主机名,改为了bogon,无法识别。
解决方案:
hostname修改,但这种只是临时。
修改/etc/sysconfig/network,
NETWORKING=yes HOSTNAME=bisal
此时再次看监听,
[oracle@bisal Desktop]$ lsnrctl status LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 10-APR-2018 09:33:00 Copyright (c) 1991, 2013, Oracle. All rights reserved.
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521)) STATUS of the LISTENER ------------------------ Alias LISTENER Version TNSLSNR for Linux: Version 11.2.0.4.0 - Production Start Date 10-APR-2018 09:33:41 Uptime 0 days 0 hr. 0 min. 6 sec Trace Level off Security ON: Local OS Authentication SNMP OFF Listener Log File /u01/app/oracle/diag/tnslsnr/bisal/listener/alert/log.xml Listening Endpoints Summary... (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=bisal)(PORT=1521))) The listener supports no services The command completed successfully
至于为何是bogon,一种说法是,
一个路由器组织的局域网环境中,并且你的DNS地址是你路由器的地址,这样终端反向查询你本机IP地址得到的结果是bogon,于是你在终端里显示的主机名就变成了bogon。
回想一下,因为之前一直无法连接内网,这台机器上午找网络,改了DNS配置,可能在尝试的过程中,有一次的改动,配置错了,出现了路由冲突,导致虚拟机网卡配置,出现错误,进而导致数据库操作异常。