注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

永福的技术博客

Linux运维

 
 
 

日志

 
 

redis平滑升级redis-2.4到redis-2.6  

2013-06-26 09:27:33|  分类: 软件编程 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
1. 升级的步骤和思路
    1.1 新建一个2.6.14版的redis。
    1.2 配置文件修改,作为slave进行配置。
    1.3 启动slave,并做好数据测试。
    1.4 将原来程序的redis读写迁移到新的slave上。
    1.5 升级原来的版本到2.6.14
2. redis 2.4和2.6的区别
    2.1 官方的2.4到2.6迁移说明
    2.2 redis2.6版的所有新特性和改进列表

升级前,系统环境:
192.168.1.119 , redis 2.4.15 , 单独的redis实例 
192.168.1.229 , 没有安装redis , 空闲的机器

升级中,系统环境:
192.168.1.119 , redis 2.4.15, redis master
192.168.1.229 , redis 2.6.14, redis slave

升级后,系统环境:
192.168.1.119 , redis 2.6.14, redis slave
192.168.1.229 , redis 2.6.14, redis master 

1. 升级的步骤和思路
1.1 新建一个2.6.14最新版redis
在192.168.1.229, 创建基本目录:
mkdir -p /opt/app/redis/{bin,db,logs,etc} 
安装
tar xzf redis-2.6.14.tar.gz
cd redis-2.6.14
make
cp src/redis-benchmark /opt/app/redis/bin/
cp src/redis-check-aof /opt/app/redis/bin/
cp src/redis-check-dump /opt/app/redis/bin/
cp src/redis-cli /opt/app/redis/bin/
cp src/redis-sentinel /opt/app/redis/bin/
cp src/redis-server /opt/app/redis/bin/

1.2 新建配置文件
/opt/app/redis/etc/redis.conf,内容如下:
daemonize yes
pidfile /var/run/redis.pid
port 6379
bind 192.168.1.229
timeout 300
loglevel warning
logfile /opt/app/redis/logs/redis.log
databases 16
save 900 1
save 300 10
save 60 10000
rdbcompression yes
dbfilename /opt/app/redis/db/redis.rdb
dir /opt/app/redis/db/
slaveof 192.168.1.119 6379
slave-serve-stale-data yes
maxmemory 128mb
appendonly no
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
slowlog-log-slower-than 10000
slowlog-max-len 1024
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
activerehashing yes

注意这三段红色部分:
第一段:表示redis绑定的ip和端口。
第二段:表示设置本redis为slave,并且设置redis的master为192.168.1.119 6379。redis 2.6的新特性,在slave的情况下,默认为只读,不能写入数据。我先以默认方式只读来同步数据,至于写入数据稍后在命令行里修改。
第三段:redis2.6新版中将选项名改为现在形式。

1.3 启动slave,数据测试
# 启动 slave
[root@localhost redis-2.6.14]# /opt/app/redis/bin/redis-server /opt/app/redis/etc/redis.conf
# 查看slave的info
[root@localhost redis-2.6.14]# /opt/app/redis/bin/redis-cli -h 192.168.1.229 info 
# Server
redis_version:2.6.14
redis_git_sha1:00000000
redis_git_dirty:0
redis_mode:standalone
os:Linux 2.6.18-238.el5 x86_64
arch_bits:64
multiplexing_api:epoll
gcc_version:4.1.2
process_id:14045
run_id:bd54d0a656843b62275888b1c22867856a61a50c
tcp_port:6379
uptime_in_seconds:76898
uptime_in_days:0
hz:10
lru_clock:905798

# Clients
connected_clients:2
client_longest_output_list:0
client_biggest_input_buf:0
blocked_clients:0

# Memory
used_memory:6347704
used_memory_human:6.05M
used_memory_rss:7655424
used_memory_peak:6367504
used_memory_peak_human:6.07M
used_memory_lua:31744
mem_fragmentation_ratio:1.21
mem_allocator:jemalloc-3.2.0

# Persistence
loading:0
rdb_changes_since_last_save:0
rdb_bgsave_in_progress:0
rdb_last_save_time:1372206578
rdb_last_bgsave_status:ok
rdb_last_bgsave_time_sec:0
rdb_current_bgsave_time_sec:-1
aof_enabled:0
aof_rewrite_in_progress:0
aof_rewrite_scheduled:0
aof_last_rewrite_time_sec:-1
aof_current_rewrite_time_sec:-1
aof_last_bgrewrite_status:ok

# Stats
total_connections_received:16
total_commands_processed:8238
instantaneous_ops_per_sec:0
rejected_connections:0
expired_keys:0
evicted_keys:0
keyspace_hits:66
keyspace_misses:8
pubsub_channels:0
pubsub_patterns:0
latest_fork_usec:6087

# Replication
role:slave
master_host:192.168.1.119
master_port:6379
master_link_status:up
master_last_io_seconds_ago:4
master_sync_in_progress:0

slave_priority:100
slave_read_only:1
connected_slaves:0

# CPU
used_cpu_sys:0.48
used_cpu_user:0.27
used_cpu_sys_children:0.61
used_cpu_user_children:0.50

# Keyspace
db0:keys=1328,expires=0
db1:keys=787,expires=0
db3:keys=123,expires=0
db4:keys=1,expires=0

当看到上面红色部分关于master信息时,表示slave已经将数据从master同步过来。
在reids2.6版中,slave默认是只读的。可以从命令行下可设置为同时读写。
[root@localhost redis-2.6.14]#  /opt/app/redis/bin/redis-cli -h 192.168.1.229 config set slave-read-only no
# 查看slave的info
[root@localhost redis-2.6.14]# /opt/app/redis/bin/redis-cli -h 192.168.1.229 info 
# Server
redis_version:2.6.14
redis_git_sha1:00000000
redis_git_dirty:0
redis_mode:standalone
os:Linux 2.6.18-238.el5 x86_64
arch_bits:64
multiplexing_api:epoll
gcc_version:4.1.2
process_id:14045
run_id:bd54d0a656843b62275888b1c22867856a61a50c
tcp_port:6379
uptime_in_seconds:76898
uptime_in_days:0
hz:10
lru_clock:905798

# Clients
connected_clients:2
client_longest_output_list:0
client_biggest_input_buf:0
blocked_clients:0

# Memory
used_memory:6347704
used_memory_human:6.05M
used_memory_rss:7655424
used_memory_peak:6367504
used_memory_peak_human:6.07M
used_memory_lua:31744
mem_fragmentation_ratio:1.21
mem_allocator:jemalloc-3.2.0

# Persistence
loading:0
rdb_changes_since_last_save:0
rdb_bgsave_in_progress:0
rdb_last_save_time:1372206578
rdb_last_bgsave_status:ok
rdb_last_bgsave_time_sec:0
rdb_current_bgsave_time_sec:-1
aof_enabled:0
aof_rewrite_in_progress:0
aof_rewrite_scheduled:0
aof_last_rewrite_time_sec:-1
aof_current_rewrite_time_sec:-1
aof_last_bgrewrite_status:ok

# Stats
total_connections_received:16
total_commands_processed:8238
instantaneous_ops_per_sec:0
rejected_connections:0
expired_keys:0
evicted_keys:0
keyspace_hits:66
keyspace_misses:8
pubsub_channels:0
pubsub_patterns:0
latest_fork_usec:6087

# Replication
role:slave
master_host:192.168.1.119
master_port:6379
master_link_status:up
master_last_io_seconds_ago:4
master_sync_in_progress:0
slave_priority:100
slave_read_only:0
connected_slaves:0

# CPU
used_cpu_sys:0.48
used_cpu_user:0.27
used_cpu_sys_children:0.61
used_cpu_user_children:0.50

# Keyspace
db0:keys=1328,expires=0
db1:keys=787,expires=0
db3:keys=123,expires=0
db4:keys=1,expires=0

1.4 更新应用程序的redis库
将php应用的redis连接修改为192.168.1.229上的redis
将Slave上的同步状态取消,避免主库在未完成版本升级前就重启,进而直接覆盖掉从库上的数据,导致所有的数据丢失。
redis 192.168.1.229:6379> SLAVEOF NO ONE
OK

1.5 升级原reids版本
升级192.168.1.119的redis版本到2.6.14
由于前面的操作,119上的redis可以放心的关闭和进行升级,操作和前面1-4步类似。

2. redis 2.4和2.6的区别
2.1 官方的2.4到2.6迁移说明
Redis 2.4 is mostly a strict subset of 2.6. However there are a few things
that you should be aware of:
redis 2.4 很大部分上是 2.6 版的一个子集。然而还是有些需要注意的地方:

* You can't use .rdb and AOF files generated with 2.6 into a 2.4 instance.
* 2.6 slaves can be attached to 2.4 masters, but not the contrary, and only
  for the time needed to perform the version upgrade.
* 不可以把2.6生成的.rdb和AOF文件用于2.4的redis实例。
* 2.4版可以作为master让2.6版的slave连接,但是反过来不行。而且这样做仅仅在于进行版本升级的时候。

There are also a few API differences, that are unlikely to cause problems,
but it is better to keep them in mind:
还有一些API的小修改,这些不同不太可能造成什么问题,但是最好还是心里有数的好。

* SORT now will refuse to sort in numerical mode elements that can't be parsed as numbers.
* EXPIREs now all have millisecond resolution (but this is very unlikely to
  break code that was not conceived exploting the previous resolution error
  in some way.)
* INFO output is a bit different now, and contains empty lines and comments
  starting with '#'. All the major clients should be already fixed to work
  with the new INFO format.
* Slaves are only read-only by default (but you can change this easily
  setting the "slave-read-only" configuration option to "no" editing your
  redis.conf or using CONFIG SET.
* SORT 将不对数字模式的元素进行排序,这些不能被解析为数字。
* EXPIRES 可以进行毫秒级的处理了。(这个和直接结束代码不同。直接结束代码在某些时候不会返回前一个处理的错误)
* INFO 的输出结果也有写改变。空行和注释以'#"开始。所有的主要clients(如php,python等)应该都已经和新的INFO格式兼容。
* "从"在默认情况下是只读的。(但是可以在配置文件中配置 slave-read-only no 或者在redis-cli命令行下使用config set命令配置为可写。)

The following INFO fields were renamed for consistency:
INFO格式中这些字段改名如下:
     changes_since_last_save -> rdb_changes_since_last_save
     bgsave_in_progress -> rdb_bgsave_in_progress
     last_save_time -> rdb_last_save_time
     last_bgsave_status -> rdb_last_bgsave_status
     bgrewriteaof_in_progress -> aof_rewrite_in_progress
     bgrewriteaof_scheduled -> aof_rewrite_scheduled

The following redis.conf and CONFIG GET / SET parameters changed:
redis.conf文件的配置项修改如下:
    * hash-max-zipmap-entries, now replaced by hash-max-ziplist-entries
    * hash-max-zipmap-value, now replaced by hash-max-ziplist-value
    * glueoutputbuf option was now completely removed (was deprecated)


2.2 An overview of new features and changes in Redis 2.6.x
======================================================

* Server side Lua scripting, see http://redis.io/commands/eval
* Virtual Memory removed (was deprecated in 2.4)
* Hardcoded limits about max number of clients removed.
* AOF low level semantics is generally more sane, and especially when used
  in slaves.
* Milliseconds resolution expires, also added new commands with milliseconds
  precision (PEXPIRE, PTTL, ...).
* Better memory usage for "small" lists, ziplists and hashes when fields or
  values contain small integers.
* Read only slaves.
* New bit opeations: BITCOUNT and BITOP commands.
* Clients max output buffer soft and hard limits. You can specifiy different
  limits for different classes of clients (normal,pubsub,slave).
* More incremental (less blocking) expired keys collection algorithm, in
  practical terms this means that Redis is more responsive when a very
  big number of keys expire about at the same time.
* AOF is now able to rewrite aggregate data types using variadic commands,
  often producing an AOF that is faster to save, load, and is smaller in size.
* Every redis.conf directive is now accepted as a command line option for the
  redis-server binary, with the same name and number of arguments.
* Hash table seed randomization for protection against collisions attacks.
* Performances improved when writing large objects to Redis.
* Integrated memory test, see redis-server --test-memory.
* INCRBYFLOAT and HINCRBYFLOAT commands.
* New DUMP, RESTORE, MIGRATE commands (back ported from Redis Cluster to 2.6).
* CRC64 checksump in RDB files.
* Better MONITOR output and behavior (now commands are logged before execution).
* "Software Watchdog" feature to debug latency issues.
* Significant parts of the core refactored or rewritten. New internal APIs
  and core changes allowed to develop Redis Cluster on top of the new code,
  however for 2.6 all the cluster code was removed, and will be released with
  Redis 3.0 when it is more complete and stable.
* Redis ASCII art logo added at startup.
* Crash report on memory violation or failed asserts improved significantly
  to make debugging of hard to catch bugs simpler.
* redis-benchmark improvements: ability to run selected tests,
  CSV output, faster, better help.
* redis-cli improvements: --eval for comfortable development of Lua scripts.
* SHUTDOWN now supports two optional arguments: "SAVE" and "NOSAVE".
* INFO output split into sections, the command is now able to just show 
  pecific sections.
* New statistics about how many time a command was called, and how much
  execution time it used (INFO commandstats).
* More predictable SORT behavior in edge cases.
* Better support for big endian and *BSD systems.
* Build system improved.



  评论这张
 
阅读(7417)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018