下載redis版本:https://redis.io/download 我下載的是:redis-3.0.6
下載后,在linux上 tar -zxvf redis-3.0.6,進入redis-3.0.6 目錄,使用make進行編譯
在安裝Redis,使用make命令編譯的時候,拋出異常
[root@node1 redis-3.0.6]# make
cd src && make all
make[1]: Entering directory `/usr/local/development/redis-3.0.6/src'
CC adlist.o
/bin/sh: cc: command not found
make[1]: *** [adlist.o] Error 127
make[1]: Leaving directory `/usr/local/development/redis-3.0.6/src'
make: *** [all] Error 2
這個是本地的Linux沒有安裝gcc的原因,因為我的Linux沒有聯網所以使用離線安裝,也就是先再Windows上下載RPM包,然后移動到Linux上手動安裝
安裝gcc的步驟:
在ftp://mirror.switch.ch/pool/4/mirror/scientificlinux/6.8/x86_64/os/Packages/連接里 下載gcc所需的RPM包
從網上查,需要下面這些包
cloog-ppl-0.15.7-1.2.el6.x86_64.rpm
cpp-4.4.7-17.el6.x86_64.rpm
gcc-4.4.7-17.el6.x86_64.rpm
gcc-c++-4.4.7-17.el6.x86_64.rpm
glibc-devel-2.12-1.192.el6.x86_64.rpm
glibc-headers-2.12-1.192.el6.x86_64.rpm
kernel-headers-2.6.32-642.el6.x86_64.rpm
libgomp-4.4.7-17.el6.x86_64.rpm
libstdc++-devel-4.4.7-17.el6.x86_64.rpm
mpfr-2.4.1-6.el6.x86_64.rpm
ppl-0.10.2-11.el6.x86_64.rpm
下載完后,新建個目錄(在你安裝應用的目錄下即可,隨意),將這些剛下載的包放到目錄下,使用
[root@node1 gcc]# rpm -Uvh ppl-0.10.2-11.el6.x86_64.rpm
warning: ppl-0.10.2-11.el6.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 192a7d7d: NOKEY
error: Failed dependencies:
libgmp.so.3()(64bit) is needed by ppl-0.10.2-11.el6.x86_64
可以看到使用rpm -ivh 有依賴問題,所以我使用的忽略依賴,強制安裝
[root@node1 gcc]# rpm -ivh cloog-ppl-0.15.7-1.2.el6.x86_64.rpm --nodeps --force
warning: cloog-ppl-0.15.7-1.2.el6.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 192a7d7d: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:cloog-ppl-0.15.7-1.2.el6 ################################# [100%]
[root@node1 gcc]# rpm -ivh cpp-4.4.7-17.el6.x86_64.rpm --nodeps --force
warning: cpp-4.4.7-17.el6.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 192a7d7d: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:cpp-4.4.7-17.el6 ################################# [100%]
查看gcc是否安裝成功
[root@node1 redis-3.0.6]# gcc --version
gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-17)
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
所有的RPM包安裝完后,再使用make命令,拋出下面異常
[root@node1 redis-3.0.6]# make
cd src && make all
make[1]: Entering directory `/usr/local/development/redis-3.0.6/src'
CC adlist.o
/usr/libexec/gcc/x86_64-redhat-linux/4.4.7/cc1: error while loading shared libraries: libgmp.so.3: cannot open shared object file: No such file or directory
make[1]: *** [adlist.o] Error 1
make[1]: Leaving directory `/usr/local/development/redis-3.0.6/src'
make: *** [all] Error 2
說是缺少libgmp.so.3 我從http://www.rpmfind.net/linux/rpm2html/search.php?query=gmp&submit=Search+...&system=&arch=連接中下載里了 gmp-4.3.1-12.el6.x86_64.rpm 這個包並安裝,再次使用make還是拋出異常
[root@node1 redis-3.0.6]# make
cd src && make all
make[1]: Entering directory `/usr/local/development/redis-3.0.6/src'
CC adlist.o
In file included from adlist.c:34:
zmalloc.h:50:31: error: jemalloc/jemalloc.h: No such file or directory
zmalloc.h:55:2: error: #error "Newer version of jemalloc required"
make[1]: *** [adlist.o] Error 1
make[1]: Leaving directory `/usr/local/development/redis-3.0.6/src'
make: *** [all] Error 2
在Redis的目錄中有個redme文件,里面有這么一段
Selecting a non-default memory allocator when building Redis is done by setting
the `MALLOC` environment variable. Redis is compiled and linked against libc
malloc by default, with the exception of jemalloc being the default on Linux
systems. This default was picked because jemalloc has proven to have fewer
fragmentation problems than libc malloc.
To force compiling against libc malloc, use:
% make MALLOC=libc
To compile against jemalloc on Mac OS X systems, use:
% make MALLOC=jemalloc
Verbose build
這段大概意思是:在Redis時選擇一個內存分配器是通過MALLOC變量來設置的,jemalloc是Linux的默認的值。如果你的linux中沒有jemalloc 所以拋出這個異常。
使用make MALLOC=libc
安裝完成
.......
.......
.......
LINK redis-cli
CC redis-benchmark.o
LINK redis-benchmark
CC redis-check-dump.o
LINK redis-check-dump
CC redis-check-aof.o
LINK redis-check-aof
Hint: It's a good idea to run 'make test' ;)
make[1]: Leaving directory `/usr/local/development/redis-3.0.6/src'
在{redis_home}/src/ 下,啟動服務端 使用命令 ./redis-server
[root@node1 src]# ./redis-server
4017:C 16 Sep 15:06:57.727 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf
4017:M 16 Sep 15:06:57.727 * Increased maximum number of open files to 10032 (it was originally set to 1024).
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 3.0.6 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 4017
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
4017:M 16 Sep 15:06:57.728 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
4017:M 16 Sep 15:06:57.728 # Server started, Redis version 3.0.6
4017:M 16 Sep 15:06:57.728 # 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.
4017:M 16 Sep 15:06:57.728 # 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.
4017:M 16 Sep 15:06:57.728 * The server is now ready to accept connections on port 6379
4017:M 16 Sep 15:08:59.648 # User requested shutdown...
4017:M 16 Sep 15:08:59.648 * Saving the final RDB snapshot before exiting.
4017:M 16 Sep 15:08:59.649 * DB saved on disk
4017:M 16 Sep 15:08:59.649 # Redis is now ready to exit, bye bye...
在{redis_home}/src/ 下,啟動客戶端 使用命令 ./redis-cli
127.0.0.1:6379> set zhang 123
OK
127.0.0.1:6379> get zhang
"123"
查看redis 進程
[root@node1 redis-3.0.6]# ps -ef|grep redis
root 4071 3341 0 15:15 pts/4 00:00:00 ./redis-server *:6379
root 4075 3244 0 15:15 pts/2 00:00:00 grep --color=auto redis
=============================================================================================================================================================
停止redis 服務
[root@node1 src]# ./redis-cli shutdown
redis服務端
4071:M 16 Sep 15:17:03.867 # User requested shutdown...
4071:M 16 Sep 15:17:03.867 * Saving the final RDB snapshot before exiting.
4071:M 16 Sep 15:17:04.248 * DB saved on disk
4071:M 16 Sep 15:17:04.248 # Redis is now ready to exit, bye bye...
查看redis進程
[root@node1 src]# ps -ef |grep redis
root 4080 3341 0 15:19 pts/4 00:00:00 grep --color=auto redis
[root@node1 src]#
