无法通过sphinx特定端口连接到mysql

时间:2015-12-22 09:10:52

标签: php mysql yii2 sphinx

我正在尝试在服务器上设置sphinx搜索引擎。

在服务器上已经是另一个sphinx搜索守护程序,它从另一个用户运行另一个站点,带有另一个配置文件(端口3312)。

这是我的sphinx配置文件 /opt/sphinx/etc/site-sphinx.conf

source site_source
{
    type        = mysql
    sql_host    = localhost
    sql_user    = username
    sql_pass    = password
    sql_db      = dbname
    sql_port    = 3306
    sql_sock    = /var/run/mysqld/mysqld.sock

    mysql_connect_flags = 32

    sql_query_pre       = SET NAMES utf8
    sql_query_pre       = SET SESSION query_cache_type=ON

    sql_query = SELECT id, title, description, is_deleted, created_at, updated_at FROM table WHERE is_deleted = 0

    sql_attr_bool       = is_deleted
    sql_attr_timestamp  = created_at
    sql_attr_timestamp  = updated_at

    sql_ranged_throttle = 0
}

index sitename
{
    type                = plain
    source              = site_source

    path                = /opt/sphinx/var/data/site_index/site
    docinfo             = extern
    dict                = keywords
    mlock               = 0
    morphology          = stem_en, stem_ru, soundex, metaphone

    enable_star         = 1
    min_stemming_len    = 1
    min_word_len        = 1
    min_infix_len       = 3

    html_strip          = 1
    html_remove_elements    = style, script
}

indexer
{
    mem_limit                   = 1024M
}

searchd
{
    listen                  = 127.0.0.1:3313
    log                     = /opt/sphinx/var/log/site/search.log
    query_log               = /opt/sphinx/var/log/site/query.log
    binlog_path             = /opt/sphinx/var/data/site_binlog

    read_timeout            = 5
    max_children            = 30
    pid_file                = /opt/sphinx/var/run/searchd-site.pid
}

我开始 sphinxd

site@servername:~$ /opt/sphinx/bin/searchd --config /opt/sphinx/etc/site-sphinx.conf
Sphinx 2.2.9-id64-release (rel22-r5006)
Copyright (c) 2001-2015, Andrew Aksyonoff
Copyright (c) 2008-2015, Sphinx Technologies Inc (http://sphinxsearch.com)

using config file '/opt/sphinx/etc/site-sphinx.conf'...
WARNING: key 'enable_star' was permanently removed from Sphinx configuration. Refer to documentation for details.
listening on 127.0.0.1:3313
precaching index 'site'
precached 1 indexes in 0.051 sec


shapoval@sitename$ netstat -nlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.0.1:3313          0.0.0.0:*               LISTEN      21225/searchd
tcp        0      0 127.0.0.1:3312          0.0.0.0:*               LISTEN      26694/searchd
tcp6       0      0 :::3306                 :::*                    LISTEN      16998/mysqld

我开始编制索引

site@servername:~$ /opt/sphinx/bin/indexer --all --rotate --config /opt/sphinx/etc/site-sphinx.conf delta
using config file '/opt/sphinx/etc/site-sphinx.conf'...
WARNING: key 'enable_star' was permanently removed from Sphinx configuration. Refer to documentation for details.
indexing index 'site'...
WARNING: index 'site': dict=keywords and prefixes and morphology enabled, forcing index_exact_words=1
collected 1660326 docs, 674.2 MB
sorted 231.9 Mhits, 100.0% done
total 1660326 docs, 674237370 bytes
total 155.531 sec, 4335045 bytes/sec, 10675.15 docs/sec
total 16 reads, 15.074 sec, 61858.4 kb/call avg, 942.1 msec/call avg
total 1950 writes, 1.040 sec, 998.5 kb/call avg, 0.5 msec/call avg
rotating indices: successfully sent SIGHUP to searchd (pid=25377).

但我无法从命令行或从php连接到数据库(我使用yii2,连接到sphinx使用yii2-sphinx)。

当我尝试从命令行连接到mysql时,会发生错误:

shapoval@servername$ mysql -h0 -P3313 -u username -p
Enter password: 
ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 0 "Internal error/check (Not system error)"

当我尝试从站点运行查询时出现几个错误:

2015-12-22 10:03:08 [10.10.10.10][][-][error][yii\db\Exception] exception 'yii\base\ErrorException' with message 'Packets out of order. Expected 0 received 1. Packet size=0' in /var/www/sitename/vendor/yiisoft/yii2/db/Connection.php:558
Stack trace:
#0 /var/www/sitename/common/extensions/rollbar/RollbarErrorHandlerTrait.php(35): yii\base\ErrorHandler->handleError(2, 'Packets out of ...', '/var/www/sitename...', 558)
#1 [internal function]: common\extensions\rollbar\RollbarErrorHandler->handleError(2, 'Packets out of ...', '/var/www/sitename...', 558, Array)
#2 /var/www/sitename/vendor/yiisoft/yii2/db/Connection.php(558): PDO->__construct('mysql:host=127....', 'username', 'password', NULL)
#3 /var/www/sitename/vendor/yiisoft/yii2/db/Connection.php(508): yii\db\Connection->createPdoInstance()
#4 /var/www/sitename/vendor/yiisoft/yii2-sphinx/Connection.php(112): yii\db\Connection->open()
#5 /var/www/sitename/vendor/yiisoft/yii2-sphinx/Schema.php(255): yii\sphinx\Connection->createCommand('SHOW TABLES')
#6 /var/www/sitename/vendor/yiisoft/yii2-sphinx/Schema.php(239): yii\sphinx\Schema->findIndexes()
#7 /var/www/sitename/vendor/yiisoft/yii2-sphinx/Schema.php(226): yii\sphinx\Schema->initIndexesInfo()
#8 /var/www/sitename/vendor/yiisoft/yii2-sphinx/Schema.php(113): yii\sphinx\Schema->getIndexTypes()
#9 /var/www/sitename/vendor/yiisoft/yii2-sphinx/Schema.php(88): yii\sphinx\Schema->resolveIndexType(Object(yii\sphinx\IndexSchema))
#10 /var/www/sitename/vendor/yiisoft/yii2-sphinx/Schema.php(151): yii\sphinx\Schema->loadIndexSchema('sitename')
#11 /var/www/sitename/vendor/yiisoft/yii2-sphinx/Connection.php(78): yii\sphinx\Schema->getIndexSchema('sitename', false)
#12 /var/www/sitename/html/vendor/yiisoft/yii2-sphinx/QueryBuilder.php(494): yii\sphinx\Connection->getIndexSchema('sitename')
#13 /var/www/sitename/vendor/yiisoft/yii2-sphinx/QueryBuilder.php(81): yii\sphinx\QueryBuilder->buildWhere(Array, 'MATCH(:qp0)', Array)
#14 /var/www/sitename/vendor/yiisoft/yii2-sphinx/Query.php(171): yii\sphinx\QueryBuilder->build(Object(yii\sphinx\Query))
#15 /var/www/sitename/vendor/yiisoft/yii2-sphinx/Query.php(184): yii\sphinx\Query->createCommand(NULL)
#16 /var/www/sitename/common/actions/SphinxSearchAction.php(78): yii\sphinx\Query->all()
#17 [internal function]: common\actions\SphinxSearchAction->run()
#18 /var/www/sitename/vendor/yiisoft/yii2/base/Action.php(91): call_user_func_array(Array, Array)
#19 /var/www/sitename/vendor/yiisoft/yii2/base/Controller.php(147): yii\base\Action->runWithParams(Array)
#20 /var/www/sitename/vendor/yiisoft/yii2/base/Module.php(460): yii\base\Controller->runAction('search', Array)
#21 /var/www/sitename/vendor/yiisoft/yii2/web/Application.php(82): yii\base\Module->runAction('site/search', Array)
#22 /var/www/sitename/vendor/yiisoft/yii2/base/Application.php(369): yii\web\Application->handleRequest(Object(yii\web\Request))
#23 /var/www/sitename/frontend/web/index.php(18): yii\base\Application->run()
#24 {main}

Next exception 'PDOException' with message 'SQLSTATE[HY000] [2006] MySQL server has gone away' in /var/www/sitename/vendor/yiisoft/yii2/db/Connection.php:558
Stack trace:
#0 /var/www/sitename/vendor/yiisoft/yii2/db/Connection.php(0): PDO->__construct()
#1 /var/www/sitename/vendor/yiisoft/yii2/db/Connection.php(508): yii\db\Connection->createPdoInstance()
#2 /var/www/sitename/yiisoft/yii2-sphinx/Connection.php(112): yii\db\Connection->open()
#3 /var/www/sitename/yiisoft/yii2-sphinx/Schema.php(255): yii\sphinx\Connection->createCommand('SHOW TABLES')
#4 /var/www/sitename/vendor/yiisoft/yii2-sphinx/Schema.php(239): yii\sphinx\Schema->findIndexes()
#5 /var/www/sitename/vendor/yiisoft/yii2-sphinx/Schema.php(226): yii\sphinx\Schema->initIndexesInfo()
#6 /var/www/sitename/vendor/yiisoft/yii2-sphinx/Schema.php(113): yii\sphinx\Schema->getIndexTypes()
#7 /var/www/sitename/vendor/yiisoft/yii2-sphinx/Schema.php(88): yii\sphinx\Schema->resolveIndexType(Object(yii\sphinx\IndexSchema))
#8 /var/www/sitename/vendor/yiisoft/yii2-sphinx/Schema.php(151): yii\sphinx\Schema->loadIndexSchema('sitename')
#9 /var/www/sitename/vendor/yiisoft/yii2-sphinx/Connection.php(78): yii\sphinx\Schema->getIndexSchema('sitename', false)
#10 /var/www/sitename/vendor/yiisoft/yii2-sphinx/QueryBuilder.php(494): yii\sphinx\Connection->getIndexSchema('sitename')
#11 /var/www/sitename/vendor/yiisoft/yii2-sphinx/QueryBuilder.php(81): yii\sphinx\QueryBuilder->buildWhere(Array, 'MATCH(:qp0)', Array)
#12 /var/www/sitename/vendor/yiisoft/yii2-sphinx/Query.php(171): yii\sphinx\QueryBuilder->build(Object(yii\sphinx\Query))
#13 /var/www/sitename/vendor/yiisoft/yii2-sphinx/Query.php(184): yii\sphinx\Query->createCommand(NULL)
#14 /var/www/sitename/common/actions/SphinxSearchAction.php(78): yii\sphinx\Query->all()
#15 [internal function]: common\actions\SphinxSearchAction->run()
#16 /var/www/sitename/vendor/yiisoft/yii2/base/Action.php(91): call_user_func_array(Array, Array)
#17 /var/www/sitename/vendor/yiisoft/yii2/base/Controller.php(147): yii\base\Action->runWithParams(Array)
#18 /var/www/sitename/vendor/yiisoft/yii2/base/Module.php(460): yii\base\Controller->runAction('search', Array)
#19 /var/www/sitename/vendor/yiisoft/yii2/web/Application.php(82): yii\base\Module->runAction('site/search', Array)
#20 /var/www/sitename/vendor/yiisoft/yii2/base/Application.php(369): yii\web\Application->handleRequest(Object(yii\web\Request))
#21 /var/www/sitename/frontend/web/index.php(18): yii\base\Application->run()
#22 {main}

Next exception 'yii\db\Exception' with message 'SQLSTATE[HY000] [2006] MySQL server has gone away' in /var/www/sitename/vendor/yiisoft/yii2/db/Connection.php:513
Stack trace:
#0 /var/www/sitename/vendor/yiisoft/yii2-sphinx/Connection.php(112): yii\db\Connection->open()
#1 /var/www/sitename/vendor/yiisoft/yii2-sphinx/Schema.php(255): yii\sphinx\Connection->createCommand('SHOW TABLES')
#2 /var/www/sitename/vendor/yiisoft/yii2-sphinx/Schema.php(239): yii\sphinx\Schema->findIndexes()
#3 /var/www/sitename/vendor/yiisoft/yii2-sphinx/Schema.php(226): yii\sphinx\Schema->initIndexesInfo()
#4 /var/www/sitename/vendor/yiisoft/yii2-sphinx/Schema.php(113): yii\sphinx\Schema->getIndexTypes()
#5 /var/www/sitename/vendor/yiisoft/yii2-sphinx/Schema.php(88): yii\sphinx\Schema->resolveIndexType(Object(yii\sphinx\IndexSchema))
#6 /var/www/sitename/vendor/yiisoft/yii2-sphinx/Schema.php(151): yii\sphinx\Schema->loadIndexSchema('sitename')
#7 /var/www/sitename/vendor/yiisoft/yii2-sphinx/Connection.php(78): yii\sphinx\Schema->getIndexSchema('sitename', false)
#8 /var/www/sitename/vendor/yiisoft/yii2-sphinx/QueryBuilder.php(494): yii\sphinx\Connection->getIndexSchema('sitename')
#9 /var/www/sitename/vendor/yiisoft/yii2-sphinx/QueryBuilder.php(81): yii\sphinx\QueryBuilder->buildWhere(Array, 'MATCH(:qp0)', Array)
#10 /var/www/sitename/vendor/yiisoft/yii2-sphinx/Query.php(171): yii\sphinx\QueryBuilder->build(Object(yii\sphinx\Query))
#11 /var/www/sitename/vendor/yiisoft/yii2-sphinx/Query.php(184): yii\sphinx\Query->createCommand(NULL)
#12 /var/www/sitename/common/actions/SphinxSearchAction.php(78): yii\sphinx\Query->all()
#13 [internal function]: common\actions\SphinxSearchAction->run()
#14 /var/www/sitename/vendor/yiisoft/yii2/base/Action.php(91): call_user_func_array(Array, Array)
#15 /var/www/sitename/vendor/yiisoft/yii2/base/Controller.php(147): yii\base\Action->runWithParams(Array)
#16 /var/www/sitename/vendor/yiisoft/yii2/base/Module.php(460): yii\base\Controller->runAction('search', Array)
#17 /var/www/sitename/vendor/yiisoft/yii2/web/Application.php(82): yii\base\Module->runAction('site/search', Array)
#18 /var/www/sitename/vendor/yiisoft/yii2/base/Application.php(369): yii\web\Application->handleRequest(Object(yii\web\Request))
#19 /var/www/sitename/frontend/web/index.php(18): yii\base\Application->run()
#20 {main}

yii2中的Sphinx连接设置

<?php
return [
    'dsn' => 'mysql:host=127.0.0.1;port=3313;',
    'username' => 'username',
    'password' => 'password',
];

yii2中执行查询的代码

$query = (new Query())
        ->from('sourceName')
        ->match('*'.Yii::$app->request->get('q').'*');
$rows = $query->all();

其他服务器信息:

  • Ubuntu 15.04
  • Linux 3.19.0-21-generic x86_64
  • Sphinx 2.2.9-id64-release(rel22-r5006)
  • MySQL 10.0.20-MariaDB-1~ vivid-log

可能是什么问题?

我很乐意得到任何帮助。谢谢!

1 个答案:

答案 0 :(得分:2)

  

listen = 127.0.0.1:3313

检查您正在使用API​​协议监听的listen的文档,而不是MySQL兼容的文档: - )