2017-05-25 145 views
3

寫入redis羣集時遇到問題。StackExchange.Redis - 寫入到redis羣集指向本地IP地址

有了這個作爲配置:

static readonly IEnumerable<EndPoint> Endpoints = new[] 
{ 
    EndPointCollection.TryParse("10.5.2.146:7000"), 
    EndPointCollection.TryParse("10.5.2.146:7001"), 
    EndPointCollection.TryParse("10.5.2.146:7002"), 
}; 

public static ConnectionMultiplexer Build() 
{ 
    var opt = new ConfigurationOptions { AllowAdmin = true }; 

    foreach (var endpoint in Endpoints) 
     opt.EndPoints.Add(endpoint); 

    Redis = ConnectionMultiplexer.Connect(opt); 
    FlushAllDatabases(); 
    return Redis; 
} 

,並使用它像這樣:

var redis = RedisConfig.Build(); 
redis.GetDatabase().StringSet("foo", "bar"); 
redis.GetDatabase().StringGet("foo"); 

返回此異常:

StackExchange.Redis.RedisServerException: 'Endpoint 127.0.0.1:7002 serving hashslot 12182 is not reachable at this point of time. Please check connectTimeout value. If it is low, try increasing it to give the ConnectionMultiplexer a chance to recover from the network disconnect. IOCP: (Busy=1,Free=999,Min=4,Max=1000), WORKER: (Busy=0,Free=2047,Min=4,Max=2047), Local-CPU: n/a' 

我認爲問題在於:var endpoints = redis.GetEndPoints();同時返回使用公共IP和羣集發現的端點配置端點(請參閱圖像)檢查變量)與本地IP,然後使用私有IP的節點檢索哈希時隙。

image

還有什麼我應該設置在配置或使用客戶端什麼錯?

目前使用的配置,每個節點都有它的文件夾.\700X與它自己的conf文件和日誌:

redis.conf (for first node) 
    port 7000 
    cluster-enabled yes 
    cluster-config-file nodes.conf 
    cluster-node-timeout 5000 
    appendonly yes 
    logfile 7000.log 
    protected-mode no 
    bind 0.0.0.0 

nodes.conf 
    0c213c727e90710bbd94d5094da2c6749872f74f 127.0.0.1:7001 master - 0 1494253090995 2 connected 5461-10922 
    2e6d24ccec03d1ca674b936eac0e48dc6a97c405 127.0.0.1:7000 myself,master - 0 0 1 connected 0-5460 
    7467c908c390bb6db202836fdff2966e4f100858 127.0.0.1:7007 slave bdd5c046e2a05b289ef0aba47a9987988defc799 0 1494253090889 8 connected 
    bbb2d02845e57622b5e95574ab843d9cefd0b28a 127.0.0.1:7006 slave 0c213c727e90710bbd94d5094da2c6749872f74f 0 1494253090890 7 connected 
    bdd5c046e2a05b289ef0aba47a9987988defc799 127.0.0.1:7002 master - 0 1494253092195 3 connected 10923-16383 
    c39aa6ff1e9823a169b758fc5aed2f5e811a971a 127.0.0.1:7008 slave bdd5c046e2a05b289ef0aba47a9987988defc799 0 1494253091700 9 connected 
    673d0af38625ae962f6ed7f527cc5162a08d7f21 127.0.0.1:7003 slave 2e6d24ccec03d1ca674b936eac0e48dc6a97c405 0 1494253091191 4 connected 
    ed1e5ba7a0a569e2d4b8542bf8a8353d33e81384 127.0.0.1:7004 slave 2e6d24ccec03d1ca674b936eac0e48dc6a97c405 0 1494253090889 5 connected 
    a4d29951bcf70593d14fbee5438608c88c971922 127.0.0.1:7005 slave 0c213c727e90710bbd94d5094da2c6749872f74f 0 1494253091722 6 connected 
    vars currentEpoch 9 lastVoteEpoch 0 
+0

請出示集羣 – Solo

+0

@MallowFox一個node.conf文件現在添加了redis.conf和nodes.conf –

回答

2

我測試了jedis場景,而這個問題也存在:公共和私有IP可以同時存在時,連接到redis羣集。

爲了解決這個問題,在設置集羣時使用public ip,並確保public ips位於每個node.conf配置文件中。如果在node.conf中寫入「127.0.0.1」,並連接到「10.5.2.146:7000」,則這兩個ips都存在。在Redis的-CLI集羣是否滿足3的公網IP,像

cluster meet 10.5.2.146 7000 
cluster meet 10.5.2.146 7001 
cluster meet 10.5.2.146 7002 
+0

'cluster meet'解決了這個問題。 閱讀'CLUSTER MEET'的文檔([link](https://redis.io/commands/cluster-meet))我已經過去了:_基本思想是,默認情況下節點不相信每個其他,並且被認爲是未知的,因此,由於系統管理錯誤或網絡地址修改,不同羣集節點不太可能混合成單個節點_ –

1

我有同樣的問題還有:

和快速的方式,在這種情況解決這個問題。還有另一種方法可以確保ip以您需要的方式發佈,在配置文件中有一部分是針對NAT地址的。我的回答的唯一問題,以及以前的答案是你需要知道正確的IP地址,它應該是靜態的......

cluster-announce-ip