在FreeBSD 6.0下安装Samba [原创]

wandering 发表于 2006-01-05 13:49:50

.

在FreeBSD 6.0下安装Samba [原创]


作者: wandering
 
1. Samba 安装
-----------------
Samba有二进制安装的版本, 也有源代码安装版本. 我用的系统是FreeBSD,
Samba的二进制安装并不支持FreeBSD. 所以, 我就选择了源代码安装方式.
 
我使用的samba版本是 samba-3.0.21a.tar.gz
 
shell> tar zxvf samba-3.0.21a.tar.gz
shell> cd samba-3.0.21a/source
shell> ./configure
shell> make
shell> make install
shell> cp ../examples/smb.conf.default /usr/local/samba/lib/smb.conf
 
 
 
2. 创建用户
-------------
这里我不得不说一句,目前我还没看到网上有任何一篇文章仔细地解释samba的用户关系问题!
不厚道啊~~ 我是摸索了好久才得出以下认识的:
    (1)samba用户管理使用smbpasswd和pdbedit命令
    (2)samba认证使用的用户和组首先要在本地系统中存在
    (3)samba只存储独立于本地系统的用户和口令信息,组则使用本地系统的组信息
 
首先在本地系统中创建用户user1和user2, 创建组group1和group2, user1属于group1,
user2属于group2.
 
 
然后再创建samba用户:
 
shell> /usr/local/samba/bin/smbpasswd -a user1
New SMB password: <new password>
Retype new SMB password: <new password>
 
shell> /usr/local/samba/bin/smbpasswd -a user2
New SMB password: <new password>
Retype new SMB password: <new password>
 
如果失败,则可能是本地系统没有事先建立同名帐号.
 
 
可以使用pdbedit -L列出现有samba用户清单, 如果清单中有新加入的用户名, 则说明用户
创建成功.
 
 
 
3. 配置Samba
-----------------
 
shell> vi /usr/local/samba/lib/smb.conf
 
下面是我实际搭建环境中的一个实例:
-----------------------------------
# Samba config file created using SWAT
# from 10.217.15.133 (10.217.15.133)
# Date: 2006/01/05 09:42:54
 
[global]
        workgroup = MYGROUP
        netbios name = MY-NFS
        server string = My NFS
        log file = /usr/local/samba/var/log-%M-%I
        max log size = 50
        load printers = No
        dns proxy = No
 
[it]
        path = /data1/it
        valid users = @group1, @group2
        read list = @group1, @group2
        write list = @group1, @group2
 
[driver]
        path = /data2/driver
        write list = @group1
        guest ok = Yes
 
[software]
        path = /data2/software
        write list = @group1
        guest ok = Yes
 
[patch]
        path = /data2/patch
        write list = @group1
        guest ok = Yes
 
 
以上是通过SWAT配置后生成的最终配置文件,但实际上我手工配置时还在global部分加入了:
 
   security = user
   encrypt passwords = yes
   smb passwd file = /usr/local/samba/private/smbpasswd
 
 
那上面配置要实现的目的是:
 
(1)所有用户都可以看到(browseable)共享目录it,driver,software,patch;
(2)group1的用户对共享目录it,driver,software,patch有读写权限;
(3)group2的用户对共享目录it有读写权限,对共享目录driver,software,patch只读;
(4)非group1和group2的用户对共享目录driver,software,patch只读,对共享目录it无读写权限;
 
 
 
 
4.设置共享目录权限
---------------------
shell> chmod -R 0777 /data1/it
shell> chmod -R 0777 /data2/driver
shell> chmod -R 0777 /data2/patch
shell> chmod -R 0777 /data2/software
 
 
 
5.启动samba
---------------
/usr/local/samba/sbin/smbd -D &
/usr/local/samba/sbin/nmbd -D &
 
 
 
6.自动运行samba
------------------
 
有两种方法:
 
(1)在/etc/rc.local加入以下内容:
 
/usr/local/samba/sbin/smbd -D &
/usr/local/samba/sbin/nmbd -D &
 
 
 
(2)在/etc/inetd.conf中加入以下内容:
 
netbios-ssn  stream  tcp  nowait       root  /usr/local/samba/sbin/smbd -D   smbd
netbios-ns   dgram   udp  wait         root  /usr/local/samba/sbin/nmbd -D   nmbd
swat         stream  tcp  nowait/400   root  /usr/local/samba/sbin/swat      swat
第二种方法要保证inetd正常运行.
 
 
 
7.SWAT管理
-------------
默认情况下SWAT已被安装.
我试过通过执行/usr/local/samba/sbin/swat启动SWAT没有成功, 只有通过inetd.conf才可以成功启动.
 
启动成功后可以通过http://samba_server_ip:901/访问SWAT管理页面.
 
默认情况, SWAT使用本地系统的root用户作为管理帐号. 注意, 是系统用户, 不是samba的共享用户.
 
 
 
8.检查服务是否正常
---------------------
 
通过netstat -an看到服务端口已处理监听状态:
tcp4       0      0  *.901                  *.*                    LISTEN
tcp4       0      0  *.139                  *.*                    LISTEN
udp4       0      0  10.0.0.38.138          *.*                   
udp4       0      0  10.0.0.38.137          *.*
udp4       0      0  *.138                  *.*
udp4       0      0  *.137                  *.*
 
 
 
9.小技巧
-------------
 
(1)如何在一个共享目录中嵌入其它目录
 
有时我们需要使用多块磁盘, 那经常变更目录或更换磁盘非常麻烦, 我还不了解在samba中如何
使用多个磁盘支持同一共享目录. 所以, 我使用的方法是:
 
    *在已有共享目录中建立一个到其它磁盘的链接.*
 
假设我要在共享目录it下建立一个到磁盘/data3上的目录iso的链接, 那么需要进行以下操作:
shell> cd /data1/it
shell> ln -s /data3/iso iso
shell> chmod -R 0777 /data3/iso
 
OK,通过共享访问一下试试吧,可以使用了.
 
 
 
 
 
 
==============================================
Created by Wandering 2006/01/05
 
 
 
 
////////////////////////////////////////////////////////////////////////////
 
 
附录一: 《Samba在线文档 - Building the Binaries》
 
下面的内容是从Samba在线文档中摘录的"Building the Binaries"部分:
 
 
 
After the source tarball has been unpacked, the next step involves configuration to match Samba to your operating system platform. If your source directory does not contain the configure script, it is necessary to build it before you can continue. Building of the configure script requires the correct version of the autoconf tool kit. Where the necessary version of autoconf is present, the configure script can be generated by executing the following:
 
root#  cd samba-3.0.20/source
root#  ./autogen.sh
 
* 这里说明如果解压后的内容中没有configure文件, 则需要通过autogen.sh手工生成一个.
* ./autogen.sh 需要的环境可不少啊! autoconf, m4, perl一个也不能少.
 
To build the binaries, run the program ./configure in the source directory. This should automatically configure Samba for your operating system. If you have unusual needs, then you may wish to first run:
 
root# ./configure --help
 
This will help you to see what special options can be enabled. Now execute ./configure with any arguments it might need:
 
root# ./configure [... arguments ...]
 
Execute the following create the binaries:
 
root#  make
 
Once it is successfully compiled, you can execute the command shown here to install the binaries and manual pages:
 
root#  make install
 
Some people prefer to install binary files and man pages separately. If this is your wish, the binary files can be installed by executing:
 
root#  make installbin
 
The man pages can be installed using this command:
 
root#  make installman
 
Note that if you are upgrading from a previous version of Samba the old versions of the binaries will be renamed with an “.old” extension. You can go back to the previous version by executing:
 
root#  make revert
 
As you can see from this, building and installing Samba does not need to result in disaster!
 
 
 
....... 
关键词(Tag): 安装 unix install freebsd samba

收藏: QQ书签 del.icio.us 订阅: Google 抓虾

最新评论

发表评论

* 昵称

已经注册过? 请登录

新用户请先注册 以便能显示头像及追踪评论回复

Email
网址
* 评论
表情
 
 

分类小组论坛
杂谈, 娱乐、八卦, 文学、艺术, 体育, 旅游、同城, 象牙塔, 情感, 时尚、生活, 星座, 科技

请注意遵守中华人民共和国法律法规, 如威胁到本站生存, 将依法向有关部门报告, 同时本站的相关记录可能成为对您不利的证据.

相关法律法规
全国人大常委会关于维护互联网安全的决定
中华人民共和国计算机信息系统安全保护条例
中华人民共和国计算机信息网络国际联网管理暂行规定
计算机信息网络国际联网安全保护管理办法
计算机信息系统国际联网保密管理规定