2010年3月26日 星期五

在 MySQL 開個資料庫給 phpBB3

前言
安裝 phpBB3 之前,總得先吧資料庫MySQl 及 PHP 準備好~
至於 phpBB3 的安裝請看 竹貓星球 http://phpbb-tw.net/


環境
OS: CentOS Linux 5.4
Apache: 2.2.3
MySQL: 5.0.77
PHP: 5.1.6 (使用 PHP 擴充附件: mysqli)


啟動 Apache 及 MySQL 並設定 MySQL 的 root 密碼
# chkconfig httpd on
# service httpd start
# chkconfig mysqld on
# service mysqld start
# mysqladmin -u root password <MySQL root 密碼>


安裝 phpMyAdmin
原本下載的是 phpMyAdmin 3 ,但是安裝好才發現它需要 PHP 5.2 以後的版本,所以就要改用 phpMyAdmin 2 。
# wget http://downloads.sourceforge.net/project/phpmyadmin/phpMyAdmin/2.11.10/phpMyAdmin-2.11.10-all-languages.tar.bz2?use_mirror=ncu
# tar xjf phpMyAdmin-2.11.10-all-languages.tar.bz2
# mv phpMyAdmin-2.11.10-all-languages/  /var/www

建立 Apache 虛擬目錄 /phpmyadmin ,並限制只有本機能使用。
# vi /etc/httpd/conf.d/phpmyadmin.conf
Alias /phpmyadmin /var/www/phpMyAdmin-2.11.10-all-languages
<Location /phpmyadmin> 
    Order deny,allow
    Deny from all
    Allow from 127.0.0.1
    Allow from ::1
    # Allow from .your-domain-name.com
</Location>  

重新啟動 Apache
# service httpd restart

設定 phpMyAdmin 驗證方式
# cp -p config.sample.inc.php config.inc.php
# vi config.inc.php
# 給 $cfg['blowfish_secret'] 一組亂數(最長 46 個字元)
$cfg['blowfish_secret'] = '1234567890abcdefghijklmnopqrstuvwxyz';
$cfg['Servers'][$i]['auth_type'] = 'cookie';
$cfg['Servers'][$i]['extension'] = 'mysqli';

開 firefox 連 http://127.0.0.1/phpmyadmin ,[Language] 選 [中文 - Chinese traditional (utf-8)] 登入。

登入名稱: root
密碼:  <MySQL root 密碼>


若出現 [無法讀取 mcrypt 模組,
請檢查 PHP 設定] 訊息,請安裝以下有關加密的套件 mhash libmcrypt php-mhash php-mcrypt 。
# yum install -y mhash libmcrypt php-mhash php-mcrypt


建立資料庫 phpbb3 及其使用者 ccuphy3-phpbb3
--> [資料庫]
建立新資料庫: phpbb3
按 [建立]






--> [權限] --> [新增使用者]
使用者名稱:[文字輸入] ccuphy3-phpbb3
主機:[本地] localhost
密碼:[文字輸入] <MySQL ccuphy3-phpbb3 密碼>
Database for user : None
整體權限:( 全部取消)
資料: (全不選)
結構: (全不選)
系統管理: (全不選)
資源限制: (全不限:0)
按 [執行]







在 [指定資料庫權限] 欄中,指定資料庫 phpbb3 給使用者 ccuphy3-phpbb3
於以下資料庫加入權限: phpbb3
指定資料庫權限:(全選)
資料: (全選)
結構: (全選)
系統管理: (全選)
按 [執行]











註1:安裝 phpBB3 [資料庫設定]  步驟的內容說明
資料庫伺服器地址,或DSN:localhost (通常架phpBB3,MySQL跟Apache在同一台主機,所以設 localhost)
資料庫伺服器連接埠:  (預設在 TCP 3306 port ,若沒有自行換 port ,可以不用設定。)
資料庫名稱: phpbb3
資料庫管理員名稱:ccuphy3-phpbb3
資料庫管理員密碼:<MySQL ccuphy3-phpbb3 密碼>
資料庫表格的字首:phpbb_ (保持預設不必更改)

註2:在註冊時若要產生 GD 驗證圖檔,就需要裝 php-gd 套件。
# yum install -y php-gd

2010年3月18日 星期四

Linux 指令備忘錄



dmidecode 查硬體資訊

    dmidecode -t [TYPE]
    Valid type keywords are:
    bios
    system
    baseboard
    chassis
    processor
    memory
    cache
    connector
    slot
例如: dmidecode -t memory 查記憶體硬體資訊



fuser 查檔案或檔案系統正由那個程序使用
Usage: fuser [ -a | -s | -c ] [ -n SPACE ] [ -SIGNAL ] [ -kimuv ] NAME...
             [ - ] [ -n SPACE ] [ -SIGNAL ] [ -kimuv ] NAME...
       fuser -l
       fuser -V
Show which processes use the named files, sockets, or filesystems.

    -a        display unused files too
    -c        mounted FS
    -f        silently ignored (for POSIX compatibility)
    -i        ask before killing (ignored without -k)
    -k        kill processes accessing the named file
    -l        list available signal names
    -m        show all processes using the named filesystems
    -n SPACE  search in this name space (file, udp, or tcp)
    -s        silent operation
    -SIGNAL   send this signal instead of SIGKILL
    -u        display user IDs
    -v        verbose output
    -V        display version information
    -4        search IPv4 sockets only
    -6        search IPv6 sockets only
    -         reset options
例1: fuser -m /mnt/usb-flash -v 查指定的檔案系統,並顯示詳細資訊。
例2: fuser -m /mnt/usb-flash -v -i -k 殺掉正在使用指定檔案系統的程序,並顯示詳細資訊。



2010年3月11日 星期四

ntop 3.3.10 on CentOS 5.4

前言
原先我裝的是 ntop-3.3.9-7.el5.i386.rpm ,但是這個版本啟動時就出現無法開啟 GeoIP 檔案的問題,後來在設定 ntop.conf 又遇到當使用 --known-subnets 參數時,ntop 就會啟動失敗。沒有 --known-subnets 功能,其他內部網段跟 Internet 的資訊混在一起,這點我的環境實在不方便。而且不定時就 crash ,就算換其他版本還是一樣。問了 Google 大神,祂給了許多不確定的答案,哎......
在眾多答案之中唯一公認較好的方式:還是自己 make 。好吧,那就來吧!


環境
OS:CentOS 5.4
Kernel: 2.6.26.10(自行編釋)
eth1: (Internet)
eth0: 192.168.10.0/24 ,透過其它 router 會有 192.168.0.0/16 的網段


安裝 CentOS 5 已具備的 rpm 套件: zlib zlib-devel libtool libtool-ltdl automake autoconf libpcap libevent gdbm m4 openssl openssl-devel
# yum -y install zlib zlib-devel libtool libtool-ltdl automake autoconf libpcap libpcap-devel libevent gdbm gdbm-devel m4 openssl openssl-devel


安裝其他 rpm 套件: rrdtool rrdtool-devel
i386:
# wget ftp://ftp.pbone.net/mirror/download.fedora.redhat.com/pub/fedora/epel/5/i386/rrdtool-1.2.27-3.el5.i386.rpm
# wget ftp://ftp.pbone.net/mirror/download.fedora.redhat.com/pub/fedora/epel/5/i386/rrdtool-devel-1.2.27-3.el5.i386.rpm
x86_64:
# wget ftp://ftp.pbone.net/mirror/download.fedora.redhat.com/pub/fedora/epel/5/x86_64/rrdtool-1.2.27-3.el5.x86_64.rpm
# wget ftp://ftp.pbone.net/mirror/download.fedora.redhat.com/pub/fedora/epel/5/x86_64/rrdtool-devel-1.2.27-3.el5.x86_64.rpm
# rpm -Uvh rrdtool-1.2.27-3.el5.x86_64.rpm rrdtool-devel-1.2.27-3.el5.x86_64.rpm


編譯及安裝 ntop-3.3.10
# wget http://downloads.sourceforge.net/project/ntop/ntop/ntop-3.3.10/ntop-3.3.10.tar.gz?use_mirror=ncu
# tar xzf ntop-3.3.10.tar.gz
# cd ntop-3.3.10/
# ./autogen.sh
出現以下錯誤訊息:
Error! You need to have libevent 1.4.X or better.
# rpm -qa | grep libevent
libevent-1.1a-3.2.1
查一下CentOS5.4 的 libevent 的版本是 1.1a ,其他的 rpm 也只到 1.3,所以只好自行 make 。


編譯及安裝 libevent-1.4.13-stable.tar.gz
# wget http://www.monkey.org/~provos/libevent-1.4.13-stable.tar.gz
# tar xzf libevent-1.4.13-stable.tar.gz
# cd libevent-1.4.13-stable/
# ./configure
# make
# make install
libevent 會裝至下列目錄:
/usr/local/lib
/usr/local/include
/usr/local/share/man/man3


裝好 libevent-1.4.13-stable,再做一次!
# ./autogen.sh
如果 TCP 80 port 網路不通時,就要自行下載以下四個檔案,放在 ntop-3.3.10/
http://www.lua.org/ftp/lua-5.1.4.tar.gz
http://www.maxmind.com/download/geoip/api/c/GeoIP.tar.gz
http://www.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
http://www.maxmind.com/download/geoip/database/asnum/GeoIPASNum.dat.gz


# ./autogen.sh
出現以下錯誤訊息:
configure: error: cannot find macro directory `m4'
建立 m4 目錄後,再做一次!
# mkdir m4
# ./autogen.sh

終於看到令人感動的訊息:
.... autogen.sh done
just type make to compile ntop



# make
# make install


建立帳號 ntop(uid:105) 及群組 ntop(gid:105) ,uid gid 自行決定
# echo 'ntop:x:105:105:ntop:/usr/local/var/ntop:/sbin/nologin' >> /etc/passwd
# echo 'ntop:x:105:' >> /etc/group


建立及設定 /usr/local/etc/ntop.conf
# vi /usr/local/etc/ntop.conf


--user ntop
--db-file-path /usr/local/var/ntop
--interface eth0
-4
-x 16384
-X 65536
--trace-level 3
--http-server 3000
--disable-schedyield
--skip-version-check=yes
--local-subnets 192.168.0.0/16
--known-subnets 192.168.0.0/16

註:ntop 會自動設定 eth0 上的網段,以我的環境為例:我的 eth0 是 192.168.10.0/24 ,在 ntop.conf 就不用特別定義 192.168.10.0/24 ,但因為我的 eth0 透過其它 router 會有 192.168.0.0/16 上的 host ,為了分類上的方便才使用 --local-subnets 及 --known-subnets 來定義 192.168.0.0/16 。


目錄建立與權限設定
# mkdir /usr/local/var/ntop/rrd
# chmod 700 /usr/local/var/ntop/rrd
# chown -R ntop:ntop /usr/local/share/ntop /usr/local/etc/ntop /usr/local/var/ntop/rrd


建立 admin 密碼
# ntop @/usr/local/etc/ntop.conf --set-admin-password=<密碼>


建立 ntop 為 Daemon Service
# vi /etc/rc.d/init.d/ntop


#!/bin/bash

# Source function library.
. /etc/rc.d/init.d/functions

# Path to the ntop program
prog=ntop
ntop=/usr/local/bin/$prog
pidfile=/var/run/$prog.pid
config=/usr/local/etc/$prog.conf

start() {
echo -n $"Starting $prog: "

[ -x $ntop ] || exit 1
[ -r "$config" ] || exit 6
if [ ! -r "/usr/local/var/$prog/${prog}_pw.db" ]; then
echo "service not configured, run $prog manually"
exit 6
fi

# ntop has string errors in locales other than "C"
LANG=C daemon "$ntop @$config --daemon > /dev/null"
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc -p $pidfile $ntop
RETVAL="$?"
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog $pidfile
}
reload() {
echo -n $"Reloading $prog: "
killproc $ntop -HUP
RETVAL=$?
echo
}

case "$1" in
start)
start
;;
stop)
stop
;;
status)
status $ntop
RETVAL=$?
;;
restart)
stop
start
RETVAL=$?
;;
condrestart)
if [ -f $pidfile ] ; then
stop
start
fi
RETVAL=$?
;;
reload)
reload
;;
*)
echo $"Usage: $prog {start|stop|restart|condrestart|reload|status}"
RETVAL=3
esac

exit $RETVAL


註:此 script 取自 ntop-3.3.9-7.el5.i386.rpm ,我修改路徑而已。

# chmod 755 /etc/rc.d/init.d/ntop
# chown root:root /etc/rc.d/init.d/ntop
# chkconfig --add ntop
# chkconfig ntop on
# service ntop start


ntop 會安裝至下列目錄:
/usr/local/bin
/usr/local/etc
/usr/local/include
/usr/local/lib
/usr/local/man/man8
/usr/local/share/ntop
/usr/local/var/ntop



參考資料:
http://forum.icst.org.tw/phpbb/viewtopic.php?f=24&t=14843