redis 安装 与错误解决办法

redis 安装与安装中遇到的错误

redis 安装

wget http://download.redis.io/releases/redis-4.0.11.tar.gz
tar xzf redis-4.0.11.tar.gz
cd redis-4.0.11
make

启动服务端

src/redis-server

客户端连接与测试

src/redis-cli
redis> set foo bar
OK
redis> get foo
"bar"

redis常用命令

redis-cli

-h  指定远程登陆ip
-p  指定远程redis访问端口
-n  指定库b编号
-a  指定密码

示例
./redis-cli  -h 127.0.0.1  -p 6379 -n 3  -a djx

远程执行命令
清空所有的数据
./redis-cli  -h 127.0.0.1  -p 6379 -n 3  -a djx  flushall

redis 常用配置

redis设置密码

临时生效

       在命令行用  config set  requirepass  password  来进行设置。重启redis后即失效。

[root@djx2 src]# ./redis-cli 
127.0.0.1:6379> config set  requirepass djx
OK
127.0.0.1:6379> config get  requirepass
(error) NOAUTH Authentication required.
127.0.0.1:6379> auth djx
OK
127.0.0.1:6379> config get  requirepass
1) "requirepass"
2) "djx"

永久生效

  通过在redis的配置文件redis.conf 进行配置,在配置文件中有个参数: requirepass  这个就是配置redis访问密码的参数;

requirepass password

然后我们启动的时候需要指定我们的配置文件进行启动。 

redis-server  /etc/redis.conf

 redis 指定端口

默认是6379,我们可以更改成公司内部统一的端口。

port 6379

redis  指定监听

redis 默认绑定的是 127.0.0.1 ,也就是只能本地访问了,如果我们需要让外网也可以进行访问,那么我们需要更改默认的绑定。

bind  0.0.0.0

这样我们就可以让应用访问了。

redis 指定日志文件存放位置

默认日志文件的存放位置是为空的,也就是直接在控制台输出了。

我们可以在logfile中配置日志文件路径。

logfile "/var/log/redis.log"

redis 指定数据存放位置(要指定)

在redis.conf 的 

# The filename where to dump the DB
dbfilename dump.rdb  #指定数据存放的文件名称

# The working directory.
#
# The DB will be written inside this directory, with the filename specified
# above using the 'dbfilename' configuration directive.
#
# The Append Only File will also be created inside this directory.
#
# Note that you must specify a directory here, not a file name.
dir ./   #指定数据存放的位置。
创建目录
mkdir /opt/redis/data/ 在配置文件中指定目录 dir /opt/redis/data/

redis 开启rdbchecksum

该参数,在3.2版本和4.0版本是默认开启的,但是在2.4版本中是没有开启的,该参数我们进行使用dump.rdb文件时是有作用的,因为在使用dump.rdb 的时候有该值是会效验该文件的完整性。rdbchecksum设置为no的话就不会效验该文件的完整性。

redis 后台运行

我们可以使用nohup和& 让redis在后台正常运行,并写入日志到/var/log/redis.log

nohup  ./src/redis-server   ./redis.conf  >>/var/log/redis.log 2>&1 &

安装中遇到的错误

错误1   gcc  编译器没有安装

解决办法 : 安装gcc  编译器

yum  install  gcc  -y

错误2  jemalloc/jemalloc.h: No such file or directory。 (注意,这里需要特别注意)

针对这个错误,我们可以在README.md 文件中看到解释。

---------

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
-------------

网上大部分解决办法都是错误的,如下文:

centos(错误解决办法)

make MALLOC=libc

正确解决办法(针对2.2以上的版本)

make distclean  && make

导致出现这个错误的原因

  错误的本质是我们在开始执行make 时遇到了错误(大部分是由于gcc未安装),然后我们安装好了gcc 后,我们再执行make  ,这时就出现了jemalloc/jemalloc.h: No such file or directory。这是因为上次的

编译失败,有残留的文件,我们需要清理下,然后重新编译就可以了。

网上的解决办法是有什么错误吗?

  网上的解决办法虽然最后也是可以成功安装好 redis ,但是是有一些隐患的,首先我们要知道redis 需要使用内存分配器的, make  MALLOC=jemalloc  就是指定内存分配器为 jemalloc ,make MALLOC=libc 就是指定内存分配器为 libc ,这个是有安全隐患的,jemalloc 内存分配器在实践中处理内存碎片是要比libc 好的,而且在README.md 文档也说明到了,jemalloc内存分配器也是包含在源码包里面的,可以在deps  目录下看到 jemalloc 目录。

以上就是我在安装的时候遇到的问题,后续如果还有其他会继续补充。

转载于:https://www.cnblogs.com/operationhome/p/9752935.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值