<?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>apt-blog.net   无证程序员的PT桑 &#187; Unix/Linux</title> <atom:link href="http://apt-blog.net/category/tech/unix_linux/feed" rel="self" type="application/rss+xml" /><link>http://apt-blog.net</link> <description>潜逃中。</description> <lastBuildDate>Sun, 05 Feb 2012 10:35:00 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <item><title>x11vnc - 远程工作站桌面</title><link>http://apt-blog.net/x11vnc_run_vncserver_in_workstation_remotely</link> <comments>http://apt-blog.net/x11vnc_run_vncserver_in_workstation_remotely#comments</comments> <pubDate>Sun, 05 Feb 2012 10:31:22 +0000</pubDate> <dc:creator>BOYPT</dc:creator> <category><![CDATA[Unix/Linux]]></category> <category><![CDATA[DE]]></category> <category><![CDATA[Linux]]></category> <category><![CDATA[vnc]]></category> <guid
isPermaLink="false">https://apt-blog.net/?p=1151</guid> <description><![CDATA[Gnome Desktop Environment的VNC服务开启很容易，仅需点开Desktop Sharing，打个勾就完了。 但是有时候某台工作站没有打开这个VNC服务，只有SSH，但是又必须通过桌面来操作，这时候自带的vino server就好像不容易跑起来。 x11vnc这个小工具就可以派上用场，它对当前的x11 session建立VNC服务，很简单直接运行x11vnc，就等你连接5900端口了。当然，如果一定要指定一个session，有个-display参数可以指定，或者看看x11vnc --help，好长好长～～～]]></description> <content:encoded><![CDATA[<p>Gnome Desktop Environment的VNC服务开启很容易，仅需点开<code>Desktop Sharing</code>，打个勾就完了。</p><p><a
href="http://apt-blog.net/wp-content/uploads/2012/02/vino-preferences.png" rel="lightbox[1151]" title="vino-preferences Gnome默认的VNC配置界面"><img
title="vino-preferences Gnome默认的VNC配置界面" alt="vino-preferences Gnome默认的VNC配置界面" src="http://apt-blog.net/wp-content/uploads/2012/02/vino-preferences.png" class="aligncenter" style="width:30%" /></a></p><p>但是有时候某台工作站没有打开这个VNC服务，只有SSH，但是又必须通过桌面来操作，这时候自带的vino server就好像不容易跑起来。</p><p>x11vnc这个小工具就可以派上用场，它对当前的x11 session建立VNC服务，很简单直接运行x11vnc，就等你连接5900端口了。当然，如果一定要指定一个session，有个<code>-display</code>参数可以指定，或者看看<code>x11vnc --help</code>，好长好长～～～</p> ]]></content:encoded> <wfw:commentRss>http://apt-blog.net/x11vnc_run_vncserver_in_workstation_remotely/feed</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>Nginx + PHP (via php-fpm) on Ubuntu 环境最佳实践</title><link>http://apt-blog.net/best-practise-nginx-php-via-php-fpm-on-ubuntu</link> <comments>http://apt-blog.net/best-practise-nginx-php-via-php-fpm-on-ubuntu#comments</comments> <pubDate>Thu, 21 Jul 2011 11:01:31 +0000</pubDate> <dc:creator>BOYPT</dc:creator> <category><![CDATA[Unix/Linux]]></category> <category><![CDATA[nginx]]></category> <category><![CDATA[php]]></category> <category><![CDATA[Ubuntu]]></category> <guid
isPermaLink="false">http://apt-blog.net/nginx-php-via-php-fpm-on-ubuntu-lucid-%e7%8e%af%e5%a2%83%e6%9c%80%e4%bd%b3%e5%ae%9e%e8%b7%b5</guid> <description><![CDATA[Nginx团队维护的PPA源带有PHP 5.3.x的子源，更新迅速，现在在Ubuntu部署Nginx+PHP环境真是太容易了（虽然LAMP更容易，一句apt-get install lamp-server^搞定，别漏了最后的上尖号）。像以前那样跑cgi-fcgi简直弱爆了。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 apt-get install python-software-properties add-apt-repository ppa:nginx/stable add-apt-repository ppa:nginx/php5 &#160; #Ubuntu 10.10 以后可不需添加以上源 &#160; apt-get update apt-get install nginx apt-get install php5-cgi php5-mysql php5-fpm php5-curl php5-mcrypt &#160; #或者你需要更齐全的php包： #aptitude install php5-cgi php5-mysql php5-fpm php5-curl php5-gd php5-idn php-pear php5-imagick [...]]]></description> <content:encoded><![CDATA[<p>Nginx团队维护的PPA源带有PHP 5.3.x的子源，更新迅速，现在在Ubuntu部署Nginx+PHP环境真是太容易了（虽然LAMP更容易，一句<code>apt-get install lamp-server^</code>搞定，别漏了最后的上尖号）。像<a
href="http://apt-blog.net/setup_nginx">以前那样</a>跑cgi-fcgi简直弱爆了。</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td
class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> python-software-properties
add-apt-repository ppa:nginx<span style="color: #000000; font-weight: bold;">/</span>stable
add-apt-repository ppa:nginx<span style="color: #000000; font-weight: bold;">/</span>php5
&nbsp;
<span style="color: #666666; font-style: italic;">#Ubuntu 10.10 以后可不需添加以上源</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">apt-get</span> update
<span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> nginx
<span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> php5-cgi php5-mysql php5-fpm php5-curl php5-mcrypt
&nbsp;
<span style="color: #666666; font-style: italic;">#或者你需要更齐全的php包：</span>
<span style="color: #666666; font-style: italic;">#aptitude install php5-cgi php5-mysql php5-fpm php5-curl php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-mhash php5-ming php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl</span>
&nbsp;
service nginx start
service php5-fpm start</pre></td></tr></table></div><h2>FPM Tunning</h2><p>php5-fpm默认参数启动的服务器还是比较耗资源的，如果环境不充裕（如512内存以下的VPS），可以做下配置。</p><p>这个包的fpm的默认配置文件是<code>/etc/php5/fpm/main.conf</code>，但对子进程的配置是在其包含的<code>/etc/php5/fpm/pool.d/</code>目录内，里面有个<code>www.conf</code>，可以对以下的参数做以下修改：</p><div
class="wp_syntax"><div
class="code"><pre class="text" style="font-family:monospace;">pm = dynamic              ;动态管理php-fpm的子进程
pm.max_children = 5       ;最多的时候开不超过5个
pm.start_servers = 2      ;启动服务时候开2个
pm.min_spare_servers = 2  ;空闲时候最少留2个
pm.max_spare_servers = 5  ;最多留5个
pm.max_requests = 300     ;每个子进程最多处理300个请求就退出换新的子进程。</pre></div></div><p>按需调整这些参数可以达到最佳动态分配资源的效果。</p> ]]></content:encoded> <wfw:commentRss>http://apt-blog.net/best-practise-nginx-php-via-php-fpm-on-ubuntu/feed</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>nginx+uwsgi架设自用Mercurial hg仓库：hgwebdir</title><link>http://apt-blog.net/mercurial-repo-under-nginx-and-uwsgi</link> <comments>http://apt-blog.net/mercurial-repo-under-nginx-and-uwsgi#comments</comments> <pubDate>Fri, 11 Mar 2011 07:43:59 +0000</pubDate> <dc:creator>BOYPT</dc:creator> <category><![CDATA[Programming]]></category> <category><![CDATA[Python]]></category> <category><![CDATA[Unix/Linux]]></category> <category><![CDATA[hg]]></category> <category><![CDATA[mercurial]]></category> <category><![CDATA[nginx]]></category> <guid
isPermaLink="false">http://apt-blog.net/mercurial-repo-under-nginx-and-uwsgi</guid> <description><![CDATA[Mercurial/hg是分布式版本管理工具之一，如google code等公共代码服务都直接支持。不过公共服务通常都有如公开开源、空间大小等等的限制，如果特殊情况，需要自己在VPS上假设一套，也不太难。 如果单独一个hg仓库，直接运行hg serve就已经是在线仓库，用nginx做的http_proxy反向代理就够了，各种功能齐全。但是要host多个hg仓库，需要用hgwebdir。 Ubuntu当中安装的mercurial已经包含了架设仓库所用的程序，包括cgi/fcgi/wcgi的，主接口在/usr/share/doc/mercurial-common/examples下的hgwebdir.(ws&#124;(f)c)gi。虽然其中的wsgi有效的只有三行。 Mercurial官方Wiki上主要介绍了用apache2来跑cgi方式的仓库，但是作为python的程序，wsgi才是最原生的嘛。用Nginx+uwsgi的方式，资源占用、响应效率等，都要比apache + cgi靠谱。 Nginx+uwsgi的方式很普遍，参见本博客之前的MoinMoin 与 Nginx, fastcgi 与 uwsgi 的配置一文。 但是因为uwsgi处于快速开发过程当中，ppa的打包也还不十分成熟，里面的路径跟以前有些不一样了。 add-apt-repository ppa:nginx/stable add-apt-repository ppa:uwsgi/release apt-get update apt-get install nginx uwsgi-python python-virtualenv mercurial &#160; mkdir -p /var/www/hgwebdir virtualenv /var/www/hgwebdir/python-home &#160; cat &#62;/var/www/hgwebdir/hgwebdir_wsgi.py &#60;&#60; EOF from mercurial import demandimport; demandimport.enable() from mercurial.hgweb.hgwebdir_mod import hgwebdir &#160; class hgwebdir_with_fixed_staticfile(hgwebdir): def __call__(self, env, respond): [...]]]></description> <content:encoded><![CDATA[<p>Mercurial/hg是分布式版本管理工具之一，如google code等公共代码服务都直接支持。不过公共服务通常都有如公开开源、空间大小等等的限制，如果特殊情况，需要自己在VPS上假设一套，也不太难。</p><p>如果单独一个hg仓库，直接运行hg serve就已经是在线仓库，用nginx做的http_proxy反向代理就够了，各种功能齐全。但是要host多个hg仓库，需要用hgwebdir。</p><p>Ubuntu当中安装的mercurial已经包含了架设仓库所用的程序，包括cgi/fcgi/wcgi的，主接口在<code>/usr/share/doc/mercurial-common/examples</code>下的<code>hgwebdir.(ws|(f)c)gi</code>。虽然其中的wsgi有效的只有三行。</p><p>Mercurial官方Wiki上主要<a
href="http://mercurial.selenic.com/wiki/HgWebDirStepByStep">介绍了用apache2来跑cgi方式的仓库</a>，但是作为python的程序，wsgi才是最原生的嘛。用Nginx+uwsgi的方式，资源占用、响应效率等，都要比apache + cgi靠谱。</p><p>Nginx+uwsgi的方式很普遍，参见本博客之前的<a
href="http://apt-blog.net/moinmoin-on-nginx-via-fastcgi-and-uwgi">MoinMoin 与 Nginx, fastcgi 与 uwsgi 的配置</a>一文。</p><p>但是因为uwsgi处于快速开发过程当中，ppa的打包也还不十分成熟，里面的路径跟以前有些不一样了。</p><div
class="wp_syntax"><div
class="code"><pre class="bash" style="font-family:monospace;">add-apt-repository ppa:nginx<span style="color: #000000; font-weight: bold;">/</span>stable
add-apt-repository ppa:uwsgi<span style="color: #000000; font-weight: bold;">/</span>release
<span style="color: #c20cb9; font-weight: bold;">apt-get</span> update
<span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> nginx uwsgi-python python-virtualenv mercurial
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>hgwebdir
virtualenv <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>hgwebdir<span style="color: #000000; font-weight: bold;">/</span>python-home
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">&gt;/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>hgwebdir<span style="color: #000000; font-weight: bold;">/</span>hgwebdir_wsgi.py <span style="color: #cc0000; font-style: italic;">&lt;&lt; EOF
from mercurial import demandimport; demandimport.enable()
from mercurial.hgweb.hgwebdir_mod import hgwebdir
&nbsp;
class hgwebdir_with_fixed_staticfile(hgwebdir):
    def __call__(self, env, respond):
        response = super(self.__class__, self).__call__(env, respond)
        return response[0] if isinstance(response, tuple) else response
&nbsp;
application = hgwebdir_with_fixed_staticfile('/var/www/hgwebdir/hgweb.config')
EOF</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">&gt;/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>hgwebdir<span style="color: #000000; font-weight: bold;">/</span>hgweb.config <span style="color: #cc0000; font-style: italic;">&lt;&lt; EOF
[collections]
/home/hg-repo = /home/hg-repo
&nbsp;
[web]
style = monoblue
allow_archive = gz, zip, bz2
baseurl = /
push_ssl = true
hidden = false
allow_read = *
allow_push = user1 user2
&nbsp;
[extensions]
#highlight =
EOF</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">&gt;/</span>etc<span style="color: #000000; font-weight: bold;">/</span>uwsgi-python<span style="color: #000000; font-weight: bold;">/</span>apps-enabled<span style="color: #000000; font-weight: bold;">/</span>uwsgi.xml <span style="color: #cc0000; font-style: italic;">&lt;&lt; EOF
&lt;uwsgi&gt;
  &lt;limit-as&gt;256&lt;/limit-as&gt;
  &lt;processes&gt;6&lt;/processes&gt;
  &lt;memory-report/&gt;
  &lt;vhost/&gt;
  &lt;no-site/&gt;
&lt;/uwsgi&gt;
EOF</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">&gt;/</span>etc<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>sites-enabled<span style="color: #000000; font-weight: bold;">/</span>hgwebdir <span style="color: #cc0000; font-style: italic;">&lt;&lt; EOF
server {
    listen   80;
    client_max_body_size 512m;
    server_name hg.mydomian.com;
    location / {
                include uwsgi_params;
                uwsgi_pass unix:///var/run/uwsgi-python/uwsgi/socket;
                uwsgi_param UWSGI_PYHOME /var/www/hgwebdir/python-home;
                uwsgi_param UWSGI_CHDIR /var/www/hgwebdir/;
                uwsgi_param UWSGI_SCRIPT hgwebdir_wsgi;
                uwsgi_param UWSGI_SCHEME \$scheme;
                uwsgi_param REMOTE_USER \$remote_user;
        }
}
EOF</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>hg-repo
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>hg-repo
hg init example-repo1
hg init example-repo2
<span style="color: #c20cb9; font-weight: bold;">chown</span> <span style="color: #660033;">-R</span> www-data:www-data <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>hg-repo
&nbsp;
<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>nginx restart
<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>uwsgi-python restart</pre></div></div><p>所以，/home/hg-repo下的所有仓库(新建的两个空仓库example-repo1/2)都会被hgwebdir列表在目录上，直接使用其地址就可以pull/push了。</p><p>注意的是hgweb.config文件里面的配置，<code>push_ssl = true</code>只允许使用https协议的时候push，也就是需要另外配置一个支持https的nginx。这个属于nginx的基本配置，这里不重提了。</p><p>对于不公开的仓库，除了HTTPS，还需要用户名密码，只需要配置nginx的basic http auth，上面命令当中的<code>uwsgi_param REMOTE_USER $remote_user</code>一行配置会把http auth的USER通过协议发送到hgweb，完成其认证过程。</p><p>其实hgweb的认证仅仅是用户名的匹配，hgweb.config里面的<code>allow_push = user1 user2</code>是全局设定，各个仓库的<code>.hg/hgrc</code>里面的同样的[web]区下也可以定义allow_push/read，即仓库各自的读写权限。</p><p><code>hgweb.config</code>中注释掉的highlight一行，是启动语法高亮插件用的，打开需要先安装<code>python-pygments</code>包，不然会出错。</p><p>这个版本的uwsgi程序的log在<code>/var/log/uwsgi-python/uwsgi.log</code>，如果出任何问题，大概看看log的提示按提示去修复即可。</p><p><strong>Update: 2011-3-17</strong></p><p>原hgwebdir的程序跟wsgi2协议兼容不好，会出现仓库目录的首页里面的静态文件全部无法打开，log里面的信息是<code>invalid WSGI2.0 response size: 1 .</code>。 上述代码中已经修复（见1楼留言。） <strong>Thank You, Leonid.</strong></p> ]]></content:encoded> <wfw:commentRss>http://apt-blog.net/mercurial-repo-under-nginx-and-uwsgi/feed</wfw:commentRss> <slash:comments>3</slash:comments> </item> <item><title>Manage multiple wordpresses with new Vimpress</title><link>http://apt-blog.net/manage-multiple-wordpresses-with-new-vimpress</link> <comments>http://apt-blog.net/manage-multiple-wordpresses-with-new-vimpress#comments</comments> <pubDate>Thu, 10 Mar 2011 07:40:53 +0000</pubDate> <dc:creator>BOYPT</dc:creator> <category><![CDATA[Blogger Tech]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[Python]]></category> <category><![CDATA[Shell]]></category> <category><![CDATA[Unix/Linux]]></category> <category><![CDATA[Vim]]></category> <category><![CDATA[Blog]]></category> <category><![CDATA[vimpress]]></category> <guid
isPermaLink="false">http://apt-blog.net/manage-multiple-wordpresses-with-new-vimpress</guid> <description><![CDATA[Update Vimpress 已经升级到2.x版本，使用、配置都有改进，请关注在vim.org的插件页面： Vimpress had been updated to 2.x, usage and configurations are now different, read the officle page in vim.org: http://www.vim.org/scripts/script.php?script_id=3510 If you noticed Vimpress before and got more than one wordpress to write, must glad now to know this VimRePressed support multiple configs and swith freely. The new VimRePressed (Version: 1.2.0) Changes: Add: [...]]]></description> <content:encoded><![CDATA[<p><strong> Update </strong><br
/> Vimpress 已经升级到2.x版本，使用、配置都有改进，请关注在vim.org的插件页面：</p><p>Vimpress had been updated to 2.x, usage and configurations are now different, read the officle page in vim.org:</p><p><a
href="http://www.vim.org/scripts/script.php?script_id=3510">http://www.vim.org/scripts/script.php?script_id=3510</a></p><hr
/><p>If you noticed <a
href="http://apt-blog.net/tag/vimpress">Vimpress</a> before and got more than one wordpress to write, must glad now to know this VimRePressed support multiple configs and swith freely.</p><p>The new VimRePressed (Version: 1.2.0) Changes:</p><div
class="wp_syntax"><div
class="code"><pre class="text" style="font-family:monospace;">      Add: MarkdownPreview command to preiview markdown in browser.
      Add: MarkdownNewPost command to convert a markdown
           written post into html and set to the new post view.
      Add: Move blog configs info to personal .vimrc
      Add: Multiple config is now supported, and with :BlogSwitch
           command added.
      Add: Show which blog your editing at :BlogList view.
      Fix: Running :BlogList in the List view got error.</pre></div></div><p>Now you got to wirte your blog config in your own ~/.vimrc file. (CAREFUL when your share your vim configure with others then. Use a <code>source my_vimpress.vimrc</code> instead. )</p><div
class="wp_syntax"><div
class="code"><pre class="text" style="font-family:monospace;">let VIMPRESS=[{'username':'user',
              \'password':'pass',
              \'blog_url':'http://your-first-blog.com/'
              \},
              \{'username':'user',
              \'password':'pass',
              \'blog_url':'http://your-second-blog.com/'
              \}]</pre></div></div><p>The syntax looks just like python or json, dictionarys in a list(or array), only that line brake need to write in the vim way.</p><p>BlogSwitch command rotate you from the first blog to the last, then the first. If you got confused, BlogList command can show you which one you're connecting to.</p><p>Then the Markdown support. I added two command to save my time saving .mkd file then convert them into html then check in a browser, MarkdownPreview command can do this for me. When flawless, the MarkdownNewPost command switch me to the new post view with all thing I write into html, which is ready to publish.</p><p>Download: <a
href="http://code.google.com/p/ptcoding/downloads/detail?name=vimpress_1.2.5-r55.zip">from google code</a></p><p>SVN Version also available:</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
</pre></td><td
class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">svn</span> checkout http:<span style="color: #000000; font-weight: bold;">//</span>ptcoding.googlecode.com<span style="color: #000000; font-weight: bold;">/</span>svn<span style="color: #000000; font-weight: bold;">/</span>trunk<span style="color: #000000; font-weight: bold;">/</span>vimpress</pre></td></tr></table></div> ]]></content:encoded> <wfw:commentRss>http://apt-blog.net/manage-multiple-wordpresses-with-new-vimpress/feed</wfw:commentRss> <slash:comments>5</slash:comments> </item> <item><title>使用wp-super-cache插件静态缓冲的nginx rewrite规则</title><link>http://apt-blog.net/nginx-rewrite-rules-for-wp-super-cache</link> <comments>http://apt-blog.net/nginx-rewrite-rules-for-wp-super-cache#comments</comments> <pubDate>Thu, 03 Mar 2011 14:39:07 +0000</pubDate> <dc:creator>BOYPT</dc:creator> <category><![CDATA[Blogger Tech]]></category> <category><![CDATA[Unix/Linux]]></category> <category><![CDATA[Cache]]></category> <category><![CDATA[nginx]]></category> <category><![CDATA[WordPress]]></category> <guid
isPermaLink="false">http://apt-blog.net/nginx-rewrite-rules-for-wp-super-cache</guid> <description><![CDATA[WordPress的缓冲插件wp-super-cache默认支持apahce的缓冲方式，在生成了静态页面数据后，通过.htaccess的规则直接让apache读取静态文件，完全不经过PHP，可以很大的提高博客的页面性能。 但是Nginx的改写规则就没这么容易让代码来配置了，虽然wp-super-cache的第二种缓存方式就是为这种使用环境设计，但实际上是用了PHP来提供静态数据了，在使用apache benchmark压力的时候，php-cgi依然占很高的CPU占有率。 通过编写nginx的rewrite规则还是可以让nginx直接读取静态文件，参考来自Code Exchange: nginx rewrite rules for WordPress + WP Super Cache，这里的配置被很多地方引用过，但实际尝试使用过程看到那里面的代码还需要微调。 server { listen 80; server_name apt-blog.net; root /var/www/pt-sites/wordpress; index index.html index.htm index.php; location / { # enable search for precompressed files ending in .gz # nginx needs to be complied using –-with-http_gzip_static_module # for this to work, comment out if using [...]]]></description> <content:encoded><![CDATA[<p>WordPress的缓冲插件wp-super-cache默认支持apahce的缓冲方式，在生成了静态页面数据后，通过.htaccess的规则直接让apache读取静态文件，完全不经过PHP，可以很大的提高博客的页面性能。</p><p>但是Nginx的改写规则就没这么容易让代码来配置了，虽然wp-super-cache的第二种缓存方式就是为这种使用环境设计，但实际上是用了PHP来提供静态数据了，在使用apache benchmark压力的时候，php-cgi依然占很高的CPU占有率。</p><p>通过编写nginx的rewrite规则还是可以让nginx直接读取静态文件，参考来自<a
href="http://forum.slicehost.com/comments.php?DiscussionID=2087">Code Exchange: nginx rewrite rules for WordPress + WP Super Cache</a>，这里的配置被很多地方引用过，但实际尝试使用过程看到那里面的代码还需要微调。</p><div
class="wp_syntax"><div
class="code"><pre class="text" style="font-family:monospace;">    server {
        listen          80;
        server_name     apt-blog.net;
        root    /var/www/pt-sites/wordpress;
        index   index.html index.htm index.php;
        location / {
                # enable search for precompressed files ending in .gz
                # nginx needs to be complied using –-with-http_gzip_static_module
                # for this to work, comment out if using nginx from aptitude
                gzip_static on;
&nbsp;
# if the requested file exists, return it immediately
                if (-f $request_filename) {
                        break;
                }
&nbsp;
set $supercache_file '';
                set $supercache_uri $request_uri;
&nbsp;
if ($request_method = POST) {
                        set $supercache_uri '';
                }
&nbsp;
# Using pretty permalinks, so bypass the cache for any query string
                if ($query_string) {
                        set $supercache_uri '';
                }
&nbsp;
if ($http_cookie ~* &quot;comment_author_|wordpress|wp-postpass_&quot; ) {
                        set $supercache_uri '';
                }
&nbsp;
# !!!! IMPORTANT
                # if we haven't bypassed the cache, specify our supercache file
                if ($supercache_uri ~ ^(.+)$) {
                        set $supercache_file /wp-content/cache/supercache/$http_host/$1/index.html;
                }
&nbsp;
# only rewrite to the supercache file if it actually exists
                if (-f $document_root$supercache_file) {
                        rewrite ^(.*)$ $supercache_file break;
                }
&nbsp;
# all other requests go to Wordpress
                if (!-e $request_filename) {
                        rewrite ^(.*)$ /index.php?q=$1 last;
                }
&nbsp;
}
        location ~ \.php$ {
              include        fastcgi_params;
              fastcgi_pass   127.0.0.1:9000;
              fastcgi_index  index.php;
              fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        }
    }</pre></div></div><p><strong>需要重点关注的是<code>set $supercache_uri</code>这一行，这里的路径是wp-super-cache生成静态文件的路径，配置文件起作用的时候，这个路径会和$document_root组成最终静态文件的绝对路径，最终输出文件。所以如果这个路径不对的话，最终还是交给了<code>index.php</code>，缓冲就不起作用了。</strong></p><p>wp-super-cache在wordpress目录<code>/wp-content/cache/supercache/$http_host/</code>下生成了各个请求url的目录，目录下是一个index.html静态文件，可以在wordpress工作时候，在这个目录下用命令<code>watch find</code>观察（在缓冲不多的情况下），总之小心的把这个路径写好，因为估计每个博客的permanent link的样式都不一样，wp-super-cache生成的目录也不一样，需要仔细调试一下。</p><p>当然这里的规则并没有安全包含了wp-super-cache 插件的功能，比如识别手机客户端之类的，如果需要还得仔细根据插件生成的.htaccess规则来添加到nginx。</p><p>完成后用apache benchmark压一下，Request per second应该很容易上百，而且php-cgi应该不会出现在top的列表前面了，CPU应该集中在nginx的子进程上，而且都是个位数CPU占有率，系统的load非常低。</p><p>Tips: 发现测试结果不对时，可以尝试删除/wp-content/cache整个目录，让wp重新生成所有缓冲。</p><p>顺便说一下，如果仅使用ab测试压力，用不着安装整个apache2，只需要<code>apt-get install apache2-utils</code>。</p> ]]></content:encoded> <wfw:commentRss>http://apt-blog.net/nginx-rewrite-rules-for-wp-super-cache/feed</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>黑莓续断膏 MDS服务器的Linux版本</title><link>http://apt-blog.net/blackberry_broken_net_fix_server_for_linux</link> <comments>http://apt-blog.net/blackberry_broken_net_fix_server_for_linux#comments</comments> <pubDate>Wed, 23 Feb 2011 10:18:43 +0000</pubDate> <dc:creator>BOYPT</dc:creator> <category><![CDATA[C/C++]]></category> <category><![CDATA[Mobile]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[Unix/Linux]]></category> <category><![CDATA[Blackberry]]></category> <category><![CDATA[Linux]]></category> <category><![CDATA[mds]]></category> <category><![CDATA[黑莓]]></category> <guid
isPermaLink="false">http://apt-blog.net/blackberry_broken_net_fix_server_for_linux</guid> <description><![CDATA[黑莓系统5.0以上系统在没有购买使用黑莓网络服务的手机上的断网现象一直比较恼人。几个月前有人做出了“黑莓续断膏”，原理是自架一台服务器，程序模拟MDS服务的简单回应，可以忽悠手机继续在线。 5.0系统断网自动修复程序黑莓断续膏(AntiBrokenNet！) BrokenNetFixup断网修复工具 区别是前者后台自动修复，后者要手动运行修复。 从网友的留言看出，虽然软件虽然有效，但没有稳定的服务器，软件刚出现时候确实有一批地址提供了服务，但很快就失效了。北京小C这里提供了模拟MDS服务器的程序，是VC写的一个小UDP服务器，虽然原理很简单，但用一台Windows的服务器来跑成本太高了，当然很难稳定提供。 其实服务只是很简单的几行代码，稍微改了一下就可以在Linux下面运行。一台低端Linux VPS的费用大概一年200RMB，这个费用对大多数人来说都不是什么问题的，所以推荐想要稳定防断网服务器的人去弄一台，一台可以很多人共享了。VPS侦探 、Lowendbox上有很多这样的推荐。 Linux版本的MDS服务器代码在Google Code上，可以直接下载。 在服务器（Debian/Ubuntu系统）上编译并运行： 1 2 3 4 5 sudo apt-get install build-essential wget http://ptcoding.googlecode.com/svn/trunk/mds_server.c gcc -Wall -o mds_server mds_server.c sudo cp mds_server /usr/local/bin/ /usr/local/bin/mds_server 现在可以设置手机的续断软件使用这个服务器来连接断网测试了，手机连接的时候，会实时打印出手机的连接信息跟PIN码。 当然最好把程序加入系统自动启动： sudo touch /var/log/mds_server.log sudo chown nobody /var/log/mds_server.log sudo sed -i '/^exit 0/isu nobody -c &#34;nohup /usr/local/bin/mds_server &#62;&#62;/var/log/mds_server.log &#38;&#34;' /etc/rc.local 这样程序会在系统启动后自动在后台运行，运行的LOG会记录在/var/log/mds_server.log文件当中。 下面也无偿提供一枚MDS服务器，就是跑在我的Linux服务器上的。 [...]]]></description> <content:encoded><![CDATA[<p>黑莓系统5.0以上系统在没有购买使用黑莓网络服务的手机上的断网现象一直比较恼人。几个月前有人做出了“黑莓续断膏”，原理是自架一台服务器，程序模拟MDS服务的简单回应，可以忽悠手机继续在线。</p><ul><li><a
href="http://www.bbercn.com/auto-fix-network-problems-by-antibrokennet.html">5.0系统断网自动修复程序黑莓断续膏(AntiBrokenNet！)</a></li><li><a
href="http://www.bjxiaoc.cn/index.php/archives/11437">BrokenNetFixup断网修复工具</a></li></ul><p>区别是前者后台自动修复，后者要手动运行修复。</p><p>从网友的留言看出，虽然软件虽然有效，但没有稳定的服务器，软件刚出现时候确实有一批地址提供了服务，但很快就失效了。<a
href="http://www.bjxiaoc.cn/index.php/archives/11437">北京小C</a>这里提供了模拟MDS服务器的程序，是VC写的一个小UDP服务器，虽然原理很简单，但用一台Windows的服务器来跑成本太高了，当然很难稳定提供。</p><p>其实服务只是很简单的几行代码，稍微改了一下就可以在Linux下面运行。一台低端Linux VPS的费用大概一年200RMB，这个费用对大多数人来说都不是什么问题的，所以推荐想要稳定防断网服务器的人去弄一台，一台可以很多人共享了。<a
href="http://www.vpser.net/">VPS侦探</a> 、<a
href="http://www.lowendbox.com/">Lowendbox</a>上有很多这样的推荐。</p><p>Linux版本的MDS服务器代码在<a
href="http://code.google.com/p/ptcoding/source/browse/trunk/mds_server.c">Google Code</a>上，可以<a
href="http://ptcoding.googlecode.com/svn/trunk/mds_server.c">直接下载</a>。</p><p>在服务器（Debian/Ubuntu系统）上编译并运行：</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
5
</pre></td><td
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> build-essential
<span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>ptcoding.googlecode.com<span style="color: #000000; font-weight: bold;">/</span>svn<span style="color: #000000; font-weight: bold;">/</span>trunk<span style="color: #000000; font-weight: bold;">/</span>mds_server.c
<span style="color: #c20cb9; font-weight: bold;">gcc</span> <span style="color: #660033;">-Wall</span> <span style="color: #660033;">-o</span> mds_server mds_server.c
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">cp</span> mds_server <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>mds_server</pre></td></tr></table></div><p>现在可以设置手机的续断软件使用这个服务器来连接断网测试了，手机连接的时候，会实时打印出手机的连接信息跟PIN码。</p><p>当然最好把程序加入系统自动启动：</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;">touch</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>mds_server.log
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">chown</span> nobody <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>mds_server.log
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-i</span> <span style="color: #ff0000;">'/^exit 0/isu nobody -c &quot;nohup /usr/local/bin/mds_server &gt;&gt;/var/log/mds_server.log &amp;&quot;'</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>rc.local</pre></div></div><p>这样程序会在系统启动后自动在后台运行，运行的LOG会记录在<code>/var/log/mds_server.log</code>文件当中。</p><p>下面也无偿提供一枚MDS服务器，就是跑在我的Linux服务器上的。</p><div
class="wp_syntax"><div
class="code"><pre class="text" style="font-family:monospace;">地址：119.134.250.11
端口：19781</pre></div></div><p>另外服务端口可以修改源代码里面的宏：</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
</pre></td><td
class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#define LOCAL_SERVER_PORT 19781</span></pre></td></tr></table></div> ]]></content:encoded> <wfw:commentRss>http://apt-blog.net/blackberry_broken_net_fix_server_for_linux/feed</wfw:commentRss> <slash:comments>4</slash:comments> </item> <item><title>MoinMoin 与 Nginx, fastcgi 与 uwsgi 的配置</title><link>http://apt-blog.net/moinmoin-on-nginx-via-fastcgi-and-uwgi</link> <comments>http://apt-blog.net/moinmoin-on-nginx-via-fastcgi-and-uwgi#comments</comments> <pubDate>Wed, 13 Oct 2010 13:38:56 +0000</pubDate> <dc:creator>BOYPT</dc:creator> <category><![CDATA[Python]]></category> <category><![CDATA[Unix/Linux]]></category> <category><![CDATA[fastcgi]]></category> <category><![CDATA[moinmoin]]></category> <category><![CDATA[nginx]]></category> <category><![CDATA[uwgi]]></category> <category><![CDATA[wiki]]></category> <guid
isPermaLink="false">http://apt-blog.net/moinmoin-on-nginx-via-fastcgi-and-uwgi</guid> <description><![CDATA[给自己架了个Wiki http://wiki.apt-blog.net作为自己的知识管理工具。虽然这个博客本来就是工具之一，也累积了快两年了，但经常碰到有些小东西，不值得为之写篇博客，很有用，但用完就忘记。个人wiki适合做写细小的笔记，当累积一定的时候还可以整理成博客。 Wiki我选择了用Python的MoinMoin，一定程度上受CPYUG社区 ZoomQuiet 大妈的推荐影响，首次试用感觉非常impresive，所以就定了。再加上 GraphViz 工具的支持，实在的强大。 在vps上服务，肯定是无视apache的，内存有限。之前架设过用来上Twitter奶瓶腿，是Nginx + php-cgi的方案，nginx是必须的。 Python跟web前端的架构方式有太多选择了，五花八门，MoinMoin的发行包里面都提供了moin.cgi moin.scgi moin.ajp moin.fcgi moin.wsgi等多种启动方式。MoinMoin里面全部通过内置的flup作为中间件提供这些接口，目前我仅尝试使用了fastcgi和wsgi。 虽然解压了moin的源码包就可以直接运行里面的wikiserver.py来本地访问了，但在服务器上通常是由nginx/lighttpd等服务来综合转发。php的话是通过spawn-fcgi启动一些php-cgi的进程，服务器接受到动态的请求就通过本地socket跟php-cgi通讯，返回的结果展现回给客户。php-cgi是使用FastCGI协议的。 MoinMoin 源码当中wiki/server/moin.fcgi就是一个类似php-cgi功能的fastcgi服务，类似地可以使用spawn-fcgi来启动moin.fcgi，作为后端的处理进程。 Running MoinMoin Wiki with Nginx via FastCGI and Flup该文章很形象解释了fastcgi的角色，以及提供了一段很方便的服务脚本来启动spawn-fcgi。 Client ----> Nginx Web Frontend -----------+ &#124; fastcgi_pass \&#124;/ +-------------------------+ moin.fcgi &#124; spawn-fcgi-moin.socket &#124; spawn-fcgi ---------------> &#124; or &#124; &#124; localhost:port &#124; +-------------------------+ 但是文章当中的nginx配置不完整，而且复杂了，这是我的配置： server { listen 80; [...]]]></description> <content:encoded><![CDATA[<p>给自己架了个Wiki <a
href="http://wiki.apt-blog.net">http://wiki.apt-blog.net</a>作为自己的知识管理工具。虽然这个博客本来就是工具之一，也累积了快两年了，但经常碰到有些小东西，不值得为之写篇博客，很有用，但用完就忘记。个人wiki适合做写细小的笔记，当累积一定的时候还可以整理成博客。</p><p>Wiki我选择了用Python的MoinMoin，一定程度上受CPYUG社区<a
href="http://wiki.woodpecker.org.cn/moin/ZoomQuiet"> ZoomQuiet </a>大妈的推荐影响，首次试用感觉非常impresive，所以就定了。再加上<a
href="http://wiki.woodpecker.org.cn/moin/GraphViz"> GraphViz </a>工具的支持，实在的强大。</p><p>在vps上服务，肯定是无视apache的，内存有限。之前架设过用来上Twitter奶瓶腿，是Nginx + php-cgi的方案，nginx是必须的。</p><p>Python跟web前端的架构方式有太多选择了，五花八门，MoinMoin的发行包里面都提供了<code>moin.cgi</code> <code>moin.scgi</code> <code>moin.ajp</code> <code>moin.fcgi</code> <code>moin.wsgi</code>等多种启动方式。MoinMoin里面全部通过内置的flup作为中间件提供这些接口，目前我仅尝试使用了fastcgi和wsgi。</p><p>虽然解压了moin的源码包就可以直接运行里面的<code>wikiserver.py</code>来本地访问了，但在服务器上通常是由nginx/lighttpd等服务来综合转发。php的话是通过<code>spawn-fcgi</code>启动一些php-cgi的进程，服务器接受到动态的请求就通过本地socket跟php-cgi通讯，返回的结果展现回给客户。php-cgi是使用FastCGI协议的。</p><p>MoinMoin 源码当中<code>wiki/server/moin.fcgi</code>就是一个类似php-cgi功能的fastcgi服务，类似地可以使用<code>spawn-fcgi</code>来启动moin.fcgi，作为后端的处理进程。</p><p><a
href="http://dotimes.com/iscale/2010/07/running-moinmoin-wiki-with-nginx-via-fastcgi-and-flup.html">Running MoinMoin Wiki with Nginx via FastCGI and Flup</a>该文章很形象解释了fastcgi的角色，以及提供了一段很方便的服务脚本来启动<code>spawn-fcgi</code>。</p><pre>
Client ----> Nginx Web Frontend -----------+
                                           | fastcgi_pass
                                          \|/
                            +-------------------------+
              moin.fcgi     | spawn-fcgi-moin.socket  |
spawn-fcgi ---------------> |           or            |
                            |     localhost:port      |
                            +-------------------------+
</pre><p>但是文章当中的nginx配置不完整，而且复杂了，这是我的配置：</p><div
class="wp_syntax"><div
class="code"><pre class="nginx" style="font-family:monospace;">server {
        listen   80; ## listen for ipv4
        server_name  wiki.apt-blog.net;
&nbsp;
access_log  /var/log/nginx/wiki.apt-blog.net.access.log;
        error_log   /var/log/nginx/wiki.apt-blog.net.error_log;
&nbsp;
location / {
                include fastcgi_params;
                fastcgi_param PATH_INFO $fastcgi_script_name;
                fastcgi_param SCRIPT_NAME /;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                if (!-f $request_filename) {
                        fastcgi_pass unix:/var/run/spawn-fcgi-moin.socket;
                }
        }
}</pre></div></div><p>当然那文章中的配置有考虑对静态文件直接由nginx服务，不通过flup这一层，有一定优化，这里省去了这些。其实增多一个<code>/moin_static193</code>(据版本号不同而不同)的location即可，可参考后面使用uwsgi做服务时候的配置。</p><p>文章还提到<code>wikiconfig.py</code>里面一个<code>fix_script_name</code>变量，是1.9版本新加入的，需要xxx.com/wiki这样访问的童鞋就不用像以前版本那样要在nginx配置里面写一大堆东西了。</p><p>Fastcgi就这么多，不算太复杂。Fastcgi虽然很流行，但弊端不少，首先是速度，在一台虚拟机上测试，用ab居然跑出每秒20个请求的速度……虽然平均下来还是有5、60次，但真的，唉。php-cgi还支持产生多个工作进程以并行和均衡请求，提高效率，fastcgi似乎就没这样的东西了。</p><p>刚好这天<a
href="http://obmem.info/">observer专栏杂记</a>写了一篇<a
href="http://obmem.info/?p=703">配置Nginx＋uwsgi更方便地部署python应用</a>，当中也提到<code>fcgi</code>和 <code>mod_python</code>的各种不便，然后介绍了<code>uwgi</code>，高性能、多应用。</p><p>uwgi充当了python解析器的角色，使用wsgi的接口和Python程序交互，这个过程中做了优化，和上层nginx之间则设计了更加轻量的协议。nginx0.8.40以后官方默认带了uwgi的协议模块，所以使用很方便。</p><p>uwgi的文档有些简略，但是重点都是在<a
href="http://projects.unbit.it/uwsgi/wiki/Example">wiki/Example</a>里面了。 MoinMoin在uwgi的配置在其中一句带过：</p><div
class="wp_syntax"><div
class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>uwsgi <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>moin.sock <span style="color: #660033;">--wsgi-file</span> wiki<span style="color: #000000; font-weight: bold;">/</span>server<span style="color: #000000; font-weight: bold;">/</span>moin.wsgi <span style="color: #660033;">-M</span> <span style="color: #660033;">-p</span> <span style="color: #000000;">4</span></pre></div></div><p>uwgi的-w参数是把某个py文件作为module，import使用，但是wsgi文件不被认识，所以新版里面多了这么个<code>--wsgi-file</code>参数。但是如果是多站点呢！</p><p>nginx配置的虚拟主机里面的<code>uwsgi_param UWSGI_SCRIPT</code>参数会让uwgi按模块导入名称，相当于命令行里面的<code>-w</code>，但是moinmoin的moin.wsgi文件，不是py结尾，只能用<code>--wsgi-file</code>参数。扫了一圈uwgi的<a
href="http://projects.unbit.it/uwsgi/wiki/Example">wiki/Example</a>和<a
href="http://projects.unbit.it/uwsgi/wiki/RunOnNginx">RunOnNginx</a>，都没提到这个问题，倒是在<a
href="http://projects.unbit.it/uwsgi/wiki/RunPinax">这里</a>提到在旧版的uwgi当中没有<code>--wsgi-file</code>参数，<strong><em>需要把wsgi文件改名成py结尾来导入</em></strong>，好吧，确实那样成功了。</p><p>至于性能，一开始我发现uwgi占的内存也不少，一个worker时候就占了20M多的内存，所以没开更多的工作进程；Fastcgi也差不多，然后用Apache Benchmark测试，好像两者区别不大。于是看了下<a
href="http://www.peterbe.com/plog/fcgi-vs-gunicorn-vs-uwsgi">fcgi vs. gunicorn vs. uWSGI的测评</a>，才发现uwgi要开多个worker进程才有性能！于是开了8个，性能出来了，秒请求马上就上千！ 显然是uwgi打开了多个进程，充分利用了机器的CPU，还做了均衡请求。</p><p>最后，我的Wiki使用uwgi后的nginx配置：</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td
class="code"><pre class="nginx" style="font-family:monospace;">server {
    server_name  wiki.apt-blog.net;
    access_log  /var/log/nginx/wiki.apt-blog.net.access.log;
    error_log   /var/log/nginx/wiki.apt-blog.net.error_log;
    location / {
        include uwsgi_params;
        #uwsgi_pass 127.0.0.1:9096;
        uwsgi_pass unix:///tmp/uswgi.sock;
        uwsgi_param UWSGI_PYHOME /usr/local/lib/moinmoin;
        uwsgi_param UWSGI_CHDIR /var/local/wiki-moinmoin/server;
        uwsgi_param UWSGI_SCRIPT moin_wsgi;
    }
    location /moin_static193/ {
        alias /usr/local/lib/moinmoin/lib/python2.6/site-packages/MoinMoin/web/static/htdocs/;
    }
}</pre></td></tr></table></div><p>完整配置指南：</p><div
class="wp_syntax"><div
class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#安装</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #660033;">-s</span>
add-apt-repository ppa:nginx<span style="color: #000000; font-weight: bold;">/</span>stable
add-apt-repository ppa:uwsgi<span style="color: #000000; font-weight: bold;">/</span>release
<span style="color: #c20cb9; font-weight: bold;">apt-get</span> update
<span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> nginx uwsgi-python python-virtualenv
&nbsp;
<span style="color: #666666; font-style: italic;">#组件配置</span>
<span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">&gt;/</span>etc<span style="color: #000000; font-weight: bold;">/</span>uwsgi-python<span style="color: #000000; font-weight: bold;">/</span>apps-enabled<span style="color: #000000; font-weight: bold;">/</span>uwsgi.xml <span style="color: #cc0000; font-style: italic;">&lt;&lt; EOF
&lt;uwsgi&gt;
  &lt;limit-as&gt;256&lt;/limit-as&gt;
  &lt;processes&gt;6&lt;/processes&gt;
  &lt;memory-report/&gt;
  &lt;vhost/&gt;
  &lt;no-site/&gt;
&lt;/uwsgi&gt;
EOF</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">&gt;/</span>etc<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>sites-enabled<span style="color: #000000; font-weight: bold;">/</span>moinmoin <span style="color: #cc0000; font-style: italic;">&lt;&lt; EOF
server {
    listen   80;
    access_log  /var/log/nginx/wiki.access_log;
    error_log   /var/log/nginx/wiki.error_log;
&nbsp;
client_max_body_size 64;
    server_name wiki.mydomian.com;
    location / {
                include uwsgi_params;
                uwsgi_pass unix:///var/run/uwsgi-python/uwsgi/socket;
                uwsgi_param UWSGI_PYHOME /var/www/moinmoin/python-home/;
                uwsgi_param UWSGI_CHDIR /var/www/moinmoin/;
                uwsgi_param UWSGI_SCRIPT moin_wsgi;
                uwsgi_param UWSGI_SCHEME $scheme;
                uwsgi_param REMOTE_USER $remote_user;
        }
}
EOF</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#Python环境预备</span>
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>moinmoin
virtualenv <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>moinmoin<span style="color: #000000; font-weight: bold;">/</span>python-home
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>tmp
<span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>static.moinmo.in<span style="color: #000000; font-weight: bold;">/</span>files<span style="color: #000000; font-weight: bold;">/</span>moin-1.9.3.tar.gz
<span style="color: #c20cb9; font-weight: bold;">tar</span> xvfz moin-1.9.3.tar.gz
<span style="color: #7a0874; font-weight: bold;">source</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>moinmoin<span style="color: #000000; font-weight: bold;">/</span>python-env<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>activate
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>moin-1.9.3
python setup.py <span style="color: #c20cb9; font-weight: bold;">install</span>
deactivate
&nbsp;
<span style="color: #666666; font-style: italic;">#MoinMoin环境</span>
<span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #660033;">-r</span> <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>moin-1.9.3<span style="color: #000000; font-weight: bold;">/</span>wiki <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>moinmoin
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>moinmoin<span style="color: #000000; font-weight: bold;">/</span>wiki
<span style="color: #c20cb9; font-weight: bold;">cp</span> config<span style="color: #000000; font-weight: bold;">/</span>wikiconfig.py wikiconfig.py
<span style="color: #c20cb9; font-weight: bold;">cp</span> server<span style="color: #000000; font-weight: bold;">/</span>moin.wsgi moin_wsgi.py
<span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-i</span> <span style="color: #ff0000;">'/# a2)/isys.path.insert(0, os.path.abspath(os.path.dirname(__file__)))'</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#可选</span>
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> config server
&nbsp;
<span style="color: #666666; font-style: italic;">#重启</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>nginx restart
<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>uwsgi-python restart</pre></div></div> ]]></content:encoded> <wfw:commentRss>http://apt-blog.net/moinmoin-on-nginx-via-fastcgi-and-uwgi/feed</wfw:commentRss> <slash:comments>14</slash:comments> </item> <item><title>OpenVPN连接后自动替换DNS服务器</title><link>http://apt-blog.net/auto-replace-dns-while-connecting-to-vpn</link> <comments>http://apt-blog.net/auto-replace-dns-while-connecting-to-vpn#comments</comments> <pubDate>Thu, 07 Oct 2010 07:08:51 +0000</pubDate> <dc:creator>BOYPT</dc:creator> <category><![CDATA[Shell]]></category> <category><![CDATA[Unix/Linux]]></category> <category><![CDATA[bash]]></category> <category><![CDATA[DNS]]></category> <category><![CDATA[openvpn]]></category> <category><![CDATA[sed]]></category> <category><![CDATA[shell]]></category> <category><![CDATA[vpn]]></category> <guid
isPermaLink="false">http://apt-blog.net/auto-replace-dns-while-connecting-to-vpn</guid> <description><![CDATA[因为国内的DNS服务器存在污染问题，用VPN后都不愿意用国内的DNS服务器；但是如果常用8.8.8.8等，又导致访问国内的cdn时候返回线路，导致访问缓慢；这个问题不好解决，相对好点的方法在连接vpn前使用isp提供的dns，而连接后替换成外国的dns。 但是OpenVPN的--dhcp-option配置，对非Win32的客户端是无效的，只能考虑执行自定义脚本来完成： vpnup.sh 1 2 3 4 5 6 7 8 9 #!/bin/bash RESOLVE=/etc/resolv.conf FOREIGNDNS1='4.2.2.1' FOREIGNDNS2='4.2.2.2' DNSMARK='_MK' &#160; sed &#34;s/^nameserver/#$DNSMARK nameserver/&#34; -i $RESOLVE echo &#34;nameserver $FOREIGNDNS1&#34; &#62;&#62; $RESOLVE echo &#34;nameserver $FOREIGNDNS2&#34; &#62;&#62; $RESOLVE vpndown.sh 1 2 3 4 #!/bin/bash RESOLVE=/etc/resolv.conf DNSMARK='_MK' sed -e '/^nameserver/d' -e &#34;s/^#$DNSMARK //&#34; -i $RESOLVE 很简单，就是使用sed来完成/etc/resolv.conf文件的内容替换。 实际上我还使用了chnroutes的脚本生成的国内路由表，上面两段只是分别贴到其中的vpnup/vpndown当中。]]></description> <content:encoded><![CDATA[<p>因为国内的DNS服务器存在污染问题，用VPN后都不愿意用国内的DNS服务器；但是如果常用8.8.8.8等，又导致访问国内的cdn时候返回线路，导致访问缓慢；这个问题不好解决，相对好点的方法在连接vpn前使用isp提供的dns，而连接后替换成外国的dns。</p><p>但是OpenVPN的--dhcp-option配置，对非Win32的客户端是无效的，只能考虑执行自定义脚本来完成：</p><p>vpnup.sh</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td
class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #007800;">RESOLVE</span>=<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>resolv.conf
<span style="color: #007800;">FOREIGNDNS1</span>=<span style="color: #ff0000;">'4.2.2.1'</span>
<span style="color: #007800;">FOREIGNDNS2</span>=<span style="color: #ff0000;">'4.2.2.2'</span>
<span style="color: #007800;">DNSMARK</span>=<span style="color: #ff0000;">'_MK'</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">&quot;s/^nameserver/#<span style="color: #007800;">$DNSMARK</span> nameserver/&quot;</span> <span style="color: #660033;">-i</span> <span style="color: #007800;">$RESOLVE</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;nameserver <span style="color: #007800;">$FOREIGNDNS1</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$RESOLVE</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;nameserver <span style="color: #007800;">$FOREIGNDNS2</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$RESOLVE</span></pre></td></tr></table></div><p>vpndown.sh</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
</pre></td><td
class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #007800;">RESOLVE</span>=<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>resolv.conf
<span style="color: #007800;">DNSMARK</span>=<span style="color: #ff0000;">'_MK'</span>
<span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'/^nameserver/d'</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;s/^#<span style="color: #007800;">$DNSMARK</span> //&quot;</span> <span style="color: #660033;">-i</span> <span style="color: #007800;">$RESOLVE</span></pre></td></tr></table></div><p>很简单，就是使用sed来完成<code>/etc/resolv.conf</code>文件的内容替换。</p><p>实际上我还使用了<a
href="http://code.google.com/p/chnroutes/">chnroutes</a>的脚本生成的国内路由表，上面两段只是分别贴到其中的vpnup/vpndown当中。</p> ]]></content:encoded> <wfw:commentRss>http://apt-blog.net/auto-replace-dns-while-connecting-to-vpn/feed</wfw:commentRss> <slash:comments>4</slash:comments> </item> <item><title>Nginx与奶瓶腿（Dabr）</title><link>http://apt-blog.net/nginx_and_dabr</link> <comments>http://apt-blog.net/nginx_and_dabr#comments</comments> <pubDate>Mon, 27 Sep 2010 10:43:37 +0000</pubDate> <dc:creator>BOYPT</dc:creator> <category><![CDATA[Blogger Tech]]></category> <category><![CDATA[Unix/Linux]]></category> <guid
isPermaLink="false">http://apt-blog.net/nginx_and_dabr</guid> <description><![CDATA[上个月买了台在美帝的超廉价vps，基本上跑跑openvpn什么的，一个月下来流量一个百分点都没过，于是试试架点别的服务，先试试奶瓶腿。 VPS的内存就是钱。虽然这台VPS有384M内存，不算小，但apache什么的内存大户还是不考虑了，直接上nginx+fastcgi。 此前有做过这个组合的笔记《简单配置nginx+fastcgi后端的WordPress服务器》，不做博客的话mysql就省掉了。 但是启动php-cgi是个问题，还好有人写了不错的启动脚本/etc/init.d/php-fastcgi，Nginx, PHP and a PHP FastCGI daemon init script。而这篇How to set up nginx with PHP on Ubuntu的脚本稍微简化一点，而且是用Unix Socket来绑定nginx跟fastcgi的通讯。这样就免除了lo interface的依赖。 假设奶瓶Dabr是没什么难度的事情，奶瓶腿的话，我从项目的SVN checkout出源码后，下载 user_oauth.php并改名覆盖原来的common/user.php，以支持后台自动oauth登录Twitter；然后配置到nginx的虚拟主机目录下，基本就结了。 当然兽兽Showfom的Dabr教程里面提到了使用nginx的伪静态改写规则，这必须的（跟用wordpress一样）： 1 2 3 if &#40;!-e $request_filename&#41; &#123; rewrite ^/&#40;.*&#41;$ /index.php?q=$1 last; &#125; 最后遇到的问题是，访问奶瓶腿的Setting，保存后502错误，查看error.log看到报的是： 24219#0: *40 upstream sent too big header while reading response header from upstream 直接Google找到答案，就是调大nginx的fastcgi缓冲区。 1 2 [...]]]></description> <content:encoded><![CDATA[<p>上个月买了台在美帝的超廉价vps，基本上跑跑openvpn什么的，一个月下来流量一个百分点都没过，于是试试架点别的服务，先试试奶瓶腿。</p><p>VPS的内存就是钱。虽然这台VPS有384M内存，不算小，但apache什么的内存大户还是不考虑了，直接上nginx+fastcgi。</p><p>此前有做过这个组合的笔记<a
href="http://apt-blog.net/setup_nginx">《简单配置nginx+fastcgi后端的WordPress服务器》</a>，不做博客的话mysql就省掉了。</p><p>但是启动php-cgi是个问题，还好有人写了不错的启动脚本<code>/etc/init.d/php-fastcgi</code>，<a
href="http://blog.codefront.net/2007/06/11/nginx-php-and-a-php-fastcgi-daemon-init-script/">Nginx, PHP and a PHP FastCGI daemon init script</a>。而这篇<a
href="http://igorpartola.com/tag/ubuntu-php-nginx-fastcgi-vps-performance">How to set up nginx with PHP on Ubuntu</a>的脚本稍微简化一点，而且是用Unix Socket来绑定nginx跟fastcgi的通讯。这样就免除了lo interface的依赖。</p><p>假设奶瓶Dabr是没什么难度的事情，<a
href="https://code.google.com/p/netputweets/source/checkout">奶瓶腿的话</a>，我从项目的SVN checkout出源码后，<a
href="https://code.google.com/p/netputweets/downloads/list">下载 user_oauth.php</a>并改名覆盖原来的common/user.php，以支持后台自动oauth登录Twitter；然后配置到nginx的虚拟主机目录下，基本就结了。</p><p>当然<a
href="http://zou.lu/dabr/">兽兽Showfom的Dabr教程</a>里面提到了使用nginx的伪静态改写规则，这必须的（<a
href="http://apt-blog.net/setup_nginx">跟用wordpress一样</a>）：</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
</pre></td><td
class="code"><pre class="bash" style="font-family:monospace;">    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">!</span>-e <span style="color: #007800;">$request_filename</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
        rewrite ^<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>.<span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>$ <span style="color: #000000; font-weight: bold;">/</span>index.php?<span style="color: #007800;">q</span>=<span style="color: #007800;">$1</span> <span style="color: #c20cb9; font-weight: bold;">last</span>;
    <span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></td></tr></table></div><p>最后遇到的问题是，访问奶瓶腿的Setting，保存后502错误，查看error.log看到报的是：</p><pre>
24219#0: *40 upstream sent too big header while reading response header from upstream
</pre><p>直接Google找到答案，就是调大nginx的fastcgi缓冲区。</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
5
</pre></td><td
class="code"><pre class="bash" style="font-family:monospace;">fastcgi_connect_timeout <span style="color: #000000;">60</span>;
fastcgi_send_timeout <span style="color: #000000;">180</span>;
fastcgi_read_timeout <span style="color: #000000;">180</span>;
fastcgi_buffer_size 128k;
fastcgi_buffers <span style="color: #000000;">4</span> 128k;</pre></td></tr></table></div><p>把这段加入到虚拟主机的配置下面，完了。没什么营养。</p><p><strong>Update: 2011-02-28</strong></p><p>2010版的奶瓶里面改用了itap作为oauth代理，但是itap对改写的规则跟奶瓶不兼容，如果使用nginx配置，需要配置两个Location域：</p><div
class="wp_syntax"><div
class="code"><pre class="text" style="font-family:monospace;">server {
    listen   80; ## listen for ipv4
    server_name     your.server.com;
    access_log /var/log/nginx/netputtweet.access.log;
    error_log /var/log/nginx/netputtweet.error.log;
    root    /var/www/netputweets/;
    index   index.html index.htm index.php;
    location / {
            if (!-e $request_filename) {
                    rewrite ^/(.*)$ /index.php?q=$1 last;
            }
    }
    location /oauthproxy/ {
            if (!-e $request_filename) {
                    rewrite . /oauthproxy/index.php last;
            }
    }
    location ~ \.php$ {
          include        fastcgi_params;
          fastcgi_pass   127.0.0.1:9000;
          fastcgi_index  index.php;
          #fastcgi_param  HTTPS on; #if you use HTTPS
          fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    }
}</pre></div></div> ]]></content:encoded> <wfw:commentRss>http://apt-blog.net/nginx_and_dabr/feed</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>Debian/Ubuntu - Xen折腾秘笈</title><link>http://apt-blog.net/cheat-notes-about-using-xen-under-debian-ubuntu</link> <comments>http://apt-blog.net/cheat-notes-about-using-xen-under-debian-ubuntu#comments</comments> <pubDate>Mon, 23 Aug 2010 10:40:47 +0000</pubDate> <dc:creator>BOYPT</dc:creator> <category><![CDATA[Unix/Linux]]></category> <category><![CDATA[Debian]]></category> <category><![CDATA[Linux]]></category> <category><![CDATA[Ubuntu]]></category> <category><![CDATA[virtual]]></category> <category><![CDATA[xen]]></category> <category><![CDATA[xen-tools]]></category> <guid
isPermaLink="false">http://apt-blog.net/?p=864</guid> <description><![CDATA[作为秘籍，本文包含折腾Xen所必须了解，但是在一般能找到的教程里面都没提及的资料。这里不包含一些必须的步骤等，所以很可能你需要先浏览这些资料，并让浏览器同时开着这些页面随时查阅： DebianWiki Xen DebianWiki DebianInstaller/Xen XenWiki HowTos Ubuntu Doc/Xen Ubuntu 9.04上的XEN虚拟服务器（一） 安装XEN （二） 安装虚拟机 在 Debian 上安装和配置 Xen 一：Xen工具及其关系 《在 Debian 上安装和配置 Xen》一文把在Debian上安装Xen简化成一道命令： On Debian Lenny 5.0 : apt-get install xen-hypervisor-3.2-1-amd64 xen-linux-system-2.6.26-2-xen-amd64 xen-utils-3.2-1 xenstore-utils xenwatch xen-shell xen-tools On Debian Squeeze 6.0 apt-get install xen-linux-system xen-hypervisor xen-utils xen-tools xen-hypervisor主要只有一个文件:/boot/xen-3.2-1-amd64.gz，就是宿主内核； xen-linux-system则是打了Xen补丁的Linux内核，这个内核脱离hypervisor是无法启动的，只适用于虚拟机；dom0对hypervisor来说也是虚拟机之一，domU也可以直接用这个内核启动。 xen-utils则是运行在Dom0上的程序，比如xend、xm，作用是跟hypervisor通讯，是主要由Python编写的一系列程序。 xen-tools是如xen-create-image的一系列工具，作为xm工具的前端，用以管理安装虚拟机；这是一套perl脚本，也有很灵活扩展性。 xen-shell是一个交互式的shell，常见用于VPS服务商提供给用户的操作界面，用户根据几个封装好的命令控制虚拟机如重启等工作。(Debian 6.0 下没有了。) xenstore-utils、 [...]]]></description> <content:encoded><![CDATA[<p>作为秘籍，本文包含折腾Xen所必须了解，但是在一般能找到的教程里面都没提及的资料。这里不包含一些必须的步骤等，所以很可能你需要先浏览这些资料，并让浏览器同时开着这些页面随时查阅：</p><ul><li><a
href="http://wiki.debian.org/Xen">DebianWiki Xen</a></li><li><a
href="http://wiki.debian.org/DebianInstaller/Xen">DebianWiki DebianInstaller/Xen</a></li><li><a
href="http://wiki.xensource.com/xenwiki/HowTos">XenWiki HowTos</a></li><li><a
href="https://help.ubuntu.com/community/Xen">Ubuntu Doc/Xen</a></li><li>Ubuntu 9.04上的XEN虚拟服务器<a
href="http://wells.osall.com/blog/index.php?m=content&amp;p=1434">（一） 安装XEN</a> <a
href="http://wells.osall.com/blog/index.php?m=content&amp;p=1436">（二） 安装虚拟机</a></li><li><a
href="http://www.vpsee.com/2010/03/install-xen-on-debian/">在 Debian 上安装和配置 Xen</a></li></ul><h2>一：Xen工具及其关系</h2><p>《<a
href="http://www.vpsee.com/2010/03/install-xen-on-debian/">在 Debian 上安装和配置 Xen</a>》一文把在Debian上安装Xen简化成一道命令：</p><p>On Debian Lenny 5.0 :</p><div
class="wp_syntax"><div
class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> xen-hypervisor-<span style="color: #000000;">3.2</span>-<span style="color: #000000;">1</span>-amd64
xen-linux-system-2.6.26-<span style="color: #000000;">2</span>-xen-amd64 xen-utils-<span style="color: #000000;">3.2</span>-<span style="color: #000000;">1</span>
xenstore-utils xenwatch xen-shell xen-tools</pre></div></div></p><p>On Debian Squeeze 6.0</p><div
class="wp_syntax"><div
class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> xen-linux-system xen-hypervisor xen-utils xen-tools</pre></div></div></p><ul><li><code>xen-hypervisor</code>主要只有一个文件:<code>/boot/xen-3.2-1-amd64.gz</code>，就是宿主内核；</li><li><code>xen-linux-system</code>则是打了Xen补丁的Linux内核，这个内核脱离hypervisor是无法启动的，只适用于虚拟机；dom0对hypervisor来说也是虚拟机之一，domU也可以直接用这个内核启动。</li><li><code>xen-utils</code>则是运行在Dom0上的程序，比如xend、xm，作用是跟hypervisor通讯，是主要由Python编写的一系列程序。</li><li><code>xen-tools</code>是如<code>xen-create-image</code>的一系列工具，作为xm工具的前端，用以管理安装虚拟机；这是一套perl脚本，也有很灵活扩展性。</li><li><code>xen-shell</code>是一个交互式的shell，常见用于VPS服务商提供给用户的操作界面，用户根据几个封装好的命令控制虚拟机如重启等工作。(Debian 6.0 下没有了。)</li><li><code>xenstore-utils</code>、 <code>xenwatch</code>分别是虚拟机间数据共享和虚拟机监控的工具，不是必要组建，可不安装。</li></ul><h2>二: Dom0的启动</h2><ol><li><p>grub2跟xen dom0目前关系不怎么所以如果你用grub2启动遇到挂掉xen启动不起来之类的，换回grub-legacy吧。</p></li><li><p>装完xen-hypervisor后可以打开<code>/boot/grub/menu.lst</code>看看，第一个选项应该是<code>Xen 3.2-1-amd64</code>之类的，看他的启动参数，是先加载Xen内核/xen-3.2-1-amd64.gz，再按模块挂在Linux内核；如果没有出现，需要运行<code>update-grub</code>。有这个后就可以放心重启了。</p></li><li><p><code>/boot/grub/menu.lst</code>文件里面有这么一行配置：</p></li></ol><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
</pre></td><td
class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">## Xen hypervisor options to use with the default Xen boot option</span>
<span style="color: #666666; font-style: italic;"># xenhopt=</span></pre></td></tr></table></div><p>是预留来传hypervisor参数的，比如要限制dom0的内存使用，可以写成：</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
</pre></td><td
class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># xenhopt=dom0_mem=256M</span></pre></td></tr></table></div><p>修改后记得运行 <code>update-grub</code>才生效。</p><p>关于Dom0内存的占用可能导致虚拟机不稳定可参看：<a
href="http://www.jolokianetworks.com/70Knowledge/Virtualization/My_Xen_is_Crashing!/Dom0_mem_allocation_and_domU_network_issues">Dom0 mem allocation and domU network issues</a>。</p><h2>三：虚拟机的网络</h2><p>无论是简单的桥接，安全的NAT子网，内部私有网，单双向网，利用内核的特性都可以做到： <a
href="http://wiki.kartbuilding.net/index.php/Xen_Networking">Xen Networking</a></p><h2>四：虚拟机的安装</h2><h3>关于管理工具</h3><p>有两套工具可以用来创建Xen虚拟机：<a
href="http://www.xen-tools.org/software/xen-tools/">xen-tools</a>, <a
href="http://libvirt.org/index.html">libvirt-bin</a>，从它们各自的主页很清晰看到它们的定位不同，前者主要用于本地管理Xen，由Debian支持，后者用于管理各种虚拟方案（xen,openvz,kvm,qeum,vbox,vmware....），由Redhat支持。虽然都支持跟兼容，但实际上前者有利于安装前者的系统，后者有利于安装后者的系统。这里只研究前者。</p><h3>关于 xen-create-image</h3><p>xen-tools是相当简单实用的一套脚本，教程里面一般提到使用的<code>xen-create-image</code>。</p><p>xen-tools有一个全局配置文件<code>/etc/xen-tools/xen-tools.conf</code>，里面写的参数会最终被<code>xen-create-image</code>的命令行参数覆盖或补充。</p><h3>关于 --install-method</h3><p>xen-tools的作用主要是控制怎么安装一个发行版，因为xen虚拟机的特殊方式，一般都不会启动该发行版的安装程序，而是用发行版的基础包管理来进行安装，安装参数<code>--install-method</code>负责这个过程，比如Debian/Ubuntu就要用<code>debootstrap</code>方法安装，CentOS/Fedora用<code>rinse</code>或<code>rpmstrap</code>，另外还有<code>copy</code>、<code>tar</code>方法。安装好一个模板系统后对那个镜像手动挂载，tar压缩后来用部署其他虚拟机，是个好方法。</p><h3>关于 --dist</h3><p><code>--dist</code>让你指定一个发行版的名字，你会发现并不是所有发行版都能被支持的，实际支持的可以看看<code>/usr/lib/xen-tools</code>的内容，里面各个对应发行版的目录内都包含了一系列的脚本，如预先安装什么包，需要设置某个配置文件，比如说<code>libc6-xen</code>，不过在<a
href="http://xen-tools.org/lists/xen-tools-discuss/Apr07/0265.html">64位机环境下这个是不需要的</a>，脚本会自动判断。</p><h3>关于安装新版本系统</h3><p>因为版本太旧，在Debian Lenny里面的xen-tools跟debootstrap不能直接支持比如Ubuntu Lucid(10.4)之类的较新的发行版的安装，倒是有比较曲折的方法<a
href="http://blog.webangel.ie/2010/04/ubuntu-upgrade-to-9-1010-04-for-xen-domu/">Ubuntu upgrade to 9.10/10.04 for Xen DomU</a> 。但其实有更好的方法：下载新版的<a
href="http://packages.debian.org/squeeze/xen-tools">Xen-tools</a>跟<a
href="http://packages.debian.org/squeeze/debootstrap">debootstrap</a>的deb回来装上。因为这些只是一些脚本，不会跟系统其他包有冲突。装完后就可以直接安装新版系统了。(dpkg安装新版xen-tool时候提示缺一个依赖，按名字装上即可)</p><h3>关于 --mirror</h3><p>安装教程里面一般都让你指定一个对应发行版的源，考虑到网速因素，这样安装一个虚拟机是很累的，虽然xen-create-image有个<code>--cache</code>可以在dom0上缓存deb包。其实如果你有相应发行版的iso文件，完全可以拿iso来做安装源：</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
</pre></td><td
class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>isodir
<span style="color: #c20cb9; font-weight: bold;">mount</span> <span style="color: #660033;">-o</span> loop <span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>the_iso_file.iso <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>isodir
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>isodir
python <span style="color: #660033;">-m</span> SimpleHTTPServer</pre></td></tr></table></div><p>现在这个机器就在8000端口上运行着一个HTTP源了，直接在mirror参数里面指定该地址即可，这样的安装过程很快。缺点是可能安装脚本有一些包在iso中没有提供而出错，建议加上<code>--verbose</code>参数查看整个安装过程。</p><p>安装过程的日至会被放在<code>/var/log/xen-tools/&lt;NAME&gt;.log</code>，如果安装过程出现什么问题可以直接看这个对应的文件。使用本地ISO做源虽然一般没什么问题，但如果缺了什么包之类的会在日志中提示。</p><h3>关于 --role</h3><p><code>--role=udev</code>这个参数建议创建新虚拟机时候加上。<code>--role</code>参数会让创建脚本在<code>/etc/xen-tools/role.d/</code>目录下寻找相应名字的脚本运行，udev就是其中一个，作用是给虚拟机装上<code>udev</code>包。udev是提供动态<code>/dev</code>目录的机制，是提供内核对硬件识别的事件桥梁，对一般的xen虚拟机来说影响不算太大，如果不安装最显然的是会找不到<code>/dev/shm</code>挂载点（启动过程有一个warnning），但一般来说还是推荐安装。</p><p><code>/etc/xen-tools/role.d/</code>里面默认包含了以下一些有用的脚本，使用时可以逗号分隔，如<code>--role=udev,minimal,cfengine</code>：</p><ul><li><code>builder</code> 自动安装build-essential等编译链包，部署distcc集群有用。</li><li><code>cfengine</code> CFengine是一个服务器自动化控制服务，对部署大量服务器很有用。会拷贝dom0上的配置。</li><li><code>editor</code> 自动根据dom0里面的sed脚本来配置domU内的配置文件，具体可以打开<code>/etc/xen-tools/role.d/editor</code>看看说明。</li><li><code>passwd</code> 自动修改domU的密码。默认--passwd参数是会出现passwd的交互修改root密码的过程，用这个role脚本就可以实现自动应答。要使用<code>--role-args=mYpassWd</code>传入相应密码。</li><li><code>minimal</code> 精简化domU系统。安装一些screen、vim等实用工具，卸除manpages等对虚拟机意义不大的包。</li><li><code>udev</code> 如前述，安装<code>udev</code>包。</li><li><code>xdm</code> 安装X、xdm、icewm等GUI包。</li><li><code>gdm</code> 同上，登陆器换成gdm。</li></ul><p>另外这些脚本默认都是针对Debian系系统设计的，Redhat系的应该用不了。</p><h3>关于 --pygrub</h3><p>最后有个<code>--pygrub</code>参数，关系到domU的引导过程。xen的半虚拟并没有从引导区的虚拟过程，而是直接读取内核文件运行。默认情况下是直接用dom0的内核的，如果domU的发行版跟版本跟dom0一致，这样处理倒是很方便，但是一旦不一致就容易出现找不到root分区等各种引导问题。如果安装的domU的系统跟dom0不一致的（包括amd64/i386这样的架构不同），就加上<code>--pygrub</code>参数，这会让domU安装上它自己的内核，以及生成一个<code>/boot/grub/menu.lst</code>文件，引导虚拟机时会根据这个文件模拟grub出现一个引导菜单，提出其自己的内核文件来启动虚拟机。</p><p>pygrub其实是xend的一个python工具，在<code>/usr/lib/xen-3.2-1/bin/pygrub</code>，可以直接这样运行来测试pygrub是否正常读取到内核：</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
</pre></td><td
class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>xen-<span style="color: #000000;">3.2</span>-<span style="color: #000000;">1</span><span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>pygrub <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>xen<span style="color: #000000; font-weight: bold;">/</span>domains<span style="color: #000000; font-weight: bold;">/</span>lenny3<span style="color: #000000; font-weight: bold;">/</span>disk.img</pre></td></tr></table></div><p>会出现菜单，选择后会退出，返回一段临时文件数据，内核文件的临时位置。</p><p>目前在Debian Squeeze内的Xen 4.0的pygrub有个小小的低级错误，运行后会报模块导入错误，其实只要编辑<code>/usr/lib/xen-4.0/bin/pygrub</code>文件，把里面修改path的一行提前即可：</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
</pre></td><td
class="code"><pre class="python" style="font-family:monospace;"><span style="color: #dc143c;">sys</span>.<span style="color: black;">path</span>.<span style="color: black;">insert</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span>, <span style="color: #dc143c;">sys</span>.<span style="color: black;">path</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> + <span style="color: #483d8b;">'/../lib/python'</span><span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;">#这行原在30行左右，提前到这里</span>
<span style="color: #ff7700;font-weight:bold;">import</span> xen.<span style="color: black;">lowlevel</span>.<span style="color: black;">xc</span>  <span style="color: #808080; font-style: italic;">#原本这里出错</span></pre></td></tr></table></div><h3>典型的几种创建方法</h3><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
5
</pre></td><td
class="code"><pre class="bash" style="font-family:monospace;">xen-create-image <span style="color: #660033;">--hostname</span>=my-lenny <span style="color: #660033;">--dist</span>=lenny <span style="color: #660033;">--mirror</span>=http:<span style="color: #000000; font-weight: bold;">//</span>mirrors.163.com<span style="color: #000000; font-weight: bold;">/</span>debian <span style="color: #660033;">--role</span>=udev <span style="color: #660033;">--force</span> <span style="color: #660033;">--verbose</span>
&nbsp;
xen-create-image <span style="color: #660033;">--hostname</span>=my-ubuntu-vm <span style="color: #660033;">--dist</span>=lucid <span style="color: #660033;">--mirror</span>=http:<span style="color: #000000; font-weight: bold;">//</span>mirrors.163.com<span style="color: #000000; font-weight: bold;">/</span>ubuntu <span style="color: #660033;">--role</span>=udev <span style="color: #660033;">--pygrub</span> <span style="color: #660033;">--force</span> <span style="color: #660033;">--verbose</span>
&nbsp;
xen-create-image <span style="color: #660033;">--hostname</span>=my-xen-vm <span style="color: #660033;">--dist</span>=squeeze <span style="color: #660033;">--install-method</span>=<span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">--install-source</span>=<span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>system_tared.tar.gz <span style="color: #660033;">--pygrub</span> <span style="color: #660033;">--force</span> <span style="color: #660033;">--verbose</span></pre></td></tr></table></div><h2>第五章：虚拟机的运行</h2><h3>关于虚拟机配置文件</h3><p>完成创建虚拟机后，默认情况下在<code>/home/xen/domains/&lt;NAME&gt;</code>下生成虚拟机的磁盘文件，在<code>/etc/xen/&lt;NAME&gt;.cfg</code>生成相应虚拟机的配置文件。关于虚拟机配置的修改，只需直接打开这个cfg文件修改即可(如内存大小，CPU多少，使用VNC等)。配置文件其实是一个Python脚本，也就是说可以对虚拟机的参数进行创建时的动态调节。</p><p>配置文件的选项完整说明可以运行<code>xm create --help_config</code>查看。</p><p>启动虚拟机以Xen的术语来说是创建一个实例：<code>xm create -c /etc/xen/&lt;NAME&gt;.cfg</code>，-c参数可以马上进入虚拟机的console，使用pygrub的虚拟机只能通过这个方法看到grub菜单。</p><h3>关于虚拟机启动过程</h3><p>本文成文时，使用Debian Lenny默认安装系统部署的domU似乎都有一个启动bug，即创建后使用<code>xm console &lt;NAME&gt;</code>仅能看到虚拟机启动的log信息，但是不出现shell，也无法登录，无法响应，只能按<code>ctrl-]</code>返回dom0。如果按上述安装了新版的<a
href="http://packages.debian.org/squeeze/xen-tools">Xen-tools</a>跟<a
href="http://packages.debian.org/squeeze/debootstrap">debootstrap</a>再创建的虚拟机就没有这个问题了。</p><p>用了旧版工具但要修复这个问题也不算太麻烦：</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td
class="code"><pre class="bash" style="font-family:monospace;">xm shutdown <span style="color: #000000; font-weight: bold;">&lt;</span>NAME<span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #666666; font-style: italic;">#确保关闭，运行xm list确保虚拟机已经没有运行</span>
<span style="color: #c20cb9; font-weight: bold;">mount</span> <span style="color: #660033;">-o</span> loop <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>xen<span style="color: #000000; font-weight: bold;">/</span>domains<span style="color: #000000; font-weight: bold;">/&lt;</span>NAME<span style="color: #000000; font-weight: bold;">&gt;/</span>disk.img <span style="color: #000000; font-weight: bold;">/</span>mnt
<span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>inittab <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>inittab.bak
<span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/tty1/hvc0/'</span> <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>inittab.bak <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>inittab
<span style="color: #c20cb9; font-weight: bold;">umount</span> <span style="color: #000000; font-weight: bold;">/</span>mnt</pre></td></tr></table></div><p>就是替换<code>/mnt/etc/inittab</code>文件里面，把虚拟终端的交互设备从tty1改成hvc0。在新版的xen-tools里面，这个替换已经由安装脚本完成了。hvc0是Xen虚拟机的类终端设备，只有让虚拟终端的输出输入跟hvc0链接，才能通过xen的console方法登录虚拟机。</p><p>如果使用vnc连接虚拟机，又会发现vnc里面无法登录虚拟机，vnc是framebuffer驱动的图形，默认连接tty1设备，可以按上述方法打开虚拟机的<code>/mnt/etc/inittab</code>文件，在getty那一段，写成这样：</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
</pre></td><td
class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000;">0</span>:<span style="color: #000000;">2345</span>:respawn:<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>getty <span style="color: #000000;">38400</span> hvc0
<span style="color: #000000;">1</span>:<span style="color: #000000;">2345</span>:respawn:<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>getty <span style="color: #000000;">38400</span> tty1</pre></td></tr></table></div><p>如果你安装的是Ubuntu，Ubuntu默认没有使用inittab来配置终端，而是使用了新的机制，使用目录<code>/etc/init/</code>里面的文件来控制，可以发现里面有tty1.conf之类的文件，可以<code>cp /etc/init/tty1.conf /etc/init/hvc0.conf</code>，然后打开<code>/etc/init/hvc0.conf</code>，把tty1那一段改成hvc0，保存即可。</p><h3>关于使用VNC查看虚拟机</h3><p>关于VNC的设置在<code>/etc/xen/xend-config.sxp</code>和各个虚拟机的配置文件里面都有选项，关系是前者是全局配置。</p><p>要打开一个虚拟机的VNC输出，只需在其配置文件内添加（望文生义即可）：</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
</pre></td><td
class="code"><pre class="python" style="font-family:monospace;">vfb = <span style="color: black;">&#91;</span> <span style="color: #483d8b;">'type=vnc'</span> <span style="color: black;">&#93;</span>
<span style="color: #808080; font-style: italic;">#复杂点的：</span>
vfb = <span style="color: black;">&#91;</span> <span style="color: #483d8b;">'type=vnc,vncdisplay=10,vncpasswd=s3cr3t'</span> <span style="color: black;">&#93;</span></pre></td></tr></table></div><p>vncdisplay的值加上5900，得到的就是最终vnc服务所监听的端口。</p><p>更复杂的配置选项看<code>xm create --help_config</code>。</p><h3>关于虚拟机的自动启动</h3><p>让虚拟机跟随dom0启动的方法有很几种，比如在<code>/etc/xen/auto/</code>目录里面放虚拟机配置文件的链接。但似乎更好的做法是在每个配置文件里面写上：</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
</pre></td><td
class="code"><pre class="python" style="font-family:monospace;">on_xend_start = <span style="color: #483d8b;">'start'</span>
on_xend_stop = <span style="color: #483d8b;">'suspend'</span></pre></td></tr></table></div><p>这样的好处是当dom0关机，Xen会先让虚拟机进入挂起状态（当然也可以改成shutdown直接关机），下次重启后虚拟机直接恢复。</p><h2>第六章：其他问题</h2><h3>关于虚拟机的磁盘方式</h3><p>使用xen-create-image工具创建的虚拟机，默认都是使用loop文件设备来映射，这样对io比较敏感的服务来说会有些影响。<a
href="http://wiki.xensource.com/xenwiki/blktap">Xen3.3后引入了使用blktap驱动映射的磁盘设备</a>，据称性能会有提高，不过根据试验好像跟pygrub配搭不怎么稳定（在xen-4.0下）。</p><p>觉得最靠谱的方式是使用lvm，xen-create-image工具也是支持直接创建lvm逻辑卷来安装的，这样即没有性能问题，也没有稳定问题。</p><h3>全虚拟半虚拟与CPU支持VM指令集的关系</h3><p>扫了一圈Google到的Xen资料，很多都让你检查<code>/proc/cpuinfo</code>里面有没有支持VM标记。其实CPU是否支持VM指令集，对xen来说只是能不能跑windows的问题，对于Xen的特色——半虚拟来说没什么影响，而且这才是xen最有价值的地方。</p><h2>相关资料</h2><ul><li><a
href="http://wiki.kartbuilding.net/index.php/Details,_Installation,_%26_Set-up_of_Debian_based_Linux_Servers">Details, Installation, &amp; Set-up of Debian based Linux Servers</a></li><li><a
href="http://mediakey.dk/~cc/howto-install-windows-xp-vista-on-xen/">Howto Install Windows XP / Vista on Xen</a></li></ul> ]]></content:encoded> <wfw:commentRss>http://apt-blog.net/cheat-notes-about-using-xen-under-debian-ubuntu/feed</wfw:commentRss> <slash:comments>6</slash:comments> </item> </channel> </rss>
