一:安装sphinx步骤如下:
下载sphinx最新的2.2.11版本
cd /opt/sphinx
wget 下载地址
tar xzvf sphinx-2.2.11-release.tar.gz
cd /opt/sphinx/sphinx-2.2.11-release
./configure --prefix=/opt/soft_install/sphinx/ --with-mysql=/usr/local/mysql
make && make install
安装成功后,会在目录:ls -lht /opt/soft_install/sphinx/下有四个文件夹
[root@XL_Php_Mysql sphinx-2.2.11-release]# ls -lht /opt/soft_install/sphinx/
总用量 16K
drwxr-xr-x 4 root root 4.0K 7月 22 12:05 var
drwxr-xr-x 2 root root 4.0K 7月 22 12:05 etc
drwxr-xr-x 3 root root 4.0K 7月 22 12:05 share
drwxr-xr-x 2 root root 4.0K 7月 22 12:05 bin
进入etc目录,拷贝配置文件, cp sphinx-min.conf.dist sphinx.conf (这里不拷贝sphinx.conf.dist ,因为这文件只是比前者多了一堆注释)
其实只需要安装coreseek即可,不需要安装sphinx。
安装coreseek
首先下载软件,打开 官网 coreseek.cn(不过该网站已经打不开了,只能去其他地方下载,我是从csdn上下的,花了5积分,好心疼)
下载coreseek-4.1-beta.tar.gz(csdn下载)
cd /opt/coreseek
wget 下载地址
tar xzvf coreseek-4.1-beta.tar.gz
里有3个文件夹 一个是mmseg中文分词包 一个是csft(其实就是sphinx)包,一个是测试包testpack,只需安装前两个即可。
创建安装目录:
mkdir /opt/soft_install/coreseek
返回coreseek mmseg目录,开始首先安装mmseg
cd /opt/coreseek/coreseek-4.1-beta/mmseg-3.2.14/
首先安装mmseg中文分词
./configure --prefix=/opt/soft_install/coreseek/mmseg
编译时可能会报错config.status: error: cannot find input file: src/Makefile.in
通过automake来解决
首先检查是否安装了libtool如果没有
yum -y install libtool
automake
如果automake报错 原因可能是下列
Libtool library used but `LIBTOOL' is undefined
The usual way to define `LIBTOOL' is to add `AC_PROG_LIBTOOL'
to `configure.ac' and run `aclocal' and `autoconf' again.
If `AC_PROG_LIBTOOL' is in `configure.ac', make sure
its definition is in aclocal's search path.
如果以上步骤都没成功,那么试下以下办法(把下面的命令都执行一遍,就好了)
aclocal
libtoolize -f (等于libtoolize --force)
automake -a (等于automake -add-missing)
autoconf
autoheader
make clean
执行完上述语句后,继续执行安装命令:
./configure --prefix=/opt/soft_install/coreseek/mmseg
此时会出现安装成功的命令显示:
------------------------------------------------------------------------
Configuration:
Source code location: .
Compiler: gcc
Compiler flags: -g -O2
Host System Type: x86_64-redhat-linux-gnu
Install path: /opt/soft_install/coreseek/mmseg
See config.h for further configuration information.
------------------------------------------------------------------------
运行安装命令:
make && make install
运行结束后,在安装目录:/opt/soft_install/coreseek/mmseg/会有四个文件产生:
[root@XL_Php_Mysql mmseg-3.2.14]# ls -lht /opt/soft_install/coreseek/mmseg/
总用量 16K
drwxr-xr-x 2 root root 4.0K 7月 22 12:31 etc
drwxr-xr-x 3 root root 4.0K 7月 22 12:31 include
drwxr-xr-x 2 root root 4.0K 7月 22 12:31 bin
drwxr-xr-x 2 root root 4.0K 7月 22 12:31 lib
测试是否安装成功:
/opt/soft_install/coreseek/mmseg/bin/mmseg -d /opt/soft_install/coreseek/mmseg/etc/ /opt/coreseek/coreseek-4.1-beta/mmseg-3.2.14/src/t1.txt
接着继续安装csft:
进入原码目录:
cd /opt/coreseek/coreseek-4.1-beta/csft-4.1
sh buildconf.sh
./configure --prefix=/opt/soft_install/coreseek/csft --with-mysql=/usr/local/mysql --with-mmseg=/opt/soft_install/coreseek/mmseg --with-mmseg-includes=/opt/soft_install/coreseek/mmseg/include/mmseg/ --with-mmseg-libs=/opt/soft_install/coreseek/mmseg/lib/
make && make install
安装成功后,在安装目录下有四个目录:
[root@XL_Php_Mysql coreseek]# ls -lht /opt/soft_install/coreseek/csft/
总用量 16K
drwxr-xr-x 4 root root 4.0K 7月 22 12:43 var
drwxr-xr-x 2 root root 4.0K 7月 22 12:43 etc
drwxr-xr-x 3 root root 4.0K 7月 22 12:43 share
drwxr-xr-x 2 root root 4.0K 7月 22 12:43 bin
安装完毕后 注意 coreseek 中的配置文件也是csft.conf 而不是 sphinx.conf
cd /opt/soft_install/coreseek/csft/etc/
cp sphinx.conf.dist csft.conf
vim csft.conf
测试是否安装成功
/opt/soft_install/coreseek/csft/bin/indexer -c /opt/soft_install/coreseek/csft/etc/csft.conf
如果出现报错:/opt/soft_install/coreseek/csft/bin/indexer: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
则需要将文件:
32位系统:ln -s /usr/local/mysql/lib/libmysqlclient.so.18.1.0 /usr/lib/libmysqlclient.so.18
64位系统:ln -s /usr/local/mysql/lib/libmysqlclient.so.18.1.0 /usr/lib64/libmysqlclient.so.18
配置、测试mysql数据源搜索
cp /opt/coreseek/coreseek-4.1-beta/testpack/etc/csft_mysql.conf /opt/soft_install/coreseek/csft/etc/
[root@XL_Php_Mysql testpack]# ls -lht /opt/soft_install/coreseek/csft/etc/
总用量 68K
-rwxr-xr-x 1 root root 2.8K 7月 22 15:42 csft_mysql.conf
-rw-r--r-- 1 root root 26K 7月 22 12:43 csft.conf
-rw-r--r-- 1 root root 903 7月 22 12:43 example.sql
-rw-r--r-- 1 root root 26K 7月 22 12:43 sphinx.conf.dist
-rw-r--r-- 1 root root 1.2K 7月 22 12:43 sphinx-min.conf.dist
mysql -uroot -p test < /opt/coreseek/coreseek-4.1-beta/testpack/var/test/documents.sql
创建索引数据库账户
mysql> grant all privileges on test.* to sphinxdbuser@"%" identified by "sphinx07test";
mysql> grant all privileges on recruitment_system.* to sphinxdbuser@"%" identified by "sphinx07test";
mysql> flush privileges;
5.2 启动搜索服务
启动搜索服务,这里选择后台运行的方式
# /opt/soft_install/coreseek/csft/bin/indexer -c /opt/soft_install/coreseek/csft/etc/csft_mysql.conf --all
# /opt/soft_install/coreseek/csft/bin/searchd -c /opt/soft_install/coreseek/csft/etc/csft_mysql.conf
以在log中记录每个查询的io和cpu状态的方式启动搜索服务
# /opt/soft_install/coreseek/csft/bin/searchd --iostats --cpustats -c /opt/soft_install/coreseek/csft/etc/csft_mysql.conf
停止搜索服务
# /opt/soft_install/coreseek/csft/bin/searchd -c /opt/soft_install/coreseek/csft/etc/csft_mysql.conf --stop
查看搜索服务状态
# /opt/soft_install/coreseek/csft/bin/searchd -c /opt/soft_install/coreseek/csft/etc/csft_mysql.conf --status
5.3 本机搜索测试
# /opt/soft_install/coreseek/csft/bin/search -c /opt/soft_install/coreseek/csft/etc/csft_mysql.conf -a 百度成立
停止mysql,观察以上本机搜索测试是否正常
# /etc/init.d/mysqld stop
启动mysql,观察以上本机搜索测试是否正常
# /etc/init.d/mysqld start
5.4 异机php客户端api调用测试
API路径:/opt/coreseek/coreseek-4.1-beta/testpack/api/
拷贝test.php 和sphinxapi.php到支持php环境的机器,然后修改数据库地址,账号,密码等配置,测试如下:
# php test.php 中国
Query '中国 ' retrieved 1 of 1 matches in 0.016 sec.
Query stats:
'中国' found 17 times in 1 documents
运行时可能会出现错误:
Warning: assert() has been disabled for security reasons in /opt/test_coreseek/sphinxapi.php on line 182
则修改:
vi /etc/php.ini
disable_functions = 该列去除assert,
重启php-fpm
/etc/init.d/php-fpm restart
再次运行即可。