Php Can';t从Docker应用程序连接到Sphinx(全文搜索)
我有一个项目在docker容器中运行,如下所示:Php Can';t从Docker应用程序连接到Sphinx(全文搜索),php,laravel,sphinx,Php,Laravel,Sphinx,我有一个项目在docker容器中运行,如下所示: $ docker-compose up -d nginx mysql redis workspace source tablename { type = mysql sql_host = mysql sql_user = user sql_pass = pass sql_db = database_name sql_
$ docker-compose up -d nginx mysql redis workspace
source tablename
{
type = mysql
sql_host = mysql
sql_user = user
sql_pass = pass
sql_db = database_name
sql_port = 3306
sql_query = SELECT id, name FROM tablename
sql_attr_uint = id
}
index tablename
{
source = tablename
path = /var/lib/sphinxsearch/data/tablename
min_prefix_len = 2
morphology = stem_en
}
searchd
{
listen = 127.0.0.1:9312
log = /var/log/sphinxsearch/searchd.log
query_log = /var/log/sphinxsearch/query.log
query_log_format = sphinxql
pid_file = /var/run/searchd.pid
}
码头工人运转良好(所有集装箱都已装好)
我现在正试图将Sphinx全文搜索集成到工作区容器中。
我的/etc/sphinxsearch/sphinx.conf文件设置如下:
$ docker-compose up -d nginx mysql redis workspace
source tablename
{
type = mysql
sql_host = mysql
sql_user = user
sql_pass = pass
sql_db = database_name
sql_port = 3306
sql_query = SELECT id, name FROM tablename
sql_attr_uint = id
}
index tablename
{
source = tablename
path = /var/lib/sphinxsearch/data/tablename
min_prefix_len = 2
morphology = stem_en
}
searchd
{
listen = 127.0.0.1:9312
log = /var/log/sphinxsearch/searchd.log
query_log = /var/log/sphinxsearch/query.log
query_log_format = sphinxql
pid_file = /var/run/searchd.pid
}
我已经按如下方式运行了索引器,看起来还不错:
root@1ec9add2d1dc:/etc/sphinxsearch# /usr/bin/indexer tablename
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 '/etc/sphinxsearch/sphinx.conf'...
indexing index 'tablename'...
WARNING: index 'tablename': dict=keywords and prefixes and morphology enabled, forcing index_exact_words=1
WARNING: attribute 'id' not found - IGNORING
WARNING: Attribute count is 0: switching to none docinfo
collected 17 docs, 0.0 MB
sorted 0.0 Mhits, 100.0% done
total 17 docs, 171 bytes
total 0.322 sec, 529 bytes/sec, 52.68 docs/sec
total 3 reads, 0.000 sec, 0.3 kb/call avg, 0.0 msec/call avg
total 9 writes, 0.000 sec, 0.2 kb/call avg, 0.0 msec/call avg
随后对/usr/bin/searchd-rotate的调用也在修补索引。
我还在工作区容器中运行了searchd:
root@1ec9add2d1dc:/etc/sphinxsearch# /usr/bin/searchd
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 '/etc/sphinxsearch/sphinx.conf'...
listening on 127.0.0.1:9312
但我似乎无法从应用程序连接到这个。
示例代码:
$query = 'keyword';
$sphinx = new SphinxClient();
$sphinx->setServer('127.0.0.1', 9312);
$sphinx->setMatchMode(SPH_MATCH_ALL);
$sphinx->addQuery($query, 'tablename');
$sphinx->setLimits(0, 10);
$result = $sphinx->runQueries();
但是$result始终为false,并出现以下错误:
SPHINX Query failed: connection to 127.0.0.1:9312 failed (errno=111, msg=Connection refused)
bool(false)
我还尝试将.conf和setServer()更改为使用'localhost','127.0.0.1','mysql'(sql容器名称),但实际上没有任何东西从应用程序代码连接到sphinx
问题:
我是不是遗漏了什么?
连接到sphinx并检索实际索引数据还需要哪些其他步骤?
非常感谢您的帮助
在Mac OSX上运行Docker Desktop, Ubuntu容器
PHP7.2,“gigablah/sphinxphp”:“^2.0.8”,“laravel/framework”:“^6.4.0”,应用程序是否在同一容器中运行?还是一个单独的容器?“尝试将Sphinx全文搜索集成到工作区容器”。如果运行docker gigablah/sphinxphp并公开9312,脚本是否在外部工作?您还可以从容器内部远程登录到端口吗?