ECStore部署SPHINX实战教程
ECStore部署SPHINX-SEARCHD实战教程
#参考资料
b2b2c :https://jinjiajin.net/762.html #
ECSTore:http://ecos.phpwindow.com/append-c/sphinx-2.html
【注意以下内容以ecstore为主,至于b2b2c则有部分配置不同】
#安装re正则,分词依赖
| 1 |
yum install -y re2 re2-devel
|
#安装sphinx searchd软件
| 1 2 3 4 5 6 |
vi /etc/bashrc #添加# PATH=$PATH:/usr/local/sphinx/bin
wget http://sphinxsearch.com/files/sphinx-2.2.10-release.tar.gz
tar xzf sphinx-2.2.10-release.tar.gz && cd sphinx-2.2.10-release
./configure --prefix=/usr/local/sphinx --with-re2 --with-re2-libs=/usr/lib64/libre2.so CXXFLAGS="-std=c++11" # –with-mysql=/usr/local/mysql/
vi src/Makefile #修改# LIBS = -lexpat -ldl -lm -lz -L/usr/local/lib -lrt -liconv -lpthread
make && make install
|
# -- 由于scws只能单机部署,如果是集群则每台机器都需要部署 -- # BEGIN
#安装scws中文分词
| 1 2 3 4 |
wget http://www.xunsearch.com/scws/down/scws-1.2.3.tar.bz2
tar xvf scws-1.2.3.tar.bz2 && cd scws-1.2.3
./configure --prefix=/usr/local/scws
make && make install
|
#安装php的scws扩展
| 1 2 3 |
cd scws-1.2.3/phpext/ && $(which phpize)
./configure --with-scws=/usr/local/scws --with-php-config=/usr/local/php/bin/php-config
make && make install
|
#配置php.ini末尾添加
| 1 2 3 4 5 |
[scws]
extension = scws.so
scws.default.charset = utf8
;以下的的路径就是编译时的--with-scws的值
scws.default.fpath = /usr/local/scws/
|
#安装scws的词典
| 1 2 3 4 5 6 |
cd /usr/local/scws/etc/
wget http://www.xunsearch.com/scws/down/scws-dict-chs-gbk.tar.bz2
wget http://www.xunsearch.com/scws/down/scws-dict-chs-utf8.tar.bz2
tar xvjf scws-dict-chs-gbk.tar.bz2
tar xvjf scws-dict-chs-utf8.tar.bz2
chown root:root *.xdb
|
# -- 由于scws只能单机部署,如果是集群则每台机器都需要部署 -- # END
#修改ecstore配置
| 1 |
vi /home/wwwroot/xxx.com/config/config.php
|
#反注释以下(配置scws分词)
| 1 2 |
define('SCWS_DICT', 'xxx.xdb');
define('SCWS_RULE', 'xxx.ini');
|
#反注释以下(指定sphinx searchd服务器)
| 1 2 |
define('SPHINX_SERVER_HOST', 'xxx');
define('SPHINX_PCONNECT', 1);
|
#修改sphinx searchd配置
| 1 |
vi /home/wwwroot/xxx.com/app/search/config/sphinx.conf
|
修改三处地方:sql_host/sql_user/sql_pass/sql_db/sql_port
修改log/query_log/pid_file路径:/usr/local/sphinx/var/log/
修改index的b2c_goods_merge/b2c_goods_delta/search_associate路径:/usr/local/sphinx/var/data/
| 1 |
cp /home/wwwroot/xxx.com/app/search/config/sphinx.conf /usr/local/sphinx/etc/sphinx.conf
|
#测试sphinx searchd更新索引
| 1 |
searchd && indexer --all --rotate
|
#修改定时任务脚本配置
| 1 2 3 |
vi /home/wwwroot/xxx.com/app/search/config/build_delta_index.sh
vi /home/wwwroot/xxx.com/app/search/config/build_main_index.sh
chmod +x /home/wwwroot/xxx.com/app/search/config/*.sh
|
改完以上两个文件的各三行配置后,分别运行一次(可能无法锁定pid文件,增加sleep方法避免)
#增加定时任务更新索引
| 1 2 3 4 |
crontab -e
30 2 * * * /home/wwwroot/xxx.com/app/search/config/build_delta_index.sh > /dev/null 2>&1 &
* * * * * /usr/local/sphinx/bin/indexer b2c_goods_delta --config /usr/local/sphinx/etc/sphinx.conf --rotate & #商品增量索引
* * * * * /usr/local/sphinx/bin/indexer search_associate --config /usr/local/sphinx/etc/sphinx.conf --rotate & #联想词索引更新
|