下载地址:http://redis.io/download,下载最新文档版本。 本文使用的最新文档版本为 3.2.7,下载,解压缩和编译安装Redis:
稳定 Redis 3.2包含对API的重大更改和Redis的实现。 Redis 3.2发行说明
wget http://download.redis.io/releases/redis-3.2.7.tar.gztar xzf redis-3.2.7.tar.gzcd redis-3.2.7make可以看出默认端口是6379,并且现在的启动不是后台启动。 vi redis.conf 设置 daemonize no–>daemonize yes
[root@souyunku redis-3.2.7]# ./bin/redis-server ./redis.conf 8258:M 08 Feb 12:26:54.279 * Increased maximum number of open files to 10032 (it was originally set to 1024). _._ _.-``__ ''-._ _.-`` `. `_. ''-._ Redis 3.2.7 (00000000/0) 64 bit .-`` .-```. ```// _.,_ ''-._ ( ' , .-` | `, ) Running in standalone mode |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379 | `-._ `._ / _.-' | PID: 8258 `-._ `-._ `-./ _.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | http://redis.io `-._ `-._`-.__.-'_.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-' `-._ `-.__.-' _.-' `-._ _.-' `-.__.-' 8258:M 08 Feb 12:26:54.293 # WARNING: The TCP backlog setting of 511 cannot be enforced because /PRoc/sys/net/core/somaxconn is set to the lower value of 128.8258:M 08 Feb 12:26:54.293 # Server started, Redis version 3.2.78258:M 08 Feb 12:26:54.293 # 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.8258:M 08 Feb 12:26:54.294 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.8258:M 08 Feb 12:26:54.294 * The server is now ready to accept connections on port 6379By default Redis does not run as a daemon. Use ‘yes’ if you need it. Note that Redis will write a pid file in /var/run/redis.pid when daemonized. daemonize yes
默认情况下,Redis不作为守护程序运行。 如果需要,使用“yes”。 #注意,Redis在守护进程时会在/var/run/redis.pid中写一个pid文件。 守护进程 yes vim redis.conf 设置 daemonize no 把‘no’修改>daemonize yes
[root@souyunku redis-3.2.7]# vi redis.conf [root@souyunku redis-3.2.7]# ./bin/redis-server ./redis.conf [root@souyunku redis-3.2.7]# ps -ef | grep redroot 8264 1 0 12:34 ? 00:00:00 ./bin/redis-server 127.0.0.1:6379root 8268 8023 0 12:34 pts/1 00:00:00 grep redredis.conf配置文件中指定的pid路径地址,这里说明一下,在 redis.conf配置文件中需要将 daemonize这个参数项设置为 yes才会在redis启动时生成pid文件,很多新人不知道,没有生成pid文件,所以脚本里根据pid文件关闭redis就失败。 如果正常关闭就会删除这个pid文件
设置redis.conf中daemonize为yes,确保守护进程开启。
问题1:make时可能会报如下错误
[root@souyunku redis-3.2.7]# make gcc -std=c99 -pedantic -c -O3 -fPIC -Wall -W -Wstrict-prototypes -Wwrite-strings -g -ggdb net.cmake[3]: gcc: Command not found[3]:gcc:命令没有找到make[3]: *** [net. o] Error 127[3]:* * * 错误127查找实时库librt所在路径: 在src下的Makefile文件中的函数,加 FINAL_LIBS+= /usr/lib64/librt.so #此路径加上librt.so,即可,在编译就成功了 大概在 105 ~110 行
ifeq ($(MALLOC),jemalloc) DEPENDENCY_TARGETS+= jemalloc FINAL_CFLAGS+= -DUSE_JEMALLOC -I../deps/jemalloc/include FINAL_LIBS+= ../deps/jemalloc/lib/libjemalloc.aFINAL_LIBS+= /usr/lib64/librt.so #此路径加上librt.soendif[root@souyunku redis-3.2.7]# make cd src && make all make[1]: Entering directory `/opt/redis/redis-3.2.7/src’
Hint: It’s a good idea to run ‘make test’ ;)
make[1]: Leaving directory `/opt/redis/redis-3.2.7/src’
bin下的命令是什么意思呢?下面我们来说一说~
[root@souyunku bin]# lltotal 30824-rwxr-xr-x. 1 root root 6725486 Feb 8 12:18 redis-benchmark-rwxr-xr-x. 1 root root 22193 Feb 8 12:18 redis-check-aof-rwxr-xr-x. 1 root root 8974545 Feb 8 12:18 redis-check-rdb-rwxr-xr-x. 1 root root 6853618 Feb 8 12:18 redis-clilrwxrwxrwx. 1 root root 12 Feb 8 12:18 redis-sentinel -> redis-server-rwxr-xr-x. 1 root root 8974545 Feb 8 12:18 redis-serverredis-benchmark ---->redis性能测试工具redis-check-aof ---->检查aof日志工具,如果日志损坏能检查出来redis-check-dump ---->检查rdb日志工具redis-cli ---->连接用的客户端redis-server ---->redis服务区进程新闻热点
疑难解答