2010年2月10日 星期三

只知道檔案部分內容,但不知道檔名也不知道這個檔案在哪裡要怎麼找到這個檔案?

        如果只知道想要搜尋的檔案中有一個特定字串 "Linux",但檔案名稱完全不記得也不知道這個檔案在哪裡,那要如何才能找到它呢?

        基本上要進行檔案全文比對一樣還是使用 grep 這個工具,由於不知道檔案所在位置,所以需要進行全檔案系統搜尋因此要加上「-r」,如果只想列出檔案名稱可以再加上「-l」這個選項,如此就能進行全檔案系統的含有特定字串檔案的搜尋。

 ==> grep -lr  <比對字串>  /*

2010年1月1日 星期五

安裝 PeerGuardian For Linux

a. 說明:

   PeerGuardian 是一套用來輔助防火牆的程式,裝在動物機上可以用來阻擋惡意 IP 的連線請求,透過黑名單機制也可以用來阻擋某些單位對於 P2P 程式的監控。
   
※一年多前的筆記,忘記參考資料來自哪個網站了....QQ

b.實作環境 :

   OS : Ubuntu 7.04
   CPU : Intel Celeron CPU 2.40GHz
   RAM : 3G

c.載點 : http://sourceforge.net/project/showfiles.php?group_id=131687&package_id=148849

d.安裝:

   $ sudo dpkg -i peerguardnf-1.5beta.i386.deb

e.建立設定檔目錄 :

   $ sudo mkdir /etc/peerguardian

f.建立啟動 Script :


   $sudo touch /usr/local/bin/peerguardian.sh
   $sudo chmod 750 /usr/local/bin/peerguardian.sh

g.peerguardian.sh 內容
=======================================
# version for bluetack.co.uk lists!
#!/bin/sh
# Update new blocklists and start/stop/restart PeerGuardian
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# testdescription
#
#CONFIGURATION
# Make sure PG_ETC points to the directory where
# you want to put your downloaded blocklists.
PG_ETC=/etc/peerguardian/
# Remove the lists you don't want to download and
# use from BLOCKLISTS.
BLOCKLISTS="level1"
PG_CONF=/etc/PG.conf
PG_LOG=/var/log/PG.log
PG_LIST=/etc/p2p.p2b.p2p
#The URL where the blocklists reside
URL=http://www.bluetack.co.uk/config
#The format of the lists to download
SUFFIX=gz
#The format after unpacking
SUFFIX2=txt

endscript () {
date +"------------ "%F" "%X" "%Z" End PeerGuardian Script"
exit $1
}
date +"------------ "%F" "%X" "%Z" Begin PeerGuardian $1"


case "$1" in
'start')
    cd "$PG_ETC"
    # check if blockfiles were updated:
    UPDATED=""
    for i in $BLOCKLISTS ; do
    TIMESTAMP=0
    if [ -e $i.$SUFFIX ] ; then
    TIMESTAMP=`stat --format=%y $i.$SUFFIX`
    echo "File $i.$SUFFIX last updated $TIMESTAMP"
    TIMESTAMP=`stat --format=%Y $i.$SUFFIX`
    fi
    wget -N $URL/$i.$SUFFIX
    if [ `stat --format=%Y $i.$SUFFIX` -gt $TIMESTAMP ] ; then
    UPDATED=$i
    fi
    done
  
    # if none of the blockfiles were updated:
    if [ -z $UPDATED ] ; then
    echo "No blocklists needed updating."
    echo "Starting PeerGuardian"
    mv $PG_LOG $PG_LOG.backup
    peerguardnf -h -m -d -c "$PG_CONF" -l "$PG_LOG"
    endscript 0
    fi
  
    # if any blockfiles were updated:
    for i in $BLOCKLISTS ; do
    gunzip -c $i.$SUFFIX > $i.$SUFFIX2
    BLOCKLISTSCAT="$BLOCKLISTSCAT $i.$SUFFIX2"
    done
    cat $BLOCKLISTSCAT | peerguardnf -f merged.p2b.p2p
    for i in $BLOCKLISTS ; do
    rm $i.$SUFFIX2
    done
    # uncomment below to unblock Yahoo! Mail and whatever
    # else needs unblocking here. Do this also in the
    # restart section.
    grep -v -i "yahoo\!" merged.p2b.p2p | grep -v -i "Microsoft" | grep -v "Google" > merged.p2b.p2p.tmp
    mv merged.p2b.p2p.tmp merged.p2b.p2p
    mv $PG_LIST $PG_LIST.backup
    mv merged.p2b.p2p $PG_LIST
    mv $PG_LOG $PG_LOG.backup
    echo "Starting PeerGuardian"
    peerguardnf -h -m -d -c "$PG_CONF" -l "$PG_LOG"
    endscript 0
    ;;

'stop')
    echo "Stopping PeerGuardian"
    killall peerguardnf > /dev/null 2>&1
    endscript 0
    ;;

'restart')
    cd "$PG_ETC"
    # check if blockfiles were updated:
    UPDATED=""
    for i in $BLOCKLISTS ; do
    TIMESTAMP=0
    if [ -e $i.$SUFFIX ] ; then
    TIMESTAMP=`stat --format=%y $i.$SUFFIX`
    echo "File $i.$SUFFIX last updated $TIMESTAMP"
    TIMESTAMP=`stat --format=%Y $i.$SUFFIX`
    fi
    wget -N $URL/$i.$SUFFIX
    if [ `stat --format=%Y $i.$SUFFIX` -gt $TIMESTAMP ] ; then
    UPDATED=$i
    fi
    done
  
    # if none of the blockfiles were updated:
    if [ -z $UPDATED ] ; then
    echo "No blocklists needed updating."
    echo "Stopping PeerGuardian"
    killall peerguardnf > /dev/null 2>&1
    mv $PG_LOG $PG_LOG.backup
    sleep 4
    echo "Starting PeerGuardian"
    peerguardnf -h -m -d -c "$PG_CONF" -l "$PG_LOG"
    endscript 0
    fi
  
    # if any blockfiles were updated:
    for i in $BLOCKLISTS ; do
    gunzip -c $i.$SUFFIX > $i.$SUFFIX2
    BLOCKLISTSCAT="$BLOCKLISTSCAT $i.$SUFFIX2"
    done
    cat $BLOCKLISTSCAT | peerguardnf -f merged.p2b.p2p
    for i in $BLOCKLISTS ; do
    rm $i.$SUFFIX2
    done
    # uncomment below to unblock Yahoo! Mail and whatever
    # else needs unblocking here. Do this also in the
    # restart section.
    grep -v -i "yahoo\!" merged.p2b.p2p | grep -v -i "Microsoft" | grep -v "Google" > merged.p2b.p2p.tmp
    mv merged.p2b.p2p.tmp merged.p2b.p2p
    echo "Stopping PeerGuardian"
    killall peerguardnf > /dev/null 2>&1
    mv $PG_LIST $PG_LIST.backup
    mv merged.p2b.p2p $PG_LIST
    mv $PG_LOG $PG_LOG.backup
    sleep 4
    echo "Starting PeerGuardian"
    peerguardnf -h -m -d -c "$PG_CONF" -l "$PG_LOG"
    endscript 0
    ;;

*)
    echo "Usage: $0 { start | stop | restart }"
    ;;
esac
exit 0
========================

h.啟動 :  $ sudo peerguardian.sh start
  重新啟動 : $ sudo peerguardian.sh restart
  停止 : $ sudo peerguardian.sh stop

i . 服務啟動層級設定

    當系統進入Runlevel 2、3、4、5 啟動 peerguardian

    $ ln -s /usr/local/bin/peerguardian.sh /etc/init.d/peerguardian.sh
    $ ln -s /etc/init.d/peerguardian.sh /etc/rc0.d/K20peerguardian.sh
    $ ln -s /etc/init.d/peerguardian.sh /etc/rc2.d/S95peerguardian.sh
    $ ln -s /etc/init.d/peerguardian.sh /etc/rc3.d/S95peerguardian.sh
    $ ln -s /etc/init.d/peerguardian.sh /etc/rc4.d/S95peerguardian.sh
    $ ln -s /etc/init.d/peerguardian.sh /etc/rc5.d/S95peerguardian.sh
    $ ln -s /etc/init.d/peerguardian.sh /etc/rc6.d/K20peerguardian.sh
===================================

j.建立自動更新機制


   $ touch /etc/cron.daily/pg.sh
   $ sudo chmod 750 /etc/cron.daily/pg.sh

k. pg.sh 的內容如下:
==========================
#!/bin/sh

/usr/local/bin/peerguardian.sh restart
================================


l.PeerGuardian的Log 檔位置在 :  /var/log/PG.log

01.1.1.監控.網路.iftop

01.1.1.監控.網路.iftop

        iftop是一套用來即時監控網路介面頻寬使用狀態的網路監控工具。

01.1.1.1.安裝

     實作環境
         a.OS : CentOS 5.4 @ VitrualBox 3.1.2r56127
         b.硬體 :
             1.CPU : Intel(R) Core(TM)2 Duo CPU T8300 @ 2.40GHz
             2.RAM : 1G

     a.iftop官方網站 : http://www.ex-parrot.com/~pdw/iftop/

     b.安裝需求 : 依官方網站的說明,安裝此套件系統需已安裝下列兩函式,







  • libcurses
    libpcap







     c.下載套件 :

    


 






2009年8月8日 星期六

Installing VirtualBox Guest Additions on Debian

出處:http://virtualbox.wordpress.com/doc/installing-guest-additions-on-debian/

  1. Login as root;
  2. Update your APT database with apt-get update;
  3. Install the latest security updates with apt-get upgrade;
  4. Install required packages with apt-get install build-essential module-assistant;
  5. Configure your system for building kernel modules by running m-a prepare;
  6. Click on Install Guest Additions… from the Devices menu, then run mount /media/cdrom.(在 Debian 500 這一步跳過)
  7. Run sh /media/cdrom/VBoxLinuxAdditions.run, and follow the instructions on screen.
蠻方便的,用apt-get就可以裝 VirtualBox 的 Additions

Debian PacKage manaGer

1. 什麼是dpkg(Debian PacKage manaGer)

dpkg 是 Debian 的套件管理工具,其它的Debain 衍生發行版,如Ubuntu、Koppix也
可以使用dpkg 來進行套件的管理。

2. dpkg 套件檔檔名格式

  • PackageName : 由數個簡短而具有說明性的單字的單字所組成,單字之間使用 desh(-;連字號) 隔開。
  • VersionNumber : 由major(主版號)、Minor(次版號、Patch(修正次數)所組成 ,中間使用 『dot(.)』隔開。
  • Architechure : 用來表示適用平台。
  • PackageName、VersionNumber與 Architechure之間使用『Underline (_;底線 )』隔開。 *
  • deb : 副檔名。
EX:
webmin_1.480_all.deb
joe_2.8-20_i386.deb
4digits_0.8-1_sparc.deb


3. dpkg 套件的版本


dpkg 套件可分成下列五種版本,


  1. experimental : 體驗版,由套件維護單位用來進行功能測試的版本,並非每個 套件都會提供這一種版本。
  2. unstable : 不穩定版,套件維護單位經過相當測試後所釋出的版本,不穩定版 通常不會有太嚴重的問題,但仍可能出現預期外的錯誤,較適合有經驗的使用者。
  3. testing : 測試版,套件被列為unstable一段時間若未出現重大問題(Release -Critical Bug;RC Bug)就會被列為testing,適用於 desktop 使用環境。
  4. stable : 穩定版,套件的正式釋出版,當套件通過Debian所訂定的測試標準該 套件即會被列為stable,適用於 Server 環境。
  5. oldstable : 前穩定版,當新的穩定版釋出後,此版本會被Debian繼續維護一 年。

4. dpkg 套件類別


依「Debian自由軟件指導方針 (DFSG,
http://www.debian.org/social_contract#guidelines)」, dpkg 套件可分成三類,分別是,

  1. main : 符合DFSG要求的套件。
  2. Contrib : 符合DFSG要求的套件,但其相依套件並不符合DFSG要求。
  3. Non-Free : 不符合DFSG要求的套件。
Debian 只負責維護及釋出被列為main 的套件。

5. Debian 的套件管理工具


dpkg : Debian 最底層的套件管理工具, 實際進行套件的安裝、移除等作業。

apt(Advanced Package Tool) : 一個可處理套件相依衝突的dpkg 套件前端工具程式
,只有提供命令列操作介面。
apt-get : apt 所提供的套件安裝、移除命令。

aptitude : Debian官方推薦的udpkg 套件前端工具程式,具有比apt更好的套件相依
衝突處理能力,除提供命令列操作介面外也提供了一個圖形化操作介面。
dselect : dpkg 的圖形介面套件管理程式,也是dpkg 的前端工具程式之一,提供了
一個選單操作介面。

7. dpkg


dpkg 的語法如下,
dpkg [-option] PackageName _ VersionNumber.deb 重要選項: a. 安裝 : -i ,--install #dpkg -i Package-Name_XXX_i386.deb b. 強制安裝 : --force-overwrite, --force-all, --force-condlicts #dpkg -i --force-overwrite Package-Name_XXX_i386.deb c.移除但保留組態檔 : -r,--remove #dpkg -r Package-Name d.完全移除 : -P,--purge #dpkg -P Package-Name e.顯示所有已安裝的套件 : -l,--list #dpkg -l f.查詢系統中是否已安裝特定套件 #dpkg -l Package-Name
Powered By Blogger