Linux 系统下sphinx的安装及php扩展的配置流程
安装sphinx
cd /usr/local
官网下载Sphinx软件包:
wget http://sphinxsearch.com/files/sphinx-2.1.5-release.tar.gz
tar zxvf sphinx-2.1.5-release.tar.gz
cd sphinx-2.1.5-release
./configure --prefix=/usr/local/sphinx
make
make install
安装完成
配置sphinx.conf文件
cd /usr/local/sphinx/etc
cp sphinx.conf.dist sphinx.conf
vim sphinx.conf 编辑完成
[root@root var]# mkdir data1
[root@root var]# mkdir data2
[root@root var]# mkdir data0
Sphinx管理命令:
1. 生成全部索引
/usr/local/sphinx/bin/indexer --config /usr/local/sphinx/etc/sphinx.conf --all
若此时searchd守护进程已经启动,那么需要加上—rotate参数:
/usr/local/sphinx/bin/indexer --config /usr/local/sphinx/etc/sphinx.conf --all --rotate
2. 启动searchd守护进程
/usr/local/sphinx/bin/searchd --config /usr/local/sphinx/etc/sphinx.conf
3 使用search命令在命令行对索引进行检索
/usr/local/sphinx/bin/search --config /usr/local/sphinx/etc/sphinx.conf
4. 添加计划任务
创建data脚本(主索引)build_main0_index.sh
Vim /usr/local/sphinx/bin/build_main0_index.sh
添加内容:
#/bin/bash
/usr/local/sphinx/bin/indexer --config /usr/local/sphinx/etc/sphinx.conf main0 --rotate
创建delta脚本(增量索引并合并索引)build_delta_index.sh
Vim /usr/local/sphinx/bin/build_delta0_index.sh
添加内容:
#/bin/bash
/usr/local/sphinx/bin/indexer --config /usr/local/sphinx/etc/sphinx.conf delta0 --rotate
/usr/local/sphinx/bin/indexer --merge main0 delta0 --config
/usr/local/sphinx/etc/sphinx.conf --rotate
5. 赋予可执行权限
chmod +x /usr/local/sphinx/bin/build_main0_index.sh(赋予权限)
chmod +x /usr/local/sphinx/bin/build_delta0_index.sh(赋予权限)
6. 把searchd 设计成开机可执行项
Vim /etc/rc.local
添加:
/usr/local/sphinx/bin/searchd --config /usr/local/sphinx/etc/sphinx.conf
7. 添加计划任务
crontab -e
添加:
0 0 * * */bin/sh /usr/local/sphinx/bin/build_main0_index.sh
0 * * * */bin/sh /usr/local/sphinx/bin/build_delta0_index.sh
配置sphinx 扩展
1、先安装sphinxclient
cd /usr/local/sphinx-2.1.5-release/api/libsphinxclient
./configure --prefix=/usr/local/sphinxclient
Make
Make install
2、安装sphinx扩展 // 此处进行了修改
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/sphinxclient/
make && make install
echo [sphinx]>>/usr/local/php/etc/php.ini
echo extension=sphinx.so>>/usr/local/php/etc/php.ini
OK!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
reboot