“Resharding” means migrating the data in one slot from one redis server to another, usually happens while increasing/decreasing the number of redis servers.
# Set auth for client session # 1. product_auth is used for auth validation among codis-dashboard, # codis-proxy and codis-server. # 2. session_auth is different from product_auth, it requires clients # to issue AUTH <PASSWORD> before processing any other commands. session_auth = ""
# Set bind address for admin(rpc), tcp only. admin_addr = "0.0.0.0:11080"
# Set bind address for proxy, proto_type can be "tcp", "tcp4", "tcp6", "unix" or "unixpacket". proto_type = "tcp4" proxy_addr = "0.0.0.0:19000"
# Set jodis address & session timeout # 1. jodis_name is short for jodis_coordinator_name, only accept "zookeeper" & "etcd". # 2. jodis_addr is short for jodis_coordinator_addr # 3. jodis_auth is short for jodis_coordinator_auth, for zookeeper/etcd, "user:password" is accepted. # 4. proxy will be registered as node: # if jodis_compatible = true (not suggested): # /zk/codis/db_{PRODUCT_NAME}/proxy-{HASHID} (compatible with Codis2.0) # or else # /jodis/{PRODUCT_NAME}/proxy-{HASHID} jodis_name = "" jodis_addr = "" jodis_auth = "" jodis_timeout = "20s" jodis_compatible = false
# Set datacenter of proxy. proxy_datacenter = ""
# Set max number of alive sessions. proxy_max_clients = 1000
# Set max offheap memory size. (0 to disable) proxy_max_offheap_size = "1024mb"
# Set heap placeholder to reduce GC frequency. proxy_heap_placeholder = "256mb"
# Proxy will ping backend redis (and clear 'MASTERDOWN' state) in a predefined interval. (0 to disable) backend_ping_period = "5s"
# Set backend pipeline buffer size. backend_max_pipeline = 20480
# Set backend never read replica groups, default is false backend_primary_only = false
# Set backend parallel connections per server backend_primary_parallel = 1 backend_replica_parallel = 1
# Set backend tcp keepalive period. (0 to disable) backend_keepalive_period = "75s"
# Set number of databases of backend. backend_number_databases = 16
# If there is no request from client for a long time, the connection will be closed. (0 to disable) # Set session recv buffer size & timeout. session_recv_bufsize = "128kb" session_recv_timeout = "30m"
# Make sure this is higher than the max number of requests for each pipeline request, or your client may be blocked. # Set session pipeline buffer size. session_max_pipeline = 10000
# Set session tcp keepalive period. (0 to disable) session_keepalive_period = "75s"
# Set session to be sensitive to failures. Default is false, instead of closing socket, proxy will send an error response to client. session_break_on_failure = false
# Set metrics server (such as http://localhost:28000), proxy will report json formatted metrics to specified server in a predefined period. metrics_report_server = "" metrics_report_period = "1s"
# Set influxdb server (such as http://localhost:8086), proxy will report metrics to influxdb. metrics_report_influxdb_server = "" metrics_report_influxdb_period = "1s" metrics_report_influxdb_username = "" metrics_report_influxdb_password = "" metrics_report_influxdb_database = ""
# Set statsd server (such as localhost:8125), proxy will report metrics to statsd. metrics_report_statsd_server = "" metrics_report_statsd_period = "1s" metrics_report_statsd_prefix = ""
redis.conf
每台机器创建两个 redis 实例,对应端口 6379 和 6380
按需求修改 redis.conf 配置文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
# 创建 codis data 目录 mkdir -p /opt/codis/data
# 创建 6379 的配置文件: cp redis.conf redis-6379.conf vim redis-6379.conf # 修改如下内容 protected-mode no port 6379 pidfile "/opt/codis/data/redis_6379.pid" logfile "/opt/codis/data/redis_6379.log" dbfilename "dump_6379.rdb" dir "/opt/codis/data" # 创建 6380 的配置文件 cp redis-6379.conf redis-6380.conf sed -i 's/6379/6380/g' redis-6380.conf
sentinel.conf
如果只是 test 可以不配置
线上环境做 HA 建议分布在 3 台不同节点
1 2 3 4 5 6
vim sentinel.conf
dir "/opt/codis/data" daemonize yes loglevel notice logfile "/opt/codis/data/setinel.log"
Codis 启停脚本
测试环境可以使用 nohup 在后台运行
线上环境建议使用 Supervisord 或者 Monit 来管理
注意这里最后一个 fe 参数是你要访问的前端地址,但是因为 zookeeper 已经占用了 8080 端口,所以你可以改成别的端口。而且为了你在任何地址都可以访问,你可以设置监听 ip 为 0.0.0.0,因为 FE 是不用密码的,所以端口最好设置一个不常见的,避免被不怀好意的人看到前端页面之后对你的 codis 集群做出不好的事情,或者通过防火墙和 SSO 限制访问
Options: --ncpu=N set runtime.GOMAXPROCS to N, default is runtime.NumCPU(). -c CONF, --config=CONF run with the specific configuration. -l FILE, --log=FILE set path/name of daliy rotated log file. --log-level=LEVEL set the log-level, should be INFO,WARN,DEBUG or ERROR, default is INFO.
Options: --ncpu=N set runtime.GOMAXPROCS to N, default is runtime.NumCPU(). -d FILE, --dashboard-list=FILE set list of dashboard, can be generated by codis-admin. -l FILE, --log=FILE set path/name of daliy rotated log file. --log-level=LEVEL set the log-level, should be INFO,WARN,DEBUG or ERROR, default is INFO. --listen=ADDR set the listen address.
Options: --ncpu=N set runtime.GOMAXPROCS to N, default is runtime.NumCPU(). -c CONF, --config=CONF run with the specific configuration. -l FILE, --log=FILE set path/name of daliy rotated log file. --log-level=LEVEL set the log-level, should be INFO,WARN,DEBUG or ERROR, default is INFO. --ulimit=NLIMIT run 'ulimit -n' to check the maximum number of open file descriptors.
关于 HOT KEY, HOT KEY 很影响 Codis/Redis 的性能,这点如果你监控不到位,你就得花一些力气去找到底是哪组出了问题,再 monitor 看看找出是哪个应用干的,比较费时费力,所以在交付 rd 上线时, 我们就严肃声明坚决不允许存在 HOT KEY,宁可使用笨方法多消耗一些内存,也要降低线上故障的风险。
关于 BIG KEY, 这点风险更为巨大:
由于 Codis 支持 “resharding without restarting cluster”,如果迁移失败,所导致的后果也是不可简单衡量的。Redis 是串行提供服务的,所以当迁移该 BIG KEY 时,其他的请求就会被 BLOCK 住,这点是十分危险的,访问该组的请求皆会失败。