简体   繁体   中英

Cannot connect to mysql via sphinx-specific port

I am trying to set up sphinx search engine on the server.

On the server already is another sphinx search daemon, that running from another user for another site with another config file (port 3312).

Here is my sphinx config file /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
}

I got to start 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

And I got to start indexing

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).

But I can not connect to the database, either from the command line or from php (I use yii2, for connection to sphinx use yii2-sphinx).

When I try to connect to mysql from the command line, an error occurs:

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)"

When I try to run a query from the site occurs several errors:

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}

Sphinx connection settings in yii2

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

The code in yii2 to execute the query

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

Additional server information:

  • 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

What could be the problem?

I would be glad of any assistance. Thanks!

listen = 127.0.0.1:3313

Check documentation for listen you are listening with API protocol, not the MySQL compatible one :-)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM