redis安装,主从集群,redis主从集群


1:服务端
  下载 $ wget http://download.redis.io/releases/redis-2.8.13.tar.gz
  解压 $ tar xzf redis-2.8.13.tar.gz
  $ cd redis-2.8.13
  编译 $ make
[jifeng@jifeng04 ~]$ tar xzf redis-2.8.13.tar.gz 
[jifeng@jifeng04 ~]$ cd redis-2.8.13
[jifeng@jifeng04 redis-2.8.13]$ make
cd src && make all
......出现一大堆信息
Hint: To run 'make test' is a good idea ;)

make[1]: Leaving directory `/home/jifeng/redis-2.8.13/src'

[jifeng@jifeng04 redis-2.8.13]$ 
  运行 $ src/redis-server
[jifeng@jifeng04 redis-2.8.13]$ src/redis-server
[6675] 10 Aug 17:19:48.837 # Warning: no config file specified, using the default config. In order to specify a config file use src/redis-server /path/to/redis.conf
[6675] 10 Aug 17:19:48.838 # You requested maxclients of 10000 requiring at least 10032 max file descriptors.
[6675] 10 Aug 17:19:48.838 # Redis can't set maximum open files to 10032 because of OS error: Operation not permitted.
[6675] 10 Aug 17:19:48.838 # Current maximum open files is 1024. maxclients has been reduced to 4064 to compensate for low ulimit. If you need higher maxclients increase 'ulimit -n'.
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 2.8.13 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in stand alone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 6675
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

[6675] 10 Aug 17:19:48.839 # Server started, Redis version 2.8.13
[6675] 10 Aug 17:19:48.839 # 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.
[6675] 10 Aug 17:19:48.839 * The server is now ready to accept connections on port 6379

测试一下
  连接redis  $ src/redis-cli  
  设置键值  redis> set foo bar 
    OK 
  读取键值  redis> get foo  "bar"

2:集群配置
用一致性哈希,做多个主从,可以做主从集群。
主从配置
配置Master-Slave,只需要在Slave上配置Master节点IP Port:
[jifeng@jifeng04 redis-2.8.13]$ vi redis.conf
################################# REPLICATION #################################

# Master-Slave replication. Use slaveof to make a Redis instance a copy of
# another Redis server. Note that the configuration is local to the slave
# so for example it is possible to configure the slave to save the DB with a
# different interval, or to listen to another port, and so on.
#
# slaveof <masterip> <masterport>
修改上面最后一行
slaveof 10.3.7.212 6379

启动slave
[jifeng@jifeng04 redis-2.8.13]$ src/redis-server ./redis.conf
[6762] 10 Aug 17:46:46.907 # You requested maxclients of 10000 requiring at least 10032 max file descriptors.
[6762] 10 Aug 17:46:46.907 # Redis can't set maximum open files to 10032 because of OS error: Operation not permitted.
[6762] 10 Aug 17:46:46.907 # Current maximum open files is 1024. maxclients has been reduced to 4064 to compensate for low ulimit. If you need higher maxclients increase 'ulimit -n'.
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 2.8.13 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in stand alone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 6762
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

[6762] 10 Aug 17:46:46.915 # Server started, Redis version 2.8.13
[6762] 10 Aug 17:46:46.916 # 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.
[6762] 10 Aug 17:46:46.916 * DB loaded from disk: 0.000 seconds
[6762] 10 Aug 17:46:46.916 * The server is now ready to accept connections on port 6379
[6762] 10 Aug 17:46:47.916 * Connecting to MASTER 10.3.7.212:6379
[6762] 10 Aug 17:46:47.916 * MASTER <-> SLAVE sync started
[6762] 10 Aug 17:46:47.916 * Non blocking connect for SYNC fired the event.
[6762] 10 Aug 17:46:47.917 * Master replied to PING, replication can continue...
[6762] 10 Aug 17:46:47.917 * Partial resynchronization not possible (no cached master)
[6762] 10 Aug 17:46:47.917 * Full resync from master: 925b249e41d001e66c4e683983439c346b96571f:1
[6762] 10 Aug 17:46:47.952 * MASTER <-> SLAVE sync: receiving 29 bytes from master
[6762] 10 Aug 17:46:47.952 * MASTER <-> SLAVE sync: Flushing old data
[6762] 10 Aug 17:46:47.952 * MASTER <-> SLAVE sync: Loading DB in memory
[6762] 10 Aug 17:46:47.952 * MASTER <-> SLAVE sync: Finished with success

测试
Master写,Slave读:
OK!!

相关内容

    暂无相关文章