redis

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了redis相关的知识,希望对你有一定的参考价值。

        http://www.runoob.com/redis/redis-php.html

        http://blog.sina.com.cn/s/blog_67196ddc0101h8v0.html

        http://sofar.blog.51cto.com/353572/861276/


redis安装 

下载 wget http://download.redis.io/releases/redis-3.2.0.tar.gz

 http://redis.io/download

             

mkdir -p /usr/local/redis/{etc,bin,var}

mkdir -p /data/logs/redis

mkdir -p /data/dbcache

tar -xf redis-3.2.0.tar.gz

cd redis-3.2.0

make 

cd redis-3.2.0/src/

cp redis-server redis-cli redis-benchmark /usr/local/redis/bin/

echo "vm.overcommit_memory=1" >> /etc/sysctl.conf

/sbin/sysctl -p


创建master 配置文件 

             拷贝 /redis-3.2.0/redis.conf或者复制下面 


vim /usr/local/redis/etc/redis.conf 


bind 192.168.80.62   #ip

protected-mode yes   #启用后台运行

port 6379         #端口

tcp-backlog 511

timeout 0

tcp-keepalive 0

daemonize yes

supervised no

pidfile  /usr/local/redis/var/redis.pid

loglevel notice

logfile ""

databases 16

save 900 1

save 300 10

save 60 10000

stop-writes-on-bgsave-error yes

rdbcompression yes

rdbchecksum yes

dbfilename dump.rdb

dir /data/dbcache     #数据库目录

slave-serve-stale-data yes

slave-read-only yes

repl-diskless-sync no

repl-diskless-sync-delay 5

repl-disable-tcp-nodelay no

slave-priority 100

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

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

activerehashing yes

client-output-buffer-limit normal 0 0 0

client-output-buffer-limit slave 256mb 64mb 60

client-output-buffer-limit pubsub 32mb 8mb 60

hz 10

aof-rewrite-incremental-fsync yes

requirepass redis123          #密码

                                      

         

创建slave配置文件 安装和前面一样


vim /usr/local/redis/etc/redis.conf


bind 192.168.80.63

protected-mode yes

port 6379

tcp-backlog 511

timeout 0

tcp-keepalive 0

daemonize yes

supervised no

pidfile  /usr/local/redis/var/redis.pid

loglevel notice

logfile ""

databases 16

save 900 1

save 300 10

save 60 10000

stop-writes-on-bgsave-error yes

rdbcompression yes

rdbchecksum yes

dbfilename dump.rdb

dir /data/dbcache

slave-serve-stale-data yes

slave-read-only yes

repl-diskless-sync no

repl-diskless-sync-delay 5

repl-disable-tcp-nodelay no

slave-priority 100

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

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

activerehashing yes

client-output-buffer-limit normal 0 0 0

client-output-buffer-limit slave 256mb 64mb 60

client-output-buffer-limit pubsub 32mb 8mb 60

hz 10

aof-rewrite-incremental-fsync yes

slaveof 192.168.80.62 6379    #映射master 

masterauth redis123         #连接密码

                          


分别启动master和slave服务

/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf 


测试是否同步 


master 运行 /usr/local/redis/bin/redis-cli -h 192.168.80.62 -a redis123 set han 123456


slave 查看 /usr/local/redis/bin/redis-cli -h 192.168.80.63 get test



停止服务 /usr/local/redis/bin/redis-cli -h 192.168.80.62 -a redis123 -p 6379 shutdown 


无密码停止服务  /usr/local/redis/bin/redis-cli -p 6379 shutdown


备份数据


/usr/local/redis/bin/redis-cli -p 6379 save  无密码

/usr/local/redis/bin/redis-cli -h 192.168.80.62 -a redis123 -p 6379 save  有密码


恢复  cp /data/dbcache/dump.rdb 到目录 即可

 



本文出自 “秋水无痕” 博客,谢绝转载!

以上是关于redis的主要内容,如果未能解决你的问题,请参考以下文章

RedisRedis 安装启动使用流程

RedisRedis 安装启动使用流程

redisredis知识点总结

redisredis知识点总结

RedisRedis高级

RedisRedis简述