[MySQL] 必要修正一些預設值 (performance tunning)

參考了一篇:『Fixing Poor MySQL Default Configuration Values』,裡面提到了四個 MySQL 預設值相當沒有意義,所以 Jeremy Zawodny 提出了修改,也解釋了為什麼這四個會降低 MySQL 的效能。 1. max_connect_errors: 當使用者連接 MySQL 出現錯誤,伺服器就會根據 connect_timeout 所設定時間之後,而放棄等待,放棄之後會有 counter 來紀錄連接失敗的次數,當達到 max_connect_errors 設定值,伺服器就會 locked out client 端,這會衍生一個問題,那就是可以惡搞同一台網站,把 MySQL 搞爛,造成封鎖,不過解決方法就是把 max_connect_errors 設定成 (max_connect_errors=1844674407370954751) 2. connect_timeout: 這跟上面 max_connect_errors 是有相當大的關係,MySQL 預設 connect_timeout 是五秒,可是在網路繁忙的時候,也許需要花費比較多的時間來做連接, 但是預設值是五秒的話,這樣會一直 time out,造成 counter 持續增加,屆時會超過 max_connect_errors 設定值,所以必須把 connect_timeout 設定提高到 15 or 20,這樣就可以了 (connect_timeout = 20) 3. skip-name-resolve: 在每次的 MySQL 連線,伺服器端會偵測 Client 的 DNS 反解,這步驟真的有點多餘 綜合上面結論,請加入 my.cnf 一些設定

max_connect_errors = 1844674407370954751
connect_timeout = 20
skip-name-resolve
slave_net_timeout = 30
Reference:

無論如何都應該修改的 MySQL 預設值 線上環境的 MySQL 預設值修改(Jeremy 建議)

[FreeBSD] port committer 快速建立 pkg-plist

FreeBSD 系統裡,最常使用就是管理安裝 ports,之前寫過一篇如何 commit update ports :『[FreeBSD] send-pr porter committer 需要注意事項』,根據 FreeBSD Porter’s Handbook 裡頭,寫到 pkg-plist 檔案內容是根據 ports 所產生的檔案列表,可以參考 Automated package list creation 這篇來快速產生,而我自己把該篇寫成 shell script 來直接產生,再來利用 diff 的方式來看看有無需要修改或者是增加,底下就是 shell script 內容:

#!/usr/local/bin/bash
###############################################
#
# Date:	    2009.11.18
# Author:   appleboy ( appleboy.tw AT gmail.com)
# Web:	    http://blog.wu-boy.com
# Ref:	    http://www.freebsd.org/doc/en/books/porters-handbook/plist-autoplist.html
#
###############################################

PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin
export PATH

if [ "$#" -lt "2" ]; then
    echo "please give two argument"
    echo "example $0 /tmp/dir1 /tmp/dir2"
    exit
fi

#
# configure system parameters

HOME=$1
TARGET=$2
TMPDIR="/var/tmp"

#
# configure end

if [ ! -d "$HOME" ]; then
    echo "${HOME} is not directory"
    exit
fi

if [ "$TARGET" != "" ] && [ ! -d "$TARGET" ]; then
    echo "$TARGET will be created"
    mkdir -p $TARGET
fi

#
# clean ports file

cd $HOME && make clean

#
# get port name 

PORTNAME=$(make -V PORTNAME)

#
# Before create port directory, please delete it.
# Next, create a temporary directory tree into which your port can be installed, and install any dependencies.
rm -rf ${TMPDIR}/${PORTNAME}
if [ ! -d "${TMPDIR}/${PORTNAME}" ]; then
    echo "${TMPDIR}/${PORTNAME} will be created"
    mkdir -p ${TMPDIR}/${PORTNAME}
fi

mtree -U -f $(make -V MTREE_FILE) -d -e -p ${TMPDIR}/${PORTNAME}
make depends PREFIX=${TMPDIR}/$PORTNAME

#
# Store the directory structure in a new file.

cd ${TMPDIR}/${PORTNAME} && find -d * -type d | sort > ${TARGET}/OLD-DIRS

#
# If your port honors PREFIX (which it should) you can then install the port and create the package list.

cd $HOME && make install PREFIX=${TMPDIR}/${PORTNAME}
cd ${TMPDIR}/${PORTNAME} && find -d * \! -type d | sort > ${TARGET}/pkg-plist

#
# You must also add any newly created directories to the packing list.

cd ${TMPDIR}/${PORTNAME} && find -d * -type d | sort | comm -13 ${TARGET}/OLD-DIRS - | sort -r | sed -e 's#^#@dirrm #' >> ${TARGET}/pkg-plist

echo "Please check  ${TARGET}/pkg-plist file"
用法大概是: ./create_pkg.sh /root/phpbb3 /root/test /root/phpbb3 是你修改 ports 的資料夾 /root/test 是 pkg-plist 新的資料夾

[Gmail] offline Gmail 根據 Labels 自訂選擇下載郵件備份

Gmail Lab 裡面講到這篇:『Choose which messages get downloaded for offline use』,內容是說之前 Gmail 開發出來可以離線瀏覽 Email 信件的 Offline Gmail 功能,不管你在任何地方您都可以任意去瀏覽之前收過的 mail 郵件,我想這功能相當方便,但是如果您的信件如果很多,有些不想同步到自己私人電腦,是不是覺得有些不方便,而想根據 Gmail 設定的 Label 來同步郵件呢,所以 Gmail 幫您考慮到的此點,也針對 Offline 做了設定改善。首先你必須先啟動 Offline Gmail 的功能,接下來在 Settings 的 Offline tab 裡面進行設定您想要下載同步的 Labels 郵件,畫面大致上如下,我想非常容易設定。 Settings - appleboy.tw@gmail.com - Gmail_1258426240802 (by appleboy46)

[Linux] VirtuBox ssh 遠端控制,Windows 資料夾分享 [On Ubuntu]

vbox_logo2_gradient (by appleboy46)

VirtualBox 是一套可以模擬虛擬作業系統的軟體,目前 Release 到 3.0.10 版本,可以去官網查看 Changelog,它可以 run 在各種不同的作業系統,例如:Windows, Linux, Macintosh and OpenSolaris etc. 可以看 guest operating systems,每次只要新的 OS Release 出來,就要先用 VirtualBox 模擬一下,還有如果需要 IE6,也是需要另一套 Windows XP,在教學方面也是相當方便的,底下紀錄一下如何 pietty 去連接 VirtuBox 裡面的 Ubuntu Server。

[Read More]

[SQL] Microsoft SQL Server 2008 Management Studio 防止儲存需要資料表重建的變更

最近要寫 ASP.Net 專案,弄 MSSQL Server 2008 當作 Database,利用 SQL 2008 SQL Server Management Studio 管理資料庫,有點類似 MySQL Navicat Lite 軟體,或者是 Web 介面的 phpMyAdmin,在資料表填入欄位新增第一次之後,接下來要去修改資料表,發現會出現錯誤訊息:『防止儲存需要資料表重建的變更MSSQL2008_01 (by appleboy46) 解決方法其實很簡單:工具->選項->左邊選單 Designers,裡面把**防止儲存需要資料表重建的變更**,取消掉,就可以了 MSSQL2008_02 (by appleboy46) 參考資料:[SQL]使用SQL 2008 SQL Server Management Studio 更改資料表結構 出現錯誤訊息不允許儲存變更

[網站] 好站連結 (六)

C#

[Perl&PHP] time() and Class::Date 日期轉換運算

為了看個 MLB 美國職棒,寫了一個網站:美國職棒影片收集站,裡面的內容影片連結,以及連結說明,都是利用 Perl 搭配 MySQL 資料庫,以及 CodeIgniter PHP Framework 寫出來的,美國 MLB 開打時間,會比台灣晚一天的時差,所以在 PHP 跟 Perl 都要針對時間作修改以及轉換運算,那底下會寫 PHP 跟 Perl 如何控制時間,還有資料庫如何設計,會比較適當。

PHP 日期轉換 MySQL 在資料庫時間格式方面,最主要常見的兩種儲存方式,一種就是 MySQL 預設 datetime,顯示的格式就會像是

2009-11-03 20:10:43,另一種就是存成 UNIX time 格式,可以設定為 int(11),這兩種其實都可以使用,在 phpBB2 是採用後者的方式,因為 open source 要支援多種資料庫,但是又要統一程式碼,所以乾脆用 UNIX 的時間標記,這樣比較好轉換時區,如果使用 UNIX 格式,可以利用 time() 函式來取的。

[Read More]

[高雄美食] 高雄-TON 卡茲日歐風尚食堂

DSC03303

mobile01 發現【Catanna食記】高雄-TON 卡茲日歐風尚食堂 這篇文章,之前答應宗翰要請他吃一次飯,原因是我找到了第一份工作,所以凹了我一頓飯,這次也拖了很久,從我畢業到現在都半年超過了,才一起出來吃飯,宗翰也寫了一篇食記:[Food]TON 卡茲日歐風尚食堂 - 高雄,先不多說,來介紹一下美食吧,我跟宗翰還有他高中同學總共一起吃了 693 元(炸豆腐 炸野菇 藍帶雙起士豬排 雙人海陸稱霸餐),吃到我們快撐死了,其實點餐點就會附上白飯跟高麗蔡絲,很大一盤,請看底下的圖:

DSC03289

DSC03290

[Read More]

[CodeIgniter] 解決 CI 下載函數 force_download 在 IE 底下檔案標題亂碼

CodeIgniter CodeIgniter 底下提供了 force_download 函數,讓使用者可以直接下載檔案,但是會遇到中文的問題,IE 底下開起來檔名會是亂碼,force_download(‘filename’, ‘data’) 如果 filename 使用中文,測試 FireFoxChrome 都是沒問題的,唯獨 IE 開起來就是有問題,所以麻煩請修改 helpers/download_helper.php 這隻程式。

if ( ! function_exists('force_download'))
{
	function force_download($filename = '', $data = '')
	{
		if ($filename == '' OR $data == '')
		{
			return FALSE;
		}

		// Try to determine if the filename includes a file extension.
		// We need it in order to set the MIME type
		if (FALSE === strpos($filename, '.'))
		{
			return FALSE;
		}
	
		// Grab the file extension
		$x = explode('.', $filename);
		$extension = end($x);

		// Load the mime types
		@include(APPPATH.'config/mimes'.EXT);
	
		// Set a default mime if we can't find it
		if ( ! isset($mimes[$extension]))
		{
			$mime = 'application/octet-stream';
		}
		else
		{
			$mime = (is_array($mimes[$extension])) ? $mimes[$extension][0] : $mimes[$extension];
		}
	
		// Generate the server headers
		if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE"))
		{
			header('Content-Type: "'.$mime.'"');
			header('Content-Disposition: attachment; filename="'.iconv('utf-8', 'big5', $filename).'"');
			header('Expires: 0');
			header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
			header("Content-Transfer-Encoding: binary");
			header('Pragma: public');
			header("Content-Length: ".strlen($data));
		}
		else
		{
			header('Content-Type: "'.$mime.'"');
			header('Content-Disposition: attachment; filename="'.$filename.'"');
			header("Content-Transfer-Encoding: binary");
			header('Expires: 0');
			header('Pragma: no-cache');
			header("Content-Length: ".strlen($data));
		}
	
		exit($data);
	}
}
裡面利用了 iconv 把 utf-8 編碼,改成 big5,這樣在 IE 底下就不會出現問題了
header('Content-Disposition: attachment; filename="'.iconv('utf-8', 'big5', $filename).'"');

WordPress 2.8.5 Hardening Release

wordpress logo WordPress 在10月20號發出安全性的更新,大家快把 2.8.4 升級到 2.8.5,可以參考 WordPress 2.8.5: Hardening Release,這次更新最主要是在安全性的議題,Wordpress 團隊在過去幾個月已經開始針對 2.9 進行新功能上的開發,但是在 2.8 branch 的版本如果有安全性的漏洞,官方網站還是會提出修正的,以增加網站的安全。 底下是一些 Release 的安全性改良:

  • A fix for the Trackback Denial-of-Service attack that is currently being seen.
  • Removal of areas within the code where php code in variables was evaluated.
  • Switched the file upload functionality to be whitelisted for all users including Admins.
  • Retiring of the two importers of Tag data from old plugins 假如您的網站最近有受到攻擊,那可以利用官網提供的弱點掃描工具 WordPress Exploit Scanner 來針對網站檔案以及資料庫內容文章,還有 comment 的資料表,以及所裝的 plugin 檔案進行漏洞檢查。 升級方式很容易,可以參考之前寫的 [wordpress] 快速升級 Upgrade 2.5.0 -> 2.5.1 for Linux & FreeBSD ps. FreeBSD commit 到 ports 裡面了,參考:ports/139812