linux下的文件服务器[ftp(ftp/tftp)、 Samba、NFS服务器

来源:互联网 发布:少女时代930事件知乎 编辑:程序博客网 时间:2024/05/24 23:11
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 -qa | grep nfs   或者 rpm -q nfs-utils portmap
2. Set up NFS server:
Edit /etc/exports file to add your configuration
 
 
3.Start the NFS server
After changing the /etc/exports file, it must be reloaded by entering:
   # exportfs -ra
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


查看nfs的当前状态
 

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的远程访问。
   卸载NFS文件系统。在客户端执行命令 # umount /mnt/nfs 就卸下挂接的NFS文件系统。
 
 
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、     其他。上述配置的samba服务器,用户的访问共享目录是系统账号的主目录。要想把共享目录设置到其他位置,修改Samba 的配置文件/etc/samba/smb.conf文件即可。
 
FTP服务器
在linux 环境下,有三个主要的FTP服务器:vsftpd、proftpd和wu-ftpd。
1、     检查是否安装vsftp包。# rpm –qa | grep vsftpd。如果没有则安装它。
2、     修改配置文件。Vsftpd的配置文件为/etc/vsftpd/vsftpd.conf,如果不打算提供匿名访问的话,需要修改配置文件 /etc/vsftpd/vsftpd.conf的项“anonymous_enable=Yes”为“anonymous_enable=No”。
3、     启用vsftpd服务。#service vsftpd start。
 
或者:

4、     客户端连接访问。可以是专用的ftp客户端工具,也可以使用浏览器。
5、     vsftpd服务器的用户。Vsftpd服务器支持三种类型的拥护:本地用户(拥有系统账号)、虚拟用户(guest)、匿名账号;系统管理员应该根据安全需求来确定vsftpd服务器的用户访问策略。
 
 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

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

服务器名称  启动脚本                   守护进程                                           配置文件
NFS     /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                /etc/vsftpd/vsftpd.conf
0 0