本文介绍一下如何部署wiki网站.
目前wikimedia网站的架构 :
本文测试环境 :
选择mediawiki 的 lts版本.
配置数据库 :
配置PostgreSQL 中文全文检索功能
配置token type, 参考 http://www.postgresql.org/docs/9.3/static/textsearch-parsers.html
设置mediawiki数据库的默认分词为中文分词.
配置nginx, 参考 http://wiki.nginx.org/MediaWiki
解决PCRE_UTF8的问题.
把这一段拷贝到一个脚本里面执行
解决办法是自行编译安装php, 并且指定pcre库.
配置php-fpm
# 使用新装的php-fpm启动
现在就差apc模块了, 但是好像有BUG. 无法安装.
配置数据库连接
配置网页数据库账号
配置账号
配置wiki.
下载这个文件LocalSettings.php, 并放到/opt/site/mediawiki/
[参考]
CentOS 6.x x64
mediawiki 1.23.1
php 5.5.14
nginx 1.6.0
PostgreSQL 9.3.x
zhparser 中文分词
# wget http://releases.wikimedia.org/mediawiki/1.23/mediawiki-1.23.1.tar.gz
# tar -zxvf mediawiki-1.23.1.tar.gz
# mv mediawiki-1.23.1 /opt/site/mediawiki
配置数据库 :
[root@db-172-16-3-150 soft_bak]# su - pg93
pg93@db-172-16-3-150-> cd /ssd4/pg93
pg93@db-172-16-3-150-> mkdir tbs_mediawiki
pg93@db-172-16-3-150-> psql
psql (9.3.3)
Type "help" for help.
digoal=# create role mediawiki nosuperuser login encrypted password 'mediawiki';
CREATE ROLE
digoal=# create tablespace tbs_mediawiki location '/ssd4/pg93/tbs_mediawiki';
CREATE TABLESPACE
digoal=# create database mediawiki with template template0 encoding 'UTF8' tablespace tbs_mediawiki owner mediawiki;
CREATE DATABASE
digoal=# \c mediawiki mediawiki
You are now connected to database "mediawiki" as user "mediawiki".
mediawiki=> create schema mediawiki;
CREATE SCHEMA
配置PostgreSQL 中文全文检索功能
# wget http://www.xunsearch.com/site/downfile?file=xunsearch-full-latest.tar.bz2
# tar -jxvf xunsearch-full-latest.tar.bz2
[root@db-172-16-3-150 soft_bak]# cd xunsearch-full-1.4.8/
[root@db-172-16-3-150 xunsearch-full-1.4.8]# ll
total 20
drwxr-xr-x 2 pg90 games 4096 Jul 14 09:47 packages
-rw-r--r-- 1 pg90 games 2937 Jul 2 2012 README.md
-rwxr-xr-x 1 pg90 games 11069 Aug 27 2013 setup.sh
[root@db-172-16-3-150 xunsearch-full-1.4.8]# cd packages/
[root@db-172-16-3-150 packages]# ll
total 9744
-rw-r--r-- 1 pg90 games 694445 Aug 27 2013 libevent-2.0.21-stable.tar.bz2
-rw-r--r-- 1 pg90 games 160888 Sep 21 2011 libuuid-1.0.0.tar.bz2
-rw-r--r-- 1 pg90 games 42 Sep 6 2011 README
-rw-r--r-- 1 pg90 games 434924 Aug 23 2013 scws-1.2.3-dev.tar.bz2
-rw-r--r-- 1 pg90 games 4090111 Dec 30 2010 scws-dict-chs-utf8.tar.bz2
-rw-r--r-- 1 pg90 games 3476028 Aug 16 2013 xapian-core-scws-1.2.15.tar.bz2
-rw-r--r-- 1 pg90 games 676474 Dec 11 2013 xunsearch-1.4.8.tar.bz2
-rw-r--r-- 1 pg90 games 423087 Dec 11 2013 xunsearch-sdk-1.4.8.zip
[root@db-172-16-3-150 packages]# tar -jxvf scws-1.2.3-dev.tar.bz2
[root@db-172-16-3-150 packages]# cd scws-1.2.3-dev
[root@db-172-16-3-150 scws-1.2.3-dev]# ./configure --prefix=/opt/scws-1.2.3-dev && make && make install
[root@db-172-16-3-150 scws-1.2.3-dev]# cd /opt/soft_bak/
[root@db-172-16-3-150 soft_bak]# git clone https://github.com/amutu/zhparser.git
[root@db-172-16-3-150 soft_bak]# cd zhparser/
[root@db-172-16-3-150 zhparser]# export PATH=/home/pg93/pgsql/bin:$PATH
[root@db-172-16-3-150 zhparser]# which pg_config
/home/pg93/pgsql/bin/pg_config
# SCWS_HOME=/opt/scws-1.2.3-dev make
# make install
[root@db-172-16-3-150 zhparser]# su - pg93
pg93@db-172-16-3-150-> psql mediawiki postgres
psql (9.3.3)
Type "help" for help.
mediawiki=# create extension zhparser;
CREATE EXTENSION
mediawiki=# select * from pg_ts_parser ;
prsname | prsnamespace | prsstart | prstoken | prsend | prsheadline | prslextype
----------+--------------+-------------+-----------------+-----------+---------------+---------------
default | 11 | prsd_start | prsd_nexttoken | prsd_end | prsd_headline | prsd_lextype
zhparser | 2200 | zhprs_start | zhprs_getlexeme | zhprs_end | prsd_headline | zhprs_lextype
(2 rows)
mediawiki=# CREATE TEXT SEARCH CONFIGURATION testzhcfg (PARSER = zhparser);
CREATE TEXT SEARCH CONFIGURATION
mediawiki=# select * from pg_ts_config where cfgname='testzhcfg';
cfgname | cfgnamespace | cfgowner | cfgparser
-----------+--------------+----------+-----------
testzhcfg | 2200 | 10 | 37586
(1 row)
配置token type, 参考 http://www.postgresql.org/docs/9.3/static/textsearch-parsers.html
mediawiki=# ALTER TEXT SEARCH CONFIGURATION testzhcfg ADD MAPPING FOR n,v,a,i,e,l WITH simple;
ALTER TEXT SEARCH CONFIGURATION
mediawiki=# select * from pg_ts_config_map where mapcfg=(select oid from pg_ts_config where cfgname='testzhcfg');
mapcfg | maptokentype | mapseqno | mapdict
--------+--------------+----------+---------
37587 | 110 | 1 | 3765
37587 | 118 | 1 | 3765
37587 | 97 | 1 | 3765
37587 | 105 | 1 | 3765
37587 | 101 | 1 | 3765
37587 | 108 | 1 | 3765
(6 rows)
mediawiki=# SELECT * FROM ts_parse('zhparser', 'hello world! 2010年保障房建设在全国范围内获全面启动,从中央到地方纷纷加大 了 保 障 房 的 建 设 和 投 入 力 度 。2011年,保障房进入了更大规模的建设阶段。住房城乡建设部党组书记、部长姜伟新去年底在全国住房城乡建设工作 会议上表示,要继续推进保障性安居工程建设。');
tokid | token
-------+----------
101 | hello
101 | world
117 | !
101 | 2010
113 | 年
118 | 保障
110 | 房建
118 | 设在
110 | 全国
110 | 范围
102 | 内
118 | 获
97 | 全面
118 | 启动
117 | ,
110 | 从中
118 | 央
118 | 到
110 | 地方
100 | 纷纷
118 | 加大
118 | 了
118 | 保
110 | 障
110 | 房
117 | 的
118 | 建
118 | 设
99 | 和
118 | 投
118 | 入
110 | 力
107 | 度
117 | 。
101 | 2011
113 | 年
117 | ,
118 | 保障
110 | 房
118 | 进入
118 | 了
100 | 更
110 | 大规模
117 | 的
118 | 建设
110 | 阶段
117 | 。
110 | 住房
110 | 城乡建设
110 | 部党组
110 | 书记
117 | 、
110 | 部长
110 | 姜伟新
116 | 去年底
112 | 在
110 | 全国
110 | 住房
110 | 城乡建设
118 | 工作
110 | 会议
110 | 上表
118 | 示
117 | ,
118 | 要
118 | 继续
118 | 推进
110 | 保障性
118 | 安居
110 | 工程建设
117 | 。
(71 rows)
mediawiki=# SELECT to_tsvector('testzhcfg','“今年保障房新开工数量虽然有所下调,但实际的年度在建规模以及竣工规模会超以往年份,相对应的对资金的需求也会创历史纪录。”陈国强说。在他看来,与2011年相比,2012年的保障房建设在资金配套上的压力将更为严峻。');
to_tsvector
------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------
'2011':27 '2012':29 '上':35 '下调':7 '严峻':37 '会':14 '会创':20 '保障':1,30 '历史':21 '压力':36 '国强':24 '在建':10 '实际':8 '对应
':17 '年份':16 '年度':9 '开工':4 '房':2 '房建':31 '数量':5 '新':3 '有所':6 '相比':28 '看来':26 '竣工':12 '纪录':22 '规模':11,13 '设
':32 '说':25 '资金':18,33 '超':15 '配套':34 '陈':23 '需求':19
(1 row)
mediawiki=# SELECT to_tsquery('testzhcfg', '保障房资金压力');
to_tsquery
---------------------------------
'保障' & '房' & '资金' & '压力'
(1 row)
设置mediawiki数据库的默认分词为中文分词.
digoal=# alter database mediawiki set default_text_search_config='testzhcfg';
配置nginx, 参考 http://wiki.nginx.org/MediaWiki
[root@db-172-16-3-150 zhparser]# cd /etc/nginx/conf.d
[root@db-172-16-3-150 conf.d]# cp default.conf default.conf.bak
[root@db-172-16-3-150 conf.d]# vi default.conf
server {
server_name digoal;
root /opt/site/mediawiki; ## <-- Your only path reference.
# Enable compression, this will help if you have for instance advagg? module
# by serving Gzip versions of the files.
gzip_static on;
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
# This matters if you use drush prior to 5.x
# After 5.x backups are stored outside the Drupal install.
#location = /backup {
# deny all;
#}
# Very rarely should these ever be accessed outside of your lan
location ~* \.(txt|log)$ {
allow 172.16.0.0/16;
deny all;
}
location ~ \..*/.*\.php$ {
return 403;
}
# No no for private
location ~ ^/sites/.*/private/ {
return 403;
}
# Block access to "hidden" files and directories whose names begin with a
# period. This includes directories used by version control systems such
# as Subversion or Git to store control files.
location ~ (^|/)\. {
return 403;
}
location / {
# This is cool because no php is touched for static content
try_files $uri @rewrite;
}
location @rewrite {
# You have 2 options here
# For D7 and above:
# Clean URLs are handled in drupal_environment_initialize().
rewrite ^ /index.php;
# For Drupal 6 and bwlow:
# Some modules enforce no slash (/) at the end of the URL
# Else this rewrite block wouldn't be needed (GlobalRedirect)
#rewrite ^/(.*)$ /index.php?q=$1;
}
location ~ \.php$ {
root /opt/site/mediawiki;
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
# Fighting with Styles? This little gem is amazing.
# This is for D6
#location ~ ^/sites/.*/files/imagecache/ {
# This is for D7 and D8
location ~ ^/sites/.*/files/styles/ {
try_files $uri @rewrite;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
}
[root@db-172-16-3-150 conf.d]# service nginx restart
Stopping nginx: [ OK ]
Starting nginx: [ OK ]
配置mediawiki
http://172.16.3.150/mw-config/index.php
解决对象缓存的问题, 安装php-apc.
[root@db-172-16-3-150 conf.d]# yum install -y php-apc
[root@db-172-16-3-150 conf.d]# service php-fpm restart
Stopping php-fpm: [ OK ]
Starting php-fpm: [ OK ]
解决PCRE_UTF8的问题.
这个报错来自 /opt/site/mediawiki/includes/installer/Installer.php
protected function envCheckPCRE() {
wfSuppressWarnings();
$regexd = preg_replace( '/[\x{0430}-\x{04FF}]/iu', '', '-АБВГД-' );
// Need to check for \p support too, as PCRE can be compiled
// with utf8 support, but not unicode property support.
// check that \p{Zs} (space separators) matches
// U+3000 (Ideographic space)
$regexprop = preg_replace( '/\p{Zs}/u', '', "-\xE3\x80\x80-" );
wfRestoreWarnings();
if ( $regexd != '--' || $regexprop != '--' ) {
$this->showError( 'config-pcre-no-utf8' );
return false;
}
return true;
}
把这一段拷贝到一个脚本里面执行
# vi test.php
<?php
$regexd = preg_replace( '/[\x{0430}-\x{04FF}]/iu', '', '-АБВГД-' );
// Need to check for \p support too, as PCRE can be compiled
// with utf8 support, but not unicode property support.
// check that \p{Zs} (space separators) matches
// U+3000 (Ideographic space)
$regexprop = preg_replace( '/\p{Zs}/u', '', "-\xE3\x80\x80-" );
var_dump($regexd);
var_dump($regexprop);
# /usr/bin/php ./test.php
string(7) "-?????-"
string(2) "--"
确实, RPM安装的php有问题.
因为pcre已经打包到php-common, 并没有使用服务器安装的pcre包.
例如系统安装的pcre带了utf8选项. 版本是7.8
[root@db-172-16-3-150 etc]# which pcretest
/usr/bin/pcretest
[root@db-172-16-3-150 etc]# pcretest -C
PCRE version 7.8 2008-09-05
Compiled with
UTF-8 support
Unicode properties support
Newline sequence is LF
\R matches all Unicode newlines
Internal link size = 2
POSIX malloc threshold = 10
Default match limit = 10000000
Default recursion depth limit = 10000000
Match recursion uses stack
[root@db-172-16-3-150 etc]# rpm -qf /usr/bin/pcretest
pcre-7.8-6.el6.x86_64
但是php安装的是8.3的pcre, 显然没有使用系统的7.8版本.
# php -i
pcre
PCRE (Perl Compatible Regular Expressions) Support => enabled
PCRE Library Version => 8.32 2012-11-30
Directive => Local Value => Master Value
pcre.backtrack_limit => 100000 => 100000
pcre.recursion_limit => 100000 => 100000
解决办法是自行编译安装php, 并且指定pcre库.
The PCRE extension is a core PHP extension, so it is always enabled. By default, this extension is compiled using the bundled PCRE library. Alternatively, an external PCRE library can be used by passing in the --with-pcre-regex=DIR configuration option where DIR is the location of PCRE's include and library files.
安装php
wget http://cn2.php.net/distributions/php-5.5.14.tar.bz2
tar -jxvf php-5.5.14.tar.bz2
cd php-5.5.14
指定pcre库和pcre.h
# rpm -ql pcre-devel
/usr/bin/pcre-config
/usr/include/pcre.h
/usr/include/pcre_scanner.h
/usr/include/pcre_stringpiece.h
/usr/include/pcrecpp.h
/usr/include/pcrecpparg.h
/usr/include/pcreposix.h
/usr/lib64/libpcre.so
# cp /usr/include/pcre.h /usr/lib64
# ./configure --with-pcre-regex=/usr/lib64 --enable-fpm --enable-opcache --with-pdo-pgsql=/home/pg93/pgsql/bin --with-pgsql=/home/pg93/pgsql/bin
# make && make install
/bin/sh /root/php-5.5.14/libtool --silent --preserve-dup-deps --mode=install cp ext/opcache/opcache.la /root/php-5.5.14/modules
Installing shared extensions: /usr/local/lib/php/extensions/no-debug-non-zts-20121212/
Installing PHP CLI binary: /usr/local/bin/
Installing PHP CLI man page: /usr/local/php/man/man1/
Installing PHP FPM binary: /usr/local/sbin/
Installing PHP FPM config: /usr/local/etc/
Installing PHP FPM man page: /usr/local/php/man/man8/
Installing PHP FPM status page: /usr/local/php/fpm/
Installing PHP CGI binary: /usr/local/bin/
Installing PHP CGI man page: /usr/local/php/man/man1/
Installing build environment: /usr/local/lib/php/build/
Installing header files: /usr/local/include/php/
Installing helper programs: /usr/local/bin/
program: phpize
program: php-config
Installing man pages: /usr/local/php/man/man1/
page: phpize.1
page: php-config.1
Installing PEAR environment: /usr/local/lib/php/
[PEAR] Archive_Tar - already installed: 1.3.11
[PEAR] Console_Getopt - already installed: 1.3.1
[PEAR] PEAR - already installed: 1.9.4
Wrote PEAR system config file at: /usr/local/etc/pear.conf
You may want to add: /usr/local/lib/php to your php.ini include_path
[PEAR] Structures_Graph- already installed: 1.0.4
[PEAR] XML_Util - already installed: 1.2.1
/root/php-5.5.14/build/shtool install -c ext/phar/phar.phar /usr/local/bin
ln -s -f /usr/local/bin/phar.phar /usr/local/bin/phar
Installing PDO headers: /usr/local/include/php/ext/pdo/
# cp /root/php-5.5.14/php.ini-production /usr/local/lib/php.ini
# php --ini
Configuration File (php.ini) Path: /usr/local/lib
Loaded Configuration File: /usr/local/lib/php.ini
Scan for additional .ini files in: (none)
Additional .ini files parsed: (none)
配置php-fpm
# cp /usr/local/etc/php-fpm.conf.default /usr/local/etc/php-fpm.conf
# service php-fpm stop
# chkconfig php-fpm off
# 使用新装的php-fpm启动
# /usr/local/sbin/php-fpm -R -y /usr/local/etc/php-fpm.conf
因为自行编译了php, 所以警告需要另外安装apc和intl.
对应的包是 :
php-pecl-apc-3.1.15-0.4.20130912.el6.remi.5.4.x86_64
php-intl-5.4.30-1.el6.remi.x86_64
安装参考 :
# pecl install intl
如果遇到这个错误, 需要安装libicu-devel libicu.
configure: error: Unable to detect ICU prefix or no failed. Please verify ICU install prefix and make sure icu-config works.
最好安装最新的.不要使用yum安装.
wget http://download.icu-project.org/files/icu4c/53.1/icu4c-53_1-src.tgz
tar -zxvf icu4c-53_1-src.tgz
cd icu/source
# ./configure --enable-shared
# make && make install
[root@db-172-16-3-150 local]# icu-config --version
53.1
[root@db-172-16-3-150 local]# which icu-config
/usr/local/bin/icu-config
安装intl
# pecl install intl
...
Build process completed successfully
Installing '/usr/local/lib/php/extensions/no-debug-non-zts-20121212/intl.so'
install ok: channel://pecl.php.net/intl-3.0.0
configuration option "php_ini" is not set to php.ini location
You should add "extension=intl.so" to php.ini
配置 intl.
[root@db-172-16-3-150 php-5.5.14]# echo "extension=intl.so" >>/usr/local/lib/php.ini
[root@db-172-16-3-150 php-5.5.14]# ps -ewf|grep fpm
root 8963 1 0 15:47 ? 00:00:00 php-fpm: master process (/usr/local/etc/php-fpm.conf)
nobody 8964 8963 0 15:47 ? 00:00:00 php-fpm: pool www
nobody 8965 8963 0 15:47 ? 00:00:00 php-fpm: pool www
root 12112 8977 0 16:07 pts/1 00:00:00 grep fpm
[root@db-172-16-3-150 php-5.5.14]# kill 8963
[root@db-172-16-3-150 php-5.5.14]# php-fpm -R -y /usr/local/etc/php-fpm.conf
现在就差apc模块了, 但是好像有BUG. 无法安装.
# pecl install apc
/tmp/pear/temp/APC/apc_compile.c: In function ‘my_copy_class_entry’:
/tmp/pear/temp/APC/apc_compile.c:755: warning: assignment from incompatible pointer type
/tmp/pear/temp/APC/apc_compile.c: In function ‘apc_copy_class_entry_for_execution’:
/tmp/pear/temp/APC/apc_compile.c:1956: warning: assignment from incompatible pointer type
/tmp/pear/temp/APC/apc_compile.c: In function ‘apc_copy_trait_alias’:
/tmp/pear/temp/APC/apc_compile.c:2379: error: ‘zend_trait_alias’ has no member named ‘function’
/tmp/pear/temp/APC/apc_compile.c:2380: error: ‘zend_trait_alias’ has no member named ‘function’
/tmp/pear/temp/APC/apc_compile.c:2380: error: ‘zend_trait_alias’ has no member named ‘function’
/tmp/pear/temp/APC/apc_compile.c: In function ‘apc_copy_trait_precedence’:
/tmp/pear/temp/APC/apc_compile.c:2416: error: ‘zend_trait_precedence’ has no member named ‘function’
/tmp/pear/temp/APC/apc_compile.c:2417: error: ‘zend_trait_precedence’ has no member named ‘function’
/tmp/pear/temp/APC/apc_compile.c:2417: error: ‘zend_trait_precedence’ has no member named ‘function’
make: *** [apc_compile.lo] Error 1
ERROR: `make' failed
修改images的权限.
[root@db-172-16-3-150 mediawiki]# cd /opt/site/mediawiki/
[root@db-172-16-3-150 mediawiki]# chmod -R 777 images
这个警告, 需要配置一下php.ini.
# vi /usr/local/lib/php.ini
allow_url_fopen = On
[root@db-172-16-3-150 images]# ps -ewf|grep fpm
root 3912 1 0 16:48 ? 00:00:00 php-fpm: master process (/usr/local/etc/php-fpm.conf)
nobody 3913 3912 0 16:48 ? 00:00:04 php-fpm: pool www
nobody 3914 3912 0 16:48 ? 00:00:04 php-fpm: pool www
root 4392 8977 0 17:05 pts/1 00:00:00 grep fpm
[root@db-172-16-3-150 images]# kill 3912
[root@db-172-16-3-150 images]# php-fpm -R -y /usr/local/etc/php-fpm.conf
继续
然后就可以点击"进入您的wiki了"
[其他]
1. 数据库在这里使用了短连接, 所以我们可以使用pgbouncer来作为连接池.