下载
https://redis.io/download,建议选择稳定版本
上传到 服务器
-rw-r--r--. 1 root root 2228781 8月 17 23:16 redis-6.0.6.tar.gz
[root@localhost software]# pwd
/home/software
安装redis
解压redis
tar -zxvf redis-6.0.6.tar.gz
解压后
drwxrwxr-x. 7 root root 4096 7月 21 02:08 redis-6.0.6
-rw-r--r--. 1 root root 2228781 8月 17 23:16 redis-6.0.6.tar.gz
安装gcc编译环境
yum install gcc-c++
进入redis-6.0.6目录进行安装
[root@localhost software]# cd redis-6.0.6
[root@localhost redis-6.0.6]# make && make install
如果报以下错误 structredisServer没有名为XXXX的成员
升级gcc
yum -y install centos-release-scl
yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
scl enable devtoolset-9 bash
- 执行make test出错解决方案
[root@localhost redis-6.0.6]# yum install tcl
[root@localhost redis-6.0.6]# make test
安装完成
配置redis,在utils下,拷贝redis_init_script到**/etc/init.d**目录,目的要把redis作为开机自启动
[root@localhost redis-6.0.6]# cd utils/
[root@localhost utils]# pwd
/home/software/redis-6.0.6/utils
[root@localhost utils]# cp redis_init_script /etc/init.d/
创建 /usr/local/redis,用于存放配置文件,拷贝redis配置文件
[root@localhost utils]# mkdir /usr/local/redis
[root@localhost utils]# cp /home/software/redis-6.0.6/redis.conf /usr/local/redis/
修改核心配置文件redis.conf
[root@localhost utils]# cd /usr/local/redis/
[root@localhost redis]# vim redis.conf
#修改 daemonize no -> daemonize yes,目的是为了让redis启动在linux后台运行
daemonize yes
#修改redis的工作目录
dir /usr/local/redis/working
#绑定ip 改为0.0.0.0 代表可以让远程连接,不受ip限制
bind 0.0.0.0
#密码修改
requirepass 123456
修改 redis_init_script 文件中的redis核心配置文件
vim /etc/init.d/redis_init_script
REDISPORT=6379
EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/bin/redis-cli
PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/usr/local/redis/redis.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 ..."
# 关闭redis 输入密码
$CLIEXEC -a "123456" -p $REDISPORT shutdown
while [ -x /proc/${PID} ]
do
echo "Waiting for Redis to shutdown ..."
sleep 1
done
echo "Redis stopped"
fi
;;
*)
echo "Please use start or stop as first argument"
;;
esac
为redis启动脚本添加执行权限,然后启动redis
[root@localhost redis]# cd /etc/init.d/
[root@localhost redis]# chmod 777 /etc/init.d/redis_init_script
[root@localhost init.d]# ./redis_init_script start
Starting Redis server...
39685:C 18 Aug 2020 00:06:12.629 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
39685:C 18 Aug 2020 00:06:12.629 # Redis version=6.0.6, b
检查redis进程
[root@localhost init.d]# ps -ef | grep redis
root 39541 1 0 8月17 pts/0 00:00:03 src/redis-server 127.0.0.1:27617
root 39691 36702 0 00:06 pts/0 00:00:00 grep --color=auto redis
设置redis开机自启动,修改 redis_init_script,添加如下内容
#chkconfig: 22345 10 90
#description: Start and Stop redis
#chkconfig: 22345 10 90
#description: Start and Stop redis
REDISPORT=6379
EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/bin/redis-cli
PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/usr/local/redis/redis.conf"
随后执行
chkconfig redis_init_script on
虚拟机重启后redis自动启动再看进程
[root@localhost ~]# ps -ef |grep redis
root 908 1 0 00:47 ? 00:00:00 /usr/local/bin/redis-server 0.0.0.0:6379
root 3099 3076 0 00:48 pts/0 00:00:00 grep --color=auto redis