安装并配置Redis数据库

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/shiheyingzhe/article/details/86548596

下载并安装

wget  http://download.redis.io/releases/redis-5.0.3.tar.gz //获取稳定版的redis  

tar -xzvf redis-5.0.3.tar.gz   //解压

cd redis-5.0.3 //进入解压目录

make    //编译安装

make install    //将可执行程序赋值到/usr/local/bin目录中,当执行程序中就不要输入完整的路径

make test   //测试redis是否编译正确

 

移动redis.conf

mkdir /etc/redis

sudo cp  ./redis.conf /etc/redis/redis.conf

 

修改redis.conf配置文件

Redis不是在后台运行,我们需要把redis放在后台运行

sudo gedit /etc/redis/redis.conf

将daemonize的值改为yes

 

备份与恢复:

修改dir为dump.rdb文件存放的路径

dbfilename dump.rdb

# The working directory.

#

# The DB will be written inside this directory, with the filename specified

# above using the 'dbfilename' configuration directive.

#

# The Append Only File will also be created inside this directory.

#

# Note that you must specify a directory here, not a file name.

dir /home/disks/project/dog

修改dir为appendonly.aof文件存放的路径

appendonly yes

# The name of the append only file (default: "appendonly.aof")

appendfilename "appendonly.aof"

dir /home/disks/project/dog

设置开机自启动:
sudo cp ./utils/redis_init_script /etc/init.d/redis # 复制文件

cd /etc/init.d/ # 进入文件目录

sudo vim redis # 编辑配置文件redis

只修改其中不同的地方

#!/bin/sh

# Simple Redis init.d script conceived to work on Linux systems

# as it does use of the /proc filesystem.

 

### BEGIN INIT INFO

# Provides:     redis_6379

# Required-Start:      

# Required-Stop:       

# Default-Start:        2 3 4 5

# Default-Stop:         0 1 6

# Short-Description:    Redis data structure server

# Description:          Redis data structure server. See https://redis.io

### END INIT INFO

 

REDISPORT=6379

EXEC=/usr/local/bin/redis-server

CLIEXEC=/usr/local/bin/redis-cli

 

PIDFILE=/var/run/redis_${REDISPORT}.pid

CONF="/etc/redis/redis.conf" ========

修改完配置文件后执行下面两条命令

sudo chmod +x /etc/init.d/redis # 取得权限

sudo update-rc.d redis defaults # 加载到系统自启动文件

 //如果报错,查看/etc/init.d/redis和上述有什么不同

 

然后开启redis服务: service redis start,查看服务的状态service redis status

显示这个表示开启成功

 

其他的命令:

开启redis: service redis start

停止redis: service redis stop

重启redis: service redis restart

查看服务状态: service redis status

猜你喜欢

转载自blog.csdn.net/shiheyingzhe/article/details/86548596