tftp协议一般用在PXE启动,常用的有atftp和tftpd-hpa,推荐使用atftp,因为atftp是唯一的免费的符合RFC规范的TFTP服务器。
下载atftp
http://down1.chinaunix.net/distfiles/atftp-0.7.tar.gz
考虑到有的Linux系统没有start-stop-daemon程序,可以自行安装。
下面是安装方法,我的SUSE是有的,因此编译后的程序没有经过测试,不保证正确。
下载start-stop-daemon
http://developer.axis.com/download/distribution/apps-sys-utils-start-stop-daemon-IR1_9_18-2.tar.gz
安装 start-stop-daemon
tar xzvf apps-sys-utils-start-stop-daemon-IR1_9_18-2.tar.gz
cd apps
gcc –o start-stop-daemon start-stop-daemon.c
cp start-stop-daemon /sbin
安装atftp
如果需要将来的tftp支持pcre参数,需要安装pcre库,因为atftp链接需要。
pcre库主页
下载pcre库源代码
http://ftp.osuosl.org/pub/haiku/releases/r1alpha2/sources/libpcre-8.02_haiku-2010-04-29.tar.xz
解压xz文件解压工具
http://tukaani.org/xz/xz-4.999.9beta.tar.bz2
$tar xzvf xz-4.999.9beta.tar.bz2
$./configure --prefix=/opt/gnu/xz
$make
$make install
$ln -s /opt/gnu/bin/xz /bin/xz
$xz -d libpcre-8.02_haiku-2010-04-29.tar.xz
$tar xvf libpcre-8.02_haiku-2010-04-29.tar
$cd pcre-8.02
$ ./configure --prefix=/opt/mathlibs/pcre --enable-pcretest-libreadline --enable-pcregrep-libz --enable-pcregrep-libbz2
$make
$make install
$ln -s /opt/mathlibs/pcre/lib/libpcre.so /lib/libpcre.so
$tar xzvf atftp-0.7.tar.gz
$cd atftp-0.7
因为此软件包比较老,目前比较新的gcc编译会有问题。
为了编译它,需要修改两个文件stats.c和argz.h。
$sed -i '160,161s/CLK_TCK/CLOCKS_PER_SEC/' stats.c
$sed -i '183,197 s/__THROW//' argz.h
$./configure -prefix=/opt/gnu/atftp --enable-libpcre --enable-debug
$make
$make install
$ln -s /opt/gnu/atftp/sbin/atftpd /usr/sbin/atftpd
Xinetd进程启动方式
建立文件/etc/xinetd.d/tftp
$vi /etc/xinetd.d/tftp
内容如下
service tftp
{
id = tftp-udp
disable = no
socket_type = dgram
protocol = udp
wait = yes
user = nobody
nice = 5
server = /opt/gnu/atftp/sbin/atftpd
server_args = /tftpboot
}
$service xinetd restart
$ps –ef|grep atftpd
我安装此方法配置后启动失败,没找到原因,如果你也是,可以用下面的守护进程启动方式。
独立守护进程启动方式
vi /etc/init.d/atftpd
#! /bin/sh
# Author: linfengfeiye@gmail.com, template by ro@suse.de
# /etc/init.d/atftpd
#
### BEGIN INIT INFO
# Provides: atftpd
# Required-Start: $syslog $network
# Required-Stop: $syslog $network
# Default-Start: 3 5
# Default-Stop: 0 1 2 4 6
# Description: Launch atftpd server, a TFTP server useful
# for network boot (PXE).
### END INIT INFO
# Determine the base and follow a runlevel link name.
base=${0##*/}
link=${base#*[SK][0-9][0-9]}
. /etc/rc.status
rc_reset
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/atftpd
NAME=atftpd
DESC="Advanced TFTP server"
USE_INETD=true
OPTIONS=""
test -f $DAEMON || { echo "/usr/sbin/atftpd not exists"; rc_failed 5; rc_status -v; rc_exit; }
if [ -f /etc/atftpd.conf ]; then
. /etc/atftpd.conf
fi
if [ "$USE_INETD" = "true" ]; then
echo "not configured in dameon,use xinetd to start atftpd"
rc_failed 6
rc_status -v;
rc_exit;
fi
# Make sure we have --daemon when not using inetd
echo "$OPTIONS"|grep -q -- --daemon || OPTIONS="--daemon $OPTIONS"
case "$1" in
start)
echo -n "Starting $DESC: "
start-stop-daemon --start --oknodo --quiet --exec $DAEMON -- $OPTIONS
rc_status -v;
;;
stop)
echo -n "Stopping $DESC: "
start-stop-daemon --stop --oknodo --quiet --exec $DAEMON
rc_status -v
;;
restart|reload|force-reload)
echo -n "Restarting $DESC: "
start-stop-daemon --stop --oknodo --quiet --exec $DAEMON
sleep 1
start-stop-daemon --start --oknodo --quiet --exec $DAEMON -- $OPTIONS
rc_status -v
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
exit 1
rc_status -v
;;
esac
exit 0
rc_exit
守护进程启动方式配置文件
vi /etc/atftpd.conf
USE_INETD=false
OPTIONS="--tftpd-timeout 300 --retry-timeout 5 --mcast-port 1758 --mcast-addr 239.239.239.0-255 --mcast-ttl 1 --maxthread 100 --verbose=5 /tftpboot"
错误:
service atftpd start done
ps –ef|grep atfpd
未启动。
tail /var/log/messages
出现
atftpd: can't bind port :69/udp
解决:
找到/etc/xinetd.d/tftp
将
disable = yes 修改为 disable = no 后保存
运行 service xinetd restart