安装sphinx相关服务。
参考:http://blog.csdn.net/e421083458/article/details/21529969
http://www.coreseek.cn/products-install/install_on_bsd_linux/
安装sphinx相关服务。 参考:http://blog.csdn.net/e421083458/article/details/21529969 http://www.coreseek.cn/products-install/install_on_bsd_linux/ 一、客户端安装 1. pecl安装 # pecl install sphinx 2. 编译安装 1)安装sphinx库 安装libsphinxclient # wget http://www.coreseek.cn/uploads/csft/4.0/coreseek-4.1-beta.tar.gz # tar zxvf coreseek-4.1-beta.tar.gz && cd coreseek-4.1-beta # cd csft-4.1/api/libsphinxclient/ # aclocal # libtoolize --force # automake --add-missing # autoconf # autoheader #./configure --prefix=/usr/local/sphinxclient # make && make install # cd /home/download/ 2)安装php扩展 # wget http://pecl.php.net/get/sphinx-1.3.2.tgz # tar zxvf sphinx-1.3.2.tgz && cd sphinx-1.3.2 # phpize # ./configure --with-sphinx=/usr/local/sphinxclient # make && make install Installing shared extensions: /usr/lib64/php/modules/ 修改php配置,增加扩展到: # cat /etc/php.d/sphinx.ini ; Enable sphinx extension module extension=sphinx.so # php -m |grep sphinx sphinx 重启php-fpm服务: # service php-fpm reload Reloading php-fpm: [12-Nov-2014 09:15:32] NOTICE: configuration file /etc/php-fpm.conf test is successful 二、安装sphinx软件coreseek服务端 [root@test1 download]# yum install libtool expat expat-devel [root@test1 download]# wget http://www.coreseek.cn/uploads/csft/4.0/coreseek-4.1-beta.tar.gz [root@test1 download]# tar zxvf coreseek-4.1-beta.tar.gz && cd coreseek-4.1-beta 1)安装mmesg3 [root@test1 coreseek-4.1-beta]# cd mmseg-3.2.14/ [root@test1 mmseg-3.2.14]# ./bootstrap [root@test1 mmseg-3.2.14]# aclocal [root@test1 mmseg-3.2.14]# libtoolize --force [root@test1 mmseg-3.2.14]# automake --add-missing [root@test1 mmseg-3.2.14]# autoconf [root@test1 mmseg-3.2.14]# autoheader [root@test1 mmseg-3.2.14]# ./configure --prefix=/usr/local/mmseg3 [root@test1 mmseg-3.2.14]# make && make install 2)安装coreseek [root@test1 mmseg-3.2.14]# cd ../csft-4.1/ [root@test1 csft-4.1]# sh buildconf.sh [root@test1 csft-4.1]# ./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 [root@test1 csft-4.1]# make && make install 测试: [root@test1 csft-4.1]# cd ../testpack [root@test1 csft-4.1]# cat var/test/test.xml #此时应该正确显示中文 生成: [root@test1 csft-4.1]# /usr/local/mmseg3/bin/mmseg -d /usr/local/mmseg3/etc var/test/test.xml [root@test1 testpack]# /usr/local/coreseek/bin/indexer -c etc/csft.conf --all Coreseek Fulltext 4.1 [ Sphinx 2.0.2-dev (r2922)] Copyright (c) 2007-2011, Beijing Choice Software Technologies Inc (http://www.coreseek.com) using config file ‘etc/csft.conf‘... indexing index ‘xml‘... collected 3 docs, 0.0 MB sorted 0.0 Mhits, 100.0% done total 3 docs, 7585 bytes total 0.011 sec, 665350 bytes/sec, 263.15 docs/sec total 3 reads, 0.000 sec, 2.8 kb/call avg, 0.0 msec/call avg total 9 writes, 0.000 sec, 2.2 kb/call avg, 0.0 msec/call avg 搜索: [root@test1 testpack]# /usr/local/coreseek/bin/search -c etc/csft.conf 网络搜索 Coreseek Fulltext 4.1 [ Sphinx 2.0.2-dev (r2922)] Copyright (c) 2007-2011, Beijing Choice Software Technologies Inc (http://www.coreseek.com) using config file ‘etc/csft.conf‘... index ‘xml‘: query ‘网络搜索 ‘: returned 1 matches of 1 total in 0.000 sec displaying matches: 1. document=1, weight=1590, published=Thu Apr 1 22:20:07 2010, author_id=1 words: 1. ‘网络‘: 1 documents, 1 hits 2. ‘搜索‘: 2 documents, 5 hits
三、控制脚本
crontab_init.sh
#!/bin/bash # # 2014/9/4 echo "[+] append coreseek control scripts to /var/spool/cron/$(whoami)" cat <<_CORESEEK >>/var/spool/cron/$(whoami) # [coreseek] # #0 5 * * * /data/svr/coreseek/bin/indexer_rotate.sh main >/dev/null 2>&1 & #0 7 * * * /data/svr/coreseek/bin/indexer_rotate.sh day >/dev/null 2>&1 & #*/2 * * * * /data/svr/coreseek/bin/indexer_rotate.sh merge >/dev/null 2>&1 & _CORESEEK echo ‘[-] finished!‘ echo ‘[-] please uncomment coreseek related tasks.‘ echo ‘‘ echo "#################" echo ‘[crontab]‘ crontab -l
coreseek_ctl.sh
#!/bin/bash # # 2014/9/4 d_coreseek_base=‘/data/svr/coreseek‘ f_coreseek_conf="${d_coreseek_base}/conf/test.conf" searchd_bin=‘/usr/local/coreseek/bin/searchd‘ stop() { ${searchd_bin} --config ${f_coreseek_conf} --stop } start() { ${searchd_bin} --config ${f_coreseek_conf} } debug() { ${searchd_bin} --config ${f_coreseek_conf} --logdebug } backup() { cd ${d_coreseek_base} local f_backup="${d_coreseek_base}/var/coreseek_$(date +%F).tar.gz" tar zcvf ${f_backup} bin/ conf/ chmod o-r ${f_backup} && ls -lh ${f_backup} } status() { ps -ef |grep -v grep |grep searchd --color } case $1 in start) start ;; stop) stop ;; restart) stop sleep 1 start ;; status) status ;; debug) debug ;; backup) backup ;; *) echo "Usage: $0 [start|stop|restart|status|debug|backup]" ;; esac
indexer_rotate.sh
#!/bin/bash # # 2014/9/23 d_coreseek_base=‘/data/svr/coreseek‘ f_coreseek_conf="${d_coreseek_base}/conf/test.conf" indexer_bin=‘/usr/local/coreseek/bin/indexer‘ d_coreseek_data=‘/home/coreseek/data‘ [ -d ${d_coreseek_data} ] || mkdir -p ${d_coreseek_data} d_coreseek_log="${d_coreseek_base}/log" [ -d ${d_coreseek_log} ] || mkdir -p ${d_coreseek_log} d_coreseek_var="${d_coreseek_base}/var" [ -d ${d_coreseek_var} ] || mkdir -p ${d_coreseek_var} #延迟执行 function wait_rotate(){ local idx=$1 echo ‘##############################################################‘ echo ‘## wait rotate‘ echo ‘##############################################################‘ while [ 1 ] do sleep .1 ls ${d_coreseek_data}/${idx}.new* >/dev/null 2>&1 if [ $? -ne 0 ]; then break fi done } function rebuild_all() { echo ‘##############################################################‘ echo ‘## rebuild all‘ echo ‘##############################################################‘ [ -d ${d_coreseek_data} ] || mkdir -p ${d_coreseek_data} ${indexer_bin} --config ${f_coreseek_conf} --all --rotate } function start_rotate() { local idx=$1 echo ‘##############################################################‘ echo ‘## start rotate‘ echo ‘##############################################################‘ echo "[-] indexer rotate: ${idx}" ${indexer_bin} --config ${f_coreseek_conf} ${idx} --rotate } function start_merge() { local idx_day=$1 local idx_delta=$2 f_proc="${idx_delta}" f_lock="${d_coreseek_var}/${f_proc}.lock" echo ‘##############################################################‘ echo ‘## start merge‘ echo ‘##############################################################‘ # 检查脚本是否已经运行,避免因为searchd服务进程退出而crontab仍然在执行,从而陷入死循环 if [ -f ${f_lock} ]; then echo "[+] ERROR: ${f_lock} exist!" exit 1 fi touch ${f_lock} echo "[+] `date` locked." #重建增量索引 echo "[+] `date` rotate ${idx_delta}" ${indexer_bin} --config ${f_coreseek_conf} ${idx_delta} --rotate echo "[-] `date` wait ${idx_delta}" wait_rotate ${idx_delta} #合并增量索引到当天索引 echo "[-] `date` merge to ${idx_day}" ${indexer_bin} --config ${f_coreseek_conf} --merge ${idx_day} ${idx_delta} --rotate --merge-dst-range deleted 0 0 echo "[-] `date` wait ${idx_day}" wait_rotate ${idx_day} rm ${f_lock} && echo "[-] `date` released." || echo "[-] `date` ${f_lock} not released!" } function run_main() { echo "[+] `date` run main:" start_rotate idx_main_blog >${d_coreseek_log}/main.blog.log 2>&1 & echo "[-] `date` end." } function run_day() { echo "[+] `date` run day:" start_rotate idx_day_blog >${d_coreseek_log}/day.blog.log 2>&1 & echo "[-] `date` end." } function run_merge() { echo "[+] `date` run merge:" start_merge idx_day_blog idx_delta_userblog >${d_coreseek_log}/merge.blog.log 2>&1 & echo "[-] `date` end." } function usage() { cat <<_USAGE usage: $0 [main|day|merge|all] _USAGE } case $1 in main) run_main ;; day) run_day ;; merge) run_merge ;; all) rebuild_all ;; *) usage ;; esac
四、配置文件示例
# #######################################source blog #用户日志主索引,每天重建 source main_blog { type = mysql sql_host = 192.168.1.123 sql_user = dbuser sql_pass = dbpass sql_db = d_blog sql_port = 3306 sql_query_info_pre = SET NAMES latin1 sql_query_pre = SET NAMES latin1 sql_query_pre = SET SESSION query_cache_type=OFF sql_query_pre = SQL 语句 sql_query = SQL 语句 sql_attr_uint = 字段1 sql_attr_string = 字段2 sql_attr_timestamp = 字段3 } #用户日志当天范围内索引,每天重建 source day_blog { type = mysql sql_host = 192.168.1.123 sql_user = dbuser sql_pass = dbpass sql_db = d_blog sql_port = 3306 sql_query_info_pre = SET NAMES latin1 sql_query_pre = SET NAMES latin1 sql_query_pre = SET SESSION query_cache_type=OFF sql_query_info_pre = SET NAMES latin1 sql_query_pre = SET NAMES latin1 sql_query_pre = SET SESSION query_cache_type=OFF sql_query_pre = SQL 语句 sql_query = SQL 语句 sql_attr_uint = 字段1 sql_attr_string = 字段2 sql_attr_timestamp = 字段3 } #用户日志当天范围内增量索引 source delta_blog : day_blog { sql_query_pre = SET NAMES latin1 sql_query_pre = SET SESSION query_cache_type=OFF sql_query = SQL 语句 sql_query_post_index = SQL 语句 } #######################################index blog #用户日志主索引,每天重建 index idx_main_blog { source = main_blog path = /data/svr/coreseek/data/idx_main_blog docinfo = extern mlock = 0 morphology = none min_word_len = 1 min_infix_len = 1 html_strip = 0 charset_dictpath = /usr/local/mmseg3/etc/ charset_type = zh_cn.utf-8 ngram_len = 0 } #用户日志当天范围内索引,每天重建 index idx_day_blog { source = day_blog path = /data/svr/coreseek/data/idx_day_blog docinfo = extern mlock = 0 morphology = none min_word_len = 1 min_infix_len = 1 html_strip = 0 charset_dictpath = /usr/local/mmseg3/etc/ charset_type = zh_cn.utf-8 ngram_len = 0 } #用户日志当天范围内增量索引 index idx_delta_blog : idx_day_blog { source = delta_blog path = /data/svr/coreseek/data/idx_delta_blog } ############################################################################# ## indexer settings ############################################################################# indexer { mem_limit = 1024M } ############################################################################# ## searchd settings ############################################################################# searchd { listen = 9312 log = /data/svr/coreseek/log/searchd.log query_log = /data/svr/coreseek/log/query.log binlog_path = # empty to close binlog. read_timeout = 5 client_timeout = 300 max_children = 30 pid_file = /data/svr/coreseek/var/searchd.pid max_matches = 5000 compat_sphinxql_magics = 0 seamless_rotate = 1 preopen_indexes = 1 unlink_old = 1 mva_updates_pool = 1M max_packet_size = 8M max_filters = 256 max_filter_values = 4096 max_batch_queries = 32 workers = threads #workers = prefork # use threads for RT to work #prefork_rotation_throttle = 50 } # --eof--
原文地址:http://nosmoking.blog.51cto.com/3263888/1595266