1、下载Redis
链接:https://redis.io/download
安装最新版本使用remi:
wget http://rpmfind.net/linux/remi/enterprise/7/test/x86_64/redis-4.0.0-1.el7.remi.x86_64.rpm
2、yum安装
yum install redis-4.0.0-1.el7.remi.x86_64.rpm
错误提示:需要:libjemalloc.so.1()(64bit) (解决方法配置eple的yum源)
3、配置epel的yum源
yum install http://mirrors.163.com/centos/7.4.1708/extras/x86_64/Packages/epel-release-7-9.noarch.rpm
4、启动服务
systemctl stat redis
netstat -lnupt | grep 6379
ps -ef | grep redis
lsof -i tcp:6379
5、登陆
#redis-cli
1、下载Redis
链接:https://redis.io/download
2、依赖关系
yum install gcc gcc-c++ make -y
3、编译
# make
# make PREFIX=/usr/local/redis install
make报jemalloc/jemalloc.h错误
[root@resiones src]# make
CC adlist.o
In file included from adlist.c:34:0:
zmalloc.h:50:31: 致命错误:jemalloc/jemalloc.h:没有那个文件或目录
#include
解决办法
make MALLOC=libc
查看README
To force compiling against libc malloc, use:
% make MALLOC=libc
To compile against jemalloc on Mac OS X systems, use:
% make MALLOC=jemalloc
make install PREFIX=/usr/local/redis/bin
4、进入/usr/local/redis/bin
命令解释:
1、redis-server 启动redis服务
2、redis-cli redis客户端工具
3、redis-benchmark redis性能测试
4、redis-check-rdb 检测rdb文件
5、redis-check-aof 检测aof日志文件
5、创建用户和组
groupadd -g 935 -r redis
useradd -u 935 -g 935 -r -d /var/lib/redis -c “redis server” -s /sbin/nologin redis
mkdir -p /var/lib/redis
chown -R redis /var/lib/redis
chmod -R 700 /var/lib/redis
6、修改配置文件 redis.conf
dir /var/lib/redis/
daemonize yes #后台运行
7、创建服务脚本
# vim /usr/lib/systemd/system/redis.service
[Unit]
Description=Redis persistent key-value database
After=network.target
After=network-online.target
Wants=network-online.target
[Service]
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/bin/redis.conf --supervised systemd
ExecStop=/usr/local/redis/bin/redis-shutdown
Type=notify
User=redis
Group=redis
RuntimeDirectory=redis
RuntimeDirectoryMode=0755
[Install]
WantedBy=multi-user.target
[root@resiones ~]# vim /usr/local/redis/bin/redis-shutdown
#!/bin/bash
#
# Wrapper to close properly redis and sentinel
test x"$REDIS_DEBUG" != x && set -x
REDIS_CLI=/usr/local/redis/bin/redis-cli
# Retrieve service name
SERVICE_NAME=redis
# Get the proper config file based on service name
CONFIG_FILE="/usr/local/redis/bin/$SERVICE_NAME.conf"
# Use awk to retrieve host, port from config file
HOST=`awk '/^[[:blank:]]*bind/ { print $2 }' $CONFIG_FILE | tail -n1`
PORT=`awk '/^[[:blank:]]*port/ { print $2 }' $CONFIG_FILE | tail -n1`
PASS=`awk '/^[[:blank:]]*requirepass/ { print $2 }' $CONFIG_FILE | tail -n1`
SOCK=`awk '/^[[:blank:]]*unixsocket\s/ { print $2 }' $CONFIG_FILE | tail -n1`
# Just in case, use default host, port
HOST=${HOST:-127.0.0.1}
if [ "$SERVICE_NAME" = redis ]; then
PORT=${PORT:-6379}
else
PORT=${PORT:-26739}
fi
# Setup additional parameters
# e.g password-protected redis instances
[ -z "$PASS" ] || ADDITIONAL_PARAMS="-a $PASS"
# shutdown the service properly
if [ -e "$SOCK" ] ; then
$REDIS_CLI -s $SOCK $ADDITIONAL_PARAMS shutdown
else
$REDIS_CLI -h $HOST -p $PORT $ADDITIONAL_PARAMS shutdown
fi
redis-cli -h host -p port -a password
1.启动redis
进入redis目录
redis-cli
2.数据备份
redis 127.0.0.1:6379> SAVE
该命令将在 redis 备份目录中创建dump.rdb文件。
1、如果需要恢复数据,只需将备份文件 (dump.rdb) 移动到 redis 安装目录并启动服务即可。获取 redis 目录可以使用 CONFIG 命令,
redis 127.0.0.1:6379> CONFIG GET dir
1) "dir"
2) "/usr/local/redis/bin"
以上命令 CONFIG GET dir 输出的 redis 备份目录为 /usr/local/redis/bin。
2、停止redis服务
3、拷贝备份文件到 /usr/local/redis/bin目录下
4、重新启动redis服务