Journaling File Systems

原文出自http://www.linux-mag.com/2002-10/jfs_01.html,本文僅做筆記摘錄,並翻譯摘錄部分.
Linux now offers four alternatives to Ext2: Ext3, ReiserFS, XFS, and JFS.
Linux 現在提供四種不同於 Ext2 的選擇: Ext3, ReiserFS, XFS, and JFS.
They supports journaling, a feature certainly demanded by enterprise, can simplify restarts, reduce fragmentation, and accelerate I/O.
她們都支援日誌(journaling),一個企業級所需的特色,它可以簡單的重新啟動,減少碎裂(fragmentation)和加速I/O.
Some vernacular of file systems:
一些關於 file systems 的常用語:
A “logical block” is the smallest unit of storage, measured in bytes, and it may take several blocks to store a single file.
一個 “logical block” 是 Storage 中最小的單位,以bytes作單位,而通常一個檔案會花好幾個 block 來存放.
A “logical volume” can be a physical disk or some subset of the physical disk space.
一個 “logical volume” 可以是一個邏輯磁碟或實體磁碟空間的集合.
“Block allocation” is a method of allocating blocks where the file system allocates one block at a time.
“Block allocation”:索取 block 的方法.
“Internal fragmentation” occurs when a file does not a fill a block completely.
“Internal fragmentation” 內部碎列,當有很多 block, 而每個 block 都沒有完全塞滿時.
“External fragmentation” occurs when the logical blocks that make up a file are scattered all over the disk.
“External fragmentation” 外部碎列,當一個檔案分散在很多且不同的 block 上時.
An “extent” is a large number of contiguous blocks. described by a triple, consisting of (file offset, starting block number, length), where file offset is the offset of the extent’s first block from the beginning of the file, starting block number is the first block in the extent, and length is the number of blocks in the extent. For large files, extent allocation is a much more efficient technique than block allocation.
“extent” 一堆連續的 blocks, 包含 file offset, starting block number, length. file offset 就是相對於檔案的位址, starting block number 就是起始的 block 號碼, length 就是 block 的數目.
“meta-data” is the file system’s internal data structures. Meta-data includes date and time stamps, ownership information, file access permissions, other security information such as access control lists (if they exist), the file’s size and the storage location or locations on disk.
“meta-data” 就是 file system 的內部資料結構. 包含日期和時間戳記,擁有者,存取權限以及其他安全性資訊,檔案長度,和位置…
An “inode” stores all of the information about a file except the data itself. as a “bookkeeping” file for a file. An inode contains file permissions, file types, and the number of links to the file. It can also contain some direct pointers to file data blocks; pointers to blocks that contain pointers to file data bocks (so-called indirect pointers); and even double- and triple-indirect pointers. Every inode has a unique inode number.
“inode” 儲存檔案除了資料以外的所有資訊. 每個 inode 都有一個獨一無二的號碼.
A “directory” is a special kind of file that simply contains pointers to other files. Specifically, the inode for a directory file simply contains the inode numbers of its contents, plus permissions, etc.
“directory” 一種特殊的檔案,簡單的包含其他檔案的指標.當然也有 inode 和存取權限等資訊.
Corruption occurs because the logical operation of writing (or updating) a file is actually a sequence of I/O, and the entire operation may not be totally reflected on the media at any given point in time.
錯誤的發生是因為寫入(或更新)檔案的邏輯動作是循序的 I/O 動作,而這整個動作並未完全地反映到實際媒體上.
The magic of journaling file systems lies in transactions.
Journaling file system 的魔法是依賴於 transaction 之上.
treats a sequence of changes as a single, atomic operation.
就像是一個循序的改變,如同一個單一,極微的動作.
tracks changes to file system meta-data and/or user data.
追蹤 file system meta-data 和(或)使用者資料的變化.
The journal in a journaling file system is simply a list of transactions.
Journal 在 journaling file system 簡單的說就是一個 transaction 的列表.
In the event of a system failure, the file system is restored to a consistent state by replaying the journal.
在系統發生錯誤時,file system 就依照目前的狀態,回頭播放一次 journal.
inspects only those portions of the meta-data that have recently changed.
審查這些 meta-data 有被變動過的部份.
also address another significant problem: scalability.
但也有另外一個值得注意的問題: scalability 可靠性.
Features of modern file systems include:
現代檔案系統的特色:
– Faster allocation of free blocks. Extents (as described above) and B+ trees are used individually or together to find and allocate several free blocks, either by size or location, quickly.
快速地配置. Extents 和 B+ trees 被單獨(或一起)用來快速地尋找和配置數個閒置的 block.
– Large (or very large) numbers of files in a directory.
在一個目錄中能存在大量或很大量的檔案.
– Large files.
大量的檔案.
Ext3
designed to provide higher availability without impacting the robustness (at least the simplicity and reliability) of Ext2.
被設計來提供高可用度而使得 Ext2 不需面對太強的衝擊.
uses the same disk layout and data structures as Ext2, and it’s forward- and backward-compatible with Ext2
使用和 Ext2 相同的 disk 配置和資料結構, 而且它可以向前或向後相容於 Ext2.
limitations that Ext2 has. The fixed internal structures of Ext2 are simply too small (too few bits) to capture large file sizes, extremely large partition sizes, and enormous numbers of files in a single directory. Moreover, the bookkeeping techniques of Ext2, such as its linked-list directory implementation, do not scale well to large file systems (there is an upper limit of 32,768 subdirectories in a single directory, and a “soft” upper limit of 10,000-15,000 files in a single directory.)
限制和 Ext2 相同.固定的Ext2內部結構太小(太少bits),且使用的 Link list 在大磁碟環境下表現不佳.
Switching to Ext3
# tune2fs -j /dev/hdb3
Ext3 provides three data journaling modes that can be set at mount time: data=journal, data=writeback, and data=ordered. The data=journal mode provides both meta-data and data journaling. data=writeback mode provides only meta-data journaling. data=ordered mode, which is the default mode, provides meta-data journaling with increased integrity.
提供三種模式: data=journal(保護最完整), data=writeback(只保護 meta-data), data=ordered(預設,保護 meta-data之外,即較完整的journaling).
By the way, the 2.4 kernel has a limit of 2048 Gb for a single block device, so no file system larger than that can be created at this time (without patching the standard kernel). This restriction could be removed in the 2.5.x development kernel, and there are patches available to remove this limit, but as of 2.5.29, the patches haven’t been officially included yet.
目前 2.4 仍然有 2048Gb 的限制.
ReiserFS
One of the unique advantages of ReiserFS is support for small files — lots and lots of small files.
比較大的特色是支援小檔案,很多很多的小檔案.
ReiserFS is about eight to fifteen times faster than Ext2 at handling files smaller than 1K.
在處理很多小於1k的檔案時,它比 ext2 快七到八倍.
ReiserFS can actually store about 6% more data that Ext2 on the same physical file system.
在和 Ext2 相同的情況下,她也可以存比 Ext2 多 6% 的資料.
ReiserFS can allocate the exact space that’s needed. A B* tree manages all file system meta-data, and stores and compresses tails, portions of files smaller than a block.
只配置實際所需的空間. 使用了 B* tree 管理.
also has excellent performance for large files, but it’s especially adept at managing small files.
同時也對大檔案有很好的效能,但他特別適合用來處理小檔案.
JFS
JFS uses many advanced techniques to boost performance, provide for very large file systems,
使用了很多先進的技術來加速.
SGI’s XFS (described next) has many similar features. Some of the features of JFS include:
XFS 也用了相似的技術. 這些技術包含了:
– Extent-based addressing structures. along with aggressive block allocation policies to produce compact, efficient, and scalable structures for mapping logical offsets within files to physical addresses on disk. This feature yields excellent performance.
Extent-based 定址的資料結構.
– Dynamic inode allocation. JFS dynamically allocates space for disk inodes as required, freeing the space when it is no longer required. Additionally, this feature decouples disk inodes from fixed disk locations.
動態的 inode 配置.自動配置所需的空間,並釋放不需要的空間.
– Directory organization. Two different directory organizations are provided: one is used for small directories and the other for large directories.
目錄的組織,使用了不同的目錄組織來分別處理大的和小個檔案.
– 64-bits. JFS is a full 64-bit file system. This allows JFS to support large files and partitions.
64-bits. 完全的 64-bit file system.
– such as allocation groups (which speeds file access times by maximizing locality), and various block sizes ranging from 512-bytes to 4096-bytes (which can be tuned to avoid internal and external fragmentation).
還有,配置群組及可變動的 block-size.
XFS
A single XFS file system can be 18,000 petabytes (that’s 1015 bytes) and a single file can be 9,000 petabytes. XFS is also capable of delivering excellent I/O performance.
一個單一個 XFS file system 最大可以到 18,000 petabytes 和單一檔案可達 9,000 petabytes. 同時也有能力提供最好的I/O效能.
uses many of the same techniques found in JFS.
使用了許多和 JFS 相同的技術.

vsftpd Overview

網址: http://vsftpd.beasts.org
vsftpd 她是目前號稱最安全的 FTP Server.
也是目前 Red Hat 8, Open BSD, Suse 所採用的 ftp server.
最新的版本是 1.1.3.
下載 tarball 以後,解開~
她不需要特別 configure, 只需要 make, make install 就可以了
make會自動安裝到 /usr/local/sbin 下面去~
而 conf 檔,則需要自行把 tarball 內附的 vsftpd.conf 複製到 /etc 去才行.
預設的 Server Type 是 inetd, 而不是 Standalone 型態~
所以你需要用 kill -HUP xinetd-pid
來請求 xinetd 重新載入 configuration.
預設的 Configuration 也很安全,完全不讓人登入,也不讓你寫入….非常的…嗯…安全~
你需要在 vsftpd.conf 裡面修改這幾個設定才能讓一般的使用者能登入並擁有寫入的權限:
local_enable=YES
write_enable=YES
如果要讓他以 Standalone 型態起來,則可以在設定裡面置入
listen=YES
並在 /etc/rc.d/init.d 裡面放 script 就行了
至於其他的設定,可以自行用 man vsftpd.conf 來找到用法.
和 proftpd 比較起來
設定是簡單了許多
蠻有那種樸實無華的味道~
再加上檔案又小~
沒什麼可以挑剔的~
期待 2.0 吧
2.0 的 beta 已經 release 了~
相信正式版應該很快就會 Release.

CVS 簡易說明

我們先假設 192.168.0.1 有安裝 cvs server
並且有三個專案在上面
怎麼用??
0. 確定自己電腦上有安裝 cvs
一般來說,如果是 Red Hat 或 Mandrake,那麼預設會有安裝
如果是其他的,我就不知道了
請到 www.cvsroot.org 去下載套件並安裝之
1. 設定
#當然你如果習慣用 vi, 這邊的 EDITOR 就設為 vi 的路徑
export EDITOR=/usr/bin/vim
#此處的 username, 要替換為自己的 username
export CVSROOT=:pserver:username@192.168.0.1:/home/cvsroot
export CVSREAD=yes
你可以把這些敘述放到 /etc/profile 或 /root/.bash_profile 裡面
免得以後每次用的時候還要再打一次
2. login
輸入
cvs lgin
cvs 會要求你輸入密碼,此密碼就是你在 192.168.0.1 上的密碼
3. checkout 將專案下載到你的電腦上
所以你可以打
cvs checkout clockd
cvs checkout helloworld
cvs checkout qt
把專案下載到自己的電腦上
4.
做完 checkout 後,你可以看到自己的電腦上出現了專案
先輸入 cvs edit xxxx
然後就可以做編輯了,你可以試著亂改, 加上一些註解或無聊的程式碼
做完修改後,當然要放回 server 囉
你可以用
cvs commit [檔案名稱]
指令來更新回 server, 更新之前, cvs 會打開 editor 讓你輸入一些文字,為這次的修改作一些說明
對了,如果別人在你修改之前修改了這個檔案,那麼 cvs 會自動將檔案作合併,讓你再去做編輯,請務必玩一玩
5.
如果要看目前的狀況,就打
cvs status [檔案名稱]
cvs diff [檔案名稱]
cvs history [檔案名稱]
來查看各種狀況
6.
不想要這個檔案加入版本管理的話,得先刪除該檔案後,再使用
cvs remove [檔案名稱]
來移除
7.若要登出 cvs server,則輸入 cvs logout 即可

autofs 的應用

這是在這一期(2002/05)的 Linux Journal 看到的~~
以下是我的摘錄:
首先先假設你已經有了一堆 iso 檔案~
如果沒有
你可以用 cat /dev/cdrom > image1.iso 來建立 iso 檔案
要不然也可以利用免費的 iso buster 來建立 iso 檔案
再放到 Linux 上去
我們把這些 iso 檔案都放到 /mnt/images 下面
然後安裝 automount 套件~~
這個套件,CD 裡面應該就有附上了~
安裝以後,利用 chkconfig –list automount
確定 automount 會開機時自動啟動.
編輯 /etc/auto.master,
加上
/mnt/isosrv_auto /etc/auto.isorv –timeout=60
這表示 automount 會參考 /etc/auto.isorv 這個設定檔,自動掛載設定中的檔案系統到 /mnt/isosrv_auto 下
建立 /etc/auto.isorv
加上
image1 “tab” -fstype=iso9660,ro,loop “tab” :/mnt/images/redhat73_1.iso
上面這行的 表示要用 tab 分開(這是我自己實驗後的心得,automount 似乎會認格式)
image1 表示會在 /mnt/isosrv_auto 下建立的目錄名稱
-fstype=iso9660,ro,loop 表示檔案系統及參數
:/mnt/images/redhat73_1.iso 表示來源的所在位置
這樣設定之後
當你 ls /mnt/isosrv_auto/image1 的時候,linux 就會自動幫你掛載上去了
因為 ls /mnt/isosrv_auto 的時候,並沒有東西顯示,也因此無法得知有什麼目錄可以使用,此時可藉著 symbolic link 解決此問題
舉例來說,我們又另外建立 /mnt/CDs
然後在 /mnt/CDs 下建立 symbolic link 連結到 /mnt/isosrv_auto/image1
ln -s /mnt/isosrv_auto/image1 image1
這樣當你 ls /mnt/CDs 的時候
不就知道有什麼目錄了嗎?
套件的名字是叫做 autofs
後記:後來才知道除了 isofs 之外,這也能把一些其他的 filesystem 掛載進來,所以能應用的範圍就更廣囉.比如說可以配合 crond 用在自動備份上面,也是非常方便的呢. ^_^

cvsweb.cgi

前幾天, 友人找到一個不錯的 cvs web 介面,粉漂亮
是用 Perl 寫的CGI,於是我試著把他裝在 cvs server 上面~
一般的安裝方法,就是找到你的 httpd 伺服器,然後放在 cgi-bin/ 下面
以 redhat 為例,就是放在 /var/www/cgi-bin/ 下面
並且把執行的屬性改為執行~執行的擁有者改為適當的擁有者
但是在安裝以後
發現友人給我的檔案無法使用
於是我 follow 該檔裡面的網址前去下載~~
網址如下:
http://www.freebsd.org/cgi/cvsweb.cgi/www/en/cgi/cvsweb.cgi/
下載之後
發現仍然無法使用
他告訴我還需要
cgi-style.pl
我的老天,網海茫茫,到哪裡去找??
後來突然發現
http://www.freebsd.org/cgi/cvsweb.cgi/www/en/cgi/
這邊就可以看到 cgi-style.pl
下載之後
又發現我沒有 cvsweb.conf
於是再次從
http://www.freebsd.org/cgi/cvsweb.cgi/www/en/cgi/
找到 cvsweb.conf
這樣子,檔案就全部到齊了
請用編輯器打開 cvsweb.cgi, 找到以下這行
for (“$mydir/cvsweb.conf”, ‘/usr/local/etc/cvsweb/cvsweb.conf’) {
加入 /etc/cvsweb.conf,於是就變成
for (“$mydir/cvsweb.conf”, ‘/usr/local/etc/cvsweb/cvsweb.conf’,’/etc/cvsweb.conf’) {
然後再用編輯器打開 cvsweb.conf, 找到以下這行
@CVSrepositories = (
…….
);
這個 Perl 陣列裡面就是你的 CVS 存放的位置也就是 CVSROOT 所指的位置
請修改之以符合你的環境.
假設,你的 CVSROOT 是 /home/cvsroot/, 裡面有一個 respository 為 libs
那麼裡面就應該是
‘libs’ => [‘libs’, ‘/home/cvsroot’],
緊接著@CVSrepositories 下面,你會看到 %MIRRORS
如果你的 CVS Server 有 Mirror 的話
也請修改,否則的話,就把他清成空的,像是這樣~
%MIRRORS = (
);
修改之後,再打開瀏覽器去執行,果然看到 cvsweb 漂漂的畫面
一切就大功告成了~~
cvsweb.jpg

J2SE in linux安裝導引

首先到 Sun(http://java.sun.com) 網站下載最新版的 j2se for linux.
假設你下載的是最新版的 1.4 版,檔名是 j2sdk-1_4_0-fcs-linux-i386.rpm.bin
並放到 /download 資料夾中
$chmod +x j2sdk-1_4_0-fcs-linux-i386.rpm.bin
$./j2sdk-1_4_0-fcs-linux-ie86.rpm.bin
此時會詢問你是否同意其版權,選擇 yes 以後,將會解出 j2sdk-1_4_0-fcs-linux-ie86.rpm
$rpm -ivh j2sdk-1_4_0-fcs-linux-i386.rpm
這樣子就安裝完成了,預設會安裝到 /usr/java/j2sdk1.4.0/ 下,接著要做一些設定
請用你順手的文書編輯器,編輯 /etc/profile
加入這幾行
# Java
export CLASSPATH=.:/usr/java/j2sdk1.4.0/lib
PATH=”$PATH:/usr/java/j2sdk1.4.0/bin”
把 CLASSPATH 和 PATH 都指向 /usr/java/j2sdk1.4.0/ 下~
登出再重新登入之後,應該就可以使用 j2se 了
讓我們編寫一個簡單的 java 程式來實驗看看,程式碼如下

class HelloLinux {
public static void main(String[] args) {
System.out.println("Hello Linux!!");
}
}

並命名為 HelloLinux.java
用 javac HelloLinux.java 編譯之.
用 java HelloLinux 執行之,注意,此處不可以用 java HelloLinux.class, 否則會發生錯誤!!這也是初學者常有的錯誤之一~
運行順利的話,你應該會看到
Hello Linux!!
Yes, Hello Linux
絕佳的學習指引:
http://java.sun.com/docs/books/tutorial/
碁峰有把這部分出書~現在已經出到 3rd Edition 了~不錯!

RAMDisk on Linux

dd if=/dev/zero of=/dev/ram bs=1k count=32768
mke2fs /dev/ram
mount –t ext2 /dev/ram /mnt/ramdisk
這樣就有個Ramdisk的Parititon
進一步的應用,
要修改的地方還有lilo.conf, fstab, rc.local…

Apache SSI 筆記

設定:
在 <directory xxxx> </directory>中的 options 加上 "+Include".
若不想執行外部程式,則改用 IncludeNoExec

慣例命名:
一般都以 .shtml 或 .shtm 來命名.

命令格式:
<!–#命令 引數1=xxx 引數2=xxx…->

命令可以是:

1.config: 可用於顯示錯或設定時間,檔案大小的格式

引數有: errmsg, sizefmt, timefmt
如:<!--#config errmsg="error" -->
<!--#config sizefmt="bytes"-->
<!--#config timefmt="%m/%d/%y"-->

2.echo:列印變數

如:<!--#echo var="DATE_LOCAL"-->

3.exec:執行外部程式

如:<!--#exec cgi="/cgi-bin/prog.cgi"-->
<!--#exec cmd="prog"--> 會啟動 shell 來處理

4.fsize:印出指定檔案的大小

如:<!--#fsize file="路徑"-->
<!--#fsize virtual="URL"-->

5.flastmod:印出檔案最後修改日期

如:<!--#flastmod file="路徑"-->
<!--#flastmod virtual="URL"-->

6.include:將某檔案含括進來

如:<!--#include file="路徑"-->
<!--#include virtual="URL"-->

7.printenv:印出所有環境變數

如:<!--#printenv-->

8.set:自行設定變數

如:<!--#set var="home" value="index.shtml"-->

SSI 預設的變數:

  1. DATE_GMT
  2. DATE_LOCAL
  3. DOCUMENT_NAME
  4. DOCUMENT_URI
  5. LAST_MODIFIED

流程控制:

<!--#if expr="${REMOTE_HOST}=/206\.171\.50/&&${DOCUMENT_NAME}=/${DATE_LOCAL}/"-->
<!--#else-->
<!--#endif-->
p.s.若是變數,要加上${}以示區別.

devfs 架設過程實錄

devfs, 讓我想起 Linuxer 第 20 期正好有這麼一篇介紹的文章.
大家可以參考這篇文章來作做看.
以下是我嘗試架設的過程,我使用的kernel是 2.4.7-10:
首先要先把 kernel 中的選項打開,但是第一次進去找,我始終都找不到這個選項,後來把 “Prompt for development and/or incomplete code/drivers” 此選項打開之後,才在 File System 裡面找到.
然後就把他打開,重新 build kernel.
依照慣例,把 vmlinux, vmlinuz, System.map 都複製到 /boot 之後
我很快樂的重新開機,結果,開不起來. poor.
原來是因為沒有安裝 devfsd 的緣故~ Linuxer 的文章中有提到,而我以為 kernel 裡面已經有了說~ sad ~
上網去找到 devfsd.tar.gz, 這是最新的版本,不是 1.3.9 的喔~
下載之後,執行 make 來重新編譯
無法編譯,依照編譯的錯誤訊息指示
我在 linux/devfs.h 裡面的 #define DEVFSD_NOTIFY_CREATE 後面加上
#define DEVFSD_NOTIFY_DELETE 7
這行
同時在 make 的時候改用下列敘述來 make (這是在make時指定環境變數的方法)
KERNEL_DIR=/usr/src/linux make
然後就 compile ok 了
接著執行
make install
依照文章指示,/etc/rc.d/rc.sysint 裡面還要有一行
[-e /dev/.devfsd -a -x /bin/devfsd] && /sbin/devfsd /dev
可是我的 /etc/rc.d/rc.sysint 檔案裡面早就已經有了
注意,這一行要放在很前面喔,否則我猜想可能會開不起來
於是再重新開機
果然就 ok 了~~
可是,文字模式下的滑鼠起不來
於是我又把 /etc/sysconfig/mouse 裡面的 DEVICE 改為 /dev/psaux
重新開機後,文字模式下的滑鼠就 ok 了
可是有些特定的設備,我還不會設定( 設定檔在 /etc/devfsd.conf )
比如我自己寫的一個 driver 還是起不來~~
devfsd 相關的套件,可以利用 Google 搜尋引擎找到.
個人覺得 devfs 與原來的 /dev 相容性蠻高的,幾乎不用作什麼修改.在Documents/filesystems/devfs/README 這份文件說的蠻清楚的,什麼有支援,什麼不支援,裡面都有說~
/dev/mouse 是確定不支援的,要改成 /dev/psaux;其他的一些 driver,我想修改 /etc/devfsd.conf 應該一切都能搞定,只是我還不會設.
coding 的話~~
現在所有中文有關 kernel 的書,講到的 register_chrdev() 都是舊的方法.
如果要支援 devfs 的話,直接使用
devfs_register_chrdev() / devfs_unregister_chrdev()
devfs_register_blkdev() / devfs_unregister_blkdev()
devfs_register() / devfs_unregister()
來註冊,跟原來的語法用法是很接近的
函數的原型參考,可以在 include/linux/devfs_fs_kernel.h 裡面找到
事實上在 devfs_fs_kernel.h 裡面
已經有利用 CONFIG_DEVFS_FS 來作判斷了
當 CONFIG_DEVFS_FS 有被定義的時候, devfs_register() / devfs_unregister() 是有東西的,如果沒被定義,那麼則是空殼子~
此外 devfs_fs_kernel.h 裡面有許多關於 devfs 的函數,而函數的實作則是放在 fs/devfs/base.c 裡面~
driver 寫的時候,建議的順序是這樣子的(看了兩三個driver的source才了解)
1.用 devfs_handle_t 宣告一個 handle.
2.用 devfs_register_chrdev() / devfs_register_blkdev() 註冊裝備的動作,MAJOR號碼以及名稱
3.再用 devfs_register() 去 /dev 裡面註冊一個設備檔案
當然如果有很多的話,可以先用 devfs_mk_dir() 去註冊一個目錄,再利用 devfs_register_series() 去註冊一狗票的設備檔案或者利用迴圈去註冊一狗票的設備檔案.
然後就 ok 了
release 的時候,則是:
1. 先 devfs_unregister() 掉設備檔案
2. 再 devfs_unregister_chrdev() / devfs_unregister_blkdev()

Stream Server – icecast 架設實錄

前兩個星期在 Linux fab 上看到一則新聞
說 icecast 已經釋出新版本了
But what is icecast?
仔細一看
才明白,原來他是一個 stream server,就類似微軟的 media service.
這樣講也許還不是很清楚,拿個實例來說吧:如廣播電台,目前廣播電台都已經可以在網路上收聽了,他們就是架設一個 server 並提供一個 url, 讓你在 media player 或 real player 裡面輸入,於是你就可以收聽到即時的節目了.又比如之前紅極一時的Naked News也是這樣子做的,只是他們輸出的是影音新聞節目.
架設的時候你必須到 icecast 網站先取得 icecast 套件,目前最新的版本是 1.3.11.
取得之後,依照 linux 的慣例安裝三部曲,輸入
./configure
make
make install
於是安裝完成~~
接下來我切換到套件預設的安裝路徑 /usr/local/icecast/
將 conf 裡面的 icecast.conf.dist 複製到 /etc, 並命名為 icecast.conf
修改裡面的
streamurl 為 http://redhat71
server_name 為 redhat71
接著就要啟用囉
請輸入
/usr/local/icecast/bin/icecast -c /etc/icecast.conf -b
以啟動 icecast server
當然到這裡都很簡單,只是依照套件內附的文件行事而已
接下來,要怎麼讓音樂播放出來呢??
這可讓我傷透了腦筋
最後才在 icecast 網站的 getting start找到方法.
我用的是 shout, 這同樣也是 icecast 網站提供的另外一個套件
請下載 shout ,依照 linux 慣例安裝三部曲來安裝.
接著,要製作 mp3 play list
我們可以利用如下指令來製作
find /mnt/cdrom -name *.mp3 -print >> /etc/mp3.lst
不過據我實驗的結果,中文的檔案名稱似乎無法用 find 來取得~~討厭~~
本來想把所有的 mp3 都用 stream server 來播放的~
最後就可以使用如下的指令來將 mp3 塞到 stream server 了
/usr/local/icecast/bin/shout localhost -P hackme -a -x -p /etc/mp3.lst -l -n “A sample name”
shout 可接的參數,在此就不再贅述,可以自行加上 –help 參數來取得.
(看到 localhost 了嗎??這表示你也可以從遠端來控制要播出的節目喔.)