Google开源软负载seesaw
https://github.com/google/seesaw
------------------------
在分布式系统中,负载均衡是非常重要的环节,通过负载均衡将请求派发到网络中的一个或多个节点上进行处理。通常来说,负载均衡分为硬件负载均衡及软件负载均衡。硬件负载均衡,顾名思义,在服务器节点之间安装专门的硬件进行负载均衡的工作,F5便为其中的佼佼者。软件负载均衡则是通过在服务器上安装的特定的负载均衡软件或是自带负载均衡模块完成对请求的分配派发。
一般而言,有以下几种常见的负载均衡策略:
一.轮询。作为非常经典的负载均衡策略,早期该策略应用地非常广泛。其原理很简单,给每个请求标记一个序号,然后将请求依次派发到服务器节点中,适用于集群中各个节点提供服务能力等同且无状态的场景。其缺点也非常明显,该策略将节点视为等同,与实际中复杂的环境不符。加权轮询为轮询的一个改进策略,每个节点会有权重属性,但是因为权重的设置难以做到随实际情况变化,仍有一定的不足。
二.随机。与轮询相似,只是不需要对每个请求进行编号,每次随机取一个。同样地,该策略也将后端的每个节点是为等同的。另外同样也有改进的加权随机的算法,不再赘述。
三.最小响应时间。通过记录每次请求所需的时间,得出平均的响应时间,然后根据响应时间选择最小的响应时间。该策略能较好地反应服务器的状态,但是由于是平均响应时间的关系,时间上有些滞后,无法满足快速响应的要求。因此在此基础之上,会有一些改进版本的策略,如只计算最近若干次的平均时间的策略等。
四. 最小并发数。客户端的每一次请求服务在服务器停留的时间可能会有较大的差异,随着工作时间加长,如果采用简单的轮循或随机均衡算法,每一台服务器上的连接进程可能会产生较大的不同,并没有达到真正的负载均衡。最小并发数的策略则是记录了当前时刻,每个备选节点正在处理的事务数,然后选择并发数最小的节点。该策略能够快速地反应服务器的当前状况,较为合理地将负责分配均匀,适用于对当前系统负载较为敏感的场景。
五.哈希。在后端节点有状态的情况下,需要使用哈希的方法进行负载均衡,此种情况下情况比较复杂,本文对此不做探讨。
另外还有其他的负载均衡策略不再一一列举,有兴趣的同学可以自己去查阅相关资料。
分布式系统面临着远比单机系统更加复杂的环境,包括不同的网络环境、运行平台、机器配置等等。在如此复杂的环境中,发生错误是不可避免的,然后如何能够做到容错性,将发生错误的代价降低到最低是在分布式系统中必须要考虑的问题。选择不同的负载均衡策略将会有非常大的不同。
------------------------
Seesaw v2
Note: This is not an official Google product.
About
Seesaw v2 is a Linux Virtual Server (LVS) based load balancing platform.
It is capable of providing basic load balancing for servers that are on the same network, through to advanced load balancing functionality such as anycast, Direct Server Return (DSR), support for multiple VLANs and centralised configuration.
Above all, it is designed to be reliable and easy to maintain.
Requirements
A Seesaw v2 load balancing cluster requires two Seesaw nodes - these can be physical machines or virtual instances. Each node must have two network interfaces - one for the host itself and the other for the cluster VIP. All four interfaces should be connected to the same layer 2 network.
Building
Seesaw v2 is developed in Go and depends on several Go packages:
- golang.org/x/crypto/ssh
- github.com/dlintw/goconf
- github.com/golang/glog
- github.com/golang/protobuf/proto
- github.com/miekg/dns
Additionally, there is a compile and runtime dependency on libnl and a compile time dependency on the Go protobuf compiler.
On a Debian/Ubuntu style system, you should be able to prepare for building by running:
apt-get install golang
apt-get install libnl-3-dev libnl-genl-3-dev
If your distro has a go version before 1.5, you may need to fetch a newer release from https://golang.org/dl/.
After setting GOPATH
to an appropriate location (for example ~/go
):
go get -u golang.org/x/crypto/ssh
go get -u github.com/dlintw/goconf
go get -u github.com/golang/glog
go get -u github.com/miekg/dns
go get -u github.com/kylelemons/godebug/pretty
Ensure that ${GOPATH}/bin
is in your ${PATH}
and in the seesaw directory:
make test
make install
If you wish to regenerate the protobuf code, the protobuf compiler and Go protobuf compiler generator are also needed:
apt-get install protobuf-compiler
go get -u github.com/golang/protobuf/{proto,protoc-gen-go}
The protobuf code can then be regenerated with:
make proto
Installing
After make install
has run successfully, there should be a number of binaries in ${GOPATH}/bin
with a seesaw_
prefix. Install these to the appropriate locations:
SEESAW_BIN="/usr/local/seesaw"
SEESAW_ETC="/etc/seesaw"
SEESAW_LOG="/var/log/seesaw"
INIT=`ps -p 1 -o comm=`
install -d "${SEESAW_BIN}" "${SEESAW_ETC}" "${SEESAW_LOG}"
install "${GOPATH}/bin/seesaw_cli" /usr/bin/seesaw
for component in {ecu,engine,ha,healthcheck,ncc,watchdog}; do
install "${GOPATH}/bin/seesaw_${component}" "${SEESAW_BIN}"
done
if [ $INIT = "init" ]; then
install "etc/init/seesaw_watchdog.conf" "/etc/init"
elif [ $INIT = "systemd" ]; then
install "etc/systemd/system/seesaw_watchdog.service" "/etc/systemd/system"
systemctl --system daemon-reload
fi
install "etc/seesaw/watchdog.cfg" "${SEESAW_ETC}"
# Enable CAP_NET_RAW for seesaw binaries that require raw sockets.
/sbin/setcap cap_net_raw+ep "${SEESAW_BIN}/seesaw_ha"
/sbin/setcap cap_net_raw+ep "${SEESAW_BIN}/seesaw_healthcheck"
The setcap
binary can be found in the libcap2-bin package on Debian/Ubuntu.
Configuring
Each node needs a /etc/seesaw/seesaw.cfg
configuration file, which provides information about the node and who its peer is. Additionally, each load balancing cluster needs a cluster configuration, which is in the form of a text-based protobuf - this is stored in /etc/seesaw/cluster.pb
.
An example seesaw.cfg file can be found in etc/seesaw/seesaw.cfg.example - a minimal seesaw.cfg provides the following:
anycast_enabled
- True if anycast should be enabled for this cluster.name
- The short name of this cluster.node_ipv4
- The IPv4 address of this Seesaw node.peer_ipv4
- The IPv4 address of our peer Seesaw node.vip_ipv4
- The IPv4 address for this cluster VIP.
The VIP floats between the Seesaw nodes and is only active on the current master. This address needs to be allocated within the same netblock as both the node IP address and peer IP address.
An example cluster.pb file can be found in etc/seesaw/cluster.pb.example - a minimal cluster.pb
contains a seesaw_vip
entry and two node
entries. For each service that you want to load balance, a separate vserver
entry is needed, with one or more vserver_entry
sections (one per port/proto pair), one or more backends
and one or more healthchecks
. Further information is available in the protobuf definition - see pb/config/config.proto.
On an upstart based system, running restart seesaw_watchdog
will start (or restart) the watchdog process, which will in turn start the other components.
Anycast
Seesaw v2 provides full support for anycast VIPs - that is, it will advertise an anycast VIP when it becomes available and will withdraw the anycast VIP if it becomes unavailable. For this to work the Quagga BGP daemon needs to be installed and configured, with the BGP peers accepting host-specific routes that are advertised from the Seesaw nodes within the anycast range (currently hardcoded as 192.168.255.0/24
).
Command Line
Once initial configuration has been performed and the Seesaw components are running, the state of the Seesaw can be viewed and controlled via the Seesaw command line interface. Running seesaw
(assuming /usr/bin
is in your path) will give you an interactive prompt - type ?
for a list of top level commands. A quick summary:
config reload
- reload the cluster.pb from the current config source.failover
- failover between the Seesaw nodes.show vservers
- list all vservers configured on this cluster.show vserver <name>
- show the current state for the named vserver.
Troubleshooting
A Seesaw should have five components that are running under the watchdog - the process table should show processes for:
seesaw_ecu
seesaw_engine
seesaw_ha
seesaw_healthcheck
seesaw_ncc
seesaw_watchdog
All Seesaw v2 components have their own logs, in addition to the logging provided by the watchdog. If any of the processes are not running, check the corresponding logs in /var/log/seesaw
(e.g. seesaw_engine.{log,INFO}
).
Google开源软负载seesaw的更多相关文章
- Ribbon软负载 (F版)
Spring Cloud 为开发者提供了在分布式系统中的一些常用的组件(例如配置管理,服务发现,断路器,智能路由,微代理,控制总线,一次性令牌,全局锁定,决策竞选,分布式会话集群状态).使用Sprin ...
- [Android]Google 开源的 Android 排版库:FlexboxLayout
最近Google开源了一个项目叫「FlexboxLayout」. 1.什么是 Flexbox 简单来说 Flexbox 是属于web前端领域CSS的一种布局方案,是2009年W3C提出了一种新的布局方 ...
- Google开源SLAM软件cartographer中使用的UKF滤波器解析
在Google开源SLAM软件cartographer中,相对<SLAM for dummies>使用了更为复杂.性能更好的Scan匹配与UKF算法,这里简单介绍下cartographer ...
- 使用ZooKeeper实现软负载均衡(原理)
ZooKeeper是一个分布式的,开放源码的分布式应用程序协调服务,提供的功能包括配置维护.名字服务.分布式同步.组服务等. ZooKeeper会维护一个树形的数据结构,类似于Windows资源管理器 ...
- 人工智能系统Google开源的TensorFlow官方文档中文版
人工智能系统Google开源的TensorFlow官方文档中文版 2015年11月9日,Google发布人工智能系统TensorFlow并宣布开源,机器学习作为人工智能的一种类型,可以让软件根据大量的 ...
- 利用中文数据跑Google开源项目word2vec
一直听说word2vec在处理词与词的相似度的问题上效果十分好,最近自己也上手跑了跑Google开源的代码(https://code.google.com/p/word2vec/). 1.语料 首先准 ...
- vmware linux top si高以及网卡队列、软负载相关优化
今日,测试公司自行开发的一rpc中间件,期间发现top si的比例很高,且几乎只有一个cpu是繁忙的,其他均基本为0. 经查,si主要是系统软中断,最后确定是网卡导致的系统中断.于是,往上搜了下资料, ...
- [转]玩转Google开源C++单元测试框架Google Test系列
gtest的官方网站是: http://code.google.com/p/googletest/ 从官方的使用文档里,你几乎可以获得你想要的所有东西 http://code.google.com/p ...
- 开源软交换系统 FreeSwitch 与 Asterisk 比较
Asterisk 与freeswitch都是流行的开源软交换服务器,Asterisk出现的比较早,大概在1999年开始此项目,应该是最流行的开源软交换服务器,整个社区上下游都已经很成熟. freesw ...
随机推荐
- python3-基础7
协程函数 面向过程编程 递归与二分法 内置函数 lambda 模块与包的使用 import from ... import ... 常用模块 ########################### ...
- 《重构-改善既有代码的设计》学习笔记----Extract Method(提炼函数)
看见一个过长的函数或者需要一段注释才能让人理解的代码,可以考虑将这段代码放进一个独立函数中. 创造一个新的函数,根据这个函数的意图来对它命名(以它“做什么”来命名,而不是以它“怎么做”命名). 需要重 ...
- vivado源文件和仿真文件的建立
目的:做一个3输入,1输出模块:其中只要有2个输入为1则输出为1: 1.打开vivado创建一个工程 2.选择保存路径和名称 3.选择创建rtl文件且勾选下面的选项 4.选择芯片如xc7a35tift ...
- SQL脚本--总耗CPU最多的前个SQL --平均耗CPU最多的前个SQL
--总耗CPU最多的前个SQL SELECT TOP 20 total_worker_time/1000 AS [总消耗CPU 时间(ms)],execution_count [运行次数], qs.t ...
- C# Xamarin开发 GenyMotion adb List of devices attached
最近,公司要求要学习Xamarin,说是将来用到PDA上,所以最近对XaMarin开始接触,16年的时候就听说.Net开始着实跨平台,安卓和IOS,但是网上看过很多资料都说Xamarin比较坑,一般的 ...
- webRTC中音频相关的netEQ(一):概述
上篇文章(语音通信中终端上的时延(latency)及减小方法)说从本篇开始会切入webRTC中的netEQ主题,netEQ是webRTC中音频技术方面的两大核心技术之一(另一核心技术是音频的前后处理, ...
- 前端-JavaScript1-7——JavaScript之数学运算符
---恢复内容开始--- 运算符叫做operator,也可以叫做操作符.运算符有很多种,一元运算符.二元运算符:数学运算符.逻辑运算符……我们今天先学习数学运算符,比较简单 + 加法 - ...
- Kong(V1.0.2)loadbalancing
介绍 Kong为多个后端服务提供了多种负载平衡请求的方法:一种简单的基于DNS-based的方法,以及一种更动态的环形负载均衡器ring-balancer,它还允许在不需要DNS服务器的情况下使用se ...
- windows短路径转换成长路径
参考: https://blog.csdn.net/wxqian25/article/details/43951281 https://docs.microsoft.com/en-us/windows ...
- [EasyUI]确认删除
//删除方法 function del() { var obj = getSelected(); if (obj) { $.messager.confirm('确认', '确定要删除:' + obj. ...