0

我好像遇到了一些我不明白的问题...

我已经安装了 MySQL 8.0.27 我已经安装了 Sphinx,创建了一个索引,填充了它,通过终端一切正常。我能够毫无问题地查询 Spinx 索引。所以 searchd 和索引器正在做他们的工作。

我创建了一个简单的 PHP 界面来使用 PHP 搜索这个索引。但这就是事情变得越来越奇怪的地方......

我无法连接到 sphinx 实例(它确实通过终端工作..)--> SQLSTATE[HY000] [2002] 权限被拒绝

我的 sphinx.conf

source page
{
        type = mysql

        sql_host = localhost
        sql_db   = db
        sql_user = user
        sql_pass = password
        sql_port = 3306

        sql_query = SELECT p.id, p.parent_id, p.date_add, p.version, p.content, p.pagenumber, p.status, pp.filename, pp.pages  FROM page p LEFT JOIN parent_page pp ON p.parent_id=pp.id

        sql_field_string = content
}

index pagedata
{
        source = wob
        path = /etc/sphinx/data/page
        morphology = none

        min_word_len = 2
        min_prefix_len = 0
}

searchd
{
    listen = 9312
    listen = 9306:mysql41
    log = /var/log/sphinx/searchd.log
    query_log = /var/log/sphinx/query.log

    read_timeout = 5
    max_children = 30
        pid_file                = /etc/sphinx/sphinx-searchd.pid
        seamless_rotate         = 1
        preopen_indexes         = 1
        unlink_old              = 1
        workers                 = threads # for RT to work
        binlog_path             = /var/log/sphinx/
}

这是狮身人面像状态

Sphinx 3.3.1 (commit b72d67b)
Copyright (c) 2001-2020, Andrew Aksyonoff
Copyright (c) 2008-2016, Sphinx Technologies Inc (http://sphinxsearch.com)

using config file '/etc/sphinx/etc/sphinx.conf'...

searchd status
--------------
uptime: 4419 
connections: 6 
maxed_out: 0 
command_search: 3 
command_snippet: 0 
command_update: 0 
command_delete: 0 
command_keywords: 0 
command_persist: 0 
command_status: 3 
command_flushattrs: 0 
agent_connect: 0 
agent_retry: 0 
queries: 2 
dist_queries: 0 
query_wall: 0.009 
query_cpu: OFF 
dist_wall: 0.000 
dist_local: 0.000 
dist_wait: 0.000 
query_reads: OFF 
query_readkb: OFF 
query_readtime: OFF 
avg_query_wall: 0.005 
avg_query_cpu: OFF 
avg_dist_wall: 0.000 
avg_dist_local: 0.000 
avg_dist_wait: 0.000 
avg_query_reads: OFF 
avg_query_readkb: OFF 
avg_query_readtime: OFF 
qcache_cached_queries: 0 
qcache_used_bytes: 0 
qcache_hits: 0 
sql_parse_error: 2 
sql_dummy: 1 
sql_select: 3 
sql_select_sysvar: 2 

这是我用来从我的 PHP 脚本连接到 Sphinx 的代码......这导致了这篇文章顶部提到的错误......

<?php
try {
    $pdo = new PDO("mysql:host=localhost:9306");
    // set the PDO error mode to exception
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $pdo->exec('SET NAMES utf8');
} catch (PDOException $e) {
    echo "Connection failed to API database: " . $e->getMessage();
}

通过终端连接没有问题,查询工作正常且快速......

[root@web03 bin]# mysql -h0 -P9306
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 3.3.1 (commit b72d67b) 

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

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

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

mysql> 

它在 $pdo = new PDO() 部分失败。无法建立连接。我尝试将 localhost 替换为 127.0.0.1,尝试将端口替换为 9312(请参阅配置)以及它们之间的所有组合。没有骰子。

有人有线索或提示吗?它快把我逼疯了……

4

1 回答 1

1

刚刚安装了 Manticore Search 4.2,它有完全相同的问题......所以这让我思考。

原来是因为 SELinux……这篇文章为我提供了解决方案。所以它与 Sphinx 或 Manticore 搜索无关......这是我的 SELinux 设置阻止我从 http 用户建立数据库连接。

答案有 4 个简单的步骤可以永久允许,一切都像魅力一样!

于 2022-02-17T15:14:49.890 回答