linux安装redis

一、下载版本

1、通过wget命令下载

wget http://download.redis.io/releases/redis-4.0.10.tar.gz
2、从官网下载版本再上传到服务器

http://www.redis.io/

二、解压、编译

解压命令:tar xzf redis-4.0.10.tar.gz
进入目录:cd redis-4.0.10

编译:make

编译完成后会在src目录下生成可执行文件:

redis-benchmark:模拟N个客户端同时发出M个请求

redis-check-aof:aof修复命令

redis-check-rdb:db修复命令

redis-cli:redis客户端

redis-server:redis服务器

redis-sentinel:redis实例的监控管理、通知和实例失效备援服务,是redis集群的管理工具

新建一个redis目录,将可执行文件拷贝到redis目录,同时将redis-4.0.10目录下的redis.conf也拷贝到redis目录,如下:

[root@test redis]# pwd
/usr/redis
[root@test redis]# ll
total 10652
-rw-r--r--. 1 root root     144 Jul 17 09:34 dump.rdb
-rwxr-xr-x. 1 root root 2451256 Jul 17 09:17 redis-benchmark
-rwxr-xr-x. 1 root root 2617296 Jul 17 09:17 redis-cli
-rwxr-xr-x. 1 root root   58766 Jul 17 09:18 redis.conf
-rwxr-xr-x. 1 root root 5768688 Jul 17 09:16 redis-server
[root@test redis]# 

三、启动redis服务

可打开redis.conf文件,找到requirepass 关键字,把这行的注释删掉,输入期望设置的密码,即是设置密码,客户端访问时需要根据该值验证。

 ./redis-server redis.conf

如果需要redis服务后台启动,则修改redis.conf文件的daemonize no改为daemonize yes即可。

四、客户端访问

如果未设置密码,则直接执行redis-cli命令即可。

[root@test redis]# ./redis-cli -a password
127.0.0.1:6379> set test 123
OK
127.0.0.1:6379> get test
"123"
127.0.0.1:6379> del test
(integer) 1
127.0.0.1:6379> get test
(nil)
127.0.0.1:6379> 

五、安装中可能出现的问题

1、错误提示

    LINK redis-server
    INSTALL redis-sentinel
    CC redis-cli.o
    LINK redis-cli
    CC redis-benchmark.o
    LINK redis-benchmark
    INSTALL redis-check-rdb
    INSTALL redis-check-aof

Hint: It's a good idea to run 'make test' ;)

make[1]: Leaving directory `/usr/local/software/redis-4.0.10/src'
[root@test redis-4.0.10]# make test
cd src && make test
make[1]: Entering directory `/usr/local/software/redis-4.0.10/src'
    CC Makefile.dep
make[1]: Leaving directory `/usr/local/software/redis-4.0.10/src'
make[1]: Entering directory `/usr/local/software/redis-4.0.10/src'
You need tcl 8.5 or newer in order to run the Redis test
make[1]: *** [test] Error 1
make[1]: Leaving directory `/usr/local/software/redis-4.0.10/src'
make: *** [test] Error 2
[root@test redis-4.0.10]# 

解决办法:

安装tcl8.5以上的版本

wget http://downloads.sourceforge.net/tcl/tcl8.6.1-src.tar.gz
tar xzvf tcl8.6.1-src.tar.gz -C /usr/local/
cd /usr/local/tcl8.6.1/unix/
./configure
make
make install


2、错误提示

MAKE hiredis
cd hiredis && make static
make[3]: Entering directory `/usr/local/software/redis-4.0.10/deps/hiredis'
gcc -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/local/software/redis-4.0.10/deps/hiredis'
make[2]: *** [hiredis] Error 2
make[2]: Leaving directory `/usr/local/software/redis-4.0.10/deps'
make[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/local/software/redis-4.0.10/src'
make: *** [all] Error 2

解决方法:

应该是系统未安装gcc编译器引起,安装即可。
[root@test redis-4.0.10]# rpm -qa |grep gcc
libgcc-4.8.5-28.el7_5.1.x86_64
[root@test rredis-4.0.10]# cd ..
[root@test software]# yum  install  gcc

 

3、错误提示

In file included from adlist.c:34:0:
zmalloc.h:50:31: fatal error: jemalloc/jemalloc.h: No such file or directory
 #include <jemalloc/jemalloc.h>
                               ^
compilation terminated.
make[1]: *** [adlist.o] Error 1

解决方法:

make MALLOC=libc

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值