redis部署
下载软件
[root@localhost /]# wget http://download.redis.io/releases/redis-2.8.9.tar.gz
解压、编译、安装
[root@localhost /]# ll redis-2.8.9.tar.gz -rw-r--r--. 1 root root 1097369 Apr 22 2014 redis-2.8.9.tar.gz [root@localhost /]# tar xf redis-2.8.9.tar.gz [root@localhost /]# cd redis-2.8.9 [root@localhost redis-2.8.9]# less README [root@localhost redis-2.8.9]# make MALLOC=jemalloc [root@localhost redis-2.8.9]# make PREFIX=/usr/local/redis install
在/usr/local/redis/bin/目录下生成5个可执行文件,分别是:
redis-benchmark redis-check-dump redis-server redis-check-aof redis-cli
他们的作用:
redis-server:Redis服务器的daemon启动程序 redis-cli:redis命令行操作工具。当然,你也可以用telnet根据其纯文本协议来操作。 redis-benchmark:redis性能测试工具,测试redis在你的系统及你的配置下的读写性能 redis-check-aof:更新日志检查 redis-check-dump:用于本地数据库检查
配置环境变量
[root@localhost bin]# echo 'PATH=/usr/local/redis/bin/:$PATH' >> /etc/profile [root@localhost bin]# tail -1 /etc/profile PATH=/usr/local/redis/bin/:$PATH [root@localhost bin]# . /etc/profile [root@localhost bin]# which redis-server /usr/local/redis/bin/redis-server
查看帮助
[root@localhost bin]# redis-server --help Usage: ./redis-server [/path/to/redis.conf] [options] ./redis-server - (read config from stdin) ./redis-server -v or --version ./redis-server -h or --help ./redis-server --test-memory <megabytes> Examples: ./redis-server (run the server with default conf) ./redis-server /etc/redis/6379.conf ./redis-server --port 7777 ./redis-server --port 7777 --slaveof 127.0.0.1 8888 ./redis-server /etc/myredis.conf --loglevel verbose Sentinel mode: ./redis-server /etc/sentinel.conf --sentinel
启动redis服务
[root@localhost bin]# cd /redis-2.8.9 [root@localhost redis-2.8.9]# pwd /redis-2.8.9 [root@localhost redis-2.8.9]# mkdir /usr/local/redis/conf [root@localhost redis-2.8.9]# cp redis.conf /usr/local/redis/conf/ [root@localhost redis-2.8.9]# redis-server /usr/local/redis/conf/redis.conf & [3315] 28 Sep 17:13:36.625 # Server started, Redis version 2.8.9 [3315] 28 Sep 17:13:36.625 # 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. [3315] 28 Sep 17:13:36.625 * DB loaded from disk: 0.000 seconds [3315] 28 Sep 17:13:36.625 * The server is now ready to accept connections on port 6379 [root@localhost redis-2.8.9]# killall redis-server [3315 | signal handler] (1475054137) Received SIGTERM, scheduling shutdown... [root@localhost redis-2.8.9]# [3315] 28 Sep 17:15:37.032 # User requested shutdown... [3315] 28 Sep 17:15:37.032 * Saving the final RDB snapshot before exiting. [3315] 28 Sep 17:15:37.033 * DB saved on disk [3315] 28 Sep 17:15:37.034 # Redis is now ready to exit, bye bye... [1]+ Done redis-server /usr/local/redis/conf/redis.conf [root@localhost redis-2.8.9]# sysctl vm.overcommit_memory=1 vm.overcommit_memory = 1 [3322] 28 Sep 17:17:13.916 # Server started, Redis version 2.8.9 [3322] 28 Sep 17:17:13.917 * DB loaded from disk: 0.000 seconds [3322] 28 Sep 17:17:13.917 * The server is now ready to accept connections on port 6379 [root@localhost redis-2.8.9]# lsof -i :6379 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME redis-ser 3322 root 4u IPv6 18071 0t0 TCP *:6379 (LISTEN) redis-ser 3322 root 5u IPv4 18073 0t0 TCP *:6379 (LISTEN)
关闭redis服务
[root@localhost redis-2.8.9]# redis-cli shutdown [3322] 28 Sep 17:20:56.467 # User requested shutdown... [3322] 28 Sep 17:20:56.467 * Saving the final RDB snapshot before exiting. [3322] 28 Sep 17:20:56.549 * DB saved on disk [3322] 28 Sep 17:20:56.549 # Redis is now ready to exit, bye bye... [1]+ Done redis-server /usr/local/redis/conf/redis.conf [root@localhost redis-2.8.9]# lsof -i :6379