<?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>I am LAZY bones ? &#187; 经验技巧</title>
	<atom:link href="http://luy.li/category/experience/feed/" rel="self" type="application/rss+xml" />
	<link>http://luy.li</link>
	<description>all linux</description>
	<lastBuildDate>Mon, 30 Aug 2010 01:26:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>跨平台共享鼠标键盘</title>
		<link>http://luy.li/2010/05/18/synergy-plus/</link>
		<comments>http://luy.li/2010/05/18/synergy-plus/#comments</comments>
		<pubDate>Tue, 18 May 2010 10:19:30 +0000</pubDate>
		<dc:creator>bones7456</dc:creator>
				<category><![CDATA[经验技巧]]></category>

		<guid isPermaLink="false">http://li2z.cn/?p=1559</guid>
		<description><![CDATA[可能有的老GEEK看到标题，会想到synergy，而我今天要介绍的其实是synergy-plus，因为synergy自从2006年以后，就没有更新了，然而它是个开源软件，所以它并不会就此死掉，有人fork了它的代码，并维护了下去，这就是synergy-plus。 synergy-plus是一个跨平台的鼠标键盘共享软件，支持linux、mac、windows，可以用一套鼠标键盘控制多台电脑，实现光标从这个屏幕飞到那个屏幕，哈哈。 我有这个需求，是因为来这个公司上班以后，公司给分了一个台式机，配置还不错，但是预装的是XP。由于我不是很习惯XP，但是工作中又经常要用到，所以就把自己的神舟本也背来了。于是，桌子上就放了俩电脑。本来俩电脑也没啥的，可是最近夏天到了，我的本本键盘越来越热，基本下不去手了。于是就想起以前看到过的synergy来了，没想到最近多了个plus，呵呵。 那就试试plus吧，目前，synergy-plus 1.3.4 版本已经在gentoo的portage里面了，但是看到主页上，最新的版本却是 1.3.5rc 。于是想尝鲜的我，下载了1.3.5版本，却发现linux下的编译过程并不是很顺利。下载的 synergy-plus-1.3.5-rc-Source.tar.gz (md5sum:db8b2c306695a163e7edf696256913fd) 根本没法编译，于是svn了最新的代码，参照这个编译说明，也还是需要修改几个文件，才能编译过去（而且好像没有install的方法）。不过这个应该是由于这段时间代码在转型吧，相信正式发布的时候，会解决所有这些小问题的。 相比之下，windows的安装过程就及其简单了，因为有现成的二进制的包了嘛，不多说。 我的需求，是要让win的机器当server，linux机器当client的（物理上插着鼠标键盘的机器需要是server）。所以参照这个配置文档，简单设置一下，我的如图： 可以看到，只要设置有几个screens，然后再设置screen间的位置关系，就可以了。 在这里要注意的是，screen的名字，最好是各机器的机器名（我这里windows的机器名是 t-liushun，linux的是 LLY），不然名字不同，是有可能被拒绝连接的。 配置完之后，server点一下start按钮，就会缩到托盘等待client的连接了，然后在linux上执行（文件在bin目录下）： ./synergyc -f t-liushun 就可以连上了，这时候，你就可以方便地用台式机键盘控制笔记本喽~ 有了这个东西，再加上Dropbox同步两边的文件，基本上，就可以把俩电脑合而为一喽。 另外，如果server端是linux的话，就要建立类似如下的配置文件： section: screens LLY: switchCorners = none switchCornerSize = 0 t-liushun: switchCorners = none switchCornerSize = 0 end section: links LLY: right = t-liushun t-liushun: left = LLY end section: options end [...]]]></description>
			<content:encoded><![CDATA[<p>可能有的老GEEK看到标题，会想到<a href="http://synergy2.sourceforge.net/">synergy</a>，而我今天要介绍的其实是<a href="http://code.google.com/p/synergy-plus/">synergy-plus</a>，因为synergy自从2006年以后，就没有更新了，然而它是个开源软件，所以它并不会就此死掉，有人fork了它的代码，并维护了下去，这就是synergy-plus。<br />
synergy-plus是一个跨平台的鼠标键盘共享软件，支持linux、mac、windows，可以用一套鼠标键盘控制多台电脑，实现光标从这个屏幕飞到那个屏幕，哈哈。<br />
我有这个需求，是因为来这个公司上班以后，公司给分了一个台式机，配置还不错，但是预装的是XP。由于我不是很习惯XP，但是工作中又经常要用到，所以就把自己的神舟本也背来了。于是，桌子上就放了俩电脑。本来俩电脑也没啥的，可是最近夏天到了，我的本本键盘越来越热，基本下不去手了。于是就想起以前看到过的synergy来了，没想到最近多了个plus，呵呵。<br />
那就试试plus吧，目前，synergy-plus 1.3.4 版本已经在gentoo的portage里面了，但是看到主页上，最新的版本却是 1.3.5rc 。于是想尝鲜的我，下载了1.3.5版本，却发现linux下的编译过程并不是很顺利。下载的 synergy-plus-1.3.5-rc-Source.tar.gz (md5sum:db8b2c306695a163e7edf696256913fd) 根本没法编译，于是svn了最新的代码，参照这个<a href="http://code.google.com/p/synergy-plus/wiki/Compiling">编译说明</a>，也还是需要修改几个文件，才能编译过去（而且好像没有install的方法）。不过这个应该是由于这段时间代码在转型吧，相信正式发布的时候，会解决所有这些小问题的。<br />
相比之下，windows的安装过程就及其简单了，因为有现成的二进制的包了嘛，不多说。<br />
我的需求，是要让win的机器当server，linux机器当client的（物理上插着鼠标键盘的机器需要是server）。所以参照这个<a href="http://code.google.com/p/synergy-plus/wiki/Setup">配置文档</a>，简单设置一下，我的如图：<br />
<img src="http://luy.li/wp-content/uploads/2010/05/synergy.png" alt="" title="synergy" width="537" height="378" class="alignnone size-full wp-image-1560" /><br />
可以看到，只要设置有几个screens，然后再设置screen间的位置关系，就可以了。<br />
在这里要注意的是，screen的名字，最好是各机器的机器名（我这里windows的机器名是 t-liushun，linux的是 LLY），不然名字不同，是有可能被拒绝连接的。<br />
配置完之后，server点一下start按钮，就会缩到托盘等待client的连接了，然后在linux上执行（文件在bin目录下）：</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">./synergyc -f t-liushun</pre></div></div>

<p>就可以连上了，这时候，你就可以方便地用台式机键盘控制笔记本喽~<br />
有了这个东西，再加上Dropbox同步两边的文件，基本上，就可以把俩电脑合而为一喽。</p>
<p>另外，如果server端是linux的话，就要建立类似如下的配置文件：</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">section: screens
	LLY:
		switchCorners = none
		switchCornerSize = 0
	t-liushun:
		switchCorners = none
		switchCornerSize = 0
end
section: links
	LLY:
		right = t-liushun
	t-liushun:
		left = LLY
end
section: options
end</pre></div></div>

<p>然后执行：</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">./synergys -f --config 配置文件名</pre></div></div>

<p>窃以为，这种集中在server进行配置，而client只管连到server的理念，也非常地棒~</p>
<p>========update========<br />
发现用这个还能在两台机器间共享剪贴板，哈哈~至少文本内容没问题，不错。</p>
]]></content:encoded>
			<wfw:commentRss>http://luy.li/2010/05/18/synergy-plus/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
		<item>
		<title>充分利用磁盘空间，打开ext文件系统的保留区块</title>
		<link>http://luy.li/2010/01/08/reserved_block/</link>
		<comments>http://luy.li/2010/01/08/reserved_block/#comments</comments>
		<pubDate>Fri, 08 Jan 2010 12:19:23 +0000</pubDate>
		<dc:creator>bones7456</dc:creator>
				<category><![CDATA[经验技巧]]></category>

		<guid isPermaLink="false">http://li2z.cn/?p=1315</guid>
		<description><![CDATA[今天，吼吼来找我说，他的硬盘，有个分区一共有234G，但是只用了222G，就报满了，无法继续使用了。 其实这个问题，我不久前刚看过一下，只要你仔细看 mkfs.ext3 的man page，就可以知道原因了，其中有这么一句： -m reserved-blocks-percentage Specify the percentage of the filesystem blocks reserved for the super-user. This avoids fragmentation, and allows root-owned daemons, such as syslogd(8), to continue to function correctly after non-privileged processes are prevented from writing to the filesystem. The default percentage is 5%. 也就是说，ext文件系统，包括ext2、ext3、ext4都会默认预留5%的磁盘空间，留给root用户维护系统或者记录系统关键日志的时候使用，这也就是导致普通用户无法使用部分磁盘空间的原因了。 我个人觉得，这个选项用在根分区或者/var之类的分区，还是有一定的必要性的。但是如果是/home、/opt或者干脆是/data之类的数据分区，就显得有点多此一举了。而且，现在的磁盘空间越来越大，5%往往会有10多G，都可以存一部高清了。这么多空间浪费了，是不是太可惜了呢？ 于是，就去找相关资料，看能可否在不格式化的情况下改变保留区块的大小。 吼吼找到了这个，比我想像得还要简单，甚至都不需要umount分区，就可以进行修改。 具体操作过程如下，已经加了详细注释： #之前的保留区有 732463 [...]]]></description>
			<content:encoded><![CDATA[<p>今天，<a href="http://www.imchao.net/">吼吼</a>来找我说，他的硬盘，有个分区一共有234G，但是只用了222G，就报满了，无法继续使用了。<br />
其实这个问题，我不久前刚看过一下，只要你仔细看 mkfs.ext3 的man page，就可以知道原因了，其中有这么一句：</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">       -m reserved-blocks-percentage
              Specify the percentage of the filesystem blocks reserved for the
              super-user.   This  avoids  fragmentation, and allows root-owned
              daemons, such as syslogd(8), to continue to  function  correctly
              after non-privileged processes are prevented from writing to the
              filesystem.  The default percentage is 5%.</pre></div></div>

<p>也就是说，ext文件系统，包括ext2、ext3、ext4都会默认预留5%的磁盘空间，留给root用户维护系统或者记录系统关键日志的时候使用，这也就是导致普通用户无法使用部分磁盘空间的原因了。<br />
我个人觉得，这个选项用在根分区或者/var之类的分区，还是有一定的必要性的。但是如果是/home、/opt或者干脆是/data之类的数据分区，就显得有点多此一举了。而且，现在的磁盘空间越来越大，5%往往会有10多G，都可以存一部高清了。这么多空间浪费了，是不是太可惜了呢？<br />
于是，就去找相关资料，看能可否在不格式化的情况下改变保留区块的大小。<br />
吼吼找到了<a href="http://wiki.linux.org.hk/w/Configure_filesystem_space_reserved_for_system_administrator">这个</a>，比我想像得还要简单，甚至都不需要umount分区，就可以进行修改。<br />
具体操作过程如下，已经加了详细注释：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#之前的保留区有 732463 块</span>
lily<span style="color: #000000; font-weight: bold;">@</span>LLY:~$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> tune2fs <span style="color: #660033;">-l</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sda7 <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">&quot;Reserved block count&quot;</span>
Reserved block count:     <span style="color: #000000;">732463</span>
<span style="color: #666666; font-style: italic;">#已用空间+可用空间 和 总空间 相比，还少了近3个G</span>
lily<span style="color: #000000; font-weight: bold;">@</span>LLY:~$ <span style="color: #c20cb9; font-weight: bold;">df</span>
文件系统	         1K-块      已用      可用 已用<span style="color: #000000; font-weight: bold;">%</span> 挂载点
<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sda7             <span style="color: #000000;">57677500</span>  <span style="color: #000000;">47662588</span>   <span style="color: #000000;">7085060</span>  <span style="color: #000000;">88</span><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #000000; font-weight: bold;">/</span>home
<span style="color: #666666; font-style: italic;">#调整：</span>
lily<span style="color: #000000; font-weight: bold;">@</span>LLY:~$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> tune2fs <span style="color: #660033;">-r</span> <span style="color: #000000;">25600</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sda7
tune2fs 1.41.9 <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">22</span>-Aug-<span style="color: #000000;">2009</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
Setting reserved blocks count to <span style="color: #000000;">25600</span>
<span style="color: #666666; font-style: italic;">#再来看看空间，哈哈</span>
lily<span style="color: #000000; font-weight: bold;">@</span>LLY:~$ <span style="color: #c20cb9; font-weight: bold;">df</span>
文件系统	         1K-块      已用      可用 已用<span style="color: #000000; font-weight: bold;">%</span> 挂载点
<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sda7             <span style="color: #000000;">57677500</span>  <span style="color: #000000;">47662584</span>   <span style="color: #000000;">9912516</span>  <span style="color: #000000;">83</span><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #000000; font-weight: bold;">/</span>home
<span style="color: #666666; font-style: italic;">#确认调整成功</span>
lily<span style="color: #000000; font-weight: bold;">@</span>LLY:~$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> tune2fs <span style="color: #660033;">-l</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sda7 <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">&quot;Reserved block count&quot;</span>
Reserved block count:     <span style="color: #000000;">25600</span></pre></div></div>

<p>看到了吧？就一眨眼的功夫，我就多了3G多的空间，哈哈。而且我还不是直接完全去掉保留区块呢，也留了百多兆以防不时之需呢，呵呵。<br />
算了一下，吼吼那个3.4T的磁盘阵列，省出来的空间居然比我的整个硬盘都大。嗨。。。</p>
]]></content:encoded>
			<wfw:commentRss>http://luy.li/2010/01/08/reserved_block/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>nginx 对某些 User_Agent 进行限速的方法</title>
		<link>http://luy.li/2009/12/30/nginx-user_agent-limit_rate/</link>
		<comments>http://luy.li/2009/12/30/nginx-user_agent-limit_rate/#comments</comments>
		<pubDate>Wed, 30 Dec 2009 08:52:26 +0000</pubDate>
		<dc:creator>bones7456</dc:creator>
				<category><![CDATA[经验技巧]]></category>

		<guid isPermaLink="false">http://li2z.cn/?p=1300</guid>
		<description><![CDATA[本文为nginx 禁止某个 User_Agent 的方法的姊妹篇，不知所云的话，建议先看看这文。 由于之前已经将某个特别疯狂的迅雷的User_Agent给封掉了，所以最近一段时间，我的那源服务器也运行地比较稳定，但是今天，Linux Deepin 9.12正式发布了，由于我给Deepin做了一个iso的镜像，所以服务器又经历了一个访问高峰，如下图： 从这里也可以看出Linux Deepin的受欢迎程度，哈哈。 可以看到从11:00以后，100M的带宽就已经被完全撑满了。。。一看日志，大部分又是迅雷干的，但这次迅雷不是用某个特定的UA来访问了，而是各有变化，但是却都包含MSIE，哈哈。 当然IE用户直接访问的话，也会有这个MSIE，但是没办法，为了保全Ubuntu APT-HTTP的合法权益，只能限制一下MSIE了。 但是怎么限制呢？总不能人家用MSIE的连主页面都打不开吧？哈哈，最好的办法就是限速，于是，有了这个配置： server { listen 80; server_name ubuntu.srt.cn; access_log /var/log/nginx/mirror.access.log; location / { root /data/mirrors; autoindex on; index index.html index.htm; if ($http_user_agent ~ &#34;MSIE&#34;) { limit_rate 2k; } if ($http_user_agent ~ &#34;Mozilla/4.0\ \(compatible;\ MSIE\ 6.0;\ Windows\ NT\ 5.1;\ SV1;\ .NET\ CLR\ 1.1.4322;\ .NET\ CLR\ [...]]]></description>
			<content:encoded><![CDATA[<p>本文为<a href="http://luy.li/2009/10/31/nginx-block-user_agent/">nginx 禁止某个 User_Agent 的方法</a>的姊妹篇，不知所云的话，建议先看看这文。<br />
由于之前已经将某个特别疯狂的迅雷的User_Agent给封掉了，所以最近一段时间，我的那源服务器也运行地比较稳定，但是今天，Linux Deepin 9.12<a href="http://linux.deepin.org/9.12/final">正式发布</a>了，由于我给Deepin做了一个iso的镜像，所以服务器又经历了一个访问高峰，如下图：<br />
<img src="http://luy.li/wp-content/uploads/2009/12/mirror-20091230.png" alt="" title="mirror-20091230" width="500" height="135" class="alignnone size-full wp-image-1301" /><br />
从这里也可以看出Linux Deepin的受欢迎程度，哈哈。<br />
可以看到从11:00以后，100M的带宽就已经被完全撑满了。。。一看日志，大部分又是迅雷干的，但这次迅雷不是用某个特定的UA来访问了，而是各有变化，但是却都包含MSIE，哈哈。<br />
当然IE用户直接访问的话，也会有这个MSIE，但是没办法，为了保全Ubuntu APT-HTTP的合法权益，只能限制一下MSIE了。<br />
但是怎么限制呢？总不能人家用MSIE的连<a href="http://ubuntu.srt.cn/">主页面</a>都打不开吧？哈哈，最好的办法就是限速，于是，有了这个配置：</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">server {
        listen   80;
        server_name  ubuntu.srt.cn;
        access_log  /var/log/nginx/mirror.access.log;
        location / {
                root   /data/mirrors;
                autoindex on;
                index  index.html index.htm;
                if ($http_user_agent ~ &quot;MSIE&quot;) {
                        limit_rate 2k;
                }
                if ($http_user_agent ~ &quot;Mozilla/4.0\ \(compatible;\ MSIE\ 6.0;\ Windows\ NT\ 5.1;\ SV1;\ .NET\ CLR\ 1.1.4322;\ .NET\ CLR\ 2.0.50727\)&quot;) {
                        return 404;
                }
        }
&nbsp;
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
                root   /var/www/nginx-default;
        }
}</pre></div></div>

<p>让我们邪恶的看一下效果，哈哈：<br />
wget的默认UA的时候：</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">$ wget --no-cache http://u.srt.cn/ubuntu/ls-lR.gz -O /dev/null
--14:08:28--  http://u.srt.cn/ubuntu/ls-lR.gz
           =&gt; `/dev/null'
正在解析主机 u.srt.cn... 211.155.227.167
Connecting to u.srt.cn|211.155.227.167|:80... 已连接。
已发出 HTTP 请求，正在等待回应... 200 OK
长度：8,051,367 (7.7M) [text/plain]
&nbsp;
100%[====================================&gt;] 8,051,367      6.34M/s             
&nbsp;
14:08:29 (6.33 MB/s) - `/dev/null' saved [8051367/8051367]</pre></div></div>

<p>UA里含有MSIE的时候：</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">$ wget --no-cache --user-agent=&quot;Something with MSIE; bla bla&quot; http://u.srt.cn/ubuntu/ls-lR.gz -O /dev/null
--14:07:59--  http://u.srt.cn/ubuntu/ls-lR.gz
           =&gt; `/dev/null'
正在解析主机 u.srt.cn... 211.155.227.167
Connecting to u.srt.cn|211.155.227.167|:80... 已连接。
已发出 HTTP 请求，正在等待回应... 200 OK
长度：8,051,367 (7.7M) [text/plain]
&nbsp;
 0% [                                     ] 49,152         2.08K/s  ETA 1:02:38</pre></div></div>

<p>某个该死的特定UA：</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">$ wget --no-cache --user-agent=&quot;Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)&quot; http://u.srt.cn/ubuntu/ls-lR.gz -O /dev/null
--14:09:22--  http://u.srt.cn/ubuntu/ls-lR.gz
           =&gt; `/dev/null'
正在解析主机 u.srt.cn... 211.155.227.167
Connecting to u.srt.cn|211.155.227.167|:80... 已连接。
已发出 HTTP 请求，正在等待回应... 404 Not Found
14:09:22 错误 404：Not Found。</pre></div></div>

<p>从上图也可以看到，做了这个设置以后，从14:00左右开始，服务器的流量虽然还是比较大，但是已经趋于正常了。<br />
所以，偶尔要从我源里下东西的同学，可以用firefox直接下载，也可以用axel或者wget之类的工具下，但是千万别用IE相关的工具，不然，后果自负，哈哈~</p>
]]></content:encoded>
			<wfw:commentRss>http://luy.li/2009/12/30/nginx-user_agent-limit_rate/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>简单的WP备份脚本</title>
		<link>http://luy.li/2009/12/15/wp_backup_script/</link>
		<comments>http://luy.li/2009/12/15/wp_backup_script/#comments</comments>
		<pubDate>Tue, 15 Dec 2009 05:26:48 +0000</pubDate>
		<dc:creator>bones7456</dc:creator>
				<category><![CDATA[经验技巧]]></category>

		<guid isPermaLink="false">http://li2z.cn/?p=1265</guid>
		<description><![CDATA[现在，写blog的人是越来越多了；这部分人里，自己建站的也越来越多了；又在这部分人里，用WP来建的也越来越多了。 而建过站的人，都知道备份的重要性。但是手工备份又显然太麻烦了，所以我写了这个脚本来自动备份，放cron里以后，基本上就不用去关心什么了，哈哈，不过在加crontab的时候，要注意用户，如果是用root跑，可能会因为读不到当前用户的key而备份失败哦。 条件是你的空间支持ssh登录，并且事先做好了rsa公钥，登录的时候不需要输入密码。 此脚本会生成两个文件，一个是文件的打包，一个是数据库的打包。上脚本吧： #!/bin/sh #WP备份脚本 #方便地备份wordpress的文件及数据库(限mysql) #作者： bones7456 &#160; #需要事先设置好这个HOST的rsa key 不然无法用ssh登录 HOST=&#34;gnometwe@li2z.cn&#34; #远程的WP文件所在目录，此目录下要有 wp-config.php REMOTE_PATH=&#34;www/li2z&#34; #本地保存目录(最好是绝对路径)，留空为当前目录 LOCAL_PATH=&#34;/home/lily/li2z.backup&#34; #备份文件的前缀，默认自动按时间生成 PRE=`date +%F-%H-%M-%S` &#160; &#91; -z $LOCAL_PATH &#93; &#124;&#124; cd $LOCAL_PATH #先备份文件 ssh $HOST &#34;cd $REMOTE_PATH; tar cf - -X exclude .&#34; &#124; gzip &#62; $PRE.tar.gz #从文件取得数据库信息 tar zxvf $PRE.tar.gz ./wp-config.php if &#91; -f wp-config.php &#93;;then [...]]]></description>
			<content:encoded><![CDATA[<p>现在，写blog的人是越来越多了；这部分人里，自己建站的也越来越多了；又在这部分人里，用WP来建的也越来越多了。<br />
而建过站的人，都知道备份的重要性。但是手工备份又显然太麻烦了，所以我写了这个脚本来自动备份，放cron里以后，基本上就不用去关心什么了，哈哈，不过在加crontab的时候，要注意用户，如果是用root跑，可能会因为读不到当前用户的key而备份失败哦。<br />
条件是你的空间支持ssh登录，并且事先做好了<a href="http://luy.li/2007/08/07/%E5%86%8D%E5%86%99%E7%82%B9%E5%85%B3%E4%BA%8Essh%E7%9A%84/">rsa公钥</a>，登录的时候不需要输入密码。<br />
此脚本会生成两个文件，一个是文件的打包，一个是数据库的打包。上脚本吧：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
<span style="color: #666666; font-style: italic;">#WP备份脚本</span>
<span style="color: #666666; font-style: italic;">#方便地备份wordpress的文件及数据库(限mysql)</span>
<span style="color: #666666; font-style: italic;">#作者： bones7456</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#需要事先设置好这个HOST的rsa key 不然无法用ssh登录</span>
<span style="color: #007800;">HOST</span>=<span style="color: #ff0000;">&quot;gnometwe@li2z.cn&quot;</span>
<span style="color: #666666; font-style: italic;">#远程的WP文件所在目录，此目录下要有 wp-config.php</span>
<span style="color: #007800;">REMOTE_PATH</span>=<span style="color: #ff0000;">&quot;www/li2z&quot;</span>
<span style="color: #666666; font-style: italic;">#本地保存目录(最好是绝对路径)，留空为当前目录</span>
<span style="color: #007800;">LOCAL_PATH</span>=<span style="color: #ff0000;">&quot;/home/lily/li2z.backup&quot;</span>
<span style="color: #666666; font-style: italic;">#备份文件的前缀，默认自动按时间生成</span>
<span style="color: #007800;">PRE</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #000000; font-weight: bold;">%</span>F-<span style="color: #000000; font-weight: bold;">%</span>H-<span style="color: #000000; font-weight: bold;">%</span>M-<span style="color: #000000; font-weight: bold;">%</span>S<span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #007800;">$LOCAL_PATH</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #007800;">$LOCAL_PATH</span>
<span style="color: #666666; font-style: italic;">#先备份文件</span>
<span style="color: #c20cb9; font-weight: bold;">ssh</span> <span style="color: #007800;">$HOST</span> <span style="color: #ff0000;">&quot;cd <span style="color: #007800;">$REMOTE_PATH</span>; tar cf - -X exclude .&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">gzip</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #007800;">$PRE</span>.tar.gz
<span style="color: #666666; font-style: italic;">#从文件取得数据库信息</span>
<span style="color: #c20cb9; font-weight: bold;">tar</span> zxvf <span style="color: #007800;">$PRE</span>.tar.gz .<span style="color: #000000; font-weight: bold;">/</span>wp-config.php
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-f</span> wp-config.php <span style="color: #7a0874; font-weight: bold;">&#93;</span>;<span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #007800;">DB_NAME</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">&quot;^define('DB_NAME'&quot;</span> wp-config.php <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">cut</span> <span style="color: #660033;">-d</span><span style="color: #000000; font-weight: bold;">\'</span> <span style="color: #660033;">-f</span> <span style="color: #000000;">4</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">DB_USER</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">&quot;^define('DB_USER'&quot;</span> wp-config.php <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">cut</span> <span style="color: #660033;">-d</span><span style="color: #000000; font-weight: bold;">\'</span> <span style="color: #660033;">-f</span> <span style="color: #000000;">4</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">DB_PASSWORD</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">&quot;^define('DB_PASSWORD'&quot;</span> wp-config.php <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">cut</span> <span style="color: #660033;">-d</span><span style="color: #000000; font-weight: bold;">\'</span> <span style="color: #660033;">-f</span> <span style="color: #000000;">4</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #c20cb9; font-weight: bold;">rm</span> wp-config.php
<span style="color: #000000; font-weight: bold;">else</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Something wrong ...&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #666666; font-style: italic;">#再备份数据库</span>
<span style="color: #c20cb9; font-weight: bold;">ssh</span> <span style="color: #007800;">$HOST</span> mysqldump <span style="color: #660033;">-u</span><span style="color: #800000;">${DB_USER}</span> <span style="color: #660033;">-p</span><span style="color: #800000;">${DB_PASSWORD}</span> <span style="color: #007800;">$DB_NAME</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">gzip</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #007800;">$PRE</span>.sql.gz
<span style="color: #666666; font-style: italic;">#这个可选，删除15天前的备份文件</span>
<span style="color: #666666; font-style: italic;">#要打开的话，记得建个专门的目录存放备份，以免误删其他文件</span>
<span style="color: #666666; font-style: italic;">#find . -maxdepth 1 -name &quot;*.gz&quot; -mtime +15 -exec rm {} \;</span></pre></div></div>

<p>PS: 稍作修改应该也可以用于非WP的blog系统。</p>
]]></content:encoded>
			<wfw:commentRss>http://luy.li/2009/12/15/wp_backup_script/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>在ubuntu下架设rsync和ftp服务</title>
		<link>http://luy.li/2009/09/21/rsync_ftp_in_ubuntu/</link>
		<comments>http://luy.li/2009/09/21/rsync_ftp_in_ubuntu/#comments</comments>
		<pubDate>Mon, 21 Sep 2009 09:37:23 +0000</pubDate>
		<dc:creator>bones7456</dc:creator>
				<category><![CDATA[经验技巧]]></category>

		<guid isPermaLink="false">http://li2z.cn/?p=1065</guid>
		<description><![CDATA[还是因为我的那个ubuntu源，之前只能以http方式访问，看到很多源也同时提供ftp和rsync的访问方式，我也就学着架设了一个。 先说说ftp方式，这个比较简单，参照官方源，我用的也是vsftpd。这个在ubuntu下几乎是不用配置就可以跑了。大致就是： sudo apt-get install vsftpd #安装vsftpd，会自动建立ftp用户，家目录默认是 /home/ftp sudo usermod -d /data/mirrors ftp #将ftp的家目录改成你数据所在的目录，人家访问的时候就可以读到这个目录的内容了 sudo /etc/init.d/vsftpd restart #重启安装的时候就默认启动的vsftpd 这样就完全可以了，如果你还想修改一下人家登录的时候的欢迎信息的话，编辑 /etc/vsftpd.conf ，将里面的 ftpd_banner= 解除注释，并将你要的信息填在后面。 其实这个配置文件还有很多其他选项可以修改，诸如是否允许匿名登录、写权限之类的，需要的话，自己 man vsftpd.conf 好了。 再说说rsync的服务端配置，我发现网上的那些中文教程用在ubuntu下都是会有问题的。 在ubuntu下，这个rsync的服务端和客户端似乎是一个东西，也就是没有rsyncd这个包了，所以也就不需要安装额外的包了，只需简单配置一下，并启动就可以了。 参照 man rsyncd.conf 的提示 建立一个 /etc/rsyncd.conf 文件，内容如下： motd file = /etc/rsyncd.motd pid file = /var/run/rsyncd.pid [ubuntu] comment = Hangzhou srt ubuntu mirror path = /data/mirrors/ubuntu max [...]]]></description>
			<content:encoded><![CDATA[<p>还是因为我的那个<a href="http://luy.li/2009/09/18/ubuntu_mirror/">ubuntu源</a>，之前只能以http方式访问，看到很多源也同时提供ftp和rsync的访问方式，我也就学着架设了一个。</p>
<p>先说说ftp方式，这个比较简单，参照官方源，我用的也是vsftpd。这个在ubuntu下几乎是不用配置就可以跑了。大致就是：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> vsftpd         <span style="color: #666666; font-style: italic;">#安装vsftpd，会自动建立ftp用户，家目录默认是 /home/ftp</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> usermod <span style="color: #660033;">-d</span> <span style="color: #000000; font-weight: bold;">/</span>data<span style="color: #000000; font-weight: bold;">/</span>mirrors <span style="color: #c20cb9; font-weight: bold;">ftp</span>   <span style="color: #666666; font-style: italic;">#将ftp的家目录改成你数据所在的目录，人家访问的时候就可以读到这个目录的内容了</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>vsftpd restart     <span style="color: #666666; font-style: italic;">#重启安装的时候就默认启动的vsftpd</span></pre></div></div>

<p>这样就完全可以了，如果你还想修改一下人家登录的时候的欢迎信息的话，编辑 /etc/vsftpd.conf ，将里面的 ftpd_banner= 解除注释，并将你要的信息填在后面。<br />
其实这个配置文件还有很多其他选项可以修改，诸如是否允许匿名登录、写权限之类的，需要的话，自己 man vsftpd.conf 好了。</p>
<p>再说说rsync的服务端配置，我发现网上的那些中文教程用在ubuntu下都是会有问题的。<br />
在ubuntu下，这个rsync的服务端和客户端似乎是一个东西，也就是没有rsyncd这个包了，所以也就不需要安装额外的包了，只需简单配置一下，并启动就可以了。<br />
参照 man rsyncd.conf 的提示<br />
建立一个 /etc/rsyncd.conf 文件，内容如下：</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">motd file = /etc/rsyncd.motd
pid file = /var/run/rsyncd.pid
[ubuntu]
comment = Hangzhou srt ubuntu mirror
path = /data/mirrors/ubuntu
max connections = 3
log file = /var/log/rsyncd.log</pre></div></div>

<p>其中 motd file 应该是可选的，如果写上了，就需要再建立一个 /etc/rsyncd.motd 的文本，写入欢迎信息，有空的话，还可以搞个帅帅的ASCII art哦。<br />
上面的两行是全局的配置，下面中括号里的是模块名，以下的配置都是模块级的。可以同时指定多个模块。<br />
配置好了以后，执行</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>rsync start</pre></div></div>

<p>rsync应该就启动了，另外可以在 sysv-rc-conf 里确保启动的时候就开启了rsync服务。</p>
<p>现在也可以通过以下方式访问SRT ubuntu mirror了：<br />
rsync://ubuntu.srt.cn/ubuntu<br />
ftp://ubuntu.srt.cn/ubuntu/</p>
]]></content:encoded>
			<wfw:commentRss>http://luy.li/2009/09/21/rsync_ftp_in_ubuntu/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
