--
第一、Samba服务器的搭建 (桑巴舞)
SMB (server message block)服务消息块协议
unix-like 间的共享 nfs
windows之间的共享 cifs (common internet file system)
unix-like 与windows之间的共享 samba
smb使用的netbios通讯协定
netbios (network basic input/output system) --最早由IBM发展出来的目的为让局域网内少数电脑进行网络连结的协议,初期的设定并不是针对大型网络,并且他是无法横跨不同路由的; 微软就使用了它进行局域网内的通讯
现在有所谓的netbios over tcp/ip 可以横跨不同路由
netbeui (netbios extened user interface) 为IBM在netbios基础上发展而来的改良版本
用samba登入某部windows主机,要加入此windows主机的群组(workgroup),并且也要设定一下netbios name (要求唯一),然后就可以视权限进行资源的访问了
samba通过两个守护进程来控制
nmbd 用来管理workgroup,netbios name的解析等 用udp 的137,138端口
smbd 用来管理samba主机分享的目录,档案 用tcp的139和445 (TCP的可靠性)
联机模式的介绍
peer/peer (workgroup model)
domain model
特点:
1、能够支持更详细的访问控制;
2、能够跨平台(Windows 和 Linux)功能文件
软件包:(现在是3.x的版本,与2.x的版本配置有点不一致)
samba-client.i386 <---Samba客户端的工具指令
samba-common.i386 <---Samba公共的工具包包括 samba.conf 和检测其语法的测试工具testparm
samba.i386 <---Samba服务器端
samba-swat.i386 <---基于www接口,用来配置Samba
服务端主配置文件: /etc/samba/smb.conf
netbios名与ip对应文件:/etc/samba/lmhosts
密码存放文件: /etc/samba/passdb.tdb /etc/samba/secrets.tdb --默认不存在,用sampass -a user 加入用户后才会产生 权限为600为宜
日志文件: /var/log/samba/ --有nmbd,smbd两个daemon的日志记录
[global] <---全局参数
workgroup = MYGROUP 《---定义工作组
server string = Samba Server Version %v 《---定义服务器的描述
# logs split per machine
# max 50KB per log file, then rotate
security = user <---定义工作模式: share , user ,domain , ads
passdb backend = tdbsam <--- 使用本地.tdb文件保存帐号密码
# the login script name depends on the machine name
# the login script name depends on the unix user used
# disables profiles support by specifing an empty path
load printers = yes <---是否加载打印机资源
cups options = raw <---打印机的类型
#obtain list of printers automatically on SystemV
[homes] 《---保留的资源名字
comment = Home Directories
browseable = no
writable = yes
[printers] 《---保留的资源名字
comment = All Printers
path = /var/spool/samba
browseable = no
guest ok = no
writable = no
printable = yes
--全局有关的参数
security =
share 不用密码,包括匿名用户
user 使用samba本身的密码资料库 要用到passwd file= 的参数
server,domain 使用外部主机的密码,还要用到password server = 远端IP 的参数
--共享目录有关的参数:
browseable 是否可视
public 是否让所有可以登入的使用者看到
writable 是否可写
read only 是否只读 --这个参数与writable参数如果都写了就会互相抵触, 最后出现的那个设定值为主要的设定
create mode 与权限有关
valid users 指定能够进入的使用者
对配置文件的测试:
testparm 命令
例子1:
直接安装完重启samba服务
service smb restart
[root@station221 ~]# netstat -ntlup|grep bd
tcp 0 0 0.0.0.0:139 0.0.0.0:* LISTEN 3471/smbd
tcp 0 0 0.0.0.0:445 0.0.0.0:* LISTEN 3471/smbd
udp 0 0 10.1.1.221:137 0.0.0.0:* 3475/nmbd
udp 0 0 192.168.116.1:137 0.0.0.0:* 3475/nmbd
udp 0 0 172.16.61.1:137 0.0.0.0:* 3475/nmbd
udp 0 0 0.0.0.0:137 0.0.0.0:* 3475/nmbd
udp 0 0 10.1.1.221:138 0.0.0.0:* 3475/nmbd
udp 0 0 192.168.116.1:138 0.0.0.0:* 3475/nmbd
udp 0 0 172.16.61.1:138 0.0.0.0:* 3475/nmbd
udp 0 0 0.0.0.0:138 0.0.0.0:* 3475/nmbd
测试:
smbclient -L //10.1.1.67 《---回车,看到简单的服务器的信息,但什么资源也看不到,因为是匿名登录查看服务器的共享资源
[root@mail ~]# smbclient -L //10.1.1.67 -U bean
Password:
session setup failed: NT_STATUS_LOGON_FAILURE 《---登录失败,看分析2
分析:
1、默认的工作模式是 user ---》 除了指定为匿名共享资源,否则所有资源都是需要用户验证,
2、samba的帐号有两个要求: 第一个要求必须是系统存在的帐号,第二要通过命令把这些帐号添加samba专有帐号文件里,解决:
smbpasswd -a bean
添加用户名之后,再去查看资源:
[root@mail ~]# smbclient -L //10.1.1.67 -U bean
Password:
Domain=[MAIL] OS=[Unix] Server=[Samba 3.0.33-3.7.el5]
Sharename Type Comment
--------- ---- -------
IPC$ IPC IPC Service (Samba Server Version 3.0.33-3.7.el5)
bean Disk Home Directories <---你会发现多了一个共享资源,就跟登录名字一样的资源。
访问 共享名为 bean的资源
[root@mail ~]# smbclient //10.1.1.67/bean -U bean
Password:
Domain=[MAIL] OS=[Unix] Server=[Samba 3.0.33-3.7.el5]
smb: /> pwd
Current directory is //10.1.1.67/bean/ 《---这个路径代表10.1.1.67上一个叫做bean的共享资源,他的实际系统路径是 bean用户的家目录,为什么? 看分析3
smb: /> put install.log
putting file install.log as /install.log (504.9 kb/s) (average 504.9 kb/s)
分析3:
就是默认配置里带有的特殊的配置段
[homes] <---定义共享资源的名字,但这里比较特殊,在查看共享资源的时候,自动变成对应的用户名
comment = Home Directories <---资源的描述
browseable = no <---代表是否可以被大众在使用 -L 进行列表的时候能看得到
writable = yes <---这个资源是否可以写,能够上传能够删除等操作
------------------------------------------------------------------------------
linux 系统的权限概念:
一个前提是:任何在linux上面的process,linux本身的档案权限大于process对于使用者所设定的权限
例如:同一目录,samba对用户是可写的,但系统不能写,那还是不能写
例子2:share模式
1、修改主配置文件
[global]
workgroup = UPL
server string = Samba Server Version %v
# logs split per machine
# max 50KB per log file, then rotate
security = share 《---修改成 share 模式
passdb backend = tdbsam
# the login script name depends on the machine name
# the login script name depends on the unix user used
# disables profiles support by specifing an empty path
load printers = yes
cups options = raw
#obtain list of printers automatically on SystemV
[homes]
comment = Home Directories
browseable = no
writable = yes
[printers]
comment = All Printers
path = /var/spool/samba
browseable = no
guest ok = no
writable = no
printable = yes
[share] 《---定义共享名字
comment = Public for everyone
path = /share
guest ok = yes <---是否匿名可以访问
browseable = yes
2、建立对应的目录
mkdir /share
3、重载测试:
service smb reload
[root@mail ~]# smbclient -L //10.1.1.67
Password:
Domain=[UPL] OS=[Unix] Server=[Samba 3.0.33-3.7.el5]
Sharename Type Comment
--------- ---- -------
share Disk Public for everyone 《--新定义
总结: share 的特点
如果是guest ok =yes 的资源,就可以不用帐号和密码访问 ,但user模式是一样的;
如果是guest ok = no 的资源,你还是不能匿名访问。但有个注意的地方,只能在linux下的客户端才能够使用帐号和密码访问这些资源,在windows客户端是不行
那到底和user有什么区别?
区别就是share模式访问需要验证的资源的时候,windows客户端不能自由填写帐号名字
[root@mail ~]# smbclient //10.1.1.67/share
Password:
Domain=[UPL] OS=[Unix] Server=[Samba 3.0.33-3.7.el5]
Server not using user level security and no password supplied.
smb: /> ls
. D 0 Thu Nov 5 10:57:52 2009
.. D 0 Thu Nov 5 10:57:52 2009
39664 blocks of size 262144. 26537 blocks available
smb: /> put install.log
NT_STATUS_ACCESS_DENIED opening remote file /install.log 《--失,默认只读
要匿名可以上传文件,对资源有可写权限,看例子3:
例子3:让匿名资源可以写
修改配置文件
[share]
comment = Public for everyone
path = /share
# guest ok = no
browseable = yes
public = yes
writeable = yes <---资源是否可以
测试:
[root@mail ~]# smbclient //10.1.1.67/share
Password:
Domain=[UPL] OS=[Unix] Server=[Samba 3.0.33-3.7.el5]
Server not using user level security and no password supplied.
smb: /> put install.log
NT_STATUS_ACCESS_DENIED opening remote file /install.log 《---上传失败
原因:匿名登录的时候,samba是使用nobody的身份去执行操作的,而我们定义的那个/share文件夹是root:root的属性,权限是下755,所以操作失败
解决办法:
chmod 757 /share
[root@mail ~]# chmod 757 /share/
[root@mail ~]# smbclient //10.1.1.67/share
Password:
Domain=[UPL] OS=[Unix] Server=[Samba 3.0.33-3.7.el5]
Server not using user level security and no password supplied.
smb: /> put install.log
putting file install.log as /install.log (3029.5 kb/s) (average 3029.5 kb/s)
例子4:user模式的
[global]
workgroup = UPL
server string = Samba Server Version %v
# logs split per machine
# max 50KB per log file, then rotate
security = user
passdb backend = tdbsam
# the login script name depends on the machine name
# the login script name depends on the unix user used
# disables profiles support by specifing an empty path
load printers = yes
cups options = raw
#obtain list of printers automatically on SystemV
[homes]
comment = Home Directories
browseable = no
writable = yes
guest ok = no
[printers]
comment = All Printers
path = /var/spool/samba
browseable = no
guest ok = no
writable = no
printable = yes
[share]
comment = Come on, Baby! <---user模式下的资源,默认是需要验证和只读
path = /share
2、验证
[root@mail ~]# smbclient //10.1.1.67/share -U bean
Password:
Domain=[MAIL] OS=[Unix] Server=[Samba 3.0.33-3.7.el5]
smb: /> put install.log
NT_STATUS_ACCESS_DENIED opening remote file /install.log
我要让资源可写,修改参数
[share]
comment = Come on, Baby!
path = /share
read only = no
[root@mail ~]# smbclient //10.1.1.67/share -U bean
smb: /> put install.log
putting file install.log as /install.log (3786.8 kb/s) (average 3786.9 kb/s)
看一下上传后文件的属性
[root@mail ~]# ll /share/install.log
-rwxr--r-- 1 bean bean 31022 11-05 11:30 /share/install.log
[root@mail ~]# smbclient //10.1.1.67/share -U tom
Password:
Domain=[MAIL] OS=[Unix] Server=[Samba 3.0.33-3.7.el5]
smb: /> rm install.log 《---可以删除不属于他的文件
smb: /> put install.log
[root@mail ~]# ll /share/install.log
-rwxr--r-- 1 tom tom 31022 11-05 11:30 /share/install.log
[root@mail ~]# chmod 577 /share/install.log
[root@mail ~]# ll /share/install.log
-r-xrwxrwx 1 tom tom 31022 11-05 11:30 /share/install.log
^ <---拥有者没有写的权限
[root@mail ~]# smbclient //10.1.1.67/share -U bean
Password:
Domain=[MAIL] OS=[Unix] Server=[Samba 3.0.33-3.7.el5]
smb: /> rm install.log
NT_STATUS_NO_SUCH_FILE listing /install.log 《--删除失败
[root@mail ~]# chmod 200 /share/install.log
[root@mail ~]# ll /share/install.log
--w------- 1 tom tom 31022 11-05 11:38 /share/install.log
[root@mail ~]# smbclient //10.1.1.67/share -U bean
Password:
Domain=[MAIL] OS=[Unix] Server=[Samba 3.0.33-3.7.el5]
smb: /> rm install.log
smb: /> 《--可以删除
总结: 只要文件的拥有者对这个文件有可写的权限,那么其他也可以对这个文件有可写的权限,也就是可以删除他;
如果文件的拥有者对这个文件没有写的权限,尽管其他人有所有权限,也就是 577的典型例子,那么其他人还是不能对这个文件进行删除
怎么样才能解决这么的行为?让别人不能上出不属于他们自己的文件
解决办法: chmod o+t /share
例子5:create mask 和 directory mask的使用
作用:修改文件的默认权限
[share]
comment = Come on, Baby!
path = /share
writeable = yes
create mask = 0444
directory mask = 0757
例子6:user模式下,实现 tom 可以上传下载 , bean 只能下载 ,其他用户不能登录,拒绝匿名访问
---------------------
对于控制资源的权限参数,还有:
read only = yes <---资源默认带的参数,也就是只读 ,如果是 no ,代表资源可写
valid users = tom,bean,@team1 《---定义可以访问资源的用户或组
write list = tom,bean 《---对资源有写权限的用户列表
writeable = yes | no
----------------------
[share]
comment = Come on, Baby!
path = /share
public = no
valid users = tom,bean
write list = tom
例子7:user模式下,实现 tom 可以上传下载, bean 只能下载 ,mary 只能上传不能下载而且不能删除别人的文件,其他用户不能登录,拒绝匿名访问
config file = /etc/samba/smb.conf.%U 《---把用户的配置文件
tom:tom rw-r----- tomfile <---因为mary对于这个文件是其他人,所以不能读
把bean加入到tom 组
mary:mary ------r-- maryfile <--- tom,bean属于其他人的角色,具有读的权限
1、
passwd -a bean tom
chmod o+t /share
2、修改配置文件
config file = /etc/samba/smb.conf.%U
[share]
comment = Come on, Baby!
path = /share
public = no
valid users = tom,bean,mary
write list = tom
create mask = 640
3、建立一个 属于 mary的个人配置文件
vim /etc/samba/smb.conf.mary
[share]
comment = Come on, Baby!
path = /share
writeable = yes
create mask = 004
为了让samba正确共享资源,所共享路径必须具有最低权限r-x
例子8:访问控制
1、实现了禁止了10.1.1.0/24这个网段主机访问,但10.1.1.20是允许
hosts deny = 10.1.1.
hosts allow = 10.1.1.20 <--如果deny 和 allow 冲突,那么allow生效
2、拒绝所有,但允许10.1.1.0/24这个网段去访问,但10.1.1.20就不允许
hosts deny = ALL
hosts allow = 10.1.1. EXCEPT 10.1.1.20
客户端访问资源的一些命令:
smbclient -L //10.1.1.67 匿名列表资源
smbclient -L //10.1.1.67 -U mary 就是以mary的身份登录后列表资源
smbclient //10.1.1.67/resource_name 匿名访问配置文件里[resource_name]定义的资源
smbclient //10.1.1.67/homes -U mary 访问mary自己的家目录资源
smbclient //10.1.1.67/mary -U mary 同上
smbclient //10.1.1.67/resource_name -U tom 以tom身份访问resource_name资源
smbpasswd
-a add user
-d disable user <--禁用用户
-e enable user <---启用一个用户
-x delete user <---删除一个用户
==================================
第二、ntp服务器的配置
时间同步对集群环境非常重要
时区的概念
GMT为格林威治时间 (经度为0的英国城市格林威治而命名)
bios时钟多少都有些偏差
UTC (coordinated universal time 协和标准时间) 利用物理时钟(也称原子钟)为基准所定义出来的正确时间
[root@station35 ~]# file /etc/localtime
/etc/localtime: timezone data --可以看到这是一个时区文件,不是ASCII类型的,所以vi 看不了,用od命令看会看到全是二进制
当此文件存在时,系统的时区以此档案代表的时区来显示
当此文件不存在时,系统的时区主要以GMT或UTC为准
所有的time zone文件则放置在/usr/share/zoneinfo 目录里
如果说服务器本来在一个国家,但后面搬到另一个国家,则要换时区档案
第一步:把/usr/share/zoneinfo目录里的时区文件拷并覆盖/etc/localtime
第二步:vim /etc/sysconfig/clock修改时区名
同步的过程:
1。client send message to server
2.ntp server send back time to client
3.client receive and coordinate the time
对于同步时的延迟问题:
网络的延迟造成时间不同步的问题
解决方法: 一,他会有自己的计算误差的方法
二,阶层概念的帮助(最多15个阶层),你的上一层已经向更上一层同步好了
ntp --- network time protocol
软件包 ntp.i386
配置文件: /etc/ntp.conf <---主配置文件
/etc/ntp/step-tickers
配置文件内参数详解:
ignore 拒绝所有NTP连接
nomodify 客户端不能使用ntpc和ntpq来修改服务器端参数。但仍然可以进行时间同步
noquery 客户端不能使用ntpq,ntpc来查询服务器,也不能进行时间同步
notrap 不提供trap这个远端事件登录的功能
notrust 拒绝没有认证的用户端
不加任何参数的话表示不受任何限制
1、修改配置文件
vim /etc/ntp.conf
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery
server 10.1.1.1 prefer <---上级时间服务器的地址,perfer表示优先使用的主机,因为可以设置多个上层服务器的地址
server ntp.api.bz
restrict 10.1.1.0 mask 255.255.255.0 nomodify notrap <--restrict定义哪些客户端可以校准时间
restrict 127.0.0.1
restrict -6 ::1
driftfile /var/lib/ntp/drift <---记录本机与上层服务器的频率,并将两者频率的误差记录下来,就为linux系统时间与BIOS硬体时钟的差,单位为10^(-6)秒
keys /etc/ntp/keys
server 127.127.1.0 <---如果所有的上级时间服务器都联系不上,这时候就以主板硬件时间为来源
fudge 127.127.1.0 stratum 10
总结:
简单来说,要搭建一个时间服务器就需要添加两句:
service 10.1.1.1
restrict 10.1.1.0 mask 255.255.255.0 nomodify notrap
2、启动服务
service ntpd restart
netstat -ntlup (查看监听端口,是udp的123端口)
[root@station35 ~]# ntpstat --查看与上阶层的ntp服务器是否顺利连接上
synchronised to local net at stratum 11
time correct to within 448 ms
polling server every 64 s
[root@station35 ~]# ntptrace -n 10.1.1.1 --查看与上阶层服务器的关系 后面两个timed out不用管(也管不了),是上层与更上层之间的关系
10.1.1.1: stratum 2, offset 0.021063, synch distance 0.180062
192.43.244.18: timed out, nothing received
***Request timed out
[root@station35 ~]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
*squid.cluster.c 192.43.244.18 2 u 61 64 177 0.201 -106879 4.183
LOCAL(0) .LOCL. 10 l 62 64 177 0.000 0.000 0.001
remote :NTP主机的IP或主机名
refid :参考的更上一层主机的地址
st :阶层
when :几秒钟前曾做过时间同步化更新的动作
poll :下一次更新在几秒钟之后
reach :已经向上层NTP服务器要求更新的次数
delay :网络传输过程当中延迟的时间 单位为10^(-6)秒
offset :时间补偿的结果,单位为10^(-3)秒
jitter :linux系统时间与BIOS硬时间的差异时间,单位为10^(-6)秒
[root@station35 ~]# cat /var/lib/ntp/drift --查看系统时间与BIOS硬体时钟的差,单位为10^(-6)秒
24.907
3、测试,等待大约5分钟,然后使用另一台没有配置成ntp服务器的电脑测试:
ntpdate 10.1.1.67
用iptable加强ntp服务器的安全性设定
iptables -A INPUT -p UDP -i $EXTIF -s 10.1.1.0/24 --deport 123 -j ACCEPT
时间的分类:系统时间(软件的时间)、硬件时间(bios的时间)
hwclock 读出BIOS时间和把系统时间读入BIOS时间
hwclock -r 读出BIOS时间
hwclock -w 把系统时间读入BIOS时间
所以一般在ntpdate 服务端IP 后再hwclock -w写入到BIOS里
================================================================================
第三、DHCP 服务器的搭建
dhcp的应用场合讲一下
DHCP 动态主机控制协议
软件包: dchp dhcp-devel dhcpv6
yum install dhcp* -y
主配置文件:/etc/dhcpd.conf 《--安装完就有,但是空的
复制模板文件进行配置:
cp /usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample /etc/dhcpd.conf
开始配置:
ddns-update-style interim; <---动态更次DNS的记录的方式,由ISC开发的DHCP服务器目前主要支持interim方法来进行DNS的动态更新,另外一种称为ad-hoc的方法基本上已经不再采用。因此,实际上,interim方法是目前Linux环境下通过DHCP实现安全DDNS更新的惟一方法。
ignore client-updates; <---不启用动态DNS记录的功能
subnet 10.1.1.0 netmask 255.255.255.0 { <--作为dhcp服务器,本身IP一定是固定,而且必须在你定一个网段里面
option routers 10.1.1.1; 《---设定默认网关
option subnet-mask 255.255.255.0; 《---设定子网掩码
option nis-domain "cluster.com"; <---设定nis 域
option domain-name "cluster.com"; <---设定域名
option domain-name-servers 10.1.1.1; <---DNS的地址
option time-offset -18000; # Eastern Standard Time
range dynamic-bootp 10.1.1.60 10.1.1.254; 《--dhcp能够分配给客户端的IP范围 --动态IP地址分配
default-lease-time 21600; <---定义默认的租约时间
max-lease-time 43200; <---定义最大租约时间
# we want the nameserver to appear at a fixed address --以mac地址为基准,静态IP地址分配
host boss {
hardware ethernet 12:34:56:78:AB:CD;
fixed-address 10.1.1.88;
}
}
2、重启服务
service dhcpd restart
3、测试
用另外一台电脑测试,必须在同一个交换机上的:
dhclient eth0
或者 vim /etc/sysconfig/network-script/ifcfg-eth0
BOOTPROTO=dhcp --这一项改成dhcp
4.检验
--客户端:
ifconfig
rount -n
cat /etc/resolv.conf
netstat -ntlup
nisdomainname
cat /var/lib/dhcpclient/dhcpd.leases --客户端查看租约
lease {
interface "eth0";
fixed-address 172.16.26.254;
option subnet-mask 255.255.255.0;
option time-offset -18000;
option routers 172.16.26.1;
option dhcp-lease-time 21600;
option dhcp-message-type 5;
option domain-name-servers 172.16.26.1;
option dhcp-server-identifier 172.16.26.1;
option nis-domain "cluster.com";
option domain-name "cluster.com";
renew 0 2010/3/21 14:37:58;
rebind 0 2010/3/21 17:15:44;
expire 0 2010/3/21 18:00:44;
}
--服务端:
cat /var/lib/dhcpd/dhcpd.leases --服务端查看租约
lease 172.16.26.254 {
starts 3 2010/03/24 07:51:49;
ends 3 2010/03/24 13:51:49;
binding state active;
next binding state free;
hardware ethernet 00:0c:29:cf:d0:b9;
}
--一些问题的思考
同一局域网内有多台dhcp服务器,那么客户端就会找先建立连接的那一台,也就是说不确定
租约到期前自己再续约
http://10.1.1.35/ule_basic/ule14_samba.txt
最新推荐文章于 2010-07-24 12:13:00 发布