2011年1月26日星期三

[Linux]Using yum to install samba

Part1: install rpm repo 

http://wiki.centos.org/AdditionalResources/Repositories/RPMForge#head-5aabf02717d5b6b12d47edbc5811404998926a1b

 RPMforge for CentOS 5

The default RPMforge repository does not replace any CentOS base packages. In the past it used to, but those packages are now in a separate repository (rpmforge-extras) which is disabled by default.
You can find a complete listing of the RPMforge package packages at http://packages.sw.be/
Download the rpmforge-release package. Choose one of the two links below, selecting to match your host's architecture. If you are unsure of which one to use you can check your architecture with the command uname -i
The preferred rpmforge-release package to retrieve and to install in order to enable that repository is one of the two listed above.
Install DAG's GPG key
rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt
Verify the package you have downloaded
rpm -K rpmforge-release-0.5.2-2.el5.rf.*.rpm
<!> Security warning: The rpmforge-release package imports GPG keys into your RPM database. As long as you have verified the md5sum of the key injection package, and trust Dag, et al., then it should be as safe as your trust of them extends.
Install the package
rpm -i rpmforge-release-0.5.2-2.el5.rf.*.rpm
This will add a yum repository config file and import the appropriate GPG keys.
Then try to install something like this
yum install htop
 

Part 2: Install Samby with yum


http://www.ihao.org/dz5/thread-228-1-2.html


在我們使用 Windows 作為客戶機的時候,通常有文件、印表機共享的需求。作為Windows 的網路功能之一,通常可以在 Windows 用戶端之間通過 Windows Network 固有的功能實現這些要求。然而,通過 Samba 我們也可以讓一臺 CentOS 主機來兼容 Windows 網路,實現同樣的功能,進而充分發揮 CentOS 主機的可用性。

本篇文檔主要介紹怎樣通過 Samba 服務器的構建實現 Windows 網路中的文件共享。


安裝 Samba

首先,通過 yum 來在線安裝 Samba 。

[root@sample ~]# yum -y install samba ← 安裝 Samba
Setting up Install Process
Setting up repositories
update 100% |=========================| 951 B 00:00
base 100% |=========================| 1.1 kB 00:00
addons 100% |=========================| 951 B 00:00
extras 100% |=========================| 1.1 kB 00:00
Reading repository metadata in from local files
primary.xml.gz 100% |=========================| 73 kB 00:00
update : ################################################## 212/212
Added 212 new packages, deleted 0 old in 4.94 seconds
primary.xml.gz 100% |=========================| 569 kB 00:00
base : ################################################## 1500/1500
Added 1500 new packages, deleted 0 old in 28.97 seconds
primary.xml.gz 100% |=========================| 157 B 00:00
Added 0 new packages, deleted 0 old in 0.03 seconds
primary.xml.gz 100% |=========================| 32 kB 00:00
extras : ################################################## 124/124
Added 124 new packages, deleted 0 old in 1.93 seconds
Parsing package install arguments
Resolving Dependencies
--> Populating transaction set with selected packages. Please wait.
---> Downloading header for samba to pack into transaction set.
samba-3.0.10-1.4E.9.i386. 100% |=========================| 101 kB 00:00
---> Package samba.i386 0:3.0.10-1.4E.9 set to be updated
--> Running transaction check
--> Processing Dependency: samba-common = 0:3.0.10 for package: samba
--> Restarting Dependency Resolution with new changes.
--> Populating transaction set with selected packages. Please wait.
---> Downloading header for samba-common to pack into transaction set.
samba-common-3.0.10-1.4E. 100% |=========================| 37 kB 00:00
---> Package samba-common.i386 0:3.0.10-1.4E.9 set to be updated
--> Running transaction check
Dependencies Resolved
=============================================================================
Package Arch Version Repository Size
=============================================================================
Installing:
samba i386 3.0.10-1.4E.9 base 13 M
Installing for dependencies:
samba-common i386 3.0.10-1.4E.9 base 5.0 M
Transaction Summary
=============================================================================
Install 2 Package(s)
Update 0 Package(s)
Remove 0 Package(s)
Total download size: 18 M
Downloading Packages:
(1/2): samba-common-3.0.1 100% |=========================| 5.0 MB 00:04
(2/2): samba-3.0.10-1.4E. 100% |=========================| 13 MB 00:11
warning: rpmts_HdrFromFdno: V3 DSA signature: NOKEY, key ID 443e1821
Public key for samba-common-3.0.10-1.4E.9.i386.rpm is not installed
Retrieving GPG key from
http://mirror.centos.org/centos/RPM-GPG-KEY-centos4
Importing GPG key 0x443E1821 "CentOS-4 key <centos-4key@centos.org>"
Key imported successfully
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing: samba-common ######################### [1/2]
Installing: samba ######################### [2/2]
Installed: samba.i386 0:3.0.10-1.4E.9
Dependency Installed: samba-common.i386 0:3.0.10-1.4E.9
Complete!

配置 Samba
然後,通過編輯 /etc/samba/smb.conf ,根據需求配置 Samba。在這裡,本文的原則是隻將文件共享應用於內網,並讓將要被共享的目錄擁有充分的讀寫權限屬性。
[root@sample ~]# vi /etc/samba/smb.conf ← 編輯 Samba 的配置文件
#======================= Global Settings =====================================
[global]
← 找到這一行(全局設置標簽),在此行下面添加如下行:
dos charset= big5 ← 將 Windows 客戶端的文字編碼設置為簡體中文 GB2312
unix charset= big5 ← 指定 Samba 所在的 CentOS 服務端新建文件或目錄時的編碼為 GB2312
display charset= big5 ← 指定使用 SWAT(一種通過瀏覽器控制Samba的工具)時頁面的默認文字編碼
directory mask = 0777 ← 指定新建目錄的屬性(以下4行)
force directory mode = 0777
directory security mask = 0777
force directory security mode = 0777
create mask = 0777 ← 指定新建文件的屬性(以下4行)
force create mode = 0777
security mask = 0777
force security mode = 0777

workgroup = MYGROUP ← 找到此行,將工作組名稱改為 Windows 網絡所定義的工作組名
workgroup = WORKGROUP
← 變為此狀態,這裡以 Windows XP 默認的“WORKGROUP”為例
; hosts allow = 192.168.1. 192.168.2. 127.
← 找到此行,去掉行首的“;”,並制定訪問限制
hosts allow = 192.168.0. 127. ← 變為此狀態,指定內網IP地址及本地,隻允許這兩種情況的訪問

然後在配置文件的末尾填如下幾行,定義公眾共享目錄:
[public]
comment = Public Stuff
path = /home/samba ← 指定共享目錄位置
public = yes
writable = yes ← 賦予共享目錄寫入權限的屬性
接下來,創建將要通過 Samba 共享給 Windows 網絡的專用目錄。
[root@sample ~]# mkdir /home/samba ← 建立共享文件專用目錄

[root@sample ~]#
chown -R nobody. /home/samba
← 設置專用目錄歸屬為 nobody

[root@sample ~]#
chmod 777 /home/samba ← 將專用目錄屬性設置為 777

在進行到服務端的連接之前,需要預先對用於登錄 Samba 的用戶進行設置。這裡我們以 CentOS 中 Samba 標準的 Samba 用戶數據庫管理工具“smbpasswd”為例,創建用於登錄 Samba 的用戶數據。這裡需要注意的一點:用 smbpasswd 創建用戶的前提是,繫統用戶中存在該用戶 -- 在基於繫統用戶之上,纔可以創建該用戶在 Samba 用戶數據庫中的信息。
[root@sample ~]# smbpasswd -a centospub ← 將繫統用戶 centospub(例)加入到 Samba 用戶數據庫

New SMB password: ← 輸入該用戶用於登錄 Samba 的密碼
Retype new SMB password: ← 再次確認輸入該密碼
Added user centospub.

啟動 Samba 服務
在啟動 Samba 服務之前,首先將防火牆設置中 Samba 所用到的端口進行開放。
[root@sample ~]# vi /etc/sysconfig/iptables ← 編輯 iptables 配置文件

-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 25 -j ACCEPT ← 找到此行,在下面添加如下行:
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 139 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 445 -j ACCEPT
-A RH-Firewall-1-INPUT -p udp -m udp --dport 137 -j ACCEPT
-A RH-Firewall-1-INPUT -p udp -m udp --dport 138 -j ACCEPT


[root@sample ~]# /etc/rc.d/init.d/iptables restart ← 重新啟動 iptables ,使新的規則生效
Flushing firewall rules: [ OK ]
Setting chains to policy ACCEPT: filter [ OK ]
Unloading iptables modules: [ OK ]
Applying iptables firewall rules: [ OK ]

最後,啟動 Samba 服務。
[root@sample ~]# chkconfig smb on ← 設置 Samba 自啟動

[root@sample ~]# chkconfig --list smb ← 確認 Samba 啟動標簽,確認 2-5 為 on 的狀態
smb 0:off 1:off 2:on 3:on 4:on 5:on 6:off

[root@sample ~]# /etc/rc.d/init.d/smb start ← 啟動 Samba 服務
Starting SMB services: [ OK ]
Starting NMB services: [ OK ]


没有评论:

发表评论