9.12. MoinMoin服务器 、Chapter 9. Debian服务器篇 2008-07-09 19:25

字号:    

debin Wiki网站使用的WiKi系统就是MoinMoin。Moin是德国北部方言"好"、"早上好"的意思,MoinMoin是"很好"的意思。

http://moinmoin.wikiwikiweb.de/HelpOnConfiguration/FileAttachments的内容。

  • 启动MoinMoin WiKi服务器

    debian:~/mywiki# ./mointwisted start

    在当前目录会生成一个叫twistd.log的日志文件。如果成功启动,日志文件的内容为:

    2005/12/13 11:48 CST [-] Log opened.2005/12/13 11:48 CST [-] twistd 2.0.1 (/usr/bin/python2.4 2.4.2) starting up2005/12/13 11:48 CST [-] reactor class: twisted.internet.selectreactor.SelectReactor2005/12/13 11:48 CST [-] Loading mointwisted.py...2005/12/13 11:48 CST [-] Enabling Multithreading.2005/12/13 11:48 CST [-] Loaded.2005/12/13 11:48 CST [-] MoinMoin.server.twistedmoin.MoinSite starting on 80802005/12/13 11:48 CST [-] Starting factory <MoinMoin.server.twistedmoin.MoinSite instance at 0xb76004cc>2005/12/13 11:48 CST [-] set uid/gid 33/33

    MoinMoin成功启动后,在浏览器上打开http://server_name:8080网址即可访问。停止服务器用stop参数即可。用不带参数的mointwisted命令可以查看命令参数,如:

    debian:~/mywiki# ./mointwisted error: nothing to domointwisted - MoinMoin daemonusage: mointwisted commandcommands: start start the server stop stop the server restart stop then start the server kill kill the server@copyright: 2004-2005 Thomas Waldmann, Nir Soffer@license: GNU GPL, see COPYING for details.

    • Apache2+Mod_Python方式,这里我选用了最新的1.5版的MoinMoin软件包。

      • 第一步要先安装Mod_Python模块,要求使用mod_python 3.1.3或以上版本的Mod_Python模块。安装命令如下:

        debian:~# apt-get install libapache2-mod-python2.3

        下载完软件包后Debian系统会自动进行软件包的配置,回答"Yes"启用Mod_Python模块。这样在/etc/apache2/mods-enabled目录下会创建一个链接到/etc/apache2/mods-available/mod_python.load文件。该文件配置了装载mod_python模块的语句,如:

        LoadModule python_module /usr/lib/apache2/modules/mod_python.so

      • 第二步是创建WiKi实例,步骤同上。

      • 第三步是配置wikiconfig.py,内容如下:

        # -*- coding: utf-8 -*- #使用UTF-8编码# IMPORTANT! This encoding (charset) setting MUST be correct! If you live in a# western country and you don't know that you use utf-8, you probably want to# use iso-8859-1 (or some other iso charset). If you use utf-8 (a Unicode# encoding) you MUST use: coding: utf-8# That setting must match the encoding your editor uses when you modify the# settings below. If it does not, special non-ASCII chars will be wrong.""" MoinMoin - Configuration for a single wiki If you run a single wiki only, you can omit the farmconfig.py config file and just use wikiconfig.py - it will be used for every request we get in that case. Note that there are more config options than you'll find in the version of this file that is installed by default; see the module MoinMoin.multiconfig for a full list of names and their default values. Also, the URL http://moinmoin.wikiwikiweb.de/HelpOnConfiguration has a list of config options. ** Please do not use this file for a wiki farm. Use the sample file from the wikifarm directory instead! ** @copyright: 2000-2005 by Juergen Hermann <jh@web.de> @license: GNU GPL, see COPYING for details."""from MoinMoin.multiconfig import DefaultConfigclass Config(DefaultConfig): # Wiki identity ---------------------------------------------------- # Site name, used by default for wiki name-logo [Unicode] sitename = u'Untitled Wiki' #你的WiKi网站的名称 # Wiki logo. You can use an image, text or both. [Unicode] # For no logo or text, use '' - the default is to show the sitename. # See also url_prefix setting below! logo_string = u'<img src="/wiki/common/moinmoin.png" alt="MoinMoin Logo">' #网站Logo # name of entry page / front page [Unicode], choose one of those: # a) if most wiki content is in a single language #page_front_page = u"MyStartingPage" # b) if wiki content is maintained in many languages page_front_page = u"FrontPage" #启用首页 # The interwiki name used in interwiki links #interwikiname = 'UntitledWiki' # Show the interwiki name (and link it to page_front_page) in the Theme, # nice for farm setups or when your logo does not show the wiki's name. #show_interwiki = 1 # Critical setup --------------------------------------------------- # Misconfiguration here will render your wiki unusable. Check that # all directories are accessible by the web server or moin server. # If you encounter problems, try to set data_dir and data_underlay_dir # to absolute paths. # Where your mutable wiki pages are. You want to make regular # backups of this directory. data_dir = '/root/mywiki/data/' #设置data目录路径,要用绝对路径 # Where read-only system and help page are. You might want to share # this directory between several wikis. When you update MoinMoin, # you can safely replace the underlay directory with a new one. This # directory is part of MoinMoin distribution, you don't have to # backup it. data_underlay_dir = '/root/mywiki/underlay/' #设置underlay目录路径,要用绝对路径 # This must be '/wiki' for twisted and standalone. For CGI, it should # match your Apache Alias setting. url_prefix = '/wiki' # Security ---------------------------------------------------------- # This is checked by some rather critical and potentially harmful actions, # like despam or PackageInstaller action: superuser = [u"moin_admin", ] #设置超级用户,1.5版新增选项 # IMPORTANT: grant yourself admin rights! replace YourName with # your user name. See HelpOnAccessControlLists for more help. # All acl_rights_xxx options must use unicode [Unicode] #acl_rights_before = u"YourName:read,write,delete,revert,admin" #设置管理权限 # Link spam protection for public wikis (Uncomment to enable) # Needs a reliable internet connection. #from MoinMoin.util.antispam import SecurityPolicy # Mail -------------------------------------------------------------- # Configure to enable subscribing to pages (disabled by default) # or sending forgotten passwords. # SMTP server, e.g. "mail.provider.com" (None to disable mail) mail_smarthost = "smtp.21cn.com" #使用21cn的smtp服务器发送邮件 # The return address, e.g u"Jürgen Wiki <noreply@mywiki.org>" [Unicode] mail_from = u"yjnet<yjnet@21cn.com>" #发送者 # "user pwd" if you need to use SMTP AUTH mail_login = "yjnet 123456" #SMTP服务器验证,以"user password"格式填写 # User interface ---------------------------------------------------- # Add your wikis important pages at the end. It is not recommended to # remove the default links. Leave room for user links - don't use # more than 6 short items. # You MUST use Unicode strings here, but you need not use localized # page names for system and help pages, those will be used automatically # according to the user selected language. [Unicode] navi_bar = [ #设置导航栏 # If you want to show your page_front_page here: u'%(page_front_page)s', u'RecentChanges', u'FindPage', u'HelpContents', ] # The default theme anonymous or new users get theme_default = 'modern' #设置网页主题峁 # Language options -------------------------------------------------- # See http://moinmoin.wikiwikiweb.de/ConfigMarket for configuration in # YOUR language that other people contributed. # The main wiki language, set the direction of the wiki pages language_default = 'zh' #设置默认语言 # You must use Unicode strings here [Unicode] page_category_regex = u'^Category[A-Z]' page_dict_regex = u'[a-z]Dict$' page_form_regex = u'[a-z]Form$' page_group_regex = u'[a-z]Group$' page_template_regex = u'[a-z]Template$' # Content options --------------------------------------------------- # Show users hostnames in RecentChanges show_hosts = 1 # Enable graphical charts, requires gdchart. #chart_options = {'width': 600, 'height': 300}

      • 第四步是配置在Apache2中配置Mod_Python,在/etc/apache2/conf目录下创建一个moin_mop_python.conf的配置文档,内容如下:

        Alias /wiki/ "/usr/share/moin/htdocs/" <Location /mywiki> SetHandler python-program# Add the path of your wiki directory PythonPath "['/root/mywiki/'] + sys.path" PythonHandler MoinMoin.request::RequestModPy.run</Location>

        配置完成后,需重启Apache服务器,查询Apache日志可看到服务器的启动状态,Apache的日志存放在/var/log/apache2目录下。成功启动后,访问http://moinserver/mywiki即可打开进入MoinMoin。

      • 最后,我们还要安装中文语言包。我们先要在MoinMoin中用登录界面创建一个有管理员权限的用户,在该例中就是moin_admin用户。以该用户登录后再访问http://moinserver/mywiki/SystemPagesSetup网页安装中文语言包。如果你没有管理权限,访问该页面时在语言包前面是不会显示"安装"按钮的。

      • 从moin1.5.1升级到moin1.5.3的操作很简单,首先备份好/usr/lib/python2.3/site-packages/MoinMoin目录和/usr/share/moin目录。接着删除这两个目录和实例目录下的underlay目录,安装新版本的moinmoin系统。最后把/usr/share/moin/underlay目录拷贝到实例目录,修改该目录的访问权限。升级完成要重启服务器。注意,如果你修改了/usr/lib/python2.3/site-packages/MoinMoin目录和/usr/share/moin目录下文件的内容,升级完成后要重新修改或用旧文件覆盖。

    • 访问控制列表(ACL)

      语法:

      #acl [+-]User[,SomeGroup,...]:[right[,right,...]] [[+-]OtherUser:...] [[+-]Trusted:...] [[+-]Known:...] [[+-]All:...] [Default]参数说明:User 用户名SomeGroup 组名Trusted 一个特殊组,包括所有通过HTTP-Basic-authentication验证的用户Known 一个特殊组,包括所有有效用户 (使用 cookie 验证方法)All 一个特殊组,包括所有用户 Default 一个特殊项,使用配置文件中acl_rights_default中的值right 表示权限,可以是 read、write、delete、revert 和 admin的组合,允许为空,表示没有任何权限。权限说明:read 读权限write 编辑权限delete 删除页面和附件的权限revert 有还原旧版本的权限admin 具有管理ACL的权限

      ACL放在网页内容的前面,下面一个ACL示例,所有用户有浏览权限,moin_admin用户具有所有权限:

      #acl moin_admin:read,write,delete,revert,admin All:read这是网页正文。MoinMoin ACL示例。...

      MoinMoin按ACL设置的顺序匹配用户,一旦匹配就不会搜索后面的配置。如上例,当我以moin_admin用户登录后访问该网页,它匹配了第一个用户名,则MoinMoin的ACL执行过程就停止,不会去再去匹配后面的ACL。所以我们在设置ACL时,应按用户、特殊组、普通组、Known、All的顺序设置。

      在MoinMoin中,组是用网页来维护的,在配置文件中的page_group_regex = u'[a-z]Group$'选项规定,以任意的小写字母组合后接Group结尾命名的页面都是一个组,如:testGroup,网页内每个最高列表项代表一个组成员,下例设置了test1,test2,test3三个用户。:

      #acl moin_admin:read,write,delete,revert,admin All:read *test1 *test2 *test3...

      在ACL设置中,MoinMoin引入"+"号和"-"号,改变ACL的配置规则,使ACL配置更灵活。当用户请求一个具有"+"或"-"号的ACL的页面时,只在用户名和权限同时匹配时才动作,"+"表示授予权限用户权限,"-"号表示禁止用户的权限,并停止ACL匹配。如果用户名和权限有一个不匹配,则继续搜索下一个ACL项。下面有一个示例:

      #acl SomeUser:read,write SomeGroup:read,write,admin All:read可以写成:#acl -SomeUser:admin SomeGroup:read,write,admin All:read或#acl +All:read -SomeUser:admin SomeGroup:read,write,admin

    • 使用Apache basic auth进行用户验证

      MoinMoin的用户信息存放在instance/data/user目录下,每个用户都有一个类似1137395855.97.12542的文件,里面记录着用户名、密码和显示样式等信息,MoinMion利用这些信息来进行用户验证和权限的控制。MoinMoin默认是使用Cookis来验证用户的,从1.3版开始,我们也可使用基于HTTP的用户验证,也就是说可以使用其它的用户数据库,如LDAP。不论使用Cookis还是HTTP方式,user目录下一定要存在一个与之对应的用户文件。因为MoinMoin只会使用该用户文件中的信息进行权限控制,所以在MoinMoin的配置文件中有一个user_autocreate参数,当把该选项设置为真时,当第一次用Apache basic auth方式登录MoinMion时,系统会自动在user目录下创建一个用户文件,该用户文件里不保存用户密码,只保存用户名和个人定制配置信息。采用HTTP验证方式,要修改两个文件,一个是wikiconfig.py,一个是moin_mod_python.conf。

      wikiconfig.py文件中修改的内容如下:

      ...from MoinMoin.auth import http...class Config(DefaultConfig):... user_autocreate=1 auth=[http]...

      修改后的moin_mod_python.conf:

      Alias /wiki/ "/usr/share/moin/htdocs/"<Location /portal> AuthType Basic AuthName "Portal" AuthUserFile "/etc/apache2/moinmoin.passwd" Require valid-user SetHandler python-program# Add the path of your wiki directory PythonPath "['/data/moin/portal/'] + sys.path" PythonHandler MoinMoin.request::RequestModPy.run</Location>

      moinmoin.passwd用户文件可用htpasswd2文件创建。需重启Apache服务器使配置生效。

    • 使用Apache+LDAP进行用户验证

      原理同上,只是验证数据我们存放在LDAP目录数据库。我使用OpenLDAP做为LDAP服务器。因为Apache+LDAP方式也是通过MoinMoin的HTTP验证模块进行的,所以wikiconfig.py的配置同上面的是一样的。这里的关健是要配置好Apache与LDAP服务器的连接。Apache需安装有mod_ldap.so和auth_ldap.so模块,如果已安装,可在/usr/lib/apache2/modules目录下查询到。在Debian中这两个模块默认是不启动的,可在/etc/apache2/mods-enable目录下创建一个auth_ldap.load链接来启动它,如:

      debian:/etc/apache2/mods-enabled# ln -s /etc/apache2/mods-available/auth_ldap.load auth_ldap.load

      auth_ldap.load文件会装载mod_ldap.so和auth_ldap.so这两个模块。下面配置moin_mod_python.conf,修改后的内容如下:

      Alias /wiki/ "/usr/share/moin/htdocs/"#LDAP连接Cache参数LDAPSharedCacheSize 200000LDAPCacheEntries 1024LDAPCacheTTL 600LDAPOpCacheEntries 1024LDAPOpCacheTTL 600<Location /portal> AuthType Basic #验证类型 AuthName "Portal" #验证名,显示在验证栏 AuthLDAPEnabled on #启用LDAP验证 AuthLDAPBindDN cn=admin,dc=com #连接LDAP服务器的用户 AuthLDAPBindPassword '1' #连接LDAP服务器的用户密码 AuthLDAPURL ldap://127.0.0.1/dc=user,dc=company,dc=com?uid? #连接URL AuthLDAPAuthoritative on #只允许LDAP验证方式 Require valid-user SetHandler python-program# Add the path of your wiki directory PythonPath "['/data/moin/portal/'] + sys.path" PythonHandler MoinMoin.request::RequestModPy.run</Location>

      mod_ldap模块提供了一个监控LDAP认证连接Cache信息的功能,在配置文件中增加以下标签即可。

      <Location /cache-info>SetHandler ldap-status</Location>~

      重启Apache服务器使配置生效。现在我们就可以通过LDAP服务器中的用户连接MoinMion了。访问http://moinserver/cache-info即可显示LDAP认证连接Cache信息。

    • 如果你的系统中安装了4suite这个XML处理软件包,MoinMoin可在线解析XML文档。

      MoinMoin会根据页面正文第一行是否以<?xml开头来判断是否要启动XML处理。MoinMoin也支持可在线解析DocBook文档,要支持在线解析DocBook文档,还需安装一个docboot-xsl包,该软件包包含把DocBook格式文档转换成HTML格式文档所需的样式表,安装完成后,HTML样式表位于/usr/share/xml/docbook/stylesheet/nwalsh/html目录。最后,我们需对MoinMoin进行配置,让它启动XSLT转换功能和指定转换DocBook的样式表目录。启动XSLT转换功能的选项是allow_xslt = 1,默认值为0,表示禁用XSLT转换功能。样式表目录选项为docbook_html_dir,在Debian Sarge中,它的默认值已是正确的啦,为/usr/share/xml/docbook/stylesheet/nwalsh/html/,不用修改。但权限有问题,不能被www-data所访问和修改,我们要用以下命令进行修改。

      debian:/usr/share/xml/docbook/stylesheet# chown -R www-data.www-data nwalsh

      修改完成后,重启MoinMoin服务器。创建一个DocBook格式的文档,如:

      #format docbook<?xml version="1.0" encoding="utf-8"?><!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" ><book> <chapter> <title>test</title> <para>test</para> </chapter></book>

      按保存,MoinMoin会把上面的DocBook文档自动转换成HTML文档输出。注意,DocBoo文档的encoding一定要用utf-8。我是在python2.4环境下做以上测试的,在python2.3中测试不成功,会出现字符编码出错提示。还有一个问题就是不能使用本地的dtd文件,会提示docbookx.dtd文档不存在错误。好象上面示例使用网上的dtd就没问题,但利用网上dtd时,HTML输出速度慢。从上面的测试结果来看,在WiKi中自动转换DocBook还不是很实用,一个是速度问题,上面已说过。另一个是编辑器问题,基于Web的编辑界面大简单了,远远比不上emacs等工具。

      • 有关MoinMoin的使用可参考自带的帮助文档,有很多都是中文版的了,查询起来很方便的。在MoinMoin的官方网站http://moinmoin.wikiwikiweb.de/上也有最新的教材可参考。有关中文化方面,现在的MoinMoin已支持I18n,会根据浏览器的设置自动显示多国语言。中文化支持也有很多志愿者在做,教材和帮助很多都是中文的了。如果你想为MoinMoin的中文化做贡献,请到http://moinmaster.wikiwikiweb.de/注册个帐号,然后把你的帐号放到MoinPagesEditorGroup页面就可以进行翻译了。

        小提示:

        • 任何用户在页面中添加ACL都需要有管理权限(admin)。

        • wikiconfig.py配置文档编码需是UTF-8格式的,如果不是UTF-8格式,就不能在该文档中使用中文。我们可用Kwrite编辑器来把它保存成UTF-8格式的。

        • /usr/lib/python2.3/site-packages/MoinMoin/theme目录存放MoinMoin的各种主题处理脚本,修改这些脚本可实现界面功能的增减,如取消标题搜索栏等。

        • /usr/share/moin/htdocs/目录下存放有各种主题的CSS文档,修改这些文档可实现界面风格的改变,如布局、字体大小和背景颜色等。

        • 删除页面时,页面文件不会从data/pages目录真正删除,它只是把文件的当前版本号增一,并在edit-log中记录删除日志。要真正删除页面,只能通过shell删除页面所在的目录。

        • 当用户创建个人页面后,每当用户编辑完任意一个页面,都会生成一个备份,存放在username/MoinEditorBackup目录下。个人页面是指以用户名命名的WiKi页面。

        Prev Up Next9.11. 安装Jabberd2服务器 Home 9.13. 安装Trac服务器

         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
        网易公司版权所有 ©1997-2009