﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-无法递归的五点半</title><link>http://www.cppblog.com/lambdacpp/</link><description>for_each(day.begin(),day.end(),bind2nd(Add(),me))</description><language>zh-cn</language><lastBuildDate>Thu, 23 Apr 2026 10:09:11 GMT</lastBuildDate><pubDate>Thu, 23 Apr 2026 10:09:11 GMT</pubDate><ttl>60</ttl><item><title>OpenLDAP启动与配置</title><link>http://www.cppblog.com/lambdacpp/archive/2010/12/25/137454.html</link><dc:creator>五点半</dc:creator><author>五点半</author><pubDate>Sat, 25 Dec 2010 09:07:00 GMT</pubDate><guid>http://www.cppblog.com/lambdacpp/archive/2010/12/25/137454.html</guid><wfw:comment>http://www.cppblog.com/lambdacpp/comments/137454.html</wfw:comment><comments>http://www.cppblog.com/lambdacpp/archive/2010/12/25/137454.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lambdacpp/comments/commentRss/137454.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lambdacpp/services/trackbacks/137454.html</trackback:ping><description><![CDATA[<h1>启动slapd<br></h1>
<div>不论是包安装还是编译安装的OpenLDAP服务,启动LDAP服务通常使用类似这样的方式运行:</div>
<div>
<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-SIZE: 13px; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">usr</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">sbin</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">slapd&nbsp;</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">h&nbsp;ldap</span><span style="COLOR: #000000">:///</span><span style="COLOR: #000000">&nbsp;ldapi</span><span style="COLOR: #000000">:///</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">g&nbsp;openldap&nbsp;</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">u&nbsp;openldap&nbsp;</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">F&nbsp;</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">etc</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">ldap</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">slapd</span><span style="COLOR: #000000">.</span><span style="COLOR: #000000">d</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000"><br></span></div>
</div>
<h4><br><br>&nbsp;如果没有任何的配置是否可以启动slapd呢？</h4>
<div>
<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-SIZE: 13px; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><span style="COLOR: #800080">$mkdir</span><span style="COLOR: #000000">&nbsp;ldap_slapd</span><span style="COLOR: #000000">.</span><span style="COLOR: #000000">d<br>$</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">usr</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">sbin</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">slapd&nbsp;</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">d&nbsp;</span><span style="COLOR: #800000">65535</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">h&nbsp;ldap</span><span style="COLOR: #000000">://</span><span style="COLOR: #000000">localhost</span><span style="COLOR: #000000">:</span><span style="COLOR: #800000">3890</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">F&nbsp;ldap_slapd</span><span style="COLOR: #000000">.</span><span style="COLOR: #000000">d<br></span></div>
<br>系统提示没有配置目录中没有 cn=config.ldif 文件</div>
<div><br></div>
<h4>&nbsp;最简单的配置<br></h4>
<div>现在在配置目录中写一个最简单的配置:</div>
<div>
<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-SIZE: 13px; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><span style="COLOR: #800080">$cat</span><span style="COLOR: #000000">&nbsp;ldap_slapd</span><span style="COLOR: #000000">.</span><span style="COLOR: #000000">d</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">cn</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">config</span><span style="COLOR: #000000">.</span><span style="COLOR: #000000">ldif<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">dn</span><span style="COLOR: #000000">:</span><span style="COLOR: #000000">&nbsp;cn</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">config<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">objectClass</span><span style="COLOR: #000000">:</span><span style="COLOR: #000000">&nbsp;olcGlobal<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">cn</span><span style="COLOR: #000000">:</span><span style="COLOR: #000000">&nbsp;config<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">$</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">usr</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">sbin</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">slapd&nbsp;</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">d&nbsp;</span><span style="COLOR: #800000">65535</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">h&nbsp;ldap</span><span style="COLOR: #000000">://</span><span style="COLOR: #000000">localhost</span><span style="COLOR: #000000">:</span><span style="COLOR: #800000">3890</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">F&nbsp;ldap_slapd</span><span style="COLOR: #000000">.</span><span style="COLOR: #000000">d<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span></div>
<br></div>
<div>&nbsp;成功启动！在ldap_slapd.d下生成了cn=config 目录并且将基本的schema自动的导入了，从运行日志中也可以看到这些。</div>
<div>&nbsp;&nbsp;通过这个例子可以看到slapd运行的过程，但这样一个没有实际Backend数据库的slapd实例是没有实际意义的。</div>
<h1>&nbsp;配置</h1>
<div>slapd的配置就是运行的关键，在新版OpenLDAP中，LDAP配置不再是slapd.conf，而是一系列的配置文件，放置在一个配置目录下。LDAP将这个目录看成一种Backend，也就是config backend。配置目录中是若干的ldif文件，然后通过子目录的方式表现树形结构，以文件名表示配置节点的名称。</div>
<h4>&nbsp;slapd.d 目录</h4>
<div>LDAP的配置Backend包含3个内容：Schema、Backend、Database，都以ldif方式直接写在配置文件中。backend和database配置相对较小可直接编辑，而schema比较复杂，如有外部定义的schema更是麻烦，如果直接编辑很麻烦也容易出错。好在可以使用slaptest将旧式的.conf文件生成新配置。<br></div>
<div>实际上，slaptest的功能还不止这个，它还负责创建基本的数据库文件。最新版的OpenLDAP在安装后还是使用slapd.conf作为配置文件，然后在运行前创建配置Backend。</div>
<h4>&nbsp;slapd.conf&nbsp;<br></h4>
<div>slapd.conf由2个部分，先include schema文件，然后配置database。要注意后面database内容的语法是依赖core.schema的，所以没有 include core.schema，后面的内容是不符合语法的。</div>
<div>
<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-SIZE: 13px; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><span style="COLOR: #000000">include&nbsp;/etc/ldap/schema/core.schema<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">include&nbsp;/etc/ldap/schema/cosine.schema<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">include&nbsp;/etc/ldap/schema/nis.schema<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">include&nbsp;/etc/ldap/schema/inetorgperson.schema<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">include&nbsp;/user/defined/special.schema<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">database&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bdb<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">suffix&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">dc=example,dc=com</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">rootdn&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">cn=admin,dc=example,dc=com</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"><br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">rootpw&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;secret<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">directory&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/ldap/data/dir<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif">index&nbsp;&nbsp;&nbsp;objectClass&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;eq<br><img align=top src="http://www.cppblog.com/Images/OutliningIndicators/None.gif"></span></div>
<br></div>
<h4>&nbsp;slaptest</h4>
<div>运行:</div>
<div>
<div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-SIZE: 13px; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><span style="COLOR: #800080">$sudo</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">usr</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">bin</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">slaptest&nbsp;</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">f&nbsp;schema</span><span style="COLOR: #000000">.</span><span style="COLOR: #000000">conf&nbsp;</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">F&nbsp;</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">etc</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">ldap</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">slapd</span><span style="COLOR: #000000">.</span><span style="COLOR: #000000">d<br></span></div>
<br></div>
<div>slaptest要完成2个工作：将按schema生成schema.ldif配置，然后在指定的目录下初始化bdb文件。<br></div>
<img src ="http://www.cppblog.com/lambdacpp/aggbug/137454.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lambdacpp/" target="_blank">五点半</a> 2010-12-25 17:07 <a href="http://www.cppblog.com/lambdacpp/archive/2010/12/25/137454.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>cron配置</title><link>http://www.cppblog.com/lambdacpp/archive/2010/02/20/108097.html</link><dc:creator>五点半</dc:creator><author>五点半</author><pubDate>Sat, 20 Feb 2010 07:30:00 GMT</pubDate><guid>http://www.cppblog.com/lambdacpp/archive/2010/02/20/108097.html</guid><wfw:comment>http://www.cppblog.com/lambdacpp/comments/108097.html</wfw:comment><comments>http://www.cppblog.com/lambdacpp/archive/2010/02/20/108097.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lambdacpp/comments/commentRss/108097.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lambdacpp/services/trackbacks/108097.html</trackback:ping><description><![CDATA[
<div>那天用Cron配置了一个MySQL数据库自动备份。几天下来才发现没有运行。瞎搞了半天，没有结果。最后在需要执行的命令下加个&nbsp;&gt; /tmp/b.log 2&gt;&amp;1。一看错误日志。哦，原来找cron不知道mysqldump在哪儿。恍然大悟。</div><div>cron在运行的时候可能PATH变量没有那么多，所以好多命令需要在脚本中加入完整的路径。其实我已经是第2次遇到这个问题了！真是不长记性啊，所以一定要记下！！</div><div>还有怎么没有一开始就把日志输出。UNIX管理员不看日志，看什么呢？这两天过年肥肉吃多了说。日志！切记啊！</div>
<img src ="http://www.cppblog.com/lambdacpp/aggbug/108097.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lambdacpp/" target="_blank">五点半</a> 2010-02-20 15:30 <a href="http://www.cppblog.com/lambdacpp/archive/2010/02/20/108097.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>OpenSSH下SFTP的配置</title><link>http://www.cppblog.com/lambdacpp/archive/2009/12/02/102409.html</link><dc:creator>五点半</dc:creator><author>五点半</author><pubDate>Wed, 02 Dec 2009 13:04:00 GMT</pubDate><guid>http://www.cppblog.com/lambdacpp/archive/2009/12/02/102409.html</guid><wfw:comment>http://www.cppblog.com/lambdacpp/comments/102409.html</wfw:comment><comments>http://www.cppblog.com/lambdacpp/archive/2009/12/02/102409.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.cppblog.com/lambdacpp/comments/commentRss/102409.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lambdacpp/services/trackbacks/102409.html</trackback:ping><description><![CDATA[<div style="text-align: right; font-style: italic;">OpenSSH网站上那只SSH刺河豚将FTP埋葬<br></div>
<br>有关sftp有人推荐www.ssh.com的实现，不过我更喜欢开源的产品，特别是Open系列的安全产品。<br><br>
<h1>需求</h1>
首先我们明确我们的目标，我们是希望通过SFTP代替FTP，需求是这样的:<br>
<ol>
    <li>这些用户<span style="font-weight: bold;">只能通过SFT</span>访问服务器</li>
    <li>用户要<span style="font-weight: bold;">锁定</span>在相应的目录下</li>
</ol>
我想通常的思路是这样的:<br>
<ol>
    <li>打开OpenSSH的SFTP</li>
    <li>将这些用户设置在一个<span style="font-style: italic;">组</span>中</li>
    <li>让OpenSSH识别这个组，只允许这些用户使用SFTP</li>
    <li>最后系统要自动的将用户<span style="font-style: italic;">chroot</span>在用户目录下</li>
</ol>
<h1>配置</h1>
我开始都觉得是不是要求太高，不过OpenSSH可以解决以上所有问题。话说回来，如果不能解决怎么可以把FTP埋葬呢。<br>
<h4>SSHD_CONFIG</h4>
sshd通常是打开了sftp的，不过我们应该使用<span style="font-weight: bold;">internal-sftp</span>在sshd_conf中作如下配置:<br>
<div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: #008080;">&nbsp;1</span>&nbsp;<span style="color: #000000;">#&nbsp;Subsystem&nbsp;sftp&nbsp;/usr/lib/openssh/sftp-server&nbsp;#&nbsp;注释掉<br></span><span style="color: #008080;">&nbsp;2</span>&nbsp;<span style="color: #000000;">Subsystem&nbsp;sftp&nbsp;internal-sftp<br></span><span style="color: #008080;">&nbsp;3</span>&nbsp;<span style="color: #000000;"><br></span><span style="color: #008080;">&nbsp;4</span>&nbsp;<span style="color: #000000;">##<br></span><span style="color: #008080;">&nbsp;5</span>&nbsp;<span style="color: #000000;">Match&nbsp;group&nbsp;sftponly<br></span><span style="color: #008080;">&nbsp;6</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;ChrootDirectory&nbsp;/sftphome/%u<br></span><span style="color: #008080;">&nbsp;7</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;X11Forwarding&nbsp;no<br></span><span style="color: #008080;">&nbsp;8</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;AllowTcpForwarding&nbsp;no<br></span><span style="color: #008080;">&nbsp;9</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;ForceCommand&nbsp;internal-sftp<br></span><span style="color: #008080;">10</span>&nbsp;<span style="color: #000000;"></span></div>
解释一下：当sshd匹配到sftponly组中的用户，就会强制使用sftp(ForceCommand的作用)，并将用户限定在/sftphome/下相应用户的目录下(ChrootDirectory的作用)。<br>
<h3>创建用户</h3>
我们需要创建相应的用户了：<br><br>
<div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: #000000;">#useradd&nbsp;-G&nbsp;sftponly&nbsp;-d&nbsp;/sftphome/sftpuser&nbsp;&nbsp;-s&nbsp;/usr/sbin/nologin&nbsp;sftpuser<br>#tail&nbsp;/etc/password<br><img src="http://www.cppblog.com/Images/dot.gif"><br>sftpuser:x:</span><span style="color: #000000;">1000</span><span style="color: #000000;">:</span><span style="color: #000000;">1000</span><span style="color: #000000;">::/sftphome/sftpuser:/usr/sbin/nologin<br>#passwd sftpuser<br></span></div>
你可以在其他机器上用sftp登录试试了。你的连接将会被reset!去看看sshd的日志，你会发现pam.d的认证是通过了的，但是chroot失败了。按网络上的说法<br>
<div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: #000000;">#chown&nbsp;root&nbsp;/sftphome/sftpuser<br>#chmod&nbsp;</span><span style="color: #000000;">755</span><span style="color: #000000;">&nbsp;/sftphome/sftpuser<br></span></div>
再试，可以登录。新的问题是不能在此目录下写入。对的嘛，755对于组用户是不能写啊。再试试775，刚才的问题就来又了，chroot失败。<br><br><span style="font-weight: bold;">以上内容网络上一google一大把。</span><br><br>可以登录不能写这个问题真让人困惑!后来我想可能应该这样理解：既然要chroot，那个目录不属于root肯定是不行的(说错了，猛拍砖)。那我们就不能为用户提供完整的sftp服务了吗？我想可以这样<br>
<div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: #000000;">#mkdir&nbsp;/sftphome/sftpuser/space<br>#chown&nbsp;sftpuser.sftpuser&nbsp;/sftphome/sftpuser/space<br></span></div>
由系统管理员为sftp用户提供一个目录，并设置其用户属性，用户在这个目录下用户是可写的。当然可以创建很多个。<br><br>这样算不算解决这个问题呢？暂且如此吧。如果您有好方法，一定告知哦。<br><br><br> <img src ="http://www.cppblog.com/lambdacpp/aggbug/102409.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lambdacpp/" target="_blank">五点半</a> 2009-12-02 21:04 <a href="http://www.cppblog.com/lambdacpp/archive/2009/12/02/102409.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>应用中的MySQL服务器部署Replication</title><link>http://www.cppblog.com/lambdacpp/archive/2009/08/14/93378.html</link><dc:creator>五点半</dc:creator><author>五点半</author><pubDate>Fri, 14 Aug 2009 14:39:00 GMT</pubDate><guid>http://www.cppblog.com/lambdacpp/archive/2009/08/14/93378.html</guid><wfw:comment>http://www.cppblog.com/lambdacpp/comments/93378.html</wfw:comment><comments>http://www.cppblog.com/lambdacpp/archive/2009/08/14/93378.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lambdacpp/comments/commentRss/93378.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lambdacpp/services/trackbacks/93378.html</trackback:ping><description><![CDATA[<p>本文记录如何给一台应用中的MySQL服务器部署Replication。</p>
<h4 id="安装环境">安装环境</h4>
<h5 id="现有MySQL">现有MySQL</h5>
现有MySQL服务器的特点：
<ol>
    <li>没有专门为Replication环境配置</li>
    <li>MySQL为编译安装</li>
    <li>MySQL处于运行状态，不可长时间停机</li>
</ol>
<h5 id="目的">目的</h5>
<p>将现有服务器作为Master服务器，配置并运行一台新的MySQL服务器作为Slave服务器</p>
<h5 id="准备">准备</h5>
<ol>
    <li>服务器硬件</li>
    <li>现有主服务器的安装代码包(mysql-5.x.xxx.tar.gz)</li>
</ol>
<h4 id="主服务器的配置和数据准备">主服务器的配置和数据准备</h4>
<h5 id="Master服务器的必须配置">Master服务器的必须配置</h5>
要使用Replication必须将Master的binlog打开，并设置服务器ID。最简单的配置如下:<br>
<pre>log-bin     =  mysql-bin<br>server-id   =  1</pre>
当然关于MySQL Bin Log的配置还有很多设置，可以参考相关手册
<h5 id="数据备份">数据备份</h5>
现在需要将Master的数据备份出来要注意的是要记住 <strong>备份点的binlog日志和postion</strong> 。Master数据备份的方式可以是停机冷备份，如果安装了LVM可以使用LVM的Snapshot。下面使用mysqldump 导出数据。在导出数据之前我们应该Flush表，并锁住表，比允许数据写入。<br>
<pre>mysql&gt; FLUASH TABLES WITH READ LOCK;<br>mysql&gt; SHOW MASTER STATUS;<br>+------------------+----------+--------------+------------------+<br>| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |<br>+------------------+----------+--------------+------------------+<br>| mysql-bin.000157 | 18757860 |              |                  |<br>+------------------+----------+--------------+------------------+<br>1 row in set (0.00 sec)</pre>
使用mysqldump导出数据<br>
<pre>mysql:~# mysqldump -uroot -p --all-databases &gt; dump.sql</pre>
解锁<br>
<pre>mysql&gt; UNLOCK TABLES;</pre>
<h5 id="安装参数的提取">安装参数的提取</h5>
需要在Slave主机编译安装MySQL要了解Master安装时的编译参数，可以通过如下方式获得:<br>
<pre>mysql:~# cat /usr/local/mysql/bin/mysqlbug | grep CONFIGURE</pre>
<h5 id="repl用户创建">repl用户创建</h5>
在Master服务器中创建repl用户，用于在Slave 数据库中访问Master数据<br>
<pre>mysql&gt; GREANT REPLICATION SLAVE ON *.* to 'repl'@'IP.SLAVE.SERVER' identified by 'repl_passwd';</pre>
<h4 id="Slave服务器的安装">Slave服务器的安装</h4>
<h5 id="MySQL的安装">MySQL的安装</h5>
<ul>
    <li>按前面提取的configure参数对源代码进行编译(<code>./configure; make; make install;</code>)</li>
    <li>安装初始化数据库:</li>
</ul>
<pre>#mysql_install_db --datadir=/data --user=mysql</pre>
<ul>
    <li>参照@{mysql-src}/support-files/<code>目录中my.cnf文件在</code>/etc/<code>下创建@my.cnf</code></li>
    <li>参照@{mysql-src}/support-files/mysql.server@文件在@/etc/init.d/<code>下配置@mysqldb</code></li>
    <li>可尝试启动mysql。 <code>/etc/init.d/mysqldb start</code></li>
</ul>
<h5 id="数据的导入">数据的导入</h5>
<pre>mysql# mysql -uroot -p &lt; dump.sql</pre>
<p>如果导入出现超出最大数据包错误可以尝试修改my.cnf中的max_allow_packet</p>
<h5 id="在mycnf中配置slave">在my.cnf中配置slave</h5>
在my.cnf中配置：<br>
<pre>server-id       =  2<br>master-host     =  master_ip<br>master-user     =  repl<br>master-password =  repl_passwd</pre>
<h5 id="在Slave服务器上启动Slave">在Slave服务器上启动Slave</h5>
<pre>mysql&gt; STOP SLAVE;<br>mysql&gt; CHANGE MASTER TO     <br>       MASTER_HOST='masterip',<br>      &nbsp;MASTER_USER='repl',<br>      &nbsp;MASTER_PASSWORD='repl_passwd',<br>      &nbsp;MASTER_LOG_FILE='mysql-bin.000157',<br>       MASTER_LOG_POS=18757860 ;<br>mysql&gt; START SLAVE;<br><br></pre><img src ="http://www.cppblog.com/lambdacpp/aggbug/93378.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lambdacpp/" target="_blank">五点半</a> 2009-08-14 22:39 <a href="http://www.cppblog.com/lambdacpp/archive/2009/08/14/93378.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Hatta Wiki试用</title><link>http://www.cppblog.com/lambdacpp/archive/2009/03/20/77329.html</link><dc:creator>五点半</dc:creator><author>五点半</author><pubDate>Fri, 20 Mar 2009 08:55:00 GMT</pubDate><guid>http://www.cppblog.com/lambdacpp/archive/2009/03/20/77329.html</guid><wfw:comment>http://www.cppblog.com/lambdacpp/comments/77329.html</wfw:comment><comments>http://www.cppblog.com/lambdacpp/archive/2009/03/20/77329.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lambdacpp/comments/commentRss/77329.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lambdacpp/services/trackbacks/77329.html</trackback:ping><description><![CDATA[<a title="冯大辉"  href="http://www.dbanotes.net/">大辉</a>推荐了一个网站www.wikimatrix.org。去看了看虽然一直用Wiki进行一些文档的协作，但那么多Wiki还是第一次哈。于是想找一个用Python开发的wiki(wikimatrix上面有一个Wizard可以帮助您找到想要的)。除了老牌的plone,著名的MoinMoin,还发现了一个叫<a title="hatta"  href="http://hatta.sheep.art.pl/">hatta</a><a></a>的。安装了一下，真还不错。<br>hatta的实现就一个python文件，功能简单，没有权限管理，没有用户管理，作者认为Wiki就是要欢迎天南地北的兄弟都可以修改。hatta的使用简单，按照语法编辑，然后提交了事。中文化也非常简单，Wiki内容本身就可以输入中文，如果觉得页面也应该是中文的也很简单，改改po文件即可。我觉得如果您对Wiki的需求如下就可以考虑使用：<br>
<ol>
    <li>内部使用。如果部署在外网，好事者乱改一气还是比较麻烦的，特别是放一些不该放的。</li>
    <li>需要版本控制的文档协作</li>
    <li>要在文档中嵌入程序代码，代码需要高亮</li>
    <li>需要在文档中嵌入数学公式。hatta使用latex语法输入公式，生成的公式非常漂亮</li>
</ol>
<br><br><br><br><img src ="http://www.cppblog.com/lambdacpp/aggbug/77329.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lambdacpp/" target="_blank">五点半</a> 2009-03-20 16:55 <a href="http://www.cppblog.com/lambdacpp/archive/2009/03/20/77329.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Debian rootkit检查</title><link>http://www.cppblog.com/lambdacpp/archive/2008/11/20/67406.html</link><dc:creator>五点半</dc:creator><author>五点半</author><pubDate>Thu, 20 Nov 2008 12:25:00 GMT</pubDate><guid>http://www.cppblog.com/lambdacpp/archive/2008/11/20/67406.html</guid><wfw:comment>http://www.cppblog.com/lambdacpp/comments/67406.html</wfw:comment><comments>http://www.cppblog.com/lambdacpp/archive/2008/11/20/67406.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lambdacpp/comments/commentRss/67406.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lambdacpp/services/trackbacks/67406.html</trackback:ping><description><![CDATA[今天维护服务器。一查看/var/log/auth.log，哦！天南地北的朋友都想登录到我们的破服务器。虽然都未成功，但动物凶猛啊。现实残酷，黑客无情，安全第一。还是安装个rootkit检查工具为妙：<br>#aptitude install chkrootkit rkhunter<br>#chkrootkit<br>.....<br>#rkhunter -c -sk<br>.....<br>还好。<br> <img src ="http://www.cppblog.com/lambdacpp/aggbug/67406.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lambdacpp/" target="_blank">五点半</a> 2008-11-20 20:25 <a href="http://www.cppblog.com/lambdacpp/archive/2008/11/20/67406.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Jazz 试用</title><link>http://www.cppblog.com/lambdacpp/archive/2008/05/28/51370.html</link><dc:creator>五点半</dc:creator><author>五点半</author><pubDate>Wed, 28 May 2008 03:37:00 GMT</pubDate><guid>http://www.cppblog.com/lambdacpp/archive/2008/05/28/51370.html</guid><wfw:comment>http://www.cppblog.com/lambdacpp/comments/51370.html</wfw:comment><comments>http://www.cppblog.com/lambdacpp/archive/2008/05/28/51370.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lambdacpp/comments/commentRss/51370.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lambdacpp/services/trackbacks/51370.html</trackback:ping><description><![CDATA[最近一直在试用Jazz。IBM宣传Jazz是下一代的软件交付平台，IBM开发者网站上一大堆的文档，看来IBM对这个软件还是非常重视的。试用体会：<br>
<ol>
    <li>IBM或者说Rational对软件工程的研究是非常深入的，IBM Rational系列软件可以充分体现IBM对软件过程的理解。Jazz中集成了各种软件开发过程(时下流行的Srcum也在其中)。Jazz充分认识到了敏捷的重要性，所以敏捷的思想贯穿整个软件。</li>
    <li>虽然IBM提供的比较丰富的文档，学习曲线还是有些陡峭。特别对于没有使用过Rational软件的开发人员。推荐初学者先看看<a href="http://www.ibm.com/developerworks/cn/edu/r-dw-r-jazz-cn-rtceintro.html">这个文档</a> <br></li>
    <li>Jazz的版本控制源于CC不是很喜欢，如果可以用SVN代替就好了。</li>
    <li>Jazz的客户端是开源的，但服务端只有90天试用。具体的价格也要6月份才出来。<br></li>
</ol>
<br> <img src ="http://www.cppblog.com/lambdacpp/aggbug/51370.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lambdacpp/" target="_blank">五点半</a> 2008-05-28 11:37 <a href="http://www.cppblog.com/lambdacpp/archive/2008/05/28/51370.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>在tex缺省安装上添加新的.cls .sty文件</title><link>http://www.cppblog.com/lambdacpp/archive/2008/05/19/50403.html</link><dc:creator>五点半</dc:creator><author>五点半</author><pubDate>Mon, 19 May 2008 09:03:00 GMT</pubDate><guid>http://www.cppblog.com/lambdacpp/archive/2008/05/19/50403.html</guid><wfw:comment>http://www.cppblog.com/lambdacpp/comments/50403.html</wfw:comment><comments>http://www.cppblog.com/lambdacpp/archive/2008/05/19/50403.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lambdacpp/comments/commentRss/50403.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lambdacpp/services/trackbacks/50403.html</trackback:ping><description><![CDATA[还是记录在这吧。<br>现在在Debian下安装tex很方便了。如果一些宏包没有下载下来可以安装在系统上。步骤：<br>
<ol>
    <li>在/usr/share/texmf/tex/latex下建一个目录mkdir xxpackage</li>
    <li>把宏包解压在这里</li>
    <li>texhash<br></li>
</ol>
<br><img src ="http://www.cppblog.com/lambdacpp/aggbug/50403.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lambdacpp/" target="_blank">五点半</a> 2008-05-19 17:03 <a href="http://www.cppblog.com/lambdacpp/archive/2008/05/19/50403.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Quixote笔记</title><link>http://www.cppblog.com/lambdacpp/archive/2008/04/19/47594.html</link><dc:creator>五点半</dc:creator><author>五点半</author><pubDate>Sat, 19 Apr 2008 07:11:00 GMT</pubDate><guid>http://www.cppblog.com/lambdacpp/archive/2008/04/19/47594.html</guid><wfw:comment>http://www.cppblog.com/lambdacpp/comments/47594.html</wfw:comment><comments>http://www.cppblog.com/lambdacpp/archive/2008/04/19/47594.html#Feedback</comments><slash:comments>15</slash:comments><wfw:commentRss>http://www.cppblog.com/lambdacpp/comments/commentRss/47594.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lambdacpp/services/trackbacks/47594.html</trackback:ping><description><![CDATA[<div style="text-align: right;"><span style="font-style: italic;">又是Python。呵呵。谁叫人家帅呢</span><br></div>
<h2>Quixote的部署</h2>
&nbsp;&nbsp;&nbsp; 在Quixote官方白皮书中已经详细描述了Quixote的工作模式。Quixote可以使用Python自代的http_server(主要用于开发调试)和与Apache(或lighttpd)配合使用。<br>&nbsp;&nbsp;&nbsp; Quixote与Apache配合使用方式如下：<br>
<ol>
    <li>使用CGI，文档中称为egular CGI。被认为效率最低的一种方式，因为每一个请求都会创建一个新的进程。</li>
    <li>使用fastCGI，CGI可以运行fastCGI一定是可以应用的。这也是豆瓣采用的方式。在Quixote作者的一个PPT中，他认为fastCGI是buggy的。哦:(也不至于啊。我们正在寻找使用fastCGI的部署经验。</li>
    <li>使用mod_python，将python代码嵌入到Apache中。</li>
    <li>使用SCGI，这是作者推荐的。使用Apache SCGI module scgi_mod将遵循SCGI协议Apache将请求发送到相应的Socket如localhost:3001。而这个Socket由本地运行的一个 Python程序打开。这个Python程序将处理请求，并返回结果。 </li>
</ol>
<h2>SCGI的配置</h2>
&nbsp;&nbsp;&nbsp; Quixote的网站上对SCGI的描述：SCGI协议是CGI协议的替代。它是一种应用程序与HTTP服务接口标准。它有些像FastCGI但他的设计更容易实现。<br><br>&nbsp;&nbsp;&nbsp; 配置SCGI过程如下：<br>
<ul>
    <li>安装各个模块不在话下，debian让程序员有了懒惰的美德：</li>
</ul>
<div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #aptitude&nbsp;install&nbsp;libapache2-mod-scgi&nbsp;python-scgi&nbsp;python-quixote<br><br></span></div>
<ul>
    <li>Apache的配置，添加配置到apache.conf。（有些教程中加入了SetHandler scgi-handler ，但这个加上就很本不会和3000通信。可能是版本的问题。最好不用。） </li>
</ul>
<div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: #0000ff;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;</span><span style="color: #800000;">Location&nbsp;</span><span style="color: #ff0000;">"/qx"</span><span style="color: #0000ff;">&gt;</span><span style="color: #000000;"><br>&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; SCGIServer&nbsp;localost:3000<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp; SCGIHandler&nbsp;On<br></span><span style="color: #0000ff;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/</span><span style="color: #800000;">Location</span><span style="color: #0000ff;">&gt;</span><span style="color: #000000;">&nbsp;<br><br></span></div>
<ul>
    <li>重启Apache </li>
</ul>
&nbsp;&nbsp;&nbsp; 配置完成。SCGI的好处在于，修改了Python程序，不用重启Apache，只要重启SCGI就可以了。<br><br>
<h2>第一个Quixote程序</h2>
&nbsp;&nbsp;&nbsp; 一切就绪，我们来一次Quixote的完整之旅。<br><br>
<ul>
    <li>scgi程序要求有一个服务打开3000端口。启动scgi的程序如下: </li>
</ul>
<div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: #008080;">&nbsp;1</span>&nbsp;<span style="color: #000000;"><br></span><span style="color: #008080;">&nbsp;2</span>&nbsp;<span style="color: #000000;"></span><span style="color: #008000;">#</span><span style="color: #008000;">!/usr/bin/python</span><span style="color: #008000;"><br></span><span style="color: #008080;">&nbsp;3</span>&nbsp;<span style="color: #008000;">#</span><span style="color: #008000;">&nbsp;-*-&nbsp;coding:&nbsp;utf-8&nbsp;-*-</span><span style="color: #008000;"><br></span><span style="color: #008080;">&nbsp;4</span>&nbsp;<span style="color: #008000;"></span><span style="color: #000000;"><br></span><span style="color: #008080;">&nbsp;5</span>&nbsp;<span style="color: #000000;"></span><span style="color: #0000ff;">from</span><span style="color: #000000;">&nbsp;scgi.quixote_handler&nbsp;</span><span style="color: #0000ff;">import</span><span style="color: #000000;">&nbsp;QuixoteHandler,&nbsp;main<br></span><span style="color: #008080;">&nbsp;6</span>&nbsp;<span style="color: #000000;"></span><span style="color: #0000ff;">from</span><span style="color: #000000;">&nbsp;quixote&nbsp;</span><span style="color: #0000ff;">import</span><span style="color: #000000;">&nbsp;enable_ptl<br></span><span style="color: #008080;">&nbsp;7</span>&nbsp;<span style="color: #000000;"></span><span style="color: #0000ff;">from</span><span style="color: #000000;">&nbsp;quixote.publish&nbsp;</span><span style="color: #0000ff;">import</span><span style="color: #000000;">&nbsp;Publisher<br></span><span style="color: #008080;">&nbsp;8</span>&nbsp;<span style="color: #000000;">enable_ptl()&nbsp;</span><span style="color: #008000;">#</span><span style="color: #008000;">启动PTL</span><span style="color: #008000;"><br></span><span style="color: #008080;">&nbsp;9</span>&nbsp;<span style="color: #008000;"></span><span style="color: #000000;"><br></span><span style="color: #008080;">10</span>&nbsp;<span style="color: #000000;"></span><span style="color: #0000ff;">def</span><span style="color: #000000;">&nbsp;create_publisher():<br></span><span style="color: #008080;">11</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">from</span><span style="color: #000000;">&nbsp;ourroot&nbsp;</span><span style="color: #0000ff;">import</span><span style="color: #000000;">&nbsp;RootDirectory<br></span><span style="color: #008080;">12</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">return</span><span style="color: #000000;">&nbsp;Publisher(RootDirectory(),&nbsp;display_exceptions</span><span style="color: #000000;">=</span><span style="color: #800000;">'</span><span style="color: #800000;">plain</span><span style="color: #800000;">'</span><span style="color: #000000;">)<br></span><span style="color: #008080;">13</span>&nbsp;<span style="color: #000000;"><br></span><span style="color: #008080;">14</span>&nbsp;<span style="color: #000000;"></span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;</span><span style="color: #800080;">__name__</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">==</span><span style="color: #000000;">&nbsp;</span><span style="color: #800000;">'</span><span style="color: #800000;">__main__</span><span style="color: #800000;">'</span><span style="color: #000000;">:<br></span><span style="color: #008080;">15</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">from</span><span style="color: #000000;">&nbsp;quixote.server&nbsp;</span><span style="color: #0000ff;">import</span><span style="color: #000000;">&nbsp;scgi_server<br></span><span style="color: #008080;">16</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;scgi_server.run(create_publisher,&nbsp;port</span><span style="color: #000000;">=</span><span style="color: #000000;">3000</span><span style="color: #000000;">,&nbsp;script_name</span><span style="color: #000000;">=</span><span style="color: #800000;">"</span><span style="color: #800000;">/qx</span><span style="color: #800000;">"</span><span style="color: #000000;">)<br></span><span style="color: #008080;">17</span>&nbsp;<span style="color: #000000;"></span></div>
<br>
<ul>
    <li>程序结构是比较简单的，使用的是scgi_server的run方法。要注意的是run方法中的script_name和前面apache 的配置Location是一样的。程序的关键是导入了ourroot这样一个ptl 。下面是我们的第一个ptl程序。</li>
</ul>
<div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: #008080;">&nbsp;1</span>&nbsp;<span style="color: #000000;"><br></span><span style="color: #008080;">&nbsp;2</span>&nbsp;<span style="color: #000000;"></span><span style="color: #008000;">#</span><span style="color: #008000;">&nbsp;-*-&nbsp;coding:&nbsp;utf-8&nbsp;-*-</span><span style="color: #008000;"><br></span><span style="color: #008080;">&nbsp;3</span>&nbsp;<span style="color: #008000;"></span><span style="color: #800000;">"""</span><span style="color: #800000;">这个是我们第一个例子的根目录<br></span><span style="color: #008080;">&nbsp;4</span>&nbsp;<span style="color: #800000;"></span><span style="color: #800000;">"""</span><span style="color: #000000;"><br></span><span style="color: #008080;">&nbsp;5</span>&nbsp;<span style="color: #000000;"></span><span style="color: #0000ff;">from</span><span style="color: #000000;">&nbsp;quixote.directory&nbsp;</span><span style="color: #0000ff;">import</span><span style="color: #000000;">&nbsp;Directory<br></span><span style="color: #008080;">&nbsp;6</span>&nbsp;<span style="color: #000000;"><br></span><span style="color: #008080;">&nbsp;7</span>&nbsp;<span style="color: #000000;"></span><span style="color: #0000ff;">class</span><span style="color: #000000;">&nbsp;RootDirectory(Directory):<br></span><span style="color: #008080;">&nbsp;8</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;_q_exports&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;[</span><span style="color: #800000;">""</span><span style="color: #000000;">]<br></span><span style="color: #008080;">&nbsp;9</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">def</span><span style="color: #000000;">&nbsp;_q_index&nbsp;[html]&nbsp;(self):<br></span><span style="color: #008080;">10</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff;">print</span><span style="color: #000000;">&nbsp;</span><span style="color: #800000;">"</span><span style="color: #800000;">debug&nbsp;message&nbsp;from&nbsp;the&nbsp;index&nbsp;page</span><span style="color: #800000;">"</span><span style="color: #000000;"><br></span><span style="color: #008080;">11</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #800000;">"""</span><span style="color: #800000;"><br></span><span style="color: #008080;">12</span>&nbsp;<span style="color: #800000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;html&gt;<br></span><span style="color: #008080;">13</span>&nbsp;<span style="color: #800000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;head&gt;<br></span><span style="color: #008080;">14</span>&nbsp;<span style="color: #800000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;meta&nbsp;http-equiv="Content-Type"&nbsp;content="text/html&nbsp;charset=UTF-8"&nbsp;/&gt;<br></span><span style="color: #008080;">15</span>&nbsp;<span style="color: #800000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;title&gt;第一个例子&lt;/title&gt;<br></span><span style="color: #008080;">16</span>&nbsp;<span style="color: #800000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/head&gt;<br></span><span style="color: #008080;">17</span>&nbsp;<span style="color: #800000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;body&gt;<br></span><span style="color: #008080;">18</span>&nbsp;<span style="color: #800000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;h1&gt;第一个例子有中文!&lt;/h1&gt;<br></span><span style="color: #008080;">19</span>&nbsp;<span style="color: #800000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/body&gt;<br></span><span style="color: #008080;">20</span>&nbsp;<span style="color: #800000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/html&gt;<br></span><span style="color: #008080;">21</span>&nbsp;<span style="color: #800000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #800000;">"""</span><span style="color: #000000;"><br></span><span style="color: #008080;">22</span>&nbsp;<span style="color: #000000;"></span></div>
<br>
<ul>
    <li>现在在浏览器中输入http://localhost/qx就可以看到结果了。</li>
    <li>除了运行上面的python脚本，也可以采用这样的方式运行scgi:</li>
    <div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: #000000;">python&nbsp;/var/lib/python-support/python2</span><span style="color: #000000;">.5</span><span style="color: #000000;">/quixote/server/scgi_server.py&nbsp;\<br>&nbsp;&nbsp;&nbsp;&nbsp;--factory</span><span style="color: #000000;">=</span><span style="color: #000000;">FirstApp.create_publisher&nbsp;\<br>&nbsp;&nbsp;&nbsp;&nbsp;--script-name</span><span style="color: #000000;">=</span><span style="color: #000000;">/qx&nbsp;&nbsp;--port</span><span style="color: #000000;">=</span><span style="color: #000000;">3000</span><span style="color: #000000;"><br></span></div>
    <br><br>
</ul>
<h2>Quixote 中文化的要点</h2>
&nbsp;&nbsp;&nbsp; Quixote的中文设置好像很麻烦。其实随着python、Quixote版本的推进，现在这个问题已经很简单了。字符集使用的是utf-8。使用gb2312可能也是可以的。<br><br>
<ol>
    <li>所有源代码使用utf-8在程序的开始加上# -*- coding: utf-8 -*-</li>
    <li>ptl的html模板加上content="text/html charset=UTF-8"</li>
    <li>关键:在quixote的安装路径下有__init__.py，将其中的DEFAULT_CHARSET = 'iso-8859-1'改成 'utf-8'</li>
    <li>也可以不修改__init__.py，使用Publisher的时候把Publisher扩展一下：</li>
</ol>
<div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: #008080;">1</span>&nbsp;<span style="color: #0000ff;">class</span><span style="color: #000000;">&nbsp;UTF8Publisher(Publisher):<br></span><span style="color: #008080;">2</span>&nbsp;<span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;quixote.DEFAULT_CHARSET&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;</span><span style="color: #800000;">"</span><span style="color: #800000;">utf-8</span><span style="color: #800000;">"</span><span style="color: #000000;"><br></span><span style="color: #008080;"></span><span style="color: #000000;"></span></div>
<br>   <img src ="http://www.cppblog.com/lambdacpp/aggbug/47594.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lambdacpp/" target="_blank">五点半</a> 2008-04-19 15:11 <a href="http://www.cppblog.com/lambdacpp/archive/2008/04/19/47594.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>久违了</title><link>http://www.cppblog.com/lambdacpp/archive/2008/04/18/47487.html</link><dc:creator>五点半</dc:creator><author>五点半</author><pubDate>Fri, 18 Apr 2008 03:33:00 GMT</pubDate><guid>http://www.cppblog.com/lambdacpp/archive/2008/04/18/47487.html</guid><wfw:comment>http://www.cppblog.com/lambdacpp/comments/47487.html</wfw:comment><comments>http://www.cppblog.com/lambdacpp/archive/2008/04/18/47487.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lambdacpp/comments/commentRss/47487.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lambdacpp/services/trackbacks/47487.html</trackback:ping><description><![CDATA[很久没有更新了。<br>敏捷时代似乎已经到了，将更多的时间花在了Python和Ruby上。C++好些地方使不上劲呢:(。<br>前段时间研究了一下boost.python，还真不错，就是文档太少啊。有时间将其整理一下。<br>pongba的这个<a href="http://groups.google.com/group/pongba">论坛</a>还真不错。天天在上面泡着。<br><br><br><img src ="http://www.cppblog.com/lambdacpp/aggbug/47487.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lambdacpp/" target="_blank">五点半</a> 2008-04-18 11:33 <a href="http://www.cppblog.com/lambdacpp/archive/2008/04/18/47487.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>