Ads 468x60px

Pages

2011年12月16日 星期五

node.js & npm 安裝注意事項 (用 forever 執行 node.js)


node.js 及 npm 的安裝都需要編譯的環境,也跟使用者的環境變數有很大的關係;以下分別逐一說明編譯、安裝、執行的注意事項,主要分成二大步驟

1. 在 server1 上編譯及安裝
2. Deploy 到 server2 上,安裝及執行

準備編譯環境
Before install nodeJS, please ensure your environment prepared these tools, below:
python - version 2.6 or higher.
GCC - c++ complier
Git

python update
yum install python26;
mv /usr/local/bin/python /usr/local/bin/python.bak;
ln -s /usr/bin/python2.6 /usr/local/bin/python;
編譯 node.js (v0.4.12 為例),並安裝到 ~/node.out
kevin@server1 {~}$ git clone --depth 1 git://github.com/joyent/node.git node
kevin@server1 {~}$ mkdir node.js
kevin@server1 {~}$ cd node
kevin@server1 {~/node}$ git checkout v0.4.12
kevin@server1 {~/node}$ ./configure --prefix=~/node.out
kevin@server1 {~/node}$ make -j2 # -j sets the number of jobs to run
kevin@server1 {~/node}$ make install
執行完成後,在你的 ~/node.out 會有以下目錄
kevin@server1 { ~/node.out  }$ ls
bin  include  lib  share
nodeJS installation is finished, we can input some test code for making sure nodeJS is ready.
kevin@server1 { ~/node.out/bin  }$ ./node --version
#result : v 0.4.12
編譯及安裝 NPM 到 ~/npm.out
Before install npm, please ensure your environment variable(path) is ready.
kevin@server1 { ~ }$ export PATH=$PATH:/usr/local/bin
kevin@server1 { ~ }$ env | grep PATH
PATH=/bin:/usr/bin:/usr/local/bin
Now npm package wrote a shell script for quick install, we download this and
kevin@server1 { ~ }$ mkdir npm.out
kevin@server1 { ~ }$ export npm_config_prefix=~/npm.out
kevin@server1 { ~ }$ curl http://npmjs.org/install.sh | sh
注意:如果沒有 "export npm_config_prefix=~/npm.out", 預設會安裝到 /usr/local 下,這樣會有檔案權限的問題,所以我們需要設定這個環境變數

After shell script executed, run npm test
kevin@server1 { ~ }$ cd npm.out/bin
kevin@server1 { ~/npm.out/bin }$ ./npm --version
#result: 1.0.105
安裝 npm modules,這個步驟跟你所在的目錄有很大的關係,預設會裝在目前目錄下的 npm_modules ,這不是我們要的,所以請照以下步驟
kevin@server1 { ~ }$ cd npm.out/lib
kevin@server1 { ~/npm.out/lib }$ npm install forever -d # 目前預設會裝 0.7.5,會遇到問題
...
npm info addNamed [ 'timespan', '2.0.x' ]
npm info addNamed [ 'watch', '0.4.x' ]
npm info addNamed [ 'utile', '0.0.x' ]
npm info addNamed [ 'winston', '0.5.x' ]
npm ERR! error installing forever@0.7.5 Error: ETIMEDOUT, Connection timed out
npm ERR! error installing forever@0.7.5     at Socket._onConnect (net.js:576:18)
npm ERR! error installing forever@0.7.5     at IOWatcher.onWritable [as callback] (net.js:165:12)
npm info unbuild /home/kevin_luo/npm/lib/node_modules/forever
npm info preuninstall forever@0.7.5
npm info uninstall forever@0.7.5
npm info postuninstall forever@0.7.5
npm ERR! Error: ETIMEDOUT, Connection timed out
npm ERR!     at Socket._onConnect (net.js:576:18)
npm ERR!     at IOWatcher.onWritable [as callback] (net.js:165:12)
...
我的解決的方法是先裝 0.6.5 ,再裝 0.7.5
kevin@server1 { ~/npm.out/lib }$ npm install forever@0.6.5 -d
kevin@server1 { ~/npm.out/lib }$ npm install forever -d # (0.7.5)
這樣裝完之後, forever  的 bin 檔沒有正確的建立,請執行以下步驟
kevin@server1 { ~/npm.out/lib }$ cd ../bin
kevin@server1 { ~/npm.out/bin }$ ln -sf ../lib/npm_modules/forever/bin/forever ./
kevin@server1 { ~/npm.out/bin }$ ln -sf ../lib/npm_modules/forever/bin/foreverd ./
安裝 socket.io,需要升級你的 tar 版本(這是什麼怪規定呢!!)
kevin@server1 {~}$ rpm -e --no-deps tar
kevin@server1 {~}$ wget ftp://ftp.gnu.org/gnu/tar/tar-1.26.tar.gz
kevin@server1 {~}$ tar zxvf tar-1.26.tar.gz
kevin@server1 {~}$ cd tar-1.26
kevin@server1 {~/tar-1.26}$ export FORCE_UNSAFE_CONFIGURE=1
kevin@server1 {~/tar-1.26}$ ./configure
kevin@server1 {~/tar-1.26}$ make
kevin@server1 {~/tar-1.26}$ make install
kevin@server1 {~/}$ cd npm.out/lib
kevin@server1 {~/npm.out/lib}$ npm install  socket.io@0.8.5 -d

└─┬ socket.io@0.8.5
  ├── policyfile@0.0.4
  ├── redis@0.6.6
  └─┬ socket.io-client@0.8.5
    ├── uglify-js@1.0.6
    ├── websocket-client@1.0.0
    └── xmlhttprequest@1.2.2
安裝 npm mysql, daemon modules
kevin@server1 {~/npm.out/lib}$ npm install mysql
kevin@server1 {~/npm.out/lib}$ npm install daemon
以上動作皆發生在 server1 上,接下到要 deploy server2 上,並執行
kevin@server1 {~} $ tar cvfz node.out.tgz node.out
kevin@server1 {~} $ tar cvfx npm.out.tgz npm.out
kevin@server1 {~} $ scp node.out.tgz server2:
kevin@server1 {~} $ scp npm.out.tgz server2:
接著來到 server2,並將 node 及 npm 安裝到 /usr/local
kevin@server2 {~} $ tar xvfz node.out.tgz
kevin@server1 {~} $ tar xvfz npm.out.tgz
kevin@server1 {~} $ cd node.out
kevin@server1 {~/node.out } $ sudo cp -r * /usr/local
kevin@server1 {~/node.out } $ cd ~npm.out
kevin@server1 {~/npm.out } $ sudo cp -r * /usr/local
這樣整個安裝算是完成了,接著執行 node.js (假設 node.js 放在 /var/www/node/node.js),我們會使用 apache 這個 user 來執行 node.js 以確保安全。
kevin@server1 {~} $ sudo -u apache -H PATH=/usr/local/bin NODE_PATH=/usr/local/bin/node:/usr/local/lib/node_modules forever start /var/www/node/node.js

info:   Forever processes running
data:       uid  command script                                      forever pid   logfile                    uptime       
data:   [0] 1YH_ node    /home/m/share/htdocs/miiicasa/comet/node.js 21088   26038 /var/www/.forever/1YH_.log 0:0:38:6.956 
kevin@server1 {~} $ sudo -u apache -H PATH=/usr/local/bin NODE_PATH=/usr/local/bin/node:/usr/local/lib/node_modules forever list

info:   Forever processes running
data:       uid  command script                                      forever pid   logfile                    uptime       
data:   [0] 1YH_ node    /home/m/share/htdocs/miiicasa/comet/node.js 21088   26038 /var/www/.forever/1YH_.log 0:0:38:6.956 
這邊最主要的問題,就是 forever 執行者(apache)的環境問題,通常我們用自己的 id (kevin) 在執行時,都會預先設定 PATH, NODE_PATH 的環境變數在我們的 .profile or .bashrc 上,不過用 sudo 執行時,這些變數,有時候沒有設定,有時候是錯的,所以我們在 sudo 的參數上做一些設定,說明如下:
  • -H : 使用 sudo 後 user 的 home directory, eg: apache 的使用者 HOME=/var/www, 而 forever 執行時,會根據 HOME 的值,在底下建立 $HOME/.forever 的目錄,來存放執行時期的設定
  • PATH=/usr/local/bin : 指定執行檔的搜尋路徑,主要是 forever, 及 env
  • NODE_PATH=/usr/local/bin/node:/usr/local/lib/node_modules : 指定 forever 要到那裡找 npm 的 modules ,由於我們只把 npm_modules 安裝到 /usr/local/lib 下,所以需要這個設定
這樣就大功告成了。

按"X"......搞了很多次,才終於瞭解

2011年10月29日 星期六

Macbook Pro 換裝 SSD 及 光碟機換硬碟

SSD 的容量可以用寸土寸金來形容,依目前的狀況和傳統硬碟來比,每 GB 的售價真的是相當昂貴;再加上一般民用市場主流的 MLC SSD 有著讓人不去注意也難的複寫次數限制,所以在幫你的 Mac 換裝 SSD 之後,最需要注意的原則就是:「盡可能地減少 SSD 的使用容量」、「盡可能縮減系統對 SSD 的寫入行為」。

所以,我換裝 SSD 之後對電腦做了下面幾項更動:

1. 將幾乎一年用不到一次的光碟機換裝成第二顆硬碟
2. 以noatime的方式掛載硬碟以減少不必要的寫入行為
3. 關閉安全休眠並刪除休眠映像檔以減少使用容量
4. 將個人資料夾中較常寫入與佔用容量較大的掛載到第二顆硬碟

設定noatime掛載

*nix的作業系統會對每一個檔案紀錄最後一次開啟( access )的時間,而這樣的功能其實不是說非常的必要。例如 Finder 內的搜尋目標有今天使用過的檔案、昨天使用過的檔案、或過去一週使用過的檔案等等,就是利用這個檔案屬性,而當我們使用 noatime 選項來掛載硬碟之後,就不會只開啟檔案就去更動其 access time 屬性了。

依個人需求斟酌,如果像我一樣覺得這並不是很重要的話,就可以選擇使用 noatime ,節省硬碟存取次數提昇些許效能,也許也可以讓硬碟的壽命延長一點點點…。詳細的作法如下:

使用文字編輯軟體建立一個檔案命名為 「com.你的名字.noatime.plist」(ex. /Library/LaunchDaemons/com.xfalcons.noatime.plist)並輸入以下內容

        "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
   
        Label
        com.你的名字.noatime
        ProgramArguments
       
            mount
            -vuwo
            noatime
            /
       
        RunAtLoad
       
   
接著開啟 Terminal 輸入 「sudo chown root:wheel /Library/LaunchDaemons/com.xfalcons.noatime.plist」 指令,之後重新啟動電腦。如果在 Terminal 輸入 「mount」 後查看,掛載在root路徑下的硬碟顯示為 /dev/disk0s2 on / (hfs, local, journaled, noatime) 之類的就是搞定啦!

關閉安全休眠

OSX 方便的休眠功能,一直是我最喜歡的功能之一,只要把螢幕蓋上,就可以馬上把電腦帶走;而打開螢幕,馬上就可以回到先前的工作狀態。而安全休眠是什麼?為了防止電源耗盡而喪失休眠時記憶體中的資料,在電源即將耗盡時, OSX 會把記憶體中的資料寫入硬碟中的 sleep image 映像檔,在電源問題解決之後把資料再放回記憶體而回覆先前的工作狀態。

這個功能如果像我有安裝 8G 的 RAM ,那麼映像檔就會佔用硬碟 8G 的空間,算是滿可觀的…以 SSD 來說。同樣的,一次就要寫入 8G 的資料,對 SSD 來說更是要命…。一般來說,電源快要耗盡時我都會先把所有工作先存檔好,除非是要作電池校正,不然也不會常常讓電池用到電腦自動關機,所以我選擇關閉這個功能來騰出硬碟空間與減少寫入的機會。詳細的作法如下:

開啟 Terminal 輸入 「sudo pmset -a hibernatemode 0」 指令關閉安全休眠模式;接著輸入 「sudo rm /var/vm/sleepimage」 指令刪除休眠映像檔,就完成了。

搬移個人資料夾
還記得以前使用 PowerBook 的時候,壓根不會想要把音樂影片等東西塞在內建的硬碟,因為容量很小。而現在硬碟其實已經相對便宜了,之前換了 500G 的硬碟之後馬上把以前丟在外接硬碟的東西全部進來,到哪裡都可以找到自己喜歡的音樂、分享影片,在外面也隨時找的到需要的素材,著實方便很多。

這個部份我移動的資料夾有:桌面、文件、下載項目、影片、音樂、圖片、網站、還有 Dropbox 等幾個資料夾,都是比較常存取、使用容量也比較龐大的, SSD 中我主要只留下應用程式和資源庫資料夾,以方便快速地開啟程式。詳細作法如下:

先將要移動的資料夾全部完整複製一份到另外一個硬碟,之後再把原本 SSD 上的資料夾刪除,然後使用 Terminal 輸入 「ln -s /Volumes/你的第二棵硬碟名稱/資料夾名稱 /user/你的使用者簡稱/資料夾名稱」 (ex. ln -s /Volumes/Macintosh\ HD/Desktop /Users/funnyq/Desktop),就會在 SSD 上建立一個和另一顆磁碟連結的替身,而將檔案都存放在第二顆硬碟上。

照這個方法做完之後,使用上會和只使用一個硬碟的時候一模一樣,一些應用程式存放資料的設定都不用再去更動他,一次搞定!設定過的相關位址會自動對應到第二個硬碟,不用再費心針對不同的應用程式一個一個修改設定。

然而,這個作法我有發現一個滿好笑的問題…。換裝 SSD 之後,重開機從蘋果 LOGO 出現到進入桌面可以開始工作,大約是15秒上下。尤其是進入桌面之後,以往常常會卡在桌面一片空白、等待一些常駐程式開啟的狀態很久很久。而現在一進到桌面,所有程式瞬間都開啟了!不過桌面常常還是一片空白…,我猜可能是因為開機太快了,而另一個硬碟還沒mount好或是還來不及反應所造成的。這個時候只要按下 Command+Option+Esc ,然後選擇 Finder 重新啟動就可以恢復正常了。

我的配置是將 SSD 主要作為 Startup Disk + Apps。這可使整體戴入時間加快好多,感覺良好。
而 Bootcamp 則安於 HD 內。

但你安 SSD,有一設定你一定要做,就是為你的 SSD 開啟 TRIM 功能。
詳細教程可在這:

http://blog.funnyq.com/2011/07/enable-trim-support-in-osx-lion/


***** Trim到底哪裡重要 ******
TRIM的目的就是在後台,允許每一個寫入刪除步驟都進行一次余塊垃%圾清除,好讓ssd時刻保持最好性能,intel提供的toolbox也是同樣道理,只是手動運行或者定期運行,不如trim開啟在後台每一個步驟運行來的方便
為何要清除余塊垃%圾,ssd在寫入部分的性能會降低,但是都知道數據直接刪除並不代表真的刪除了,只是記錄刪除,實際上數據還在,所以ssd如果刪除不需要的文件,但是此文件依然還存在,就會導致ssd的測試性能下降(實際上對於使用文件一點作用都沒有,就是測試好看而已,因為有文件的地方就已經降低性能了,提高空餘部分的性能只是心裡滿足)

[ quoted from: http://gdgt.com/question/in-os-x-lion-how-do-you-enable-trim-support-for-ssds-f16/ ]

Don't use TRIM Enabler, it's bad software! It replaces a Lion kernel extension with one from 10.6.8! You should revert the change ASAP. Using an older extension is only going to cause problems and conflicts with dependent extensions. I called the developer out about this problem and he claims that he's going to update TRIM enabler to simply patch, instead of replace, but he hasn't yet...and he deleted my comment :P

Instead, you can run the following Terminal commands:

So, here's the proper way to enable TRIM support. Copy these commands out, find/delete all "[REMOVE ME]" placeholders so the commands are contiguous, and run them in Terminal:

→ Backup the file we're patching:
sudo cp /System/Library/Extensions/IOAHCIFamily.[REMOVE ME]kext/Contents/PlugIns/IOAHCIBlockStorage[REMOVE ME].kext/Contents/MacOS/IOAHCIBlockStorage /IOAHCIBlockStorage.original

→ Patch the file to enable TRIM support:
sudo perl -pi -e 's|(\x52\x6F\x74\x61\x74\x69\x6F\x6E\x61[REMOVE ME]\x6C\x00).{9}(\x00\x51)|$1\x00\x00\x00\[REMOVE ME]x00\x00\x00\x00\x00\x00$2|sg' /System/Library/Extensions/IOAHCIFamily.[REMOVE ME]kext/Contents/PlugIns/IOAHCIBlockStorage[REMOVE ME].kext/Contents/MacOS/IOAHCIBlockStorage

→ Clear the kext caches
sudo kextcache -system-prelinked-kernel
sudo kextcache -system-caches

→ Now, Reboot!

→ If in the future you want to disable TRIM support:
sudo perl -pi -e 's|(\x52\x6F\x74\x61\x74\x69\x6F\x6E\x61[REMOVE ME]\x6C\x00).{9}(\x00\x51)|$1\x41\x50\x50\[REMOVE ME]x4C\x45\x20\x53\x53\x44$2|sg' /System/Library/Extensions/IOAHCIFamily.[REMOVE ME]kext/Contents/PlugIns/IOAHCIBlockStorage[REMOVE ME].kext/Contents/MacOS/IOAHCIBlockStorage

→ Or if something goes horribly wrong, restore the backup:
sudo cp /IOAHCIBlockStorage.original /System/Library/Extensions/IOAHCIFamily.[REMOVE ME]kext/Contents/PlugIns/IOAHCIBlockStorage[REMOVE ME].kext/Contents/MacOS/IOAHCIBlockStorage

All the patch does is edit the IOAHCIBlockStoage file, patching out the string "APPLE SSD" to zeros. This happens to enable TRIM support for all SSDs.

Please visit my post about these Terminal commands here: digitaldj.net­/2011­/07­/21­/trim­-enabler­-for­-lion/

2011年5月9日 星期一

host map: lookup (domain): deferred


遇到的問題是,系統送信時,透過 php 網頁程式送給 sendmail,再送到目的地的信箱;但是,收件人很久才收到這封 email. 查了一下 sendmail 的 queue, 用以下 command, 出現了以下錯誤訊息
$ sudo mailq
p495lhl1016320     5731 Mon May  9 13:50                  (host map: lookup (yahoo.com.tw): deferred)    
p49654DW016419     5731 Mon May  9 14:07                  (host map: lookup (yahoo.com.tw): deferred)    
p4947h00015791     5731 Mon May  9 12:10                  (host map: lookup (yahoo.com.tw): deferred)    

p490RhMm014614     3476 Mon May  9 08:29 MAILER-DAEMON                 (Deferred: Name server: miiicasa.com.: host name lookup failu)   

p48K2BMl013111     1547 Mon May  9 04:03                  (Deferred: Name server: miiicasa.com.: host name lookup failu)                                         
p480RhOc006719     3435 Sun May  8 08:29 MAILER-DAEMON                 (Deferred: Name server: miiicasa.com.: host name lookup failu)                                         
可是,在 DNS 的設定上並沒有錯;查了一下大家的解決方案,好像只有一個是比較符合的;但是,它解釋的也不是很清楚。詳細說明,請參考  host_map__lookup_(domain)__deferred

With Sendmail 8.12.x, you can ignore AAAA "SERVFAIL" or "NXDOMAIN" errors and continue DNS processing with the following entry in your macro configuration (.mc) file:
define(`confBIND_OPTS', `WorkAroundBrokenAAAA')dnl
暫時就只能先這麼做了,如果還有問題,可以用以下指令看 sendmail 的動作
To watch Sendmail's DNS queries when processing a queued message, use the -d8.8 debug syntax:
sendmail -v -d8.32 -qImessage_ID
另外一方面,因為看到 yahoo 又看到 deferred, 所以也想到了,yahoo 會有防堵類似垃圾信機制,所以就先 ssh 到發信主機,去測試一下,果真是 deferred 的問題。
kevin_luo@w1 { /var/log }$ telnet mx1.mail.tw.yahoo.com 25
Trying 203.188.197.119...
Connected to mx1.mail.tw.yahoo.com (203.188.197.119).
Escape character is '^]'.
421 4.7.0 [GL01] Message from (202.153.186.89) temporarily deferred - 4.16.50. Please refer to http://postmaster.yahoo.com/errors/postmaster-21.html
Connection closed by foreign host.
要解決這個問題,就只能按它的建議,去那個 URL 看看,並填寫相關的訊息,讓 yahoo mail 將你的 mail server 列入 deferred 時間較長的名單,或甚至於加到 whitelist.

2011年4月26日 星期二

安裝 Remine 及 Migrate Trac to Redmine 之解決 wiki format 的相容問題(二)


繼上一篇安裝及把資料從 Trac 移到 Redmine 之後,除了 wiki format 的錯亂之外,還會發生一些 internal server error 的問題,例如看 wiki page 含有 attachment 時,或是點擊 issue;主要問題是移轉後,redmine 資料庫裡,部份 table 欄位如果有 datetime 的格式時,轉過來後都變成 "0000-00-00 00:00:00". 目前發現有問題的是這些,所以就用以下方式把它們都設定成現在的時間。
mysql> update attachments set created_on=now();

mysql> update issues set created_on=now(), updated_on=now();

mysql> update wiki_content_versions set updated_on=now();

mysql> update journals set created_on=now();
附帶問題發生時的錯誤訊息,及發現問題的方法:
/home/m/share/htdocs/redmine/log/production.log
ActionView::TemplateError (undefined method `<=>' for nil:NilClass) on line #2 of app/views/wiki/_content.rhtml:
1: 
2: <%= textilizable content, :text, :attachments => content.page.attachments %> 3:
app/helpers/application_helper.rb:504:in `parse_inline_attachments' app/helpers/application_helper.rb:502:in `gsub!' app/helpers/application_helper.rb:502:in `parse_inline_attachments' app/helpers/application_helper.rb:458:in `send' app/helpers/application_helper.rb:458:in `textilizable' app/helpers/application_helper.rb:457:in `each' app/helpers/application_helper.rb:457:in `textilizable' app/helpers/application_helper.rb:477:in `parse_non_pre_blocks' app/helpers/application_helper.rb:456:in `textilizable' app/views/wiki/_content.rhtml:2:in `_run_rhtml_app47views47wiki47_content46rhtml_locals_content_object' app/views/wiki/show.rhtml:30:in `_run_rhtml_app47views47wiki47show46rhtml' app/controllers/wiki_controller.rb:80:in `show' public/dispatch.fcgi:24 Rendering /home/m/share/htdocs/redmine/public/500.html (500 Internal Server Error)
修改 app/helpers/application_helper.rb:504, 將 sort_by 拿掉就好了,所以就想說是不是資料庫的問題,改完 DB 之後,果然就好了。所以這支 application_helper.rb 也不必 hack 了。
504 #       attachments ||= (options[:attachments] || obj.attachments).sort_by(&:created_on).reverse
505         attachments ||= options[:attachments]
最後是更新 wiki contents 了,請照著 github 上的說明來做。

https://xfalcons@github.com/xfalcons/migrate-trac-to-redmine.git

後續,接下來會試一些好用的 plugins ,到時再分享。

2011年4月18日 星期一

安裝 Remine 及 Migrate Trac to Redmine 之解決 wiki format 的相容問題(一)


Requirements:
  • CentOS 5.x
  • Redmine 1.1.x
  • Ruby 1.8.7
  • RubyGems: 1.3.7
  • Sqlite: 3.6.16 (For migration Trac to Redmine)
  • Rails: 2.3.5
  • Rack: 1.0.1
  • MySQL 5.1 or higher (recommended)
  • openssl + openssl-devel
  • zlib + zlib-devel
官方文件:http://www.redmine.org/projects/redmine/wiki/RedmineInstall


原本想說,直接用現有的 rpm packages 來安裝以上的軟體就好了,可是最新的 ruby rpm 只有到 1.8.5 而已,所以只能用自己 compile 的方式來解決。


0. 安裝 compile 所需要的 packages
# yum install zlib-devel curl-devel expat-devel gettext-devel gcc make
1. 安裝 ruby 1.8.7:
~# cd ~
~# wget http://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7-p249.tar.gz
~# tar zxvf ruby-1.8.7-p334.tar.gz
~# cd ruby-1.8.7-p334
~/ruby-1.8.7-p334 # ./configure --prefix=/usr
~/ruby-1.8.7-p334 # make
~/ruby-1.8.7-p334 # make install
~/ruby-1.8.7-p334 # which ruby
/usr/bin/ruby
~/ruby-1.8.7-p334 $ ruby -v
ruby 1.8.7 (2011-02-18 patchlevel 334) [x86_64-linux]
 3. 安裝 sqlite 3.6.16:
~ # cd ~
~ # wget http://www.sqlite.org/sqlite-amalgamation-3.6.16.tar.gz
~ # tar xvzf sqlite-amalgamation-3.6.16.tar.gz
~ # cd sqlite-3.6.16
~ /sqlite-3.6.16 # ./configure --prefix=/usr
~ /sqlite-3.6.16 # make
~ /sqlite-3.6.16 # make install
~ /sqlite-3.6.16 # sqlite3 -version
3.6.16
4. 安裝 rubygem 1.3.7
~ # wget http://rubyforge.org/frs/download.php/70696/rubygems-1.3.7.tgz
~ # tar xvfz rubygems-1.3.7.tgz
~ # cd rubygems-1.3.7
~ /rubygems-1.3.7 # ruby setup.rb
5. 安裝 rails & rack & sqlite3
~ # gem install rails -v=2.3.5
~ # gem install rack -v=1.0.1
~ # gem install i18n -v=0.4.2
~ # gem install sqlite3-ruby
6. 安裝 mysql
~ # yum install mysql-server
~ # yum install mysql.x86_64
~ # yum install mysql-devel
~ # yum install ruby-mysql
~ # gem install mysql
7. 安裝 apache, fcgid(fastcgi)
~ # yum install httpd.x86_64
~ # yum install fcgi.x86_64   
~ # yum install fcgi-devel.x86_64
~ # yum install mod_fcgid.x86_64
~ # gem install fcgi
8. 安裝 redmine
~ # wget http://rubyforge.org/frs/download.php/74419/redmine-1.1.2.tar.gz
~ # tar xvfz redmine-1.1.2.tar.gz
~ # mkdir /var/www
~ # mv redmine-1.1.2 /var/www/redmine
9. 設定 redmine (依照官方說明即可)

2. Create an empty database and accompanying user named redmine for example.
For MySQL:
create database redmine character set utf8;
create user 'redmine'@'localhost' identified by 'my_password';
grant all privileges on redmine.* to 'redmine'@'localhost';

3. Copy config/database.yml.example to config/database.yml and edit this file in order to configure your database settings for "production" environment.
Example for a MySQL database:
production:
  adapter: mysql
  database: redmine
  host: localhost
  port: 3306
  username: redmine
  password: my_password
4. Generate a session store secret.
rake generate_session_store
5. Create the database structure, by running the following command under the application root directory:
RAILS_ENV=production rake db:migrate
6. Insert default configuration data in database, by running the following command:
RAILS_ENV=production rake redmine:load_default_data
7. Setting up permissions
NB: Windows users have to skip this section.
The user who runs Redmine must have write permission on the following subdirectories: files, log, tmp (create the last one if not present).
Assuming you run Redmine with a redmine user:
mkdir tmp public/plugin_assets
sudo chown -R redmine:redmine files log tmp public/plugin_assets
sudo chmod -R 755 files log tmp public/plugin_assets
8. Test the installation by running WEBrick web server:
ruby script/server webrick -e production
Once WEBrick has started, point your browser to http://localhost:3000/. You should now see the application welcome page.
Note: Webrick is not suitable for normal use, please only use webrick for testing that the installation up to this point is functional. It is not recommended to use webrick for anything other than development. Use one of the many other guides in this wiki to setup redmine to use either passenger (aka mod_rails) or mongrel to serve up your redmine.
9. Use default administrator account to log in:
  • login: admin
  • password: admin
10. 設定 Apache config & fastcgi
# vi /etc/httpd/conf.d/redmine.conf
<VirtualHost *:80>
      ServerName doc1.corp.muchiii.com
      DocumentRoot /home/m/share/htdocs/redmine/public/
      ErrorLog logs/redmine_error_log

      <Directory /home/m/share/htdocs/redmine/public/>
         AllowOverride all
         Options Indexes ExecCGI FollowSymLinks
         Order Deny,Allow
         Deny from all
         Allow from 122.146.2.130 172.17.8.31
      </Directory>
</VirtualHost>
# vi /var/www/redmine/public/.htaccess
<IfModule mod_fcgid.c>
        AddHandler fcgid-script .fcgi
</IfModule>
<IfModule mod_cgi.c>
        AddHandler cgi-script .cgi
</IfModule>
Options  FollowSymLinks  ExecCGI

RewriteEngine On

RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.] )$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
<IfModule mod_fcgid.c>
        RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
</IfModule>
Save the config and restart your httpd server
# /usr/sbin/service httpd configtest
# /usr/sbin/service httpd restart
Open your browser and hit http://redmine.mydomain.com, use default administrator account to log in.



11. Migrate Trac to Redmine, 轉移 Trac 的 project(sqlite3 格式) 到 Redmine 上。官方文件:http://www.redmine.org/projects/redmine/wiki/RedmineMigrate, 由於預設安裝的 migrate_from_trac.rake 會有一點點小問題(http://www.redmine.org/issues/6868),所以需要手動改一下 source codes (/var/www/redmine/lib/tasks/migrate_from_trac.rake).


The problem seems to be that function Time.fake() has problem to handle when the given input is nil.
class ::Time
    class << self
      alias :real_now :now
      def now
        real_now - @fake_diff.to_i
      end
      def fake(time)
        @fake_diff = real_now - time
        res = yield
        @fake_diff = 0
       res
      end
    end
  end
To solve that issue I modified this function in such way :
class ::Time
    class << self
      alias :real_now :now
      def now
        real_now - @fake_diff.to_i
      end
      def fake(time)
         time = 0 if time.nil? 
        @fake_diff = real_now - time
        res = yield
        @fake_diff = 0
       res
      end
    end
  end
接下來,就照著官方文件的步驟:
1. Run the following command, where test is your Redmine target environment:
rake redmine:migrate_from_trac RAILS_ENV="test"
2. The script (source:trunk/lib/tasks/migrate_from_trac.rake) asks you for your Trac settings:
Trac directory []: /var/trac/myproject
Trac database adapter (sqlite, sqlite3, mysql, postgresql) [sqlite]:
Database encoding [UTF-8]:
Target project identifier []: myproject
Trac directory is the root directory of your Trac environment. Redmine will look in this directory for db/trac.db (if you choose sqlite/sqlite3 database) and the attachments directory.
When using a mysql or postgresql Trac database, the script will ask you for the connection parameters (host, database name, username and password).
Target project identifier is the identifier of the Redmine project in which the data will be loaded (the project is created if not found).
4. The script migrates your data:
Deleting data
Migrating components..............................
Migrating milestones..............
Migrating custom fields.......
Migrating tickets.................................
Migrating wiki...........

Components: 29/30
Milestones: 14/14
Tickets: 1275/1275
Ticket files: 106/106
Custom values: 4409/4409
Wiki edits: 102/102
最後的問題會是 wiki 轉到 redmine 之後,所有的 wiki link 都亂掉了。預計用一個 script 來解決。


待續...