1: Server Download $ wget http://download.redis.io/releases/redis-2.8.13.tar.gz unzip $ tar xzf redis-2.8.13.tar.gz $ CD redis-2.8.13 compile $ make
[[Email protected] ~] $ Tar xzf redis-2.8.13.tar.gz [[email protected] ~] $ CD redis-2.8.13 [[email protected] redis-2.8.13] $ makmcm 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] $
Run $ 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
Test
Connect to redis $ src/redis-cli
Set the key value redis> set Foo bar
OK
Read key value redis> Get foo "bar"
2: cluster configuration
With consistent hash, multiple master-slave nodes can be master-slave clusters.
Master/Slave Configuration
To configure master-slave, you only need to configure the master node IP port on slave:
[[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>
Modify the last line above
slaveof 10.3.7.212 6379
Start 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
Test
Master write, slave read:
OK!!