安装 redis [standlone模式]

下载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]#

原文地址:https://www.cnblogs.com/zhangXingSheng/p/7526771.html