Samba和NFS自动挂载

 

Samba最先在Linux和Windows两个平台之间架起了一座桥梁哈,正是由于Samba的出现,我们可以在Linux系统和Windows系统之间互相通信,比如拷贝文件、实现不同操作系统之间的资源共享等等,我们可以将其架设成一个功能非常强大的文件服务器,也可以将其架设成打印服务器提供本地和远程联机打印,甚至我们可以使用samba Server完全取代NT/2K/2K3中的域控制器,做域管理工作,使用也非常方便
Samba使用的是smb协议Samba的安全级别分为1、share 匿名可以访问;2、user 需要身份验证,需要samba帐号库(本地用户);3、server 通过其他服务器进行身份验证;4、domain 活动目录数据库【ads】 身份验证
Smb 服务器/客户端架构
Tcp udp 137 138 139 445端口
Smbd服务139 445端口tcp 资源共享【连接控制】
Nmbd服务 137 138端口udp 宣告资源

1.Samba自动挂载

[root@localhost ~]# mount /dev/cdrom /mnt/cdrom
mount: block device /dev/cdrom is write-protected, mounting read-only
mount: /dev/cdrom already mounted or /mnt/cdrom busy
mount: according to mtab, /dev/hdc is already mounted on /mnt/cdrom
[root@localhost ~]# cd /mnt/cdrom/Server/
[root@localhost Server]# ll samba*
-r--r--r-- 86 root root 17012467 2009-07-23 samba-3.0.33-3.14.el5.i386.rpm
-r--r--r-- 86 root root 5930356 2009-07-23 samba-client-3.0.33-3.14.el5.i386.rpm
-r--r--r-- 99 root root 9094678 2009-07-23 samba-common-3.0.33-3.14.el5.i386.rpm
-r--r--r-- 86 root root 8628593 2009-07-23 samba-swat-3.0.33-3.14.el5.i386.rpm
[root@localhost Server]# rpm -qa |grep samba
samba-common-3.0.33-3.14.el5
samba-client-3.0.33-3.14.el5
[root@localhost Server]# rpm -ivh sa
sabayon-2.12.4-6.el5.i386.rpm               samba-swat-3.0.33-3.14.el5.i386.rpm
sabayon-apply-2.12.4-6.el5.i386.rpm         sane-backends-1.0.18-5.el5.i386.rpm
samba-3.0.33-3.14.el5.i386.rpm              sane-backends-devel-1.0.18-5.el5.i386.rpm
samba-client-3.0.33-3.14.el5.i386.rpm       sane-backends-libs-1.0.18-5.el5.i386.rpm
samba-common-3.0.33-3.14.el5.i386.rpm       sane-frontends-1.0.14-1.2.2.i386.rpm
[root@localhost Server]# rpm -ivh samba-3.0.33-3.14.el5.i386.rpm
error: Failed dependencies:
         perl(Convert::ASN1) is needed by samba-3.0.33-3.14.el5.i386
[root@localhost Server]# rpm -ivh perl-Co
perl-Compress-Zlib-1.42-1.fc6.i386.rpm perl-Convert-ASN1-0.20-1.1.noarch.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.14.el5.i386.rpm
Preparing...                 ########################################### [100%]
   1:samba                  ########################################### [100%]
[root@localhost Server]#
 
[root@localhost Server]# service smb start
启动 SMB 服务:                                             [确定]
启动 NMB 服务:                                             [确定]
[root@localhost Server]# netstat -tupln |grep smb
tcp         0      0 0.0.0.0:139                 0.0.0.0:*                   LISTEN      9207/smbd          
tcp         0      0 0.0.0.0:445                 0.0.0.0:*                   LISTEN      9207/smbd          
[root@localhost Server]# netstat -tupln |grep nmb
udp         0      0 192.168.20.20:137           0.0.0.0:*                               9210/nmbd          
udp         0      0 0.0.0.0:137                 0.0.0.0:*                               9210/nmbd          
udp         0      0 192.168.20.20:138           0.0.0.0:*                               9210/nmbd           
udp         0      0 0.0.0.0:138                 0.0.0.0:*                               9210/nmbd          
编辑smb配置文件
[root@localhost ~]# vim /etc/samba/smb.conf
[public]
        comment = this is a public dir
        path = /abc
        browseable = yes
        guest ok = yes
        writable = no
        printable = no
 
[smbzs]
        comment = this is a zhangsan share
        path = /zhangsan
        browseable = yes
        guest ok = no
        valid users = zhangsan
        writable = yes
        printable = no
 
[smbls]
        comment = this is a lisi share
        path = /lisi
        browseable = yes
        guest ok = no
        valid users = lisi
        writable = yes
        printable = no
建立相应目录
[root@localhost ~]# mkdir /abc
[root@localhost ~]# mkdir /zhangsan
[root@localhost ~]# mkdir /lisi
 
[root@localhost ~]# useradd zhangsan
[root@localhost ~]# useradd lisi
 
[root@localhost ~]# chown zhangsan.zhangsan /zhangsan/
[root@localhost ~]# chown lisi.lisi /lisi/
 
[root@localhost ~]# cd /abc/
[root@localhost abc]# touch f1.public
[root@localhost abc]# cd /zhangsan/
[root@localhost zhangsan]# touch f1.zhangsan
[root@localhost zhangsan]# cd /lisi/
[root@localhost lisi]# touch f1.lisi
建立smb账号库
[root@localhost lisi]# smbpasswd -a lisi
New SMB password:
Retype new SMB password:
Added user lisi.
[root@localhost lisi]# smbpasswd -a zhangsan
New SMB password:
Retype new SMB password:
Added user zhangsan.
重新启动smb服务
[root@localhost lisi]# service smb restart
关闭 SMB 服务:                                             [确定]
关闭 NMB 服务:                                             [确定]
启动 SMB 服务:                                             [确定]
启动 NMB 服务:                                             [确定]
 
测试:
 linux客户端测试:
 [root@localhost ~]# smbclient //192.168.20.20/smbzs -U zhangsan
Password:
Domain=[LOCALHOST] OS=[Unix] Server=[Samba 3.0.33-3.14.el5]
smb: \> dir
 .                                    D        0 Mon Aug 20 00:45:38 2012
 ..                                   D        0 Mon Aug 20 00:27:53 2012
 f1.zhangsan                                   0 Mon Aug 20 00:32:09 2012
 111                                  D        0 Mon Aug 20 00:45:36 2012
  新建 文本文档.txt              A        0 Sun Sep 16 15:41:35 2012
 
                   38752 blocks of size 262144. 25762 blocks available
smb: \> !dir
01    abcd             b   d3            f1 inittab              install.log.syslog      nn   passwd qq3      useradd.sh
abc anaconda-ks.cfg d2 Desktop f3 install.log mbox              nxl qq2     test.sh
smb: \> dir
 .                                    D        0 Mon Aug 20 00:45:38 2012
 ..                                   D        0 Mon Aug 20 00:27:53 2012
 f1.zhangsan                                   0 Mon Aug 20 00:32:09 2012
 111                                  D        0 Mon Aug 20 00:45:36 2012
  新建 文本文档.txt              A        0 Sun Sep 16 15:41:35 2012
 
                   38752 blocks of size 262144. 25762 blocks available
smb: \> put install.log
putting file install.log as \install.log (637.2 kb/s) (average 637.2 kb/s)
smb: \> dir
 .                                    D        0 Mon Aug 20 00:59:16 2012
 ..                                   D        0 Mon Aug 20 00:27:53 2012
 f1.zhangsan                                   0 Mon Aug 20 00:32:09 2012
 111                                  D        0 Mon Aug 20 00:45:36 2012
  新建 文本文档.txt              A        0 Sun Sep 16 15:41:35 2012
 install.log                          A    35236 Mon Aug 20 00:59:17 2012
 
                   38752 blocks of size 262144. 25762 blocks available
smb: \> mget f1.zhangsan
Get file f1.zhangsan? y
getting file \f1.zhangsan of size 0 as f1.zhangsan (0.0 kb/s) (average 0.0 kb/s)
smb: \> !dir
01    abcd             b   d3            f1                 f3      install.log            mbox nxl        qq2     test.sh
abc anaconda-ks.cfg d2 Desktop f1.zhangsan    inittab install.log.syslog nn    passwd qq3          useradd.sh
smb: \>

 

挂载到本地

建立挂载点

[root@localhost ~]# mkdir /mnt/smb

[root@localhost ~]# mount -t cifs //192.168.20.20/smbzs /mnt/smb -o username=zhangsan
Password:
查看
[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.20.20/smbzs on /mnt/smb type cifs (rw,mand)
进入目录查看信息
[root@localhost ~]# cd /mnt/smb/
[root@localhost smb]# ll
总计 36
drwxr-xr-x 2 502 502      0 08-20 00:45 111
-rw-r--r-- 1 root root      0 08-20 00:32 f1.zhangsan
-rwxr--r-- 1 502 502 35236 08-20 00:59 install.log
-rwxr--r-- 1 502 502      0 2012-09-16 新建 文本文档.txt
 
开机自启动挂载
 
[root@localhost ~]# vim /etc/fstab
//192.168.20.20/smbzs /mnt/smb       cifs    defaults,username=zhangsan%123   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 /mnt/cdrom type iso9660 (ro)
//192.168.20.20/smbzs on /mnt/smb type cifs (rw,mand)
 
2.NFS
 
NFS是Network File System的简写,即网络文件系统.网络文件系统是FreeBSD支持的文件系统中的一种,也被称为NFS. NFS允许一个系统在网络上与他人共享目录和文件。通过使用NFS,用户和程序可以像访问本地文件一样访问远端系统上的文件。
Nfs默认已经安装
启动nfs
[root@localhost ~]# service nfs start
启动 NFS 服务:                                             [确定]
关掉 NFS 配额:                                             [确定]
启动 NFS 守护进程:                                         [确定]
启动 NFS mountd:                                           [确定]
[root@localhost ~]# chkconfig nfs on
建立共享文件目录
[root@localhost ~]# mkdir /public
编辑共享清单
[root@localhost ~]# vim /etc/exports
/public 192.168.20.0/24(ro)
输出共享清单
 [root@localhost ~]# exportfs -rv
exporting 192.168.20.0/24:/public
客户端查看rpc进程
[root@localhost ~]# rpcinfo -p
   程序 版本 协议    端口
    100000    2   tcp    111 portmapper
    100000    2   udp    111 portmapper
    100024    1   udp    839 status
100024     1   tcp    842 status
查看访问权限
[root@localhost ~]# showmount -e 192.168.20.20
Export list for 192.168.20.20:
/public 192.168.20.0/24
建立挂载目录和挂载
[root@localhost ~]# mkdir /mnt/nfs
[root@localhost ~]# mount 192.168.20.20:/public /mnt/nfs
查看
[root@localhost ~]# df -h
文件系统               容量   已用 可用 已用% 挂载点
/dev/sda2              9.5G 3.7G 5.4G 41% /
/dev/sda1              130M   12M 112M 10% /boot
tmpfs                  506M     0 506M   0% /dev/shm
/dev/hdc               2.8G 2.8G     0 100% /mnt/cdrom
//192.168.20.20/smbzs
                      9.5G 2.7G 6.3G 30% /mnt/smb
192.168.20.20:/public
                      9.5G 2.7G 6.3G 30% /mnt/nfs
 
开机自挂载设置
 
编辑fstab
[root@localhost nfs]# vim /etc/fstab
192.168.20.20:/public    /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 /mnt/cdrom type iso9660 (ro)
192.168.20.20:/public on /mnt/nfs type nfs (ro,soft,intr,addr=192.168.20.20)
 
自动挂载
 
查看自动挂载服务已经安装
[root@localhost ~]# rpm -qa |grep auto
autofs-5.0.1-0.rc2.131.el5
编辑脚本
[root@localhost ~]# vim /etc/auto.master
/mnt/nfs /etc/auto.nfs          --timeout=30
产生/etc/auto.nfs文件
[root@localhost ~]# cp -p /etc/auto.misc /etc/auto.nfs
编辑auto.nfs
[root@localhost ~]# vim /etc/auto.nfs
server           -ro,soft,intr           192.168.20.20:/public
重启autofs
[root@localhost ~]# service autofs restart
停止 automount:                                            [确定]
启动 automount:                                            [确定]
进入挂载目录查看挂载信息
[root@localhost nfs]# cd server
[root@localhost server]# 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.20.20:/public on /mnt/nfs/server type nfs (ro,soft,intr,addr=192.168.20.20)
[root@localhost server]# 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.20.20:/public on /mnt/nfs/server type nfs (ro,soft,intr,addr=192.168.20.20)
30秒后将自动断开
[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)

你可能感兴趣的:(windows,server,服务器,domain,samba,nfs)