CentOS安装 redis-8.6.4
1、采用源码编译方式来安装,下载源码:
wget -c https://github.com/redis/redis/archive/refs/tags/8.6.4.tar.gz
2、解压代码包
tar -zxvf redis-8.6.4.tar.gz
3、make编译提示错误
make[3]: g++:命令未找到
make[3]: *** [fast_float_strtod.o] 错误 127
make[3]: 离开目录“/opt/redis-8.6.4/deps/fast_float”
make[2]: *** [fast_float] 错误 2
make[2]: 离开目录“/opt/redis-8.6.4/deps”
make[1]: [persist-settings] 错误 2 (忽略)
CC threads_mngr.o
In file included from server.h:57:0,
from threads_mngr.c:16:
zmalloc.h:30:31: 致命错误:jemalloc/jemalloc.h:没有那个文件或目录
#include <jemalloc/jemalloc.h>
^
编译中断。
make[1]: *** [threads_mngr.o] 错误 1
make[1]: 离开目录“/opt/redis-8.6.4/src”
make: *** [all] 错误 2
[root@localhost redis-8.6.4]#
4、安装相关依赖包
yum install gcc gcc-c++ jemalloc-devel -y
5、编译源码
cd /opt/redis-8.6.4
make
6、安装到系统
make install
7、启动redis
redis-server --daemonize yes
8、验证redis是否启动成功
ps -ef | grep redis

redis正常启动
停止redis
[root@localhost redis-8.6.4]# redis-cli shutdown
[root@localhost redis-8.6.4]#
[root@localhost redis-8.6.4]#
[root@localhost redis-8.6.4]# ps -ef|grep redis
root 11249 1825 0 16:47 pts/1 00:00:00 grep --color=auto redis
[root@localhost redis-8.6.4]#
[root@localhost redis-8.6.4]#
9、配置
cd /opt/redis-8.6.4/
cp redis.conf 6379.conf
vim 6379.conf
支持外网注释掉
# bind 127.0.0.1
更改
protected-mode no
设置密码
找到# requirepass foobared 去掉前面的注释#,
并把foobared 替换为你自己的密 码:123456!?
配置后台启动
daemonize yes
# 守护进程模式配置
# daemonize yes # 后台运行
# daemonize no # 前台运行(默认)
10、指定端口配置文件启动
redis-server ./6379.conf
11、设置防火墙端口
--permanent 永久生效,没有此参数重启后失效
firewall-cmd --zone=public --add-port=6379/tcp --permanent
重启防火墙
systemctl restart firewalld.service
12、配置开机启动服务
服务脚本,添加到 /etc/init.d/
vim redisd.sh
#!/bin/sh
# chkconfig: 2345 90 10
# description: Redis is a persitent key-val database
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
REDISPORT=6379
EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/bin/redis-cli
PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/opt/redis-8.6.4/${REDISPORT}.conf"
case "$1" in
start)
if [ -f $PIDFILE ]
then
echo "$PIDFILE exists, process is already running or crashed"
else
echo "Starting Redis server..."
$EXEC $CONF
fi
;;
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
PID=$(cat $PIDFILE)
echo "Stopping ..."
$CLIEXEC -p $REDISPORT -a "hh2018ccg!?" shutdown
while [ -x /proc/${PID} ]
do
echo "Waiting for Redis to shutdown ..."
sleep 1
done
echo "Reids stopped"
fi
;;
*)
echo "Please use start or stop as first argument"
;;
esac
13、赋予可执行权限
[root@hhkj2 init.d]# chmod +x redisd.sh
14、设置为开机自启动服务器
chkconfig redisd on
#打开服务
service redisd start
#关闭服务
service redisd stop

15、启动的时候有一个WARNING,要去掉提示进行如下配置
编辑配置文件:
vim /etc/sysctl.conf
添加或修改这一行:
vm.overcommit_memory = 1
加载配置:
sysctl -p
之后再重启 Redis 就不会再报这个警告了:
service redisd restart
16、reboot重启测试

redis正常启动,至此安装OK。
更多推荐



所有评论(0)