Linux文件服务器:ftp服务器(ftp/tftp)、 Samba服务器、NFS服务器。


ftp的客户可以是任意平台,samba是专门针对windows客户,而NFS则是面向linux/unix用户的。下面是三种服务器的对比情况:
服务器名称         用户客户端平台         使用范围         服务端口
FTP         Windows/linux/unix/macOS等         发布网站,文件共享         Tcp/21
Samba         Windows         文件共享(网上邻居)         Tcp/445,tcp/139
NFS         Linux/unix         网站发布,文件共享(mount)         Tcp/2049
接下来我们就逐个来配置和运行这些服务器。



NFS服务器 --是一种基于远程过程调用(RPC)的分布式文件系统架构


1. Check if NFS software package is installed


   或者 rpm -q nfs-utils portmap


2. Set up NFS server:



Edit /etc/exports file to add your configuration

Samba 和 nfs samba和nfs和ftp_Samba 和 nfs




3.Start the NFS server


After changing the /etc/exports file, it must be reloaded by entering: 
 
   
   
  

  Start the services: 
 
   
   
  # service portmap start;  
  //portmap的功能是启用远程过程调用,检查portmap服务是否启动(# ps aux | grep portmap)。 
 
   
   
  # service nfs start 
 
 // 先启动portmap(service protmap restart),再启动nfs(service nfs start) 
 

 4. Add them to the start configuration with: 
 
 /sbin/chkconfig --level 35 portmap on 
 
 /sbin/chkconfig --level 35 nfs on 
 
 /sbin/chkconfig --level 35 nfslock on 
 
 
 
 If the services are not present in the level management add them with "--add" chkconfig option. 
 

 

  Verify that the daemons are running with 
 
 /usr/sbin/rpcinfo -p


Samba 和 nfs samba和nfs和ftp_配置文件_02



查看nfs的当前状态


Samba 和 nfs samba和nfs和ftp_客户端_03

 



5. 在客户端挂接NFS共享出来的目录。先在客户端创建一个挂接点,如 # mkdir /mnt/nfs ,
     使用命令把nfs服务器共享出来的目录挂接上,我们挂接目录 /tmp ,

# mount –t nfs 192.168.100.100:/tmp /mnt/nfs  
  //假定nfs服务器的ip地址是192.168.100.100。


     访问NFS共享资源。接上步,改变文件目录 # cd /mnt/nfs就方便地实现了对nfs服务器目录/tmp的远程访问。
   

Samba服务器
   这个世界既非只有linux/unix,也不是由microsoft windows 独霸天下的格局。也许出于linux/unix与windows既竞争又共存的事实,人们开发了 linux给windows用户提供文件共享的工具Samba,这应该算得上linux的开放精神吧!
1、         检查是否安装samba软件包。# rpm –qa | grep smb ,如果没有则自行安装samba。
2、         修改配置文件/etc/samba/smb.conf。早期的linux版本的配置文件smb.conf的安全选项“security=share”,这个默认值是个安全隐患,不过现在流行的linux版本的安全选项的默认值是“security=user”。如果只想用户对他的目录拥有只读权限,就把选项“writeable=yes”改成“read only=yes”。其他的选项根据自己的要求更改即可。对于一般的应用而言,基本上不用修改这个文件。
3、         添加系统账户。由于smb的访问是使用系统账号进行的,因此添加账号是必不可少的。这个比较简单,用命令 # useradd sery , # passwd sery,就可以依次添加若干系统账号。
4、         建立Samba用户密码文件。虽然samba的用户是系统用户,但出于安全考虑,samba用户的密码并非创建系统用户时设定的用户密码。为了生成smb所需的密码,应该进行下面的操作:

# cat /etc/passwd | mksmbpasswd.sh > /etc/samba/smbpasswd 
 
 # smbpasswd sery  
   
  //为系统用户设置smb口令 
 
 # chown root.root /etc/samba/smbpasswd 
 
 # chmod 600 /etc/samba/smbpasswd  
   
  //不准别的用户访问


5、         启用Samba服务器。我比较喜欢用 # service smb start 这种方式。
6、         检查服务是否正常启动。# service smb status 或者 # ps aux | grep smb。
7、         windows客户端访问 Samba服务器共享目录。在windows环境下,右键点击“网上邻居”图标,然后左击“搜索计算机”,把Samba服务器的IP地址填写在“计算机名”搜索栏,点击立即搜索。找到后双击图标,然后输入在Samba服务器上预先设定的用户名和密码,就能合法访问Samba服务器设定的共享资源。为了方便使用,可以把Samba服务器提供的共享目录映射成本地驱动器。
8、       



FTP服务器在linux 环境下,有三个主要的FTP服务器:vsftpd、proftpd和wu-ftpd。


       检查是否安装vsftp包。# rpm –qa | grep vsftpd。如果没有则安装它。
2、         修改配置文件。Vsftpd的配置文件为/etc/vsftpd/vsftpd.conf,如果不打算提供匿名访问的话,需要修改配置文件 /etc/vsftpd/vsftpd.conf的项“anonymous_enable=Yes”为“anonymous_enable=No”。
3、       


Samba 和 nfs samba和nfs和ftp_服务器_04




或者:




Samba 和 nfs samba和nfs和ftp_Samba 和 nfs_05



4、         客户端连接访问。可以是专用的ftp客户端工具,也可以使用浏览器。
5、       




TFTP服务器


Usually the TFTP sevice is by default started in Linux. you only need to doulble check if not sure.
 #/bin/netstat -a|grep udp
In case, the tftp service is not started by default, you can start it manually.
 1. Firstly, Configuring the TFTP server
 #vi /etc/xinetd.d/tftp

Samba 和 nfs samba和nfs和ftp_客户端_06


# /sbin/service xinetd restart  
 3. To get xinetd configured to start at boot you can use the chkconfig command.  
 #chkconfig xinetd on




服务器名称   启动脚本                                     守护进程                                                                                   


/etc/init.d/nfs  
  /etc/init.d/nfslock /usr/sbin/rpc.nfsd  
   
   
   
  /usr/sbin/rpc.mountd /etc/exports 
 
 Samba     
  /etc/init.d/smb  
  /etc/init.d/winbind  
   
   
   
  /usr/sbin/smbd  
   
   
   
  /usr/sbin/nmbd  
   
   
   
 /etc/samba/smb.conf 
 
 vsftpd    etc/xinetd.d/vsftpd  
   
   
   
  /usr/sbin/vsftpd