引用
# make install
cd src && make install
make[1]: Entering directory `/opt/software/redis-2.4.16/src'
MAKE hiredis
make[2]: Entering directory `/opt/software/redis-2.4.16/deps/hiredis'
make[2]: Nothing to be done for `static'.
make[2]: Leaving directory `/opt/software/redis-2.4.16/deps/hiredis'
MAKE linenoise
make[2]: Entering directory `/opt/software/redis-2.4.16/deps/linenoise'
make[2]: “linenoise_example”是最新的。
make[2]: Leaving directory `/opt/software/redis-2.4.16/deps/linenoise'
MAKE hiredis
make[2]: Entering directory `/opt/software/redis-2.4.16/deps/hiredis'
make[2]: Nothing to be done for `static'.
make[2]: Leaving directory `/opt/software/redis-2.4.16/deps/hiredis'
LINK redis-benchmark
LINK redis-cli
引用
[1958] 13 Aug 16:18:24 * Server started, Redis version 2.4.16
[1958] 13 Aug 16:18:24 # 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.
[1958] 13 Aug 16:18:24 * The server is now ready to accept connections on port 6379
[1958] 13 Aug 16:18:24 - 0 clients connected (0 slaves), 717544 bytes in use
四、测试
通过客户端命令redis-cli访问Redis
引用
# redis-cli
redis> set name zlex
OK
redis> get name
"zlex"
99.96% <= 1 milliseconds
100.00% <= 1 milliseconds
84033.61 requests per second
^CET (10 keys): 26200.00
五、关闭
也可通过客户端命令redis-cli完成Redis关闭操作:
Shell代码
redis-cli shutdown
引用
[2639] 13 Aug 16:35:35 # User requested shutdown...
[2639] 13 Aug 16:35:35 * Saving the final RDB snapshot before exiting.
[2639] 13 Aug 16:36:49 * DB saved on disk
[2639] 13 Aug 16:36:49 # Redis is now ready to exit, bye bye...
六、调优
1./etc/sysctl.conf
前面启动Redis时,看到如下警告:
引用
[1958] 13 Aug 16:18:24 # 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.
这里的Master IP 为192.168.133.139 端口位6379,配置redis.conf:
slaveof 192.168.133.139 6379
PS:为了两个Redis Server可以互访,需要注释掉bind 127.0.0.1
依次启动Master,Slave:
Master
[7651] 17 Aug 19:08:07 * Server started, Redis version 2.4.16
[7651] 17 Aug 19:08:07 * DB loaded from disk: 0 seconds
[7651] 17 Aug 19:08:07 * The server is now ready to accept connections on port 6379
[7651] 17 Aug 19:08:08 * Slave ask for synchronization
[7651] 17 Aug 19:08:08 * Starting BGSAVE for SYNC
[7651] 17 Aug 19:08:08 * Background saving started by pid 7652
[7652] 17 Aug 19:08:08 * DB saved on disk
[7651] 17 Aug 19:08:08 * Background saving terminated with success
[7651] 17 Aug 19:08:08 * Synchronization with slave succeeded
Slave
[7572] 17 Aug 19:07:39 * Server started, Redis version 2.4.16
[7572] 17 Aug 19:07:39 * DB loaded from disk: 0 seconds
[7572] 17 Aug 19:07:39 * The server is now ready to accept connections on port 6379
[7572] 17 Aug 19:07:39 * Connecting to MASTER...
[7572] 17 Aug 19:08:08 * MASTER <-> SLAVE sync started: SYNC sent
[7572] 17 Aug 19:08:08 * MASTER <-> SLAVE sync: receiving 10 bytes from master
[7572] 17 Aug 19:08:08 * MASTER <-> SLAVE sync: Loading DB in memory
[7572] 17 Aug 19:08:08 * MASTER <-> SLAVE sync: Finished with success
看到上述日志,就说明Master-Slave已经连通。
简单测试,Master写,Slave读:
Master写
telnet 192.168.133.139 6379
Trying 192.168.133.139...
Connected to 192.168.133.139.
Escape character is '^]'.
set name snowolf
+OK
Slave读
telnet 192.168.133.140 6379
Trying 192.168.133.140...
Connected to 192.168.133.140.
Escape character is '^]'.
get name
$7
snowolf
搞定!
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status $prog
RETVAL=$?
;;
restart)
stop
start
;;
condrestart)
if test "x`pidof redis`" != x; then
stop
start
fi
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart}"
exit 1
esac
exit $RETVAL
引用
# service redis-server restart
Stopping redis [失败]
Starting redis [确定]
# service redis-server status
redis (pid 14965) 正在运行...