Linux 下 Redis 6 的安装使用(Ubuntu 18.04)
2020-08-07 12:39
495 查看
Redis 的安装使用
Redis(Remote Dictionary Server )是一个使用ANSI C编写的开源、支持网络、基于内存、可选持久性的键值对存储数据库,提供了多种语言的API。
下面是 Ubuntu 18.04 系统上安装Redis简易版教程
第一步:下载安装包
-
获取下载地址
Redis官方网站:https://redis.io/
- 选择安装路径,我选择的是 /root/tools/software/
cd tools/software/
- 下载Redis安装包(6.0.5为版本号,可更换成最新的版本号,若连接更换,请移步官网)
wget http://download.redis.io/releases/redis-6.0.5.tar.gz
第二步:安装
- 解压(请使用对应的文件名)
tar -xvf redis-6.0.5.tar.gz
图文过长,只截取前面一部分
- 创建软链接(为了方便,非必须,如果没有创建,接下来的涉及到redis路径请用redis-6.0.5)
ln -s 原始目录名 快速访问目录名
ln -s redis-6.0.5 redis
- 进入redis目录,对解压的Redis文件进行编译
cd redis
make
如果没有配置好编译环境,则使用以下命令配置:
yum install gcc-c++
- 进入src文件夹进行Redis安装
cd src
make install
第三步:部署
- 回到redis目录下,创建data、conf文件夹用于保存数据和配置文件
cd ..
mkdir data
mkdir conf
- 进入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 : 永不过期,返回错误
第四步:测试
- 指定配置文件开启redis服务
redis-server redis-6379.conf
- 连接指定服务器(请使用对应的IP和端口号)
redis-cli -h 127.0.0.1 –port 6379
- set、get测试
set name redis
get name
PS:
Linux命令:
- 查看当前redis服务进程:
ps -ef | grep redis
- 去除空行和注释行复制 redis.conf (在redis目录下复制到conf目录):
grep -Ev "^$|#" redis.conf > ./conf/redis-6379.conf
- 关闭指定redis进程
kill PID
Reids命令:
- 默认方式启动redis服务
redis-server
默认端口号 6379,下面为指定端口号启动
redis-server --port 6379
使用 Ctrl + C 快捷键可结束服务
- redis客户端中结束服务并退出
shutdown
exit
相关文章推荐
- Ubuntu 18.04等Linux系统安装Anbox并使用它运行Android应用程序
- Ubuntu 18.04及其他版本Linux 下 Nmap 网络扫描工具的安装与使用
- 【Linux】Ubuntu18.04使用【python2】安装PIL、opencv、numpy、matplotlib、pandas、seaborn
- linux教程:使用Ubuntu LiveCD安装grub
- Linux上安装使用SSH(ubuntu)
- Ubuntu Linux gcc 安装 使用方法
- Linux下的Source Insight+Ubuntu 10.04使用Wine安装Source Insight
- 使用Virtual Machine虚拟机安装Ubuntu发行版linux系统的步骤
- Linux上安装使用SSH(ubuntu&&redhat)
- Linux下的Source Insight+Ubuntu 10.04使用Wine安装Source
- 在VMware 8虚拟机下,ubuntu系统如何安装 vmware tools【使用所有Linux系统安装vmware tools】
- ubuntu下arm-linux-gcc已安装,root用户使用却显示command not find
- linux 下安装、使用 redis
- Linux(Ubuntu) 安装mysql,windows使用Navicat 连接
- Linux开发环境搭建与使用——ubuntu物理机安装方法:U盘安装
- ubuntu安装redis的方法以及PHP安装redis扩展、CI框架sess使用redis的方法
- 〖Linux〗Ubuntu中使用KVM安装虚拟机
- linux下安装配置使用memcache,memcached,libevent(后有ubuntu的memcache安装)
- Linux(ubuntu)下用eclipse对log4cplus库的安装,编译和使用-由张海伦指导完成
- Linux下的Source Insight+Ubuntu 10.04使用Wine安装Source Insight