2012年6月7日 星期四

Ubuntu 12.04下安裝SendmailAnalyzer

先至SendmailAnalyzer官網下載SendmailAnalyzer,並將檔案放至要安裝的Linux主機上。
SendmailAnalyzer官方有寫明安裝的系統需求,轉載如下:

Requirement

SendmailAnalyzer can work in any platform where Sendmail and Perl could run. What you need is a modern Perl distribution 5.8.x or more is good but older version should also work.
You need the following Perl modules. If they are not yet include in your OS distribution you can always find them at http://search.cpan.org/
        MIME::Base64;
        MIME::QuotedPrint;
        GD
        GD::Graph
        GD::TextUtil
        GD::Graph::bars3d;
Or if you have Internet access from your server, you can execute the following command to install GD::Graph::bars3d and all its dependencies.
 perl -MCPAN -e 'install GD::Graph::bars3d'
The graph output are generated using the libgd and libpng. You can get them at the following places:
 http://www.libgd.org/
 http://www.libpng.org/
安裝:
先至下載的SendmailAnalyzer檔案位置下,執行
tar xzf sendmailanalyzer-x.x.tar.gz
接著進入解壓縮的資料夾內
cd sendmailanalyzer-x.x/
以管理員身分執行以下指令
perl Makefile.PL
make && make install
預設會將SendmailAnalyzer安裝在/usr/local/sendmailanalyzer,接著修改
/usr/local/sendmailanalyzer/sendmailanalyzer.conf內容,將LOG_FILE修改如下
LOG_FILE        /var/log/mail.log
存檔後離開! 
接著到apache下新增一個
SendmailAnalyzer site讓SendmailAnalyzer使用。
cd /etc/apache2/sites-available/
vim sendmailanalyzer
接著輸入如下內容
Alias /SendmailAnalyzer /usr/local/sendmailanalyzer/www
<Directory /usr/local/sendmailanalyzer/www>
  Options ExecCGI
  AddHandler cgi-script .cgi
  DirectoryIndex sa_report.cgi
  Order deny,allow
  Deny from all
  Allow from 127.0.0.1
  Allow from 192.168.1.0/24
</Directory>
上方設定只允許server本機及192.168.1.0/24登入SendmailAnalyzer
接著啟用SendmailAnalyzer site並重新載入apache
a2ensite sendmailanalyzer
service apache2 reload

接著設定SendmailAnalyzer成為服務,並使其在系統開機時自動啟動
在/etc/init.d下做/usr/local/sendmailanalyzer下sendmailanalyzer的聯結
ln /usr/local/sendmailanalyzer 
執行update-rc.d 讓sendmailanalyzer成為服務
update-rc.d sendmailanalyzer defaults

設定crontab讓sendermailanalyzer每5分鐘讀取一次mail.log
crontab -e
*/5 * * * * /usr/local/sendmailanalyzer/sa_cache -a > /dev/null 2>&1

至此,sendermailanalyzer安裝完成,若進入sendermailanalyzer畫面卻看不到圖表,應該是有缺少某些Perl modules,試試以下指令:
apt-get update
apt-get install php5 php5-gd libtemplate-plugin-gd-perl



2012年6月5日 星期二

讓ubuntu開機後自動執行指定的script

ubuntu 中若要開機/關機執行某些script,須將script加入/etc/init.d目錄中,再依執行的runlevel將/etc/rcX.d對應/etc/init.d目錄中的script作softlink,雖然只是幾個步驟但有點小複雜>"<以上這些動作可以藉由update-rc.d命令輕鬆完成。
1.先將欲直行的script放置在/etc/init.d目錄下
2.執行
sudo update-rc.d default 99 1
default:不指定要設定第幾runlevel,則rc0.d~rc6.d都會加入softlink
99:表示開機執行的順序,越小越早執行
1:表示關機執行的順序,越小越早執行
開機與關機執行順序數值介於00~99之間,通常會讓兩數值相加為100,如此開機過程中越早開啟的程序在關機時將越晚關閉。
update-rc.d用法參閱man update-rc.d