<?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/" 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/</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/#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/">继续阅读 <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/">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/</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/</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/</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/#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/">继续阅读 <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/">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/</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/</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/</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/#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/">继续阅读 <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/">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/</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/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>再谈Nginx Rewrite， 中文URL和其它</title>
		<link>http://www.cslog.cn/Content/nginx-rewrite-chinese/</link>
		<comments>http://www.cslog.cn/Content/nginx-rewrite-chinese/#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/">继续阅读 <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/">http://www.cslog.cn/Content/nginx-rewrite-chinese/</a></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.cslog.cn/Content/nginx-rewrite-chinese/feed/</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/</link>
		<comments>http://www.cslog.cn/Content/nginx-pcre-utf8-rewrite/#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/">继续阅读 <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/">http://www.cslog.cn/Content/nginx-pcre-utf8-rewrite/</a></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.cslog.cn/Content/nginx-pcre-utf8-rewrite/feed/</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/</link>
		<comments>http://www.cslog.cn/Content/unicorn-for-ruby-on-rails/#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/">继续阅读 <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/">http://www.cslog.cn/Content/unicorn-for-ruby-on-rails/</a></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.cslog.cn/Content/unicorn-for-ruby-on-rails/feed/</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/</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/#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/">继续阅读 <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/">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/</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/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>博客搬到国外了</title>
		<link>http://www.cslog.cn/Content/out-of-g-firewall/</link>
		<comments>http://www.cslog.cn/Content/out-of-g-firewall/#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/">继续阅读 <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/">http://www.cslog.cn/Content/out-of-g-firewall/</a></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.cslog.cn/Content/out-of-g-firewall/feed/</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/</link>
		<comments>http://www.cslog.cn/Content/miibeian-gov-cn-no-backend-servers-available/#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/">继续阅读 <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/">http://www.cslog.cn/Content/miibeian-gov-cn-no-backend-servers-available/</a></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.cslog.cn/Content/miibeian-gov-cn-no-backend-servers-available/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>linux下使用logrotate自动备份mysql数据库</title>
		<link>http://www.cslog.cn/Content/logrotate-mysql-automated-backu/</link>
		<comments>http://www.cslog.cn/Content/logrotate-mysql-automated-backu/#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/">继续阅读 <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/">http://www.cslog.cn/Content/logrotate-mysql-automated-backu/</a></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.cslog.cn/Content/logrotate-mysql-automated-backu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
