2016-09-15 15 views
0

私の環境: 私は3つのUbuntuサーバーを持っています。 1台のサーバーがNginxを使用するロードバランサとして使用されます。 他の2つのサーバーには、まったく同じプロジェクトが含まれています(1つのボックスがマスターで、もう1つがスレーブである場合は赤とは異なります)。 Celeryを使用して書き込むときにRedisClusterExceptionが発生する

私は パイソン、 Gunicorn、 ジャンゴ、 セロリ、 のRedis、 センチネルを使用しているプログラム/アプリケーション

私のプロジェクトは何: は私が取り込んでURLを持っていますリクエストに関するいくつかのロジックを行い、レディスに保存します。

def save(key, value): 
    conn = redis_cluster_connect() 
    print conn 
    conn.set(key, value) 
    conn.set('bar','foo') 

私の接続だったときにこれが正常に動作した

def redis_connect(): 
    print 'redis connected' 
    return redis.Redis(host="xxx.xx.xxx.x", port=6380, db=1) # CHANGE TO THE REDIS PORT THAT IS ACTIVE 

しかし、私はクラスタ接続を使用します。私は取得

def redis_cluster_connect(): 
    startup_nodes = [{"host": "xxx.xx.xxx.x", "port": "6380"}] 
    rc = StrictRedisCluster(startup_nodes=startup_nodes, decode_responses=True) 

return rc 

をエラー:

[2016-09-15 13:28:59,682: INFO/MainProcess] Received task: testapp.tasks.mobilise_stops[cc64c425-bd37-4896-b6ab-4319de5fb743] 
    [2016-09-15 13:28:59,684: WARNING/Worker-1] Oh no! Task failed: RedisClusterException("ERROR sending 'cluster slots' command to redis server: {'host': 'xxx.xx.xxx.x', 'port': '6380'}",) 
    [2016-09-15 13:28:59,685: ERROR/MainProcess] Task testapp.tasks.mobilise_stops[cc64c425-bd37-4896-b6ab-4319de5fb743] raised unexpected: RedisClusterException("ERROR sending 'cluster slots' command to redis server: {'host': 'xxx.xx.xxx.x', 'port': '6380'}",) 
    Traceback (most recent call last): 
     File "/usr/local/lib/python2.7/dist-packages/celery/app/trace.py", line 240, in trace_task 
     R = retval = fun(*args, **kwargs) 
     File "/usr/local/lib/python2.7/dist-packages/celery/app/trace.py", line 438, in __protected_call__ 
     return self.run(*args, **kwargs) 
     File "/var/www/gateway/venv/gateway/testapp/tasks.py", line 50, in mobilise_stops 
     save(mobilise_stops.request.id, 'Success') 
     File "/var/www/gateway/venv/gateway/testapp/tasks.py", line 28, in save 
     conn = redis_cluster_connect() 
     File "/var/www/gateway/venv/gateway/testapp/tasks.py", line 19, in redis_cluster_connect 
     rc = StrictRedisCluster(startup_nodes=startup_nodes, decode_responses=True) 
     File "/usr/local/lib/python2.7/dist-packages/rediscluster/client.py", line 157, in __init__ 
     **kwargs 
     File "/usr/local/lib/python2.7/dist-packages/rediscluster/connection.py", line 83, in __init__ 
     self.nodes.initialize() 
     File "/usr/local/lib/python2.7/dist-packages/rediscluster/nodemanager.py", line 148, in initialize 
     raise RedisClusterException("ERROR sending 'cluster slots' command to redis server: {0}".format(node)) 
    RedisClusterException: ERROR sending 'cluster slots' command to redis server: {'host': 'xxx.xx.xxx.x', 'port': '6380'} 

私はRedisの-CLIを実行し、(サーバー1上)マスターに変数を設定すると、私は(サーバ2上)スレーブ上でそれを取得することができます

server 1: 
xxx.xx.xxx.x:6380> set test 100 
OK 

server 2: 
xxx.xx.xxx.x:6381> get test 
"100" 

私はスロットはRedisのクライアントでコマンドクラスタをやってみてください私は上記と同じエラーが発生します。考慮すべき

xxx.xx.xxx.x:6380> cluster slots 
(error) ERR unknown command 'cluster' 

ことの一つは、私は動作しませんTCPのRedisのを使用しようとしたとき、私のRedisの設定ファイルは、TCPソケットを持っていないです。私はredisを実行しようとしたときにエラーが発生しました。あなたはRedisのクラスタを実行しているので、実行しようとしていない

unixsocket /var/run/redis/redis.sock 
unixsocketperm 700 

答えて

0

:へ

tcp-backlog 511 

:これはからは、デフォルトのredis.confファイル

で来るデフォルトUnixsocketに変更されましたredis-clusterのみのコマンドは失敗します。

+0

ありがとう、私はマスタースレーブとレディスクラスターの間で混乱していました。解明してくれてありがとう! – Jahedh

0

私の場合、バージョン1.3.1に再インストールした後、問題はバージョンredis-py-cluster(1.3.4)にありました。私はいくつかのPythonパッケージのバージョンの問題があったと思う。

関連する問題