介绍

https://www.nginx.com/resources/wiki/modules/consistent_hash/地址

ngx_http_upstream_consistent_hash - a load balancer that uses an internal consistent hash ring to select the right backend node. It is designed to be compatible with memcache.hash_strategy = consistent of the php-memcache module. This means you can store values into a memcached cluster using the php-memcache module, and later NGINX can find that value in the cluster and read it from there.

ngx_http_upstream_consistent_hash-一种使用内部一致哈希环来选择正确后端节点的负载均衡器。它被设计为与memcache兼容。hash_strategy=与php memcache模块一致。这意味着您可以使用php memcache模块将值存储到memcache集群中,之后NGINX可以在集群中找到该值并从那里读取。

此参数必须在上游定义内。它打开一致性哈希上游模块,并定义必须进行哈希的字符串,以便在哈希环上找到正确的后端。例如,您可以这样做:

upstream somestream {consistent_hash $request_uri;server 10.50.1.3:11211;server 10.50.1.4:11211;server 10.50.1.5:11211;
}...server {listen       80;server_name  localhost;location / {default_type text/html;set $memcached_key $request_uri;memcached_pass somestream;error_page      500 404 405 = @fallback;}location @fallback {root /srv/www/whatever;fastcgi_intercept_errors on;error_page 404 = @404;set $script $uri;set $path_info "";include /usr/local/nginx/conf/fastcgi_params;fastcgi_param SCRIPT_FILENAME /srv/www/whatever/test.php;fastcgi_param SCRIPT_NAME $script;fastcgi_param REQUEST_URI $uri;fastcgi_pass   127.0.0.1:9000;}
}

本示例使用三个后端服务器。在初始化时,NGINX将创建一个哈希环,其中包含每个服务器(160*weight)次,其方式与hash_strategy=consistent的php memcache模块相同。基于$request_uri的散列,它将决定必须使用哪个后端服务器。现在是测试。上面示例中的php脚本可能如下所示:

$memcache = new Memcache;$memcache->addServer('10.50.1.3', 11211);
$memcache->addServer('10.50.1.4', 11211);
$memcache->addServer('10.50.1.4', 11211);$memcache->set($_SERVER["REQUEST_URI"], $_SERVER["REQUEST_URI"] . "from memcache");

Important to know

我使用PHP memcache模块版本1.2.8进行了测试。该版本中的模块似乎有一个错误,如果hash_strategy设置为consistent_hash,则会导致它完全忽略权重。NGINX一致性哈希上游知道权重参数,但如果您将其与memcache模块1.2.8一起使用,则不应触及任何后端服务器的权重。

我用NGINX 0.7.61和0.6.34测试了该模块,其他版本没有保证

Bugs/Feedback

If you find any bugs, please email me and I will try to help.

I would appreciate every kind of feedback or problem reports.

Mail: mauro.stettler(A.T)gmail.com

Download

On github I have to branches “master” and “dns”. The reason for this is that if you want to use DNS entries on the PHP side, instead of IPs, you will need to apply a patch to the NGINX to make this work. So if your PHP does not use DNS names to connect to memcache, its nicer to download the “master” branch, because this is a clean module. If your PHP uses DNS names, you have to download the “dns” branch, which includes a patch for NGINX.

Upstream Consistent Hash相关推荐

  1. 关于consistent hash的思考及改进方案

    这里默认读者已经知道了一致性hash算法的原理. 1. 为什么在某台机器宕机之后consistent hash算法能够避免所有或者大部分key重新hash? 首先需要弄清的是,如果某一台机器宕机之后, ...

  2. 聊聊jump consistent hash

    序 本文主要简介一下jump Consistent hash. jump consistent hash jump consistent hash是一致性哈希的一种实现,论文见A Fast, Mini ...

  3. 主从mysql replication 集群的sharding memcache集群使用consistent hash

    sharding 实现跨越DB的分区与扩展功能 consistent hash 一致哈希实现memcache的扩展 http://cache.baidu.com/c?m=9f65cb4a8c8507e ...

  4. haproxy Consistent Hash浅析

    http://blog.sina.com.cn/s/blog_502c8cc40100kfz2.html Haproxy实现了Map-based 和consistent hash算法,来完成通过哈希值 ...

  5. Google Jump Consistent Hash 一致性哈希算法

    接触到这个一致性哈希算法是在腾讯音乐的讲座中,用于在线扩容 如图中的例子,本来只有group0和group1,现在要增加一个group2用于推送新的数据,如果使用不满足单调性要求的hash方法,首先向 ...

  6. dapr的consistent hash

    序 本文主要研究一下dapr的consistent hash consistent_hash dapr/pkg/placement/hashing/consistent_hash.go var rep ...

  7. 2016 -Nginx的负载均衡 - 一致性哈希 (Consistent Hash)

    Nginx版本:1.9.1 算法介绍 当后端是缓存服务器时,经常使用一致性哈希算法来进行负载均衡. 使用一致性哈希的好处在于,增减集群的缓存服务器时,只有少量的缓存会失效,回源量较小. 在nginx+ ...

  8. consistent hash

    https://www.youtube.com/watch?v=ffE1mQWxyKM https://www.youtube.com/watch?v=zaRkONvyGr8

  9. Nginx学习之五:Nginx第三方模块

    为什么80%的码农都做不了架构师?>>>    第三方模块 这些模块不被官方所支持,亦未必能跨越Nginx的版本兼容.不过其中有些模块证明是对多数用户是有用的.只在于个人的风险问题. ...

最新文章

  1. 呼之欲出的量子计算机和漫长的最后一公里
  2. 笔记:django is not a registered namespace错误
  3. WTM系列视频教程:View和Taghelper
  4. [css] 为什么说对opacity进行动画要比box-shadow进行动画性能更好呢?
  5. 反质数问题,求不大于n的最大反质数
  6. 计算机网络email服务的配置,计算机网络邮件配置实验报告
  7. 51Nod-1384 全排列【全排列】
  8. wikioi 2315 longge的问题 2012年省队选拔赛山东(欧拉函数应用)
  9. JDBC 数据连接池
  10. Noip 2016 蛋碎一地晚节不保
  11. css聊天气派,css如何实现小尖角聊天对话框带尖角的说话泡泡效果
  12. android 获得ram大小,Android中获取(RAM)总运存大小和可用运存大小
  13. 苹果X 顶部和底部留白问题
  14. validator校验注解
  15. python xlwings库对于excel单元格的操作
  16. 网狐网络获取失败是否重试
  17. 大数据开发工程师前景如何?
  18. 好用不卡,这些插件和配置让你的 Webstorm 更牛逼!
  19. 猎头职场:混职场别败在嘴上
  20. 用inkscape做logo

热门文章

  1. 如何使用 Java 实现后台全局监听快捷键
  2. 用VASP计算GW+BSE
  3. 全国A级景点信息与分布数据
  4. java包 agent_使用Maven打包可运行jar和javaagent.jar的区别
  5. 如何高效、优雅、愉快地阅读项目源码?
  6. 视频教程-桫哥-GOlang-06文件读写-Go语言
  7. 数字资产:新基建重构数字经济新形态|读书笔记一
  8. 局域网Ping不通防火墙设置
  9. python自动填写excel,使用python自动填充语料关键词到Excel
  10. Arthas的安装使用笔记