Samba是SMB的一种实现方法,主要用来实现Linux系统的文件和打印服务。Linux用户通过配置使用Samba服务器可以实现与Windows用户的资源共享。守护进程smbd和nmbd是Samba的核心,在全部时间内运行。nmbd程序使得通过企图计算机可以浏览Linux服务器。
NFS是网络文件系统(Network File System)的简称,是分布式计算系统的一个组成部分,可实现在异种网络上共享和装配远程文件系统。NFS由Sun公司开发,目前已经成为文件服务的一种标准(RFC1904,RFC1813)。其最大的功能就是可以通过网络,让不同操作系统的计算机可以共享数据,所以也可以将它看做是一个文件服务器。NFS文件服务器是Linux最常见网络的服务之一。尽管它的规则简单,却有着丰富的内涵。NFS 服务器可以看作是一个文件服务器,它可以让你的PC通过网络将远端的NFS 服务器共享出来的文件挂载到自己的系统中,在客户端看来使用NFS的远端文件就象是在使用本地文件一样。
samba共享文件挂载
samba服务器搭建
[root@localhost ~]# mount /dev/cdrom /mnt/cdrom
[root@localhost ~]# cd /mnt/cdrom/Server/
[root@localhost Server]# ll samba*
-r--r--r-- 55 root root 17197883 2008-12-16 samba-3.0.33-3.7.el5.i386.rpm
-r--r--r-- 55 root root 6008643 2008-12-16 samba-client-3.0.33-3.7.el5.i386.rpm
-r--r--r-- 63 root root 9148397 2008-12-16 samba-common-3.0.33-3.7.el5.i386.rpm
-r--r--r-- 55 root root 8726082 2008-12-16 samba-swat-3.0.33-3.7.el5.i386.rpm
[root@localhost Server]# rpm -ivh perl-Convert-ASN1-0.20-1.1.noarch.rpm
Preparing... ########################################### [100%]
1:perl-Convert-ASN1 ########################################### [100%]
[root@localhost Server]# rpm -ivh samba-3.0.33-3.7.el5.i386.rpm
Preparing... ########################################### [100%]
1:samba ########################################### [100%]
[root@localhost Server]# service smb start
启动 SMB 服务: [确定]
启动 NMB 服务: [确定]
在局域网其它机器上就可以看到samba服务器了
至于其中的配置就不多说了,这里只讨论共享文件的挂载
我自己新建了samba用户user1 密码为123
[root@localhost ~]# useradd user1
[root@localhost ~]# mkdir /user1
[root@localhost ~]# cd /user1/
[root@localhost ~]# chown user1.user1 /user1
[root@localhost user1]# touch f1.user1
[root@localhost ~]# vim /etc/samba/smb.conf
263 [user1]
264 comment = this is user1 dir
265 path = /user1
266 browseable = yes
267 guest ok = no
268 writable = yes
269 printable = no
270 valid users = user1
[root@localhost ~]# smbpasswd -a user1
[root@localhost ~]# service smb restart
samba客户端测试
[root@localhost ~]# smbclient -L //192.168.145.100 -U user1
Password:
Domain=[LOCALHOST] OS=[Unix] Server=[Samba 3.0.33-3.14.el5]
Sharename Type Comment
--------- ---- -------
user1 Disk this is user1 dir
IPC$ IPC IPC Service (Samba Server Version 3.0.33-3.14.el5)
Domain=[LOCALHOST] OS=[Unix] Server=[Samba 3.0.33-3.14.el5]
Server Comment
--------- -------
Workgroup Master
--------- -------
MYGROUP LOCALHOST
手动挂载
[root@localhost ~]# mkdir /mnt/smb
[root@localhost ~]# mount -t cifs //192.168.145.100/user1 /mnt/smb/ -o username=user1%123
[root@localhost ~]# mount
/dev/sda2 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/sda1 on /boot type ext3 (rw)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
/dev/hdc on /mnt/cdrom type iso9660 (ro)
//192.168.145.100/user1 on /mnt/smb type cifs (rw,mand)
自动挂载
[root@localhost ~]# vim /etc/fstab
LABEL=/ / ext3 defaults 1 1
LABEL=/boot /boot ext3 defaults 1 2
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
LABEL=SWAP-sda3 swap swap defaults 0 0
//192.168.145.100/user1 /mnt/smb cifs defaults,username=user1%123 0 0
但是这样每个系统用户都能通过fstab文件看到samba用户user1的密码,我们可以这样做。
[root@localhost ~]# vim /etc/fstab
8 //192.168.145.100/user1 /mnt/smb cifs defaults,credentials=/etc/samba/f1 0 0
把用户名密码放在f1文件中。该文件不允许其他人访问。
[root@localhost ~]# chmod 600 /etc/samba/f1
[root@localhost ~]# vim /etc/samba/f1
username=user1
password=123
[root@localhost ~]# umount /mnt/smb/
[root@localhost ~]# mount -a
[root@localhost ~]# mount
/dev/sda2 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/sda1 on /boot type ext3 (rw)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
/dev/hdc on /mnt/cdrom type iso9660 (ro)
//192.168.145.100/user1 on /mnt/smb type cifs (rw,mand)
智能挂载
当使用的时候自动挂载,超过一段时间后自动取消挂载
[root@localhost ~]# vim /etc/auto.master
9 /misc /etc/auto.misc
10 /mnt /etc/auto.samba --timeout=60 // /mnt是自定义的mount自动挂载点 /etc/auto.samba定义了mount的动作,超出时间自动取消挂载
root@localhost ~]# cp -p /etc/auto.misc /etc/auto.samba
[root@localhost ~]# vim /etc/auto.samba
8 cd -fstype=iso9660,ro,nosuid,nodev :/dev/cdrom
9 smb -fstype=cifs,username=user1,password=123,-ro,soft,intr ://192.168.145.100/user1
[root@localhost server]# service autofs restart
[root@localhost ~]# cd /mnt/
[root@localhost mnt]# mount
/dev/sda2 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/sda1 on /boot type ext3 (rw)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
/dev/hdc on /mnt/cdrom type iso9660 (ro)
[root@localhost mnt]# cd smb
[root@localhost smb]# mount
/dev/sda2 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/sda1 on /boot type ext3 (rw)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
/dev/hdc on /mnt/cdrom type iso9660 (ro)
//192.168.145.100/user1 on /mnt/smb type cifs (rw,mand)
当切换到/mnt/smb 目录时会自动挂载。60秒无动作时自动取消挂载。
NFS共享文件挂载
NFS服务器配置
nfs默认安装的
[root@localhost ~]# rpm -qa | grep nfs
nfs-utils-lib-1.0.8-7.6.el5
nfs-utils-1.0.9-42.el5
[root@localhost ~]#mkdir /abc
[root@localhost ~]# vim /etc/exports
/abc 192.168.145.0/24 (ro) //来源是192.168.145.0网段的具有只读权限
[root@localhost ~]# service nfs start
当修改exports文件后,执行exportfs -rv。
nfs客户端测试:
[root@localhost ~]# showmount -e 192.168.145.100
Export list for 192.168.145.100:
/abc (everyone)
共享文件挂载
手动挂载:
[root@localhost ~]# mkdir /mnt/nfs
[root@localhost ~]# mount 192.168.145.100:/abc /mnt/nfs
[root@localhost ~]# mount
/dev/sda2 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/sda1 on /boot type ext3 (rw)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
/dev/hdc on /media/RHEL_5.4 i386 DVD type iso9660 (ro,noexec,nosuid,nodev,uid=0)
/dev/hdc on /mnt/cdrom type iso9660 (ro)
nfsd on /proc/fs/nfsd type nfsd (rw)
192.168.145.100:/abc on /mnt/nfs type nfs (rw,addr=192.168.145.100)
自动挂载
[root@localhost ~]# umount /mnt/nfs
[root@localhost ~]# vim /etc/fstab
6 proc /proc proc defaults 0 0
7 LABEL=SWAP-sda3 swap swap defaults 0 0
8 192.168.145.100:/abc /mnt/nfs nfs ro,soft,intr 0 0
[root@localhost ~]# mount -a
[root@localhost ~]# mount
/dev/sda2 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/sda1 on /boot type ext3 (rw)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
/dev/hdc on /media/RHEL_5.4 i386 DVD type iso9660 (ro,noexec,nosuid,nodev,uid=0)
/dev/hdc on /mnt/cdrom type iso9660 (ro)
nfsd on /proc/fs/nfsd type nfsd (rw)
192.168.145.100:/abc on /mnt/nfs type nfs (ro,soft,intr,addr=192.168.145.100)
智能挂载
和samba挂载一样
这里就不介绍了