Ubuntu系统,搭建mysql+sphinx环建

本文介绍下如何在ubuntu系统中,利用apt工具,搭建mysql+sphinx的全文检索环境。


一 安装mysql


1 更新源列表

打开"终端窗口",输入"sudo apt-get update"-->回车-->"输入root用户的密码"-->回车,就可以了。如果不运行该命令,直接安装mysql,会出现"有几个软件包无法下载,您可以运行apt-get update------"的错误提示,导致无法安装。


2 安装mysql

打开"终端窗口",输入"sudo apt-get install mysql-server mysql-client"-->回车-->输入"y"-->回车-->在"软件包设置对话框"中输入mysql中"root"用户的密码-->回车-->再输一次密码-->回车,安装完成。


3 如何判断mysql是否安装成功

打开"终端窗口",输入"sudo service mysql restart"-->回车-->如果mysql启动成功,处于运行状态说明mysql安装成功。


4 让apache支持mysql

打开"终端窗口",输入"sudo apt-get install libapache2-mod-auth-mysql"-->回车-->安装成功,安装这个模块后,apache才能支持mysql。


5 让php支持mysql

打开"终端窗口",输入"sudo apt-get install php5-mysql"-->回车-->安装成功,安装这个模块后,php才能支持mysql。


6 登录mysql

打开"终端窗口",输入"mysql -u root -p"-->回车-->输入mysql中"root"用户的密码-->回车-->登录成功。


二安装sphinx

       01、安装全文搜索引擎 Sphinx 前,必须先安装 MySQL server 并设置数据库 root 用户(参考步骤一)

       02、使用 apt-get 方法直接安装 Sphinx:

  1. apt-get install sphinxsearch
复制代码
       03、创建全文搜索引擎 Sphinx 的配置文件:
  1. cp /etc/sphinxsearch/sphinx.conf.sample /etc/sphinxsearch/sphinx.conf
  2. vi /etc/sphinxsearch/sphinx.conf
复制代码
              配置全文搜索引擎 Sphinx 的配置文件:
  1. sql_user = test
  2. sql_pass =
  3. # compat_sphinxql_magics = 1
复制代码
              将以上代码改为
  1. sql_user = root
  2. sql_pass = 您的数据库 root 用户密码
  3. compat_sphinxql_magics = 0
复制代码
       04、开启 sphinxsearch 功能:
  1. vi /etc/default/sphinxsearch
复制代码
              将其中的
  1. START=no
复制代码
              改为
  1. START=yes
复制代码
       05、创建 test 数据库:
  1. root:~# mysql -u root -p

  2. Enter password: 键入您的数据库 root 用户密码

  3. Welcome to the MySQL monitor.  Commands end with ; or \g.
  4. Your MySQL connection id is 20177
  5. Server version: 5.5.40-0ubuntu0.14.04.1 (Ubuntu)

  6. Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

  7. Oracle is a registered trademark of Oracle Corporation and/or its
  8. affiliates. Other names may be trademarks of their respective
  9. owners.

  10. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

  11. mysql>create database test;

  12. Query OK, 1 row affected (0.00 sec)

  13. mysql> use test;

  14. Reading table information for completion of table and column names
  15. You can turn off this feature to get a quicker startup with -A

  16. Database changed

  17. mysql> exit

  18. Bye

  19. root:~#

复制代码
       06、将 test 数据库范例文件
  1. /etc/sphinxsearch/example.sql
复制代码
              下载到本地计算机

       07、导入example.sql


mysql -u root -p你的root密码 -Dtest < /etc/sphinxsearch/example.sql

              说明 example.sql 文件导入 test 数据库成功

       08、建立全文搜索引擎 Sphinx 的索引:
  1. indexer --all
复制代码
1.jpg
        09、启动全文搜索引擎 Sphinx 服务:
  1. root:~# service sphinxsearch start

  2. Starting sphinxsearch: Sphinx 2.0.4-id64-release (r3135)
  3. Copyright (c) 2001-2012, Andrew Aksyonoff
  4. Copyright (c) 2008-2012, Sphinx Technologies Inc (http://sphinxsearch.com)

  5. using config file '/etc/sphinxsearch/sphinx.conf'...
  6. listening on all interfaces, port=9312
  7. listening on all interfaces, port=9306
  8. precaching index 'test1'
  9. precaching index 'test1stemmed'                             
  10. WARNING: multiple addresses found for 'localhost', using the first one (ip=127.0.0.1)
  11. precaching index 'rt'
  12. precached 3 indexes in 0.001 sec
  13. sphinxsearch.

  14. root:~# 

复制代码
       10、测试搜索 EN 单词 test
  1. root:~# /usr/bin/search test

  2. Sphinx 2.0.4-id64-release (r3135)
  3. Copyright (c) 2001-2012, Andrew Aksyonoff
  4. Copyright (c) 2008-2012, Sphinx Technologies Inc (http://sphinxsearch.com)

  5. using config file '/etc/sphinxsearch/sphinx.conf'...
  6. index 'test1': query 'test ': returned 3 matches of 3 total in 0.000 sec

  7. displaying matches:
  8. 1. document=1, weight=2421, group_id=1, date_added=Mon Dec 22 15:30:18 2014
  9.     id=1
  10.     group_id=1
  11.     group_id2=5
  12.     date_added=2014-12-22 15:30:18
  13.     title=test one
  14.     content=this is my test document number one. also checking search within phrases.
  15. 2. document=2, weight=2421, group_id=1, date_added=Mon Dec 22 15:30:18 2014
  16.     id=2
  17.     group_id=1
  18.     group_id2=6
  19.     date_added=2014-12-22 15:30:18
  20.     title=test two
  21.     content=this is my test document number two
  22. 3. document=4, weight=1442, group_id=2, date_added=Mon Dec 22 15:30:18 2014
  23.     id=4
  24.     group_id=2
  25.     group_id2=8
  26.     date_added=2014-12-22 15:30:18
  27.     title=doc number four
  28.     content=this is to test groups

  29. words:
  30. 1. 'test': 3 documents, 5 hits

  31. index 'test1stemmed': query 'test ': returned 3 matches of 3 total in 0.000 sec

  32. displaying matches:
  33. 1. document=1, weight=2421, group_id=1, date_added=Mon Dec 22 15:30:18 2014
  34.     id=1
  35.     group_id=1
  36.     group_id2=5
  37.     date_added=2014-12-22 15:30:18
  38.     title=test one
  39.     content=this is my test document number one. also checking search within phrases.
  40. 2. document=2, weight=2421, group_id=1, date_added=Mon Dec 22 15:30:18 2014
  41.     id=2
  42.     group_id=1
  43.     group_id2=6
  44.     date_added=2014-12-22 15:30:18
  45.     title=test two
  46.     content=this is my test document number two
  47. 3. document=4, weight=1442, group_id=2, date_added=Mon Dec 22 15:30:18 2014
  48.     id=4
  49.     group_id=2
  50.     group_id2=8
  51.     date_added=2014-12-22 15:30:18
  52.     title=doc number four
  53.     content=this is to test groups

  54. words:
  55. 1. 'test': 3 documents, 5 hits

  56. index 'rt': search error: failed to open /var/lib/sphinxsearch/data/rt.sph: No such file or directory.

  57. root:~#
复制代码
       11、好啦,一切 OK

三测试

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值