码迷,mamicode.com
首页 > 其他好文 > 详细

redis

时间:2018-12-02 16:47:16      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:over   key   install   timeout   软件   命令   硬盘   append   删除   

Redis

    知识点

        Redis简介

            是分布式存储系统,特别适合充当缓存服务器

        Redis缓存服务器

            redis存储系统主要靠内存。

通常情况下要求redis服务器内存要很大

        Redis主从复制

            复制可支持master-slave1-slave2

        Redis Sentinel(高可用)

            是redis自带的高可用(HA)软件

            最好选择最高版本,低版本的bug较多

            集群中互相通信采用的gossip协议

            最关键的问题是,IP地址已经变化,对于sentinel怎么办

            认为down和故障切换是两块

        多实例

            多个不同端口的sentinel服务

        redis cluster

            数据分片

        Redis读写分离

        Redis数据持久化

            持久化是作为缓存服务器使用的。如果只用于数据的缓存,那么可以关闭数据持久化;如果要是需要数据保存在硬盘上,那么开启数据持久化

        redis的安全

            修改端口号

            设置客户端密码登陆验证

        子主题 10

    功能

        redis初始化安装(通过install_server脚本)

            #!/usr/bin/bash

yum -y install cpp

yum -y install binutils

yum -y install glibc

yum -y install glibc-kernheaders

yum -y install glibc-common

yum -y install glibc-devel

yum -y install gcc

yum -y install tcl

yum -y install make

            下载好redis并解压,进入redis目录

                make test

                    报错1

            make install

            cd ./utils/目录,运行install_server脚本

            vim /etc/redis/redis_6379.conf

                bind

                daemonize

                port

                protected-mode

                maxmemory

            /etc/init.d/redis_6379 start/stop

        redis主从复制

            master与slave端vim /etc/redis_redis_6379

                redis安全(可选)

            slave端:vim /etc/redis/redis_6379

                设置slaveof <masterip> <masterport>

            测试

                写字段

                    master

                        redis-cli -p 8888

                        set fuck you

                        get fuck

                            you

                    slave

                        redis-cli -p 8888

                        keys *

                        get fuck

                            you

                查看master的/var/log/redis的log日志

        redis Sentinel高可用

            cp redis-3.2.3/sentinel.conf /etc/redis/

            vim /etc/redis/sentinel.conf

                daemonize yes

                logfile "/var/log/sentinel_log.log"

            redis-sentinel /etc/redis/sentinel.conf

                sentinel monitor mymaster 10.10.0.5 6379 2

                sentinel down-after-milliseconds mymaster 5000

                sentinel failover-timeout mymaster 180000

                sentinel parallel-syncs mymaster 1

        redis Cluster

            至少需要六个节点,三主三从

            ruby

                yum -y install ruby

                yum install rubygems

                gem  install  redis

            ./redis-trib.rb命令

                cp redis-trib.rb /usr/local/bin

                appendfilename "appendonly-6666.aof"

                ./redis-trib.rb create --replicas 1 127.0.0.1:6666 127.0.0.1:6667  127.0.0.1:6668  127.0.0.1:6669 127.0.0.1:6670 127.0.0.1:6671

                ruby redis-trib.rb help

                查看集群信息(主从关系)

                    ruby redis-trib.rb info 192.168.100.71:6670

                添加节点到集群中

                    本节点为master

                        ./redis-trib.rb add-node 192.168.100.70:6667 192.168.100.70:6666

                        ./redis-trib.rb add-node 192.168.100.70:6668 192.168.100.70:6666

                    在slave上操作

                        ruby redis-trib.rb add-node --slave --master-id 97db37c2ccf15adb815d554f3cdb0648f6378db1 192.168.100.71:6669 192.168.100.70:6666

                        ruby redis-trib.rb add-node --slave --master-id 64af3f00f3ee3e73f8969ea4b1a275e8b9148deb 192.168.100.71:6670 192.168.100.70:6667

                        ruby redis-trib.rb add-node --slave --master-id aa82294b945e4c78a240e26d4a28df065d0b7d0e 192.168.100.71:6671 192.168.100.70:6668

                    子主题 3

                        1、将需要新增的节点下aof、rdb、node本地备份文件删除

2、重启系统

                        172.168.63.201:7001>  flushdb      #清空当前数据库

                删除集群节点

                    Node 127.0.0.1:9003 is not empty! Reshard data away and try again.

                    ruby ./redis-trib.rb del-node 127.0.0.1:6669 44458be24b9b7859a55bc30ad73be536307e5fa1

                    删除的节点必须是空的,也就是不能缓存任何数据,否则会删除不成功。对于非空节点,在删除之前需要重新分片,将缓存的数据转移到别的节点。

                检查集群

                    ./redis-trib.rb check 127.0.0.1:6666

                转移节点上的数据

                     ./redis-trib.rb reshard 127.0.0.1:6667

                        5462

                          

                集群修复

                    删除节点后哈希槽不对

                    ./redis-trib.rb fix 192.168.100.70:6666

            redis客户端操作

                redis-cli -c -h 127.0.0.1 -p 6666

            redis服务自启

        redis读写分离

        redis持久化

    redis测试

        redis-cli

            redis-cli -p

    注意点

        最大内存设置

            选项设置:maxmemory

        内存达到上限,但还要往redis添加缓存内容

            maxmemory-policy allkeys-lru

redis

标签:over   key   install   timeout   软件   命令   硬盘   append   删除   

原文地址:https://www.cnblogs.com/yujiebin/p/10053905.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!