一、整体架构说明
这里安装的redis为单节点redis,版本号为4.0.2
二、准备工作
http://download.redis.io/releases/redis-4.0.2.tar.gz 下载redis
三、安装redis
先把tar包解压至/usr/local目录下
tar -zxvf redis-4.0.2.tar.gz -C /usr/local/
做软连接
cd /usr/local/
ln -s redis-4.0.2 redis
编译
cd redis
make
make test
若出现报错You need tcl 8.5 or newer in order to run the Redis test,则yum -y install tcl-8.5*,安装完成后再make test,显示All tests passed without errors!
修改redis的目录结构
mkdir bin conf others
mv redis.conf sentinel.conf conf/
cd src/
mv redis-cli redis-sentinel redis-server ../bin/
四、修改redis配置文件redis.conf
1)修改监听地址
bind 192.168.0.12
2)daemonize no 修改为 daemonize yes
daemonize <yes|no>:是否以后台daemon方式运行 #yes|no(default:no)
3)port 6379
4)修改redis的日志文件地址
logfile "" 修改为 logfile "/data/redis/log/redis.log"
5)snapshoting的持久化方式
save 900 1 #在900秒内有1个key发生了变化
save 300 10 #在300秒内有10个key发生了变化
save 60 10000 #在900秒内有10000个key发生了变化
6)修改两个持久化文件(rdb和aof)的位置
dir ./ 修改为 dir /data/redis/
7)开启aof的持久化方式
appendonly no 修改为 appendonly yes
8)修改redis密码
# requirepass foobared 修改为 requirepass 123456
创建redis日志文件和两个持久化方式的目录
mkdir -p /data/redis/log
五、启动redis
由于之前修改了目录结构,所以启动方式如下:
cd bin/
./redis-server ../conf/redis.conf