安装环境
系统:CentOS 7.6
Redis版本:6.0.6
安装包准备
wget http://download.redis.io/releases/redis-6.0.6.tar.gz
由于我的系统是mini安装,在安装时会有如下报错,在安装前先将下列包提前安装好
报错:make[3]: cc: Command not found
yum -y install cpp binutils glibc glibc-kernheaders glibc-common glibc-devel gcc
报错:server.c:5212:31: error: ‘struct redisServer’ has no member named ‘server_cpulist’
redisSetCpuAffinity(server.server_cpulist);
安装的时候碰到如上报错,需要升级scl,运行如下命令:
wget http://mirror.centos.org/centos/7/extras/x86_64/Packages/centos-release-scl-2-3.el7.centos.noarch.rpm
wget http://mirror.centos.org/altarch/7/extras/aarch64/Packages/centos-release-scl-rh-2-3.el7.centos.noarch.rpm
yum localinstall centos-release-scl*
yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
scl enable devtoolset-9 bash
echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile
安装Redis
tar -zxvf redis-6.0.6.tar.gz
mkdir -v /usr/local/redis
make install PREFIX=/usr/local/redis
配置Redis
mkdir /etc/redis
cp redis-6.0.6/redis.conf /etc/redis
配置文件参数说明:
-
绑定ip:如果需要远程访问,可将此行注释,或绑定一个真实IP
bind 127.0.0.1 -
端口:默认6379
port 6379 -
是否以守护进程运行
如果以守护进程运行,则不会在命令行阻塞,类似于服务
如果以非守护进程运行,则当前终端被阻塞
设置为yes表示守护进程,设置no 表示非守护进程
daemonize yes -
数据文件
dbfilename dump.rdb -
数据文件存储路径
dir /var/lib/redis -
日志文件
logfile /var/log/redis/redis-server.log -
数据库,默认有16个
database 16 -
主从复制,类似于双机备份
slaveof (默认没有配置)
配置
mkdir -v {/var/lib/redis,/var/log/redis}
sed -i s/"daemonize no"/"daemonize yes"/g /etc/redis/redis.conf
sed -i s@"dir ./"@"dir /var/lib/redis"@g /etc/redis/redis.conf
sed -i s@"logfile \"\""@"logfile \"/var/log/redis/redis-server.log\""@g /etc/redis/redis.conf
启动Redis 服务
/usr/local/redis/bin/redis-server /etc/redis/redis.conf