2017-10-13 122 views
0

我有兩個相同的服務器(A和B)通過Lsyncd同步。主服務器A使用配置了apache,Redis和RDS的Magento 1.9.1 CE並使用FPC。我已經配置了自定義管理員網址,其中A爲管理員,B爲前臺。由於B對redis配置進行了輕微修改,因此我已同步除var和app/etc/local.xml之外的所有目錄。Magento管理員/前分割服務器Redis錯誤

B連接到A的redis實例。 Redis配置爲後端緩存和會話存儲。 我測試了禁用緩存管理中的所有緩存類型,它運行良好,但是當我啓用它們時,它在B中給出了redis錯誤。我禁用了'配置'緩存類型,錯誤消失了。

這是神祕的東西;如果我啓用'Configuration'緩存類型,然後在redis中執行'flushall';以及哪個服務器A或B先裝入並創建後端緩存鍵,另一個則出現此錯誤。 可以說,如果A先加載然後B有redis錯誤。如果在Redis中完成flushall並且B先加載,那麼A有redis錯誤。

我似乎無法弄清楚什麼是錯的。 這裏是我的Redis配置:

 <session_save>db</session_save> 
    <cache> 
     <backend>Mage_Cache_Backend_Redis</backend> 
     <backend_options> 
      <server>127.0.0.1</server> 
      <port>6379</port> 
      <database>0</database> 
      <password>SOME_PASSWORD</password> 
      <force_standalone>0</force_standalone> <!-- 0 for phpredis, 1 for standalone PHP --> 
      <connect_retries>3</connect_retries> <!-- Reduces errors due to random connection failures --> 
      <automatic_cleaning_factor>0</automatic_cleaning_factor> <!-- Disabled by default --> 
      <compress_data>1</compress_data> <!-- 0-9 for compression level, recommended: 0 or 1 --> 
      <compress_tags>1</compress_tags> <!-- 0-9 for compression level, recommended: 0 or 1 --> 
      <compress_threshold>20480</compress_threshold> <!-- Strings below this size will not be compressed --> 
      <compression_lib>gzip</compression_lib> <!-- Supports gzip, lzf and snappy --> 
      <persistent>1</persistent> <!-- persistence value, 0: not in use, > 0 used as persistence ID --> 
     </backend_options> 
    </cache> 
    <redis_session>      <!-- All options seen here are the defaults --> 
     <host>127.0.0.1</host> 
     <port>6379</port> 
     <password>SOME_PASSWORD</password>   <!-- Specify if your Redis server requires authentication --> 
     <timeout>2.5</timeout>   <!-- This is the Redis connection timeout, not the locking timeout --> 
     <persistent></persistent>   <!-- Specify unique string to enable persistent connections. E.g.: sess-db0; bugs with phpredis and php-fpm are known: https://github.com/nicolasff/phpredis/issues/70 --> 
     <db>1</db>      <!-- Redis database number; protection from accidental loss is improved by using a unique DB number for sessions --> 
     <compression_threshold>2048</compression_threshold> <!-- Set to 0 to disable compression (recommended when suhosin.session.encrypt=on); known bug with strings over 64k: https://github.com/colinmollenhour/Cm_Cache_Backend_Redis/issues/18 --> 
     <compression_lib>gzip</compression_lib>    <!-- gzip, lzf or snappy --> 
     <log_level>4</log_level>    <!-- 0 (emergency: system is unusable), 4 (warning; additional information, recommended), 5 (notice: normal but significant condition), 6 (info: informational messages), 7 (debug: the most information for development/testing) --> 
     <max_concurrency>6</max_concurrency>     <!-- maximum number of processes that can wait for a lock on one session; for large production clusters, set this to at least 10% of the number of PHP processes --> 
     <break_after_frontend>5</break_after_frontend>  <!-- seconds to wait for a session lock in the frontend; not as critical as admin --> 
     <break_after_adminhtml>30</break_after_adminhtml> 
     <bot_lifetime>7200</bot_lifetime>     <!-- Bots get shorter session lifetimes. 0 to disable --> 
    </redis_session> 

的問題是與後端緩存即數據庫0 它似乎沒有不同的URL之間共享。

Redis的錯誤是: Redis error

但是,如果B的local.xml中我使用單獨的數據庫可以說2後端緩存比它沒有任何問題。我想爲A和B使用相同的後端緩存數據庫。誰能幫我理解這裏發生了什麼?

謝謝!

回答

0

我發現了一個解決方法,解決方案似乎有道理。我在兩臺服務器上創建了相同的local.xml文件。在服務器A中的local.xml文件中,我配置了redis來連接到它的私有IP,而不是它的本地IP 127.0.0.1,用於緩存和會話。由於B需要連接到A中的redis實例,因此配置相同。然後我做了flushall redis,它工作。 我認爲Magento將配置存儲在數據庫中。因此,在緩存管理中啓用緩存類型「配置」似乎會給前端服務器B帶來錯誤,因爲當A首先加載之前爲127.0.0.1的主機名已保存在導致服務器B出現redis連接錯誤的數據庫中時,因爲它試圖連接而不是遠程服務器A.(redis服務在B中停止)

我做了一些研究,發現它確實如此。這篇文章有助於點燃思維過程。

How can I disable the cache via the database?

這與本地數據庫中的相同。所以我使用了RDS,但沒有意識到這是與主機名不一致的問題。