3 月 4 2015
12 月 30 2014
Crucial M550 on Lenovo L412
12 月 14 2014
rsyslog daemon 在 OpenVZ guest 瘋狂佔用 CPU resource
剛幫忙解掉的問題。
某台建立在 OpenVZ 的 Ubuntu 的 rsyslog daemon process 瘋狂佔用 CPU resource。
log 看到的狀況是這樣:
... Dec 14 06:25:13 Linux rsyslogd-2177: rsyslogd[internal_messages]: 1134916 messages lost due to rate-limiting Dec 14 06:25:13 Linux rsyslogd: imklog: error reading kernel log - shutting down: Bad file descriptor Dec 14 06:25:13 Linux rsyslogd: message repeated 498 times: [imklog: error reading kernel log - shutting down: Bad file descriptor] Dec 14 06:25:19 Linux rsyslogd-2177: rsyslogd[internal_messages]: 1114295 messages lost due to rate-limiting Dec 14 06:25:19 Linux rsyslogd: imklog: error reading kernel log - shutting down: Bad file descriptor Dec 14 06:25:19 Linux rsyslogd: message repeated 498 times: [imklog: error reading kernel log - shutting down: Bad file descriptor] Dec 14 06:25:25 Linux rsyslogd-2177: rsyslogd[internal_messages]: 1805432 messages lost due to rate-limiting Dec 14 06:25:25 Linux rsyslogd: imklog: error reading kernel log - shutting down: Bad file descriptor Dec 14 06:25:25 Linux rsyslogd: message repeated 498 times: [imklog: error reading kernel log - shutting down: Bad file descriptor] ...
把 /etc/rsyslog.conf 下列這行註解掉,重新啟動 rsyslog 就搞定了…
$ModLoad imklog # provides kernel logging support
11 月 30 2014
[MySQL] shrink ibdata file
最近幫忙處理某台 MySQL 5.0 server,做了個小實驗,寫個文章把處理過程紀錄下來。
因為該 server 沒有 innodb_file_per_table 這個設定,所有的 InnoDB 資料都放在 ibdata 這個檔案裡,而我們希望能讓該 server 持續運作,盡可能在不停機的狀況下,把 InnoDB 的資料切開。
實驗後,我們透過這些步驟完成切割/轉移:
- 確認舊的 server 有開啟 binlog,準備跑 replication。
- 用 Percona XtraBackup 備份舊的 MySQL 資料庫。
- 準備新機器,把備份檔丟到新的 server。
- 在新機器的 my.cnf 加入 innodb_file_per_table 設定,把 MySQL daemon 跑起來。
- 在新機器用以下指令把 InnoDB table 挑出來:
SELECT `TABLE_SCHEMA`, `TABLE_NAME` FROM `TABLES` WHERE `ENGINE`='InnoDB' ORDER BY `TABLE_SCHEMA`,`TABLE_NAME`;
- 在新機器用 mysqldump 匯出 table schema & data :
mysqldump -u root -pMY_PASSWORD --max_allowed_packet=512M -Cx --opt TABLE_SCHEMA TABLE_NAME > TMP_DIR/TABLE_SCHEMA.TABLE_NAME.sql
- 在新機器 drop 掉已匯出的 table:
DROP TABLE `TABLE_SCHEMA`.`TABLE_NAME`;
- 停掉新機器的 MySQL daemon,把 datadir 的 ib* 搬走,再啟動 MySQL daemon。
- 重新匯入 table:
mysql -u root -pMY_PASSWORD TABLE_SCHEMA < TMP_DIR/TABLE_SCHEMA.TABLE_NAME.sql
- 用 CHANGE MASTER TO … 指令開始讓新機器的 MySQL 成為舊 server 的 SLAVE。
- 同步完成後,找時間讓舊的 server 退下,讓新的 server 佔用舊機器的 IP。
- 在新機器的 MySQL 執行 RESET SLAVE,停掉 replication。
7 月 10 2014
[PHP] 自製金錢分攤函式
近日在工作上應該會需要計算金錢分攤,簡單寫了個 PHP 函式備用。
function shareAmount( $amount , $shares ) { $arr = array(); if ( is_numeric($amount) && is_int($shares) ) { $precision = is_int($amount) ? 0 : strlen(substr($amount, strpos($amount, '.')+1)); for ( $i = $shares; $i > 0; $i-- ) { $val = round( $amount / $i , $precision ); array_push( $arr , $val ); $amount -= $val; } } return $arr; }
執行結果大概像這樣:
// var_dump( shareAmount(101,3) ); array(3) { [0]=> float(34) [1]=> float(34) [2]=> float(33) } // var_dump( shareAmount(0.5101,3) ); array(3) { [0]=> float(0.17) [1]=> float(0.1701) [2]=> float(0.17) }
我在資料庫沒看到大數,所以就沒考慮 BC Math,直接用 is_numeric() 了… :p
5 月 4 2014
Javascript 的變數範圍
最近在微調部門某個 PHP 專案程式,該專案使用 ExtJS 作前端介面 framework …
整理這個專案內的 Javascript 程式讓我覺得… 應該有不少人忽略,或是不在意 Javascript 的變數定義方式。
這張圖有趣就在第 40, 41 行程式碼執行的結果差異,以及 42, 43 行程式碼執行的結果差異。
在 Javascript 不透過 var 進行定義之變數,皆為全域變數;但透過 var 定義之變數就有變數範圍。
這兩種變數定義方式影響瀏覽器開啟網頁後的記憶體耗用量,以及 Javascript engine 進行 GC 的效率與結果,不得不慎呀…
2 月 22 2014
[Apache Tomcat] Enhance security
我沒有在使用 Apache Tomcat 的後台,佈署軟體/程式都是透過 scp/sftp/ftp 等方式做傳輸。
所以在解開 Apache Tomcat 的壓縮檔之後,我會執行以下指令,把不必要的檔案清掉,增強安全性:
cd apache-tomcat-* && \ /bin/rm -rf webapps/docs webapps/examples webapps/host-manager webapps/manager && \ /bin/rm -f webapps/ROOT/*.gif webapps/ROOT/*.xml webapps/ROOT/*.ico webapps/ROOT/*.txt webapps/ROOT/*.svg && \ /bin/cat /dev/null > webapps/ROOT/index.jsp && /bin/cat /dev/null > webapps/ROOT/index.html
2 月 14 2014
[實測] Plextor M5M 256GB mSATA SSD (PX-256M5M) on Lenovo T420s
前幾天幫我在家用的 Lenovo T420s 裝上新的 mSATA SSD,用 AS SSD Benchmark 跑了些數據,貼在這裡做個紀錄。
受限於 T420s 的介面速度,Plextor M5M 256GB mSATA SSD 的效能沒有完全發揮。
對照組,T420s 原廠給的 7mm 2.5″ 7200rpm HDD。
雖然 SSD 的效能沒有完全發揮,用來當系統碟的爽度依然很高啊…
8 月 25 2015
調整 Apache HTTPD & Apache Tomcat & nginx 的 content cache & compression
前陣子調整了一些 Apache HTTPD & Tomcat & nginx 的 cache 機制與內容壓縮機制,稍微紀錄一下。
Apache HTTPD 的 cache:
Apache HTTPD 的壓縮:
Apache Tomcat 的 cache(在 application 的 web.xml 做調整):
Apache Tomcat 的壓縮(在 conf/server.xml 做調整):
nginx 的 cache(在 server tag 內做調整):
nginx 的壓縮(在 http tag 內做調整):
大概就調這些,其他多媒體檔案就看需求了…
By Joe Horn • WWW 0 • Tags: Apache HTTPD, Apache Tomcat, cache, compression, deflate, gzip, nginx