<?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>Bernie Yu</title>
	<atom:link href="http://bernieyu.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://bernieyu.com</link>
	<description>复刻生活</description>
	<lastBuildDate>Tue, 17 May 2016 09:03:15 +0000</lastBuildDate>
	<language>zh-CN</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.2.38</generator>
	<item>
		<title>VPS从DirectSpace迁移到vultr</title>
		<link>http://bernieyu.com/2016/05/vps-from-directspace-to-vultr/</link>
		<comments>http://bernieyu.com/2016/05/vps-from-directspace-to-vultr/#comments</comments>
		<pubDate>Tue, 17 May 2016 09:01:59 +0000</pubDate>
		<dc:creator><![CDATA[Bernie Yu]]></dc:creator>
				<category><![CDATA[IT技术]]></category>
		<category><![CDATA[vps]]></category>
		<category><![CDATA[vultr]]></category>

		<guid isPermaLink="false">http://bernieyu.com/?p=271</guid>
		<description><![CDATA[DirectSpace的VPS已经用了好几年，稳定性差强人意。 而且由于是OpenVZ架构，做SS加速不是很理 ... <a class="more-link" href="http://bernieyu.com/2016/05/vps-from-directspace-to-vultr/">　　>>阅读全文&#60;&#60;</a>]]></description>
				<content:encoded><![CDATA[<p>DirectSpace的VPS已经用了好几年，稳定性差强人意。</p>
<p>而且由于是OpenVZ架构，做SS加速不是很理想，于是便决定迁到其他VPS。</p>
<p>对比后，最终决定用Vultr的$5/mo 产品，可惜日本机房要绕行美国，所以选了LA的机房，不过速度还好，比DS的要快不少。</p>
<p>对SS做了优化后，youtube1080P无压力。</p>
]]></content:encoded>
			<wfw:commentRss>http://bernieyu.com/2016/05/vps-from-directspace-to-vultr/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>查看阻止电脑进入休眠的程序</title>
		<link>http://bernieyu.com/2015/12/query-process-prevent-into-standby/</link>
		<comments>http://bernieyu.com/2015/12/query-process-prevent-into-standby/#comments</comments>
		<pubDate>Fri, 25 Dec 2015 07:22:54 +0000</pubDate>
		<dc:creator><![CDATA[Bernie Yu]]></dc:creator>
				<category><![CDATA[未分类]]></category>

		<guid isPermaLink="false">http://bernieyu.com/?p=268</guid>
		<description><![CDATA[打开命令提示符窗口后，键入以下命令: powercfg /requests]]></description>
				<content:encoded><![CDATA[<p>打开命令提示符窗口后，键入以下命令:</p>
<pre>powercfg /requests</pre>
]]></content:encoded>
			<wfw:commentRss>http://bernieyu.com/2015/12/query-process-prevent-into-standby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HDCN，纪念</title>
		<link>http://bernieyu.com/2015/10/hdcn%ef%bc%8c%e7%ba%aa%e5%bf%b5/</link>
		<comments>http://bernieyu.com/2015/10/hdcn%ef%bc%8c%e7%ba%aa%e5%bf%b5/#comments</comments>
		<pubDate>Thu, 29 Oct 2015 06:03:31 +0000</pubDate>
		<dc:creator><![CDATA[Bernie Yu]]></dc:creator>
				<category><![CDATA[未分类]]></category>

		<guid isPermaLink="false">http://bernieyu.com/?p=264</guid>
		<description><![CDATA[竟然要关站了。。。。 发文留念。 &#160;]]></description>
				<content:encoded><![CDATA[<p>竟然要关站了。。。。</p>
<p>发文留念。</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://bernieyu.com/2015/10/hdcn%ef%bc%8c%e7%ba%aa%e5%bf%b5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[转] lsyncd实时同步搭建指南——取代rsync+inotify</title>
		<link>http://bernieyu.com/2015/10/lsyncd-synchronize-realtime/</link>
		<comments>http://bernieyu.com/2015/10/lsyncd-synchronize-realtime/#comments</comments>
		<pubDate>Thu, 22 Oct 2015 00:59:40 +0000</pubDate>
		<dc:creator><![CDATA[Bernie Yu]]></dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[lsyncd]]></category>
		<category><![CDATA[同步]]></category>

		<guid isPermaLink="false">http://bernieyu.com/?p=261</guid>
		<description><![CDATA[转自http://seanlook.com/2015/05/06/lsyncd-synchronize-rea ... <a class="more-link" href="http://bernieyu.com/2015/10/lsyncd-synchronize-realtime/">　　>>阅读全文&#60;&#60;</a>]]></description>
				<content:encoded><![CDATA[<p>转自http://seanlook.com/2015/05/06/lsyncd-synchronize-realtime/</p>
<h1 id="1-_几大实时同步工具比较">1. 几大实时同步工具比较</h1>
<h2 id="1-1_inotify_+_rsync">1.1 inotify + rsync</h2>
<p>最近一直在寻求生产服务服务器上的同步替代方案，原先使用的是<code>inotify + rsync</code>，但随着文件数量的增大到100W+，目录下的文件列表就达20M，在网络状况不佳或者限速的情况下，变更的文件可能10来个才几M，却因此要发送的文件列表就达20M，严重减低的带宽的使用效率以及同步效率；更为要紧的是，加入inotifywait在5s内监控到10个小文件发生变化，便会触发10个rsync同步操作，结果就是真正需要传输的才2-3M的文件，比对的文件列表就达200M。使用这两个组合的好处在于，它们都是最基本的软件，可以通过不同选项做到很精确的控制，比如排除同步的目录，同步多个模块或同步到多个主机。</p>
<p>搭建过程参考 <a href="http://seanlook.com/2014/12/12/rsync_inotify_setup/" target="_blank" rel="external">Linux下同步工具inotify+rsync使用详解</a> 。</p>
<h2 id="1-2_sersync">1.2 sersync</h2>
<p>后来听同事说 <a href="http://www.ccvita.com/422.html" target="_blank" rel="external">sersync</a> 这么个工具可以提高同步的性能，也解决了同步大文件时出现异常的问题，所以就尝试了一下。sersync是国内的一个开发者开源出来的，使用c++编写，采用多线程的方式进行同步，失败后还有重传机制，对临时文件过滤，自带crontab定时同步功能。网上看到有人说性能还不错，说一下我的观点：</p>
<ul>
<li>国产开源，文档不是很全，在2011年之后就没更新了（googlecode都要快关闭了，其实可以转交其他人维护），网上关于它的使用和讨论都止于10年了</li>
<li>采用xml配置文件的方式，可读性比较好，但是有些原生的有些功能没有实现就没法使用了</li>
<li>无法实现多目录同步，只能通过多个配置文件启动多个进程</li>
<li>文件排除功能太弱。这个要看需求，不是每个人都需要排除子目录。而对于我的环境中，这个功能很重要，而且排除的规则较多</li>
<li>虽然提供插件的功能，但很鸡肋，因为软件本身没有持续更新，也没有看到贡献有其它插件出现（可能是我知识面不够，还用不到里面的refreshCDN plugin）。</li>
</ul>
<p>虽然不懂c++，但大致看了下源码 <a href="http://code.google.com/p/sersync/source/browse/FileSynchronize.cpp" target="_blank" rel="external">FileSynchronize</a>，拼接rsync命令大概在273行左右，最后一个函数就是排除选项，简单一点可以将<code>--exclude=</code>改成<code>--eclude-from</code>来灵活控制。有机会再改吧。</p>
<p>另外，在作者的文章 <a href="http://hi.baidu.com/johntech/item/a4a2060ecf3053c6905718e1" target="_blank" rel="external">Sersync服务器同步程序 项目简介与设计框架</a> 评论中，说能解决上面 <code>rsync + inotify</code>中所描述的问题。阅读了下源码，这个应该是没有解决，因为在拼接rsync命令时，后面的目的地址始终是针对module的，只要执行rsync命令，就会对整个目录进行遍历，发送要比对的文件列表，然后再发送变化的文件。sersync只是减少了监听的事件，减少了rsync的次数——这已经是很大的改进，但每次rsync没办法改变。（如有其它看法可与我讨论）</p>
<p>其实我们也不能要求每一个软件功能都十分健全，关键是看能否满足我们当下的特定的需求。所谓好的架构不是设计出来的，而是进化来的。目前使用<code>sersync2</code>没什么问题，而且看了它的设计思路应该是比较科学的，特别是过滤队列的设计。双向同步看起来也是可以实现。</p>
<h2 id="1-3_lsyncd">1.3 lsyncd</h2>
<p>废话说这么多，本文就是介绍它了。有些博客说lsyncd是谷歌开源的，实际不是了，只是托管在了googlecode上而已，幸运的是已经迁移到github了：<a href="https://github.com/axkibe/lsyncd" target="_blank" rel="external">https://github.com/axkibe/lsyncd</a> 。</p>
<p>Lysncd 实际上是lua语言封装了 inotify 和 rsync 工具，采用了 Linux 内核（2.6.13 及以后）里的 inotify 触发机制，然后通过rsync去差异同步，达到实时的效果。我认为它最令人称道的特性是，完美解决了 <code>inotify + rsync</code>海量文件同步带来的文件频繁发送文件列表的问题 —— 通过时间延迟或累计触发事件次数实现。另外，它的配置方式很简单，lua本身就是一种配置语言，可读性非常强。lsyncd也有多种工作模式可以选择，本地目录cp，本地目录rsync，远程目录rsyncssh。</p>
<p>实现简单高效的本地目录同步备份（网络存储挂载也当作本地目录），一个命令搞定。</p>
<h1 id="2-_使用_lsyncd_本地目录实时备份">2. 使用 lsyncd 本地目录实时备份</h1>
<p>这一节实现的功能是，本地目录source实时同步到另一个目录target，而在source下有大量的文件，并且有部分目录和临时文件不需要同步。</p>
<h2 id="2-1_安装lsyncd">2.1 安装lsyncd</h2>
<p>安装<code>lsyncd</code>极为简单，已经收录在ubuntu的官方镜像源里，直接通过<code>apt-get install lsyncd</code>就可以。<br />
在Redhat系（我的环境是CentOS 6.2 x86_64 ），可以手动去下载 <a href="ftp://195.220.108.108/linux/fedora/linux/updates/21/x86_64/l/lsyncd-2.1.5-6.fc21.x86_64.rpm" target="_blank" rel="external">lsyncd-2.1.5-6.fc21.x86_64.rpm</a>，但首先你得安装两个依赖<code>yum install lua lua-devel</code>。也可以通过在线安装，需要<code>epel-release</code>扩展包：</p>
<figure class="highlight">
<table>
<tbody>
<tr>
<td class="gutter">
<div class="line">1</div>
<div class="line">2</div>
</td>
<td class="code">
<div class="line"><span class="preprocessor"># rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm</span></div>
<div class="line"><span class="preprocessor"># yum install lsyncd</span></div>
</td>
</tr>
</tbody>
</table>
</figure>
<p><strong>源码编译安装</strong><br />
从源码编译安装可以使用最新版的lsyncd程序，但必须要相应的依赖库文件和编译工具：<code>yum install lua lua-devel asciidoc cmake</code>。</p>
<p>从 <a href="http://code.google.com/p/lsyncd/downloads/list" target="_blank" rel="external">googlecode lsyncd</a> 上下载的<code>lsyncd-2.1.5.tar.gz</code>，直接<code>./configure</code>、<code>make &amp;&amp; make install</code>就可以了。</p>
<p>从github上下载<a href="https://github.com/axkibe/lsyncd/archive/master.zip" target="_blank" rel="external">lsyncd-master.zip</a> 的2.1.5版本使用的是 cmake 编译工具，无法<code>./configure</code>：</p>
<figure class="highlight">
<table>
<tbody>
<tr>
<td class="gutter">
<div class="line">1</div>
<div class="line">2</div>
<div class="line">3</div>
<div class="line">4</div>
</td>
<td class="code">
<div class="line"><span class="preprocessor"># uzip lsyncd-master.zip</span></div>
<div class="line"><span class="preprocessor"># cd lsyncd-master</span></div>
<div class="line"><span class="preprocessor"># cmake -DCMAKE_INSTALL_PREFIX=/usr/local/lsyncd-2.1.5</span></div>
<div class="line"><span class="preprocessor"># make &amp;&amp; make install</span></div>
</td>
</tr>
</tbody>
</table>
</figure>
<p>我这个版本编译时有个小bug，如果按照<code>INSTALL</code>在<code>build</code>目录中make，会提示：</p>
<figure class="highlight">
<table>
<tbody>
<tr>
<td class="gutter">
<div class="line">1</div>
<div class="line">2</div>
<div class="line">3</div>
<div class="line">4</div>
<div class="line">5</div>
<div class="line">6</div>
</td>
<td class="code">
<div class="line">[100%] Generating doc/lsyncd.1</div>
<div class="line">Updating the manpage</div>
<div class="line">a2x: failed: source file not found: doc/lsyncd.1.txt</div>
<div class="line">make[2]: <span class="keyword">*</span><span class="keyword">*</span><span class="keyword">*</span> [doc/lsyncd.1] Error 1</div>
<div class="line">make[1]: <span class="keyword">*</span><span class="keyword">*</span><span class="keyword">*</span> [CMakeFiles/manpage.dir/all] Error 2</div>
<div class="line">make: <span class="keyword">*</span><span class="keyword">*</span><span class="keyword">*</span> [all] Error 2</div>
</td>
</tr>
</tbody>
</table>
</figure>
<p>解决办法是要么直接在解压目录下cmake，不要<code>mkdir build</code>，要么在<code>CMakeList.txt</code>中搜索<code>doc</code>字符串，在前面加上<code>${PROJECT_SOURCE_DIR}</code>。</p>
<h2 id="2-2_lsyncd-conf">2.2 lsyncd.conf</h2>
<p>下面都是在编译安装的情况下操作。</p>
<h3 id="2-2-1_lsyncd同步配置">2.2.1 lsyncd同步配置</h3>
<figure class="highlight">
<table>
<tbody>
<tr>
<td class="gutter">
<div class="line">1</div>
<div class="line">2</div>
<div class="line">3</div>
<div class="line">4</div>
<div class="line">5</div>
<div class="line">6</div>
<div class="line">7</div>
<div class="line">8</div>
<div class="line">9</div>
<div class="line">10</div>
<div class="line">11</div>
<div class="line">12</div>
<div class="line">13</div>
<div class="line">14</div>
<div class="line">15</div>
<div class="line">16</div>
<div class="line">17</div>
<div class="line">18</div>
<div class="line">19</div>
<div class="line">20</div>
<div class="line">21</div>
<div class="line">22</div>
<div class="line">23</div>
</td>
<td class="code">
<div class="line"><span class="comment"># cd /usr/local/lsyncd-2.1.5</span></div>
<div class="line"><span class="comment"># mkdir etc var</span></div>
<div class="line"><span class="comment"># vi etc/lsyncd.conf</span></div>
<div class="line">settings {</div>
<div class="line"><span class="variable">logfile =</span><span class="string">&#8220;/usr/local/lsyncd-2.1.5/var/lsyncd.log&#8221;</span>,</div>
<div class="line"><span class="variable">statusFile =</span><span class="string">&#8220;/usr/local/lsyncd-2.1.5/var/lsyncd.status&#8221;</span>,</div>
<div class="line"><span class="variable">inotifyMode =</span> <span class="string">&#8220;CloseWrite&#8221;</span>,</div>
<div class="line"><span class="variable">maxProcesses =</span> <span class="number">7</span>,</div>
<div class="line">&#8212; <span class="variable">nodaemon =</span><span class="constant">true</span>,</div>
<div class="line">}</div>
<div class="line"></div>
<div class="line">sync {</div>
<div class="line">default.rsync,</div>
<div class="line"><span class="variable">source =</span> <span class="string">&#8220;/tmp/src&#8221;</span>,</div>
<div class="line"><span class="variable">target =</span> <span class="string">&#8220;/tmp/dest&#8221;</span>,</div>
<div class="line">&#8212; <span class="variable">excludeFrom =</span> <span class="string">&#8220;/etc/rsyncd.d/rsync_exclude.lst&#8221;</span>,</div>
<div class="line"><span class="variable">rsync =</span> {</div>
<div class="line"><span class="variable">binary =</span> <span class="string">&#8220;/usr/bin/rsync&#8221;</span>,</div>
<div class="line"><span class="variable">archive =</span> <span class="constant">true</span>,</div>
<div class="line"><span class="variable">compress =</span> <span class="constant">true</span>,</div>
<div class="line"><span class="variable">verbose =</span> <span class="constant">true</span></div>
<div class="line">}</div>
<div class="line">}</div>
</td>
</tr>
</tbody>
</table>
</figure>
<p>到这启动 lsycnd 就可以完成实时同步了，默认的许多参数可以满足绝大部分需求，非常简单。</p>
<h3 id="2-2-2_lsyncd-conf配置选项说明">2.2.2 lsyncd.conf配置选项说明</h3>
<p><strong>settings</strong><br />
里面是全局设置，<code>--</code>开头表示注释，下面是几个常用选项说明：</p>
<ul>
<li><code>logfile</code> 定义日志文件</li>
<li><code>stausFile</code> 定义状态文件</li>
<li><code>nodaemon=true</code> 表示不启用守护模式，默认</li>
<li><code>statusInterval</code> 将lsyncd的状态写入上面的statusFile的间隔，默认10秒</li>
<li><code>inotifyMode</code> 指定inotify监控的事件，默认是<code>CloseWrite</code>，还可以是<code>Modify</code>或<code>CloseWrite or Modify</code></li>
<li><code>maxProcesses</code> 同步进程的最大个数。假如同时有20个文件需要同步，而<code>maxProcesses = 8</code>，则最大能看到有8个rysnc进程</li>
<li><code>maxDelays</code> 累计到多少所监控的事件激活一次同步，即使后面的<code>delay</code>延迟时间还未到</li>
</ul>
<p><strong>sync</strong><br />
里面是定义同步参数，可以继续使用<code>maxDelays</code>来重写settings的全局变量。一般第一个参数指定<code>lsyncd</code>以什么模式运行：<code>rsync</code>、<code>rsyncssh</code>、<code>direct</code>三种模式：</p>
<ul>
<li><code>default.rsync</code> ：本地目录间同步，使用rsync，也可以达到使用ssh形式的远程rsync效果，或daemon方式连接远程rsyncd进程；<br />
<code>default.direct</code> ：本地目录间同步，使用<code>cp</code>、<code>rm</code>等命令完成差异文件备份；<br />
<code>default.rsyncssh</code> ：同步到远程主机目录，rsync的ssh模式，需要使用key来认证</li>
<li><code>source</code> 同步的源目录，使用绝对路径。</li>
<li><code>target</code> 定义目的地址.对应不同的模式有几种写法：<br />
<code>/tmp/dest</code> ：本地目录同步，可用于<code>direct</code>和<code>rsync</code>模式<br />
<code>172.29.88.223:/tmp/dest</code> ：同步到远程服务器目录，可用于<code>rsync</code>和<code>rsyncssh</code>模式，拼接的命令类似于<code>/usr/bin/rsync -ltsd --delete --include-from=- --exclude=* SOURCE TARGET</code>，剩下的就是rsync的内容了，比如指定username，免密码同步<br />
<code>172.29.88.223::module</code> ：同步到远程服务器目录，用于<code>rsync</code>模式<br />
三种模式的示例会在后面给出。</li>
<li><code>init</code> 这是一个优化选项，当<code>init = false</code>，只同步进程启动以后发生改动事件的文件，原有的目录即使有差异也不会同步。默认是<code>true</code></li>
<li><code>delay</code> 累计事件，等待rsync同步延时时间，默认15秒（最大累计到1000个不可合并的事件）。也就是15s内监控目录下发生的改动，会累积到一次rsync同步，避免过于频繁的同步。（可合并的意思是，15s内两次修改了同一文件，最后只同步最新的文件）</li>
<li><code>excludeFrom</code> 排除选项，后面指定排除的列表文件，如<code>excludeFrom = "/etc/lsyncd.exclude"</code>，如果是简单的排除，可以使用<code>exclude = LIST</code>。<br />
这里的排除规则写法与原生rsync有点不同，更为简单：</p>
<ul>
<li>监控路径里的任何部分匹配到一个文本，都会被排除，例如<code>/bin/foo/bar</code>可以匹配规则<code>foo</code></li>
<li>如果规则以斜线<code>/</code>开头，则从头开始要匹配全部</li>
<li>如果规则以<code>/</code>结尾，则要匹配监控路径的末尾</li>
<li><code>?</code>匹配任何字符，但不包括<code>/</code></li>
<li><code>*</code>匹配0或多个字符，但不包括<code>/</code></li>
<li><code>**</code>匹配0或多个字符，可以是<code>/</code></li>
</ul>
</li>
</ul>
<ul>
<li><code>delete</code> 为了保持target与souce完全同步，Lsyncd默认会<code>delete = true</code>来允许同步删除。它除了<code>false</code>，还有<code>startup</code>、<code>running</code>值，请参考 <a href="https://github.com/axkibe/lsyncd/wiki/Lsyncd%202.1.x%20%E2%80%96%20Layer%204%20Config%20%E2%80%96%20Default%20Behavior" target="_blank" rel="external">Lsyncd 2.1.x ‖ Layer 4 Config ‖ Default Behavior</a>。</li>
</ul>
<p><strong>rsync</strong><br />
（提示一下，<code>delete</code>和<code>exclude</code>本来都是<strong>rsync</strong>的选项，上面是配置在<strong>sync</strong>中的，我想这样做的原因是为了减少rsync的开销）</p>
<ul>
<li><code>bwlimit</code> 限速，单位kb/s，与rsync相同（这么重要的选项在文档里竟然没有标出）</li>
<li><code>compress</code> 压缩传输默认为<code>true</code>。在带宽与cpu负载之间权衡，本地目录同步可以考虑把它设为<code>false</code></li>
<li><code>perms</code> 默认保留文件权限。</li>
<li>其它rsync的选项</li>
</ul>
<p>其它还有rsyncssh模式独有的配置项，如<code>host</code>、<code>targetdir</code>、<code>rsync_path</code>、<code>password_file</code>，见后文示例。<code>rsyncOps={"-avz","--delete"}</code>这样的写法在2.1.*版本已经不支持。</p>
<p><code>lsyncd.conf</code>可以有多个<code>sync</code>，各自的source，各自的target，各自的模式，互不影响。</p>
<h2 id="2-3_启动lsyncd">2.3 启动lsyncd</h2>
<p>使用命令加载配置文件，启动守护进程，自动同步目录操作。</p>
<pre><code>lsyncd -<span class="built_in">log</span> Exec /usr/local/lsyncd-<span class="number">2.1</span>.<span class="number">5</span>/etc/lsyncd.<span class="keyword">conf</span>
</code></pre>
<h2 id="2-4_lsyncd-conf其它模式示例">2.4 lsyncd.conf其它模式示例</h2>
<p>以下配置本人都已经过验证可行，必须根据实际需要裁剪配置：</p>
<figure class="highlight">
<table>
<tbody>
<tr>
<td class="gutter">
<div class="line">1</div>
<div class="line">2</div>
<div class="line">3</div>
<div class="line">4</div>
<div class="line">5</div>
<div class="line">6</div>
<div class="line">7</div>
<div class="line">8</div>
<div class="line">9</div>
<div class="line">10</div>
<div class="line">11</div>
<div class="line">12</div>
<div class="line">13</div>
<div class="line">14</div>
<div class="line">15</div>
<div class="line">16</div>
<div class="line">17</div>
<div class="line">18</div>
<div class="line">19</div>
<div class="line">20</div>
<div class="line">21</div>
<div class="line">22</div>
<div class="line">23</div>
<div class="line">24</div>
<div class="line">25</div>
<div class="line">26</div>
<div class="line">27</div>
<div class="line">28</div>
<div class="line">29</div>
<div class="line">30</div>
<div class="line">31</div>
<div class="line">32</div>
<div class="line">33</div>
<div class="line">34</div>
<div class="line">35</div>
<div class="line">36</div>
<div class="line">37</div>
<div class="line">38</div>
<div class="line">39</div>
<div class="line">40</div>
<div class="line">41</div>
<div class="line">42</div>
<div class="line">43</div>
<div class="line">44</div>
<div class="line">45</div>
<div class="line">46</div>
<div class="line">47</div>
<div class="line">48</div>
<div class="line">49</div>
<div class="line">50</div>
<div class="line">51</div>
<div class="line">52</div>
<div class="line">53</div>
<div class="line">54</div>
<div class="line">55</div>
<div class="line">56</div>
<div class="line">57</div>
<div class="line">58</div>
<div class="line">59</div>
<div class="line">60</div>
<div class="line">61</div>
<div class="line">62</div>
<div class="line">63</div>
<div class="line">64</div>
<div class="line">65</div>
<div class="line">66</div>
<div class="line">67</div>
<div class="line">68</div>
<div class="line">69</div>
<div class="line">70</div>
<div class="line">71</div>
<div class="line">72</div>
<div class="line">73</div>
<div class="line">74</div>
<div class="line">75</div>
<div class="line">76</div>
<div class="line">77</div>
<div class="line">78</div>
<div class="line">79</div>
<div class="line">80</div>
<div class="line">81</div>
<div class="line">82</div>
<div class="line">83</div>
<div class="line">84</div>
<div class="line">85</div>
<div class="line">86</div>
<div class="line">87</div>
<div class="line">88</div>
<div class="line">89</div>
<div class="line">90</div>
<div class="line">91</div>
</td>
<td class="code">
<div class="line">settings {</div>
<div class="line"><span class="variable">logfile =</span><span class="string">&#8220;/usr/local/lsyncd-2.1.5/var/lsyncd.log&#8221;</span>,</div>
<div class="line"><span class="variable">statusFile =</span><span class="string">&#8220;/usr/local/lsyncd-2.1.5/var/lsyncd.status&#8221;</span>,</div>
<div class="line"><span class="variable">inotifyMode =</span> <span class="string">&#8220;CloseWrite&#8221;</span>,</div>
<div class="line"><span class="variable">maxProcesses =</span> <span class="number">8</span>,</div>
<div class="line">}</div>
<div class="line"></div>
<div class="line"></div>
<div class="line">&#8212; I. 本地目录同步，direct：cp/rm/mv。 适用：<span class="number">500</span>+万文件，变动不大</div>
<div class="line">sync {</div>
<div class="line">default.direct,</div>
<div class="line"><span class="variable">source =</span> <span class="string">&#8220;/tmp/src&#8221;</span>,</div>
<div class="line"><span class="variable">target =</span> <span class="string">&#8220;/tmp/dest&#8221;</span>,</div>
<div class="line"><span class="variable">delay =</span> <span class="number">1</span></div>
<div class="line"><span class="variable">maxProcesses =</span> <span class="number">1</span></div>
<div class="line">}</div>
<div class="line"></div>
<div class="line">&#8212; II. 本地目录同步，rsync模式：rsync</div>
<div class="line">sync {</div>
<div class="line">default.rsync,</div>
<div class="line"><span class="variable">source =</span> <span class="string">&#8220;/tmp/src&#8221;</span>,</div>
<div class="line"><span class="variable">target =</span> <span class="string">&#8220;/tmp/dest1&#8243;</span>,</div>
<div class="line"><span class="variable">excludeFrom =</span> <span class="string">&#8220;/etc/rsyncd.d/rsync_exclude.lst&#8221;</span>,</div>
<div class="line"><span class="variable">rsync =</span> {</div>
<div class="line"><span class="variable">binary =</span> <span class="string">&#8220;/usr/bin/rsync&#8221;</span>,</div>
<div class="line"><span class="variable">archive =</span> <span class="constant">true</span>,</div>
<div class="line"><span class="variable">compress =</span> <span class="constant">true</span>,</div>
<div class="line"><span class="variable">bwlimit =</span> <span class="number">2000</span></div>
<div class="line">}</div>
<div class="line">}</div>
<div class="line"></div>
<div class="line">&#8212; III. 远程目录同步，rsync模式 + rsyncd daemon</div>
<div class="line">sync {</div>
<div class="line">default.rsync,</div>
<div class="line"><span class="variable">source =</span> <span class="string">&#8220;/tmp/src&#8221;</span>,</div>
<div class="line"><span class="variable">target =</span> <span class="string">&#8220;syncuser@172.29.88.223::module1&#8243;</span>,</div>
<div class="line"><span class="variable">delete=</span><span class="string">&#8220;running&#8221;</span>,</div>
<div class="line"><span class="variable">exclude =</span> { <span class="string">&#8220;.*&#8221;</span>, <span class="string">&#8220;.tmp&#8221;</span> },</div>
<div class="line"><span class="variable">delay =</span> <span class="number">30</span>,</div>
<div class="line"><span class="variable">init =</span> <span class="constant">false</span>,</div>
<div class="line"><span class="variable">rsync =</span> {</div>
<div class="line"><span class="variable">binary =</span> <span class="string">&#8220;/usr/bin/rsync&#8221;</span>,</div>
<div class="line"><span class="variable">archive =</span> <span class="constant">true</span>,</div>
<div class="line"><span class="variable">compress =</span> <span class="constant">true</span>,</div>
<div class="line"><span class="variable">verbose =</span> <span class="constant">true</span>,</div>
<div class="line"><span class="variable">password_file =</span> <span class="string">&#8220;/etc/rsyncd.d/rsync.pwd&#8221;</span>,</div>
<div class="line"><span class="variable">_extra =</span> {<span class="string">&#8220;&#8211;bwlimit=200&#8243;</span>}</div>
<div class="line">}</div>
<div class="line">}</div>
<div class="line"></div>
<div class="line">&#8212; IV. 远程目录同步，rsync模式 + ssh shell</div>
<div class="line">sync {</div>
<div class="line">default.rsync,</div>
<div class="line"><span class="variable">source =</span> <span class="string">&#8220;/tmp/src&#8221;</span>,</div>
<div class="line"><span class="variable">target =</span> <span class="string">&#8220;172.29.88.223:/tmp/dest&#8221;</span>,</div>
<div class="line">&#8212; <span class="variable">target =</span> <span class="string">&#8220;root@172.29.88.223:/remote/dest&#8221;</span>,</div>
<div class="line">&#8212; 上面target，注意如果是普通用户，必须拥有写权限</div>
<div class="line"><span class="variable">maxDelays =</span> <span class="number">5</span>,</div>
<div class="line"><span class="variable">delay =</span> <span class="number">30</span>,</div>
<div class="line">&#8212; <span class="variable">init =</span> <span class="constant">true</span>,</div>
<div class="line"><span class="variable">rsync =</span> {</div>
<div class="line"><span class="variable">binary =</span> <span class="string">&#8220;/usr/bin/rsync&#8221;</span>,</div>
<div class="line"><span class="variable">archive =</span> <span class="constant">true</span>,</div>
<div class="line"><span class="variable">compress =</span> <span class="constant">true</span>,</div>
<div class="line"><span class="variable">bwlimit =</span> <span class="number">2000</span></div>
<div class="line">&#8212; <span class="variable">rsh =</span> <span class="string">&#8220;/usr/bin/ssh -p 22 -o StrictHostKeyChecking=no&#8221;</span></div>
<div class="line">&#8212; 如果要指定其它端口，请用上面的rsh</div>
<div class="line">}</div>
<div class="line">}</div>
<div class="line"></div>
<div class="line">&#8212; V. 远程目录同步，rsync模式 + rsyncssh，效果与上面相同</div>
<div class="line">sync {</div>
<div class="line">default.rsyncssh,</div>
<div class="line"><span class="variable">source =</span> <span class="string">&#8220;/tmp/src2&#8243;</span>,</div>
<div class="line"><span class="variable">host =</span> <span class="string">&#8220;172.29.88.223&#8221;</span>,</div>
<div class="line"><span class="variable">targetdir =</span> <span class="string">&#8220;/remote/dir&#8221;</span>,</div>
<div class="line"><span class="variable">excludeFrom =</span> <span class="string">&#8220;/etc/rsyncd.d/rsync_exclude.lst&#8221;</span>,</div>
<div class="line">&#8212; <span class="variable">maxDelays =</span> <span class="number">5</span>,</div>
<div class="line"><span class="variable">delay =</span> <span class="number">0</span>,</div>
<div class="line">&#8212; <span class="variable">init =</span> <span class="constant">false</span>,</div>
<div class="line"><span class="variable">rsync =</span> {</div>
<div class="line"><span class="variable">binary =</span> <span class="string">&#8220;/usr/bin/rsync&#8221;</span>,</div>
<div class="line"><span class="variable">archive =</span> <span class="constant">true</span>,</div>
<div class="line"><span class="variable">compress =</span> <span class="constant">true</span>,</div>
<div class="line"><span class="variable">verbose =</span> <span class="constant">true</span>,</div>
<div class="line"><span class="variable">_extra =</span> {<span class="string">&#8220;&#8211;bwlimit=2000&#8243;</span>},</div>
<div class="line">},</div>
<div class="line"><span class="variable">ssh =</span> {</div>
<div class="line"><span class="variable">port =</span> <span class="number">1234</span></div>
<div class="line">}</div>
<div class="line">}</div>
</td>
</tr>
</tbody>
</table>
</figure>
<p>上面的内容几乎涵盖了所有同步的模式，其中第<code>III</code>个要求像rsync一样配置rsyncd服务端，见本文开头。第<code>IV</code>、<code>V</code>配置ssh方式同步，达到的效果相同，但实际同步时你会发现每次同步都会提示输入ssh的密码，可以通过以下方法解决：</p>
<p>在远端被同步的服务器上开启ssh无密码登录，请注意用户身份：</p>
<figure class="highlight">
<table>
<tbody>
<tr>
<td class="gutter">
<div class="line">1</div>
<div class="line">2</div>
<div class="line">3</div>
<div class="line">4</div>
</td>
<td class="code">
<div class="line">user$ ssh-keygen -t rsa</div>
<div class="line">一路回车<span class="keyword">&#8230;</span></div>
<div class="line">user$ cd ~/.ssh</div>
<div class="line">user$ cat id_rsa.pub &gt;&gt; authorized_keys</div>
</td>
</tr>
</tbody>
</table>
</figure>
<p>把<code>id_rsa</code>私钥拷贝到执行lsyncd的机器上</p>
<figure class="highlight">
<table>
<tbody>
<tr>
<td class="gutter">
<div class="line">1</div>
<div class="line">2</div>
<div class="line">3</div>
</td>
<td class="code">
<div class="line">user<span class="variable">$ </span>chmod <span class="number">600</span> ~<span class="regexp">/.ssh/id</span>_rsa</div>
<div class="line">测试能否无密码登录</div>
<div class="line">user<span class="variable">$ </span>ssh user<span class="variable">@172</span>.<span class="number">29.88</span>.<span class="number">223</span></div>
</td>
</tr>
</tbody>
</table>
</figure>
<h1 id="3-_lsyncd的其它功能">3. lsyncd的其它功能</h1>
<p><code>lsyncd</code>的功能不仅仅是同步，官方手册 <a href="https://github.com/axkibe/lsyncd/wiki/Lsyncd%202.1.x%20%E2%80%96%20Layer%202%20Config%20%E2%80%96%20Advanced%20onAction" target="_blank" rel="external">Lsyncd 2.1.x ‖ Layer 2 Config ‖ Advanced onAction</a> 高级功能提到，还可以监控某个目录下的文件，根据触发的事件自己定义要执行的命令，example是监控某个某个目录，只要是有jpg、gif、png格式的文件参数，就把它们转成pdf，然后同步到另一个目录。正好在我运维的一个项目中有这个需求，现在都是在java代码里转换，还容易出现异常，通过lsyncd可以代替这样的功能。但，门槛在于要会一点点lua语言（根据官方example还是可以写出来）。</p>
<p>另外偶然想到个问题，同时设置了<code>maxDelays</code>和<code>delay</code>，当监控目录一直没有文件变化了，也会发生同步操作，虽然没有可rsync的文件。</p>
<p>TO-DO：</p>
<ul>
<li>其它同步工具：<a href="http://www.chinaxing.org/articles/linux/2013/04/18/2013-04-18-incrond-and-csync2.html" target="_blank" rel="external">csync2</a>，clsync，btsync，drdb 。</li>
<li>lsyncd双向同步：<a href="https://github.com/axkibe/lsyncd/wiki/Faq" target="_blank" rel="external">GlusterFS</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://bernieyu.com/2015/10/lsyncd-synchronize-realtime/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>在群晖NAS上搭建MantisBT Bug跟踪系统</title>
		<link>http://bernieyu.com/2015/07/install-mantis-bug-tracking-on-synology-nas/</link>
		<comments>http://bernieyu.com/2015/07/install-mantis-bug-tracking-on-synology-nas/#comments</comments>
		<pubDate>Fri, 10 Jul 2015 04:01:48 +0000</pubDate>
		<dc:creator><![CDATA[Bernie Yu]]></dc:creator>
				<category><![CDATA[IT技术]]></category>
		<category><![CDATA[Synology]]></category>
		<category><![CDATA[bug tracking]]></category>
		<category><![CDATA[mantis]]></category>

		<guid isPermaLink="false">http://bernieyu.com/?p=256</guid>
		<description><![CDATA[启用WEB服务 进入群晖的管理后台，打开控制页面，在里面打开WEB服务 安装MariaDB数据库，配置好roo ... <a class="more-link" href="http://bernieyu.com/2015/07/install-mantis-bug-tracking-on-synology-nas/">　　>>阅读全文&#60;&#60;</a>]]></description>
				<content:encoded><![CDATA[<ol>
<li>启用WEB服务<br />
进入群晖的管理后台，打开控制页面，在里面打开WEB服务<br />
<img class="alignnone size-full wp-image-257" src="http://bernieyu.com/wp-content/uploads/2015/07/201506261549467.png" alt="201506261549467" width="541" height="433" /></li>
<li>安装MariaDB数据库，配置好root账户的密码</li>
<li>安装MantisBT<br />
打开套件中心，找到MantisBT，进行安装。安装过程中要输入Mysql (MariaDB)的root账号和密码，安装过程中会自动创建MantisBT所需要的库表<br />
<img class="alignnone size-full wp-image-258" src="http://bernieyu.com/wp-content/uploads/2015/07/20150710110313.png" alt="20150710110313" width="617" height="437" /></li>
<li>配置MantisBT
<ul>
<li>打开http://synology_address/mantisbt，默认用户名：adminstrator，初始密码：root</li>
<li>现在数据库是用root登录的，为了数据库安全，在数据库里新建mantis用户，仅拥有对mantis库的权限。然后修改config_inc.php:
<pre>$g_hostname = 'localhost';
$g_db_type = 'mysql';
$g_database_name = 'mantis';
$g_db_username = 'mantis';
$g_db_password = 'mantis';
</pre>
</li>
<li>修改默认语言为简体中文：在config_inc.php中添加：
<pre>$g_default_language= 'chinese_simplified';</pre>
</li>
<li>mantis默认新用户都是要邮件激活的，因此还需要添加邮件支持。修改config_defaults_inc.php，把发信人修改为真正使用的发件邮箱地址（有些邮箱服务器会校验发件人地址和真实发件地址，不匹配有可能造成发信失败）
<pre>$g_administrator_email	= 'mantis@host.com';
$g_webmaster_email	= 'mantis@host.com';
$g_from_email			= 'mantis@host.com';
$g_return_path_email	= 'mantis@host.com';</pre>
<p>继续修改发件的smtp信息</p>
<pre>$g_phpMailer_method		= PHPMAILER_METHOD_SMTP;
$g_smtp_host			= 'smtp.exmail.qq.com';
$g_smtp_username = 'mantis@host.com';
$g_smtp_password = 'password';
$g_smtp_connection_mode = 'ssl';
$g_smtp_port = 465;</pre>
</li>
<li>登录到mantis里，新建管理员用户。然后以新建用户登录后，就可以禁用administrator，以保证安全。</li>
<li>Tips:
<ul>
<li>在library\phpmailer下是邮件发送组件，可以新建一个mailtest.php，然后在浏览器打开这个页面测试邮件发送是否正常：
<pre>&lt;?php
/**
 * @author [pooy] &lt;[pooy@pooy.net]&gt;
 * @blog  http://www.pooy.net
 */
require 'class.phpmailer.php';
 
$mail = new PHPMailer;
$mail-&gt;SMTPDebug = 1;
$mail-&gt;IsSMTP();                                      // Set mailer to use SMTP
 
$mail-&gt;Host = 'smtp.exmail.qq.com';  // Specify main and backup server
$mail-&gt;SMTPAuth = true;                               // Enable SMTP authentication
$mail-&gt;Username = 'mantis@host.com';                            // SMTP username
$mail-&gt;Port = 465;
$mail-&gt;Password = 'password';                           // SMTP password
$mail-&gt;SMTPSecure = 'ssl';                            // Enable encryption, 'ssl' also accepted
$mail-&gt;From = 'mantis@host.com';
 
$mail-&gt;FromName = 'Mailer Testing';
$mail-&gt;AddAddress('reciver@host.com');   
$mail-&gt;WordWrap = 50;                                 // Set word wrap to 50 characters
$mail-&gt;IsHTML(true);                                  // Set email format to HTML
 
$mail-&gt;Subject = 'Here is the subject';
$mail-&gt;Body    = 'This is the HTML message body &lt;b&gt;in bold!&lt;/b&gt;';
$mail-&gt;AltBody = 'This is the body in plain text for non-HTML mail clients';
 
if(!$mail-&gt;Send()) {
   echo 'Message could not be sent.';
   echo 'Mailer Error: ' . $mail-&gt;ErrorInfo;
   exit;
}
 
echo 'Message has been sent';
// To load the Chinese version
$mail-&gt;SetLanguage('cn', '/path_to_mantisbt/library/phpmailer/language');
?&gt;</pre>
</li>
<li>在scripts下的send_eamils.php，可以在控制台执行，测试在config_defaults_inc.php里的邮件配置是否能正常发送邮件
<pre>php -q /path_to_mantisbt/scripts/send_emails.php</pre>
</li>
</ul>
</li>
</ul>
</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://bernieyu.com/2015/07/install-mantis-bug-tracking-on-synology-nas/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>在群晖Nas上搭建Git服务器</title>
		<link>http://bernieyu.com/2015/06/built-git-server-on-synology-nas/</link>
		<comments>http://bernieyu.com/2015/06/built-git-server-on-synology-nas/#comments</comments>
		<pubDate>Fri, 26 Jun 2015 07:53:57 +0000</pubDate>
		<dc:creator><![CDATA[Bernie Yu]]></dc:creator>
				<category><![CDATA[Git]]></category>
		<category><![CDATA[IT技术]]></category>
		<category><![CDATA[Synology]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[安装]]></category>
		<category><![CDATA[黑群晖]]></category>

		<guid isPermaLink="false">http://bernieyu.com/?p=244</guid>
		<description><![CDATA[开启DSM的SSH远程功能 在“控制面板” →“终端机和SNMP”→“启动SSH功能” 建立Git用户 在“控 ... <a class="more-link" href="http://bernieyu.com/2015/06/built-git-server-on-synology-nas/">　　>>阅读全文&#60;&#60;</a>]]></description>
				<content:encoded><![CDATA[<ol>
<li>开启DSM的SSH远程功能<br />
在“控制面板” →“终端机和SNMP”→“启动SSH功能”<br />
<img class="size-full wp-image-245" src="http://bernieyu.com/wp-content/uploads/2015/06/20150626141436.png" alt="20150626141436" width="501" height="220" /></li>
<li>建立Git用户<br />
在“控制面板” →“用户账号”中添加Git专用用户。此处设置为git，用户组为users。权限为禁止访问任何共享文件夹<br />
<img class="alignnone size-full wp-image-246" src="http://bernieyu.com/wp-content/uploads/2015/06/20150626141852.png" alt="20150626141852" width="560" height="226" /></li>
<li>安装Git<br />
进入“套件中心”，找到Git Server，安装<br />
<img class="alignnone size-large wp-image-247" src="http://bernieyu.com/wp-content/uploads/2015/06/20150626142125-1024x517.png" alt="20150626142125" width="640" height="323" />安装完成后，打开Git设置界面，将之前添加的git用户设置为允许访问<img class="alignnone size-full wp-image-248" src="http://bernieyu.com/wp-content/uploads/2015/06/20150626142342.png" alt="20150626142342" width="599" height="351" /></li>
<li>创建Git库文件夹并设置权限<br />
以root用户SSH登录到DSM，在目标盘下创建git库目录</p>
<pre>cd /volume1
mkdir git</pre>
<p>创建测试项目</p>
<pre>cd git
mkdir test</pre>
<p>初始化git</p>
<pre>cd test
git init --bare</pre>
<p>设置目录权限</p>
<pre>chown -R git:users /volume1/git</pre>
</li>
<li>客户端：<br />
Windows：<br />
下载并安装  <a href="http://msysgit.github.io/">http://msysgit.github.io/</a><br />
Linux：</p>
<pre>yum install git-core</pre>
<p>或</p>
<pre>apt-get install git-core</pre>
<p>安装完成后，进入git-bash，测试</p>
<pre>git clone ssh://git@192.168.1.5/volume1/git/test</pre>
<p>测试添加文件并提交到本地库</p>
<pre>echo "t1.txt" &gt;t1.txt

git add t1.txt

git commit -m "add t1.txt"</pre>
<p>推送到远程库</p>
<pre>git push origin master</pre>
</li>
<li>设置SSH Key<br />
现在所有与远程库的交互都需要输入密码，除了不方便，还有不安全，不过可以使用SSH公钥来进行授权。<br />
在msysgit安装好后，已经生成了公钥和密钥。在git-bash中查看：</p>
<pre>$ ls ~/.ssh
id_rsa  id_rsa.pub  known_hosts</pre>
<p>其中，id_rsa就是私钥，id_rsa.pub则是公钥。把公钥复制到远程服务器：</p>
<pre>$ scp -P 9822 ~/.ssh/id_rsa.pub  root@192.168.1.5:/volume1/homes/git/.</pre>
<p>这里用的不是SSH标准的22端口，而是9822。如果是标准端口，则不用输入-P参数<br />
把公钥内容追加到authorized_keys</p>
<pre>mkdir /volume1/homes/git/.ssh
cat /volume1/homes/git/id_rsa.john.pub &gt;&gt; /volume1/homes/git/.ssh/authorized_keys</pre>
<p>更改权限</p>
<pre>chown -R git:users /volume1/homes/git/.ssh
chmod 644 /volume1/homes/git/.ssh/authorized_keys</pre>
<p>再与远程库交互就不会再要求输入密码了。</li>
<li>配置SourceTree的SSH Key<br />
使用SourceTree做客户端的话，SSH Key的配置有一些不同。<br />
首先需要在“工具”→“选项”→“一般”中，将SSH客户端设置为“PuTTY/Plink”<br />
<img class="alignnone size-full wp-image-249" src="http://bernieyu.com/wp-content/uploads/2015/06/20150626154646.png" alt="20150626154646" width="542" height="338" /><br />
然后进入“工具”→“创建或导入SSH密钥”<br />
<img class="alignnone size-full wp-image-250" src="http://bernieyu.com/wp-content/uploads/2015/06/20150626154946.png" alt="20150626154946" width="492" height="476" /><br />
其中“Generate”是生成新的密钥对，“Load”则是读取已经存在的私钥（比如上面git-bash里已经生成的私钥。<br />
生成或读取后，分别保存公钥和私钥。私钥由客户端使用，公钥则需要添加到服务上的authorized_keys文件里。<br />
在服务器端添加成功后，就可以不用再输入密码了。</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://bernieyu.com/2015/06/built-git-server-on-synology-nas/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Android SDK在线更新镜像服务器</title>
		<link>http://bernieyu.com/2015/06/android-sdk-update-mirror/</link>
		<comments>http://bernieyu.com/2015/06/android-sdk-update-mirror/#comments</comments>
		<pubDate>Wed, 24 Jun 2015 04:19:30 +0000</pubDate>
		<dc:creator><![CDATA[Bernie Yu]]></dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[IT技术]]></category>

		<guid isPermaLink="false">http://bernieyu.com/?p=241</guid>
		<description><![CDATA[中国科学院开源协会镜像站地址: IPV4/IPV6: http://mirrors.opencas.cn 端口 ... <a class="more-link" href="http://bernieyu.com/2015/06/android-sdk-update-mirror/">　　>>阅读全文&#60;&#60;</a>]]></description>
				<content:encoded><![CDATA[<ol>
<li>中国科学院开源协会镜像站地址:
<ul>
<li>IPV4/IPV6: <code>http://mirrors.opencas.cn</code> 端口：80</li>
<li>IPV4/IPV6: <code>http://mirrors.opencas.org</code> 端口：80</li>
<li>IPV4/IPV6: <code>http://mirrors.opencas.ac.cn</code> 端口：80</li>
</ul>
</li>
<li>上海GDG镜像服务器地址:<code>http://sdk.gdgshanghai.com</code> 端口：8000</li>
<li>北京化工大学镜像服务器地址:
<ul>
<li>IPv4: <code>http://ubuntu.buct.edu.cn/</code> 端口：80</li>
<li>IPv4: <code>http://ubuntu.buct.cn/</code> 端口：80</li>
<li>IPv6: <code>http://ubuntu.buct6.edu.cn/</code> 端口：80</li>
</ul>
</li>
<li>大连东软信息学院镜像服务器地址:<code>http://mirrors.neusoft.edu.cn</code> 端口：80</li>
</ol>
<p>&nbsp;</p>
<p><strong>使用方法</strong>：</p>
<ol>
<li>启动 Android SDK Manager ，打开主界面，依次选择『<strong>Tools</strong>』、『<strong>Options&#8230;</strong>』，弹出『<strong>Android SDK Manager &#8211; Settings</strong>』窗口；</li>
<li>在『<strong>Android SDK Manager &#8211; Settings</strong>』窗口中，在『<strong>HTTP Proxy Server」和「HTTP Proxy Port</strong>』输入框内填入上面镜像服务器地址(<strong>不包含http://</strong>，如下图)和端口，并且选中『<strong>Force https://&#8230; sources to be fetched using http://&#8230;</strong>』复选框。设置完成后单击『<strong>Close</strong>』按钮关闭『<strong>Android SDK Manager &#8211; Settings</strong>』窗口返回到主界面；</li>
<li>依次选择『<strong>Packages</strong>』、『<strong>Reload</strong>』。</li>
</ol>
<p>&nbsp;</p>
<p>转自：http://www.androiddevtools.cn/</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://bernieyu.com/2015/06/android-sdk-update-mirror/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>在Windows下搭建基于nginx的视频直播和点播系统</title>
		<link>http://bernieyu.com/2015/06/build-video-live-and-vod-with-nginx-rtmp-on-windows/</link>
		<comments>http://bernieyu.com/2015/06/build-video-live-and-vod-with-nginx-rtmp-on-windows/#comments</comments>
		<pubDate>Fri, 19 Jun 2015 09:00:27 +0000</pubDate>
		<dc:creator><![CDATA[Bernie Yu]]></dc:creator>
				<category><![CDATA[IT技术]]></category>
		<category><![CDATA[ffmpeg]]></category>
		<category><![CDATA[ffplay]]></category>
		<category><![CDATA[hls]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[rtmp]]></category>
		<category><![CDATA[yamdi]]></category>
		<category><![CDATA[录制]]></category>
		<category><![CDATA[直播]]></category>

		<guid isPermaLink="false">http://bernieyu.com/?p=234</guid>
		<description><![CDATA[一、软件准备 由于nginx原生是为linux服务的，因此官方并没有编译好的windows版本可以下载，要在w ... <a class="more-link" href="http://bernieyu.com/2015/06/build-video-live-and-vod-with-nginx-rtmp-on-windows/">　　>>阅读全文&#60;&#60;</a>]]></description>
				<content:encoded><![CDATA[<h2>一、软件准备</h2>
<p style="padding-left: 30px;">由于nginx原生是为linux服务的，因此官方并没有编译好的windows版本可以下载，要在windows上使用nginx，要么下载源码进行编译，要么使用其他人已经编译好的文件。</p>
<p style="padding-left: 30px;">而要让nginx支持视频直播和点播，还需要第三方的nginx模块：nginx-rtmp-module</p>
<p style="padding-left: 30px;">所幸，已经有大神做好了nginx的编译，而且集成了很多nginx模块，其中就已经包括了<a href="https://github.com/arut/nginx-rtmp-module">nginx-rtmp-module</a>。</p>
<p style="padding-left: 30px;">下载地址：<a href="http://nginx-win.ecsds.eu">http://nginx-win.ecsds.eu</a>/，详细说明可参见：<a href="http://nginx-win.ecsds.eu/download/Readme%20nginx-win%20version.txt">Readme nginx-win version.txt</a></p>
<p style="padding-left: 30px;">我下载的是<a href="http://nginx-win.ecsds.eu/download/nginx%201.7.11.3%20Gryphon.zip">nginx 1.7.11.3 Gryphon</a>这个版本。</p>
<p style="padding-left: 30px;">这个网站同时也提供了vcredist的下载（<a href="http://nginx-win.ecsds.eu/download/vcredist_x86.exe">x86</a>，<a href="http://nginx-win.ecsds.eu/download/vcredist_x64.exe">x64</a>），以避免运行nginx时出现缺少库的错误。</p>
<p style="padding-left: 30px;">另外还要下载<a href="https://github.com/arut/nginx-rtmp-module/blob/master/stat.xsl"> stat.xsl</a> 用于显示当前ngix-rtmp服务状态</p>
<p style="padding-left: 30px;">另外还需要下载ffmpeg、ffplay、yamdi：</p>
<p style="padding-left: 30px;">总结如下：</p>
<p style="padding-left: 30px;">1. <a href="http://nginx-win.ecsds.eu/download/nginx%201.7.11.3%20Gryphon.zip">nginx 1.7.11.3 Gryphon</a></p>
<p style="padding-left: 30px;">2. <a href="https://github.com/arut/nginx-rtmp-module/blob/master/stat.xsl">stat.xsl</a></p>
<p style="padding-left: 30px;">3. <a href="http://ffmpeg.zeranoe.com/builds/win32/static/ffmpeg-20150619-git-bb3703a-win32-static.7z">ffmpeg、ffplay</a></p>
<p style="padding-left: 30px;">4. <a href="http://sourceforge.net/projects/yamdi/files/latest/download?source=files">yamdi</a></p>
<h2>二、Nginx 配置</h2>
<p style="padding-left: 30px;"> 1. nginx配置</p>
<pre>worker_processes  1;

error_log  logs/error.log debug;

events {
    worker_connections  1024;
}

rtmp {
    server {
        listen 1935;

        application hls {
             live on;  #启用rtmp直播
                       #地址为rtmp://[server]:[rtmp_port]/[app]/[stream]
             hls on;   #启用hls直播
                       #地址为http://[server]:[http_port]/[app]/[stream].m3u8
                       #需要配合下面http段设置使用
             hls_path nginx-rtmp-module/tmp/app/;
             hls_fragment 5s;
             recorder rec {  #启用录制
               record all manual;  #手动控制录制启停
               record_suffix _rec.flv;
               record_path nginx-rtmp-module/tmp/rec/;  #录制保存地址
               record_unique on;
           }
       }
       application vod2{  #rtmp点播
       		play nginx-rtmp-module/tmp/rec/;    
       }
    }
}

http {
    server {
        listen      18080;

        location /stat {  #服务器状态
            rtmp_stat all;
            rtmp_stat_stylesheet stat.xsl;
        }

        location /stat.xsl {
            root nginx-rtmp-module/;
        }

        location /control { #控制器
            rtmp_control all;
        }
        
	location /hls/ {  #hls直播地址
           #server hls fragments
           types{
             application/vnd.apple.mpegurl m3u8;
             video/mp2t ts;
           }
           alias nginx-rtmp-module/tmp/app/;
           expires -1;
        }

        location /vod/{  #hls点播地址
            alias nginx-rtmp-module/tmp/rec/;
        }

        location / {
            root nginx-rtmp-module/test/www/;
        }
    }
}
</pre>
<h2>三、测试</h2>
<p style="padding-left: 30px;">1. 启动nginx</p>
<pre>start nginx_1.7.11.3_Gryphon\nginx</pre>
<p style="padding-left: 30px;">2. 推送rtmp流到nginx-rtmp</p>
<pre>start ffmpeg\ffmpeg -re -i rtmp://live.hkstv.hk.lxdns.com/live/hks -vcodec libx264 -preset:v ultrafast -tune:v zerolatency -acodec copy -f flv rtmp://localhost:1935/hls/mystream -loglevel quiet</pre>
<p style="padding-left: 30px;">3. rtmp直播</p>
<pre>ffmpeg\ffplay "rtmp://127.0.0.1:1935/hls/mystream"
</pre>
<p style="padding-left: 30px;">4. hls 直播</p>
<pre>ffmpeg\ffplay "http://127.0.0.1:18080/hls/mystream.m3u8"</pre>
<p style="padding-left: 30px;">5. 开始录制</p>
<pre>http://127.0.0.1:18080/control/record/start?app=hls&amp;name=mystream&amp;rec=rec</pre>
<p style="padding-left: 30px;">6. 停止录制</p>
<pre>http://127.0.0.1:18080/control/record/stop?app=hls&amp;name=mystream&amp;rec=rec</pre>
<p style="padding-left: 30px;">7. 为rtmp点播文件添加索引，否则文件在播放时进度条不能拖动，假定刚才录制的文件名为mystream-1428384476_rec.flv</p>
<pre>yamdi\yamdi -i nginx_1.7.11.3_Gryphon\nginx-rtmp-module\tmp\rec\mystream-1428384476_rec.flv -o nginx_1.7.11.3_Gryphon\nginx-rtmp-module\tmp\rec\mystream-1428384476_rec_idx.flv</pre>
<p style="padding-left: 30px;">8. rtmp点播</p>
<pre>ffmpeg\ffplay "rtmp://127.0.0.1:1935/vod2/mystream-1428384476_rec_idx.flv"</pre>
<p style="padding-left: 30px;">9. 制作hls点播分片文件</p>
<pre>ffmpeg\ffmpeg -i E:\video-nginx\nginx_1.7.11.3_Gryphon\nginx-rtmp-module\tmp\rec\mystream-1428384476_rec.flv -acodec copy -bsf:a h264_mp4toannexb -g 105 -vcodec libx264 -vprofile baseline -bf 0 -bufsize 850k -bsf:v dump_extra -map 0 -f segment -segment_format mpegts -segment_list "E:\video-nginx\nginx_1.7.11.3_Gryphon\nginx-rtmp-module\tmp\rec\mystream-1428384476_rec\mystream-1428384476_rec.m3u8" -segment_time 10 E:\video-nginx\nginx_1.7.11.3_Gryphon\nginx-rtmp-module\tmp\rec\mystream-1428384476_rec\mystream-1428384476_rec-%d.ts</pre>
<p style="padding-left: 30px;">10. hls 点播</p>
<pre>ffplay "http://127.0.0.1:8080/vod/mystream-1428384476_rec/mystream-1428384476_rec.m3u8"</pre>
]]></content:encoded>
			<wfw:commentRss>http://bernieyu.com/2015/06/build-video-live-and-vod-with-nginx-rtmp-on-windows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VPS搭建LNMP过程全记录</title>
		<link>http://bernieyu.com/2015/06/build-nginx-mysql-php-full-record/</link>
		<comments>http://bernieyu.com/2015/06/build-nginx-mysql-php-full-record/#comments</comments>
		<pubDate>Tue, 09 Jun 2015 08:56:47 +0000</pubDate>
		<dc:creator><![CDATA[Bernie Yu]]></dc:creator>
				<category><![CDATA[IT技术]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[vps]]></category>
		<category><![CDATA[安装]]></category>

		<guid isPermaLink="false">http://bernieyu.com/?p=227</guid>
		<description><![CDATA[最近有朋友新买一个VPS，让帮忙搭建服务器（Linux + Nginx + MySQL + PHP）。 本来觉 ... <a class="more-link" href="http://bernieyu.com/2015/06/build-nginx-mysql-php-full-record/">　　>>阅读全文&#60;&#60;</a>]]></description>
				<content:encoded><![CDATA[<p>最近有朋友新买一个VPS，让帮忙搭建服务器（Linux + Nginx + MySQL + PHP）。<br />
本来觉得手到擒来的事，可操作起来却发现有些东西记忆已经模糊了。帮朋友弄好后，赶紧把过程记下来，以备后查。</p>
<ol>
<li>更新系统
<ul>
<li>
<pre>apt-get update
apt-get upgrade</pre>
</li>
</ul>
</li>
<li>安装MySQL
<ul>
<li>
<pre>apt-get install mysql-server mysql-client</pre>
<p>MySQL 安全设置</p>
<pre>mysql_secure_installation</pre>
<p>过程中会询问是否更改 root密码，是否移除匿名用户，是否禁止root远程登录等。</li>
</ul>
</li>
<li>安装Nginx
<ul>
<li>
<pre>apt-get install nginx
service nginx start</pre>
<p>如果没有service命令，则使用</p>
<pre>/etc/init.d/nginx start</pre>
<p>直接访问IP地址，验证nginx安装是否成功<br />
<img class="alignnone size-full wp-image-229" src="http://bernieyu.com/wp-content/uploads/2015/06/20150609154658.png" alt="20150609154658" width="390" height="181" /></li>
</ul>
</li>
<li>安装PHP
<ul>
<li>
<pre>apt-get install php5-fpm php5-gd php5-mysql php5-curl</pre>
<p>安装完毕之后，查看PHP的版本，验证安装是否成功 ：</p>
<pre>root@vultr:/www# php5-fpm -v
PHP 5.3.10-1ubuntu3.18 (fpm-fcgi) (built: Apr 17 2015 15:08:33)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies</pre>
</li>
</ul>
</li>
<li>配置PHP-FPM
<ul>
<li>编辑/etc/php5/fpm/php.ini
<pre>vi /etc/php5/fpm/php.ini</pre>
<pre>cgi.fix_pathinfo=0

error_reporting =E_ALL | E_STRICT

display_errors = On

log_errors = On
error_log = /var/log/php_error.log</pre>
</li>
<li>编辑 /etc/php5/fpm/pool.d/www.conf
<pre>vi /etc/php5/fpm/pool.d/www.conf</pre>
<pre>user = www-data
group = www-data

;listen = 127.0.0.1:9000
listen = /var/run/php5-fpm.sock
listen.owner = www-data
listen.group = www-data
listen.mode = 0660

pm.status_path = /fpm_status</pre>
</li>
<li>重启php5-fpm
<pre>service php5-fpm restart</pre>
</li>
</ul>
</li>
<li>配置Nginx
<ul>
<li>编辑/etc/nginx/nginx.conf
<pre>user  www-data;
worker_processes  4;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    server_tokens off;

    gzip  on;
    gzip_disable "msie6";
    gzip_buffers 4 16K;
    gzip_comp_level 5;
    gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png application/javascript;
    gzip_vary on;
    include /etc/nginx/sites-available/*.conf;
}</pre>
</li>
</ul>
</li>
<li>配置网站
<ul>
<li>新建/www/test目录
<pre>mkdir /www
mkdir /www/test</pre>
</li>
<li>新建index.php
<pre>vi /www/test/index.php</pre>
<pre>&lt;?php

phpinfo();

?&gt;</pre>
</li>
<li>更改目录权限
<pre>chown -R www-data:www-data /www/test</pre>
</li>
<li>新建网站配置
<pre>vi /etc/nginx/conf.d/www.test.com.conf</pre>
<pre>server {
    listen       80;
    server_name  www.test.com;

    access_log /var/log/nginx/www.test.com.access.log main;
    error_log  /var/log/nginx/www.test.com.error.log warn;

    error_page  404              /404.html;
    error_page  500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    location / {
        root /www/test;
        index  index.html index.htm index.php;
        #WordPress伪静态,不需要可以删除
        if (-f $request_filename/index.html){
                rewrite (.*) $1/index.html break;
        }
        if (-f $request_filename/index.php){
                rewrite (.*) $1/index.php;
        }
        if (!-f $request_filename){
                rewrite (.*) /index.php;
        }
    }

    #fpm_status,可通过www.test.com/fpm_status查看fpm状态，添加?full参数可查看详细状态。
    #正式上线时需要注释掉此段
    location ~ ^/(fpm_status)$ {
     access_log off;
     include fastcgi_params;
     fastcgi_pass unix:/var/run/php5-fpm.sock;
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

    location ~ \.php$ {
        proxy_buffers 8 16k;
        proxy_buffer_size 32k;
        root   /www/test;
        # With php5-fpm:
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}
</pre>
</li>
<li>链接到sites-available
<pre>ln -s /etc/nginx/conf.d/www.test.com.conf /etc/nginx/sites-available/www.test.com.conf</pre>
</li>
<li>测试nginx配置
<pre>nginx -t</pre>
<p>如果配置文件正常，则显示：</p>
<pre>nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful</pre>
<p>如果报错，则检查配置文件</li>
<li>待一切正常后，重启nginx
<pre>service nginx restart</pre>
</li>
<li>此时访问www.test.com，会出现PHP运行信息<br />
<img class="alignnone size-medium wp-image-230" src="http://bernieyu.com/wp-content/uploads/2015/06/20150609164645-300x236.png" alt="20150609164645" width="300" height="236" /></li>
<li>访问 www.test.com/fpm_status 或者 www.test.com/fpm_status?full 可以查看fpm状态</li>
</ul>
</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://bernieyu.com/2015/06/build-nginx-mysql-php-full-record/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>解决Chrome升级到42版本后安全控件不可用的问题</title>
		<link>http://bernieyu.com/2015/06/resolve-chrome-update-to-version-42-security-control-not-available/</link>
		<comments>http://bernieyu.com/2015/06/resolve-chrome-update-to-version-42-security-control-not-available/#comments</comments>
		<pubDate>Tue, 02 Jun 2015 06:27:28 +0000</pubDate>
		<dc:creator><![CDATA[Bernie Yu]]></dc:creator>
				<category><![CDATA[IT技术]]></category>
		<category><![CDATA[chrome]]></category>
		<category><![CDATA[安全控件]]></category>
		<category><![CDATA[浏览器]]></category>

		<guid isPermaLink="false">http://bernieyu.com/?p=221</guid>
		<description><![CDATA[Chrome升级到最新的42版本后，由于默认停止对NPAPI插件的支持，因此导致种种安全控件不再可用。 解决方 ... <a class="more-link" href="http://bernieyu.com/2015/06/resolve-chrome-update-to-version-42-security-control-not-available/">　　>>阅读全文&#60;&#60;</a>]]></description>
				<content:encoded><![CDATA[<p>Chrome升级到最新的42版本后，由于默认停止对NPAPI插件的支持，因此导致种种安全控件不再可用。</p>
<p>解决方法1：</p>
<p>使用ie浏览器</p>
<p>解决方法2：</p>
<p>回退chrome版本</p>
<p>解决方法3：</p>
<p>在Chrome地址栏输入</p>
<pre>chrome://flags/</pre>
<p>在打开的配置页面中启用 NPAPI 插件即可。</p>
<p><a href="http://bernieyu.com/wp-content/uploads/2015/06/20150602142558.png"><img class="alignnone size-full wp-image-222" src="http://bernieyu.com/wp-content/uploads/2015/06/20150602142558.png" alt="20150602142558" width="289" height="91" /></a> <a href="http://bernieyu.com/wp-content/uploads/2015/06/20150602142625.png"><img class="alignnone size-full wp-image-223" src="http://bernieyu.com/wp-content/uploads/2015/06/20150602142625.png" alt="20150602142625" width="212" height="62" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://bernieyu.com/2015/06/resolve-chrome-update-to-version-42-security-control-not-available/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
