samba服务器搭建,NTP ,HCP服务器搭建,尚观Day14

  第一、Samba服务器的搭建

    特点:
        1、能够支持更详细的访问控制;
        2、能够跨平台(Windows 和 Linux)功能文件


    软件包:
samba-client.i386    <---Samba客户端的工具
samba-common.i386    <---Samba公共的工具包
samba.i386        <---Samba服务器端
samba-swat.i386        <---基于www接口,用来配置Samba


    服务端主配置文件: /etc/samba/smb.conf




[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


    例子1:

    直接安装完重启samba服务
    service smb restart


    测试:
    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        <---这个资源是否可以写,能够上传能够删除等操作



    例子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服务器的配置

    ntp --- network  time protocol

    软件包  ntp.i386
    
    配置文件: /etc/ntp.conf   <---主配置文件
        /etc/ntp/step-tickers

    时间同步对集群环境非常重要

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 <---上级时间服务器的地址
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  <---记录最后一次与上级服务器时间同步所花的时间
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


3、测试,等待大约5分钟,然后使用另一台没有配置成ntp服务器的电脑测试:
    ntpdate 10.1.1.67
    




时间的分类:系统时间(软件的时间)、硬件时间(bois的时间)

hwclock  
    --hctosys   --> hard clock  to  system 把硬件时间同步到系统
    --systohc   --> 与上相反


================================================================================

第三、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的记录的方式
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范围
        default-lease-time 21600;  <---定义默认的租约时间
        max-lease-time 43200;        <---定义最大租约时间

        # we want the nameserver to appear at a fixed address
        host boss {
                hardware ethernet 12:34:56:78:AB:CD;
                fixed-address 10.1.1.88;
        }
}



    2、重启服务
    service dhcpd restart
    
    3、测试

用另外一台电脑测试,必须在同一个交换机上的:
dhclient eth0

如果提示dhclient已经正在运行:
ps -ef | grep dhclient
kill -9 #

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章