我已经配置了一个redis sentinel组(1个主服务器和2个具有自动故障转移功能的服务器),连接都很好,Sentinel故障转移工作正常,但是从应用程序连接时会抛出以下错误:
Request Method: GET
Request URL: https://node-app/leaderboard/5790778dd4a8db6171625910/
Django Version: 1.9.9
Python Version: 2.7.6
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_mongoengine',
'django_mongoengine.mongo_auth',
'django_mongoengine.mongo_admin.sites',
'django_mongoengine.mongo_admin',
'mongonaut',
'rest_framework',
'rest_framework_swagger',
'rest_framework_mongoengine',
'rest_framework.authtoken',
'social.apps.django_app.me',
'rest_social_auth',
'django_s3_storage',
'mongoengine',
'corsheaders',
'seacucumber',
'djcelery',
'src',
'oauth2_provider',
'rest_framework_social_oauth2']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'social.apps.django_app.middleware.SocialAuthExceptionMiddleware']
Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
149. response = self.process_exception_by_middleware(e, request)
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
147. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/views/decorators/csrf.py" in wrapped_view
58. return view_func(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/views/generic/base.py" in view
68. return self.dispatch(request, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/rest_framework/views.py" in dispatch
466. response = self.handle_exception(exc)
File "/usr/local/lib/python2.7/dist-packages/rest_framework/views.py" in dispatch
463. response = handler(request, *args, **kwargs)
File "./src/apps/users/views/rankview.py" in get
16. ranks, status = RankClass.retrieve_rank(id)
File "./src/apps/users/libraries/ranklib.py" in retrieve_rank
132. ranks[name][TOP] = leaderboard.top(TOPRANKUPTO, with_member_data=True)
File "/usr/local/lib/python2.7/dist-packages/leaderboard/leaderboard.py" in top
890. return self.top_in(self.leaderboard_name, number, **options)
File "/usr/local/lib/python2.7/dist-packages/leaderboard/leaderboard.py" in top_in
903. return self.members_from_rank_range_in(leaderboard_name, 1, number, **options)
File "/usr/local/lib/python2.7/dist-packages/leaderboard/leaderboard.py" in members_from_rank_range_in
861. if ending_rank > self.total_members_in(leaderboard_name):
File "/usr/local/lib/python2.7/dist-packages/leaderboard/leaderboard.py" in total_members_in
323. return self.redis_connection.zcard(leaderboard_name)
File "/usr/local/lib/python2.7/dist-packages/redis/client.py" in zcard
1595. return self.execute_command('ZCARD', name)
File "/usr/local/lib/python2.7/dist-packages/redis/client.py" in execute_command
578. connection.send_command(*args)
File "/usr/local/lib/python2.7/dist-packages/redis/connection.py" in send_command
563. self.send_packed_command(self.pack_command(*args))
File "/usr/local/lib/python2.7/dist-packages/redis/connection.py" in send_packed_command
538. self.connect()
File "/usr/local/lib/python2.7/dist-packages/redis/connection.py" in connect
446. self.on_connect()
File "/usr/local/lib/python2.7/dist-packages/redis/connection.py" in on_connect
514. if nativestr(self.read_response()) != 'OK':
File "/usr/local/lib/python2.7/dist-packages/redis/connection.py" in read_response
577. response = self._parser.read_response()
File "/usr/local/lib/python2.7/dist-packages/redis/connection.py" in read_response
238. response = self._buffer.readline()
File "/usr/local/lib/python2.7/dist-packages/redis/connection.py" in readline
168. self._read_from_socket()
File "/usr/local/lib/python2.7/dist-packages/redis/connection.py" in _read_from_socket
143. (e.args,))
Exception Type: ConnectionError at /leaderboard/5790778dd4a8db6171625910/
Exception Value: Error while reading from socket: ('Connection closed by server.',)
我按照以下文档进行了haproxy-redis-sentinel设置:https://discuss.zendesk.com/hc/en-us/articles/205309388-How-to-setup-HAProxy-and-Redis-Sentinel-for-automatic-failover-between-Redis-Master-and-Slave-servers
我可以使用redis-cli连接到haproxy但是当运行info命令时,会弹出连接关闭错误(它会将我放到redis-cli shell中),同时在redis中启用auth并且它正在运行任何问题。
配置等都是一样的,我检查了防火墙,安全组等,nc -zv一切正常,等等。
答案 0 :(得分:0)
问题是Elastic Load-balancer配置了错误的检查,因此它假设HA实例已停止服务。因此丢弃任何通信。我的坏。