尝试调试 /etc/init.d/named,没有输出,将 > /dev/null 替换为 /var/log/named.log?

尝试调试 /etc/init.d/named,没有输出,将 > /dev/null 替换为 /var/log/named.log?

当我尝试时,我正在尝试调试命名:

[root@test master]# service named start
Starting named:  

                                      [FAILED]

它默默地失败了,所以我尝试:

sed -i 's/\/dev\/null/\/var\/log\/named.log/g' /etc/init.d/named

因为我不知道 shell 脚本,但我知道一些东西,比如重定向的作用。

sed 工作了,我检查并确保发生了更改,但 /var/log/named.log 仍然为空。我不明白为什么或如何继续。

答案1

不要修改初始化脚本,而是调查软件已提供哪些调试选项。

您尚未指定您使用的 Linux 发行版。不过,我可以基于 CentOS 6 提出以下建议:

1:手册页named显示了指定守护进程的这些调试选项:

   -d debug-level
       Set the daemon’s debug level to debug-level. Debugging traces from
       named become more verbose as the debug level increases.

   -g Run the server in the foreground and force all logging to stderr.

2:将这些选项传递给守护进程的正确方法是修改/etc/sysconfig/named,并在 OPTIONS 变量中指定需要传递给守护进程的命令行选项。/etc/sysconfig/named在运行守护进程之前,该文件在 init 脚本中获取named

查找带有 OPTIONS= 的行,取消注释,然后编辑它以显示如下:

OPTIONS="-g"

3:现在使用 init 脚本启动守护进程;该脚本应保留在前台,并且守护程序的输出应出现在窗口中。

以下是在我的测试中启用“-g”选项的效果示例:

不对 OPTIONS 进行任何修改:

[user@mycentos6box ~]# /etc/init.d/named start
Starting named:                                            [  OK  ]
[user@mycentos6box ~]# 

按照上面修改选项:

[user@mycentos6box ~]# /etc/init.d/named start
Starting named:     24-Nov-2014 20:23:28.963 starting BIND 9.8.2rc1-RedHat-9.8.2-0.23.rc1.el6_5.1 -u named -g
24-Nov-2014 20:23:28.963 built with '--build=x86_64-redhat-linux-gnu' '--host=x86_64-redhat-linux-gnu' '--target=x86_64-redhat-linux-gnu' '--program-prefix=' '--prefix=/usr' '--exec-prefix=/usr' '--bindir=/usr/bin' '--sbindir=/usr/sbin' '--sysconfdir=/etc' '--datadir=/usr/share' '--includedir=/usr/include' '--libdir=/usr/lib64' '--libexecdir=/usr/libexec' '--sharedstatedir=/var/lib' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--with-libtool' '--localstatedir=/var' '--enable-threads' '--enable-ipv6' '--with-pic' '--disable-static' '--disable-openssl-version-check' '--with-dlz-ldap=yes' '--with-dlz-postgres=yes' '--with-dlz-mysql=yes' '--with-dlz-filesystem=yes' '--with-gssapi=yes' '--disable-isc-spnego' '--with-docbook-xsl=/usr/share/sgml/docbook/xsl-stylesheets' '--enable-fixed-rrset' 'build_alias=x86_64-redhat-linux-gnu' 'host_alias=x86_64-redhat-linux-gnu' 'target_alias=x86_64-redhat-linux-gnu' 'CFLAGS= -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic' 'CPPFLAGS= -DDIG_SIGCHASE'
24-Nov-2014 20:23:28.963 ----------------------------------------------------
24-Nov-2014 20:23:28.963 BIND 9 is maintained by Internet Systems Consortium,
24-Nov-2014 20:23:28.963 Inc. (ISC), a non-profit 501(c)(3) public-benefit
24-Nov-2014 20:23:28.963 corporation.  Support and training for BIND 9 are
24-Nov-2014 20:23:28.963 available at https://www.isc.org/support
24-Nov-2014 20:23:28.963 ----------------------------------------------------
24-Nov-2014 20:23:28.964 adjusted limit on open files from 4096 to 1048576
24-Nov-2014 20:23:28.964 found 2 CPUs, using 2 worker threads
24-Nov-2014 20:23:28.964 using up to 4096 sockets
24-Nov-2014 20:23:28.967 loading configuration from '/etc/named.conf'
24-Nov-2014 20:23:28.967 reading built-in trusted keys from file '/etc/named.iscdlv.key'
24-Nov-2014 20:23:28.967 using default UDP/IPv4 port range: [1024, 65535]
24-Nov-2014 20:23:28.968 using default UDP/IPv6 port range: [1024, 65535]
24-Nov-2014 20:23:28.969 listening on IPv4 interface lo, 127.0.0.1#53
24-Nov-2014 20:23:28.970 generating session key for dynamic DNS
24-Nov-2014 20:23:28.970 sizing zone task pool based on 6 zones
24-Nov-2014 20:23:28.972 using built-in DLV key for view _default
24-Nov-2014 20:23:28.973 set up managed keys zone for view _default, file '/var/named/dynamic/managed-keys.bind'
24-Nov-2014 20:23:28.973 Warning: 'empty-zones-enable/disable-empty-zone' not set: disabling RFC 1918 empty zones
24-Nov-2014 20:23:28.973 automatic empty zone: 127.IN-ADDR.ARPA
24-Nov-2014 20:23:28.973 automatic empty zone: 254.169.IN-ADDR.ARPA
24-Nov-2014 20:23:28.973 automatic empty zone: 2.0.192.IN-ADDR.ARPA
24-Nov-2014 20:23:28.973 automatic empty zone: 100.51.198.IN-ADDR.ARPA
24-Nov-2014 20:23:28.973 automatic empty zone: 113.0.203.IN-ADDR.ARPA
24-Nov-2014 20:23:28.973 automatic empty zone: 255.255.255.255.IN-ADDR.ARPA
24-Nov-2014 20:23:28.973 automatic empty zone: 0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.IP6.ARPA
24-Nov-2014 20:23:28.973 automatic empty zone: D.F.IP6.ARPA
24-Nov-2014 20:23:28.973 automatic empty zone: 8.E.F.IP6.ARPA
24-Nov-2014 20:23:28.973 automatic empty zone: 9.E.F.IP6.ARPA
24-Nov-2014 20:23:28.973 automatic empty zone: A.E.F.IP6.ARPA
24-Nov-2014 20:23:28.973 automatic empty zone: B.E.F.IP6.ARPA
24-Nov-2014 20:23:28.973 automatic empty zone: 8.B.D.0.1.0.0.2.IP6.ARPA
24-Nov-2014 20:23:28.975 none:0: open: /etc/rndc.key: permission denied
24-Nov-2014 20:23:28.975 couldn't add command channel 127.0.0.1#953: permission denied
24-Nov-2014 20:23:28.975 none:0: open: /etc/rndc.key: permission denied
24-Nov-2014 20:23:28.975 couldn't add command channel ::1#953: permission denied
24-Nov-2014 20:23:28.975 ignoring config file logging statement due to -g option
24-Nov-2014 20:23:28.975 zone 0.in-addr.arpa/IN: loaded serial 0
24-Nov-2014 20:23:28.976 zone 1.0.0.127.in-addr.arpa/IN: loaded serial 0
24-Nov-2014 20:23:28.976 zone 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa/IN: loaded serial 0
24-Nov-2014 20:23:28.977 zone localhost.localdomain/IN: loaded serial 0
24-Nov-2014 20:23:28.977 zone localhost/IN: loaded serial 0
24-Nov-2014 20:23:28.977 managed-keys-zone ./IN: loaded serial 1
24-Nov-2014 20:23:28.979 error (network unreachable) resolving './DNSKEY/IN': 2001:503:ba3e::2:30#53
24-Nov-2014 20:23:28.979 error (network unreachable) resolving './NS/IN': 2001:503:ba3e::2:30#53
24-Nov-2014 20:23:28.979 error (network unreachable) resolving 'dlv.isc.org/DNSKEY/IN': 2001:500:2f::f#53
24-Nov-2014 20:23:28.979 error (network unreachable) resolving './DNSKEY/IN': 2001:500:2f::f#53
24-Nov-2014 20:23:28.979 error (network unreachable) resolving './NS/IN': 2001:500:2f::f#53
24-Nov-2014 20:23:28.979 running

我可以按 CTRL-C 来停止守护进程:

^C
24-Nov-2014 20:23:34.247 shutting down
24-Nov-2014 20:23:34.248 no longer listening on 127.0.0.1#53
24-Nov-2014 20:23:34.250 exiting
                           [  OK  ]
[user@mycentos6box ~]#

相关内容