samba伺服器安裝

tonykorn97發表於2008-10-17
一,安裝軟體
[root@station10 ~]# yum install -y samba samba-common samba-client system-config-samba
檢視安裝的軟體
[root@station10 ~]# rpm -aq | grep samba
samba-3.0.25b-0.el5.4
system-config-samba-1.2.39-1.el5
samba-client-3.0.25b-0.el5.4
samba-common-3.0.25b-0.el5.4
[root@station10 ~]#
[@more@]
二,配置samba,方法有如下三種
1,system-config-samba
2,samba-swat()
3, 編輯 smb.conf 檔案
三,透過第3中方法配置samba
1, 建立一個共享的資料夾
[root@station10 /]# mkdir /backup
[root@station10 /]# chmod 777 -R /backup
2,在/etc/samba/smb.conf末尾新增:
[backup]
comment = backup
path = /backup
writeable = yes
public = yes
printable = no
3,新增samba使用者
[root@station10 /]# smbpasswd -a root
New SMB password:
Retype new SMB password:
[root@station10 /]# smbpasswd -a back
New SMB password:
Retype new SMB password:
[root@station10 /]#
4,測試語法
[root@station10 /]# testparm /etc/samba/smb.conf
Load smb config files from /etc/samba/smb.conf
Processing section "[homes]"
Processing section "[printers]"
Processing section "[backup]"
Loaded services file OK.
Server role: ROLE_STANDALONE
Press enter to see a dump of your service definitions
[global]
workgroup = MYGROUP
server string = Samba Server Version %v
passdb backend = tdbsam
cups options = raw
[homes]
comment = Home Directories
read only = No
browseable = No
[printers]
comment = All Printers
path = /var/spool/samba
printable = Yes
browseable = No
[backup]
comment = backup
path = /backup
read only = No
guest ok = Yes
[root@station10 /]# testparm /etc/samba/smb.conf station10.example.com 192.168.0.10
Load smb config files from /etc/samba/smb.conf
Processing section "[homes]"
Processing section "[printers]"
Processing section "[backup]"
Loaded services file OK.
Server role: ROLE_STANDALONE
Allow connection from station10.example.com (192.168.0.10) to homes
Allow connection from station10.example.com (192.168.0.10) to printers
Allow connection from station10.example.com (192.168.0.10) to backup
[root@station10 /]#
5,啟動samba
[root@station10 /]# /etc/init.d/smb start
Starting SMB services: [ OK ]
Starting NMB services: [ OK ]
[root@station10 /]#
6, 在另外一臺機器上測試
[root@station12 ~]# smbclient -L station10 -U 'back%redhat'
Domain=[STATION10] OS=[Unix] Server=[Samba 3.0.25b-0.el5.4]
Sharename Type Comment
--------- ---- -------
backup Disk backup
IPC$ IPC IPC Service (Samba Server Version 3.0.25b-0.el5.4)
back Disk Home Directories
Domain=[STATION10] OS=[Unix] Server=[Samba 3.0.25b-0.el5.4]
Server Comment
--------- -------
Workgroup Master
--------- -------
MYGROUP
[root@station12 ~]#
7,建立資料夾的時候出錯
[root@station12 ~]# smbclient -U 'back%redhat' //station10/backup
Domain=[STATION10] OS=[Unix] Server=[Samba 3.0.25b-0.el5.4]
smb: > ls
. D 0 Fri Oct 17 18:36:04 2008
.. D 0 Fri Oct 17 18:36:05 2008
63483 blocks of size 65536. 17042 blocks available
smb: > mkdir test
NT_STATUS_ACCESS_DENIED making remote directory test
smb: >
8,檢視selinux對應的策略
# SELINUX NOTES:
#
# If you want to use the useradd/groupadd family of binaries please run:
# setsebool -P samba_domain_controller on
#
# If you want to share home directories via samba please run:
# setsebool -P samba_enable_home_dirs on
#
# If you create a new directory you want to share you should mark it as
# "samba-share_t" so that selinux will let you write into it.
# Make sure not to do that on system directories as they may already have
# been marked with othe SELinux labels.
#
# Use ls -ldZ /path to see which context a directory has
#
# Set labels only on directories you created!
# To set a label use the following: chcon -t samba_share_t /path
#
# If you need to share a system created directory you can use one of the
# following (read-only/read-write):
# setsebool -P samba_export_all_ro on
# or
# setsebool -P samba_export_all_rw on
#
# If you want to run scripts (preexec/root prexec/print command/...) please
# put them into the /var/lib/samba/scripts directory so that smbd will be
# allowed to run them.
# Make sure you COPY them and not MOVE them so that the right SELinux context
# is applied, to check all is ok use restorecon -R -v /var/lib/samba/scripts
#
#--------------
9,更改selinux的策略
[root@station10 /]# chcon -t samba_share_t /backup
[root@station10 /]# /etc/init.d/smb restart
Shutting down SMB services: [ OK ]
Shutting down NMB services: [ OK ]
Starting SMB services: [ OK ]
Starting NMB services: [ OK ]
[root@station10 /]#
10,繼續建立資料夾測試ok:
[root@station12 ~]# smbclient -U 'back%redhat' //station10/backup
Domain=[STATION10] OS=[Unix] Server=[Samba 3.0.25b-0.el5.4]
smb: > mkdir test
smb: > ls
. D 0 Fri Oct 17 18:44:36 2008
.. D 0 Fri Oct 17 18:36:05 2008
test D 0 Fri Oct 17 18:44:36 2008
63483 blocks of size 65536. 17042 blocks available
smb: >
11,設定簡單共享
更改配置檔案security 為 share
security = share
重啟samba服務
[root@station10 ~]# /etc/init.d/smb restart
測試:
[root@station10 ~]# smbclient //station10/backup
Password:
Domain=[MYGROUP] OS=[Unix] Server=[Samba 3.0.25b-0.el5.4]
Server not using user level security and no password supplied.
smb: >
四,samba Client Tools: nmblookup
list specific machine
nmblookup -U WINS_server -R name
list all machines
nblookup *
[root@station12 ~]# nmblookup *
querying * on 192.168.0.255
192.168.0.10 *<00>
192.168.0.12 *<00>
[root@station12 ~]#
五,samba Clients Tools:mounts
The SMB and CIFS file systems are supported by the Linux Kernel
use mount to mount a Samba-shared resource:
mount -t cifs service mountpoing -o option1,option2
例子:
[root@station12 ~]# mount -t cifs //station10/backup /mnt -o username=back
Password:
[root@station12 ~]# mount
/dev/mapper/VolGroup00-LogVol00 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/mapper/VolGroup00-LogVol01 on /home type ext3 (rw)
/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)
//station10/backup on /mnt type cifs (rw,mand)
[root@station12 ~]#
或者把root使用者加入到samba使用者
[root@station12 ~]# smbpasswd -a root
New SMB password:
Retype new SMB password:
Added user root.
[root@station12 ~]#
[root@station12 ~]# mount -t cifs //station10/backup /mnt
Password:
[root@station12 ~]# mount
/dev/mapper/VolGroup00-LogVol00 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/mapper/VolGroup00-LogVol01 on /home type ext3 (rw)
/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)
//station10/backup on /mnt type cifs (rw,mand)
[root@station12 ~]#

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/312079/viewspace-1011990/,如需轉載,請註明出處,否則將追究法律責任。

相關文章