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  编译器没有安装

redis 安装 json redis 安装报错follow_redis

解决办法 : 安装gcc  编译器



yum  install  gcc  -y



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

redis 安装 json redis 安装报错follow_c/c++_02

针对这个错误,我们可以在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



导致出现这个错误的原因

jemalloc/jemalloc.h: No such file or directory。这是因为上次的

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

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

网上的解决办法虽然最后也是可以成功安装好 redis ,但是是有一些隐患的,首先我们要知道redis 需要使用内存分配器的,

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