您好,欢迎访问一九零五行业门户网

Redis安装及主从配置

redis是一种面向ldquo;键/值rdquo;对类型数据的分布式nosql数据库系统,特点是高性能,持久存储,适应高并发的应用场景。它起步
redis是一种面向“键/值”对类型数据的分布式nosql数据库系统,特点是高性能,持久存储,适应高并发的应用场景。它起步较晚,发展迅速,目前已被许多大型机构采用,如google、taobao、sina微博等。本文不对其数据结构做深入的讲解,只是介绍其安装及主从结构的配置过程。如需要更详细的了解请参考其官方网站。redis的安装
redis目前只支持linux及bsd等系统,不支持window下的安装。在linux下安装的过程如下所示:
$ wget
$ tar xzf redis-2.2.12.tar.gz
$ cd redis-2.2.12
$ make
安装成功后的提示为:
hint: to run 'make test' is a good idea ;)
make[1]: leaving directory `/usr/alibaba/install/redis-2.2.12/src'
在安装完成后,即可进入至该工程的src下启动服务:
$ src/redis-server
通过内置的build-cli工具进行相应的测试,其测试过程如下:
$ src/redis-cli
redis> set foo bar
ok
redis> get foo
bar
redis > getset foo 123
“bar”
redis >get foo
123
redis的主从配置机器的分配主从结构的配置所涉及到的机器及各机器所完成的功能如下所示:
ip地址                                      
角色
10.20.150.205
主结点
10.20.150.208
从结点1
10.20.150.209
从结点2
主从结构的配置在进行主从结构配置之前,请确保已经在上述三台机器上已经安装了redis服务。对于redis的主从结构的配置相对比较简单,只需修改redis.conf文件,配置上主结点对应的ip及端口。具体如下所示:
port 6380
bind 10.20.150.205
slaveof 10.20.150.205 6379
l  port 6380表示当前该redis服务对应的端口号;
l  bind 10.20.150.205 表示当前redis绑定的主结点的ip地址;
l  slaveof 10.20.150.205 6379 表示当前redis是哪个主结点的从结点,其中包括ip及端口号。
当主结点在启动时                        当只有一台主结点在启动时,会显示如下的信息:
[29028] 26 sep 18:39:12 * server started, redis version 2.2.12
[29028] 26 sep 18:39:12 # warning overcommit_memory is set to 0! background save may fail under low memory condition. to fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
[29028] 26 sep 18:39:12 * db loaded from disk: 0 seconds
[29028] 26 sep 18:39:12 * the server is now ready to accept connections on port 6379
[29028] 26 sep 18:39:12 - 0 clients connected (0 slaves), 790584 bytes in use
当有一台从结点10.20.150.208启动时其中主结点会自动检测到有新的从结点启动并加入进来,其显示的信息如下:
[29028] 26 sep 18:40:31 - accepted 10.20.150.208:44779
[29028] 26 sep 18:40:31 * slave ask for synchronization
[29028] 26 sep 18:40:31 * starting bgsave for sync
[29028] 26 sep 18:40:31 * background saving started by pid 29091
[29091] 26 sep 18:40:31 * db saved on disk
[29028] 26 sep 18:40:31 * background saving terminated with success
[29028] 26 sep 18:40:31 * synchronization with slave succeeded
[29028] 26 sep 18:40:32 - 0 clients connected (1 slaves), 798752 bytes in use
[29028] 26 sep 18:40:37 - 0 clients connected (1 slaves), 798752 bytes in use
[29028] 26 sep 18:40:42 - 0 clients connected (1 slaves), 798752 bytes in use
[29028] 26 sep 18:40:47 - 0 clients connected (1 slaves), 798752 bytes in use
对于从结点显示的信息如下:
#[597] 26 sep 18:40:29 * server started, redis version 2.2.12
[597] 26 sep 18:40:29 # warning overcommit_memory is set to 0! background save may fail under low memory condition. to fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
[597] 26 sep 18:40:29 * the server is now ready to accept connections on port 6379
[597] 26 sep 18:40:29 - 0 clients connected (0 slaves), 790616 bytes in use
[597] 26 sep 18:40:29 * connecting to master...
[597] 26 sep 18:40:29 * master slave sync started: sync sent
[597] 26 sep 18:40:29 * master slave sync: receiving 10 bytes from master
[597] 26 sep 18:40:29 * master slave sync: loading db in memory
[597] 26 sep 18:40:29 * master slave sync: finished with success
[597] 26 sep 18:40:34 - 1 clients connected (0 slaves), 798744 bytes in use
当有另外一台从机10.20.150.209挂载时当有另一台从机挂载至主机时,主机显示的信息如下:
其它类似信息

推荐信息