CentOS6.4 64位下安装sphinx及sphinx for php扩展

[ 2020-08-04 09:34:57 | 作者: admin ]
字号: | |
p.s. 官网上好像最新的 sphinx3没有提供源码,可以使用sphinx2,最新sphinx2.2.11。编译完再编译libsphinxclient ,最后下载编译php支持Sphinx模块 sphinx1.3.3 。

在官方网站下载最新的sphinx,这儿分享一下sphinx的安装及php扩展sphinx.so的安装方法,可能网上有很多相似的教程。
安装前请确定你安装了一些常用的东东,比如gcc mysql-devel之类的!当然,不装它也会提示你一些错误的,看着来吧!下面进入正题
yum install -y python python-devel


sphinx官网:http://sphinxsearch.com/downloads/release/
请使用稳定版,线上机器就别玩beta版啦!

安装sphinx
tar zxvf sphinx-2.1.4-release.tar.gz
cd sphinx-2.1.4-release
./configure --prefix=/usr/local/sphinx –-with-mysql
make && make install

编译出现错误 undefined reference to `libiconv
解决办法,在configure之后make前,编辑:./src/MakeFile文件,LIBS 加入-liconv 参数
将 LIBS = -lm -lexpat -L/usr/local/lib 改成 LIBS = -lm -L/usr/local/lib -lexpat -liconv


libsphinxclient 安装(PHP模块需要)
cd api/libsphinxclient
./configure --prefix=/usr/local/sphinx
make && make install

  安装PHP的Sphinx模块
下载地址:http://pecl.php.net/package/sphinx
安装教程:https://www.bbsmax.com/A/gVdnlKrpJW/
wget http://pecl.php.net/get/sphinx-1.3.0.tgz
tar zxf sphinx-1.3.0.tgz
cd sphinx-1.3.0
/usr/local/PHP/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --with-sphinx=/usr/local/sphinx/
make && make install

安装好后,在安装目录下etc目录下,有份测试数据和配置的样本
cd /usr/local/sphinx/etc
cp sphinx.conf.dist sphinx.conf

将sphinx.conf里面的数据库地址,账号密码改下就好了,再将lvtao.sql导进数据库lvtao
测试执行
/usr/local/sphinx/bin/search lvtao


  创建索引

创建索引命令:indexer
-c     指定配置文件
--all    对所有索引重新编制索引
--rotate  用于轮换索引,在不停止服务的时候(searchd运行时)增加索引;searchd运行时不加会报错。
--merge  合并索引,增量索引合并到主索引的时候用

 

生成全部索引: /usr/local/sphinx/bin/indexer -c /usr/local/sphinx/etc/sphinx.conf --all
注意:生成全部索要需要先关闭sphinx服务 service searchd stop ,不然会报错 Resource temporarily unavailable, will not index.


或指定索引(例如main): /usr/local/sphinx/bin/indexer -c /usr/local/sphinx/etc/sphinx.conf main


启动Sphinx

重建索引:./searchd -c /usr/local/sphinx/etc/sphinx.conf

轮换索引: ./searchd -c /usr/local/sphinx/etc/sphinx.conf goods_list --rotate

      ./searchd -c /usr/local/sphinx/etc/sphinx.conf store_list --rotate

启动服务:./searchd -c /usr/local/sphinx/etc/sphinx.conf --start

停止服务:./searchd -c /usr/local/sphinx/etc/sphinx.conf --stop






sphinx的自动启动脚本
复制下面的内容到:/etc/init.d/sphinx 或者 /etc/init.d/searchd
!/bin/sh
# sphinx: Startup script for Sphinx search
#
# chkconfig: 345 86 14
# description: This is a daemon for high performance full text \
# search of MySQL and PostgreSQL databases. \
# See http://www.sphinxsearch.com/ for more info.
#
# processname: searchd
# pidfile: $sphinxlocation/var/log/searchd.pid
  
# Source function library.
. /etc/rc.d/init.d/functions
  
processname=searchd
servicename=sphinx
username=seboraid
sphinxlocation=/usr/local/sphinx
pidfile=$sphinxlocation/var/log/searchd.pid
  
RETVAL=0
  
PATH=$PATH:$sphinxlocation/bin
  
start() {
         echo -n $"Starting Sphinx daemon: "
         daemon --user=$username --check $servicename $processname
         RETVAL=$?
         echo
         [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$servicename
}
  
stop() {
         echo -n $"Stopping Sphinx daemon: "
  
         killproc -p $pidfile $servicename -TERM
         RETVAL=$?
         echo
         if [ $RETVAL -eq 0 ]; then
                rm -f /var/lock/subsys/$servicename
                rm -f $pidfile
         fi
}
  
# See how we were called.
case "$1" in
         start)
                start
                ;;
         stop)
                stop
                ;;
         status)
                status $processname
                RETVAL=$?
                ;;
         restart)
                stop
  sleep 3
                start
                ;;
         condrestart)
                if [ -f /var/lock/subsys/$servicename ]; then
                     stop
   sleep 3
                     start
                fi
                ;;
         *)
                echo $"Usage: $0 {start|stop|status|restart|condrestart}"
                ;;
esac
exit $RETVAL

  然后执行下面的命令,以便此脚本能在本机时启动,最后一句相当于2345启动
chmod 755 /etc/init.d/sphinx
chkconfig --add sphinx
chkconfig sphinx on




后续:
今天发现sphinx没有启动,查看searchd.pid为空,手动启动sphinx提示“创建searchd.pid因为权限而失败”,删除searchd.pid后手动启动成功



备注:
coreseek是一款基于sphinx开源的搜索引擎,专门为用户提供免费的中文全文检索系统,coreseek被称为带有中文分词的sphinx,与sphinx不同的是coreseek增加了一个带有中文分司的词库,目前coreseek的官网已经不能访问,且该开源项目已不再维护,但这并不妨碍我们使用coreseek进行全文搜索,中文分词。不过为了可持续运行,对于不再维护的项目还是不要使用,因此不建议继续使用coreseek,继续使用sphinx的单字符中文检索。
基于php的sphinx和coreseek全文搜索,中文分词(一) https://www.yangpanyao.com/archives/72.html
基于php的sphinx和coreseek全文搜索,中文分词(二) https://www.yangpanyao.com/archives/73.html
[最后修改由 admin, 于 2021-12-31 11:24:17]
评论Feed 评论Feed: http://blog.xg98.com/feed.asp?q=comment&id=2698

这篇日志没有评论。

此日志不可发表评论。