Redis日志、数据目录、AOF、AUTH配置

简单粗暴的Redis数据备份和恢复方法:[url]http://www.jb51.net/article/87249.htm[/url]
创建日志目录:
[code="java"]# mkdir redis
# ls
bin boot dev etc home lib lib64 media mnt opt proc redis root run sbin srv sys tmp usr var zabbix
# cd /redis/
# ls
# mkdir logs
# ls -al
total 4
drwxr-xr-x 3 root root 17 Dec 20 15:18 .
dr-xr-xr-x. 19 root root 4096 Dec 20 15:16 ..
drwxr-xr-x 2 root root 6 Dec 20 15:18 logs
# cd .
# ls
# mv redis.sh /redis/
# ls
anaconda-ks.cfg dump.rdb
# cd /redis/
# ls
logs redis.sh
# mkdir bin
# ls
bin logs redis.sh
# mv redis.sh ./bin/
# ls
bin logs
# cd bin/
# ls
redis.sh
# vim /usr/local/redis/conf/redis.conf
修改日志配置项
# Specify the log file name. Also the empty string can be used to force
# Redis to log on the standard output. Note that if you use standard
# output for logging but daemonize, logs will be sent to /dev/null
logfile /redis/logs/redis.log
##注意logs文件夹必须存在
# ./redis.sh start
start redis-server...runing
# netstat -ntlp | grep 6379
tcp 0 0 0.0.0.0:6379 0.0.0.0:* LISTEN 14855/redis-server
tcp6 0 0 :::6379 :::* LISTEN 14855/redis-server

vim /usr/local/redis/conf/redis.conf
# cd ../logs/
# ls
redis.log
# tail redis.log
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'

14855:M 20 Dec 15:19:24.007 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
14855:M 20 Dec 15:19:24.007 # Server started, Redis version 3.0.5
14855:M 20 Dec 15:19:24.007 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
14855:M 20 Dec 15:19:24.007 * The server is now ready to accept connections on port 6379

# cd ..
# ls
bin logs
[/code]
创建数据文件目录

[code="java"]# mkdir data
# vim /usr/local/redis/conf/redis.conf
修改data目录
# The filename where to dump the DB
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.
关键是这个,注意/redis/data目录要存在
dir /redis/data

# cd data/
# ls -al
total 0
drwxr-xr-x 2 root root 6 Dec 20 15:27 .
drwxr-xr-x 5 root root 38 Dec 20 15:27 ..
# cd ..
[/code]
添加密码校验、开启AOF

[code="java"]# vim /usr/local/redis/conf/redis.conf
添加客户端验证
# Warning: since Redis is pretty fast an outside user can try up to
# 150k passwords per second against a good box. This means that you should
# use a very strong password otherwise it will be very easy to break.
#
requirepass redis

开启AOF
# AOF and RDB persistence can be enabled at the same time without problems.
# If the AOF is enabled on startup Redis will load the AOF, that is the file
# with the better durability guarantees.
#
# Please check http://redis.io/topics/persistence for more information.
### 默认情况下,redis需要异步dump数据到磁盘上,但这种情况下redis进程可能导致
部分写丢失,同时断电也会导致部分写丢失,为了避免这种情况,我们可以开启appendonly
为yes,更好的保证redis的持久化,当redis启动时,redis会加载AOF文件;
redis写操作,先写入到到AOF文件中,默认情况下,当AOF file每增加32MB,就将数据同步持久化到磁盘

appendonly yes

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


# redis-cli -h localhost -p 6379
localhost:6379> help
redis-cli 3.0.5
Type: "help @<group>" to get a list of commands in <group>
"help <command>" for help on <command>
"help <tab>" to get a list of possible help topics
"quit" to exit
localhost:6379> help auth

AUTH password
summary: Authenticate to the server
since: 1.0.0
group: connection

localhost:6379> AUTH redis
OK
localhost:6379> get name
(nil)
localhost:6379> set name donald
OK
localhost:6379> get name
"donald"
localhost:6379>
# ls -al
total 4
drwxr-xr-x 2 root root 27 Dec 20 15:57 .
drwxr-xr-x 5 root root 38 Dec 20 15:27 ..
-rw-r--r-- 1 root root 58 Dec 20 16:00 appendonly.aof
redis写操作,先写入到到AOF文件中,默认情况下,当AOF file每增加32MB,就将数据同步持久化到磁盘dump.rdb文件,或者触发BGREWRIETE条件
#
# Save the DB on disk:
#
# save <seconds> <changes>
#
# Will save the DB if both the given number of seconds and the given
# number of write operations against the DB occurred.
#
# In the example below the behaviour will be to save:
# after 900 sec (15 min) if at least 1 key changed
# after 300 sec (5 min) if at least 10 keys changed
# after 60 sec if at least 10000 keys changed
#
# Note: you can disable saving completely by commenting out all "save" lines.
#
# It is also possible to remove all the previously configured save
# points by adding a save directive with a single empty string argument
# like in the following example:
#
# save ""

save 900 1
save 300 10
save 60 10000

[redis@zabbix Desktop]$ cd /redis/data/
[redis@zabbix data]$ ls -al
total 8
drwxr-xr-x 2 root root 42 Dec 20 16:12 .
drwxr-xr-x 5 root root 38 Dec 20 15:27 ..
-rw-r--r-- 1 root root 58 Dec 20 16:00 appendonly.aof
-rw-r--r-- 1 root root 33 Dec 20 16:12 dump.rdb
[redis@zabbix data]$
[/code]
[code="java"]# redis-cli -h localhost -p 6379 -a redis
localhost:6379> get name
"donald"
关闭服务器
# redis-cli -h localhost -p 6379 -a redis
localhost:6379> shutdown
not connected> exit
[/code]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值