歡迎您光臨本站 註冊首頁

A主機apache訪問B主機mysql+sphinx遇到的麻煩,請大家分析一下[新手]

這幾天在部署sphinx,但是遇到了意外的問題,希望有類似經驗的給點提示~

    基本狀況:
               1.A主機:www伺服器(apache),B主機:數據伺服器(mysql+sphinx);

               2.mysql的數據連接,以及取sphinx相關索引都能連接成功;

               3.當A主機上面的頁面連接請求B主機上面的sphinx的索引數據的時候,出錯率在20%左右(我用有無返回數據來判斷,詳細見代碼)。

                 為了說明是不是數據源的問題(mysql+sphinx),我還在c主機上放了同樣的代碼,獲取數據無錯誤。

              4.考慮到數據獲取埠因素, 我在A主機上做了一個簡單測試:讓A主機的一個頁面通過url去讀取B主機上面的一個頁面,看返回值的情況。這個測試同樣也出錯,錯誤率也在20%左右。
                 
                 期間我曾懷疑過伺服器的處理能力,導致處理數據超時,然後數據包被扔掉等等。但是cpu的使用率是很低的,內存使用率在90%左右(為了減少磁碟IO),伺服器A的下行流量也只有2.4Mb/s。
                 沒有數據能直接說明是內存和下行流量的原因,看起來似乎是這兩個主機的網路連接有問題,但是很快就被下面的測試否定了
               
              5.剛才還做了一個A主機取B主機mysql數據的測試,這個沒任何問題。同時A ping B,B ping A 都沒loss
    到目前為止沒找到原因,感覺要失去方向了,請大家幫幫忙~給點啟發什麼的
    如果我沒說清楚的或者不專業的地方請見諒,今天一直在線。

<?php
//A主機上請求B主機sphinx索引數據測試代碼

error_reporting(E_ALL);
ini_set("display_errors",1);
include_once("inc/sphinxapi.php");

$cl = new SphinxClient ();

$cl->SetServer('B-host',3312);
$cl->SetMatchMode(SPH_MATCH_ALL);

$cl->SetLimits(0,50);
$res = $cl->Query ( "Getting Bigger and Better", "main" );
if(is_array($res)){
    $out="OK";
}else{
    $out="Error";
}
$handle = fopen('_manage_/orders/sphinx_log.html','a');
$now = date("h:i:s");
fwrite($handle,"<br><br>".$now."---------------------".$out);
fclose($handle);
echo '<html><head><meta http-equiv="refresh" content="10;URL=/test.php></head></html>';

?>



<?php
//A主機上通過url讀取B主機一個頁面的測試代碼

error_reporting(E_ALL);
ini_set("display_errors",1);
$a = file_get_contents("http://www.****.com/test/postinfo.html");
if(strpos($a,"The HTML comments in this page contain the configurationinformation")){
    $out="OK";   
}else{
    $out="Error";
}
$handle = fopen('_manage_/orders/13112_log.html','a');
$now = date("h:i:s");
fwrite($handle,"<br><br>".$now."---------------------".$out);
fclose($handle);
echo '<html><head><meta http-equiv="refresh" content="5;URL=test44.php></head></html>';
?>


<?php
//放在A主機上的請求B主機mysql數據的測試代碼

error_reporting(E_ALL);
ini_set("display_errors",1);
    $db_user="";
    $db_pass="";
    $db_name="";
    $db_host="";
    mysql_connect($db_host,$db_user,$db_pass);
    mysql_select_db($db_name);
    $query = "SELECT * FROM table limit 10";
    $result = mysql_query($query);
    while($array=mysql_fetch_array($result)){
        $out_array[]=$array;   
    }
if(count($out_array)>5){
    $out="OK";   
}else{
    $out="Error";
}
$handle = fopen('_manage_/orders/db_log.html','a');
$now = date("h:i:s");
fwrite($handle,"<br><br>".$now."---------------------".$out);
fclose($handle);
echo '<html><head><meta http-equiv="refresh" content="5;URL=test77.php></head></html>';
?>
《解決方案》

問題已經解決,謝謝Hellex 幫助
《解決方案》

《解決方案》

hosts沒有做好配置,他的另外一貼這麼解決了。

[火星人 ] A主機apache訪問B主機mysql+sphinx遇到的麻煩,請大家分析一下[新手]已經有474次圍觀

http://coctec.com/docs/service/show-post-18555.html