侯体宗的博客
  • 首页
  • Hyperf版
  • beego仿版
  • 人生(杂谈)
  • 技术
  • 关于我
  • 更多分类
    • 文件下载
    • 文字修仙
    • 中国象棋ai
    • 群聊
    • 九宫格抽奖
    • 拼图
    • 消消乐
    • 相册

redis的failover ,redmon安装

Redis  /  管理员 发布于 5年前   824
redmon安装
http://www.cr173.com/html/14775_1.html

failover
参考一点http://dmouse.iteye.com/blog/813026
redis支持master-slave模式,可以设置一个master,多个slave;采用读写分离的策略,master负责写数据,多个slave负责读数据,slave的数据是复制master上的,所以多个slave之间的数据是可以保持一致的,即便down了之后,也会通过加载dump数据的方式,重新加载会原来的缓存数据。

Fail-Tolerance
当前项目需要保证一个client连接到slave服务上读取数据,如果slave down 了之后,可以在不影响应用的情况下,自动切换到另外一个可用的slave

因为jredis不支持设置多个slave服务器,所以写了一个小工具类,目的是为了探测如果的当前正在使用的slave没有heartbeat之后,立马可以切换到一个可用的slave;这样可以保证one of slave down掉之后,不用missing-load也可及时切换到另外一个slave上读数据。
public class RedisFailToleranceUtil {private static JRedisService jredisService =  null;private static ConnectionSpec defaultConnectionSpec = null;private static int current = 1;private static HashMap<String,ConnectionSpec> serverPools = new HashMap<String,ConnectionSpec>();static{ConnectionSpec connectionSpec1 = DefaultConnectionSpec.newSpec("192.168.1.238", 6380, 0,null);ConnectionSpec connectionSpec2 = DefaultConnectionSpec.newSpec("192.168.1.238", 6381, 0,null);serverPools.put("1", connectionSpec1);serverPools.put("2", connectionSpec2);}private String next(){if(current>serverPools.size()){current=1;}int nextIndex = current;current++;return nextIndex+"";}private ConnectionSpec getConnectionSpec(){if(defaultConnectionSpec != null){return defaultConnectionSpec;}jredisService = null;/** * we are working multiple servers * try different servers,util we fetch the first available server pool */HashMap<String,ConnectionSpec> tryServers = new HashMap<String,ConnectionSpec>(serverPools);if(serverPools.size() == 1){return (ConnectionSpec)serverPools.get("1");}while(!tryServers.isEmpty()){ConnectionSpec connectionSpec = tryServers.get(this.next());if(isConnect(connectionSpec)){return connectionSpec;}tryServers.remove(connectionSpec);if(tryServers.isEmpty()){break;}}return null;}/** * try whether the server is available * @param connectionSpec  * @return true or false */private boolean isConnect(ConnectionSpec connectionSpec){if(connectionSpec == null){return false;}JRedis jredis = new JRedisClient(connectionSpec.getAddress().getHostAddress(), connectionSpec.getPort());try{jredis.ping();jredis.quit();}catch(Exception e){return false;}return true;}public void initialize(){defaultConnectionSpec = this.getConnectionSpec();if(jredisService == null){synchronized (RedisFailToleranceUtil.class) {jredisService = new JRedisService(defaultConnectionSpec,100);}}}public String getS(String key){this.initialize();String value = null;try {value = DefaultCodec.toStr(jredisService.get(key));} catch (Exception e) {defaultConnectionSpec = null;this.initialize();}return value;}public static void main(String args[]){RedisFailToleranceUtil redis = new RedisFailToleranceUtil();redis.getS("name");try {Thread.sleep(10000);} catch (InterruptedException e) {// TODO Auto-generated catch blocke.printStackTrace();}redis.getS("name");try {Thread.sleep(30000);} catch (InterruptedException e) {// TODO Auto-generated catch blocke.printStackTrace();}redis.getS("name");}}

改成jedis的
public class JedisPoolTest extends Assert {    private static HostAndPort hnp = HostAndPortUtil.getRedisServers().get(0);    private static HostAndPort hnp2 = HostAndPortUtil.getRedisServers().get(1);    private static HashMap<String,JedisPool> serverPools = new HashMap<String,JedisPool>();    static{    JedisPool pool1 = new JedisPool(new JedisPoolConfig(), hnp.host, hnp.port, 2000);    JedisPool pool2 = new JedisPool(new JedisPoolConfig(), hnp2.host, hnp2.port, 2000);    serverPools.put("1", pool1);    serverPools.put("2", pool2);}    private static int current = 1;    static Jedis jredisService=null;    private static JedisPool defaultConnectionSpec = null;    public void initialize(){defaultConnectionSpec = this.getConnectionSpec();if(jredisService == null){synchronized (RedisFailToleranceUtil.class) {jredisService = defaultConnectionSpec.getResource();}}}    public String getS(String key){this.initialize();String value = null;try {value = jredisService.get(key);} catch (Exception e) {defaultConnectionSpec = null;this.initialize();}return value;}    public static void main(String[] args) {    JedisPoolTest redis = new JedisPoolTest();System.out.println("1 "+redis.getS("foo"));try {Thread.sleep(10000);} catch (InterruptedException e) {e.printStackTrace();}System.out.println("2  "+redis.getS("foo"));try {Thread.sleep(10000);} catch (InterruptedException e) {e.printStackTrace();}System.out.println("3  "+redis.getS("foo"));try {Thread.sleep(10000);} catch (InterruptedException e) {e.printStackTrace();}System.out.println("4  "+redis.getS("foo"));try {Thread.sleep(10000);} catch (InterruptedException e) {e.printStackTrace();}System.out.println("5  "+redis.getS("foo"));}    private JedisPool getConnectionSpec(){if(defaultConnectionSpec != null){return defaultConnectionSpec;}HashMap<String,JedisPool> tryServers = new HashMap<String,JedisPool>(serverPools);System.out.println("tryServers:"+tryServers.size());if(serverPools.size() == 1){System.out.println("22222");//jredisService=connectionSpec.getResource();return (JedisPool)serverPools.get("2");}while(!tryServers.isEmpty()){JedisPool connectionSpec = tryServers.get("1");if(isConnect(connectionSpec)){System.out.println("1111");jredisService=connectionSpec.getResource();return connectionSpec;}else{connectionSpec = tryServers.get("2");jredisService=connectionSpec.getResource();System.out.println("1111---2222");serverPools.remove("1");return connectionSpec;}}return null;}    private boolean isConnect(JedisPool pool){if(pool == null){return false;}try{Jedis jedis = pool.getResource();jedis.ping();pool.returnResource(jedis);}catch(Exception e){return false;}return true;}}

----------------
安装
jredis
https://github.com/alphazero/jredis/downloads
http://liuxinglanyue.iteye.com/blog/829428

参数说明
http://aronlulu.iteye.com/blog/1236773
appendonly 默认情况下,redis 会在后台异步的把数据库镜像备份到磁盘,但是该备份是非常耗时 的,而且备份也不能很频繁,如果发生诸如拉闸限电、拔插头等状况,那么将造成比较 大范围的数据丢失。所以 redis提供了另外一种更加高效的数据库备份及灾难恢复方式。 开启 append only 模式之后,redis 会把所接收到的每一次写操作请求都追加到 appendonly.aof 文件中,当redis重新启动时,会从该文件恢复出之前的状态。但是这样 会造成 appendonly.aof 文件过大,所以 redis 还支持了 BGREWRITEAOF 指令,对 appendonly.aof 进行重新整理。所以我认为推荐生产环境下的做法为关闭镜像,开启 appendonly.aof,同时可以选择在访问较少的时间每天对 appendonly.aof 进行重写一次


注意dump.rdb文件
默认在redis-server的同一个目录下
dir指定
官方文档
http://try.redis-db.com/
导出json
https://github.com/delano/redis-dump
--------------
rais的安装
http://archive.cnblogs.com/a/1937602/
http://www.cnblogs.com/watir/archive/2011/01/17/1937602.html
为了装https://github.com/steelThread/redmon
redmon
sqlite3报错
http://blog.toolib.net/cnmahj/2011/09/rails3-1%E4%BD%BF%E7%94%A8sqlite%E6%97%B6%E2%80%9Csqlite3_int64-undeclared%E2%80%9D%E9%94%99%E8%AF%AF%E7%9A%84%E8%A7%A3%E5%86%B3%E6%96%B9%E6%B3%95/


i容量预计和估算
http://blog.nosqlfan.com/html/3430.html
u不过发现脚本执行几次,差值不一样
数据增量存储
http://www.hoterran.info/redis_persistence

源码分析
http://blog.nosqlfan.com/html/2949.html?ref=rediszt
资料总会专题
http://blog.nosqlfan.com/html/3537.html

Redis采用不同内存分配器碎片率对比
http://blog.nosqlfan.com/html/3490.html

目录
http://blog.nosqlfan.com/tags/redis

Redis复制与可扩展集群搭建
http://www.infoq.com/cn/articles/tq-redis-copy-build-scalable-cluster

测试,需要看valgrind
http://blog.nosqlfan.com/html/2383.html

容量
http://timyang.net/data/redis-capacity/

微波两个人
http://weibo.com/bachmozart?key_word=redis
http://weibo.com/tangfl?key_word=redis

lua
http://blog.nosqlfan.com/html/1658.html

ruby的监控
用最新版zlib问题
https://rvm.beginrescueend.com/rvm/install/
http://belmount.blog.51cto.com/1897431/766728
https://blog.johncheng.com/?p=1389
rvm
http://floger.iteye.com/blog/935374


不用openssl
最后那个运行下就行
rvm requirements
rvm install 1.9.3
rvm list
rvm alias create default ruby-1.9.3-p125
gem install bundler
rvm rubygems latest
rvm pkg install openssl
gem install rails
rvm gemset list
看rails的版本,然后
rvm gemset create rails3.2.1


rvm pkg install zlib ;
rvm pkg install readline;
rvm pkg install openssl;
rvm pkg install iconv;
rvm remove 1.9.3;
rvm install 1.9.3 --with-zlib-dir=$rvm_path/usr --with-openssl-dir=$rvm_path/usr --with-readline-dir=$rvm_path/usr --with-iconv-dir=$rvm_path/usr

rvm gemset create rails3.2.1

zlib
https://rvm.beginrescueend.com/packages/zlib/

Ruby 1.9.3-p0 makes psych—the replacement for 1.8.7’s YAML library,
http://www.cnblogs.com/qq78292959/archive/2011/12/15/2288567.html

rvm info

rvm requirements
rvm install 1.8.7
rvm list
rvm alias create default ruby-1.8.7-p358
ruby -v
gem install rails
rvm gemset list
rvm gemset list
rvm gemset create rails3.2.1
gem install jquery-rails
rails new demo1

集群
http://wenku.baidu.com/view/d9ac5ab9960590c69ec37683.html
cassandra
http://baike.baidu.com/view/1350234.htm
2.6 Redis集群功能说明
http://blog.nosqlfan.com/html/3302.html
ppt
http://blog.nosqlfan.com/html/1007.html
hash
http://emreyilmaz.me/implementing-consistent-hashing-into-your-redis

  • 上一条:
    第三章 Redis/SSDB+Twemproxy安装与使用
    下一条:
    redis 学习
  • 昵称:

    邮箱:

    0条评论 (评论内容有缓存机制,请悉知!)
    最新最热
    • 分类目录
    • 人生(杂谈)
    • 技术
    • linux
    • Java
    • php
    • 框架(架构)
    • 前端
    • ThinkPHP
    • 数据库
    • 微信(小程序)
    • Laravel
    • Redis
    • Docker
    • Go
    • swoole
    • Windows
    • Python
    • 苹果(mac/ios)
    • 相关文章
    • 在Redis中能实现的功能、常见应用介绍(0个评论)
    • 2024年Redis面试题之一(0个评论)
    • 在redis缓存常见出错及解决方案(0个评论)
    • 在redis中三种特殊数据类型:地理位置、基数(cardinality)估计、位图(Bitmap)使用场景介绍浅析(2个评论)
    • Redis 删除 key用 del 和 unlink 有啥区别?(1个评论)
    • 近期文章
    • 在go中实现一个常用的先进先出的缓存淘汰算法示例代码(0个评论)
    • 在go+gin中使用"github.com/skip2/go-qrcode"实现url转二维码功能(0个评论)
    • 在go语言中使用api.geonames.org接口实现根据国际邮政编码获取地址信息功能(1个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf分页文件功能(0个评论)
    • gmail发邮件报错:534 5.7.9 Application-specific password required...解决方案(0个评论)
    • 欧盟关于强迫劳动的规定的官方举报渠道及官方举报网站(0个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf文件功能(0个评论)
    • Laravel从Accel获得5700万美元A轮融资(0个评论)
    • 在go + gin中gorm实现指定搜索/区间搜索分页列表功能接口实例(0个评论)
    • 在go语言中实现IP/CIDR的ip和netmask互转及IP段形式互转及ip是否存在IP/CIDR(0个评论)
    • 近期评论
    • 122 在

      学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..
    • 123 在

      Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..
    • 原梓番博客 在

      在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..
    • 博主 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..
    • 1111 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
    • 2017-12
    • 2020-03
    • 2020-05
    • 2021-04
    • 2022-03
    • 2022-05
    • 2022-08
    • 2023-02
    • 2023-04
    • 2023-07
    • 2024-01
    • 2024-02
    Top

    Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号 PHP交流群

    侯体宗的博客