[Logo]
Messages posted by: andowson
Forum Index » Profile for andowson » Messages posted by andowson
Message
最近客戶的網站當機了幾次, 由於客戶的網站用戶會打電話給他們申訴, 故客戶希望在障礙發生時系統可以發出一個通知, 至少一個email, 以便大家可以早點處理. 但是當機的系統自身都難保了, 怎麼還能發出email求救信?故我們可轉而採用由別的系統來監控該目標網站(TARGET), 透過wget這個指令可以抓取遠端網頁的功能, 進行HTTP連線測試, 如果無法成功抓首頁回來, 便判斷為網站連線失敗, 然後發信通知網站負責人(OWNER),底下是這個shell script的內容:
#! /bin/sh
# Name: webmon.sh
# Author: Andowson Chang (andowson [at] gmail [dot] com)
# Version: 0.2
# Created: 2008-02-16
# Last Modified: 2008-02-17
# Description: Web connection monitor (health check)
#              If target web server failed, then notify its owner.
#              Here email is used for the simplest and cheapest way.
# Usage: webmon.sh <hostname> <owner email>
# Example:
# 1. Single owner:
# /root/admin/webmon.sh www.yourcompany.com you@yourcompany.com
# 2.Multiple onwer:
# /root/admin/webmon.sh www.yourcompany.com you@yourcompany.com,yourboss@yourcompany.com
# 3. Set a cron job to keep checking a web site every few minutes.
# */5 * * * * root /root/admin/webmon.sh www.yourcompany.com you@yourcompany.com,yourboss@yourcompany.com
TARGET=$1
OWNER=$2
WEBMONLOG=/tmp/$TARGET.log
export LANG=en_US
wget -S -t 1 -T 5 http://$TARGET/ -O /tmp/index.html -o $WEBMONLOG
RESULT=`grep "HTTP/1." $WEBMONLOG | awk '{print $2}'`
TIMEOUT=`grep "timed out" $WEBMONLOG | wc -l`
if [ $TIMEOUT == 1 ] || [ ! $RESULT == 200 ]; then
   mail -s "[ALERT]$TARGET HTTP connection fail" $OWNER < $WEBMONLOG
fi
# clean up
rm -rf /tmp/index.html
rm -rf $WEBMONLOG

這裡用到了wget的幾個參數, 主要是要取得HTTP的回應代碼, 並控制重試次數及連線的Timeout時間, 詳細說明如下
-S
--server-response
Print the headers sent by HTTP servers and responses sent by FTP servers.

-t number
--tries=number
Set number of retries to number. Specify 0 or inf for infinite retrying. The default is to retry 20 times, with the exception of fatal errors
like connection refused or not found (404), which are not retried.

-T seconds
--timeout=seconds
Set the network timeout to seconds seconds. This is equivalent to specifying --dns-timeout, --connect-timeout, and --read-timeout, all at the same time.
另外,這邊使用了export LANG=en_US來控制wget輸出訊息時的編碼為英文,以便配合cron使用.
使用時, 只需將webmon.sh放到/root/admin目錄下, 並更改權限為可執行, 然後在/etc/crontab中新增一行即可:
*/5 * * * * root /root/admin/webmon.sh www.yourcompany.com you@yourcompany.com,yourboss@yourcompany.com
忘記密碼的原因有百百種,除了自身忘記外,還有人員異動時交接不清,尤其是那種越不常用的密碼,忘得越快。例如HiNet ADSL上網的撥接密碼,通常是HiNet人員來施工時幫你輸入進去之後就存起來,以後也沒再改過。等到買了第二台電腦時,才發現找不到當初的那張密碼卡了,或是當時也改了密碼,找到密碼卡也沒用了。如果打電話給HiNet的客服人員處理,通常需要傳真身分證件影本,實在是很麻煩,只要還有原來的電腦還可以上網就可以自救一下,到NirSoftPassword Recovery Utilities裡面下載Dialupass,解壓縮並執行就可以看到舊的密碼了。
其它的密碼工具就請大家依照場合應用吧。

參考資料:
http://blog.pixnet.net/dearguo/post/9454030
最近把原本在Windows平台上的系統轉移到Linux平台來,網頁檔案也一樣複製了一份過來,可是轉移過去之後卻發現有些網頁無法正常顯示,原因就是檔案或目錄名稱大小寫不一致。
對於目錄名稱,可以用mv指令將大寫的目錄改為小寫的目錄名稱,例如:
mv ABC abc

同樣的,單一檔案,也可以使用mv的方式來處理,但是如果一個目錄裡面有很多同樣檔名開頭的檔案,例如IMG001.jpg~IMG999.jpg,總共上千個檔案,總不可能還一個一個去mv吧?
可是也不能不處理啊?再換回Windows平台去?雖然也是一招,但也是我們盡量不要採用的最後一招,常用這種方式會消磨自己的志氣,遇到問題正是促進我們學習的機會。
上網查了一下Linux rename,沒想到Linux還真的有這個指令可以用來大量取代檔案名稱的共同部分,使用起來也很簡單:
rename IMG img IMG*

第一個參數是被替換掉的字串,
第二個參數是要替換成的字串,
第三個參數是要替換的檔案清單
這樣就會把所有大寫的IMG檔名替換成小寫的img了。

參考資料:
http://linux.die.net/man/1/rename
http://linux.die.net/man/1/mv
沒想到這個問題今天在Windows Server 2003上又碰上了,為了幫客戶升級Tomcat到新的版本5.5.26,想說順便升級JDK到6.0 Update 4,通常我都是用Windows Installer安裝方式並勾選將Tomcat安裝成Service,結果安裝完成居然無法啟動,趕緊設定了JAVA_HOME及CATALINA_HOME和PATH參數都無效,乾脆改裝Tomcat 6.0.16,也是一樣起不來,火了 smilie ,全部移除重新開機又重裝也不行,檢查了一下Tomcat的logs目錄下,有一個jakarta_service_20080214.log的log檔,裡面的訊息如下:
[2008-02-14 00:26:45] [info] Procrun (2.0.3.0) started
[2008-02-14 00:26:45] [info] Running Service...
[2008-02-14 00:26:45] [info] Starting service...
[2008-02-14 00:26:45] [174 javajni.c] [error] 找不到指定的模組。
[2008-02-14 00:26:45] [986 prunsrv.c] [error] Failed creating java C:\Program Files\Java\jre1.6.0_04\bin\client\jvm.dll
[2008-02-14 00:26:45] [1260 prunsrv.c] [error] ServiceStart returned 1
[2008-02-14 00:26:45] [info] Run service finished.
[2008-02-14 00:26:45] [info] Procrun finished.

想起了在安裝過程中Tomcat詢問了J2SE 5.0 JRE的目錄是不是它找到的那個,
image
這裡特別標明5.0難道說非得用JDK 5.0才行嗎?果然換成JDK 5.0 Update 14就一切正常了。

上網用Google找了一陣子終於找到了JDK 6.0+Tomcat 5.5/6.0在Windows上無法啟動問題的解法:
將JDK或JRE的bin目錄下的msvcr71.dll複製到Windows的system32目錄下或Tomcat的bin目錄下即可。
copy %JAVA_HOME%\bin\msvcr71.dll %SystemRoot%\system32

我個人是偏好複製到system32目錄,主要的考量是對於日後升級到別的Tomcat版本較為方便。
看到參考資料的最後一篇,才發現這個問題不只是我遇到而已,真是「江湖一點訣,說破不值錢」。smilie

參考資料:
http://tw.myblog.yahoo.com/ttoduepxo/article?mid=786&next=694&l=f&fid=29
http://www.javaworld.com.tw/jute/post/view?bid=9&id=206538&sty=1&tpg=1&age=0
http://www.nabble.com/Tomcat-not-starting-to12554960.html
http://issues.apache.org/bugzilla/show_bug.cgi?id=41538
今天找到了JGS goodsolutions GmbH一篇比較OLAT和Moodle的文章,OLAT-Moodle comparison,對於想要找Open Source e-Learning Platform的人可以做個參考。
JForum 2.x以前的版本都是使用自己的MVC架構來開發,唯一有使用的framework就是freemarker這個template engine。而template就是在html頁面上加上一些輸出控制碼,這些控制碼在系統執行時可以與運算資料一起結合而轉譯成真正的html標籤,變成真正顯示出來的web page。但如果直接用瀏覽器器開啟這些檔案,因為並未透過系統執行,故本質上就是副檔名為.htm的一個文字檔而已,但瀏覽器看到.htm的副檔名,卻會以正常的網頁方式處理,結果就是那些非html標籤的輸出控制碼就變成你看到的東西了。所以直接用IE去開/templates/default/底下的這些htm檔是沒有意義的。
預先安裝函式庫:Apache Commons HttpClient 3.x, Apache Commons Codec, Apache Commons Logging
程式碼:
httpclient.jsp:
<%@ page contentType="text/html;charset=big5" %>
<%@ page import="org.apache.commons.httpclient.*" %>
<%@ page import="org.apache.commons.httpclient.methods.*" %>
<%@ page import="org.apache.commons.httpclient.params.HttpMethodParams" %>
<%@ page import="java.io.*" %>
<%    
    String url = "http://tw.stock.yahoo.com/";
    
    String stockId = request.getParameter("stock_id");
    if (stockId != null) { 
      url += "q/q?s="+stockId;
    }
    
    // Create an instance of HttpClient.
    HttpClient client = new HttpClient();

    // Create a method instance.
    HttpMethod method = new GetMethod(url);
    
    // Provide custom retry handler is necessary
    method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, 
    		new DefaultHttpMethodRetryHandler(3, false));

    try {
      // Execute the method.
      int statusCode = client.executeMethod(method);

      if (statusCode != HttpStatus.SC_OK) {
        System.err.println("Method failed: " + method.getStatusLine());
      }

      // Read the response body.
      byte[] responseBody = method.getResponseBody();

      // Deal with the response.
      // Use caution: ensure correct character encoding and is not binary data
      //System.out.println(new String(responseBody));
      
      String result = new String(responseBody, "Big5");
      if (stockId != null) {        
        result = result.substring(result.indexOf("nowrap><b>")+"nowrap><b>".length());
        result = result.substring(0, result.indexOf("</b>"));
        out.println(stockId + " Price Now: " + result);
      } else {
        out.println(result);
      }
    } catch (HttpException e) {
      System.err.println("Fatal protocol violation: " + e.getMessage());
      e.printStackTrace();
    } catch (IOException e) {
      System.err.println("Fatal transport error: " + e.getMessage());
      e.printStackTrace();
    } finally {
      // Release the connection.
      method.releaseConnection();
    } 
%>

參考資料:
http://hc.apache.org/httpclient-3.x/tutorial.html
http://www.andowson.com/examples/httpclient.jsp
http://www.andowson.com/examples/httpclient.jsp?stock_id=2412
edwin wrote:你好, 我是第一次來的, 我近期需要編寫一個web mail system, 但是 自動forward 我老是想不通logic 是怎樣, 若然定時login , 那不是對系統有一定負荷, 還是另有logic 呢?! 可唔不可以指教一下呢(又或者提議一些網站給我自學呢)?!

1.自動forward:一般是在mail server的主機上,自己的家目錄下設定一個.forward檔,可以參考底下這篇的說明
http://www.phys.sinica.edu.tw/computer_lab/forward.htm
還有,樓主的webmail近期老是connection fail or invalid account, 不論是透過您的webmail 網頁或者我download下來用本人的tomcat也是一樣, 早一陣子還是行的, 是不是本人電腦或者isp的問題呢? thx

2.本站的webmail我用來登入HiNet信箱是正常的,不知道您是用來登入哪裡?
1. PING不到Gateway(default router)
檢查並修改/etc/defaultrouter
如果有修改,需重新啟動
sync; sync; sync; init 6


2.PING不到同一個LAN上的某部主機
檢查是否有設定static route
$ netstat -rn

Routing Table: IPv4
  Destination           Gateway           Flags  Ref   Use   Interface
-------------------- -------------------- ----- ----- ------ ---------
172.16.244.0         172.16.244.240       U         1     35  ce0
224.0.0.0            172.16.244.240       U         1      0  ce0
default              172.16.244.254       UG        1    268
127.0.0.1            127.0.0.1            UH        3    287  lo0

如果有UGH的Flags,可透過route delete destination gateway的方式來刪除

3.PING不到其他不同LAN上的主機
可能原因很多,如果兩邊都各自PING得到Gateway,先檢查防火牆設定看看
如果防火牆設定有允許PING,則可用traceroute指令追蹤看看
如果是由防火牆後的內部網段主機PING外面Internet主機,因需配發一個Public IP給該主機出去的封包,故要順便檢查防火牆有沒有設定為NAT mode,如果是routing mode則需對每部要連出去的主機設定一個mapping IP。
今天花了一整天終於把現有的OLAT由5.2.2升級至5.2.3, 步驟如下:
cd ~/download
mv olat3 olat-5.2.2
wget http://www.olat.org/downloads/stable/OLAT-5.2.3.zip
unzip OLAT-5.2.3.zip
mv OLAT-5.2.3-PUBLIC-* olat3
cd olat3
sed -e "s/\/usr\/local\/opt\/olat\/olat3/\/home\/andowson\/download\/olat3/g" \
-e "s/\/usr\/local\/opt\/olat\/olatdata/\/home\/andowson\/www\/olatdata/g" \
-e "1,$$s/myolat/andowson/g" \
-e "s/smtp.host=smtp.andowson.com/smtp.host=mail.andowson.com/" \
-e "s/\/usr\/local\/opt\/tomcat/\/var\/tomcat5/g" \
-e "1,$$s/net.sf.hibernate/org.hibernate/g" \
-e "48c\server.modjk.enabled=true" \
-e "86,108d" \
-e "1,$$s/#db/db/g" \
-e "s/instantMessaging.enable=false/instantMessaging.enable=true/" \
-e "s/instantMessaging.server.name=jabber.andowson.com/instantMessaging.server.name=www.andowson.com/" \
-e "s/instantMessaging.generateTestUsers=false/instantMessaging.generateTestUsers=true/" \
-e "s/instantMessaging.db.name=wildfire/instantMessaging.db.name=openfire/" \
-e "s/instantMessaging.db.user=wildfire/instantMessaging.db.user=olat/" \
-e "s/instantMessaging.db.pass=wildfire/instantMessaging.db.pass=olat/" build.properties.default > build.properties
ant install
ant jsmath
sudo /etc/init.d/tomcat stop
mv ~/www/olat /tmp/olat-5.2.2
cp -rf ~/download/olat3/webapp ~/www/olat
cp -rf ~/download/olat3/htdocs/* ~/www/olat
sed -i -e "13c\        <\!-- default session timeout -->" ~/www/olat/WEB-INF/web.xml
rm -rf ~/www/olat/WEB-INF/src
rm -rf ~/www/olat/WEB-INF/patchesSrc
chgrp -R tomcat ~/www/olat
chgrp -R tomcat ~/www/olatdata
chmod 775 ~/www/olat/static
sudo /etc/init.d/tomcat start
http://www.webappers.com/
作者因自身需要花了很多的時間針對網頁程式開發上常需要用到的元件、功能、素材等尋找Open Source的Solution並分門別類的整理起來,每個都是高品質的資源,並且保證每天都會更新,下次遇到些網頁元件的需求可以先過去找找看,應該可以節省一些搜尋跟測試的時間。

資料來源:
joaoko's blog: 網路應用開發人員不可錯過的好站
CSS Tab Designer is a freeware that let you visually make css-based list / tabs.
Various styles and colors are included (currently, there are 60+ different styles and colors included).

You may see that JForum uses the tabs10 style for Poll and Attachments Options on adding a new post.

Download from:
http://www.highdots.com/css-tab-designer/
廠商幫忙安裝好的Solaris 9,預設只能使用/etc/hosts內的設定去找到主機名稱對應的IP,如果要一一設定一些常用的網站的IP,將是個大工程跟苦差事,最簡單的方法還是使用DNS來解析主機名稱,方法很簡單,先自己產生/etc/resolv.conf,再將/etc/nsswitch.conf改為使用dns來解析hosts。
cd /etc
vi resolv.conf
nameserver 168.95.1.1
nameserver 168.95.192.1

cp nsswitch.dns nsswitch.conf
注意:順序很重要!我就遇到先執行cp nsswitch.dns nsswitch.conf再vi resolv.conf而無法正常運作的狀況。
如果遇到上述的問題,可以執行下列的動作還原回來:
rm -rf /etc/resolv.conf
cp /etc/nsswitch.files /etc/nsswitch.conf
JSPWiki是一個開放原始碼的wiki engine,目前採用LGPL授權,未來將會轉移到Apache去,使用Java語言(JSP+Servlet)開發,wiki的精神就是每個人都可以編輯,所以滿適合用於公司內團隊的協同作業上,例如產生軟體開發專案相關的說明文件或是系統安裝、設定、操作的說明文件等,讓小組成員隨時參考。

安裝起來也滿方便的,首先我們先下載目前stable的2.6.3版,並將其解壓縮後,放到Tomcat的webapps目錄下,在我的環境上是symbolic link到使用者家目錄下的www目錄。
cd ~/download
wget http://www.ecyrd.com/~jalkanen/JSPWiki/2.6.3/JSPWiki-2.6.3-bin.zip
rm -rf JSPWiki
unzip JSPWiki-2.6.3-bin.zip
cd JSPWiki
mkdir ~/www/wiki
unzip JSPWiki.war -d ~/www/wiki/
mkdir ~/www/data/wikidata
unzip JSPWiki-corepages.zip -d ~/www/data/wikidata
sed -i -e "s/\/p\/web\/www-data\/jspwiki/\/home\/andowson\/www\/data\/wikidata/g" \
-e "s/\/tmp\/jspwiki.log/logs\/jspwiki.log/g" ~/www/wiki/WEB-INF/jspwiki.properties
sudo chmod 664 ~/www/wiki/WEB-INF/jspwiki.properties
sudo chgrp tomcat ~/www/wiki/WEB-INF/jspwiki.properties
sudo chmod 775 ~/www/data/wikidata
sudo chmod 664 ~/www/data/wikidata/*.txt
sudo chgrp -R tomcat ~/www/data/wikidata


接著修改/etc/httpd/conf.d/mod_jk.conf:
JkMount /wiki/* loadbalancer

重新啟動Apache和Tomcat,載入JSPWiki,
利用http://<myhost>/wiki/Install.jsp設定並產生admin的帳號及密碼(亂數產生),請登入後先修改密碼。
再來就可以參考網站上的文件進行編輯了。

參考資料:
JSPWiki繁體中文文件
關於JSPWiki兩三事
每個 team 都該裝個 Wiki
HP ProLiant DL360 G4用的是Smart Array 6i,原來的RHEL 3.0會出現找不到硬碟機的錯誤訊息,依據Red Hat Knowledgebase說明,必須要使用Update 2以後的版本才行。

參考資料:
When I try to install Red Hat Enterprise Linux version 3 on my HP Proliant DL360 I get an error message saying: "No drives found". What can I do?
RedHat ES 3.0 won’t install on HP DL360 with sm6i
Problem of Install RedHat Enterprise AS3.0 on HP DL360 G4
 
Forum Index » Profile for andowson » Messages posted by andowson
Go to:   

交換連結乌托邦博客 
在本站刊登廣告
練功房推薦書單
SCJP 6.0認證教戰手冊 (附光碟) 雲端策略:雲端運算與虛擬化技術 SCJP Java 6專業認證手冊 Java認證SCJP 6.0/5.0--猛虎出閘 SCWCD 5 猛虎出閘:Java Web 應用程式專業認證 SCWCD專業認證手冊 Head First Servlets and JSP
[版權說明] 本站授權方式:創用CC 姓名標示-非商業性-相同方式分享 3.0 台灣 授權條款
Creative Commons License
Powered by JForum 2.2.0 © JForum Team