当前位置: 首页 > 工具软件 > tftpd-hpa > 使用案例 >

Ubuntu tftp-hpa 启动失败的解决方法

孙光临
2023-12-01

1 现象

$ sudo /etc/init.d/tftpd-hpa start
[....] Starting tftpd-hpa (via systemctl): tftpd-hpa.serviceJob for tftpd-hpa.service failed because the control process exited with error code.
See "systemctl status tftpd-hpa.service" and "journalctl -xe" for details.
 failed!

2 定位问题

2.1 发现是由于tftp使用的69端口被占用

$ systemctl status tftpd-hpa.service
● tftpd-hpa.service - LSB: HPA's tftp server
   Loaded: loaded (/etc/init.d/tftpd-hpa; generated)
   Active: failed (Result: exit-code) since Wed 2020-08-05 11:22:06 CST; 7s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 28487 ExecStart=/etc/init.d/tftpd-hpa start (code=exited, status=71)

$ sudo journalctl -xe
......
Aug 05 11:22:06 pek-vx-nwk1 sudo[28471]: svc-cmnet : TTY=pts/32 ; PWD=/ ; USER=root ; COMMAND=/etc/init.d/tftpd-hpa start
Aug 05 11:22:06 pek-vx-nwk1 sudo[28471]: pam_unix(sudo:session): session opened for user root by svc-cmnet(uid=0)
Aug 05 11:22:06 pek-vx-nwk1 systemd[1]: Starting LSB: HPA's tftp server...
-- Subject: Unit tftpd-hpa.service has begun start-up
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- Unit tftpd-hpa.service has begun starting up.
Aug 05 11:22:06 pek-vx-nwk1 tftpd-hpa[28487]:  * Starting HPA's tftpd in.tftpd
Aug 05 11:22:06 pek-vx-nwk1 in.tftpd[28509]: cannot bind to local IPv4 socket: Address already in use
Aug 05 11:22:06 pek-vx-nwk1 systemd[1]: tftpd-hpa.service: Control process exited, code=exited status=71
Aug 05 11:22:06 pek-vx-nwk1 systemd[1]: tftpd-hpa.service: Failed with result 'exit-code'.
Aug 05 11:22:06 pek-vx-nwk1 systemd[1]: Failed to start LSB: HPA's tftp server.
-- Subject: Unit tftpd-hpa.service has failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- Unit tftpd-hpa.service has failed.
--
-- The result is RESULT.
Aug 05 11:22:06 pek-vx-nwk1 sudo[28471]: pam_unix(sudo:session): session closed for user root
Aug 05 11:22:41 pek-vx-nwk1 sudo[28550]: svc-cmnet : TTY=pts/32 ; PWD=/ ; USER=root ; COMMAND=/bin/journalctl -xe
Aug 05 11:22:41 pek-vx-nwk1 sudo[28550]: pam_unix(sudo:session): session opened for user root by svc-cmnet(uid=0)

2.2 查找占用69端口的进程,发现是xinetd

$ sudo netstat -lnp | grep 69
tcp        0      0 127.0.0.1:6942          0.0.0.0:*               LISTEN      35952/java
udp        0      0 0.0.0.0:69              0.0.0.0:*                           3192/xinetd

3 解决问题

3.1 关闭xinetd占用的69端口

3.1.1 查找为何xinetd占用69端口

/etc/xinetd.d下是xinet的自动启动的服务,发现包含tftp

$ cd /etc/xinetd.d/

$ ls -l

-rw-r--r-- 1 root root 640 Feb  6  2018 chargen
-rw-r--r-- 1 root root 313 Feb  6  2018 chargen-udp
-rw-r--r-- 1 root root 502 Feb  6  2018 daytime
-rw-r--r-- 1 root root 313 Feb  6  2018 daytime-udp
-rw-r--r-- 1 root root 391 Feb  6  2018 discard
-rw-r--r-- 1 root root 312 Feb  6  2018 discard-udp
-rw-r--r-- 1 root root 422 Feb  6  2018 echo
-rw-r--r-- 1 root root 304 Feb  6  2018 echo-udp
-rw-r--r-- 1 root root 312 Feb  6  2018 servers
-rw-r--r-- 1 root root 314 Feb  6  2018 services
-rwxrwxrwx 1 root root 464 Aug  5 11:12 tftp*
-rw-r--r-- 1 root root 569 Feb  6  2018 time
-rw-r--r-- 1 root root 313 Feb  6  2018 time-udp

3.1.2 编辑文件 /etc/xinetd.d/tftp,禁止xinetd启动时自动启动

将disable设为yes,保存退出

service tftp
{
        socket_type             = dgram
        protocol                = udp
        wait                    = yes
        user                    = root
        server                  = /usr/sbin/in.tftpd
        server_args             = -s /tftpboot
#       server_args             = -s /
        disable                 = yes
        per_source              = 11
        cps                     = 100 2
        flags                   = IPv4
}

3.1.3 重新启动xinet服务,再次查看netstat,发现69端口不再被占用,成功关闭69端口

$ sudo service xinetd restart

$ sudo netstat -lnp | grep 69
tcp        0      0 127.0.0.1:6942          0.0.0.0:*               LISTEN      35952/java
 

3.2 再次启动tftp-hpa,成功

$ sudo /etc/init.d/tftpd-hpa start
[ ok ] Starting tftpd-hpa (via systemctl): tftpd-hpa.service.

4 改进配置

4.1 根因分析

发现这个问题是由于tftp download文件失败,从tftpd-hpa 服务配置的tftp根目录位置download文件失败。

$ cat /etc/default/tftpd-hpa
# /etc/default/tftpd-hpa

TFTP_USERNAME="tftp"
TFTP_DIRECTORY="/"
TFTP_ADDRESS=":69"
TFTP_OPTIONS="--secure"

而xinetd服务自启动的tftp服务中的tftp根目录的位置与tftpd-hpa的配置不一致,导致启动tftpd-hpa服务失败。

问题解决前的xinetd.d/tftp的配置如下:

$ cat /etc/xinetd.d/tftp
service tftp
{
        socket_type             = dgram
        protocol                = udp
        wait                    = yes
        user                    = root
        server                  = /usr/sbin/in.tftpd
        server_args             = -s /tftpboot
#      server_args             = -s /
        disable                 = no
        per_source              = 11
        cps                     = 100 2
        flags                   = IPv4
}

4.2 改正xinetd自启动tftp服务的配置,使其与tftpd-hpa的配置一致,使能自启动tftp

$ cat /etc/xinetd.d/tftp
service tftp
{
        socket_type             = dgram
        protocol                = udp
        wait                    = yes
        user                    = root
        server                  = /usr/sbin/in.tftpd
#      server_args             = -s /tftpboot
        server_args             = -s /
        disable                 = no
        per_source              = 11
        cps                     = 100 2
        flags                   = IPv4
}

4.3 重启xinetd服务,查看xinetd占用69端口

$ sudo service xinetd start

$ sudo netstat -lnp | grep 69
tcp        0      0 127.0.0.1:6942          0.0.0.0:*               LISTEN      35952/java
udp        0      0 0.0.0.0:69              0.0.0.0:*                           19497/xinetd

4.4 测试tftp download文件,成功

 

 

 类似资料: