Spring Cloud、Spring Data Redis 和 Eureka 的生产注意事项

Production considerations for Spring Cloud, Spring Data Redis & Eureka

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

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

服务发现由Eureka提供。我有两个用于故障转移的 Eureka 服务器。

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

我决定为 Redis 设置 3 个虚拟机("Example 2: basic setup with three boxes" URL:http://redis.io/topics/sentinel)。

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

这一切在开发机器和系统测试机器上都运行良好,大多数情况下 运行 在同一台服务器上运行所有进程。

我现在正着手 运行在类似生产的环境中使用多个 VM 进行性能测试。我希望得到已经在生产中具有类似 Spring 云设置的开发人员的一些反馈和建议:

这是我的主 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