Spring Cloud,Spring Data Redis和Eureka的生产考虑因素

我有一个
Spring Cloud微服务应用程序,涵盖4种服务器类型:安全网关,两个UI服务器和一个REST API服务器.其中每个都将在生产环境中的自己的VM上运行:REST服务器的4个服务器实例和每个其他服务器的2个实例.

该系统预计将为大约30,000名用户提供服务.

服务发现由Eureka提供.我有两台Eureka服务器用于故障转移.

共享的HTTP会话由Spring Session&提供. Spring Data Redis,在参与的服务器上使用@EnableRedisHttpSession注释.

我决定使用Redis的3个VM设置(“示例2:使用三个框的基本设置”在此URL:http://redis.io/topics/sentinel).

每个VM将运行Redis服务器和Redis sentinel进程(其中一个Redis服务器将成为主服务器,两个实例将成为从服务器)

这一切都适用于开发机器和系统测试机器,主要是在同一台服务器上运行所有进程.

我现在正朝着具有多个虚拟机的类似生产的环境运行性能测试.我想要一些已经在生产中具有类似Spring Cloud设置的开发人员的反馈和建议:

>我应该寻找哪些边缘案例?
>是否有任何推荐的配置设置?我的设置如下所示.
>是否存在可能在测试环境中正常运行但在生产环境中成为严重问题的配置设置?
>在我的特定场景中,我还想要一个从Redis中清除旧数据的解决方案,因为它只用于保存会话信息.如果出于某种原因,spring不会在会话到期时清理会话数据(例如服务器突然被杀死),我想要清理真正的旧数据.我读到了关于Redis上的LRU /缓存机制,但它似乎没有关于时间的保证,只有在达到某些数据大小时才有.

这是我的Redis主服务器的配置.奴隶几乎是相同的,只是不同的端口,并表明他们是主人的奴隶:

daemonize no

port 6379
dbfilename "dump6379.rdb"
dir "/Users/odedia/Work/Redis/6379"
pidfile "/Users/odedia/Work/Redis/redis6379.pid"
#logfile "/Users/odedia/Work/Redis/redis6379.log"

tcp-backlog 511
timeout 0
tcp-keepalive 60
loglevel notice
databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
slave-serve-stale-data yes
slave-read-only no
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events "gxE"
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-entries 512
list-max-ziplist-value 64
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes

这是Redis的哨兵配置:

port 5000
sentinel monitor mymaster 127.0.0.1 6379 2
sentinel down-after-milliseconds mymaster 5000
sentinel failover-timeout mymaster 5000
sentinel config-epoch mymaster 59

这是Eureka服务器的application.yml:

server:
  port: 1111 

eureka:
  instance:
    hostname: localhost
  client:
    serviceUrl: 
      defaultZone: https://${eureka.instance.hostname}:${server.port}/eureka/
    registerWithEureka: false #Dont register yourself with yourself...
    fetchRegistry: false
  server:
    waitTimeInMsWhenSyncEmpty: 0

spring:
  application:
    name: eureka

这里是网关服务器的application.yml,它负责基于Zuul的路由:

# Spring properties
spring:
  application:
   name: gateway-server  # Service registers under this name
  redis:
    sentinel:
      master: mymaster
      nodes: 127.0.0.1:5000,127.0.0.1:5001,127.0.0.1:5002

server:
  port: 8080

security:
  sessions: ALWAYS 


zuul: 
 retryable: true #Always retry before failing
 routes:
   ui1-server: /ui1/** 
   ui2-server: /ui2/** 
   api-resource-server: /rest/** 

# Discovery Server Access
eureka:
  client:
    serviceUrl:
      defaultZone: https://localhost:1111/eureka/ 
  instance:
    hostname: localhost
  metadataMap:
        instanceId: ${spring.application.name}:${spring.application.instance_id:${random.value}}


hystrix:
  command:
    default:
      execution:
        isolation:
          strategy: THREAD
          thread:
            timeoutInMilliseconds: 40000 #Timeout after this time in milliseconds

ribbon:
  ConnectTimeout: 5000 #try to connect to the endpoint for 5 seconds.
  ReadTimeout: 50000 #try to get a response after successfull connection for 5 seconds
  # Max number of retries on the same server (excluding the first try)
  maxAutoRetries: 1
  # Max number of next servers to retry (excluding the first server)
  MaxAutoRetriesNextServer: 2

最佳答案 我根据我在Spring Data Redis的制作经验写了一篇文章,这里有兴趣的人可以使用.

https://medium.com/@odedia/production-considerations-for-spring-session-redis-in-cloud-native-environments-bd6aee3b7d34

点赞