[root@localhost src]# tar xvzf redis4.0.9.tar.gzg
[root@localhost src]# cd redis-4.0.9/
[root@localhost redis- 4.0.9]# make
[root@localhost redis-4.0.9]# make PREFIx=/s/localredis install
I [root@localhost ~]# In -s /usrlocalredis/bin/ /usrl/local/bin/
[root@localhost redis]# cd /uslocal/src/redis 4.0.9/utils/
[root@localhost utils]# ./install server.sh
Welcome to the redis service installer
This script will help you easily set up a running redis server
Please select the redis port for this instance: [6379]
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf]
Selected default - /etc/redis/6379.conf
Please select the redis log file name [varl/log/redis_ 6379.l0og]
Selected default - /var/log/redis_ 6379.log
Please select the data directory for this instance [var/lib/redis/6379]
Selected default - /var/lib/redis/6379
Please select the redis executable path 0 /sr/local/redis/bin/redis-server
[root@localhost utils]# /etc/init.d/redis_ 6379 status
Redis is running (5436)
[root@localhost utils]# /etc/init.d/redis_ 6379 stop
Stopping...
Redis stopped
[root@localhost utils]# /etc/init.d/redis_ 6379 start
Starting Redis server...
[root@localhost utils]# /etc/init.d/redis_ 6379 restart
Stopping...
Redis stopped
Starting Redis server...
配置参数(/etc/redis/6379.conf)
bind:监听的主机地址
port: 端口
daemonize yes:启用守护进程
pidfile:指定PID文件
loglevel notice:日志级别
logfile:指定日志文件
连接本地数据库
[root@localhost utils]# /us/localredis/bin/redis-cli
127.0.0.1:6379>
D
连接远程数据库
[root@localhost utils]# redis-cli -h 192. 168.10.161 -p 6379
192.168. 10.161:6379>
获取命令帮助
help @<group>:获取<group>中的命令列表
help <command>:获取某个命令的帮助
help <tab>:获取可能帮助的主题列表
[root@localhost ~]# /usr/local/redis/bin/redis-cli
127.0.0.1:6379> set teacher zhanglong
OK
127.0.0.1:6379> get teacher
"zhanglong"
●keys:获取符合规则的键值列表
●exists: 判断键值是否存在
●del:删除当前数据库的指定key
●type: 获取key对应的value值类型
●rename(覆盖) 1 renamenx (不覆盖) :对已有的key进行
重命名
●dbsize:查看当前数据库中key的数目
-h:指定服务器主机名
-p:指定服务器端口
-C: 指定并发连接数
-n:指定请求数
-d:以字节的形式指定SET/GET值的数据大小
-q:强制退出Redis,仅显示query/sec值
[root@localhost ~]# /s/lacal/edisbin/redis benchmark -h 192.168.10.161 -P 6379 -C 100 -n 100000
[root@localhost ~]# /usrlocal/redis/bin/redis-benchmark -h 192. 168.10.161 -p 6379 -q -d 100
RDB缺点 快照只是基于一个时间点,还是会有数据丢失的风险
AOF缺点 恢复工作量大
RDB+AOF
vim /etc/redis/6379.conf // 900秒之内至少-次写操作、300秒之内至少发生10次写操作,60秒之内发生至少10000次写操作,只要满足其一都会触发快照操作,注释所有的save项表示关闭RDB
save 900 1
save 300 10
save 60 10000
dbfilename dump.rdb // RDB文件名称
dir /var/ib/redis/6379 // RDB文件路径
rdbcompression yes // 是否进行压缩
- 将appendonly.aof文件拷贝到Redis的安装目录的bin目录下,重启Redis服务即可
配置文件选项
vim /etc/redis/6379.conf
appendonly yes 开启AOF持久化
appendfilename "appendonly.aof " AOF文件名称
# appendfsync always always:同步持文化.每次发生数据变化会立刻写入磁盘
appendfsync everysec everysec:默认推荐,每秒异步记录一次(默认值)
# appendfsync no no:不同步,交给操作系统决定如何同步
aof-load-truncated yes 忽略最后一条可能存在问题的招令
vim /etc/redis/6379.conf
#在日志进行BGREWRITEAOF时,如果设置为yes表示新写操作不进
行同步fsync,只是暂存在缓冲区里,避免造成磁盘I0操作冲突,等重
写完成后在写入。Redis中默认为no
no-appendfsync-on-rewrite no
#当前AOF文件大小是上次日志重写时AOF文件大小两倍时,发生
BGREWRITEAOF操作
auto-aof-rewrite-percentage 100
#当前AOF文件执行BGREWRITEAOF命令的最小值,避免刚开始启动
Reids时由于文件尺寸较小导致频繁的BGREWRITEAOF
auto-aof-rewrite-min-size 64mb
[root@master1 ~]# /usrlocalredis/bin/redis-cli
127.0.0.1:6379> info memory
# Memory 内存使用总量
used memory:2650536
used memory_ human:2.53M
used_ memory_ rss:12120064
used memory_ rSs_ human:11 .56M
used memory_ peak:2650536
used memory_ peak human:2,53M
used memory_ peak perc: 100.00%
used memory_ overhead:2573336
used memory_ startup:1458272
used memory_ dataset:77200
used_ memory dataset perc:6 48%
total system memory: 1912078336
otal system_ memory. human:1.78G
used memory_ lua:37888
used memory. Tua_ human:37.00K
maxmemory:0
maxmemory human:0B
maxmemory_ policy:noeviction
mem_ fragmentation_ ratio:4.57 内存碎片率
mem allocator:jemallc 4.0.3
active_ _defrag. running:0
lazyfree pending. objects:0