redis 安装与安装中遇到的错误html
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
启动服务端redis
src/redis-server
客户端链接与测试centos
src/redis-cli redis> set foo bar OK redis> get foo "bar"
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
临时生效ide
在命令行用 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"
永久生效ui
经过在redis的配置文件redis.conf 进行配置,在配置文件中有个参数: requirepass 这个就是配置redis访问密码的参数;this
requirepass password
而后咱们启动的时候须要指定咱们的配置文件进行启动。 spa
redis-server /etc/redis.conf
默认是6379,咱们能够更改为公司内部统一的端口。命令行
port 6379
redis 默认绑定的是 127.0.0.1 ,也就是只能本地访问了,若是咱们须要让外网也能够进行访问,那么咱们须要更改默认的绑定。
bind 0.0.0.0
这样咱们就可让应用访问了。
默认日志文件的存放位置是为空的,也就是直接在控制台输出了。
咱们能够在logfile中配置日志文件路径。
logfile "/var/log/redis.log"
在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/
该参数,在3.2版本和4.0版本是默认开启的,可是在2.4版本中是没有开启的,该参数咱们进行使用dump.rdb文件时是有做用的,由于在使用dump.rdb 的时候有该值是会效验该文件的完整性。rdbchecksum设置为no的话就不会效验该文件的完整性。
咱们可使用nohup和& 让redis在后台正常运行,并写入日志到/var/log/redis.log
nohup ./src/redis-server ./redis.conf >>/var/log/redis.log 2>&1 &
useradd -M -s /sbin/nologin [username]
Redis 无权限分离,其管理员帐号和普通帐号无明显区分。攻击者登陆后可执行任意操做,所以须要隐藏如下重要命令:FLUSHDB, FLUSHALL, KEYS,PEXPIRE, DEL, CONFIG, SHUTDOWN, BGREWRITEAOF, BGSAVE, SAVE, SPOP, SREM, RENAME,DEBUG, EVAL
。
咱们能够隐藏,也能够将这些命令设置为复杂的字符。
隐藏命令和重命名命令须要在 配置文件中配置 redis.conf。
隐藏命令
rename-command CONFIG ""
rename-command FLUSHALL ""
rename-command FLUSHDB ""
rename-command SHUTDOWN ""
重命名命令
rename-command CONFIG FYConfigdjx rename-command FLUSHALL FYFlushalldjx rename-command FLSUHDB FYFlushdbdjx rename-command SHUTDOWN FYShutdowndjx
错误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 目录。
以上就是我在安装的时候遇到的问题,后续若是还有其余会继续补充。