第一、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 #
samba服務器搭建,NTP ,HCP服務器搭建,尚觀Day14
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.