Ads 468x60px

Pages

2012年3月7日 星期三

Dell PowerEdge R710 - 查詢 RAID 的設定

臨時要查詢目前主機上的 RAID 設定值,不過找了一下,這方面的資訊不是很好找;而且每種廠牌,軟/硬體的 RAID Controller 都不同;在這紀錄一下我的設定

環境:
* Dell R710 E5520*2/146GB*6 SAS/2GB*4
* Integrated RAID Controller(HW)
* CentOS 5.x

一開始要先找到系統上的 RAID Controller 系統型號是什麼,試了以下的方式。

root@m001 { /proc/scsi  }$ cat scsi 
Attached devices:
Host: scsi0 Channel: 02 Id: 00 Lun: 00
  Vendor: DELL     Model: PERC H700        Rev: 2.0.
  Type:   Direct-Access                    ANSI SCSI revision: 05
Host: scsi1 Channel: 00 Id: 00 Lun: 00
  Vendor: PLDS     Model: DVD+-RW DS-8A3S  Rev: HD52
  Type:   CD-ROM                           ANSI SCSI revision: 05

不過,我的系統是用 SAS 的,所以應該不是這一個。再試

root@m001 { /proc  }$ cat devices 
Character devices:
  1 mem
  4 /dev/vc/0
  4 tty
  4 ttyS
  5 /dev/tty
  5 /dev/console
  5 /dev/ptmx
  6 lp
  7 vcs
 10 misc
 13 input
 21 sg
 29 fb
128 ptm
136 pts
162 raw
180 usb
189 usb_device
202 cpu/msr
203 cpu/cpuid
216 rfcomm
251 blktap
252 uio
253 megaraid_sas_ioctl
254 pcmcia

Block devices:
  1 ramdisk
  8 sd
  9 md
 11 sr
 65 sd
 66 sd
 67 sd
 68 sd
 69 sd
 70 sd
 71 sd
128 sd
129 sd
130 sd
131 sd
132 sd
133 sd
134 sd
135 sd
253 device-mapper
254 mdp

也沒看出什麼端泥

root@m001 { /proc  }$ cat diskstats 
   1    0 ram0 0 0 0 0 0 0 0 0 0 0 0
   1    1 ram1 0 0 0 0 0 0 0 0 0 0 0
   1    2 ram2 0 0 0 0 0 0 0 0 0 0 0
   1    3 ram3 0 0 0 0 0 0 0 0 0 0 0
   1    4 ram4 0 0 0 0 0 0 0 0 0 0 0
   1    5 ram5 0 0 0 0 0 0 0 0 0 0 0
   1    6 ram6 0 0 0 0 0 0 0 0 0 0 0
   1    7 ram7 0 0 0 0 0 0 0 0 0 0 0
   1    8 ram8 0 0 0 0 0 0 0 0 0 0 0
   1    9 ram9 0 0 0 0 0 0 0 0 0 0 0
   1   10 ram10 0 0 0 0 0 0 0 0 0 0 0
   1   11 ram11 0 0 0 0 0 0 0 0 0 0 0
   1   12 ram12 0 0 0 0 0 0 0 0 0 0 0
   1   13 ram13 0 0 0 0 0 0 0 0 0 0 0
   1   14 ram14 0 0 0 0 0 0 0 0 0 0 0
   1   15 ram15 0 0 0 0 0 0 0 0 0 0 0
   8    0 sda 2912902 5836954 68738123 7169600 160459782 17123814 1395096183 25929156 0 13643852 33091376
   8    1 sda1 40 239 580 256 0 0 0 0 0 224 256
   8    2 sda2 119 381 638 256 0 0 0 0 0 228 256
   8    3 sda3 98 1738 2073 300 26 10 70 16 0 268 316
   8    4 sda4 4 0 8 48 0 0 0 0 0 48 48
   8    5 sda5 2912623 5834579 68734544 7168636 160459756 17123804 1395096113 25929140 0 13643356 33089664
 253    0 dm-0 9539 0 268418 38228 2335167 0 18681336 3292088 0 1955100 3331236
 253    1 dm-1 8687278 0 67271513 17692256 154407246 0 1209683729 24606260 0 8434120 42334020
 253    2 dm-2 12322 0 263170 11840 16610092 0 132880736 14888900 0 4044548 14900772
 253    3 dm-3 284 0 2266 952 2883732 0 23069856 468160 0 61080 469112
 253    4 dm-4 39746 0 928154 173252 1347557 0 10780456 917888 0 69840 1091140
 253    5 dm-5 75 0 600 304 0 0 0 0 0 52 304
  11    0 sr0 7 10 136 3248 0 0 0 0 0 3144 3248
   9    0 md0 0 0 0 0 0 0 0 0 0 0 0

有看到 sdx ,不過沒什麼用

root@m001 { /proc  }$ dmidecode | grep -i sas
root@m001 { /proc  }$ dmidecode | less
root@m001 { /proc  }$ dmidecode
# dmidecode 2.7
SMBIOS 2.6 present.
83 structures occupying 4569 bytes.
Table at 0xCF79C000.

Handle 0xDA00, DMI type 218, 11 bytes.
OEM-specific Type
        Header and Data:
                DA 0B 00 DA B2 00 17 00 0E 20 00

Handle 0x0000, DMI type 0, 24 bytes.
BIOS Information
        Vendor: Dell Inc.
        Version: 1.3.6
        Release Date: 10/30/2009
        Address: 0xF0000
        Runtime Size: 64 kB
        ROM Size: 4096 kB
......

連這個都沒有。最後試到

root@m001 { /proc  }$ dmesg | grep -i sas
megasas: 00.00.04.31-RH1 Tues. June. 15 14:13:02 EST 2010
megasas: 0x1000:0x0079:0x1028:0x1f17: bus 3:slot 0:func 0
 gen2: instance->base_addr = df1bc000<6>megasas: FW now in Ready state
megasas_init_mfi: fw_support_ieee=0<6>scsi0 : LSI SAS based MegaRAID driver

終於有了。不過,怎麼不是它 SPEC 上說的 PERC 6/xx , SAS 5/E 呢?

不過,這個 MegaRAID driver 到是很多人討論到,所以就跟著找下去了。然後,找到了 LSI MegaRaid – MegaCli Linux Commands 這篇,就照著它,去 LSI Web Site 下載它的命令列工具。我是用第二頁的 MegaRAID SAS MegaCLI - Linux, Version 1.01.39 這個檔案。把 rpm 裝一下唄

[root@qa1 ~]# rpm -Uvh MegaCli-1.01.39-0.i386.rpm

[root@qa1 ~]# rpm -ql MegaCli-1.01.39-0
/opt/MegaRAID/MegaCli/MegaCli
/opt/MegaRAID/MegaCli/MegaCli64

接著去看看 help 吧. 一堆 command(請小心使用,它可以直接修改,刪除 VD)。由於我只要查詢而已,所以就執行以下 command.

[root@qa1 ~]# /opt/MegaRAID/MegaCli/MegaCli64 -AdpAllInfo -aAll
                                     
Adapter #0

==============================================================================
                    Versions
                ================
Product Name    : PERC 6/i Integrated
Serial No       : 1122334455667788
FW Package Build: 6.2.0-0013

                    Mfg. Data
                ================
Mfg. Date       : 06/24/08
Rework Date     : 06/24/08
......

終於看到它是:PERC 6/i Integrated, 然後

[root@qa1 ~]# /opt/MegaRAID/MegaCli/MegaCli64 -LDInfo -L0 -a0
                                     
Adapter 0 -- Virtual Drive Information:
Virtual Disk: 0 (target id: 0)
Name:
RAID Level: Primary-5, Secondary-0, RAID Level Qualifier-3
Size:696960MB
State: Optimal
Stripe Size: 64kB
Number Of Drives:6
Span Depth:1
Default Cache Policy: WriteBack, ReadAheadNone, Direct, No Write Cache if Bad BBU
Current Cache Policy: WriteBack, ReadAheadNone, Direct, No Write Cache if Bad BBU
Access Policy: Read/Write
Disk Cache Policy: Disk's Default

噔噔!終於出現了。原來是 RAID 5.

2012年1月2日 星期一

網路監控 : 活用 Nagios + ndo2db + Cacti + NPC (二)



2. 安裝 Apache, Mysql, Php
yum install httpd php php-mysql mysql mysql-server php-snmp net-snmp-utils

安裝完畢後,設定服務於 Server 啟動後,自動重啟
service httpd start     # Start httpd service
chkconfig httpd on      # Start after init

service mysqld start     # Start mysql service
chkconfig mysqld on      # Start after init

mysql 預設 root 密碼為 '' 空值,如要變更如下:
mysqladmin -uroot password '123456'  

Mysql for Cacti 配置, 資料庫名稱為 cactidb, 使用者為 cactier
mysql> CREATE DATABASE cactidb;
mysql> GRANT ALL ON cactidb.* TO cactier@'192.168.253.%' IDENTIFIED BY '123456';
mysql> FLUSH privileges;

基本配置完成,接下來安裝 rrdtool

3. 安裝 rrdtool

其中主要用到的是 rrdtool-1.2.27-3.el5.i386.rpm 和 rrdtool-devel-1.2.27-3.el5.i386.rpm 和rrdtool-php-1.2.27-3.el5.i386.rpm 這三個 packages.

yum install rrdtool rrdtool-devel rrdtool-php

4. 安裝 Cacti

效能問題:cacti 在做 polling 時,預設會使用 cmd.php 的方式去做,不過它的效能很差,所以需改用 Spine (Cactid)

Spine 使用 C 來取代呼叫 cmd.php ,在效能上提升很多。官方網頁也寫說 ,如果執行 php poller.php 時間超過 300 秒,就需要使用 Spine 。使用方法很簡單,照著官方網頁作就可以了,不在此贅述。個人是覺得 cmd.php 的方法該廢掉了,目前存在的意義只是因為 php 讓 cacti 達成跨平台的特性。

For cacti-spine package, download from here http://pkgs.repoforge.org/cacti-spine/cacti-spine-0.8.7g-1.el5.rf.x86_64.rpm , and then install cacti and spine.
yum install cacti-0.8.7g-1.el5.1.noarch.rpm
yum -y localinstall --nogpgcheck cacti-spine-0.8.7g-1.el5.rf.x86_64.rpm

根據 mysql 的設定,修改 spine.conf 的配置
DB_Host         192.168.1.100
DB_Database     cactidb
DB_User         cactier
DB_Pass         123456
DB_Port         3306

5. 安裝及配置 snmpd

# yum install net-snmp

在被監控的主機,配置 /etc/snmp/snmpd.conf
rocommunity public
#com2sec notConfigUser  default       public
com2sec readonly  default       public

syslocation Taipei
syscontact admin@yourdomain.com

測試 snmp
# snmpwalk -v 1 -c public 192.168.1.103 | less

SNMPv2-MIB::sysDescr.0 = STRING: Linux w1.yourdomain.com 2.6.18-238.1.1.el5 #1 SMP Tue Jan 4 13:32:19 EST 2011 x86_64
SNMPv2-MIB::sysObjectID.0 = OID: NET-SNMP-MIB::netSnmpAgentOIDs.10
DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (32300) 0:05:23.00
SNMPv2-MIB::sysContact.0 = STRING: admin@yourdomain.com
SNMPv2-MIB::sysName.0 = STRING: w1.yourdomain.com
SNMPv2-MIB::sysLocation.0 = STRING: Taipei
...

7. 配置 Cacti

建立 cacti 資料庫
# mysql -u root -p cactidb < /usr/share/doc/cacti-0.8.7g/cacti.sql
## 將 cacti.sql 資料庫文件導入,並輸入 root 密碼即可 
編輯 /usr/share/cacti/include/config.php,對應到 mysql 的設定
$database_type = "mysql";
$database_default = "cactidb";
$database_hostname = "192.168.100.1";
$database_username = "cactier";
$database_password = "123456";
$database_port = "3306";
先暫時把 selinux 關閉,不然不能以 web 執行 install
# setenforce 0
修改目錄權限, cacti 服務以 cacti 這個 unix user 在執行
# chown -R cacti /usr/share/cacti/rra
# chown -R cacti /usr/share/cacti/log
好了,下面就可以用 web 訪問 cacti 進行配置管理了。 筆者所用的 web ip 為 192.168.100.1 從瀏覽器直接訪問以下地址 即可看到 cacti 配置畫面 http://192.168.100.1/cacti/install/ 如果看到以下畫面,則可以進行之後的配置 如果上面全是 [FOUND] ,則可以點擊 Finish 完成,當中的路徑可能與圖片不同。 Finish 後就會出現登入畫面 用戶名 admin, 密碼 admin 即可登入(第一次登作後會強迫修改密碼) 等待 5~10 分鐘後,即會有圖形出現。 8. 安裝 NDOUtils 安裝 NDOUtils,NDOUtils 用來將 Nagios 的配置信息和各 event產生的數據存入資料庫,以實現這些數據的快速檢索和處理。http://packages.sw.be/ndoutils/ndoutils-1.4-0.beta7.3.el5.rf.x86_64.rpm
# yum install postgresql-libs-8.1.22-1.el5_5.1.x86_64 postgresql-8.1.22 perl-DBD-MySQL.x86_64
# rpm -ivh ndoutils-1.4-0.beta7.3.el5.rf.x86_64.rpm
配置 mysql for ndo
mysql> create database ndodb;
mysql> grant all privileges on ndodb.* to ndouser@'192.168.100.%' IDENTIFIED BY '123456';
mysql> grant all privileges on ndodb.* to ndouser@'192.168.100.%' IDENTIFIED BY '123456';
mysql> flush privileges;
載入 ndodb
root@h { /usr/share/ndoutils  }$ ./installdb -u ndouser -p 123456 -h 192.168.100.1 -d ndodb
編輯以下配置檔
/etc/nagios/nagios.cfg
/etc/nagios/ndo2db.cfg
/etc/nagios/ndomod.cfg
## /etc/nagios/nagios.cfg
broker_module=/usr/libexec/ndomod-3x.o config_file=/etc/nagios/ndomod.cfg
## /etc/nagios/ndo2db.cfg
socket_type=unix
socket_name=/var/nagios/rw/ndo.sock
db_servertype=mysql
db_host=192.168.100.1
db_name=cacti
db_user=cacti
db_pass=123456
db_prefix=npc_
## /etc/nagios/ndomod.cfg
output_type=unixsocket
output=/var/nagios/rw/ndo.sock
Restart nagios and cacti. 9. 安裝 NTop
# yum install ntop
設定 ntop admin 密碼
# ntop -A

Wed Nov  9 18:17:35 2011  NOTE: Interface merge enabled by default
Wed Nov  9 18:17:35 2011  Initializing gdbm databases

ntop startup - waiting for user response!

Please enter the password for the admin user: 
Please enter the password again: 
Wed Nov  9 18:17:41 2011  Admin user password has been set
10. Cacti 整合 NPC, Nagios 依據你的 npc 版本,下載 http://mirror.cactiusers.org/downloads/plugins/cacti-plugin-0.8.7g-PA-v2.8.tar.gz
# {/} tar xvfz cacti-plugin-0.8.7g-PA-v2.8.tar.gz 
# {/} cd cacti-plugin-arch/
# {/cacti-plugin-arch/} cd files-0.8.7g/
# {/cacti-plugin-arch/files-0.8.7g/} cp -rp * /usr/share/cacti/
# {/cacti-plugin-arch/files-0.8.7g/} cd /usr/share/cacti/
# {/usr/share/cacti/} patch -p1 -N < ~/cacti/cacti-plugin-arch/cacti-plugin-0.8.7g-PA-v2.8.diff
Modify /usr/share/cacti/include/global.php file
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "192.168.253.6";
$database_username = "cacti";
$database_password = "e29e776dbdd150c30c55171cb3bcd452";
$database_port = "3306";
$url_path = "/"; ## depend on your apache config
回到 Browser 介面 http://service_url/cacti 选择左下的 User Managenment 之后点击 admin 在其中最后一项打钩,并保存 ... 好了,现在 cacti 就支持其他插件功能了,下面把 ntop 和 nagios 加进去就可以了 http://docs.cacti.net/_media/plugin:ntop-v0.2-1.tgz 首先去下载cacti的ntop插件,而后解压至cacti的插件目录: # tar zxvf ntop-0.1.tar.gz -C /var/www/html/cacti/plugins/ 接着配置cacti的主配置文件,启用此插件: # vim /var/www/html/cacti/include/config.php 添加如下内容: $plugins[] = 'ntop'; For NPC https://api.opensuse.org/public/source/server:monitoring/cacti-npc/npc-2.0.4.tar.gz
root@img2 { ~/cacti/npc  }$ tar xvfz npc-2.0.4.tar.gz 
root@img2 { ~/cacti/npc  }$ cd ../
root@img2 { ~/cacti  }$ cp -rp npc /usr/share/cacti/plugins

接下来到cacti的控制台中"settings"中配置此插件,将其指向实际的ntop服务器所在的URL;然后再到cacti控制台的"user Management"中的admin用户中启用此插件即可。

2011年12月30日 星期五

多重網域 UCC SSL 憑證的申請方式 Multi-domain UCC SSL on one certificates

近代,使用 https 協定的網站或服務,經常是由多個 domain name 來組成一個網頁,可是 ssl v1.0 只允許單一 SSL certificate 使用於單一 domain name,這樣,在使用上就會有問題。

要支援 multiple sites 使用 HTTPS 以及名稱虛擬主機(Name-Based Virtual Host) 可以使用

  1. Wildcard Names(萬用字元): specified in RFC2818
  2. Subject Alternative Names(憑證主體別名):  x509 version 3 certificate (specified in RFC3280)

這二者在使用上是不同的。萬用字元是用在同一個 sub-domain 之下的,例如: *.example.com 的憑證, 可以使用在 www.example.com, foo.example.com, bar.example.com, 但是不可以使用在 example.com, aaa.www.example.com. 而憑證主體別名卻可以涵蓋多個不同的網域,例如:www.mydomain.com 的憑證,可以包含 www.myimage.com, foo.myugc.com, foo.bar.mydomain.com. 至於如何挑選要使用那一種憑證,就要視你的網站規劃而定了,它們的費用也不一樣,正常來說,萬用字元會比憑證主體別名還貴。

以下詳列「憑證主體別名」的申請以及自行簽章的方式,環境為 Cent-OS 5.x, OpenSSL 0.9.8e. 你需要修改 /etc/pki/tls/openssl.cnf

1. 啟動擴展
[req]
req_extensions = v3_req
2. 增加 subjectAltName 到 v3_req 的區段
[ v3_req ]
subjectAltName = @alt_names
3. 例如你要包含的多個網域
[alt_names]
DNS.1 = example.com
DNS.2 = hello.example.com
DNS.3 = testing.com
DNS.4 = www.testing.com
DNS.5 = foo.testing.com
4. 修改完成,存檔後,接著產生私密金鑰
openssl genrsa -des3 -out www.example.com.key 2048
這個步驟,一定要你輸入 passphrase;不過在未來使用上,重啟 Apache Server 時,都一定要輸入這個 passphrase 有點麻煩。我們可以另外產生一個不需要 passphrase 的 key 來使用。
openssl rsa -in www.example.com.key -out www.example.key.insecure
5. 產生 CSR(憑證簽署請求)
openssl req -new -key www.example.com.key -out www.example.com.csr
按照步驟填入適當資料,請注意,在填寫 commonName 的地方,就是填入你的主網站名稱,如本例:www.example.com 做完之後,就會有一個 www.example.com.csr 的檔案,在你當前的目錄中,接著我們確認一下
openssl req -text -noout -in www.example.com.csr
應該會看到
Attributes:
        Requested Extensions:
            X509v3 Basic Constraints:
                CA:FALSE
            X509v3 Key Usage:
                Digital Signature, Non Repudiation, Key Encipherment
            X509v3 Subject Alternative Name:
                DNS:example.com, DNS:hello.example.com, DNS:testing.com, DNS:www.testing.com, DNS:foo.testing.com
這樣,你就可以拿這個 CSR 去申請有效的 SAN 憑證了。在此,我們繼續做自行簽章及核發的動作。
openssl x509 -req -days 3650 -extfile /etc/pki/tls/openssl.cnf -extensions v3_req -in www.example.com.csr -signkey www.example.com.key -out www.example.com.crt
這裡,要注意一下,一定要加 "-extfile /etc/pki/tls/openssl.cnf -extensions v3_req" 這二個參數(卡關很久啊!);然後,再驗證一下
openssl x509 -text -noout -in www.example.com.crt
應該會看到
X509v3 extensions:
            X509v3 Basic Constraints: 
                CA:FALSE
            X509v3 Key Usage: 
                Digital Signature, Non Repudiation, Key Encipherment
            X509v3 Subject Alternative Name: critical
                DNS:example.com, DNS:hello.example.com, DNS:testing.com, DNS:www.testing.com, DNS:foo.testing.com
這樣,就大致完成了。接著就 copy www.example.com.key.insecure, 以及 www.example.com.crt 到你的 Apache Server, 並設定 apache conf(請自己 google 一下就不贅述了)

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 來解決。


待續...

2011年4月15日 星期五

sendmail dead.letter/user unknown 問題 (dead.letter issue)


問題:在主機 a1.corp.xfalcons.com 要送信到 kevin@xfalcons.com,但是 xfalcons.com 的收信主機實際上是 host 在 gmail.com 的。

問題發生的起因:
1. a1.corp.xfs.com 修改主機名稱成 a1.corp.xfalcons.com
2. xfalcons.com 的收信伺服器 host 在 gmail.com 上
3. 而在 /etc/mail/sendmail.cf 裡有這樣的設定
Cwlocalhost
# file containing names of hosts for which we receive email
Fw/etc/mail/local-host-names

# my official domain name
# ... define this only if sendmail cannot automatically determine your domain
#Dj$w.Foo.COM
並且 /etc/mail/local-host-names 檔案裡,包含了
xfalcons.com
這樣的設定結果,造成 sendmail 認為本機是可以收 userXXX@miiicasa.com 的信件,可是我們要的是它送到 gmail 的 miiicasa.com 去。

解決方式:清空 /etc/mail/local-host-names 的檔案,或是寫成真正的主機名稱,如:a1.corp.xfalcons.com

另一解法是說,直接修改 /etc/mail/sendmail.cf 把 #Dj$w.Foo.COM 的註解拿掉,並且把 Foo.COM 改成一個不存在的 domain ,就可以了,或是修改 /etc/mail/sendmail.mc
define(`confDOMAIN_NAME', `mail.example.net')dnl
不過好像有點問題。

2011年3月17日 星期四

網路監控 : 活用 Nagios + ndo2db + Cacti + NPC (一)


說到 Linux 免費網路監控軟體,前三名不外乎是 Nagios, Ntop, Cacti. 它們各有各自的強項。這裡我是取 Nagios 強大的監測及通知的功能,Cacti 強大的繪圖及 plugin 能力。所以才會使用 Nagios + Cacti + NPC。它們的基本的安裝方式,去 google 一下就很多了,這裡只列安裝要點,主要說明 nagios 配置檔, ndo2db及NPC 的設定及使用方式。

1. 安裝 Nagios
RHEL5.x 的 repository 裡的 nagios 還是 2.x 的,所以自行去下載
$ yum install libtool-ltdl.x86_64 fping perl-Net-SNMP
$ wget http://packages.sw.be/nagios/nagios-3.2.3-3.el5.rf.x86_64.rpm
$ rpm -ivh nagios-3.2.3-3.el5.rf.x86_64.rpm
$ yum install nagios-common-2.12-10.el5 
$ yum install nagios-plugins-1.4.15-2.el5
$ yum install nagios-plugins-all-1.4.15-2.el5
裝完之後,基本的設定檔 /etc/nagios 就已經可以執行了,只要再修改二個地方就可以。
  1. 修改 /etc/nagios/objects/contacts.cfg 檔裡的 email address 成你的 email ,這樣你才可以收到通知信。
  2. 修改 nagiosadmin 的 password (瀏覧器介面的帳號)
# cd /etc/nagios 
# htpasswd -c /etc/nagios/htpasswd.users nagiosadmin
....你的密碼....

# /sbin/service nagios restart
接著打開 Browser,輸入 http://localhost/nagios 就可以看到畫面了。

2011年3月15日 星期二

回復 screen session 時,自動連結到 ssh-agent


一般情況下,我都是透過我的 notbook 的 macOSX(terminal) or windows(pietty) ssh 進去一台主機(dev)後,執行 screen 再開一些 windows 連到其他的主機(m1,m2,m3...)上做事,但是在併用 ssh-agent 及 screen detach 時,時常會發生找不到 agent 的情況,網路上有一大堆的解法,參考 http://www.reasonablyopinionated.com/2009/03/automatically-reconnecting-to-ssh-agent.html ,最後,我使用如下的方式解決。

先從 notebook 登入主機 dev
notebook> $ ssh dev

修改 dev 主機上的 .bash_profile,增加下面的 code
test $SSH_AUTH_SOCK && ln -sf "$SSH_AUTH_SOCK" "/tmp/ssh-agent-$USER-screen"
修改 dev 主機上的 .screenrc,增加下面的 code
setenv SSH_AUTH_SOCK "/tmp/ssh-agent-$USER-screen"

2011年3月9日 星期三

sendmail 本地送信 masquerade 設定-解決 From, Reply-To的問題


環境:
- Linux kernel: 2.6.18-164.11.1.el5.centos.plus
- Distribution: CentOS release 5.4 (Final)
- 主機名稱:w1.xfs.tw.mydomain.com

需求:將本機(例如以 shell: /usr/sbin/sendmail -t ...) 送出的信件,From, Reply-To 重寫為 noreply@mydomain.com,讓收件人無法回覆這一封系統發出的信件。

預設:sendmail 的基本設定會將 From: noreply@mydomain.com 的 mydomain.com 改為主機名稱,如 w1.xfs.tw.mydomain.com. 這樣會暴露我們的主機名稱,並且也不是我們想要達到的目的。

修改:sendmail 的設定檔,預設是存在 /etc/mail/sendmail.cf(給神人看的), 我們要看及修改的是 /etc/mail/sendmail.mc, 修改完畢之後,再做以下動作,以更新 sendmail.cf 檔,最後再重啟 sendmail 的 service.

2010年8月13日 星期五

cfengine 3 的安裝與設定




Note: cfengine 3 is a revisional version, compare to cfengine 2.

Go to the website and dowload rpm (http://www.cfengine.org)

[root@host]#rpm -ivh ./cfengine-community-3.0.5-1.el5.x86_64.rpm

安裝完成後,請查看一下所安裝的檔案位置。

[root@h masterfiles]# rpm -ql cfengine-community
/etc/default/cfengine3
/etc/init.d/cfengine3
/usr/local/share
/usr/local/share/doc
/usr/local/share/doc/cfengine
/usr/local/share/doc/cfengine/ChangeLog
/usr/local/share/doc/cfengine/INSTALL
/usr/local/share/doc/cfengine/NEWS
/usr/local/share/doc/cfengine/README
/usr/local/share/doc/cfengine/cfengine_stdlib.cf
/usr/local/share/doc/cfengine/inputs
/usr/local/share/doc/cfengine/inputs/failsafe.cf
/usr/local/share/doc/cfengine/inputs/library.cf
/usr/local/share/doc/cfengine/inputs/promises.cf
/usr/local/share/doc/cfengine/inputs/site.cf
/usr/local/share/doc/cfengine/inputs/update.cf
/usr/local/share/doc/cfengine/promise_knowledge.cf
....

2010年8月12日 星期四

CentOS 5.x RHEL(RedHat Enterprise Linux) 5.x 安裝 Xen hypervisor 3.x 筆記



因為工作上的需求,要提供多份的 RHEL 5.x 環境給不同部門做測試用;因為是測試用,所以它所需的硬體資源也不會太多,於是乎想到來試試把它們都安裝到同一台主機上吧!要達成這個目的,非 Virtualization 莫屬。

因為是要提供 RHEL 5.x 的環境,Redhat 公司對於 Xen Hpyervisor 支援完整,所以就直接選定用它囉!

Xen 支援兩種不同的虛擬化模式:Para-virtualization(半虛擬化), Fully-virtualization(全虛擬化),以下是它們的簡短介紹。

  • Para-virtualization(半虛擬化)
    • 半虛擬化需使用特殊的系統核心(Xen kernel or kernel-xen). 半虛擬化的作業系統(guest)在執行時可以共用主系統(host)的資源(libraries and devices)。所以它相對的會比全虛擬化系統快速。
  • Full virtualization(全虛擬化)
    • 全虛擬化系統使用處理器的功能來提供整個硬體資源的抽象層(可以稱作虛擬機器),然後將所要安裝的作業系統安裝在它的上面,就好是裝在一台實體的機器一般。

2010年8月6日 星期五

Linux 提示符號 - Fancy Prompt & Color Theme

在 iTerm 及 linux command line mode 底下,預設的提示符號及色彩(無色彩),要辨別訊息,不是那麼容易,於是就來給它改造一番。底下分三個種類來說(我的 login shell 一律使用 bash):

一、Mac OS X iTerm 底下的提示符號 (Regular Prompt)
底下是我的 ~/.bash_profile 的一部份

if [ "$PS1" ]; then
    case $TERM in
    xterm*)
        if [ -e /etc/sysconfig/bash-prompt-xterm ]; then
            PROMPT_COMMAND=/etc/sysconfig/bash-prompt-xterm
        else
            PROMPT_COMMAND='echo -ne "\033]0;${HOSTNAME%%.*}:${PWD/#$HOME/~}"; echo -ne "\007"'
        fi
        ;;
    screen)
        if [ -e /etc/sysconfig/bash-prompt-screen ]; then
            PROMPT_COMMAND=/etc/sysconfig/bash-prompt-screen
        else
            PROMPT_COMMAND='echo -ne "\033_${HOSTNAME%%.*}:${PWD/#$HOME/~}"; echo -ne "\033\\"'
        fi
        ;;
    *)
        [ -e /etc/sysconfig/bash-prompt-default ] && PROMPT_COMMAND=/etc/sysconfig/bash-prompt-default
        ;;
    esac
    # Turn on checkwinsize
    shopt -s checkwinsize
    PS1="\[\033[0;32m\][\u@\h:\[\033[0;33m\\w\[\033[0;32m\]]$\[\033[0m\] "
fi

export LANG=zh_TW.UTF-8
export CLICOLOR=1

粗體的部份,
PS1="\[\033[0;32m\][\u@\h:\[\033[0;33m\\w\[\033[0;32m\]]$\[\033[0m\] "
是用來改造命令提示符號的,

export CLICOLOR=1

是用來啟動色彩的。

二、Linux 底下的提示符號 (Fancy Bash Prompt)
原文請參考這裡 http://www.debian-administration.org/articles/205
簡單的說,就是把那一串 shell script 存成一個檔,例:~/.fancy_bash_prompt ,然後,在你的 ~/bash_profile 的最後面,加上

. ~/.fancy_prompt

就可以了。

三、Mac OS X 下 iTerm 的 color theme (對投影來說,特別容易辨別)
原文請參考這裡 http://kpumuk.info/mac-os-x/customizing-iterm-creating-a-display-profile-with-pastel-colors/

先關閉你的 iTerm, 接著啟動 Terminal.app,然後

你可以使用以下方式,安裝最新的 pastel theme

$ bash  (curl http://gist.github.com/raw/473731/iterm_pastel_theme.sh)


Enjoy ~~

2010年7月15日 星期四

iPad Jailbreak (JB)

7月初,拿到滾燙燙的 iPad wifi 64G 之後,就想到直接上 JB,免得跟 iPhone 3G 一樣,一開始沒有JB,日後怕出問題,一直沒有上 JB.

在爬了文,及詢問過同事之後,大家都說現在 JB 跟吃飯一樣,幾個 click 就好了。於是就下定決心開始了......

系統/環境資訊:

- Mac OS X 10.6.3
- iTune 9.2
- iPad OS 3.2

步驟一,備份 SHSH:
- Open iTune Apps on Mac.
- Connect iPad to USB, then iTune will detect it.
- Download and install backup application: TinyUmbrella (google it)

- Open TinyUmbrella, then it will detect your iPad and your OS version.
- Click on "Advanced Options" in TinyUmbrella Apps.
  - you will see your "ECID" on screen, which is Exclusive Chip ID.
  - select "Location" to "Cydia"
  - click "Save My SHSH"
    -The file will be saved in your local machine ($HOME/.shsh/) and Cydia server.
- Done.

步驟二,JailBarek:
- Download and install "SPIRIT" software.
- Open SPIRIT.
- SPIRIT will detect that your iPad is connected.
- Just click "Jailback". within 1 sec and it's done. (三小,這樣就完成了喔!)
  - Don't click "Close" yet until iPad has been rebooted.
  - iPad is rebooting.
- JB is done, Quit SPIRIT.

步驟三,Initializing Cydia:
- on iPad, click "Cydia" to initialize. 
- Done

步驟四,安裝 AppSync , 讓 *.ipa (Apps 檔案格式)可以直接裝到 iPad 上:
- Open Cydia
- Click Manage, and click Source
- Add a source: http://cydia.hackulo.us
- After that, Click Hackulo source, then select AppSync OS 3.2 to install.
- Done.

~~~~~~ Happy Play Around Your iPad ~~~~~~

2010年6月2日 星期三

Add Additional YUM Repository to Redhat EL5

在標準的 Redhat EL5 底下,yum 的 repository 只提供官方的版本。日前,因為工作需要要裝以下的 library or package 給 PHP 使用,

pecl/json
pecl/imagick

可是在官方版本底下,找不到相關的套件;嘗試用 'pecl install imagick' 重新編譯時,又會發生找不到 libWand.so 相關的函式庫。在網路上 google 了一番,發現在 EPEL(Extra Package for Enterprise Linux) 有現在的 rpm 可用,所以就試著把它裝起來,以下是所有的步驟。

--------------------------------------------------------------------
Add the following two files into '''/etc/yum.repos.d'''

filename: /etc/yum.repos.d/epel.repo
[epel]
name=Extra Packages for Enterprise Linux 5 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/5/$basearch
mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=epel-5&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL

[epel-debuginfo]
name=Extra Packages for Enterprise Linux 5 - $basearch - Debug
#baseurl=http://download.fedoraproject.org/pub/epel/5/$basearch/debug
mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=epel-debug-5&arch=$basearch
failovermethod=priority
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL
gpgcheck=1

[epel-source]
name=Extra Packages for Enterprise Linux 5 - $basearch - Source
#baseurl=http://download.fedoraproject.org/pub/epel/5/SRPMS
mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=epel-source-5&arch=$basearch
failovermethod=priority
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL
gpgcheck=1

filename: /etc/yum.repos.d/epel-testing.repo
[epel-testing]
name=Extra Packages for Enterprise Linux 5 - Testing - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/testing/5/$basearch
mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=testing-epel5&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL

[epel-testing-debuginfo]
name=Extra Packages for Enterprise Linux 5 - Testing - $basearch - Debug
#baseurl=http://download.fedoraproject.org/pub/epel/testing/5/$basearch/debug
mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=testing-debug-epel5&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL
gpgcheck=1

[epel-testing-source]
name=Extra Packages for Enterprise Linux 5 - Testing - $basearch - Source
#baseurl=http://download.fedoraproject.org/pub/epel/testing/5/SRPMS
mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=testing-source-epel5&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL
gpgcheck=1

Also you need to import the gpg key for the repository as follows: (check out latest location of file: https://fedoraproject.org/keys)
$ cd /etc/pki/rpm-gpg
$[/etc/pki/rpm-gpg] wget -o RPM-GPG-KEY-EPEL https://fedoraproject.org/static/217521F6.txt
$[/etc/pki/rpm-gpg] sudo rpm -import RPM-GPG-KEY-EPEL

2010年5月20日 星期四

在 Chrome on Mac 上移除擾人的 google translate bar

最近用 Google Chrome 的時候,被那個惱人的 translate bar 搞得很火,所以就辦法看能不能把它 disable 掉;找來找去,遍尋不著。後來,想到直接到檔案系統裡,找出它的設定檔來改。

設定檔位置:  ~/Library/Application Support/Google/Chrome/Default/Preferences

裡頭會有幾個跟 translate 相關的設定,如下:


   "translate_language_blacklist": [ "zh-TW" ],
   "translate_site_blacklist": [ "xfalcons.blogspot.com", "mail.google.com", "www.facebook.com", "www.plurk.com", "udn.com", "www.google.com.tw", "tw.yahoo.com" ],

我的設定方式是將所有 zh-TW, googe.com, yahoo.com ... 等,不想要 translate bar 的站,都加到裡面去,這樣,就不會被那個 bar 一直推來推去了。

2010年4月13日 星期二

[PHP] upload file 的同時,存取其他的 parameters

幾天前,被問到 html form 在 upload file 的同時,如何存取其他的參數?太久沒寫 code ,一時也無法確定,所以寫了個測試程式。結果是可以用 $_POST 拿到。

[upload_form.html]
------
....

form action="http://192.168.0.1:80/ws/uploadFile" enctype="multipart/form-data" method="post"
input name="t" type="hidden" value="1271143058" 
input name="expire" type="hidden" value="1271143063" 
input name="routerAccessKeyId" type="hidden" value="05f6adb19e46f06ef0515f24e2dc586e" 
input name="sig" type="hidden" value="e53a274015c4ab6670faa98775827c3b" 
input name="path" type="hidden" value="/usb1/muchiii/photo" 
input name="callback" type="hidden" value="_getdata_123456" 

input name="filename" type="file" 
...
...
------

[uploadFile.php]
------
var_dump($_POST);
print "\n";
var_dump($_FILES);
------

得到以下結果。
------
array(6) {
  ["t"]=>
  string(10) "1271143058"
  ["expire"]=>
  string(10) "1271143063"
  ["routerAccessKeyId"]=>
  string(32) "05f6adb19e46f06ef0515f24e2dc586e"
  ["sig"]=>
  string(32) "e53a274015c4ab6670faa98775827c3b"
  ["path"]=>
  string(19) "/usb1/muchiii/photo"
  ["callback"]=>
  string(15) "_getdata_123456"
}

array(1) {
  ["uploadedfile"]=>
  array(5) {
    ["name"]=>
    string(18) "OverallSystem1.png"
    ["type"]=>
    string(9) "image/png"
    ["tmp_name"]=>
    string(14) "/tmp/phpNbiLMY"
    ["error"]=>
    int(0)
    ["size"]=>
    int(86265)
  }
}
------

2010年2月2日 星期二

USB SATA 外接硬碟如何在 Mac OS & Windows XP 之間共享及讀寫

之前把這顆 USB SATA 硬碟,格式化成 Mac OS Extended Journaled,然後,用在 2 台 macbook pro 之間透過 rsync 做備份及同步我的 home directory,沒有什麼大的問題。

有天,想要把我另一台 Windows XP 上 download 下來的電影檔要 copy 到 MacbookPro,發現 Windows XP 竟然認不得這顆外接 USB 硬碟;原來,Windows XP 是認不得 "Mac OS Extended Journaled" 的檔案格式,只好來將它 format 成 FAT32 格式。

之後,將 USB 硬碟做了第二份備份之後,就把它放在 MacbookPro 裡,格式化成 FAT32。接下來,接到 Windows XP 的電腦上。看起來是可以用了,可是之後發現了另一個問題,就是 FAT32 格式,不支援單一檔案超過 4GB;只有 NTFS 可以支援,可是 Mac OS 又不認得 NTFS 格式(Leopard 之前,縱使認得,也只能讀,不能寫)。那到底我要用什麼格式呢?

在考量這顆外接 USB 硬碟的穩定性(“建達“出奇蛋,果然是蛋,很脆弱),就放棄它當做 MacbookPro 的備份硬碟,而拿它來做為 Windows XP 下的第三顆硬碟。

即然要 format 成 NTFS,當然就選擇在 Windows XP 下進行;在著手 format 它的過程中,又發現,它有一個奇怪的分割區,叫做“GPT保護的磁碟分割“,沒有辦法刪除它;google 了一下,發現原來它是 Vista or Windows 7 額外建出來的 partition,用來保護資料用的;不過在 Windows XP 下,它是沒有作用的,所以就想辦法來刪除它。以下是刪除它的方法

==================================================================
Windows XP → 開始 → 執行 → diskpart

接著輸入 list disk 查看所有磁碟機編號

選擇你要修改的磁碟, 假設是 disk 1, 就輸入 select disk 1 來選擇 磁碟#1

最後在輸入 clean

搞定
==================================================================

之後,再到 「控制台」-「系統管理工具」-「電腦管理」做 partition 及 format 成 NTFS 即可。

當當當,接下來,這顆 USB 外接硬碟雖然在 mac 端可以讀取,但是卻不能寫入。有二個方式:

1. MacFUSE + NTFS-3G
2. NTFS Mounter

二種方式,都各有利幣,就看你的需求而定囉!基本上,我會以「讀取」為主,偶而用用「寫入」,所以我選 NTFS Mounter.