星期五, 5月 20, 2005

使用AWStats分析Web和Mail的紀錄檔心得

使用AWStats分析Web和Mail的紀錄檔
Lab環境 Fedora core 3

1.檢查是否有安裝Perl
#which perl
2.安裝AWStats
官方網站 http://awstats.sourceforge.net/#DOWNLOAD 下載RPM檔安裝
#rpm -ivh awstats-6.4-1.noarch.rpm
3.設定AWStats
#cd /usr/local/awstats/tools/
#./awstats_configure.pl
1.此時會要求輸入Apache設定檔位置 /etc/httpd/conf/httpd.conf
2.詢問是否要建立新設定檔----回答y
3.詢問網站位置--------輸入網站的位置
4.修改細部設定
#cd /etc/awstats/
#vi awstats.您的網站.conf
LogFile="/var/log/httpd/access_log"-----原來是mylog.log不正確
AllowAccessFromWebToFollowingIPAddresses="192.168.1.3-192.168.1.254"
設定允許看報表的ip範圍..建議加入conf中..因為實測時候發現粉耗費CPU
5.建立報表輸出資料夾(在之前的conf檔案有提到但是系統預設不存在)
#mkdir /var/lib/awstats
6.執行AWStats產生報表
#/usr/local/awstats/tools/awstats_updateall.pl now
7.排入crond 設定每日3點定時更新
#crontab -e
0 3 * * * /usr/local/awstats/tools/awstats_updateall.pl now
8.驗收成果
http://您的網站/awstats/awstats.pl
就可以看到Web報表

接下來來製作Mail分析報表
9.#cd /etc/awstats
#cp awstats.model.conf awstats.mail.conf (複製預設檔來做)
#vi awstats.mail.conf

列出修改的部份
< LogFile="/var/log/maillog"
< LogType=M
< #LogFormat=1
< LogFormat="%time2 %email %email_r %host %host_r %method %url %code %bytesd"
< sitedomain="您的網站"
< AllowAccessFromWebToFollowingIPAddresses="192.168.1.3-192.168.1.254"
< LevelForBrowsersDetection=0 # 0 disables Browsers detection.
< LevelForOSDetection=0 # 0 disables OS detection.
< LevelForRefererAnalyze=0 # 0 disables Origin detection.
< LevelForRobotsDetection=0 # 0 disables Robots detection.
< LevelForSearchEnginesDetection=0 # 0 disables Search engines detection.
< LevelForFileTypesDetection=0 # 0 disables File types detection.
< ShowMonthStats=HB
< ShowDaysOfMonthStats=HB
< ShowDaysOfWeekStats=HB
< ShowHoursStats=HB
< ShowDomainsStats=0
< ShowHostsStats=HBL
< ShowRobotsStats=0
< ShowEMailSenders=HBML
< ShowEMailReceivers=HBML
< ShowSessionsStats=0
< ShowPagesStats=0
< ShowFileTypesStats=0
< ShowOSStats=0
< ShowBrowsersStats=0
< ShowOriginStats=0
< ShowKeyphrasesStats=0
< ShowKeywordsStats=0
< ShowMiscStats=0
< ShowHTTPErrorsStats=0
< ShowSMTPErrorsStats=1

10.執行AWStats產生報表
#/usr/local/awstats/tools/awstats_updateall.pl now
11.驗收成果
http://您的網站/awstats/awstats.pl?config=mail
就可以看到Mail報表

使用Webalizer分析報表心得

在RedHat系列中大多都內建Webalizer這套分析軟體
使用rpm -qa | grep web查詢是否安裝

安裝後預設在/var/www/usage目錄
可以建立一個link連結usage達到用網頁監控的目的
#cd /var/www/html
#ln -s /var/www/usage status
就可以瀏覽http://yoursite/status來觀看

但可以先調整語系Fedora core 3 預設適用UTF-8
可改為Big5 修改/etc/httpd/conf/httpd.conf
#Max edit at 20th May 2005
#LanguagePriority en ca cs da de el eo es et fr he hr it ja ko ltz nl nn no pl pt pt-BR ru sv zh-CN zh-TW
LanguagePriority zh-TW en ca cs da de el eo es et fr he hr it ja ko ltz nl nn no pl pt pt-BR ru sv zh-CN

#Max edit at 20th May 2005
#AddDefaultCharset UTF-8
AddDefaultCharset Big5

重新啟動httpd
#service httpd restart

LINUX LPI 資格檢定讀書心得Part 2

1.7 使用正規表示式搜尋文字檔

globbing(使用萬用字符wildcard的行為)
操作可以同時列出或找出具有共同元素的檔案.但是若想將glob的概念延伸到任何一般的文字形式上就得靠正規表示式(regular expressions)的協助才行.

指令 grep
語法
grep [options] regex [files]

常用選項
-c 計算相符的列數
-h 顯示相符的每一列.但指定多檔時.不前置檔名
-i 忽略大小寫
-n 前置其列號
-v 顯示不相符的每一列

正規表示式內可以內含
中介字符(metacharacter)與字面字符(literal)
而且grep 可以只使用literal作為正規表示式

指令sed
語法
sed [options] 'command1' [files]
sed [options] -e 'command1' [-e 'command2'] [files]
sed [options] -f script [files]

正規表示式定義自數串文字或樣式(pattern). 而樣式是由中介字符(metacharacter)與字面字符(literal)所組成.所以當建構正規表示式時便可以使用中介字符(metacharacter)與字面字符(literal)對所要處理的輸入文字表達三個基本的意念:

1.位置定位符(Postition anchor)
用來指定一或多個字符位於整列文字的何處
2.字符集(Character set)
字符集可用來比對文字
3.數量修飾符(Quantity modifier)
代表與字符集的文字比對應該重複出現.讓正規表示式用有不定長度的文字比對能力

正規表示式的使用範例

定位符(anchor)

^ 比對一列之首
$ 比對一列之尾

範例1
顯示 file1檔中以 Linux 開頭的每一列文字

$grep '^Linux' file1

範例2
顯示file1檔中以 x 字符結尾的每一列文字

$grep 'x$' file1

群組與範圍

[abc] 符合a,b,或c的任一字符
[a-z] 符合範圍a到z的任一字符
[^abc] 非符合a,b,或c的任一字符
[^a-z] 非符合範圍a到z的任一字符
\ 比對單字
. 相符於newline以外的任一字符
\ 關閉其後所接字符的特殊意義

範例1
顯示 file1檔中包含 Linux 、 linux 的每一列文字
$grep '[Ll]inux' file1

範例2
顯示file1 包含連續三位數字的每一列
$grep '[0-9][0-9][0-9]' file1

範例3
顯示file1檔中任何非以一位數字起頭的每一列
$grep '^[^0-9]' file1

範例4
顯示file1檔中包含單字Linux或是linux (但不包含LinuxOS 或是 TurboLinux)的每一列
$grep '\<[Ll]inux\>' file1

範例5
顯示file1檔中包含五個或更多字符(newline字符不算在內)的每一列
$grep '.....' file1

範例6
顯示file1檔中包含一個句點(原是中介字符.但是使用倒斜線避開它的特殊意義)的每一列
$grep '\.' file1

修飾符

* 用來表示它之前的單一字符可能重現零次或多次
? 用來表示它之前的正規表示式可能重現零次或一次.屬延伸功能需使用-E才有作用
+ 用來表示它之前的正規表示式可能重現一次或多次.屬延伸功能需使用-E才有作用
\{n,m\} 用來表示它之前的單一字符可能重現的次數範圍
| 交替比對.可比對| 之前或是之後的正規表示式.屬延伸功能需使用-E才有作用

範例1
顯示file1檔中包含ab abc abcc 或是abccc等等的每一列
$grep 'abc*' file1

範例2
顯示file1檔中包含ab abc abcc 或是abccc(但是不包含ab)等等的每一列
$grep 'abcc*' file1

範例3
顯示file1檔中包含連續兩位或多位數字的每一列
$grep '[0-9][0-9][0-9]*' file1

範例4
顯示file1檔中包含file,file1,或是file2字樣的每一列
$grep -E 'file[12]?' file1

範例5
顯示file1檔中至少包含一位數字的每一列
$grep -E '[0-9]+' file1

範例6
顯示flie1檔中只包含111,1111,或是11111的每一列
$grep '^1\{3,5\}$' file1

範例7
顯示file1檔中包含3位4位或是5位數字的每一列
$grep '\<[0-9]\{3,5\}\>' file1

範例8
顯示file1檔中包含Happy,happy,Sad,sad,Angry,angry的每一列
$grep -E '[Hh]appy|[Ss]ad|[Aa]ngry' file1

星期五, 5月 13, 2005

資訊安全理論與實務讀後心得

密碼技術可以達到下列四項功能
1.隱密性
2.可認証性
3.完整性
4.不可否認性

兩大密碼系統
1.對稱式金鑰 Symmetric Key
著名的演算法有DES RC4 RC5 IDEA SAFER FEAL Skipjack Rijndael(AES)

DES演算法(Data Encryption Standard)
1970年代由IBM提出.長度為56位元有時會輸入64個位元.則第8.16.24.32.40.48.56.64八個位元是同位檢查碼.在加解密時並沒有真正使用
2.非對稱式金鑰 Asymmetric key

星期二, 5月 03, 2005

linux心得--常用linux字元

- Single-dash 單破折號
$0 Command name
' ' Full quote (no expansion)
" " Partial quote (allows variable and command expansion)
$$ Process id
$* All arguments as a simple word
$n nth argument (n from 0 to 9)
$var Use avalue for variable
& Run process in background
() Execute in subshell
* wildcard (represents everything)
. Single Period (The current directory)
.. Double Period (Parent Directory)
; Separate commands on same line
? Single character wildcard
[] Match any characters enclosed
\ Quote the following character.Also used to break a command line to multiple lines
` ` back ticks (Substitute output of enclosed command)
| Pipe (Takes the stdout and it becomes the stdin for the command after the pipe)
< Redirect input
<< Uses a delimiter with text to pass as input a command
> Redirect output
>> Used to append data to another file

LPI LINUX 資格檢定讀書心得

Chapter 1
*大體來說,Unix系統的架構從內而外依序是
硬體Hardware--系統核心Kernel--系統呼叫System call--命令解譯器command interpreter(又稱為shell)
*命令列command line是指使用者在shell操作模式中.於提示符號之後所鍵入的一列完整命令.
其中包含: 命令.選項.以及引數串列
*bash (Bourne-Again Shell) 為linux系統上預設的shell
*Shell 變數簡介
PS1 ( Prompt String1 ) 第一個提示字串
可以用echo的指令來顯示PS1或其他shell變數的內容但是必須要變數名稱之前附加$符號

#echo $PS1
[\u@\h \W]\$

在此範例中
每個前置倒斜線的字符對bash而言都有其特殊的意義
\u會被代換成使用者名稱
\h會被代換成系統主機名稱
\W會被代換成現行工作目錄的最底層

PATH --存放命令以及執行程式的目錄清單
要讓bash可以順利找到並執行你在提示符號之後所鍵入的命令.該命令必須
#是一個bash內建的命令
#是一個可執行的程式.其所在目錄已列在PATH的變數中
#有明確的定義(完整路徑名稱)

*在linux系統上.使用者對shell所下達的命令.通常組成自四個部分
#一個有效的命令
#命令選項
#引數
#受理機制(即按下Enter鍵)

*若想要在單一的命令列上同時加入一筆以上的命令應該依序執行順序鍵入每筆命令並以分號(;)將他們隔開.
#ls ; ps

*命令歷程(history)
當bash以互動的模式執行時.可讓使用者存取自己先前所鍵入的命令.使用者所鍵入的每筆命令.都會先存放到歷程清單(history list). 再交由Shell 進行解譯.
history list 是由shell 變數 HISTSIZE所控制
一般於/etc/profile 中定義 預設為1000列
在bash session 結束之後會存放在 ~/.bash_history
並可以用history檢視命令的歷程
*請注意.如果同時啟動多個shell.那只有最後一個結束執行的shell才會將其所經歷過的命令寫入~/.bash_history

星期二, 4月 26, 2005

論語溫習

子曰:「學而時習之,不亦說乎?有朋自遠方來,不亦說乎?人不知而不慍,不亦君子乎?」

星期日, 4月 17, 2005

系統升級RH9 to FC3

今天做了desktop的升級
Redhat 9.0 to Fedora core 3
1.更改語系設定
#vi /etc/sysconfig/i18n
修改UTF-8 為Big5
2.更改輸入法設定為xcin
#service iiim stop
#chkconfig iiim off
功能表-系統設定-輸入法-調整為xcin
#vi /etc/chinese/xcin/xcinrc
修改自己喜歡的詞音輸入法
3.安裝apt
http://apt.nc.hcc.edu.tw
安裝apt套件並更新
4.安裝jpilot
使用jpilot-0.99-1
yum的版本到0.99-2但是中文會有亂碼故使用0.99-1
記得要chmod 666 /dev/ttyS0
5.升級firefox and thruderbird
移除原來的英文版改為中文版
6.安裝java環境
7.安裝openoffice 1.1.3 firefly 到/usr/local下
8.安裝thunderbird及設定e-mail account
9.升級flash player 到7.0版用tar ball的方式 /usr/local/firefox-installer
10.設定scanner for linux
11.安裝acrobat reader for linux

星期五, 4月 15, 2005

Sendmail+MailScanner4.40+Clamav0.83

今天心血來潮
又做了一次Sendmail+MailScanner4.40+Clamav0.83
O/S: Redhat 9.0
Mail server: Sendmail
使用套件: clamav-0.83
clamav-db-0.83
MailScanner-4.40


1.取得MailScanner

http://www.sng.ecs.soton.ac.uk/mailscanner/

點選Download 選取您的版本並儲存

2.解壓縮檔案 小弟抓的是4.40版

#tar zxvf MailScanner-4.40.11-1.rpm.tar.gz

3.安裝MailScanner
#cd MailScanner-4.40.11-1/
#./install.sh

完成MailScanner 的安裝

4.取得防毒軟體 Clam AntiVirus
由rpmfind.org 下載 clamav套件
關鍵字 clamav and clamav-db

下載: http://dag.wieers.com/packages/clamav/

5.安裝clamav套件

#rpm -ivh clamav-db-0.83-1.0.rh9.rf.i386.rpm
#rpm -ivh clamav-0.83-1.0.rh9.rf.i386.rpm
#rpm -ivh clamav-devel-0.83-1.0.rh9.rf.i386.rpm
#rpm -ivh clamav-milter-0.83-1.0.rh9.rf.i386.rpm
#rpm -ivh clamd-0.83-1.0.rh9.rf.i386.rpm

6.修改Mail Scanner 設定讓Mail Scanner 和 Clam Anti Virus結合

#cd /etc/MailScanner
#vi MailScanner.conf

找尋 Virus Scanner = none
改成 Virus Scanner = clamav
修改一下MailScanner的設定檔
%org-name% = yoursite -->個人或公司的簡稱
%org-long-name% = Your Organisation Name Here --> 公司或個人全名
%web-site% = www.your-organisation.com --> 公司或個人網址
Notify Senders = no --> 不通知原寄信人....如果他是廣告商怎辦^^還通知他勒
Virus Subject Text = {病毒信?} --> 收到病毒信加上{病毒信?}的字串原來是英文改中文
Spam Subject Text = {廣告信?} --> 收到廣告信加上{廣告信?}的字串原來是英文改中文
Archive Mail = /var/spool/MailScanner/archive -->備份寄出/入信件於指定目錄...請注意隱私權的問題還有必須手動建立目錄 #mkdir /var/spool/MailScanner/archive

儲存後離開 (:wq)

7.讓MailScanner 接手Sendmail的工作啟動防毒機制

#service sendmail stop
#chkconfig sendmail off
#chkconfig --level 2345 MailScanner on
#service MailScanner start


8.啟動clamd 讓clamav 定時更新
#service clamd start

星期日, 4月 10, 2005

舊的筆記移轉

把之前的舊筆記移過來

讓FC3可以收信

FEDORA3 將IMAP,POP3包裝成一個,套件dovecot-0.99.11-1.FC3.4
或是你要使用cyrus-imapd 就必須安裝這些套件
cyrus-imapd-utils-2.2.10-3.fc3
cyrus-imapd-2.2.10-3.fc3
cyrus-imapd-devel-2.2.10-3.fc3
cyrus-imapd-nntp-2.2.10-3.fc3
cyrus-imapd-murder-2.2.10-3.fc3

1.(在mail server部份要勾選 cyrus-imapd的套件)

2.修改 /etc/dovecot.conf

將protocols = imap imaps 改成
protocols = imap imaps pop3 pop3s

3. 重新啟動 dovecot

Service dovecot restart

4. 安裝完成

*************************************************
Practice some shell scripts
if else fi practice
#vi shell.sh

#!/bin/sh
#
#my shell 2
#
ans=0
echo "choice your language"
echo "1.Chinese"
echo "2.English"
echo -n "Please make your choice [1 or 2]"
read ans

if test $ans -eq 1;then
echo "your language is Chinese"

else ###nested if i.e if within if####
if test $ans -eq 2;then
echo "your language is English"
else
echo "wrong choice"
fi
fi
*************************************************
設定scanner for linux
軟體----xsane
硬體:acer szw 3300U

原本的情形是看得到掃描器於hwbrowser
但是無法使用xsane
參考網站
http://snapscan.sourceforge.net/
決定性的網頁......
告訴我要從windows的驅動程式中把bin拷貝到linux
並且要修改/etc/sane.d/snapscan.conf
把其中的路徑指向拷貝過來的BIN

# Change to the fully qualified filename of your firmware file, if
# firmware upload is needed by the scanner
firmware /home/max/U176V042.BIN
#U176V042.BIN 就是從windos driver 拷貝過來的bin

就可以正常使用了

其他網頁
http://phorum.study-area.org/viewtopic.php?t=11299
*************************************************
轉貼自酷學園
http://phorum.study-area.org/viewtopic.php?t=20200
於文中有些在實作上有小小的修正



如何於RED HAT 9.0 的NAT下使用MSN6.1的語音及網路攝影機通訊(使用UPnP)
前言:
花了一晚的時間找了一些資料實驗(大部份是原始程式網站的討論區)實驗成功,不用每次拔網路線了
1.作業環境:
linux red hat 9.0(使用iptables做nat)
我的eth0 為對外NIC eth1 為對內NIC

rpm -q e2fsprogs 如果沒有請安裝
win xp pro(directx 9.0b,msn6.1)
固定ip

2.準備檔案:
下載
libupnp-1.2.1a.tar.gz
http://prdownloads.sourceforge.net/upnp/libupnp-1.2.1a.tar.gz?download
至/tmp或你要的目錄中

linux-igd
在這裡使用cvs的方式取得最新版,請在shell的提示後執行
cd /tmp
cvs -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/linux-igd login
會出現PASSWORD,請直接按ENTER
cvs -z3 -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/linux-igd co linux-igd

3.開始安裝:
在/tmp下執行
tar zxvf libupnp-1.2.1a.tar.gz
cd libupnp-1.2.1a
cd upnp 這裡和文中的不一樣請注意
make
make install

在這裡不知為何,有些東西無法正確複製至/usr/include/upnp及/usr/lib中
請再至libupnp-1.2.1a中的ixml及threadutil做個make
再請以手動複製

cp libupnp-1.2.1a/ixml/inc/* /usr/include/upnp/
cp libupnp-1.2.1a/ixml/bin/* /usr/lib
cp libupnp-1.2.1a/threadutil/inc/* /usr/include/upnp/
cp libupnp-1.2.1a/threadutil/bin/* /usr/lib
上面這一段是參考英文版修改的


應該可以執行下一步了
cd /tmp/linux-igd
make
make install
看看還有沒有錯誤,如果有錯,找一下.h和.so是否沒有複製至適當位置

4.執行
請先至/etc
vi upnpd.conf

# The full path and name of the iptables executable
#
#iptables_location = /usr/sbin/iptables -->這是原來的設定,如果用tarball的話應該是這裡沒錯
iptables_location = /sbin/iptables -->我是用rpm安裝的,所以在sbin裡

存檔
其它設定我是用內定的
log檔
vi syslog.conf
在最後加入
#upnpd log
*.=debug /var/log/upnpdebug

存檔
執行
route add -net 239.0.0.0 netmask 255.0.0.0 eth1
這裡也配合環境修改過
現在執行upnpd eth1 eth0
如果是用ppp0的請自己改

執行後,在xp的網路連線裡會出現一個網際網路閘道群組,裡面有個網際網路連線,在此不貼圖了

在xp上執行msn,找個人試試語音及視訊會議吧。
**************************************************
bandwidthd 安裝心得
實驗環境
O/S: Redhat 9.0

心得:實務上安裝的時候需再安裝
gd-devel-1.8.4-11.i386.rpm
libpng-devel-1.2.2-16.i386.rpm
兩個函式庫檔案 在cdrom disk 2
才可以順利make install



以下轉貼臥龍小三大大的文章:
臥龍小三專欄 : 追蹤並圖型顯示 TCP/IP 網路使用狀況:bandwidthd
發表者 ols3 於 2004-01-15 11:36:12 (8398 人氣)

OLS3 推薦軟體:bandwidthd

'bandwidthd' 可以用來追蹤並以圖型化、網頁化的方式,顯示你的 TCP/IP 網段中的使用狀況。

bandwidthd 圖型化是以網段中各自獨立的 IP 為對象,它可以不同的色彩來顯示 HTTP, TCP, UDP, ICMP, VPN 以及 P2P 協定的交通流量。

和 MRTG 不同的是,'bandwidthd' 追蹤的是各別的 IP 用量,而不像 MRTG 是顯示某一網路介面的總量,對於網管人員而言,bandwidthd 可說是一項好用的利器。

* bandwidthd 採用 GPL 授權,原始網址如下:

http://bandwidthd.sourceforge.net/

下載位址:

http://sourceforge.net/project/showfiles.php?group_id=89685&release_id=184856

或由敝中心下載:

ftp://ftp.tnc.edu.tw/pub/bandwidthd

* 安裝

bandwidthd 的安裝方法可說十分簡單,

首先您要檢查一下基本的配備是否充足:

須先安裝有以下函式庫:

libpcap ( http://www.tcpdump.org/ )
libpng ( http://www.libpng.org/ )
libgd ( http://www.boutell.com/gd/ )

系統須有支援 System V IPC (大部份 Unix/Linux 都有)

接著,便可來安裝 bandwidthd 啦!

ncftp ftp.tnc.edu.tw

cd pub/bandwidthd

get bandwidthd-1.2.0.tgz

quit

以 root 身份執行以下動作

tar xvzf bandwidthd-1.2.0.tgz

cd bandwidthd-1.2.0

make install

至此即已安裝完成,它會將 bandwidthd 安裝 至 /usr/local/bandwidthd 下

* 設定

bandwidthd 的設定可說超級簡單,請編輯:

/usr/local/bandwidthd/etc/bandwidthd.conf

把其中 subnet 的設定設好即可,以 203.68.102.0/26 四分之一網段為例:

subnet 203.68.102.0 255.255.255.192

存檔之後,便可準備執行。

* 執行

cd /usr/local/bandwidthd
./bandwidthd

* 顯示:

在您的 web 主目錄下即行

ln -s /usr/local/bandwidthd/htdocs bandwidthd

接著您便可用 http://您的主機/bandwidthd
看到網路中各主機的頻寬使用情況啦!

* 統計結果圖例:

http://bandwidthd.sourceforge.net/demo/

* 結語:

這個工具真是太棒了! 小而美,方便實用不傷神,值得小型網路管理者試試!

OLS3 下次再為您報導更好的軟體喲!
**************************************************
磁碟限額 quota 實作
1.針對Filesystem {Partition}
2.對象: User or Group
3.限制內容: 1.使用空間
2.建立檔案數量

實驗環境
O/S: Redhat 9.0

Target: 限制max 在/home Filesystem 可使用空間在4MB ~ 5MB 之間 可建立 60~100檔案

1.#vi /etc/fstab
LABEL=/home /home ext3 defaults,usrquota 0 0

2.讓new option生效
#mount -o remount /home

3.初始化quota DB
#quotacheck -c /home

4.#quotaon /home

5.編寫限制max的quota
#edquota max
Filesystem block soft hard inode soft hard
/dev/hda# 76 4096 5120 10 60 100

6.測試
#su - max
$quota
$dd if=/dev/zero of=big bs=1M count=6
此時應該是不行的



edquota -p user1 user2 user3

edquota -t

repquota /dev/hd#

§使用warnquota 以郵件的方式通知超過soft limit 的 user
1.#vi /etc/warnquota.conf
加入自訂內容

2.#touch /etc/quotatab
#vi /etc/quotatab
/dev/hda3:您的家目錄

3.#warnquota

4.#crontab -e
* 0 * * * /usr/sbin/warnquota

大功告成
*************************************************
Sendmail 的防毒機制
可以使用 Mailsacnner + Clam Antivirus 來做具防毒功能的伺服器

建置環境
O/S: Redhat 9.0
Mail server: Sendmail
使用套件: clamav-0.65-1.1.i386.rpm
clamav-db-0.65-1.1.i386.rpm
MailScanner-4.30.3-2.rpm.tar.gz


1.取得MailScanner

http://www.sng.ecs.soton.ac.uk/mailscanner/

點選Download 選取您的版本並儲存

2.解壓縮檔案 小弟抓的是4.30.3-2版

#tar zxvf MailScanner-4.30.3-2.rpm.tar.gz

3.安裝MailScanner
#cd MailScanner-4.30.3-2
#./Update-MakeMaker.sh
#./install.sh

完成MailScanner 的安裝

4.取得防毒軟體 Clam AntiVirus
由rpmfind.org 下載 clamav套件
關鍵字 clamav and clamav-db

下載: http://rpmfind.net/

5.安裝clamav套件

#rpm -ivh clamav-db-0.65-1.1.i386.rpm
#rpm -ivh clamav-0.65-1.1.i386.rpm

6.修改Mail Scanner 設定讓Mail Scanner 和 Clam Anti Virus結合

#vi /etc/MailScanner
#vi MailScanner.conf

找尋 Virus Scanner = none
改成 Virus Scanner = clamav
儲存後離開 (:wq)

7.讓MailScanner 接手Sendmail的工作啟動防毒機制

#service sendmail stop
#chkconfig sendmail off
#chkconfig --level 2345 MailScanner on
#service MailScanner start

8.建立一個clam uptedate的log以查詢升級狀況
#touch /var/log/clam-update.log
#chmod 600 /var/log/clam-update.log
#chown clamav /var/log/clam-update.log

9.測試升級clamav 並寫入到log

#freshclam -d -c 6 -l /var/log/clam-update.log

10.將自動升級clam寫入crontab中
#crontab -e
0 * * * * /usr/bin/freshclam --quiet -l /var/log/clam-update.log

大功告成啦

這裡有
0.70版的rpm喔
http://dag.wieers.com/packages/clamav
**************************************************
plugin 網頁

http://mplayerplug-in.sourceforge.net/

如果要在mozilla中觀看mplayer的影片
必須加裝
1.mplayerplug-in 的套件
2.mplayer 的套件

mplayerplug-in 的取得處
http://mplayerplug-in.sourceforge.net/download.html

mplayer 的取得處
http://freshrpms.net

先安裝mplayer 在安裝完 mplayerplun-in 以後您的mozilla 就可看
mediaplayer的影片啦

^_^

**************************************************
主機的備分問題一直是粉多人的煩惱之一
在這裡使用 rsync 這個套件 來作兩台電腦的資料備份

環境說明

server (需要備份的主機.目前運作中的機器) :
O/S:Redhat 9.0
ip : 192.168.0.2
user : root
欲備份目錄 : /test (實驗用.預設沒有此目錄請自行建立)

client (遠端存放備份的機器.不提供服務只備份資料) :
O/S:Redhat 9.0
ip : 192.168.0.253
user : root
存放資料目錄 : /test (實驗用.預設沒有此目錄請自行建立)

分兩個部分來做

server 部分:

1.首先檢查有沒有rsync 套件 (Redhat 預設都會裝)
#rpm -q rsync
rsync-2.5.5-4

2.開啟rsync的服務並檢查狀態
#chkconfig rsync on
#chkconfig rsync --list
rsync 開啟

client 部分:
為了使用SSH加密傳輸且不需要輸入密碼

1.#cd /root/.ssh (進入到/root/.ssh/ 目錄下)
2.#ssh-keygen -d (產生ssh的公鑰和私鑰)
Generating public/private dsa key pair.
Enter file in which to save the key (/root/.ssh/id_dsa): (產生到何處.按Enter 就可以了)
Enter passphrase (empty for no passphrase): (要不要設定passwd.避免問我們按Enter 就可以了)
Enter same passphrase again: (再按一次Enter)
Your identification has been saved in /root/.ssh/id_dsa.
Your public key has been saved in /root/.ssh/id_dsa.pub.

此時目錄下會產生公鑰id_dsa.pub和私鑰id_dsa
現在要把id_dsa.pub丟到192.168.0.2 並且更名為 authorized_keys

3.#scp id_dsa.pub 192.168.0.2:/root/.ssh/authorized_keys
root@192.168.0.2's password:
id_dsa.pub 100% |*****************************| 613 00:00

試試看 ssh 到server 應該就不用輸入密碼了
4.#ssh 192.168.0.2
#exit (記得離開)
5.#cd /usr/local/bin (要寫一個shell script 在 /usr/local/bin下 故先到此目錄下)
#vi sync
rsync -avlR --delete -e ssh 192.168.0.2:/test /
(把192.168.0.2下面的 /test 目錄 備份到本機上的 / , 因為備份會產生test這個資料夾.所以本機上設定為/)
(讓/test => /test 而不是 /test => /test/test)
參數意義如下﹕

-a, --archive
It is a quick way of saying you want recursion and want to preserve almost everything.
-v, --verbose
This option increases the amount of information you are given during the transfer.
-l, --links
When symlinks are encountered, recreate the symlink on the destination.
-R, --relative
Use relative paths. 保留相對路徑...才不會讓子目錄跟 parent 擠在同一層...
--delete
是指如果Server端刪除了一文件,那客戶端也相應把這一文件刪除,保持真正的一致。
-e ssh
建立起加密的連接。
6.#chmod 700 sync 只讓root 可以使用
7.#./sync (執行sync這個script.........此時你就會發現兩台電腦的/test是同步的呢^_^)


參考文件
小弟的心得是參考以下的文件來製作

http://www.adj.idv.tw/server/linux_rsync.php
http://www.fanqiang.com/a6/b7/20010908/1305001258_b.html
http://phorum.study-area.org/viewtopic.php?t=15553&highlight=rsync
http://linux.tnc.edu.tw/techdoc/rsync
**************************************************
Macromedia Flash Player 6 for x86 Linux
此套件能解決 MOZILIA 原本在觀看FLASH無法觀看的狀況

測試環境
O/S : 9.0

所需套件
flash-plugin-6.0.81-1.i386.rpm

下載頁面
http://ruslug.rutgers.edu/macromedia/site_ru.html

下載回來之後
於終端機輸入指令 此時必須為root身分
#rpm -Uvh 套件名稱

這樣就大功告成啦^_^
以後瀏覽器就可以正常的觀看FLASH
**************************************************
REALPLAYER FOR LINUX
是可以解決LINUX使用者在網路上收聽 .rm格式還有撥放 .mp3的有利工具
測試環境
O/S : Redhat 9.0

所需套件
RealPlayer9-9.0.7.151-4.i386.rpm

下載頁面
http://rpm.pbone.net/index.php3/stat/4/idpl/713146/com/RealPlayer9-9.0.7.151-4.i386.rpm.html

openmotif21-2.1.30-8.i386.rpm

下載頁面 (這個rpm 套件在光碟的第2片也有.建議用光碟的比較快)
http://www.itp.tu-graz.ac.at/Comp/RPM/rh-9/openmotif21-2.1.30-8.i386.html

下載回來之後
於終端機輸入指令 此時必須為root身分
#rpm -Uvh 套件名稱

這樣就大功告成啦^_^
點選小红帽-音效和視訊-realplayer

就可以用realplayer 聽音樂了
**************************************************
GAIM 的安裝和使用
GAIM 是整合目前常見的即時通訊軟體.....如MSN, YAHOO MESSENGER,ICQ...等
REDHAT 9.0 內含GAIM 0.59版但是目前已經不敷使用必須升級至0.74版以上才可以
YAHOO MESSENGER 目前的加密問題還未解決. 故只用在MSN AND ICQ....
測試環境
O/S : Redhat 9.0

所需套件
gaim-0.76-0rh9.i386.rpm
gaim-devel-0.76-0rh9.i386.rpm

下載頁面
http://gaim.sourceforge.net/downloads.php



請選取適合自己的版本的RPM 或是 TARBALL
另外還必須安裝
gtkspell這個套件
gtkspell-2.0.4-fr3.i386.rpm
gtkspell-devel-2.0.4-fr3.i386.rpm

下載頁面
http://shrike.freshrpms.net/

下載回來之後
於終端機輸入指令 此時必須為root身分
#rpm -Uvh 套件名稱

這樣就大功告成啦^_^
點選小红帽-網際網路-gaim
設定個人的帳號和密碼

就可以享受用open source 上網聊天的快樂
**************************************************
研討會心得-----CA認證的製作1. cd /usr/share/ssl/misc
2. ./CA -newca
3.設定private key 密碼
填寫CA的資訊

CA的憑證會在
/usr/share/ssl/misc/demoCA/cacert.pem

CA的private Key
/usr/share/ssl/misc/demoCA/private/cakey.pem
此時CA已經建立完成

再來建立user
1. cd /usr/share/ssl/misc

2. ./CA -newreq

3.設定private key 密碼 填寫申請者資訊

4.此時會產生一個檔案 newreq.pem

5. head -18 newreq.pem > private.key

6. vi newreq.pem 去除newreq.pem 內 private key 的部分
也就是前18行

再來要請CA作簽署的動作
1. cd /usr/share/ssl/misc

2. ./CA -sign (請注意檔名必須為newreq.pem 且在/usr/share/ssl/misc 下)

3.輸入 CA private 的密碼 及user private key的密碼
按y 檢是申請人資訊
按y同意簽署
此時會產生 newcert.pem 的憑證檔
也就是簽署完畢

要讓user 使用

必須轉成.p12 ---------for windows user

在此之前
先mkdir username 在/usr/share/ssl/misc 下
方便管理
mv newcert.pem newreq.pem private.key userfolder/

cd /usr/share/ssl/misc/user

openssl pkcs12 -export -in newcert.pem -out username.p12 -inkey private.key

用上述的指令把.pem 轉成 .p12

openssl x509 -in newcert.pem -outform der -out username.der

用上述的指令把.pem 轉成 der -------------給LDAP用

接下來複製CA的憑證更改為副檔名 .crt

cp /usr/share/ssl/misc/demoCA/cacert.pem cacert.crt

這樣windows 的 user就可以匯入使用

在windows Client的部分

下載或是由磁片把 username.12 還有 cacert.crt
複製到機器上
於檔案上按兩下左鍵進行安裝
此時在開始-控制台-網際網路選項-內容-憑證內
應該會看到已經安裝好憑證
個人的標籤會有個人的憑證
信任的根目錄會有CA的憑證

開啟outlook express
工具-帳號-選取帳號-內容-安全性
在憑證簽章 還有加密選項設定 都要按
選擇-選取憑證-確定
確定

這樣就大功告成了

以後傳送郵件就有簽章及加密的功能

**************************************************
RRAS 遠端存取及路由
(ROUTER AND REMOTE ACCESS SERVICE)
架設環境

Linux(NAT & DHCP) 61.X.X.X
| 192.168.1
|
2000 (NAT & DHCP) 192.168.1.
| 192.168.58.
|
98 DHCP CLINET 192.168.58.X

2000:
對外:192.168.1.
對內:192.168.58.X

98:
DHCP 指定

方式一
控制台-系統管理工具
方式二
開始-執行-rrasmgmt.msc

執行中-----綠色向上箭頭

1.啟動服務(執行-啟用)
2.路由型態(服務方式)於機器上按右鍵-設定和啟動路由及遠端存取
3. 出現精靈-下一步-選取INTERNET連線伺服器-下一步-設定含有網路位址轉譯(NAT)路由通訊協定的路由器-下一步-選取對外網卡(使用選取的 INTERNET連線)-下一步-選取對內網卡(選取可以存取INTERNET的網路路由介面)-下一步-啟用基本的名稱及位址服務-下一步-觀看位址指 派範圍-下一步-完成

操作影片
http://www.atos.org.tw/images/Test
**************************************************
NFS 網路檔案分享
NETWORK FILE SYSTEM
使用RPC協定
REMOTE PROCEDURE CALL 遠端程序呼叫
需要
rpc.nfsd 管理Client能否登入主機的權限
rpc.mountd 管理NFS的檔案系統
必須先啟動portmap
必須有nfs-utils

設定檔:
/etc/exports 主要設定檔
指令:
/usr/sbin/exportfs 分享目錄資料
/usr/sbin/showmount 查看分享目錄
/var/lib/nfs/xtab NFS紀錄檔

啟動服務

/etc/rc.d/init.d/portmap start
/etc/rc.d/init.d/nfs start

掛載遠端主機
mount -t nfs 主機名稱:目錄 mountpoint

防火牆設定

iptables -A INPUT -p TCP --dport 111 -j ACCEPT
iptables -A INPUT -p UDP --dport 111 -j ACCEPT
*************************************************
架設環境
REDHAT 9.0

取得並安裝套件 OPENWEBMAIL2.30

http://openwebmail.org/openwebmail/download/redhat/rpm/release/openwebmail-2.30-1.i386.rpm

http://openwebmail.org/openwebmail/download/redhat/rpm/packages/rh9/perl-CGI-2.81-88.i386.rpm

http://openwebmail.org/openwebmail/download/redhat/rpm/packages/rh9/perl-Compress-Zlib-1.21-RH9.i386.rpm

http://openwebmail.org/openwebmail/download/redhat/rpm/packages/rh9/perl-Text-Iconv-1.2-RH80.i386.rpm

http://openwebmail.org/openwebmail/download/redhat/rpm/packages/rh9/perl-suidperl-5.8.0-88.i386.rpm

http://openwebmail.org/openwebmail/download/redhat/rpm/packages/rh9/optional/perl-CGI-SpeedyCGI-2.21-RH9.i386.rpm

#/var/www/cgi-bin/openwebmail/openwebmail-tool.pl --init
按Enter (不用理會她的警告)
#cp /var/www/cgi-bin/openwebmail/etc/dbm.conf.default /var/www/cgi-bin/openwebmail/etc/dbm.conf
#vi /var/www/cgi-bin/openwebmail/etc/dbm.conf
dbm_ext .db
dbmopen_ext .db
dbmopen_haslock yes
#/var/www/cgi-bin/openwebmail/openwebmail-tool.pl --init

完成
登入到
http://yourdomain/cgi-bin/openwebmail/openwebmail.pl


大功告成
**************************************************

星期四, 4月 07, 2005

Linux VPN 心得筆記

為何要使用VPN (Virtual Private Network)?
可以在兩個或是兩個以上的網路
可建立通道tunnel來將封包加密以維護安全
可建立認證機制

那種情形不需要用到VPN
1.E-mail 加密
2.Wed 加密
3.遠端控制

因為都有其protocol 不用特別用VPN

VPN 的架構分兩大類
1. Site to Site
2. Clent to Site

VPN 兩端的private ip 儘可能的不要同一個網段


常用的VPN技術
***CIPE (Crypto IP Encapsulation)***
可適用於Site to Site & Client to Site
*簡單設定
*使用UDP--速度快
*可使用帳號/密碼 及key 驗證
*有win 2000 的Beta client
*Linux only not Open standard


CIPE 在redhat linux kernel中預設有支援且開啟
故只要設定User space 就可以了不用編譯核心
CIPE扮演一張網卡
設定檔 /etc/sysconfig/network-scripts/ifcfg-cipcb0
/etc/cipe/options.cipcb0 (user space設定檔)

Lab 架構
OS: redhat linux 9.0
PC1: 192.168.0.252
PC2: 192.168.0.249
Lab: Site to Site VPN

(PC1)#rpm -q cipe
(PC1)#cp /usr/share/doc/cipe-1.4.5/samples/redhat-ifcfg-cipcb0 /etc/sysconfig/network-scripts/ifcfg-cipcb0
(PC1)#vi /etc/sysconfig/network-scripts/ifcfg-cipcb0 #修改以下部份
USERCTL=no
MYPORT=6060
PEER=192.168.0.249:6060
PTPADDR=10.0.2.1
IPADDR=10.0.1.1
(PC1)#echo "key `dd if=/dev/random bs=1024 count=1 | md5sum | cut -c1-32`" > /etc/cipe/options.cipcb0
(PC1)#chmod 400 /etc/cipe/options.cipcb0
(PC1)#vi /etc/sysconfig/static-routes
any net 10.0.2.0 netmask 255.255.255.0 gw 10.0.2.1
(PC1)#service network restart
(PC2)#cp /usr/share/doc/cipe-1.4.5/samples/redhat-ifcfg-cipcb0 /etc/sysconfig/network-scripts/ifcfg-cipcb0
(PC2)#vi /etc/sysconfig/network-scripts/ifcfg-cipcb0 #修改以下部份
USERCTL=no
MYPORT=6060
PEER=192.168.0.252:6060
PTPADDR=10.0.1.1
IPADDR=10.0.2.1
(PC2)#scp 192.168.0.252:/etc/cipe/options.cipcb0 /etc/cipe
(PC2)#chmod 400 /etc/cipe/options.cipcb0
(PC2)#vi /etc/sysconfig/static-routes
any net 10.0.1.0 netmask 255.255.255.0 gw 10.0.1.1
(PC2)#service network restart

測試PC1 and PC2 互ping 對方並用tcpdump or ethereal 觀察只會看到UDP封包