您的位置:首页 > 数据库 > Redis

Linux 下 Redis 6 的安装使用(Ubuntu 18.04)

2020-08-07 12:39 495 查看

Redis 的安装使用


我的小站Github


Redis(Remote Dictionary Server )是一个使用ANSI C编写的开源、支持网络、基于内存、可选持久性的键值对存储数据库,提供了多种语言的API。


下面是 Ubuntu 18.04 系统上安装Redis简易版教程



第一步:下载安装包

  1. 获取下载地址

    Redis官方网站:https://redis.io/


  1. 选择安装路径,我选择的是 /root/tools/software/
cd tools/software/


  1. 下载Redis安装包(6.0.5为版本号,可更换成最新的版本号,若连接更换,请移步官网)
wget  http://download.redis.io/releases/redis-6.0.5.tar.gz



第二步:安装

  1. 解压(请使用对应的文件名)
tar  -xvf  redis-6.0.5.tar.gz


图文过长,只截取前面一部分



  1. 创建软链接(为了方便,非必须,如果没有创建,接下来的涉及到redis路径请用redis-6.0.5)

​ ln -s 原始目录名 快速访问目录名

ln -s redis-6.0.5 redis


  1. 进入redis目录,对解压的Redis文件进行编译
cd redis
make


如果没有配置好编译环境,则使用以下命令配置:

yum install gcc-c++

  1. 进入src文件夹进行Redis安装
cd  src
make  install



第三步:部署

  1. 回到redis目录下,创建data、conf文件夹用于保存数据和配置文件
cd ..
mkdir data
mkdir conf


  1. 进入conf目录,编写配置文件 redis-端口号.conf

例:redis-6379.conf (除了带注释的行,其他均为默认设置,见redis目录下的redis.conf文件)

#  绑定的ip,请根据需求自行更换
bind 127.0.0.1
protected-mode yes
#  端口设置
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
#  以守护进程的方式启动,redis以服务的形式存在,日志不再打印到命令窗口中
daemonize yes
supervised no
pidfile /var/run/redis_6379.pid
loglevel notice
#  日志文件名
logfile "6379.log"
databases 16
always-show-logo yes
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
rdb-del-sync-files no
#  当前服务文件保存位置,包含日志文件、持久化文件等
dir ../data
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-diskless-load disabled
repl-disable-tcp-nodelay no
replica-priority 100
acllog-max-len 128
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
lazyfree-lazy-user-del no
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
stream-node-max-bytes 4096
stream-node-max-entries 100
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
dynamic-hz yes
aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes
jemalloc-bg-thread yes
# 内存到达上限之后的处理策略
maxmemory-policy noeviction
# 1. volatile-lru:对设置了过期时间的key执行LRU逐出策略(默认值)
# 2. allkeys-lru : 对所有key使用LRU逐出策略
# 3. volatile-random:随机删除即将过期key(LFU)
# 4. allkeys-random:随机删除
# 5. volatile-ttl : 删除即将过期的
# 6. noeviction : 永不过期,返回错误


第四步:测试

  1. 指定配置文件开启redis服务
redis-server redis-6379.conf

  1. 连接指定服务器(请使用对应的IP和端口号)
redis-cli -h 127.0.0.1 –port 6379

  1. set、get测试
set name redis
get name




PS:

Linux命令:

  1. 查看当前redis服务进程:
ps -ef | grep redis

  1. 去除空行和注释行复制 redis.conf (在redis目录下复制到conf目录):
grep -Ev "^$|#" redis.conf >  ./conf/redis-6379.conf

  1. 关闭指定redis进程
kill  PID



Reids命令:

  1. 默认方式启动redis服务
redis-server

​ 默认端口号 6379,下面为指定端口号启动

redis-server --port 6379

使用 Ctrl + C 快捷键可结束服务


  1. redis客户端中结束服务并退出
shutdown
exit



内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: