首页 > 代码库 > Linux系统下安装单台Redis

Linux系统下安装单台Redis

搭建redis前一定要安装gcc

redis安装方式一

1.安装gcc命令:yum install -y gcc

#安装gcc
[root@localhost src]# yum install -y gcc

#出现如下信息则安装成功
Installed:
gcc.x86_64 0:4.4.7-17.el6

Dependency Installed:
cloog-ppl.x86_64 0:0.15.7-1.2.el6 cpp.x86_64 0:4.4.7-17.el6 mpfr.x86_64 0:2.4.1-6.el6 ppl.x86_64 0:0.10.2-11.el6

Complete

#查看gcc方式1
[root@localhost src]# gcc -v 
Using built-in specs.
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info......
Thread model: posix
gcc version 4.4.7 20120313 (Red Hat 4.4.7-17) (GCC)

#查看gcc方式2
[root@localhost src]# rpm -q gcc 
gcc-4.4.7-17.el6.x86_64

2.下载网址

redis官网地址:http://www.redis.io/

redis下载地址:http://download.redis.io/releases/

3.以centos6.5系统,redis3.2.4版本为例,把下载好的redis压缩包传到linxu系统中,进行解压.

[root@localhost redis]# tar zxvf redis-3.2.4.tar.gz

4.编译安装,执行命令 make

#执行命令
[root@localhost redis-3.2.4]# make

#出现以下信息则表示安装完成
Hint: It‘s a good idea to run ‘make test‘ ;)

make[1]: Leaving directory `/usr/redis/redis-3.2.4/src‘

5.启动redis

[root@localhost redis-3.2.4]# src/redis-server

6.安装出现错误情况

(1)执行make命令出现如下错误,则没有安装gcc,按照上面安装方法安装gcc

[root@localhost redis]# cd redis-3.2.4/
[root@localhost redis-3.2.4]# make cd src && make all sh: ./mkreleasehdr.sh: Permission denied make[1]: Entering directory `/usr/redis/redis-3.2.4/srcrm -rf redis-server redis-sentinel redis-cli redis-benchmark redis-check-rdb redis-check-aof *.o *.gcda *.gcno *.gcov redis.info lcov-html (cd ../deps && make distclean) make[2]: Entering directory `/usr/redis/redis-3.2.4/deps(cd hiredis && make clean) > /dev/null || true (cd linenoise && make clean) > /dev/null || true (cd lua && make clean) > /dev/null || true (cd geohash-int && make clean) > /dev/null || true (cd jemalloc && [ -f Makefile ] && make distclean) > /dev/null || true (rm -f .make-*) make[2]: Leaving directory `/usr/redis/redis-3.2.4/deps(rm -f .make-*) echo STD=-std=c99 -pedantic -DREDIS_STATIC=‘‘ >> .make-settings echo WARN=-Wall -W >> .make-settings echo OPT=-O2 >> .make-settings echo MALLOC=jemalloc >> .make-settings echo CFLAGS= >> .make-settings echo LDFLAGS= >> .make-settings echo REDIS_CFLAGS= >> .make-settings echo REDIS_LDFLAGS= >> .make-settings echo PREV_FINAL_CFLAGS=-std=c99 -pedantic -DREDIS_STATIC=‘‘ -Wall -W -O2 -g -ggdb -I../deps/geohash-int -I../deps/hiredis -I../deps/linenoise -I../deps/lua/src -DUSE_JEMALLOC -I../deps/jemalloc/include >> .make-settings echo PREV_FINAL_LDFLAGS= -g -ggdb -rdynamic >> .make-settings (cd ../deps && make hiredis linenoise lua geohash-int jemalloc) make[2]: Entering directory `/usr/redis/redis-3.2.4/deps(cd hiredis && make clean) > /dev/null || true (cd linenoise && make clean) > /dev/null || true (cd lua && make clean) > /dev/null || true (cd geohash-int && make clean) > /dev/null || true (cd jemalloc && [ -f Makefile ] && make distclean) > /dev/null || true (rm -f .make-*) (echo "" > .make-ldflags) (echo "" > .make-cflags) MAKE hiredis cd hiredis && make static make[3]: Entering directory `/usr/redis/redis-3.2.4/deps/hiredisgcc -std=c99 -pedantic -c -O3 -fPIC -Wall -W -Wstrict-prototypes -Wwrite-strings -g -ggdb net.c make[3]: gcc: Command not found make[3]: *** [net.o] Error 127 make[3]: Leaving directory `/usr/redis/redis-3.2.4/deps/hiredismake[2]: *** [hiredis] Error 2 make[2]: Leaving directory `/usr/redis/redis-3.2.4/depsmake[1]: [persist-settings] Error 2 (ignored) CC adlist.o /bin/sh: cc: command not found make[1]: *** [adlist.o] Error 127 make[1]: Leaving directory `/usr/redis/redis-3.2.4/srcmake: *** [all] Error 2

 (2)执行maker出现如下错误,则没有权限执行命令,要在 /src 目录执行授权命令:chmod 777 mkreleasehdr.sh

#1.执行make报错,则没有权限执行命令
[root@localhost redis-3.2.4]# make
cd src && make all
sh: ./mkreleasehdr.sh: Permission denied
make[1]: Entering directory `/usr/redis/redis-3.2.4/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/redis/redis-3.2.4/srcmake: *** [all] Error 2

#2.授权
[root@localhost src]# chmod 777 mkreleasehdr.sh

 (3)执行make出现如下错误,则要配置变量

#1.错误信息
make[1]: Entering directory `/usr/redis/redis-3.2.4/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/redis/redis-3.2.4/srcmake: *** [all] Error 2

#2.添加变量
[root@localhost src]# make MALLOC=libc

(4)执行 make MALLOC=libc 命令报错 或 还有其他错误,建议删除redis所有文件重新装,或者按照下面的方式安装.

 

redis安装方式二

1.在线下载redis(默认下载 /root 文件下)

[root@localhost ~]# wget http://download.redis.io/releases/redis-3.2.4.tar.gz

#要是出现如下错误则没有配置好linux环境变量
#bash:command not found

2.移动到指定文件夹下,进行解压

#移动文件
[root@localhost ~]# mv /root/redis-3.2.4.tar.gz /usr/redis
#解压文件
[root@localhost ~]# tar -xzvf redis-3.2.4.tar.gz

3.执行make编译

[root@localhost redis-3.2.4]# make

#出现以下信息则安装完成
Hint: It‘s a good idea to run ‘make test‘ ;)

make[1]: Leaving directory `/usr/redis/redis-3.2.4/src‘

4.启动redis

#启动后不会在后台运行,按Ctrl+C就会停止
[root@localhost redis-3.2.4]# src/redis-server

#加&符号启动后在后台运行
[root@localhost redis]# src/redis-server &

5.启动成功

技术分享

6.查看redis版本号

进入redis的安装目录src下面

#方式1
[root@svr-zk src]# redis-cli -v
redis-cli 3.2.4

#方式2
[root@svr-zk src]# redis-cli --version
redis-cli 3.2.4

#方式3
[root@svr-zk src]# redis-server -v 
Redis server v=3.2.4 sha=00000000:0 malloc=jemalloc-4.0.3 bits=64 build=54077ebb4b018819

 

Linux系统下安装单台Redis