Ubuntu10.10配置TFTPNFS

TFTP
 
配置tftp服务的步骤:( 提示:tftp服务程序,也可参考附录中的版本)目前有若干版本的
 
1、安装相关软件包:tftpd(服务端),tftp(客户端),xinetd
sudo apt-get install tftpd tftp xinetd
 
2、建立配置文件
在/etc/xinetd.d/下建立一个配置文件tftp
sudo vi tftp
 
在文件中输入以下内容:
service tftp
{
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s  /tftpboot
disable = no
per_source = 11
cps = 100 2
flags = IPv4
}
保存退出
 
3、建立tftp服务文件目录(上传文件与下载文件的位置),并且更改其权限
sudo mkdir /tftpboot
sudo chmod 777 /tftpboot
 
4、重新启动服务
sudo /etc/init.d/xinetd restart
 
至此tftp服务已经安装完成了,下面可以对其进行一下测试。(假设在/tftpboot目录下有一个测试文件test.txt)
$tftp 127.0.0.1                       
tftp> get test.txt
Received 46 bytes in 0.0 seconds
tftp> quit
 
通过get命令,可以从/tftpboot目录下载test.txt文件。这样就验证了tftp服务配置的正确性,下载结束后,可以通过quit命令退出。
按照以上步骤配置tftp服务,一般都可以成功,如果出现无法get的时候,可以查看一下防火墙是否关闭。
 
查看tftp 服务
$ ps -ef | grep xinet
linux      2123 1890 0 09:39 pts/0    00:00:00 grep --color=auto xinet
 
或者
$ netstat -an | grep udp
udp         0      0 0.0.0.0:940             0.0.0.0:*                         
udp         0      0 0.0.0.0:34736           0.0.0.0:*                         
udp         0      0 0.0.0.0:36581           0.0.0.0:*                         
udp         0      0 0.0.0.0:5353            0.0.0.0:*                         
udp         0      0 0.0.0.0:54261           0.0.0.0:*                         
udp         0      0 0.0.0.0:2049            0.0.0.0:*                         
udp         0      0 0.0.0.0:49168           0.0.0.0:*                         
udp         0      0 0.0.0.0:69              0.0.0.0:*                         
udp         0      0 0.0.0.0:111             0.0.0.0:*                         
udp6        0      0 :::41637                :::*                              
udp6        0      0 :::5353                 :::*                              
 
或者
$ netstat -a | grep tftp
udp         0      0 *:tftp                  *:*                               
 
NFS
NFS(Network File System/网络文件系统):
1、设置Linux系统之间的文件共享;
2、NFS只是一种文件系统,本身没有传输功能,是基于RPC协议实现的;
3、 NFS为C/S架构
 
在ubuntu下安装、配置nfs服务的步骤如下:
 
1、安装NFS
Ubuntu上默认是没有安装nfs服务器的,因此我们首先安装nfs服务器端:
$sudo apt-get install nfs-kernel-server
 
2、配置/etc/exports
NFS允许挂载的目录及权限在文件/etc/exports中进行了定义。例如,我们要将根目录下的/source/rootfs目录共享出来,那么我们需要在/etc/exports文件末尾添加如下一行:
/source/rootfs         *(rw,sync,no_root_squash)
其中:/source/rootfs是要共享的目录,*代表允许所有的网络段访问,rw是可读写权限,sync是资料同步写入内存和硬盘,no_root_squash是NFS客户端分享目录使用者的权限,如果客户端使用的是root用户,那么对于该共享目录而言,该客户端就具有root权限。
其它nfs常用的参数有:
ro 只读访问
rw 读写访问sync 所有数据在请求时写入共享
async nfs在写入数据前可以响应请求
secure nfs通过1024以下的安全TCP/IP端口发送
insecure nfs通过1024以上的端口发送
wdelay 如果多个用户要写入nfs目录,则归组写入(默认)
no_wdelay 如果多个用户要写入nfs目录,则立即写入,当使用async时,无需此设置。
hide 在nfs共享目录中不共享其子目录
no_hide 共享nfs目录的子目录
subtree_check 如果共享/usr/bin之类的子目录时,强制nfs检查父目录的权限(默认)
no_subtree_check 和上面相对,不检查父目录权限
all_squash 共享文件的UID和GID映射匿名用户anonymous,适合公用目录。
no_all_squash 保留共享文件的UID和GID(默认)
root_squash root用户的所有请求映射成如anonymous用户一样的权限(默认)
no_root_squas root用户具有根目录的完全管理访问权限
anonuid=xxx 指定nfs服务器/etc/passwd文件中匿名用户的UID
anongid=xxx 指定nfs服务器/etc/passwd文件中匿名用户的GID
 
3、重启服务
$sudo /etc/init.d/portmap restart
$sudo /etc/init.d/nfs-kernel-server restart
 
4、测试nfs
此时可以运行以下命令来显示一下共享出来的目录:
$showmount –e 127.0.0.1
Export list for ubuntu:
/source/rootfs                     *
或者可以使用以下命令把它挂载在本地磁盘上,例如将/source/rootfs挂载到/mnt下:
$ sudo mount -t nfs 127.0.0.1:/source/rootfs /mnt
可以运行df命令查看是否挂载成功。
$ df
Filesystem            1K-blocks      Used Available Use% Mounted on
/dev/sda1              19737268 11651080   7083592 63% /
none                     248648       208    248440   1% /dev
none                     254244       184    254060   1% /dev/shm
none                     254244       108    254136   1% /var/run
none                     254244         0    254244   0% /var/lock
127.0.0.1:/source/rootfs
                      19737280 11651072   7083648 63% /mnt
查看后可以使用以下命令卸载:$ sudo umount /mnt
 
附录
ubuntu10.10 安装 TFTP 其它版本
 
sudo mkdir /tftpboot
sudo chmod 777 /tftpboot
 
sudo apt-get install tftp                               /* 安装客户端 */
sudo apt-get install tftpd                           /* 安装服务器端 */
sudo apt-get install openbsd-inetd           /*  inetd服务器的debian移植版本 */
 
sudo vi /etc/inetd.conf     在最后加入一行:
tftp dgram udp wait nobody /usr/sbin/tcpd /usr/sbin/in.tftpd /tftpboot
 
sudo /etc/init.d/openbsd-inetd reload
sudo /etc/init.d/openbsd-inetd restart
 
查看一下
netstat -an | grep udp
可以看到69端口已经启用:
udp         0      0 0.0.0.0:69              0.0.0.0:*
 
或者
netstat -a | grep tftp
udp         0      0 *:tftp                  *:*  
 
测试TFTP:
拷贝一文件(如uImage)到tftpboot下,然后:
tftp localhost
出现:tftp>
再输入:get uImage
提示下载成功后,看当前目录下多了个uImage文件.
 
注意:
tftp服务器默认规则是可以下载,限制上传,上传文件的话,必须在tftpboot中有一个相同名字的文件,而且具备相应的可读写的权限,这样才能上传文件。
 
也可以试一下另外的版本:
 
1、安装 tftp-server (一般已经安装)
#apt-get install tftpd-hpa tftp-hpa xinetd
 
2、修改文件vim /etc/default/tftpd-hpa,开启tftp服务
# /etc/default/tftpd-hpa
TFTP_USERNAME="tftp"
TFTP_DIRECTORY="/tftpboot"
TFTP_ADDRESS="0.0.0.0:69"
TFTP_OPTIONS="-l -c -s“
 
3、 创建tftp根目录,启动 tftp-server
 #mkdir /tftpboot
 #chmod o+w        /tftpboot
 # service tftpd-hpa restart
 
4、登陆本机测试以下,命令如下:
 #tftp      127.0.0.1
 tftp>get <download file>
 tftp>put <upload file>
 tftp>q