开源框架XWIKI搭建介绍

原文地址:http://john88wang.blog.51cto.com/2165294/1605787

一 应用背景描述

  在平时的运维工作中,把常规工作进行文档整理非常重要,无论是平时工作处理或是工作交接,实时的维护文档资料可以提高工作效率。如果采用传统的TXT文档或者Word文档来记录的话修改不太方便,采用在线WIKI可以更好的让大家实时地查看或者修改文档资料。

  Wiki系统做得比较好的是Confluence,但是Confluence需要购买License才能使用,网上也有**版本的。对比多个开源WIKI系统,我们选择XWIKI作为我们的WIKI系统,因为它提供的功能与Confluence的功能非常相似,不需要学习任何语法格式,可以直接在线像编辑Word一样编辑WIKI页面。

  XWIKI有以下几个显著的功能特性:

  1)多语言支持,可以支持英文,中文,韩文,日文等

  2)可以上传附件

  3)支持LDAP方式认证登录

  4)可以将Office文档直接导入为WIKI页面,也可以将WIKI页面导出成Office文档或PDF文档

  5)使用者不需要学习任何WIKI语法格式,直接使用WYSIWYG编辑器进行WIKI页面的编辑。

  6)具有版本控制管理的功能,并且可以回退到之前的历史版本

  7)界面友好,功能丰富,内置搜索引擎,可以进行站内搜索。

  8)用户和组权限管理,空间和页面的权限管理

  9)邮件通知功能

  10)支持多种WIKI的语法格式,如Confluence,Markdown,Jspwiki,meidawiki,twiki等


二 安装XWIKI

目前XWIKI官方最新版本是6.3,可以单独安装也可以结合其他WEB容器如tomcat安装。这里我们使用tomcat作为容器安装XWIKI

各个版本的安装方法都类似


本文使用的是CentOS6系列操作系统

1)安装Java和Tomcat

yum -y install java-1.7.0-openjdk

安装中文字体库

yum install autocorr-zh.noarch    libreoffice-langpack-zh-Hans.x86_64 libreoffice-langpack-zh-Hant.x86_64   

wget http://mirrors.cnnic.cn/apache/tomcat/tomcat-7/v7.0.57/bin/apache-tomcat-7.0.57-fulldocs.tar.gz

wget http://download.forge.ow2.org/xwiki/xwiki-enterprise-web-6.3.war


2)进入到tomcat的安装目录下,根据自己的tomcat安装目录而定。

cd /data/app_platform/xwiki_tomcat/webapps/

mkdir xwiki

将xwiki-enterprise-web-6.3.war放到xwiki目录下

cd /data/app_platform/xwiki_tomcat/webapps/xwiki/

unzip xwiki-enterprise-web-6.3.war


3)编辑tomcat的server.xml修改8080端口描述设置编码为UTF8,并允许gzip压缩

1
2
3
4
5
6
7
   <Connector port="8080" protocol="HTTP/1.1"
                connectionTimeout="20000"
                redirectPort="8443"
                URIEncoding="UTF-8"
                compression="on"
                compressionMinSize="2048"
                compressableMimeType="text/html,text/xml,text/css,text/javascript,application/x-javascript"/>


4)配置JVM的内存大小和安装路径

如果是通过yum安装的tomcat需要修改如/etc/tomcat6/tomcat6.conf 这个文件

如果是使用的tomcat源码包安装,则修改bin/catalina.sh 这个文件

1
2
JAVA_HOME="/usr/lib/jvm/java-1.7.0-openjdk.x86_64/"
JAVA_OPTS="-Xmx300m -XX:MaxPermSize=196m"


5)配置Nginx转发

默认XWIKI通过类似http://xxxx:8080/xwiki/

的方式访问,可以配置Nginx转发

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
server {
     listen       80;
     server_name  xwiki.xxx.xxx;
     root  /data/app_platform/xwiki_tomcat/webapps/xwiki/;
 
     location / {
         rewrite ^ $scheme://$server_name/xwiki$request_uri? permanent;
     }
 
     location ^~ /xwiki {
# If path starts with /xwiki - then redirect to backend: XWiki application in Tomcat
        proxy_pass http://localhost:8080/xwiki;
 
     }
}


6)配置MySQL数据库

MySQL版本建议使用5.0以上,不要使用MyISAM存储引擎,因为MyISAM不支持事务处理,推荐使用InnoDB存储引擎。


创建XWIKI数据库

create database xwiki default character set utf8 collate utf8_bin;  


赋予相应的权限

grant all privileges on xwiki.* to xwiki identified by 'xwiki';

flush privileges;


下载MySQL JDBC Driver Jar放到/data/app_platform/xwiki_tomcat/webapps/xwiki/WEB-INF/lib目录下

wget http://repo1.maven.org/maven2/mysql/mysql-connector-java/5.1.34/mysql-connector-java-5.1.34.jar


编辑/data/app_platform/xwiki_tomcat/webapps/xwiki/WEB-INF/hibernate.cfg.xml

将默认的给注释掉,然后将MySQL那一段去掉注释

1
2
3
4
5
6
7
8
9
10
11
12
13
<!-- MySQL configuration.
          Uncomment if you want to use MySQL and comment out other database configurations.
     -->
     <property name="connection.url">jdbc:mysql://localhost/xwiki</property>
     <property name="connection.username">xwiki</property>
     <property name="connection.password">xwiki</property>
     <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
     <property name="dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
     <property name="dbcp.ps.maxActive">20</property>
     <mapping resource="xwiki.hbm.xml"/>
     <mapping resource="feeds.hbm.xml"/>
     <mapping resource="activitystream.hbm.xml"/>
     <mapping resource="instance.hbm.xml"/>


7)配置Office Server

 yum install libreoffice   libreoffice-headless

编辑xwiki.properties

1
2
openoffice.autoStart=true
openoffice.homePath=/usr/lib64/libreoffice/


wKioL1S-C-ii55OxABznrC08fx8243.bmp



8)XWIKI字符集编码配置

/data/app_platform/xwiki_tomcat/webapps/xwiki/WEB-INF/web.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
  <filter>
     <filter-name>Set Character Encoding</filter-name>
     <filter-class>org.xwiki.container.servlet.filters.internal.SetCharacterEncodingFilter</filter-class>
     <!-- The encoding to use. This must be the same as the one in xwiki.cfg (hopefully only one
          encoding will be used later). -->
     <init-param>
       <param-name>encoding</param-name>
       <param-value>UTF-8</param-value>
     </init-param>
     <!-- Whether to ignore and override the encoding specified by the client, when this actually
          happens. For example, AJAX requests made through XmlHttpRequests specify UTF-8. When this
          is set to false, the custom encoding is used only when there wasn't any encoding specified
          by the client. -->
     <init-param>
       <param-name>ignore</param-name>
       <param-value>false</param-value>
     </init-param>
   </filter>


/data/app_platform/xwiki_tomcat/webapps/xwiki/WEB-INF/xwiki.cfg


1
2
3
#-# The encoding to use when transformin strings to and from byte arrays. This causes the jvm encoding to be ignored,
#-# since we want to be independend of the underlying system.
xwiki.encoding=UTF-8


hibernate.cfg.xml中添加

1
2
     <property name="connection.useUnicode">true</property>
     <property name="connection.characterEncoding">UTF-8</property>


MySQL的配置文件my.cnf

1
2
3
4
5
6
[client]
default-character-set=utf8
[mysqld]
default-character-set=utf8
character-set-server=utf8
collation-server=utf8_bin


9)管理附件

默认情况下,XWIKI使用数据库存储附件,上传的附件最大为30M左右,同时MySQL的配置文件my.cnf中要设置max_allowed_packet为最大值的3倍左右,因为存储历史版本也会耗费空间

使用文件系统存储可以上传更大的附件,XWIKI使用一个临时目录来存储从数据库中调出的图片或附件。


附件的存储目录在xwiki.properties中设定,不可以随意增加或删除这个目录下的内容,因为每个附件在数据库中都有相应的元数据

1
2
3
4
5
#-# Note if the system property xwiki.data.dir is set then this property is not used.
#-# If neither the system property nor this configuration value here are set then the Servlet container's temporary
#-# directory is used; This is absolutely not recommended since that directory could be wiped out at any time and you
#-# should specify a value.
environment.permanentDirectory=/data/xwiki/


最好在第一次运行XWIKI的时候就设定好附件的存储方式

在xwik.cfg文件中设置

1
2
3
xwiki.store.attachment.hint=file
xwiki.store.attachment.versioning.hint=file
xwiki.store.attachment.recyclebin.hint=file


10)通过xwiki.xxx.xxx的方式可以直接访问XWIKI,然后进入安装页面


wKioL1S9JfPiXW3FAAIsEUrgXXI255.bmp



wKiom1S-EVOCCoC0AAC-1uTXQvM416.bmp

wKioL1S-EiiCRoEfAAH2Upis_Ro601.bmp




参考文档:

http://www.xwiki.org/xwiki/bin/view/Main/WebHome

http://enterprise.xwiki.org/xwiki/bin/view/Main/Download

http://platform.xwiki.org/xwiki/bin/view/AdminGuide/

https://www.atlassian.com/software/confluence/

http://en.wikipedia.org/wiki/Comparison_of_wiki_software

http://download.forge.objectweb.org/xwiki/