2012/02/27

SSH tunnel + socks proxy 穿透防火牆

情境
1. 無論是想從家裡連回公司的serve去做事


2. 或是想從公司逃離MIS的掌控 (有些公司會禁止使用MSN或是禁止上facebook)

SSH tunnel + socks proxy都可以幫你解決

2012/02/26

Nginx 基本設定教學

下載與安裝:http://wiki.nginx.org/Install
若 make 的時候出現下面錯誤
make -f objs/Makefile
make[1]: Entering directory `/home/user/src/server/nginx-1.0.14'
cd /usr/lib \
        && if [ -f Makefile ]; then make distclean; fi \
        && CC="gcc" CFLAGS="-O2 -fomit-frame-pointer -pipe " \
        ./configure --disable-shared
/bin/sh: line 2: ./configure: No such file or directory
make[1]: *** [/usr/lib/Makefile] Error 127
make[1]: Leaving directory `/home/user/src/server/nginx-1.0.14'
make: *** [build] Error 2
解決方式:
在 configure 時 --with-pcre 指向 pcre 的 source tree
$ ./configure --with-pcre=~/pcre-8.30
$ make 


基本指令

# 啟動
/usr/local/nginx/sbin/nginx

# 停止
/usr/local/nginx/sbin/nginx -s stop

# Reload
/usr/local/nginx/sbin/nginx -s reload

# 編輯設定檔
vim /usr/local/nginx/conf/nginx.conf

# 檢查設定檔
/usr/local/nginx/sbin/nginx -t


下面列出幾種常用的模式:

2012/02/20

Hosting the js and css resource file

使用google blog時,額外載入的javascript、css檔該放在哪裡?
<link href='http://host/test.css' rel='stylesheet' type='text/css'/>
<script src='http://host/test.js' type='text/javascript'/>

下面提供幾種方法讓各位參考:


Google sites (協作平台)
1. 建立一個協作平台
2. 新增頁面,類型選擇『檔案櫃』
3. 設定共用權限為『公開在網路上,所有人皆可尋找和檢視』
4. 複製下載連結 Ex:
https://sites.google.com/site/blog-resource/file-cabinet/test.js?attredirects=0&d=1
去掉http(s),以及?後面的字眼,最後變成:
http://sites.google.com/site/blog-resource/file-cabinet/test.js

*限制:只限blogspot.com結尾的網域去load,像我在blog額外加自己的網址 01-labro.com 則會下載不到,如果是其他網域就更不用說了


Google project hosting
1. 進入後選擇『Create a new project』
2. 填完基本資料後就可以開始上載檔案

3. 最後複製檔案連結,大概是長這樣
http://blog-resource.googlecode.com/files/test.js

*限制:不限網域,但我的css一直載不進來,js則ok。


Dropbox
這是最簡單的方式,把檔案放到dropbox的public folder,然後copy link就可以拿到URL了。



不論速度還是穩定度,應該都是google的最佳!


2012/02/18

申請新網域 www.01-labor.com

一時衝動就申請了新的網域 www.01-labor.com,一年US$10。



誰叫google的服務和GoDaddy.com整合這麼好,從後台設定進去填兩個表格就申請好了,而且馬上可以使用,順便也幫你啓用Google Apps,看來要好好來經營一下部落格了 :)


但突然發現,原本hosting在google協作平台的javascript檔都load不進來了
Ex: http://sites.google.com/site/hosting/file/extension.css
原本點了連結應該是直接連接到那個檔案,但現在卻變成


推測應該是google會檢查http referer,應該用google app新申請一個自已網域的協作平台,再把檔案轉移過去就可以了。
見下一篇:Hosting the js and css resource file

使用jquery跨網域存取json資料

jQuery的$.getJSON()能夠跨網域存取資料,是base在browser可以load不同網域的js檔的方式去包裝的。
<script src="http://www.example.com/test.js"></script>

範例

Client端
$.getJSON("http://www.example.com/getMessage.php?jsoncallback=?",
    function(data) {
        alert(data.message);
    });
Request發出時,jsoncallback後面的?會被取代成特定string,server回應的訊息必需包含此string才會被接受。而回傳的data會被轉成object。


Server端
$data = '{"message" : "hello world"}';
echo $_GET['jsoncallback'] . '(' . $data . ')';


參考資料

2011/10/26

AWS Toolkit for Eclipse

AWS Toolkit for Eclipse

安裝時出現下面錯誤訊息:
Cannot complete the install because one or more required items could not be found.
Software currently installed: Amazon SimpleDB Management 1.0.0.v201110211341 (com.amazonaws.eclipse.datatools.enablement.simpledb.feature.feature.group 1.0.0.v201110211341)
Missing requirement: Eclipse Data Tools Platform Amazon SimpleDB UI Plug-in 1.0.0.v201110211341 (com.amazonaws.eclipse.datatools.enablement.simpledb.ui 1.0.0.v201110211341) requires 'bundle org.eclipse.datatools.sqltools.sqlscrapbook 1.0.0' but it could not be found
Cannot satisfy dependency:
From: Amazon SimpleDB Management 1.0.0.v201110211341 (com.amazonaws.eclipse.datatools.enablement.simpledb.feature.feature.group 1.0.0.v201110211341)
To: com.amazonaws.eclipse.datatools.enablement.simpledb.ui [1.0.0.v201110211341]

錯誤訊息是說缺少了 Eclipse Data Tools Platform Amazon SimpleDB UI Plug-in,但我從Eclipse Data Tools Platform (DTP)下載最新的套件還是不足。

最後直接去下載Eclipse IDE for Java EE Developers,這個版本的eclipse內建的plug-in比較完整。
再次安裝aws toolkit就可以成功了!


參考資料:
AWS Developer Forums: Eclipse AWS Toolkit install error. ...
having hard time install AWS toolkit for java and eclipse - HPCS

2011/10/04

Postgresql + pgpool-II

抓一張官方的示意圖:

特色
  • Connection Pooling: 減少建立connection的overhead
  • Load Balance: 依照負載去dispatch
  • Replication: 所有的修改都會replication到底下所有database
  • Parallel Query
不外乎就是要來增加throughput啦。

設定
可以參考官方網站,在這邊以下列的架構為例




pgpool 192.168.0.2
DB1 192.168.0.3
DB2 192.168.0.4