- 论坛徽章:
- 0
|
五,Relayd负载均衡(3层)
1,配置PF的NAT策略
#vi /etc/pf.conf
将以上pf修改NAT规则,开启relayd的NAT,关闭原有RDR的均衡
# ********** NAT Configure ******************* #
rdr-anchor "relayd/*"
#nat on $ext_if inet from any to $ext_tc50 -> 10.1.222.97
#rdr on em1 proto tcp from any to $ext_tc50 port 7777 -> $tc50_hosts port 7777
2,配置relayd(3层)均衡功能
#vi /etc/relayd.conf
# ******************************************** #
# Edit By Sunwaylove #
# Support:010-8513XXXX #
# Mail:sunwaylove@163.com #
# ******************************************** #
#***** Macros *****
ext_addr="192.168.251.2"
tc50_hosts1="10.1.222.98"
tc50_hosts2="10.1.222.97"
tc50_hosts3="10.1.222.95"
#***** Global Options *****
interval 10
timeout 1000
prefork 5
# Each table will be mapped to a pf table.
table <webjy> { $tc50_hosts1, $tc50_hosts2, $tc50_hosts3 }
table <fallback> { 127.0.0.1 }
# Services will be mapped to a rdr rule.
redirect webjy {
# Run as a simple TCP relay
listen on $ext_addr port 7777
tag relayd
forward to <webjy> check tcp
# forward to <webjy> port 7777 mode roundrobin check tcp
# forward to <fallback> check icmp
}
启动relayd
#relayd –f relayd.conf
观察启动状态
#relayctl show summary
bash-2.04# relayctl show summary
Id Type Name Avlblty Status
0 redirect webjy active
2 table webjy:7777 active (3 hosts up)
6 host 10.1.222.98 100.00% up
5 host 10.1.222.97 100.00% up
4 host 10.1.222.95 100.00% up
开启测试压力工具,连接并发数总共20000
这时候BSD状态:
#top
load averages: 0.12, 0.18, 0.15 19:20:55
32 processes: 1 running, 30 idle, 1 on processor
CPU0 states: 0.0% user, 0.0% nice, 0.0% system, 0.6% interrupt, 99.4% idle
CPU1 states: 0.0% user, 0.0% nice, 0.0% system, 0.0% interrupt, 100% idle
CPU2 states: 0.0% user, 0.0% nice, 0.0% system, 0.0% interrupt, 100% idle
CPU3 states: 0.0% user, 0.0% nice, 0.0% system, 0.0% interrupt, 100% idle
CPU4 states: 0.0% user, 0.0% nice, 0.0% system, 0.0% interrupt, 100% idle
CPU5 states: 0.0% user, 0.0% nice, 0.0% system, 0.0% interrupt, 100% idle
CPU6 states: 0.0% user, 0.0% nice, 0.0% system, 0.0% interrupt, 100% idle
CPU7 states: 0.0% user, 0.0% nice, 0.0% system, 0.0% interrupt, 100% idle
Memory: Real: 12M/84M act/tot Free: 2933M Swap: 0K/1028M used/tot
PID USERNAME PRI NICE SIZE RES STATE WAIT TIME CPU COMMAND
32611 root 28 0 1460K 1792K run/0 - 0:00 0.00% sshd2
29775 root 2 0 532K 428K idle netio 0:00 0.00% pflogd
23989 sunwei 10 0 584K 1196K idle wait 0:00 0.00% bash
16629 _syslogd 2 0 384K 748K sleep/0 poll 0:00 0.00% syslogd
19339 root 10 0 584K 1304K sleep/0 wait 0:00 0.00% bash
27134 root 2 0 564K 796K idle select 0:00 0.00% cron
32686 _pflogd 4 0 596K 340K sleep/0 bpf 0:00 0.00% pflogd
27664 _relayd 2 0 712K 1208K idle kqread 0:00 0.00% relayd
20595 _relayd 2 0 712K 1292K idle kqread 0:00 0.00% relayd
31953 _relayd 2 0 708K 1256K sleep/0 kqread 0:00 0.00% relayd
9744 _relayd 2 0 604K 1204K idle kqread 0:00 0.00% relayd
12731 _relayd 2 0 604K 1320K idle kqread 0:00 0.00% relayd
19210 _relayd 2 0 1084K 1608K sleep/0 kqread 0:00 0.00% relayd
16058 _relayd 2 0 608K 1224K idle kqread 0:00 0.00% relayd
9807 _relayd 2 0 708K 1196K idle kqread 0:00 0.00% relayd
28725 _relayd 2 0 712K 1208K idle kqread 0:00 0.00% relayd
840 _relayd 2 0 604K 1288K sleep/0 kqread 0:00 0.00% relayd
18995 root 2 0 1032K 1536K sleep/0 kqread 0:00 0.00% relayd
22692 root 2 0 936K 1572K sleep/0 kqread 0:00 0.00% relayd
12036 root 3 0 320K 724K idle ttyin 0:00 0.00% getty
15104 root 28 0 620K 1400K onproc/0 - 0:00 0.00% top
#vmstat –w 1
procs memory page disks traps cpu
r b w avm fre flt re pi po fr sr sd0 cd0 int sys cs us sy id
0 0 0 7200 3011256 7 0 0 0 0 0 0 0 471 49 17 0 0 100
0 0 0 7200 3011256 7 0 0 0 0 0 0 0 477 129 29 0 0 100
0 0 0 7200 3011256 7 0 0 0 0 0 0 0 476 23 12 0 0 100
0 0 0 7200 3011256 7 0 0 0 0 0 0 0 468 23 12 0 0 100
0 0 0 7200 3011256 7 0 0 0 0 0 0 0 479 23 12 0 0 100
0 0 0 7200 3011256 7 0 0 0 0 0 0 0 459 26 14 0 0 100
0 0 0 7200 3011256 7 0 0 0 0 0 0 0 475 26 15 0 0 100
0 0 0 7200 3011256 7 0 0 0 0 0 0 0 475 23 12 0 0 100
CPU-8个内核 基本闲置
内存也基本闲置状态
测试成功!
六,Relayd负载均衡(7层)
1,配置PF的NAT策略
#vi /etc/pf.conf
将以上pf修改NAT规则,开启relayd的NAT,关闭原有RDR的均衡
# ********** NAT Configure ******************* #
rdr-anchor "relayd/*"
#nat on $ext_if inet from any to $ext_tc50 -> 10.1.222.97
#rdr on em1 proto tcp from any to $ext_tc50 port 7777 -> $tc50_hosts port 7777
2,配置relayd(7层)均衡功能
#vi /etc/relayd.conf
# ******************************************** #
# Edit By Sunwaylove #
# Support:010-8513XXXX #
# Mail:sunwaylove@163.com #
# ******************************************** #
# Macros
ext_addr="192.168.251.2"
tc50_hosts1="10.1.222.98"
tc50_hosts2="10.1.222.97"
tc50_hosts3="10.1.222.95"
# Global Options
interval 10
timeout 1000
prefork 5
# Each table will be mapped to a pf table.
table <webjy> { $tc50_hosts1, $tc50_hosts2, $tc50_hosts3 }
# Services will be mapped to a rdr rule.
protocol tc50 {
# The TCP_NODELAY option is required for "smooth" terminal sessions
tcp nodelay
}
relay webjy {
# Run as a simple TCP relay
listen on $ext_addr port 7777
protocol tc50
# Forward to the shared carp(4) address of an internal gateway
forward to <webjy> port 7777 mode roundrobin check tcp
}
启动relayd
#relayd –f relayd.conf
观察启动状态
#relayctl show summary
bash-2.04# relayctl show summary
Id Type Name Avlblty Status
0 realy webjy active
2 table webjy:7777 active (3 hosts up)
6 host 10.1.222.98 100.00% up
5 host 10.1.222.97 100.00% up
4 host 10.1.222.95 100.00% up
开启测试压力工具,连接并发数总共20000
这时候BSD状态:
#top
load averages: 0.12, 0.18, 0.15 19:20:55
32 processes: 1 running, 30 idle, 1 on processor
CPU0 states: 0.0% user, 0.0% nice, 0.0% system, 0.4% interrupt, 99.6% idle
CPU1 states: 0.0% user, 0.0% nice, 0.0% system, 0.0% interrupt, 100% idle
CPU2 states: 0.0% user, 0.0% nice, 0.0% system, 0.0% interrupt, 100% idle
CPU3 states: 0.0% user, 0.0% nice, 0.0% system, 0.0% interrupt, 100% idle
CPU4 states: 0.0% user, 0.0% nice, 0.0% system, 0.0% interrupt, 100% idle
CPU5 states: 0.0% user, 0.0% nice, 0.0% system, 0.0% interrupt, 100% idle
CPU6 states: 0.0% user, 0.0% nice, 0.0% system, 0.0% interrupt, 100% idle
CPU7 states: 0.0% user, 0.0% nice, 0.0% system, 0.0% interrupt, 100% idle
Memory: Real: 12M/84M act/tot Free: 2933M Swap: 0K/1028M used/tot
PID USERNAME PRI NICE SIZE RES STATE WAIT TIME CPU COMMAND
32611 root 28 0 1460K 1792K run/0 - 0:00 0.00% sshd2
29775 root 2 0 532K 428K idle netio 0:00 0.00% pflogd
23989 sunwei 10 0 584K 1196K idle wait 0:00 0.00% bash
16629 _syslogd 2 0 384K 748K sleep/0 poll 0:00 0.00% syslogd
19339 root 10 0 584K 1304K sleep/0 wait 0:00 0.00% bash
27134 root 2 0 564K 796K idle select 0:00 0.00% cron
32686 _pflogd 4 0 596K 340K sleep/0 bpf 0:00 0.00% pflogd
27664 _relayd 2 0 712K 1208K idle kqread 0:00 0.00% relayd
20595 _relayd 2 0 712K 1292K idle kqread 0:00 0.00% relayd
31953 _relayd 2 0 708K 1256K sleep/0 kqread 0:00 0.00% relayd
9744 _relayd 2 0 604K 1204K idle kqread 0:00 0.00% relayd
12731 _relayd 2 0 604K 1320K idle kqread 0:00 0.00% relayd
19210 _relayd 2 0 1084K 1608K sleep/0 kqread 0:00 0.00% relayd
16058 _relayd 2 0 608K 1224K idle kqread 0:00 0.00% relayd
9807 _relayd 2 0 708K 1196K idle kqread 0:00 0.00% relayd
28725 _relayd 2 0 712K 1208K idle kqread 0:00 0.00% relayd
840 _relayd 2 0 604K 1288K sleep/0 kqread 0:00 0.00% relayd
18995 root 2 0 1032K 1536K sleep/0 kqread 0:00 0.00% relayd
22692 root 2 0 936K 1572K sleep/0 kqread 0:00 0.00% relayd
12036 root 3 0 320K 724K idle ttyin 0:00 0.00% getty
15104 root 28 0 620K 1400K onproc/0 - 0:00 0.00% top
#vmstat –w 1
procs memory page disks traps cpu
r b w avm fre flt re pi po fr sr sd0 cd0 int sys cs us sy id
0 0 0 7200 3011256 7 0 0 0 0 0 0 0 471 49 17 0 0 100
0 0 0 7200 3011256 7 0 0 0 0 0 0 0 477 129 29 0 0 100
0 0 0 7200 3011256 7 0 0 0 0 0 0 0 476 23 12 0 0 100
0 0 0 7200 3011256 7 0 0 0 0 0 0 0 468 23 12 0 0 100
0 0 0 7200 3011256 7 0 0 0 0 0 0 0 479 23 12 0 0 100
0 0 0 7200 3011256 7 0 0 0 0 0 0 0 459 26 14 0 0 100
0 0 0 7200 3011256 7 0 0 0 0 0 0 0 475 26 15 0 0 100
0 0 0 7200 3011256 7 0 0 0 0 0 0 0 475 23 12 0 0 100
0 0 0 7200 3011256 7 0 0 0 0 0 0 0 471 23 12 0 0 100
CPU-8个内核 基本闲置
内存也基本闲置状态
测试成功!
[ 本帖最后由 sunwaylove 于 2008-5-17 22:10 编辑 ] |
|