<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Posts on Siwei&#39;s site.</title>
    <link>https://xusiwei.github.io/post/</link>
    <description>Recent content in Posts on Siwei&#39;s site.</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>zh-CN</language>
    <lastBuildDate>Sun, 19 Apr 2020 21:28:53 +0800</lastBuildDate>
    
	<atom:link href="https://xusiwei.github.io/post/index.xml" rel="self" type="application/rss+xml" />
    
    
    <item>
      <title>Effective C&#43;&#43;（第三版）第三章笔记</title>
      <link>https://xusiwei.github.io/post/2020/04/effective-cpp-notes3/</link>
      <pubDate>Sun, 19 Apr 2020 21:28:53 +0800</pubDate>
      
      <guid>https://xusiwei.github.io/post/2020/04/effective-cpp-notes3/</guid>
      <description>资源管理 13. 以对象管理资源 RAII（Resource Acquisition Is Initialization），通俗的说就是用类的构造函数和和析构函数管理资源。 C++98 有 auto_ptr</description>
    </item>
    
    <item>
      <title>Effective C&#43;&#43;（第三版）第二章笔记</title>
      <link>https://xusiwei.github.io/post/2020/02/effective-cpp-notes2/</link>
      <pubDate>Tue, 25 Feb 2020 20:08:22 +0800</pubDate>
      
      <guid>https://xusiwei.github.io/post/2020/02/effective-cpp-notes2/</guid>
      <description>构造、析构、赋值运算符 5. 了解C++默默编写并调用哪些函数 一个空的类，如果你没有声明，编译器会为它声明： 默认构造函数 拷贝构造函数 赋值运算符函数</description>
    </item>
    
    <item>
      <title>从开源镜像站下载Android系统源码</title>
      <link>https://xusiwei.github.io/post/2020/02/sync-aosp-code-from-mirror-site/</link>
      <pubDate>Fri, 07 Feb 2020 20:42:51 +0800</pubDate>
      
      <guid>https://xusiwei.github.io/post/2020/02/sync-aosp-code-from-mirror-site/</guid>
      <description>国内可以用来下载Andorid源码的开源镜像站有： 科大开源镜像站 清华开源镜像站 Tips: 不同地区（或不同运营商）的网络，从这两个镜像站下载代码的速度</description>
    </item>
    
    <item>
      <title>Effective C&#43;&#43;（第三版）第一章笔记</title>
      <link>https://xusiwei.github.io/post/2020/02/effective-cpp-notes/</link>
      <pubDate>Sat, 01 Feb 2020 12:04:52 +0800</pubDate>
      
      <guid>https://xusiwei.github.io/post/2020/02/effective-cpp-notes/</guid>
      <description>《Effective C++》是Scott Meyers的著名技术著作，它开创了Effective系列的技术图书， 包括后来的《Effective</description>
    </item>
    
    <item>
      <title>用Travis CI自动化Hugo生成及GitHub Pages部署</title>
      <link>https://xusiwei.github.io/post/2019/10/hugo-github-pages-with-travis-ci/</link>
      <pubDate>Fri, 18 Oct 2019 22:58:33 +0800</pubDate>
      
      <guid>https://xusiwei.github.io/post/2019/10/hugo-github-pages-with-travis-ci/</guid>
      <description>用Travis CI自动化Hugo生成及GitHub Pages部署 背景 使用Hugo作为个人博客生成器有一段时间了，博客原始文稿的markdow</description>
    </item>
    
    <item>
      <title>Raspberry Pi 使用科大镜像源</title>
      <link>https://xusiwei.github.io/post/2016/raspberry-pi-use-ustc-mirror/</link>
      <pubDate>Sat, 26 Mar 2016 18:40:13 +0800</pubDate>
      
      <guid>https://xusiwei.github.io/post/2016/raspberry-pi-use-ustc-mirror/</guid>
      <description>&lt;p&gt;&lt;a href=&#34;http://mirrors.ustc.edu.cn/&#34;&gt;科大开源镜像站&lt;/a&gt;提供了raspbian的软件包镜像，国内的用户可以选择改用科大镜像站作为更新源。&lt;/p&gt;

&lt;p&gt;科大镜像站官方已经提供了一份&lt;a href=&#34;https://lug.ustc.edu.cn/wiki/mirrors/help/raspbian&#34;&gt;帮助文档&lt;/a&gt;，用于指导用户如何使用科大镜像更新raspbian。
但这份文档是基于 wheezy 的，最新的jessie版可以参考本文。&lt;/p&gt;

&lt;h2 id=&#34;具体做法&#34;&gt;具体做法&lt;/h2&gt;

&lt;p&gt;修改之前，最好先备份原始的配置文件。例如，使用如下命令将两个源配置文件拷贝到HOME目录。&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;cp /etc/apt/sources.list ~
cp /etc/apt/sources.d/raspi.list ~
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;或者直接在原来配置文件的基础上修改，但将原有的配置全部注释掉（使用#注释）。&lt;/p&gt;

&lt;h3 id=&#34;修改-source-list&#34;&gt;修改 source.list&lt;/h3&gt;

&lt;p&gt;更新后的&lt;code&gt;/etc/apt/sources.list&lt;/code&gt;：&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;#deb http://mirrordirector.raspbian.org/raspbian/ jessie main contrib non-free rpi
# Uncomment line below then &#39;apt-get update&#39; to enable &#39;apt-get source&#39;
#deb-src http://archive.raspbian.org/raspbian/ jessie main contrib non-free rpi

# use ustc mirror:
deb http://mirrors.ustc.edu.cn/raspbian/raspbian/ jessie main contrib non-free rpi
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;实际修改是，将&lt;code&gt;mirrordirector.raspbian.org&lt;/code&gt;替换为&lt;code&gt;mirrors.ustc.edu.cn/raspbian/&lt;/code&gt;。&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Raspberry Pi 3 无显示器 安装指南</title>
      <link>https://xusiwei.github.io/post/2016/raspberry-pi-headless-setup/</link>
      <pubDate>Sat, 26 Mar 2016 09:31:01 +0800</pubDate>
      
      <guid>https://xusiwei.github.io/post/2016/raspberry-pi-headless-setup/</guid>
      <description>&lt;p&gt;本文记录了——在没有显示器、键盘的条件下，如何通过网线为树梅派（后面简称pi）安装系统。&lt;/p&gt;

&lt;p&gt;实验环境如下图。&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://xusiwei.github.io/post/2016/raspi-rj45-laptop.png&#34; alt=&#34;raspberrypi-rj45-laptop&#34; /&gt;&lt;/p&gt;

&lt;h2 id=&#34;下载系统镜像&#34;&gt;下载系统镜像&lt;/h2&gt;

&lt;p&gt;官网的&lt;a href=&#34;https://www.raspberrypi.org/downloads&#34;&gt;下载页面&lt;/a&gt;可以找到pi的系统镜像。&lt;/p&gt;

&lt;p&gt;官方首推新手使用的是NOOBS和raspbian，而NOOBS和Raspbian都提供了完整版和Lite版。&lt;/p&gt;

&lt;p&gt;NOOBS的完整版是包含了Raspbian，可以离线安装raspbian。Lite版仅有一个系统安装程序，需要连接网络才能安装具体的操作系统。&lt;/p&gt;

&lt;p&gt;Raspbian的完整版是一个完整的桌面镜像，Lite版预装的软件包要少一些（联网后可以继续安装）。&lt;/p&gt;

&lt;p&gt;我下载的是&lt;a href=&#34;http://director.downloads.raspberrypi.org/raspbian/images/raspbian-2016-03-18/2016-03-18-raspbian-jessie.zip&#34;&gt;RASPBIAN JESSIE&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;下载完成后解压zip文件，将会得到一个img文件。&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>NGINX的并发模型</title>
      <link>https://xusiwei.github.io/post/2016/nginx-concurrency-model/</link>
      <pubDate>Wed, 09 Mar 2016 23:38:56 +0800</pubDate>
      
      <guid>https://xusiwei.github.io/post/2016/nginx-concurrency-model/</guid>
      <description>&lt;h2 id=&#34;apache-的并发模型&#34;&gt;Apache 的并发模型&lt;/h2&gt;

&lt;p&gt;Apache 的早期版本的并发模型是 one process per connection，也是早期Unix服务端的主流模型：
主进程accept阻塞在listen fd上，有新的HTTP请求到来时（accept返回connection fd），主进程fork一个服务进程，
专门为该连接服务，HTTP会话结束退出此进程。&lt;/p&gt;

&lt;p&gt;Apache 后来的版本，改用one thread per connection，改用单独一个线程为客户端连接提供服务。
这个模式和之前版本的一样，listen fd和connection fd用的都是阻塞模式。&lt;/p&gt;

&lt;p&gt;使用阻塞模式的好处是，逻辑清晰，编程模型简单。process per connection的好处还有可以保证客户端连接的稳定性
（据说早期Unix的某些版本上多进程模型并不稳定），同时也保证了安全性（即使客户端通过hack手段在connection上拿到了shell也只能控制服务进程）。&lt;/p&gt;

&lt;p&gt;Tomcat 使用的并发模型也是 one thread per connection。开发环境下，在servlet或jsp代码中上打断点，
在有超过一个浏览器访问有断点的servlet时，能够看到Tomcat为每个连接创建了一个线程。&lt;/p&gt;

&lt;p&gt;这种模型下，单个服务器的服务能力主要受到内存的限制，因为每创建一个进程/线程都要消耗一定数量的内存（MB级别）。&lt;/p&gt;

&lt;h2 id=&#34;nginx-的并发模型&#34;&gt;NGINX 的并发模型&lt;/h2&gt;

&lt;p&gt;NIGNX 支持 single 模式 和 master + worker 模式。&lt;/p&gt;

&lt;h3 id=&#34;nginx-master-worker-模式&#34;&gt;NGINX master + worker 模式&lt;/h3&gt;

&lt;p&gt;NGINX通常工作在master + worker模式下，master和worker都是单线程的进程，用户可以通过增加worker进程数实现提高多核CPU的利用率。
同时，这种每个进程仅有一个线程的模型，使得不需要时刻考虑数据的保护问题（如果是多线程则需要考虑）。&lt;/p&gt;

&lt;p&gt;来自Andrew Alexeev的一张图：
&lt;img src=&#34;http://www.aosabook.org/images/nginx/architecture.png&#34; alt=&#34;NGINX architecture&#34; /&gt;&lt;/p&gt;

&lt;h4 id=&#34;master-进程&#34;&gt;master 进程&lt;/h4&gt;

&lt;p&gt;NGINX的master进程，负责解析配置文件，并启动其他角色的进程，如启动worker，cache manager。&lt;/p&gt;

&lt;p&gt;启动完成其他进程之后，master进程仅起监视作用（相当与monitor角色），后面用户可以通过singaller角色的nginx向master发命令，
master再通知它创建起来的其他进程。&lt;/p&gt;

&lt;h4 id=&#34;worker-进程&#34;&gt;worker 进程&lt;/h4&gt;

&lt;p&gt;worker进程是实际服务客户的进程。包括接受新连接（accept），相应连接上的消息（read/write）.&lt;/p&gt;

&lt;h4 id=&#34;singaller-进程&#34;&gt;singaller 进程&lt;/h4&gt;

&lt;p&gt;singaller进程仅仅是一个向master进程发送信号的工具进程。
通过向master发生特定消息，能够让：
* master/worker完成当前服务后，正常退出。
* master进程重新加载配置文件，或者重启worker。
* 重新打开log 文件。&lt;/p&gt;

&lt;h4 id=&#34;cache-manager&#34;&gt;cache manager&lt;/h4&gt;

&lt;p&gt;可以做 HTTP、文件缓存，即对同一个静态文件的请求进行缓存。&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>docker 入门指南</title>
      <link>https://xusiwei.github.io/post/2016/docker-get-start/</link>
      <pubDate>Tue, 08 Mar 2016 22:58:33 +0800</pubDate>
      
      <guid>https://xusiwei.github.io/post/2016/docker-get-start/</guid>
      <description>&lt;p&gt;本文是实践官方“Get Started”的一个记录，由于我的桌面系统是Debian 8，本文的操作仅确保在 Debian 8 上正确。
指南链接（Linux版）： &lt;a href=&#34;https://docs.docker.com/linux/&#34;&gt;https://docs.docker.com/linux/&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&#34;安装-docker&#34;&gt;安装 Docker&lt;/h2&gt;

&lt;h3 id=&#34;官方脚本安装&#34;&gt;官方脚本安装&lt;/h3&gt;

&lt;p&gt;如果没有 curl ，先安装 curl&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;sudo apt-get update
sudo apt-get install curl
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;用curl下载安装脚本并运行：&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;curl -fsSL https://get.docker.com/ | sh
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;安装成功后会提示你，使用如下命令：&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;sudo usermod -aG docker xu
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;将当前用户（xu）加到docker组，此后运行docker可以不加sudo。另外，让当前用户的组别改变需要重新登录（先log out再log in）。&lt;/p&gt;

&lt;h3 id=&#34;验证&#34;&gt;验证&lt;/h3&gt;

&lt;h3 id=&#34;bash&#34;&gt;bash&lt;/h3&gt;

&lt;pre&gt;&lt;code&gt;docker run -i -t debian docker
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;可以用docker创建一个交互的bash会话，在新的会话中运行ps -ef：&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;xu@debian:~$ docker run -i -t debian bash
root@d99cc11447c7:/#
root@d99cc11447c7:/#
root@d99cc11447c7:/# ps -ef
UID        PID  PPID  C STIME TTY          TIME CMD
root         1     0  2 15:32 ?        00:00:00 bash
root         8     1  0 15:32 ?        00:00:00 ps -ef
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;可以看到，仅有两个进程，而且pid都非常小。这说明，这个会话环境已经与外界隔离了。&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>NGINX 源码安装</title>
      <link>https://xusiwei.github.io/post/2016/nginx-source-install/</link>
      <pubDate>Mon, 07 Mar 2016 23:35:28 +0800</pubDate>
      
      <guid>https://xusiwei.github.io/post/2016/nginx-source-install/</guid>
      <description>&lt;p&gt;NIGNX 是由 Igor Sysoev 开发的一个 Web 服务器。
官网：&lt;a href=&#34;http://nginx.org/&#34;&gt;http://nginx.org/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;下载页面： &lt;a href=&#34;http://nginx.org/en/download.html&#34;&gt;http://nginx.org/en/download.html&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&#34;下载-nginx&#34;&gt;下载 NGINX&lt;/h2&gt;

&lt;p&gt;以 1.8.1 版本为例：&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;wget http://nginx.org/download/nginx-1.8.1.tar.gz
&lt;/code&gt;&lt;/pre&gt;

&lt;h2 id=&#34;下载依赖库&#34;&gt;下载依赖库&lt;/h2&gt;

&lt;p&gt;NGINX必须依赖zlib和pcre, (若想让nginx支持HTTPS协议，还需OpenSSL)&lt;/p&gt;

&lt;p&gt;NGINX 使用zlib进行gzip编/解码（压缩/解压缩）， zlib: &lt;a href=&#34;http://zlib.net/&#34;&gt;http://zlib.net/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;下载 zlib-1.2.8:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;wget http://zlib.net/zlib-1.2.8.tar.gz
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;NGINX 使用pcre作正则表达式匹配， pcre: &lt;a href=&#34;http://pcre.org/&#34;&gt;http://pcre.org/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;ftp: &lt;a href=&#34;ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/&#34;&gt;ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;下载 pcre-8.38:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.38.tar.gz
&lt;/code&gt;&lt;/pre&gt;

&lt;h2 id=&#34;解压&#34;&gt;解压&lt;/h2&gt;

&lt;pre&gt;&lt;code&gt;tar xzvf nginx-1.8.1.tar.gz

tar xzvf zlib-1.2.8.tar.gz

tar xzvf pcre-8.38.tar.gz
&lt;/code&gt;&lt;/pre&gt;

&lt;h2 id=&#34;编译&#34;&gt;编译&lt;/h2&gt;

&lt;pre&gt;&lt;code&gt;cd nginx-1.8.1/

./configure --with-pcre=../pcre-8.38 --with-zlib=../zlib-1.2.8
&lt;/code&gt;&lt;/pre&gt;

&lt;h2 id=&#34;安装&#34;&gt;安装&lt;/h2&gt;

&lt;pre&gt;&lt;code&gt;sudo make install
&lt;/code&gt;&lt;/pre&gt;</description>
    </item>
    
    <item>
      <title>用Hugo和GitHub Pages搭建博客</title>
      <link>https://xusiwei.github.io/post/2016/build-blog-with-hugo-and-github-pages/</link>
      <pubDate>Sun, 21 Feb 2016 16:36:54 +0800</pubDate>
      
      <guid>https://xusiwei.github.io/post/2016/build-blog-with-hugo-and-github-pages/</guid>
      <description>&lt;p&gt;从前天晚上开始尝试了一下用Hugo和GitHub Pages搭建静态博客，总体还算顺利（主要是Hugo用起来比较方便）。&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;关于 Hugo&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Hugo 是由 spf13 创建的一个静态网站生成器，首页：&lt;a href=&#34;https://www.gohugo.io/&#34;&gt;https://www.gohugo.io/&lt;/a&gt;&lt;/p&gt;

&lt;h1 id=&#34;hugo-工作流&#34;&gt;Hugo 工作流&lt;/h1&gt;

&lt;p&gt;下面将介绍Hugo的完整工作流程：&lt;/p&gt;

&lt;h2 id=&#34;快速安装&#34;&gt;快速安装&lt;/h2&gt;

&lt;p&gt;在 &lt;a href=&#34;https://www.gohugo.io/&#34;&gt;https://www.gohugo.io/&lt;/a&gt; 能够找到 Homebrew 安装 Hugo的命令，&lt;/p&gt;

&lt;p&gt;以及Download： &lt;a href=&#34;https://github.com/spf13/hugo/releases&#34;&gt;https://github.com/spf13/hugo/releases&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;下载对应的操作系统版本的Hugo二进制文件（hugo或者hugo.exe），添加到&lt;code&gt;$PATH&lt;/code&gt;能找到的目录下。&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>你好，世界</title>
      <link>https://xusiwei.github.io/post/hello-world/</link>
      <pubDate>Fri, 19 Feb 2016 23:16:09 +0800</pubDate>
      
      <guid>https://xusiwei.github.io/post/hello-world/</guid>
      <description>&lt;p&gt;这是一篇测试博客，在这你将看到Hugo对Markdown的渲染效果。&lt;/p&gt;

&lt;h1 id=&#34;关于-hugo&#34;&gt;关于 Hugo&lt;/h1&gt;

&lt;p&gt;Hugo是一个静态网站生成器&lt;/p&gt;</description>
    </item>
    
  </channel>
</rss>