3

在Centos7上安装Redis6

 2 years ago
source link: https://segmentfault.com/a/1190000041101602
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Redis是一个非常流行的NOSQL数据库,拥有的数据类型非常丰富,此处我们简单记录一下在Centos7上是如何安装Redis6的。Redis的安装是推荐使用源码进行安装的。

二、安装步骤

1、安装gcc依赖

安装Redis需要的依赖

2、下载redis6

wget https://download.redis.io/releases/redis-6.2.6.tar.gz

下载链接

3、解压编译

# 解压
tar -zxvf redis-6.2.6.tar.gz
# 进入解压后的目录
cd redis-6.2.6
# 执行编译,如果make出错,可以看下方 可能出现的错误 的这个标题
make

1、安装到默认的位置

make install

2、安装redis到指定的位置

make PREFIX=具体的路径 install

此处我们安装到默认的路径下。

5、启动redis

1、前台启动

redis-server

2、后台启动

vim redis.conf,这个文件默认在redis-6.2.6/redis.conf
修改

daemonize yes
redis-server redis.conf

6、防火墙放行6379端口

[root@centos01 redis-6.2.6]# firewall-cmd --zone=public --add-port=6379/tcp --permanent
success
[root@centos01 redis-6.2.6]# firewall-cmd --reload
success

7、连接到redis

[appuser@centos01 ~]$ redis-cli -h 127.0.0.1 -p 6379
127.0.0.1:6379>

三、redis的简单配置

配置项值解释port6379客户端通讯端口,redis服务器启动的端口daemonizeyes以后台的方式运行bind192.168.56.101redis服务启动时绑定的ip地址,是本地网卡的地址pidfile/var/run/redis_6379.pid当是以后台方式运行时,会产生一个pid文件logfile/var/log/redis_6379.log指定日志文件的路径dir./数据库的持久化文件保存的路径,必须是目录appendonlyyes打开aof持久化appendfsynceverysecaof每秒写入一次appendfilenameappendonly.aofaof文件名requirepass123456设置一个redis的密码,可以设置的复杂一些maxclients10000设置最大可以有多少个连接连接到redis servermaxmemory2GB设置redis最多可用的内存

四、可能出现的错误

1、zmalloc.h:50:31: 致命错误:jemalloc/jemalloc.h:没有那个文件或目录

可能出现的错误
经过百度,可知通过make MALLOC=libc命令解决。

2、如果出现了Connection refused

1、检查redis端口是否放行
2、检查redis.conf 中bind的值,默认只能通过127.0.0.1来访问。
学习测试可以配置成 bind 0.0.0.0,生产环境不可以。

3、如果rdb保存失败时

rbd失败日志如果出现了如下日志时的处理
如果出现了如上日志,那么我们可以修改vm.overcommit_memory=1来解决。

五、参考文档

1、Redis Quick Start


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK