1 Star 0 Fork 38

JORDANSG / G5

forked from calvinwilliams / G5 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
LGPL-2.1
通讯转发分发(负载均衡)器(G5)

1.开发背景
	今天和系统运维的老大聊天,谈到一直在用的F5,行里对其评价为价格过高、功能复杂难懂,没有发挥相应的价值。因为以前我曾经给行里开发过一个通讯中间件,附带软实现了负载均衡,几年使用下来一直效果不错,突然想自己再软实现一个纯负载均衡通讯分发器,并开源分享给大家。
	说干就干,回到家,搜了一下网上同类软件,整理技术需求,
	软件定义如下:
	基于规则的通讯转发、分发。客户端连入时,根据来源网络地址和本地侦听端口查询转发规则,参照负载均衡算法分发到目标网络地址集合中的其中一个。
	
	实现目标如下:
	* 支持长/短TCP,后续还会支持UDP
	* 与应用层协议无关,即支持HTTP,FTP,TELNET,SSH等等所有应用层协议
	* 稳定高效,Linux下首选epoll(ET模式),全异步设计,也决定了目前仅支持Linux
	* 分发规则配置文件;也支持远程在线管理规则,以及查询状态
	* 支持多种主流负载均衡算法
	* 源码和可执行程序体型轻巧,概念简单,使用快捷
	
	完整实现基于epoll(ET)的非堵塞全异步应用层框架,主要包含以下内容:
	* 基于epoll(ET)事件处理应用层框架。
	* accept客户端连接后转连服务端connect的非堵塞异步实现。
	* recv客户端数据后转发send服务端时,当转发速度小于接收速度情况下的非堵塞异步实现。
	* 客户端和服务端的请求和响应在转发端的并发隔离。
	
	使用场景:
	* 通讯转发、分发
	* 与无负载均衡功能的通讯软件配合实现本地连接对端的负载均衡分发,避免改造通讯软件带来的工作量和风险
	* 低成本的网站前端负载均衡通讯网关
	
	研发之前,取个好听的名字,相对于硬实现F5,就取名为软实现G5吧 ^_^
	经过5个晚上的奋笔疾书,捣鼓出第一版,源代码只有一个.c(2400行)和一个.h文件(260行),编译链接出可执行程序约70KB大小。
	
2.安装部署
	从http://git.oschina.net/calvinwilliams/G5下载源码安装包,在你的临时目录解开
	$ tar xvzf G5-x.x.x.tar.gz
	$ cd G5-x.x.x/src
	$ make -f makefile.Linux clean
	$ make -f makefile.Linux install
	因为只有一对源文件,所以编译链接很快,也便于编译器优化,更便于你自己手工编译。
	如果不报错的话,可执行程序G5就安装到/usr/bin/下了。
	
3.基本使用
3.1.命令行参数
	不带参数执行G5会显示版本、命令行参数说明等信息
	$ G5
	G5 - tcp LB dispatch
	v1.0.0 build Apr  6 2014 15:00:31 WITH 100:1024:4096,10:3:100,64
	Copyright by calvin 2014
	Email : calvinwilliams.c@gmail.com
	
	USAGE : G5 -f config_pathfilename [ -r forward_rule_maxcount ] [ -s forward_session_maxcount ] [ -b transfer_bufsize ] [ -d ]
	
3.1.启动
	因为是工具型软件,所以用户界面设计的比较简单,自行编写一个分发规则配置文件
	$ cat demo.conf
	admin G 192.168.1.54:* - 192.168.1.54:8060 ;
	webdog MS 192.168.1.54:* - 192.168.1.54:8070 > 192.168.1.79:8088 ;
	webdog2 RR *.*.*.*:* - 192.168.1.54:8080 > 192.168.1.79:8089 192.168.1.79:8090 192.168.1.79:8091 ;
	作为G5唯一一个必须的命令行参数-f启动
	$ G5 -f demo.conf
	G5 - tcp LB dispatch
	v1.1.0 build Apr 12 2014 03:57:33 WITH 100:1024:4096,10:3:100,64
	Copyright by calvin 2014
	Email : calvinwilliams.c@gmail.com
	forward_rule_maxcount    [100]
	forward_session_maxcount [1024]
	transfer_bufsize         [4096]bytes
	epoll_create ok #3#
	2014-04-12 03:59:05 | admin G 192.168.1.54:* - 192.168.1.54:8060(LISTEN)#5# ;
	2014-04-12 03:59:05 | webdog MS 192.168.1.54:* 192.168.1.79:* - 192.168.1.54:8070(LISTEN)#7# > 192.168.1.79:8088 ;
	2014-04-12 03:59:05 | webdog2 RR *.*.*.*:* - 192.168.1.54:8080(LISTEN)#8# > 192.168.1.79:8089 192.168.1.79:8090 192.168.1.79:8091 ;
	...
	之后产生的所有普通信息、错误都输出到标准输出、错误输出上,如果启动参数加上-d,则还会输出所有调试信息,如连接、断开、数据分发
	
	我模拟发起一个HTTP请求
	$ lynx http://192.168.1.54:8080/index.php
	G5的标准输出上产生如下信息
	2014-04-12 03:60:05 | forward2 [192.168.1.54:43477]#3# - [192.168.1.54:8080]#7# > [192.168.1.79:8089]#8#
	2014-04-12 03:60:05 | transfer #3# [324]bytes to #8#
	2014-04-12 03:60:05 | transfer #8# [257]bytes to #3#
	2014-04-12 03:60:05 | close #8# recv 0
	说明一下
	192.168.1.54:43477(lynx)连接192.168.1.54:8080(G5)被转发到网站服务器192.168.1.79:8089(apache)
	lynx发送了HTTP请求324字节给网站服务器
	lynx从网站服务器接收了HTTP响应257字节
	服务端首先断开连接
	
	一般都使用nohup使其变为守护进程,输出导向到文件
	$ nohup G5 demo.conf >demo.log 2>&1 &
	
3.2.停止
	别客气,直接kill (pid)即可。
	
4.配置文件
	配置文件里一行为一条转发规则,每条规则由三大段组成:规则名称、规则类型和规则实体,之间用白字符(空格、TAB)隔开。
	
4.1.规则名称
	唯一标识该规则,便于新增、修改和删除规则。
	
4.2.规则类型
	说明该规则是在线管理(G),还是以某种通讯分发算法。目前实现的算法列表如下
	MS : 主备模式,即一直连接第一个目标地址,如果第一个目标地址故障了,切换到下一个目标地址
	RR : 轮询模式,把所有目标地址按次序依次循环使用
	LC : 最少连接数模式,在目标地址集合中挑选当前最少连接的目标
	RT : 最小响应时间模式,在目标地址集合中挑选历史数据交换最快的目标
	RD : 随机模式,随机选择目标地址
	HS : HASH模式,根据来源地址计算HASH得到一个唯一固定的目标地址
	
4.3.规则实体
	格式为"来源地址集合 - 本地转发地址集合 > 目标地址集合 ;",其中三个地址集合内可以包含一个地址或白字符隔开的地址列表。单个地址由"IP:PORT"组成。来源单个地址中的IP和PORT可以使用'*'和'?'通配。当只有一个目标地址时,通讯分发算法就没有意义了。
	
4.4.属性
	规则类型可选追加属性集合格式为"( 属性1名称 属性1值 属性2名称 属性2值 ... )",之间用白字符(空格、TAB)隔开。目前可用的属性有
		timeout 秒数
	规则实体内来源地址集合可选追加属性集合同规则类型属性集合。目前可用的属性有
		maxclient 最大客户端会话数量
	
4.5.示例
	回来解释一下前面展示的配置文件
	$ cat demo.conf
	# 只允许本机192.168.1.54连接到G5在线管理规则,管理连接空闲超时为5分钟,超时时强制断开
	admin G ( timeout 300 ) 192.168.1.54:* - 192.168.1.54:8060 ;
	# 本地所有TCP连接到本机8070端口时统统转发到192.168.1.79:8088
	# 用于跨网段的通讯转发,空闲超时为2分钟,超时时强制断开,最大客户端会话数量为5个,多余连接将被强制断开
	webdog MS ( timeout 120 ) 192.168.1.54:* 192.168.1.79:* - 192.168.1.54:8070 > 192.168.1.79:8088 ;
	# 允许所有主机连接192.168.1.79:8089,并以轮询算法分发给三个服务器192.168.1.79:8089 192.168.1.79:8090 192.168.1.79:8091
	# 用于网站前端负载均衡通讯节点
	webdog2 RR *.*.*.*:* ( maxclients 5 ) - 192.168.1.54:8080 > 192.168.1.79:8089 192.168.1.79:8090 192.168.1.79:8091 ;
	还简单吧
	
5.在线管理
	G5在启动时必须指定一个配置文件装载所有规则并以之工作,也支持远程连接上管理端口在线管理规则,用telnet即可
	$ telnet 192.168.1.54 8060
	Trying 192.168.1.54...
	Connected to rhel54 (192.168.1.54).
	Escape character is '^]'.
	>
	'>'为输入提示符,后面可以键入的命令有
	ver : 显示G5版本及编译日期时间
	quit : 断开管理连接
	list rules : 显示当前所有转发规则
	add rule (...规则...) : 新增转发规则
	modify rule (...规则...) : 修改转发规则
	remove rule (规则名称) : 删除转发规则
	dump rule : 保存所有转发规则到启动时指定的配置文件中
	list forwards : 显示当前所有转发连接信息
	
	使用示例
	$ telnet 192.168.1.54 8060
	Trying 192.168.1.54...
	Connected to rhel54 (192.168.1.54).
	Escape character is '^]'.
	> ver
	version v1.0.0 build Apr  3 2014 08:05:54
	> list rules
	    1 : admin G ( timeout 300 ) 192.168.1.54:* ( conntions[1/2] ) - 192.168.1.54:8060 ;
	    2 : webdog MS ( timeout 120 ) 192.168.1.54:* 192.168.1.79:* - 192.168.1.54:8070 > 192.168.1.79:8088 ;
	    3 : webdog2 RR *.*.*.*:* ( conntions[0/100] ) - 192.168.1.54:8080 > 192.168.1.79:8089 192.168.1.79:8090 192.168.1.79:8091 ;
	> add rule webdog3 MS 192.168.1.54:* - 192.168.1.54:8070 > 192.168.1.79:8088 ;
	add forward rule ok
	> modify rule webdog3 HS 192.168.1.54:* - 192.168.1.54:8070 > 192.168.1.79:8088 ;
	modify forward rule ok
	> remove rule webdog3
	remove forward rule ok
	> dump rules
	dump all forward rules ok
	> list forwards
	    1 : LISTEN [192.168.1.54:8060]#5#
	    2 : LISTEN [192.168.1.54:8060]#6#
	    3 : LISTEN [192.168.1.54:8070]#7#
	    4 : LISTEN [192.168.1.54:8080]#8#
	    5 : CLIENT [192.168.1.54:54162]#4# - MANAGE [192.168.1.54:8060]#5#
	 2138 : CLIENT [192.168.1.54:39869]#11# < LISTEN [192.168.1.54:8080]#8# - SERVER [192.168.1.79:8090]#12# connected
	 2139 : CLIENT [192.168.1.54:39869]#11# - LISTEN [192.168.1.54:8080]#8# > SERVER [192.168.1.79:8090]#12# connected
	 2140 : CLIENT [192.168.1.54:39871]#27# < LISTEN [192.168.1.54:8080]#8# - SERVER [192.168.1.79:8091]#28# connected
	 2141 : CLIENT [192.168.1.54:39871]#27# - LISTEN [192.168.1.54:8080]#8# > SERVER [192.168.1.79:8091]#28# connected
	 2142 : CLIENT [192.168.1.54:39873]#17# < LISTEN [192.168.1.54:8080]#8# - SERVER [192.168.1.79:8089]#18# connected
	 2143 : CLIENT [192.168.1.54:39875]#25# < LISTEN [192.168.1.54:8080]#8# - SERVER [192.168.1.79:8090]#26# connected
	 2144 : CLIENT [192.168.1.54:39875]#25# - LISTEN [192.168.1.54:8080]#8# > SERVER [192.168.1.79:8090]#26# connected
	 2145 : CLIENT [192.168.1.54:39873]#17# - LISTEN [192.168.1.54:8080]#8# > SERVER [192.168.1.79:8089]#18# connected
	 2146 : CLIENT [192.168.1.54:39877]#21# < LISTEN [192.168.1.54:8080]#8# - SERVER [192.168.1.79:8091]#22# connected
	 2147 : CLIENT [192.168.1.54:39877]#21# - LISTEN [192.168.1.54:8080]#8# > SERVER [192.168.1.79:8091]#22# connected
	 2148 : CLIENT [192.168.1.54:39879]#9# < LISTEN [192.168.1.54:8080]#8# - SERVER [192.168.1.79:8089]#10# connected
	 2149 : CLIENT [192.168.1.54:39879]#9# - LISTEN [192.168.1.54:8080]#8# > SERVER [192.168.1.79:8089]#10# connected
	 2150 : CLIENT [192.168.1.54:39881]#15# < LISTEN [192.168.1.54:8080]#8# - SERVER [192.168.1.79:8090]#16# connected
	 2151 : CLIENT [192.168.1.54:39881]#15# - LISTEN [192.168.1.54:8080]#8# > SERVER [192.168.1.79:8090]#16# connected
	 2152 : CLIENT [192.168.1.54:39883]#19# < LISTEN [192.168.1.54:8080]#8# - SERVER [192.168.1.79:8091]#20# connected
	 2153 : CLIENT [192.168.1.54:39884]#23# < LISTEN [192.168.1.54:8080]#8# - SERVER [192.168.1.79:8089]#24# connected
	 2154 : CLIENT [192.168.1.54:39884]#23# - LISTEN [192.168.1.54:8080]#8# > SERVER [192.168.1.79:8089]#24# connected
	 2155 : CLIENT [192.168.1.54:39883]#19# - LISTEN [192.168.1.54:8080]#8# > SERVER [192.168.1.79:8091]#20# connected
	 2156 : CLIENT [192.168.1.54:39887]#13# < LISTEN [192.168.1.54:8080]#8# - SERVER [192.168.1.79:8090]#14# connected
	 2157 : CLIENT [192.168.1.54:39887]#13# - LISTEN [192.168.1.54:8080]#8# > SERVER [192.168.1.79:8090]#14# connected
	> quit
	Connection closed by foreign host.
	$
	
6.性能测试
	因为是简单的通讯转发、分发器,内部使用epoll(ET)+全异步实现,达到高并发和充分负载均衡,几乎可以榨干单核硬件资源。
	由于我没有完整靠谱的压测环境,只能在我的老爷机上做直连和通过G5转连的性能比较差异。
	
	压测硬件(2007年买的老爷机)
		CPU  : Intel Dual E2160 1.8GHz 1.81GHz
		内存 : 2GB
		硬盘 : 希捷 250GB 7200转
	压测软件
		Windows XP SP3 ( VMware 6.0 ( RedHat Enterprise Linux 5.4 分了256MB内存 ) )
	压测场景
		ab直连apache 和 ab通过G5转发给apache
		并发数100,总请求数10000次
	
	首先是192.168.1.54:*(apache ab)直连192.168.1.79:8090(apache 2.2.13 for win32),

	Server Software:        Apache/2.2.13
	Server Hostname:        192.168.1.79
	Server Port:            8090
	
	Document Path:          /index.html
	Document Length:        44 bytes
	
	Concurrency Level:      100
	Time taken for tests:   12.503706 seconds
	Complete requests:      10000
	Failed requests:        0
	Write errors:           0
	Total transferred:      3160000 bytes
	HTML transferred:       440000 bytes
	Requests per second:    799.76 [#/sec] (mean)
	Time per request:       125.037 [ms] (mean)
	Time per request:       1.250 [ms] (mean, across all concurrent requests)
	Transfer rate:          246.73 [Kbytes/sec] received
	
	Connection Times (ms)
	             min  mean[+/-sd] median   max
	Connect:        0    0   4.4      0      86
	Processing:    11  123  31.7    113     283
	Waiting:        8  122  31.6    112     281
	Total:         28  123  31.9    113     284
	
	Percentage of the requests served within a certain time (ms)
	 50%    113
	 66%    115
	 75%    117
	 80%    120
	 90%    163
	 95%    187
	 98%    249
	 99%    256
	100%    284 (longest request)

	然后是192.168.1.54:*(apache ab)发往192.168.1.54:8080(G5)(主备模式MS)分发给192.168.1.79:8089,8090,8091(apache 2.2.13 for win32),

	Server Software:        Apache/2.2.13
	Server Hostname:        192.168.1.54
	Server Port:            8080
	
	Document Path:          /index.html
	Document Length:        44 bytes
	
	Concurrency Level:      100
	Time taken for tests:   14.235889 seconds
	Complete requests:      10000
	Failed requests:        0
	Write errors:           0
	Total transferred:      3160000 bytes
	HTML transferred:       440000 bytes
	Requests per second:    702.45 [#/sec] (mean)
	Time per request:       142.359 [ms] (mean)
	Time per request:       1.424 [ms] (mean, across all concurrent requests)
	Transfer rate:          216.71 [Kbytes/sec] received
	
	Connection Times (ms)
	             min  mean[+/-sd] median   max
	Connect:        0    0   8.3      0     154
	Processing:    25  140  31.3    132     335
	Waiting:       22  139  31.2    131     334
	Total:         70  140  32.3    132     338
	
	Percentage of the requests served within a certain time (ms)
	 50%    132
	 66%    134
	 75%    137
	 80%    140
	 90%    175
	 95%    190
	 98%    275
	 99%    295
	100%    338 (longest request)

	然后是192.168.1.54:*(apache ab)发往192.168.1.54:8080(G5)(轮询模式RR)分发给192.168.1.79:8089,8090,8091(apache 2.2.13 for win32),

	Server Software:        Apache/2.2.13
	Server Hostname:        192.168.1.54
	Server Port:            8080
	
	Document Path:          /index.html
	Document Length:        44 bytes
	
	Concurrency Level:      100
	Time taken for tests:   14.15712 seconds
	Complete requests:      10000
	Failed requests:        0
	Write errors:           0
	Total transferred:      3160316 bytes
	HTML transferred:       440044 bytes
	Requests per second:    713.48 [#/sec] (mean)
	Time per request:       140.157 [ms] (mean)
	Time per request:       1.402 [ms] (mean, across all concurrent requests)
	Transfer rate:          220.18 [Kbytes/sec] received
	
	Connection Times (ms)
	             min  mean[+/-sd] median   max
	Connect:        0    0   7.5      0     140
	Processing:    26  137  67.8     91     342
	Waiting:       25  137  67.8     90     340
	Total:         49  138  68.1     91     347
	
	Percentage of the requests served within a certain time (ms)
	 50%     91
	 66%    178
	 75%    219
	 80%    222
	 90%    229
	 95%    259
	 98%    273
	 99%    279
	100%    347 (longest request)

	然后是192.168.1.54:*(apache ab)发往192.168.1.54:8080(G5)(最小响应时间模式RT)分发给192.168.1.79:8089,8090,8091(apache 2.2.13 for win32),

	Server Software:        Apache/2.2.13
	Server Hostname:        192.168.1.54
	Server Port:            8080
	
	Document Path:          /index.html
	Document Length:        44 bytes
	
	Concurrency Level:      100
	Time taken for tests:   14.260485 seconds
	Complete requests:      10000
	Failed requests:        0
	Write errors:           0
	Total transferred:      3160000 bytes
	HTML transferred:       440000 bytes
	Requests per second:    701.24 [#/sec] (mean)
	Time per request:       142.605 [ms] (mean)
	Time per request:       1.426 [ms] (mean, across all concurrent requests)
	Transfer rate:          216.33 [Kbytes/sec] received
	
	Connection Times (ms)
	             min  mean[+/-sd] median   max
	Connect:        0    0   7.7      0     148
	Processing:    29  140  27.3    133     346
	Waiting:       26  139  27.2    132     346
	Total:         65  141  28.4    133     346
	
	Percentage of the requests served within a certain time (ms)
	 50%    133
	 66%    136
	 75%    138
	 80%    140
	 90%    181
	 95%    190
	 98%    241
	 99%    287
	100%    346 (longest request)

	然后是192.168.1.54:*(apache ab)发往192.168.1.54:8080(G5)(随机模式RD)分发给192.168.1.79:8089,8090,8091(apache 2.2.13 for win32),

	Server Software:        Apache/2.2.13
	Server Hostname:        192.168.1.54
	Server Port:            8080
	
	Document Path:          /index.html
	Document Length:        44 bytes
	
	Concurrency Level:      100
	Time taken for tests:   14.114779 seconds
	Complete requests:      10000
	Failed requests:        0
	Write errors:           0
	Total transferred:      3160632 bytes
	HTML transferred:       440088 bytes
	Requests per second:    708.48 [#/sec] (mean)
	Time per request:       141.148 [ms] (mean)
	Time per request:       1.411 [ms] (mean, across all concurrent requests)
	Transfer rate:          218.64 [Kbytes/sec] received
	
	Connection Times (ms)
	             min  mean[+/-sd] median   max
	Connect:        0    0   7.3      0     139
	Processing:    22  138  67.3     92     354
	Waiting:       21  138  67.3     92     353
	Total:         48  139  67.6     92     356
	
	Percentage of the requests served within a certain time (ms)
	 50%     92
	 66%    184
	 75%    212
	 80%    221
	 90%    239
	 95%    255
	 98%    279
	 99%    292
	100%    356 (longest request)
	
	可以看出,转发的总耗时比直连多了10%左右,大体还是可以接受的,如果G5和WebServer分开部署在不同机器里,G5就能发挥出负载均衡的优势,性能也会大幅提升。
	以后若有更好的环境,我将会做更全面更深入的压测。

7.最后
	作为一个负载均衡通讯转发分发网络工具,G5基本实现设计目标,并发布出来分享给开源世界,欢迎试用。
	G5源代码作为epoll(ET)+全异步综合使用示例也供大家学习参考,欢迎批评指正。
	如有问题或建议请及时联系我,让我们共同把她搞大!
	开源项目首页 : http://git.oschina.net/calvinwilliams/G5
	作者邮箱 : calvinwilliams.c@gmail.com
GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999 Copyright (C) 1991, 1999 Free Software Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. (This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.) Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. GNU LESSER GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Libraries If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License). To apply these terms, attach the following notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. {description} Copyright (C) 2014 calvinwilliams.c This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the library, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the library `Frob' (a library for tweaking knobs) written by James Random Hacker. {signature of Ty Coon}, 1 April 1990 Ty Coon, President of Vice That's all there is to it!

简介

负载均衡通讯分发器(LB dispatcher) 展开 收起
LGPL-2.1
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/zzsg2005/G5.git
git@gitee.com:zzsg2005/G5.git
zzsg2005
G5
G5
master

搜索帮助