【转】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. Graphql介绍(Introduction to GraphQL)

    Introduction to GraphQL  GraphQL介绍 Learn about GraphQL, how it works, and how to use it in this seri ...

  2. Mysql与Redis的同步实践

    一.测试环境在Ubuntu kylin 14.04 64bit 已经安装Mysql.Redis.php.lib_mysqludf_json.so.Gearman. 点击这里查看测试数据库及表参考 本文 ...

  3. SharePoint 站点集和子站点数据互相读取

    1.站点集中可以使用SPSite.AllWeb,然后遍历所有站点的isRootWeb,根据siteTemplate取得需要的子站点. /// <summary> /// Handles t ...

  4. 【Alpha版本】冲刺阶段——Day 5

    我说的都队 031402304 陈燊 031402342 许玲玲 031402337 胡心颖 03140241 王婷婷 031402203 陈齐民 031402209 黄伟炜 031402233 郑扬 ...

  5. android之ViewPager的使用

    XML代码 <android.support.v4.view.ViewPager   ViewPager控件        android:layout_width="wrap_con ...

  6. HttpServletRequest 转换成MultipartHttpServletRequest

    //转换 HttpServletRequestMultipartHttpServletRequest mulReq=(MultipartHttpServletRequest)request;//获取上 ...

  7. Jenkins的maven工程打包的时候怎么指定不同环境的配置文件

    http://outofmemory.cn/code-snippet/6643/maven-profile-define-enviroment-package 在打包的时候我们添加上 这里我们指定配置 ...

  8. iOS开发小技巧--即时通讯项目:使用富文本在UILabel中显示图片和文字;使用富文本占位显示图片

    Label借助富文本显示图片 1.即时通讯项目中语音消息UI的实现,样式如图: 借助富文本在UILabel中显示图片和文字 // 1.创建一个可变的富文本 NSMutableAttributedStr ...

  9. Maven-搭建maven web项目

    点击Eclipse菜单File->New->Other->Maven->Maven Project 在选择maven-archetype的界面进行如下操作:(其他选项基本与创建 ...

  10. DOS命令行下mysql 基本命令

    第一招.mysql服务的启动和停止 net stop mysql net start mysql 第二招.登陆mysql 语法如下: mysql -u用户名 -p用户密码 键入命令mysql -uro ...