下載地址: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服務區進程新聞熱點
疑難解答