如下是我實戰sphinx的心得,寫下來與你們分享:php
一,下載coreseek:mysql
1
2
3
|
$ wget http:
//www
.coreseek.cn
/uploads/csft/4
.0
/coreseek-4
.1-beta.
tar
.gz
$
tar
xzvf coreseek-4.1-beta.
tar
.gz
$
cd
coreseek-4.1-beta
|
##前提:需提早安裝操做系統基礎開發庫及mysql依賴庫以支持mysql數據源和xml數據源
二,安裝mmseglinux
1
2
3
4
5
|
$
cd
mmseg-3.2.14
$ .
/bootstrap
#輸出的warning信息能夠忽略,若是出現error則須要解決
$ .
/configure
--prefix=
/usr/local/mmseg3
$
make
&&
make
install
$
cd
..
|
三,安裝coreseeksql
1
2
3
4
5
6
7
8
9
10
11
12
13
|
$
cd
csft-3.2.14 或者
cd
csft-4.0.1 或者
cd
csft-4.1
$ sh buildconf.sh
#輸出的warning信息能夠忽略,若是出現error則須要解決
$ .
/configure
--prefix=
/usr/local/coreseek
--without-unixodbc --with-mmseg --with-mmseg-includes=
/usr/local/mmseg3/include/mmseg/
--with-mmseg-libs=
/usr/local/mmseg3/lib/
--with-mysql
##若是提示mysql問題,要安裝下mysql的開發庫
##$ yum install mysql-devel libxml2-devel expat-devel
##而後執行下上面的configure##若是出現錯誤提示:「ERROR: cannot find MySQL include files.......To disable MySQL support, use --without-mysql option.「,可按照以下方法處理:
##請找到頭文件mysql.h所在的目錄,通常是/usr/local/mysql/include,請替換爲實際的
##請找到庫文件libmysqlclient.a所在的目錄,通常是/usr/local/mysql/lib,請替換爲實際的
##configure參數加上:--with-mysql-includes=/usr/local/mysql/include --with-mysql-libs=/usr/local/mysql/lib,執行後,從新編譯安裝
$
make
&&
make
install
$
cd
..
|
四,安裝libsphinxclientbootstrap
1
2
3
4
|
$
cd
testpack
/api/libsphinxclient
$ .
/configure
$
make
&&
make
install
$
cd
../../../
|
五,測試mmseg分詞,coreseek搜索(須要預先設置好字符集爲zh_CN.UTF-8,確保正確顯示中文)api
1
2
3
4
5
|
$
cd
testpack
$
cat
var
/test/test
.xml
#此時應該正確顯示中文
$
/usr/local/mmseg3/bin/mmseg
-d
/usr/local/mmseg3/etc
var
/test/test
.xml
$
/usr/local/coreseek/bin/indexer
-c etc
/csft
.conf --all
$
/usr/local/coreseek/bin/search
-c etc
/csft
.conf 網絡搜索
|
六,安裝php擴展sphinx
首先檢查下是否是安裝phpize,bash
1
2
3
4
5
6
7
8
9
10
|
$ phpize -
v
##若是顯示一些版本信息,證實安裝成功,不然須要安裝php-devel
##$ yum install php-devel
##而後下載sphinx擴展
$ wget http:
//pecl
.php.net
/get/sphinx-1
.0.4.tgz
$
tar
xzvf sphinx-1.0.4.tgz
$
cd
sphinx-1.0.4
$ phpize
$ .
/configure
$
make
&&
make
install
|
##成功的安裝後自動將建立 extname.so並放置於PHP 的擴展庫目錄中。
##須要調整php.ini,加入 extension=extname.so這一行以後才能使用此擴展庫。網絡
1
|
$ php -m |
grep
sphinx
|
##若是出現sphinx的擴展,證實安裝成功測試
七,將sphinx deamon加入rc.local開機自動啓動ui
1
2
|
$
cp
/usr/local/coreseek/etc/sphinx
.conf.dist
/usr/local/coreseek/etc/sphinx
.conf
$
vi
/etc/rc
.
local
|
加入以下腳本
1
|
/usr/local/coreseek/bin/search
-c
/usr/local/coreseek/etc/sphinx
.conf
|
八,將sphinx的配置目錄的寫權限開放(可選)
1
|
$
chmod
a+w
/usr/local/coreseek/etc/sphinx
.conf
|