(一)Redis数据库-在centos7中安装Redis5.0

x33g5p2x  于2021-12-19 转载在 其他  
字(0.8k)|赞(0)|评价(0)|浏览(476)

redis官网:https://redis.io/
上面的连接是下载最新版,下面的连接是查看历史版本。我这里直接复制最新版连接安装。

#centos中默认没有安装wget,先安装wget
yum install wget -y

#连接中下载的是redis的源码包,需要c环境编译安装,我这里使用gcc
yum install gcc -y

#下载
wget http://download.redis.io/releases/redis-5.0.4.tar.gz

#解压
tar -zxvf redis-5.0.4.tar.gz

#切换到安装目录
cd redis-5.0.4

#编译
make
我这里报:MALLOC=jemalloc错误,可以安装jemalloc再编译,或者如下最简单的方式
make MALLOC=libc

#经过漫长的编译切换到src目录就可以启动服务了
cd src
./redis-server

出现如下页面表示redis安装完成并且已经启动。


默认情况下redis是前台启动的,需要改为后台启动。

vi ../redis.conf

daemonize no    #设置为yes改为后台启动

如果需要在非本机外的网络访问还需要如下操作

#修改配置文件
vi ../redis.conf

bind 127.0.0.1    #前面加#注释掉,允许外网访问,默认只能本机
protected-mode yes    #改为no,关闭保护模式允许外网访问

打开防火墙6379端口

#查看6379端口是否开启
firewall-cmd --permanent --query-port=6379/tcp

#允许外部访问6379端口
firewall-cmd --zone=public --add-port=6379/tcp --permanent

#配置生效
systemctl restart firewalld.service

保存配置文件后再次启动,默认就是在后台启动了,而且允许其他主机连接。

./redis-server ../redis.conf

相关文章