【转】sphinx服务器安装及配置详解 安装PHP sphinx扩展

1、架构:ip192.168.0.200 redhat5.4(64位)
2、安装

   #cd /usr/local/src
   #yum -y install mysql-devel             #安装mysql头文件支持mysql
   #wget http://sphinxsearch.com/files/sphinx-0.9.9.tar.gz
   #tar -xvzf sphinx-0.9.9.tar.gz
   #cd sphinx-0.9.9
   #./configure --prefix=/usr/local/sphinx --with-mysql --with-iconv --enable-id64
   #make
   #make install

3、配置

   #cd /usr/local/sphinx
   #cp etc/sphinx.conf.dist etc/sphinx.conf
   #vim etc/sphinx.conf                      #修改配置文件
   source goods_src
   {
        type                                    = mysql
        sql_host                                = localhost
        sql_user                                = ecshop
        sql_pass                                = ecshop
        sql_db                                  = ecshop
        sql_port                                = 3306
        sql_sock                                = /tmp/mysql.sock
        sql_query_pre                           = SET NAMES utf8
        sql_query_pre                           = SET SESSION query_cache_type=OFF
        sql_query                               = \
                SELECT goods_id,cat_id,goods_sn,goods_name,brand_id,provider_name,goods_number,goods_weight,market_price,shop_price,promote_price,promote_start_date,keywords \
                FROM ecs_goods
        sql_attr_multi          = uint gid from query; SELECT goods_id,cat_id FROM ecs_goods
        sql_attr_uint           = brand_id
        sql_attr_float          = market_price
        sql_attr_float          = shop_price
        sql_attr_float          = promote_price
        sql_attr_float          = goods_weight
        sql_attr_str2ordinal    = goods_sn
        sql_attr_str2ordinal    = goods_name
        sql_ranged_throttle     = 100
    }
    index goods
    {
        source                  = goods_src
        path                    = /usr/local/sphinx/var/data/goods
        docinfo                 = extern
        mlock                   = 1
        morphology              = none
        min_stemming_len        = 1
        min_word_len            = 1
        charset_type            = utf-8
        charset_table           = 0..9, A..Z->a..z, _, a..z, U+410..U+42F->U+430..U+44F, U+430..U+44F
        ignore_chars            = U+00AD
        ngram_len               = 1
        html_strip              = 0

    }

    indexer
    {
        mem_limit               = 1024M               //建议256到1024之间
    }
    searchd
    {
        listen                  = 9312
        log                     = /usr/local/sphinx/var/log/searchd.log
        query_log               = /usr/local/sphinx/var/log/query.log
        read_timeout            = 5
        client_timeout          = 300
        max_children            = 30
        pid_file                = /usr/local/sphinx/var/log/searchd.pid
        max_matches             = 1000
        seamless_rotate         = 1
        preopen_indexes         = 0
        unlink_old              = 1
        mva_updates_pool        = 1M
        max_packet_size         = 8M
        max_filters             = 256
        max_filter_values       = 4096
    }

4、启动

   #/usr/local/sphinx/bin/indexer --config /usr/local/sphinx/etc/sphinx.conf --all   #创建索引
   #/usr/local/sphinx/bin/searchd --config /usr/local/sphinx/etc/sphinx.conf         #启动索引服务
   #crontab -e                                加入crontab五分钟重新索引
   */5 * * * */usr/local/sphinx/bin/indexer --config /usr/local/sphinx/etc/sphinx.conf --rotate
  

下面是安装PHP  sphinx扩展

1、安装

 1、先安装sphinxclient
   #cd /usr/local/src
   #wget http://sphinxsearch.com/files/sphinx-0.9.9.tar.gz
   #tar xzvf sphinx-0.9.9.tar.gz
   #cd sphinx-0.9.9/api/libsphinxclient
   #vim sphinxclient.c                   
    找到
    void sock_close ( int sock );
    改为
    static void sock_close ( int sock );
   #./configure --prefix=/usr/local/sphinxclient
   #make
   #make install
 2、安装sphinx扩展
   #wget http://pecl.php.net/get/sphinx-1.0.4.tgz
   #tar xvzf sphinx-1.0.4.tgz
   #cd sphinx-1.0.4
   #/usr/local/php/bin/phpize
   #./configure --with-php-config=/usr/local/php/bin/php-config --with-sphinx=/usr/local/sphinxclient
   #make
   #make install
   修改php.ini
   extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"
   [sphinx]
   extension=sphinx.so

2、测试
   1、安装sphinx
      请参照文档http://linux008.blog.51cto.com/2837805/622088
   2、编写测试文件

    #vim sphinx.php
    <?php
     $s = new SphinxClient;
     setServer("localhost", 9312);
     $s->setMatchMode(SPH_MATCH_ANY);
     $s->setMaxQueryTime(3);
     $result = $s->query("demo");
     var_dump($result);
    ?>
    #/usr/local/php/bin/php sphinx.php   运行结果
    array(9) {
  ["error"]=>
  string(0) ""
  ["warning"]=>
  string(0) ""
  ["status"]=>
  int(0)
  ["fields"]=>
  array(5) {
    [0]=>
    string(6) "cat_id"
    [1]=>
    string(13) "provider_name"
    [2]=>
    string(12) "goods_number"
    [3]=>
    string(18) "promote_start_date"
    [4]=>
    string(8) "keywords"
  }
  ["attrs"]=>
  array(8) {
    ["goods_sn"]=>
    string(1) "3"
    ["goods_name"]=>
    string(1) "3"
    ["brand_id"]=>
    string(1) "1"
    ["goods_weight"]=>
    string(1) "5"
    ["market_price"]=>
    string(1) "5"
    ["shop_price"]=>
    string(1) "5"
    ["promote_price"]=>
    string(1) "5"
    ["gid"]=>
    string(10) "1073741825"
  }
  ["total"]=>
  int(0)
  ["total_found"]=>
  int(0)
  ["time"]=>
  float(0)
  ["words"]=>
  array(1) {
    ["demo"]=>
    array(2) {
      ["docs"]=>
      int(0)
      ["hits"]=>
      int(0)
    }
  }
}

原文地址:
sphinx服务器安装及配置详解:http://linux008.blog.51cto.com/2837805/622088

http://linux008.blog.51cto.com/2837805/622171

sphinx安装记录 转的更多相关文章

  1. Linux Sphinx 安装与使用

    一.什么是 Sphinx? Sphinx 是一个基于SQL的全文检索引擎,可以结合 MySQL,PostgreSQL 做全文搜索,它可以提供比数据库本身更专业的搜索功能,使得应用程序 更容易实现专业化 ...

  2. 分布式监控系统Zabbix-3.0.3-完整安装记录(7)-使用percona监控MySQL

    前面已经介绍了分布式监控系统Zabbix-3.0.3-完整安装记录(2)-添加mysql监控,但是没有提供可以直接使用的Key,太过简陋,监控效果不佳.要想更加仔细的监控Mysql,业内同学们都会选择 ...

  3. 关于node.js和npm,cnpm的安装记录以及gulp自动构建工具的使用

    关于node.js和npm,cnpm的安装记录以及gulp自动构建工具的使用   工作环境:window下 在一切的最开始,安装node.js (中文站,更新比较慢http://nodejs.cn/) ...

  4. sourceinsight安装记录

    sourceinsight安装记录 此文章为本人使用sourceinsight一个星期之后的相关设置步骤记录和经验记录,以备以后查验,网上的相关资料都也较为完善,但是对于新手还是有一定困难的,所以在这 ...

  5. openerp安装记录及postgresql数据库问题解决

    ubuntu-14.04下openerp安装记录1.安装PostgreSQL 数据库    a.安装         sudo apt-get install postgresql    安装后ubu ...

  6. Matlab安装记录 - LED Control Activex控件安装

    Matlab安装记录-LED Control Activex控件安装 2013-12-01  22:06:36 最近在研究Matlab GUI技术,准备用于制作上位机程序:在Matlab GUI的技术 ...

  7. Arch Linux 安装记录

    Arch Linux 安装记录 基本上参考wiki上的新手指南,使用arch 2014.6.1 iso安装 设置网络 有线网络 Arch Linux 默认开启DHCP. 静态ip 首先关闭DHCP:s ...

  8. 修改sphinx最大输出记录数

    修改sphinx最大输出记录数 归纳如下: Sphinx的查询默认最大记录数是:1000,而我们想更改这个数值.就需要更改三个地方. 1是更改sphinx.conf配置文件的:max_matches ...

  9. redis5.0.3单实例简单安装记录

    redis5.0.3单实例简单安装记录 日常需要测试使用,索性记录下来,免得临时又麻烦的找资料. yum -y install make gcc-c++ cmake bison-devel ncurs ...

随机推荐

  1. 使用jsp/servlet简单实现文件上传与下载

    使用JSP/Servlet简单实现文件上传与下载    通过学习黑马jsp教学视频,我学会了使用jsp与servlet简单地实现web的文件的上传与下载,首先感谢黑马.好了,下面来简单了解如何通过使用 ...

  2. Okio 1.9简单入门

    Okio 1.9简单入门 Okio库是由square公司开发的,补充了java.io和java.nio的不足,更加方便,快速的访问.存储和处理你的数据.而OkHttp的底层也使用该库作为支持. 该库极 ...

  3. 利用ajaxfileupload.js异步上传文件

    1.引入ajaxfileupload.js 2.html代码 <input type="file" id="enclosure" name="e ...

  4. Linux_Shell_脚本参数接收键盘输入

    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 #!/bin/bash     #提示"请输入姓名"并等待30秒,把用户的输入保存入变量name ...

  5. 状态压缩 poj 3254

    n * m 个玉米 n*m个数字 0 或者1 1可以种玉米 0 不能  种玉米不能相邻 计算有几种 种的方法 #include<stdio.h> #include<algorithm ...

  6. UITextView实现placeHolder方法汇总

    UITextField中有一个placeholder属性,可以设置UITextField的占位文字,起到提示用户的作用.可是UITextView就没那么幸运了,apple没有给UITextView提供 ...

  7. UIScrollView实现图片轮播器及其无限循环效果

    图片轮播器: 一.实现效果 实现图片的自动轮播            二.实现代码 storyboard中布局 代码: 1 #import "YYViewController.h" ...

  8. 【LintCode】计算两个数的交集(一)

    问题分析: 既然返回值没有重复,我们不妨将结果放进set中,然后对两个set进行比较. 问题求解: public class Solution { /** * @param nums1 an inte ...

  9. 浅谈malloc()与free()

    malloc()与free() l  函数原型 malloc函数的函数原型为:void* malloc(unsigned int size),它根据参数指定的尺寸来分配内存块,并且返回一个void型指 ...

  10. GraphX的三大图算法

    1. PageRank http://blog.csdn.net/hguisu/article/details/7996185 2. Connected Components 3. Triangle ...