<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>船長日誌 &#187; 站長文檔</title>
	<atom:link href="http://www.cslog.cn/category/%e7%ab%99%e9%95%bf%e6%96%87%e6%a1%a3/feed/zh-hant/" rel="self" type="application/rss+xml" />
	<link>http://www.cslog.cn</link>
	<description>最讓我激動的是不知道下一個星球上能發現什麼...</description>
	<lastBuildDate>Wed, 30 Jul 2025 16:06:05 +0000</lastBuildDate>
	<language>zh-CN</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.1</generator>
		<item>
		<title>百度使用移動轉碼功能盜竊網站內容，並加上自己的廣告</title>
		<link>http://www.cslog.cn/Content/%e7%99%be%e5%ba%a6%e4%bd%bf%e7%94%a8%e7%a7%bb%e5%8a%a8%e8%bd%ac%e7%a0%81%e5%8a%9f%e8%83%bd%e7%9b%97%e7%aa%83%e7%bd%91%e7%ab%99%e5%86%85%e5%ae%b9%ef%bc%8c%e5%b9%b6%e5%8a%a0%e4%b8%8a%e8%87%aa%e5%b7%b1/zh-hant/</link>
		<comments>http://www.cslog.cn/Content/%e7%99%be%e5%ba%a6%e4%bd%bf%e7%94%a8%e7%a7%bb%e5%8a%a8%e8%bd%ac%e7%a0%81%e5%8a%9f%e8%83%bd%e7%9b%97%e7%aa%83%e7%bd%91%e7%ab%99%e5%86%85%e5%ae%b9%ef%bc%8c%e5%b9%b6%e5%8a%a0%e4%b8%8a%e8%87%aa%e5%b7%b1/zh-hant/#comments</comments>
		<pubDate>Wed, 25 Mar 2015 16:49:48 +0000</pubDate>
		<dc:creator>船長</dc:creator>
				<category><![CDATA[站長文檔]]></category>
		<category><![CDATA[百度]]></category>
		<category><![CDATA[站長]]></category>

		<guid isPermaLink="false">http://www.cslog.cn/?p=1265</guid>
		<description><![CDATA[百度又無恥了。我意外地在手機用百度搜索自己的網站，點擊後打開，發現原來網站上的廣 &#8230; <a href="http://www.cslog.cn/Content/%e7%99%be%e5%ba%a6%e4%bd%bf%e7%94%a8%e7%a7%bb%e5%8a%a8%e8%bd%ac%e7%a0%81%e5%8a%9f%e8%83%bd%e7%9b%97%e7%aa%83%e7%bd%91%e7%ab%99%e5%86%85%e5%ae%b9%ef%bc%8c%e5%b9%b6%e5%8a%a0%e4%b8%8a%e8%87%aa%e5%b7%b1/zh-hant/">繼續閱讀 <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>百度又無恥了。我意外地在手機用百度搜索自己的網站，點擊後打開，發現原來網站上的廣告沒有了，被換上了百度自己的廣告！</p>
<p>百度竟然把這個無恥的行為包裝成一種功能，叫<a href="http://m.baidu.com/pub/help.php?pn=22&#038;ssid=0&#038;from=844b&#038;bd_page_type=1&#038;uid=&#038;pu=usm@5,sz@1330_220,ta@big_3_7.5_4_9.0" target="_blank">百度轉碼</a>！ </p>
<p>百度沒有通知和詢問我們這些站長的同意，將我們網站內容盜竊，讓用戶以為是百度的內容，放上廣告。讓無數的網站成為受害者：<br />
<a href="http://www.im286.com/thread-14306138-1-1.html" target="_blank">http://www.im286.com/thread-14306138-1-1.html</a><br />
<a href="http://zhidao.baidu.com/link?url=5QXqTR-9_bT2jUbhF_RPNuQzJjGooabLinH2fXTd5fylCz_5EJWf1NcDVoon2zie1hziTT-qvUHijRBmJUkL5_" target="_blank">http://zhidao.baidu.com/link?url=5QXqTR-9_bT2jUbhF_RPNuQzJjGooabLinH2fXTd5fylCz_5EJWf1NcDVoon2zie1hziTT-qvUHijRBmJUkL5_</a><br />
<a href="http://tieba.baidu.com/p/3059153091" target="_blank">http://tieba.baidu.com/p/3059153091</a><br />
<a href="http://bbs.zhanzhang.baidu.com/thread-13671-1-1.html" target="_blank">http://bbs.zhanzhang.baidu.com/thread-13671-1-1.html</a></p>
<p>我已經按照百度的說明，在服務器nginx的輸出的header上加上了Cache-control為no-siteapp。據說需要一周才能生效。希望能早日有效地擺脫百度的掠奪。</p>
<p>代碼：<br />
<code>add_header    Cache-Control  no-siteapp;</code>
<div style="margin-top: 15px; font-style: italic">
<p>轉載請註明: 轉自<a href="http://www.cslog.cn/">船長日誌</a>, 本文鏈接地址: <a href="http://www.cslog.cn/Content/%e7%99%be%e5%ba%a6%e4%bd%bf%e7%94%a8%e7%a7%bb%e5%8a%a8%e8%bd%ac%e7%a0%81%e5%8a%9f%e8%83%bd%e7%9b%97%e7%aa%83%e7%bd%91%e7%ab%99%e5%86%85%e5%ae%b9%ef%bc%8c%e5%b9%b6%e5%8a%a0%e4%b8%8a%e8%87%aa%e5%b7%b1/zh-hant/">http://www.cslog.cn/Content/%e7%99%be%e5%ba%a6%e4%bd%bf%e7%94%a8%e7%a7%bb%e5%8a%a8%e8%bd%ac%e7%a0%81%e5%8a%9f%e8%83%bd%e7%9b%97%e7%aa%83%e7%bd%91%e7%ab%99%e5%86%85%e5%ae%b9%ef%bc%8c%e5%b9%b6%e5%8a%a0%e4%b8%8a%e8%87%aa%e5%b7%b1/zh-hant/</a></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.cslog.cn/Content/%e7%99%be%e5%ba%a6%e4%bd%bf%e7%94%a8%e7%a7%bb%e5%8a%a8%e8%bd%ac%e7%a0%81%e5%8a%9f%e8%83%bd%e7%9b%97%e7%aa%83%e7%bd%91%e7%ab%99%e5%86%85%e5%ae%b9%ef%bc%8c%e5%b9%b6%e5%8a%a0%e4%b8%8a%e8%87%aa%e5%b7%b1/feed/zh-hant/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>推薦一個不錯的nginx教程</title>
		<link>http://www.cslog.cn/Content/%e6%8e%a8%e8%8d%90%e4%b8%80%e4%b8%aa%e4%b8%8d%e9%94%99%e7%9a%84nginx%e6%95%99%e7%a8%8b/zh-hant/</link>
		<comments>http://www.cslog.cn/Content/%e6%8e%a8%e8%8d%90%e4%b8%80%e4%b8%aa%e4%b8%8d%e9%94%99%e7%9a%84nginx%e6%95%99%e7%a8%8b/zh-hant/#comments</comments>
		<pubDate>Fri, 02 Aug 2013 15:31:36 +0000</pubDate>
		<dc:creator>船長</dc:creator>
				<category><![CDATA[站長文檔]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[教程]]></category>
		<category><![CDATA[服務器]]></category>

		<guid isPermaLink="false">http://www.cslog.cn/?p=1186</guid>
		<description><![CDATA[推薦一個不錯的nginx服務器軟件教程： http://openresty.or &#8230; <a href="http://www.cslog.cn/Content/%e6%8e%a8%e8%8d%90%e4%b8%80%e4%b8%aa%e4%b8%8d%e9%94%99%e7%9a%84nginx%e6%95%99%e7%a8%8b/zh-hant/">繼續閱讀 <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>推薦一個不錯的nginx服務器軟件教程： <a href="http://openresty.org/download/agentzh-nginx-tutorials-zhcn.html">http://openresty.org/download/agentzh-nginx-tutorials-zhcn.html</a></p>
<p>這個nginx教程很有點特別。作者製作了一個獨特的軟件包（openresty），將nginx和一些第三方modules合在一起，產生一個獨立的網頁程序平台。。。 所以這個nginx教程讀起來會更新是一個腳本語言教程。不過這倒提供了一個很特別的切入nginx配置語法的視角。作者深入淺出，語言簡明，而且很多例子代碼。總之是非常難得的教程。可惜的是教程應該還在寫作過程中，還不完整。期待早日有完整版本現世。
<div style="margin-top: 15px; font-style: italic">
<p>轉載請註明: 轉自<a href="http://www.cslog.cn/">船長日誌</a>, 本文鏈接地址: <a href="http://www.cslog.cn/Content/%e6%8e%a8%e8%8d%90%e4%b8%80%e4%b8%aa%e4%b8%8d%e9%94%99%e7%9a%84nginx%e6%95%99%e7%a8%8b/zh-hant/">http://www.cslog.cn/Content/%e6%8e%a8%e8%8d%90%e4%b8%80%e4%b8%aa%e4%b8%8d%e9%94%99%e7%9a%84nginx%e6%95%99%e7%a8%8b/zh-hant/</a></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.cslog.cn/Content/%e6%8e%a8%e8%8d%90%e4%b8%80%e4%b8%aa%e4%b8%8d%e9%94%99%e7%9a%84nginx%e6%95%99%e7%a8%8b/feed/zh-hant/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>linode上各個VPS的流量限制是共享的</title>
		<link>http://www.cslog.cn/Content/linode%e4%b8%8a%e5%90%84%e4%b8%aavps%e7%9a%84%e6%b5%81%e9%87%8f%e9%99%90%e5%88%b6%e6%98%af%e5%85%b1%e4%ba%ab%e7%9a%84/zh-hant/</link>
		<comments>http://www.cslog.cn/Content/linode%e4%b8%8a%e5%90%84%e4%b8%aavps%e7%9a%84%e6%b5%81%e9%87%8f%e9%99%90%e5%88%b6%e6%98%af%e5%85%b1%e4%ba%ab%e7%9a%84/zh-hant/#comments</comments>
		<pubDate>Mon, 04 Mar 2013 10:15:45 +0000</pubDate>
		<dc:creator>船長</dc:creator>
				<category><![CDATA[站長文檔]]></category>
		<category><![CDATA[linode]]></category>
		<category><![CDATA[vps]]></category>
		<category><![CDATA[服務器]]></category>
		<category><![CDATA[站長]]></category>
		<category><![CDATA[網站空間]]></category>

		<guid isPermaLink="false">http://www.cslog.cn/?p=1141</guid>
		<description><![CDATA[更新：就在這兩天，Linode上的流量限制提高到了原來的10倍。看來大多數站長不 &#8230; <a href="http://www.cslog.cn/Content/linode%e4%b8%8a%e5%90%84%e4%b8%aavps%e7%9a%84%e6%b5%81%e9%87%8f%e9%99%90%e5%88%b6%e6%98%af%e5%85%b1%e4%ba%ab%e7%9a%84/zh-hant/">繼續閱讀 <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><strong>更新：就在這兩天，Linode上的流量限制提高到了原來的10倍。看來大多數站長不用再關注Linode的流量限制問題了。</strong></p>
<p><a href="http://www.linode.com/?r=c59c1d797e6bb4212471c1b7418e8f2d2dab45b6">Linode</a>是目前為止我感覺最好用的網站空間提供商。2年多的使用體驗讓我很滿意。但到今天才知道原來Linode上各個vps的流量是共享的。也就是說如果有2個Linode 512，流量是200GB/月x2,共400GB。如果其中一個VPS做mysql數據服務器，另一個做頁面前端服務器，那個數據服務器有可能產生接近0的流量（Linode之間的內網流量不計在流量限額之內），而另一個vps就可以使用掉餘下的所有400GB流量，而不是說明中的200GB。</p>
<p>以下是所有我所知的關於Linode流量限制相關的信息：<br />
1.Linode上的VPS有流量限制， 512的是200GB, 1G的是400GB，隨價格的上升線性增加。<br />
2.多個Linode之間的VPS內部傳輸流量不計入流量限制計算。<br />
3.上傳到Linode的流量不計入流量限制計算，只計算從Linode下載的數據流量。<br />
4.所有Linode之間的流量是加在一起共享的。如上文所詳述。<br />
5.如果你網站的流量超出限額，會在次月初被加收額外的費用。收費標準是0.1美元每GB。（這個價格同Additional Transfer 100GB 10美元一個月的標準是相當的。）<br />
6.你可以在Extras中添加如上的Additional Transfer，這個是按天收費的。比如你選100GB 10美元一個月的選項，如果當月只有3天了，你只會被收1美元，同時你得到的額外流量也只有10GB。如果你在使用不到一個月前取消這個功能，Linode.com也會退回餘下天數的錢，並收回餘下天數的額外流量。個人感覺不用使用這個功能，原因參看上條。</p>
<div style="margin-top: 15px; font-style: italic">
<p>轉載請註明: 轉自<a href="http://www.cslog.cn/">船長日誌</a>, 本文鏈接地址: <a href="http://www.cslog.cn/Content/linode%e4%b8%8a%e5%90%84%e4%b8%aavps%e7%9a%84%e6%b5%81%e9%87%8f%e9%99%90%e5%88%b6%e6%98%af%e5%85%b1%e4%ba%ab%e7%9a%84/zh-hant/">http://www.cslog.cn/Content/linode%e4%b8%8a%e5%90%84%e4%b8%aavps%e7%9a%84%e6%b5%81%e9%87%8f%e9%99%90%e5%88%b6%e6%98%af%e5%85%b1%e4%ba%ab%e7%9a%84/zh-hant/</a></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.cslog.cn/Content/linode%e4%b8%8a%e5%90%84%e4%b8%aavps%e7%9a%84%e6%b5%81%e9%87%8f%e9%99%90%e5%88%b6%e6%98%af%e5%85%b1%e4%ba%ab%e7%9a%84/feed/zh-hant/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>再談Nginx Rewrite， 中文URL和其它</title>
		<link>http://www.cslog.cn/Content/nginx-rewrite-chinese/zh-hant/</link>
		<comments>http://www.cslog.cn/Content/nginx-rewrite-chinese/zh-hant/#comments</comments>
		<pubDate>Fri, 29 Jun 2012 15:36:17 +0000</pubDate>
		<dc:creator>船長</dc:creator>
				<category><![CDATA[信息處理]]></category>
		<category><![CDATA[站長文檔]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[nginx中文url重寫]]></category>
		<category><![CDATA[nginx的utf8支持]]></category>
		<category><![CDATA[nginx重寫]]></category>
		<category><![CDATA[pcre]]></category>
		<category><![CDATA[rewrite]]></category>
		<category><![CDATA[unicode]]></category>
		<category><![CDATA[url]]></category>
		<category><![CDATA[url重寫]]></category>
		<category><![CDATA[utf8]]></category>
		<category><![CDATA[中文]]></category>
		<category><![CDATA[中文url]]></category>
		<category><![CDATA[服務器]]></category>
		<category><![CDATA[漢字編碼]]></category>

		<guid isPermaLink="false">http://www.cslog.cn/?p=1058</guid>
		<description><![CDATA[上次談到過Nginx和中文URL的問題，這幾天又加深了認識。 多分享幾個關於Ng &#8230; <a href="http://www.cslog.cn/Content/nginx-rewrite-chinese/zh-hant/">繼續閱讀 <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>上次談到過<a href="http://www.cslog.cn/Content/nginx-pcre-utf8-rewrite/">Nginx和中文URL的問題</a>，這幾天又加深了認識。 多分享幾個關於Nginx Rewrite的經驗。</p>
<p>Nginx匹配指定中文URL的方法：<br />
<code><br />
rewrite "(*UTF8)^\x{66f4}\x{6539}$" /index.html last;<br />
</code><br />
這個會將 http://www.cslog.cn/%E6%9B%B4%E6%94%B9 重定向到http://www.cslog.cn/index.html。<br />
&#8216;/%E6%9B%B4%E6%94%B9&#8242;是中文URL ‘/更改’， \x{66f4}\x{6539}是這兩個漢字的Unicode編碼。</p>
<p>注意配合PCRE 7.9以上版本使用，詳細看<a href="http://www.cslog.cn/Content/nginx-pcre-utf8-rewrite/">Nginx和中文URL的問題</a>。<br />
<span id="more-1058"></span><br />
Nginx匹配URL中中文參數的方法：<br />
如果要將 http://www.cslog.cn/index.php?title=%E6%9B%B4%E6%94%B9 重定向到http://www.cslog.cn, 則要使用<br />
<code><br />
location = /index\.php$ {<br />
if ($args_title =%E6%9B%B4%E6%94%B9 ) {<br />
rewrite ^ /;<br />
}<br />
}<br />
</code><br />
在這裡， &#8216;?title=%E6%9B%B4%E6%94%B9&#8242; 是不能用上例那裡的rewrite捕捉到的， 而要使用$arg_參數名這樣的方式處理。 而且在這裡， &#8216;%E6%9B%B4%E6%94%B9&#8242;是不用特別轉換的，直接放上去就可以了。</p>
<p>還要注意到 location後面的 ~, *~, ^~, =或空是有不同的效果的。詳細參看<a href="http://nginx.org/en/docs/http/ngx_http_core_module.html#location">nginx的官方手冊</a>。</p>
<p>讓Nginx在同時識別到兩個參數的情況下重定向的方法<br />
假設要在例如 http://www.cslog.cn/index.php?title=%E6%9B%B4%E6%94%B9&amp;lang=Zh-tw 這樣的URL，只有在lang=Zh-tw參數存在，並且title參數也存在（不管它的值）的情況下才重定向， 要求會苛刻些，因為nginx自身沒有並列的邏輯處理能力，但可以使用如下的方法曲線解決：<br />
<code><br />
location = /index\.php {<br />
set $redirect "";</code></p>
<p><code># 檢查是否存在"title"參數:<br />
if ( $arg_title ) {<br />
set $redirect "Y";<br />
}</p>
<p># 檢查lang參數是否為 "Zh-tw":<br />
if ( $arg_lang =Zh-tw ) {<br />
set $redirect "${redirect}ES";<br />
}</p>
<p># 看看條件是否同時成立 "YES":<br />
if ( $redirect = YES ) {<br />
rewrite ^ / last;<br />
}</p>
<p></code></p>
<p><code> ....<br />
}<br />
</code>
<div style="margin-top: 15px; font-style: italic">
<p>轉載請註明: 轉自<a href="http://www.cslog.cn/">船長日誌</a>, 本文鏈接地址: <a href="http://www.cslog.cn/Content/nginx-rewrite-chinese/zh-hant/">http://www.cslog.cn/Content/nginx-rewrite-chinese/zh-hant/</a></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.cslog.cn/Content/nginx-rewrite-chinese/feed/zh-hant/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Nginx、PCRE和中文URL（UTF8編碼）rewrite路徑重寫匹配問題</title>
		<link>http://www.cslog.cn/Content/nginx-pcre-utf8-rewrite/zh-hant/</link>
		<comments>http://www.cslog.cn/Content/nginx-pcre-utf8-rewrite/zh-hant/#comments</comments>
		<pubDate>Tue, 01 Nov 2011 15:08:45 +0000</pubDate>
		<dc:creator>船長</dc:creator>
				<category><![CDATA[信息處理]]></category>
		<category><![CDATA[站長文檔]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[nginx中文url重寫]]></category>
		<category><![CDATA[nginx的utf8支持]]></category>
		<category><![CDATA[pcre]]></category>
		<category><![CDATA[PCRE的UTF8編碼支持]]></category>
		<category><![CDATA[rewrite]]></category>
		<category><![CDATA[url]]></category>
		<category><![CDATA[url重寫]]></category>
		<category><![CDATA[utf8]]></category>
		<category><![CDATA[中文]]></category>
		<category><![CDATA[中文url]]></category>
		<category><![CDATA[服務器]]></category>
		<category><![CDATA[漢字編碼]]></category>

		<guid isPermaLink="false">http://www.cslog.cn/?p=793</guid>
		<description><![CDATA[最近遇到了使用Nginx 重寫中文UTF8編碼路徑的問題。 才發現默認情況下Ng &#8230; <a href="http://www.cslog.cn/Content/nginx-pcre-utf8-rewrite/zh-hant/">繼續閱讀 <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>最近遇到了使用<a href="http://www.cslog.cn/tag/nginx/">Nginx</a> 重寫中文UTF8編碼路徑的問題。 才發現默認情況下Nginx的rewrite是不支持UTF8匹配的。 比如：</p>
<p><code>rewrite ^/(..)$ /2個字符文章.html break; #用2個點</code><br />
可以匹配到 /ab 或 /51, 但 /漢字 是匹配不到的。 我測試了一下， 要匹配兩個字的 /漢字 路徑， 得用</p>
<p><code>rewrite ^/(……)$ /2個漢字文章.html break; #要用六個點</code></p>
<p>如果要讓 ^/(..)$ 匹配到2個漢字字符，得開啟Nginx對UTF8字符的正則支持， 準確點說是開啟Nginx使用的PCRE庫的對UTF8字符的支持。因為Nginx的rewrite模塊是調用PCRE來處理正則的。 如果PCRE沒有問題，Nginx支持UTF8編碼的重寫樣式是：</p>
<p><code>rewrite "(*UTF8)^/(..)$" /2個字符文章.html break;<br />
#注意(*UTF8)前綴和引號的加入。</code></p>
<p><span id="more-793"></span>因為PCRE只有7.9以上的版本才支持這個(*UTF8)開頭，所以系統上的PCRE一定要使用7.9以上的版本。 另外，編譯PCRE時一定要開啟UTF8的支持。 即使用(&#8211;enable-utf8)參數。 檢查系統的PCRE版本和是否支持UTF8編碼可以使用<br />
<code>pcretest -C</code><br />
命令。執行後會顯示如下的報告：</p>
<blockquote><p>PCRE version 8.13 2011-08-16<br />
Compiled with<br />
UTF-8 support<br />
Unicode properties support<br />
Newline sequence is LF<br />
\R matches all Unicode newlines<br />
Internal link size = 2<br />
POSIX malloc threshold = 10<br />
Default match limit = 10000000<br />
Default recursion depth limit = 10000000<br />
Match recursion uses stack</p></blockquote>
<p>顯示“UTF-8 support”就是支持UTF8編碼了。</p>
<p>如果Nginx調用的PCRE為7.9以下的版本，使用 rewrite &#8220;(*UTF8)^/(..)$&#8221; /2個字符文章.html break; 這種形式的重寫，在執行nginx -t檢查時會出現如下的錯誤提示：</p>
<blockquote><p>[emerg]: pcre_compile() failed: (*VERB) not recognized in &#8220;(*UTF8)^、……</p></blockquote>
<p>如果Nginx調用的是7.9以上版本的PCRE，但是PCRE安裝時沒打開UTF8的支持開關，則會出現如下的錯誤提示：</p>
<blockquote><p>nginx: [emerg] pcre_compile() failed: this version of PCRE is not compiled with PCRE_UTF8 support in &#8220;(*UTF8)^/&#8230;</p></blockquote>
<p>解決辦法是安裝最新版本的的PCRE，並打開UTF8支持，方法如下（以當前8.13版的PCRE為例）：<br />
<code>wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.13.tar.gz<br />
tar zxvf pcre-8.13.tar.gz<br />
cd pcre-8.13<br />
./configure --enable-utf8 --enable-unicode-properties<br />
make<br />
make install</code></p>
<p>然後重新編譯安裝Nginx。 Nginx默認會打開rewrite模塊，並會自動查找系統上已經安裝了的PCRE。 如果Nginx查找不到已經安裝在系統上的PCRE， 或者系統上有多個PCRE， nginx調用了不支持UTF8的、或低版本的PCRE時（我遇到了後一種情況，並花費了很長的時間解決這個問題，這也是我為什麼寫這篇總結文章在這裡給大家分享的原因。。。），可以在編譯安裝Nginx時指定PCRE源文件。例如：</p>
<p><code>wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.13.tar.gz<br />
tar zxvf pcre-8.13.tar.gz<br />
wget http://nginx.org/download/nginx-1.0.8.tar.gz<br />
tar zxvf nginx-1.0.8.tar.gz<br />
cd nginx-1.0.8<br />
./configure \<br />
--with-pcre=../pcre-8.13</code></p>
<p>注意，如果接着直接make &amp;&amp; make install的話， PCRE因為沒有啟用UTF8， nginx將不能支持UTF8重寫， 所以在這一種，我動了一點小手腳：打開./objs/Makefile 文件，找到以下段落：</p>
<p><code> ../pcre-8.13/Makefile:	objs/Makefile<br />
cd ../pcre-8.13 \<br />
&amp;&amp; if [ -f Makefile ]; then $(MAKE) distclean; fi \<br />
&amp;&amp; CC="$(CC)" CFLAGS="-O2 -fomit-frame-pointer -pipe " \<br />
./configure --disable-shared </code><br />
在&#8211;disable-shared後加上 &#8211;enable-utf8和 &#8211;enable-unicode-properties參數， 即變成：<br />
<code> ../pcre-8.13/Makefile:	objs/Makefile<br />
cd ../pcre-8.13 \<br />
&amp;&amp; if [ -f Makefile ]; then $(MAKE) distclean; fi \<br />
&amp;&amp; CC="$(CC)" CFLAGS="-O2 -fomit-frame-pointer -pipe " \<br />
./configure --disable-shared --enable-utf8 --enable-unicode-properties</code><br />
然後再make, make install。 最後關閉nginx並重啟nginx（這裡不能用nginx -s reload)。這樣nginx就支持中文UTF8編碼的url重寫了。
<div style="margin-top: 15px; font-style: italic">
<p>轉載請註明: 轉自<a href="http://www.cslog.cn/">船長日誌</a>, 本文鏈接地址: <a href="http://www.cslog.cn/Content/nginx-pcre-utf8-rewrite/zh-hant/">http://www.cslog.cn/Content/nginx-pcre-utf8-rewrite/zh-hant/</a></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.cslog.cn/Content/nginx-pcre-utf8-rewrite/feed/zh-hant/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>使用Unicorn替代Mongrel作為Ruby on Rails的服務器</title>
		<link>http://www.cslog.cn/Content/unicorn-for-ruby-on-rails/zh-hant/</link>
		<comments>http://www.cslog.cn/Content/unicorn-for-ruby-on-rails/zh-hant/#comments</comments>
		<pubDate>Thu, 21 Jul 2011 16:54:41 +0000</pubDate>
		<dc:creator>船長</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[站長文檔]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rubyonrails]]></category>
		<category><![CDATA[unicorn]]></category>
		<category><![CDATA[服務器]]></category>
		<category><![CDATA[網站開發]]></category>

		<guid isPermaLink="false">http://www.cslog.cn/?p=727</guid>
		<description><![CDATA[先前的開發的Ruby on Rails網站使用的服務程序是Mongrel + N &#8230; <a href="http://www.cslog.cn/Content/unicorn-for-ruby-on-rails/zh-hant/">繼續閱讀 <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>先前的開發的Ruby on Rails網站使用的服務程序是<a title="在ubuntu6.06上安裝apache2.2X + mysql + PHP + Ruby on Rails + Mongrel Cluster | 船長日誌" href="http://www.cslog.cn/Content/ubuntu606_mysql_apache2_ruby_rails_mongrel_cluster/">Mongrel + Nginx</a>， 現在用了Rails 3， 發現Mongrel對它有兼容問題， 所以要換一個。 雖然現在<a title="Overview — Phusion Passenger™ (a.k.a. mod_rails / mod_rack)" href="http://www.modrails.com/">Phusion Passenger</a>大行其道， 但使用前要重新編譯Nginx。 為了避免重新安裝nginx，我找到mongrel的替代品<a title="File: README [Unicorn: Rack HTTP server for fast clients and Unix]" href="http://unicorn.bogomips.org/">Unicorn</a>。 沒想到unicorn的設置非常方便。 我記錄在這裡供大家參考：</p>
<p>安裝unicorn:<br />
<code><br />
sudo gem install unicorn<br />
</code></p>
<p>創建網站配置文件(myproject是項目名稱):<br />
<code><span id="more-727"></span><br />
sudo mkdir /etc/unicorn<br />
cd /etc/unicorn/<br />
sudo nano /etc/unicorn/myproject.conf<br />
</code></p>
<p>內容如下：<br />
<code><br />
RAILS_ROOT=/www/myproject<br />
RAILS_ENV=production<br />
</code></p>
<p>在網站里再創建一個unicorn配置文件<br />
<code><br />
nano /www/myproject/config/unicorn.rb<br />
</code></p>
<p>內容如下：<br />
<code><br />
# Minimal sample configuration file for Unicorn (not Rack) when used<br />
# with daemonization (unicorn -D) started in your working directory.<br />
#<br />
# See http://unicorn.bogomips.org/Unicorn/Configurator.html for complete<br />
# documentation.<br />
# See also http://unicorn.bogomips.org/examples/unicorn.conf.rb for<br />
# a more verbose configuration using more features.</code></p>
<p><code> </code></p>
<p><code>app_path = "/www/myproject"</code></p>
<p><code> </code></p>
<p><code>listen 8080 # by default Unicorn listens on port 8080<br />
worker_processes 2 # this should be &gt;= nr_cpus<br />
pid "#{app_path}/tmp/pids/unicorn.pid"<br />
stderr_path "#{app_path}/log/unicorn.log"<br />
stdout_path "#{app_path}/log/unicorn.log"<br />
</code></p>
<p>設置unicorn啟動腳本：<br />
<code><br />
sudo nano /etc/init.d/unicorn_init<br />
</code><br />
腳本內容：<br />
<code><br />
#!/bin/sh<br />
#<br />
# init.d script for single or multiple unicorn installations. Expects at least one .conf<br />
# file in /etc/unicorn<br />
#<br />
# Modified by jay@gooby.org http://github.com/jaygooby<br />
# based on http://gist.github.com/308216 by http://github.com/mguterl<br />
#<br />
## A sample /etc/unicorn/my_app.conf<br />
##<br />
## RAILS_ENV=production<br />
## RAILS_ROOT=/var/apps/www/my_app/current<br />
#<br />
# This configures a unicorn master for your app at /var/apps/www/my_app/current running in<br />
# production mode. It will read config/unicorn.rb for further set up.<br />
#<br />
# You should ensure different ports or sockets are set in each config/unicorn.rb if<br />
# you are running more than one master concurrently.<br />
#<br />
# If you call this script without any config parameters, it will attempt to run the<br />
# init command for all your unicorn configurations listed in /etc/unicorn/*.conf<br />
#<br />
# /etc/init.d/unicorn start # starts all unicorns<br />
#<br />
# If you specify a particular config, it will only operate on that one<br />
#<br />
# /etc/init.d/unicorn start /etc/unicorn/my_app.conf</code></p>
<p><code> </code></p>
<p><code>set -e</code></p>
<p><code>sig () {<br />
test -s "$PID" &amp;&amp; kill -$1 `cat "$PID"`<br />
}</p>
<p>oldsig () {<br />
test -s "$OLD_PID" &amp;&amp; kill -$1 `cat "$OLD_PID"`<br />
}</p>
<p>cmd () {</p>
<p>case $1 in<br />
start)<br />
sig 0 &amp;&amp; echo &gt;&amp;2 "Already running" &amp;&amp; exit 0<br />
echo "Starting"<br />
$CMD<br />
;;<br />
stop)<br />
sig QUIT &amp;&amp; echo "Stopping" &amp;&amp; exit 0<br />
echo &gt;&amp;2 "Not running"<br />
;;<br />
force-stop)<br />
sig TERM &amp;&amp; echo "Forcing a stop" &amp;&amp; exit 0<br />
echo &gt;&amp;2 "Not running"<br />
;;<br />
restart|reload)<br />
sig USR2 &amp;&amp; sleep 5 &amp;&amp; oldsig QUIT &amp;&amp; echo "Killing old master" `cat $OLD_PID` &amp;&amp; exit 0<br />
echo &gt;&amp;2 "Couldn't reload, starting '$CMD' instead"<br />
$CMD<br />
;;<br />
upgrade)<br />
sig USR2 &amp;&amp; echo Upgraded &amp;&amp; exit 0<br />
echo &gt;&amp;2 "Couldn't upgrade, starting '$CMD' instead"<br />
$CMD<br />
;;<br />
rotate)<br />
sig USR1 &amp;&amp; echo rotated logs OK &amp;&amp; exit 0<br />
echo &gt;&amp;2 "Couldn't rotate logs" &amp;&amp; exit 1<br />
;;<br />
*)<br />
echo &gt;&amp;2 "Usage: $0 "<br />
exit 1<br />
;;<br />
esac<br />
}</p>
<p>setup () {</p>
<p>echo -n "$RAILS_ROOT: "<br />
cd $RAILS_ROOT || exit 1<br />
export PID=$RAILS_ROOT/tmp/pids/unicorn.pid<br />
export OLD_PID="$PID.oldbin"</p>
<p>CMD="/usr/bin/unicorn_rails -c config/unicorn.rb -E $RAILS_ENV -D"<br />
}</p>
<p>start_stop () {</p>
<p># either run the start/stop/reload/etc command for every config under /etc/unicorn<br />
# or just do it for a specific one</p>
<p># $1 contains the start/stop/etc command<br />
# $2 if it exists, should be the specific config we want to act on<br />
if [ $2 ]; then<br />
. $2<br />
setup<br />
cmd $1<br />
else<br />
for CONFIG in /etc/unicorn/*.conf; do<br />
# import the variables<br />
. $CONFIG<br />
setup</p>
<p># run the start/stop/etc command<br />
cmd $1<br />
done<br />
fi<br />
}</p>
<p></code></p>
<p><code>ARGS="$1 $2"<br />
start_stop $ARGS<br />
</code><br />
注意將裡面的/usr/bin/unicorn_rails 換成你系統中unicorn_rails程序的實際路徑。</p>
<p>設置unicorn_init文件屬性:<br />
<code><br />
sudo chmod 755 /etc/init.d/unicorn_init<br />
</code></p>
<p>啟動unicorn:<br />
<code><br />
/etc/init.d/unicorn_init<br />
</code></p>
<p>修改nginx的配置文件，加入unicorn的代理設置：<br />
<code><br />
upstream myproject_mongrel {<br />
server 127.0.0.1:8080 fail_timeout=0;<br />
}<br />
</code><br />
這部分跟使用mongrel的類似的。</p>
<p>這樣unicorn的設置就完成了。 剛設置好，感覺unicorn跟mongrel一樣， 都是比較吃內存的， 一啟動就佔了50M. 不知道會不會也像mongrel一樣把內存吃爆， 會得話得設置監控軟件（如god）看住它。
<div style="margin-top: 15px; font-style: italic">
<p>轉載請註明: 轉自<a href="http://www.cslog.cn/">船長日誌</a>, 本文鏈接地址: <a href="http://www.cslog.cn/Content/unicorn-for-ruby-on-rails/zh-hant/">http://www.cslog.cn/Content/unicorn-for-ruby-on-rails/zh-hant/</a></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.cslog.cn/Content/unicorn-for-ruby-on-rails/feed/zh-hant/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>原來深圳電信耍流氓已經很久了</title>
		<link>http://www.cslog.cn/Content/%e5%8e%9f%e6%9d%a5%e6%b7%b1%e5%9c%b3%e7%94%b5%e4%bf%a1%e8%80%8d%e6%b5%81%e6%b0%93%e5%b7%b2%e7%bb%8f%e5%be%88%e4%b9%85%e4%ba%86/zh-hant/</link>
		<comments>http://www.cslog.cn/Content/%e5%8e%9f%e6%9d%a5%e6%b7%b1%e5%9c%b3%e7%94%b5%e4%bf%a1%e8%80%8d%e6%b5%81%e6%b0%93%e5%b7%b2%e7%bb%8f%e5%be%88%e4%b9%85%e4%ba%86/zh-hant/#comments</comments>
		<pubDate>Mon, 23 May 2011 05:37:31 +0000</pubDate>
		<dc:creator>船長</dc:creator>
				<category><![CDATA[其它]]></category>
		<category><![CDATA[站長文檔]]></category>
		<category><![CDATA[流氓]]></category>
		<category><![CDATA[電信]]></category>

		<guid isPermaLink="false">http://www.cslog.cn/?p=693</guid>
		<description><![CDATA[之前中國電信在我的印象中一直挺好的。今天竟然發現它竟然也在耍流氓， 而且不是今天 &#8230; <a href="http://www.cslog.cn/Content/%e5%8e%9f%e6%9d%a5%e6%b7%b1%e5%9c%b3%e7%94%b5%e4%bf%a1%e8%80%8d%e6%b5%81%e6%b0%93%e5%b7%b2%e7%bb%8f%e5%be%88%e4%b9%85%e4%ba%86/zh-hant/">繼續閱讀 <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>之前中國電信在我的印象中一直挺好的。今天竟然發現它竟然也在耍流氓， 而且不是今天剛開始的</p>
<p>參看：</p>
<p>http://www.pufen.net/live/2010/39/</p>
<p>http://www.btsmth.com/show_snapshot.php?en_name=DigiHome&#038;gid=223759</p>
<p>http://www.tianya.cn/publicforum/content/free/1/1542795.shtml</p>
<p>http://www.tianya.cn/publicforum/content/itinfo/1/96974.shtml</p>
<p>http://topic.csdn.net/u/20101018/15/2ee893d0-7826-49a3-90c6-c406b572b081.html</p>
<p>http://help.360.cn/5030809/24119258.html
<div style="margin-top: 15px; font-style: italic">
<p>轉載請註明: 轉自<a href="http://www.cslog.cn/">船長日誌</a>, 本文鏈接地址: <a href="http://www.cslog.cn/Content/%e5%8e%9f%e6%9d%a5%e6%b7%b1%e5%9c%b3%e7%94%b5%e4%bf%a1%e8%80%8d%e6%b5%81%e6%b0%93%e5%b7%b2%e7%bb%8f%e5%be%88%e4%b9%85%e4%ba%86/zh-hant/">http://www.cslog.cn/Content/%e5%8e%9f%e6%9d%a5%e6%b7%b1%e5%9c%b3%e7%94%b5%e4%bf%a1%e8%80%8d%e6%b5%81%e6%b0%93%e5%b7%b2%e7%bb%8f%e5%be%88%e4%b9%85%e4%ba%86/zh-hant/</a></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.cslog.cn/Content/%e5%8e%9f%e6%9d%a5%e6%b7%b1%e5%9c%b3%e7%94%b5%e4%bf%a1%e8%80%8d%e6%b5%81%e6%b0%93%e5%b7%b2%e7%bb%8f%e5%be%88%e4%b9%85%e4%ba%86/feed/zh-hant/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>博客搬到國外了</title>
		<link>http://www.cslog.cn/Content/out-of-g-firewall/zh-hant/</link>
		<comments>http://www.cslog.cn/Content/out-of-g-firewall/zh-hant/#comments</comments>
		<pubDate>Sun, 22 May 2011 19:04:58 +0000</pubDate>
		<dc:creator>船長</dc:creator>
				<category><![CDATA[其它]]></category>
		<category><![CDATA[站長文檔]]></category>
		<category><![CDATA[博客]]></category>
		<category><![CDATA[站長]]></category>

		<guid isPermaLink="false">http://www.cslog.cn/?p=691</guid>
		<description><![CDATA[博客搬到國外了。 我知道遲早會有這樣一天的。 在國內做網站有問題的東西太多了，  &#8230; <a href="http://www.cslog.cn/Content/out-of-g-firewall/zh-hant/">繼續閱讀 <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>博客搬到國外了。 我知道遲早會有這樣一天的。 在國內做網站有問題的東西太多了， 指哪哪有， 百發百中。問題不在於我的博客， 而在於這種機制。</p>
<p>我的問題是服務器必須安裝華盾軟件。 我不喜歡華盾。 聽到這詞我就噁心， 反胃， 想吃酸的。雖然我是十分不喜歡， 但我是想過要做一個良民站長，咬牙安裝上這個軟件的。 在這樣的國度，報着被強姦也許也能撿一個高潮的僥倖心理的站長肯定不在少數。 問題是華盾竟然是個陽痿， 沒有辦法兼容我那個使用nginx軟件的服務器系統！ 託管公司是目睹了整個過程的。 他們知道內情， 但他們說庇護不了，不敢留我，同情地看着服務器上的宮砂痣把我請走。 我不怪託管公司， 他們或愛國愛黨， 或混口飯吃， 都不容易。站長如我， 託管公司如斯， 折騰到了這樣的地步，都沒得什麼利益。 </p>
<p>亂世出英雄， 識時務者為俊傑。 綠壩算一個，華盾應該算一個。 一個早泄，一個陽痿。病不在英雄， 遺傳病， 病在DNA里， 治病得檢查他們的爸媽。可惜國內醫院沒有這樣的CT機器。</p>
<p>搬走就搬走吧。 搬之前一直擔心， 真的搬走之倒好像一身輕鬆。 如飛鳥展翅， 海闊天空。
<div style="margin-top: 15px; font-style: italic">
<p>轉載請註明: 轉自<a href="http://www.cslog.cn/">船長日誌</a>, 本文鏈接地址: <a href="http://www.cslog.cn/Content/out-of-g-firewall/zh-hant/">http://www.cslog.cn/Content/out-of-g-firewall/zh-hant/</a></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.cslog.cn/Content/out-of-g-firewall/feed/zh-hant/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>工信部備案網站打不開 顯示No backend servers available</title>
		<link>http://www.cslog.cn/Content/miibeian-gov-cn-no-backend-servers-available/zh-hant/</link>
		<comments>http://www.cslog.cn/Content/miibeian-gov-cn-no-backend-servers-available/zh-hant/#comments</comments>
		<pubDate>Tue, 29 Mar 2011 04:15:02 +0000</pubDate>
		<dc:creator>船長</dc:creator>
				<category><![CDATA[站長文檔]]></category>
		<category><![CDATA[備案]]></category>
		<category><![CDATA[工信部]]></category>
		<category><![CDATA[黑客]]></category>

		<guid isPermaLink="false">http://www.cslog.cn/?p=655</guid>
		<description><![CDATA[2011年3月27號（？）開始，到今天（29號）,我一直嘗試打開工信部的備案網站 &#8230; <a href="http://www.cslog.cn/Content/miibeian-gov-cn-no-backend-servers-available/zh-hant/">繼續閱讀 <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>2011年3月27號（？）開始，到今天（29號）,我一直嘗試打開工信部的備案網站http://www.miibeian.gov.cn/ 和 http://www.miitbeian.gov.cn/ 都沒能成功打開過。 顯示 No backend servers available。</p>
<p>日前還不清楚是什麼原因。 有的說是服務器故障， 有的人則懷疑工信部的網站被黑了。據網上說同樣問題在去年6月新版工信部備案網站http://www.miitbeian.gov.cn/剛推出時發生過。</p>
<p>我認為是服務器的3天多的故障的可能性比較大。因為我感覺黑客們應該知道，黑了工信部的備案網站幾乎對所有的公務員都不會產生影響（甚至部分可能會利用這個借口帶薪休假）， 受難的將仍會是大批無靠山無後台的小站長。
<div style="margin-top: 15px; font-style: italic">
<p>轉載請註明: 轉自<a href="http://www.cslog.cn/">船長日誌</a>, 本文鏈接地址: <a href="http://www.cslog.cn/Content/miibeian-gov-cn-no-backend-servers-available/zh-hant/">http://www.cslog.cn/Content/miibeian-gov-cn-no-backend-servers-available/zh-hant/</a></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.cslog.cn/Content/miibeian-gov-cn-no-backend-servers-available/feed/zh-hant/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>linux下使用logrotate自動備份mysql數據庫</title>
		<link>http://www.cslog.cn/Content/logrotate-mysql-automated-backu/zh-hant/</link>
		<comments>http://www.cslog.cn/Content/logrotate-mysql-automated-backu/zh-hant/#comments</comments>
		<pubDate>Fri, 12 Nov 2010 15:31:19 +0000</pubDate>
		<dc:creator>船長</dc:creator>
				<category><![CDATA[站長文檔]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[logrotate]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[數據備份]]></category>
		<category><![CDATA[數據庫]]></category>

		<guid isPermaLink="false">http://www.cslog.cn/?p=568</guid>
		<description><![CDATA[logrotate是linux下的一個日誌文件管理工具。apache,nignx &#8230; <a href="http://www.cslog.cn/Content/logrotate-mysql-automated-backu/zh-hant/">繼續閱讀 <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>logrotate是linux下的一個日誌文件管理工具。apache,nignx或系統的log文件如不處理， 正常情況下會慢慢變的大， 久了， 硬盤就會爆掉。 logrotate（配合cron）就是用來周期性分割、壓縮、刪除日誌文件用的。前段時間在找mysql數據庫的自動備份方法的時候， 在 <a href="http://islandlinux.org/howto/automated-mysql-backups">http://islandlinux.org/howto/automated-mysql-backups</a> 看到了使用logrotate來備份mysql數據庫的偏方， 感覺不錯， 在這裡和大家分享一下。</p>
<p><span id="more-568"></span></p>
<p>首先， 先創建一個腳本文件</p>
<pre>nano /usr/local/sbin/mysql_auto_backup.sh</pre>
<p>貼入如下內容</p>
<pre>#!/bin/sh
#
# 作者 Dallas Vogels 2008-10-01
#
export PATH=/bin:/usr/bin:/sbin:/usr/sbin

OUTPUTDIR="/root/mysql-backups" #將這裡修改成你要放備份文件的目錄
OPTIONS="--all --complete-insert --add-drop-table --extended-insert --quote-names"
CONFIG_FILE="/root/.my.cnf.backup"

# 檢查備份目錄是否存在
if [ ! -d $OUTPUTDIR ]; then
        mkdir $OUTPUTDIR
fi

# 獲取數據庫列表
DATABASES=`echo "SHOW DATABASES" | mysql --defaults-file="$CONFIG_FILE" mysql`

for DATABASE in $DATABASES; do
# 不備份 Database 和 information_schema 這兩個數據庫
  if [ "$DATABASE" != "Database" -a "$DATABASE" != "information_schema" ]; then
    # 數據庫備份開始
    mysqldump --defaults-file="$CONFIG_FILE" $OPTIONS $DATABASE &gt; $OUTPUTDIR/$DATABASE.sql
  fi

done

exit 0</pre>
<p>將這個備份腳本添加可執行屬性：</p>
<pre>sudo chmod og-rwx /usr/local/sbin/mysql_auto_backup.sh</pre>
<p>運行mysql</p>
<pre>mysql -u root -p</pre>
<p>給mysql添加專門用來備份數據庫的用戶：</p>
<pre>GRANT SELECT, LOCK TABLES ON *.* TO mysqlbackup@localhost IDENTIFIED BY 'password';
FLUSH PRIVILEGES;</pre>
<p>注意將password換成你想要設定的密碼。</p>
<p>新創建一個mysql配置文件：</p>
<pre>nano /root/.my.cnf.backup</pre>
<p>將這個mysql備份用戶信息加到裡面：</p>
<pre>[client]
user="mysqlbackup"
password="password"</pre>
<p>注意再次換密碼。</p>
<p>設置好這個文件的屬性：</p>
<pre>chmod og-rwx /root/.my.cnf.backup</pre>
<p>現在可以測試一下數據備份腳本了，運行：</p>
<pre>/usr/local/sbin/mysql_auto_backup.sh</pre>
<p>如果可以在設定的目錄（/root/mysql-backups）找到mysql數據庫dump出來的sql文件，那到目前為止一切正常，繼續。</p>
<p>創建用來自動備份mysql數據庫的logrotate配置文件：</p>
<pre>nano /etc/logrotate.d/mysql-backups</pre>
<p>貼入如下內容:</p>
<pre>/root/mysql-backups/*.sql {
  weekly
  copy
  missingok
  rotate 30
  compress
  notifempty
  create 640 root adm
  sharedscripts
  prerotate
    /usr/local/sbin/mysql_auto_backup.sh
  endscript
}</pre>
<p>上面的設置會每周一次地將mysql中所有除Database和information_schema之外的數據庫自動dump到/root/mysql-backups/目錄中， 並自動將dump文件壓縮成gz格式(如果不希望壓縮，去掉上面的compress行）。<br />
如果希望將數據備份周期改到每天一次， 直接將上面logrotate配置文件weekly改成daily就可以了（每月一次是monthly)<br />
上面的腳本會自動保留最近30個備份（注意rotate 30參數， 修改30可設置保留的備份數）</p>
<p>最後測試一下logrotate配置文件有沒有問題，強制運行logrotate：</p>
<pre>logrotate -f /etc/logrotate.d/mysql-backups</pre>
<p>這時/root/mysql-backups/目錄應該出來gz格式的mysql數據庫備份文件。</p>
<p>這時用logrotate的自動mysql數據庫的備份部署完成了。這樣每星期到/root/mysql-backups/目錄下載mysql備份文件就可了。
<div style="margin-top: 15px; font-style: italic">
<p>轉載請註明: 轉自<a href="http://www.cslog.cn/">船長日誌</a>, 本文鏈接地址: <a href="http://www.cslog.cn/Content/logrotate-mysql-automated-backu/zh-hant/">http://www.cslog.cn/Content/logrotate-mysql-automated-backu/zh-hant/</a></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.cslog.cn/Content/logrotate-mysql-automated-backu/feed/zh-hant/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- WP Chinese Conversion Full Page Converted -->