標籤: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
[[email protected] ~]$ tar xzf redis-2.8.13.tar.gz [[email protected] ~]$ cd redis-2.8.13[[email protected] redis-2.8.13]$ makecd src && make all......出現一大堆資訊Hint: To run 'make test' is a good idea ;)make[1]: Leaving directory `/home/jifeng/redis-2.8.13/src'[[email protected] redis-2.8.13]$
運行 $ src/redis-server[[email protected] 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:
[[email protected] 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
[[email protected] 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!!