一,OpenBSD-4.3安装和准备BSD爱好者乐园 n-aZ;X-j
方法精化贴上很多,这里不作重复介绍。
x6{B4|_m"W准备设备:BSD服务器一台、测试服务器3台、压力测试服务器2台
7O1N n.rzBSD服务器选购了Lenovo R515 1U机架式
_&h)JL+k]-CkiCPU:4核 *2BSD爱好者乐园d `"?c~m
:1G *4BSD爱好者乐园D;MnZqOph4d n
:73G 1.5K转速 * 3 (做 6)BSD爱好者乐园^&Vt*gL:pl
测试服务器均为Dell GX620个人电脑
(b&m4q8gfVx1}
R)}c-X-k二,OpenBSD系统
4Qa @JP3Fk-mb1c1,关闭无用服务,如sendmail,inetd等BSD爱好者乐园g:zm[EO*p
修改rc.conf关闭不需要启动的服务BSD爱好者乐园/@2n:|w%`9\2UN
#vi /etc/rc.conf BSD爱好者乐园4T3{f;a ~p"??9Q
sendmail_flags=NO
u*| mn [9Q$^inetd=NOBSD爱好者乐园e zZX Z"aE"l0M,w
其他如yp也可以关闭。
|&AK b v4rY6IBSD爱好者乐园#E*A(~0TM8^%s8qlL F7C
2,优化系统参数(参考,视自身情况而定)BSD爱好者乐园E u g,Q+Ke
#vi /etc/sysctl.conf
WT7s ]0\E&`F}打开forwarding
Yz1I4h9Vnet.inet.ip.forwarding=1 BSD爱好者乐园Y5\z G|8P"r3[wt
net.inet.ip.mforwarding=1
bz w9v9QPq.QWZj-}Vnet.inet6.ip6.forwarding=1BSD爱好者乐园8[*Ps_xV1T
net.inet6.ip6.mforwarding=1
K/i?)jq1I5~s/_BSD爱好者乐园w7i9ln^O v
优化内核参数
o)T?(s1\dV$B#*** Edit by sunwaylove *****#
z!r!go I2N-DFnsA"U#net.inet.ip.sourceroute=0
`D4],c {Z:znet.inet.tcp.drop_synfin=1BSD爱好者乐园q.Do,o9e R,Hyl
kern.maxvnodes=32768BSD爱好者乐园Y6Oi9`yt0W.m
kern.shminfo.shmall=32768BSD爱好者乐园 td.N#m8oSl0H
kern.somaxconn=65535
4p5TpXe:i,ykern.sominconn=2048BSD爱好者乐园2z6sW"i;@pj sz
kern.maxproc=65535
^(p3lt P:fZ+c0Hkern.maxfiles=65535
:|(B-NWOkern.maxclusters=32768
*Z GR9e)K/k%t:i;e&~Z#kern.securelevel=3
B L~Q\EHz/~Cknet.inet.tcp.sendspace=65535BSD爱好者乐园*g2^7C)bV0U"i^4A)c
net.inet.tcp.recvspace=65535
VGF tk-r IQnet.inet.udp.sendspace=65535BSD爱好者乐园 vuZ6Fdt
net.inet.udp.recvspace=65535
{dv_k'k ^6]BSD爱好者乐园jf6V7L(b
三,系统配置
L8?*b dm`;M;O1,安装SSH2
#N n%jhu$Y'fL,a安装最新的SSH2,替换自带OpenSSHBSD爱好者乐园({.I%K+\_ h)A%a
#tar zxf ssh-3.2.9.1.tar.gz
ir%Pir4[#cd ssh-3.2.9.1
ZIt;n,y7hz1[?q#./configureBSD爱好者乐园&|*\z9?Htq Q ma
#make
!EO[X#}S+`)H#make install
cN+w6l p `BSD爱好者乐园a?\&{E$mS
2,配置sshd2服务BSD爱好者乐园/iV5D!KgU
禁止用户登录,修改端口为2222。BSD爱好者乐园{q}'k A5f
#cd /etc/ssh2;vi sshd2_config
!S"rOy:m e7I Port 2222
*I7qIFv T PermitRootLogin nopwd
!oC,vAp'_tgO
R"b-J I4@配置sshd2为默认启动BSD爱好者乐园 T e!YH"{@ V c
#vi /etc/rc
'Fe&t6b G;^JoJ/gif [ X"${sshd_flags}" != X"NO" ]; then
O9@zX-tQLG echo -n ' sshd2'; /usr/local/sbin/sshd2 ${sshd_flags};
pu/w8tefiBSD爱好者乐园LdF)^6Qs!i1W
"a;ftVo7h重起后,上传个人证书,修改为只允许证书方式BSD爱好者乐园_,dZ0x"d o
#vi /etc/ssh2/sshd2.confBSD爱好者乐园\ A\bb
AllowedAuthentications publickey
四,PF防火墙+NAT负载均衡
Q8x2mm.DlL网络介绍:
BSD爱好者乐园 M^Yam*p(m8D内网均衡设备(3台)----------
em0| OpenBSD |
em1---------外网测试设备(2台)
BSD爱好者乐园\i|#C2W(FI?f]9X;KM9}^ ~nE内网均衡设备:{ 10.1.222.95, 10.1.222.97, 10.1.222.98 } port 7777
BSD爱好者乐园 xL(Y O;kT外网测试设备:{ 192.168.251.10, 192.168.251.11 }
BSD爱好者乐园8}c _ xg&e({eHOpenBSD—内网卡em0:10.1.222.105
(S+H |M WaOpenBSD—外网卡em1:192.168.251.6
BSD爱好者乐园*y)S(b3b F-_GG/~/a外网均衡地址:192.168.251.2 绑定在em1网卡上
lo6o0` `+Eut测试的应用名称为webjy 端口为 7777
n_&_ w5GBSD爱好者乐园P1_ hy }*s"t _配置外网卡多IP
BSD爱好者乐园o0r0Y zo(cd6Ybash-2.04# vi /etc/hostname.em1BSD爱好者乐园)sZTW-C-@ HhZlinet 192.168.251.6 255.255.255.0 NONE
BSD爱好者乐园qr;E g;I-finet alias 192.168.251.2 255.255.255.255
BSD爱好者乐园0[9TP*YBinet alias 192.168.251.3 255.255.255.255
8pz0r|1a@(Iinet alias 192.168.251.4 255.255.255.255
?)kl2EPinet alias 192.168.251.5 255.255.255.255
BSD爱好者乐园(M!eSF @w4]0MU/O U)vBSD爱好者乐园@9j/~T [{Q]$U设置rc.conf中pf为yes
$W%s ma U.Zt配置pf
BSD爱好者乐园 RtR-Jts#vi pf.confr6Zu'PYXgc2Ys8y jz M# ******************************************** #
BSD爱好者乐园*O7p;] p%_*G5VW,Z# Edit By Sunwaylove #
} y#ohs|-F!\# Support:010-8513XXXX #
%l S E Qyy4E,c# Mail:sunwaylove@163.com #
BSD爱好者乐园u*p OYY @+yr.r# ******************************************** #
BSD爱好者乐园(^Ve US8nV Htb8u9Q# ********* Start Configure ******************* #
e I.`|0R&rd\sext_if="em1"
v0p+M\c'Sd:u!Jint_if="em0"
%qmo$R%^*u'@ext_tc50="192.168.251.2"
BSD爱好者乐园,Q3Q9KfMil] F"[tc50_hosts="{ 10.1.222.95, 10.1.222.97, 10.1.222.98 }"
)m!a.rCHg2vtable
{ 10.1.222.0/24 }BSD爱好者乐园R Y%O ~.P+iff.W
table { 10.1.0.0/16 }
VT:PFtblMBSD爱好者乐园2?6uA3s8B;GL {M
# ********* Better pf-network ******************* #BSD爱好者乐园V7rw1~9{
set timeout {interval 3,frag 10}BSD爱好者乐园 y9\N7B F#h u
set timeout {tcp.first 10,tcp.opening 2,tcp.established 600}
-Va9F(C.I.^5p-y tSset timeout {tcp.closing 20,tcp.finwait 10,tcp.closed 10}BSD爱好者乐园B"c%Q{w8@(]]^l5l(W
set timeout {udp.first 20,udp.single 10,udp.multiple 10}
%[,B$o wQp5l(En,\set timeout {icmp.first 10,icmp.error 5}
L(y oMO1e _!Mset timeout {other.first 20,other.single 10,other.multiple 20}
%i5O6K MnL-[I"aFAdset timeout {adaptive.start 0,adaptive.end 0}
B vO8y`K h!pgset limit states 1000000
*Lpu la'{mset limit frags1000000 #次数为单个node(IP)并发数量BSD爱好者乐园5Iv0NL {1d h0JE
set limit src-nodes 1000000
^E aL/m)M(t^%?8Bgset limit tables 100000BSD爱好者乐园"lW5R-EI:\x2@
set limit table-entries 1000000
(ac,F$\ QPB|set optimization aggressiveBSD爱好者乐园\^x:Ss/ILi;qdO
set block-policy drop
^hzn/WJiAset require-order yes
8y/c8z#m9e1td3Lset debug none
e:H%Ee Kb7dJ$wset skip on loBSD爱好者乐园t;D oME-DN g)E
scrub in allBSD爱好者乐园x:H;r%NOz
'i}m3ia hi# ********** NAT Configure ******************* #
Cf'p6e M V2_%B @#rdr-anchor "relayd/*"BSD爱好者乐园6d {(P-qa
#nat on $ext_if inet from any to $ext_tc50 -> 10.1.222.97
Z H0Lb9L9Vrdr on em1 proto tcp from any to $ext_tc50 port 7777 -> $tc50_hosts port 7777BSD爱好者乐园.J3[P]8q?} A2Y)^Q \v
# 以下NAT只是测试方便远程操作和传输方便而设置 正式场合无意义#BSD爱好者乐园 h$QJ(BRNbb
rdr on em1 proto tcp from any to $ext_tc50 port 139 -> 10.1.222.97 port 139BSD爱好者乐园 l"`C e1ZQ&@:m
rdr on em1 proto tcp from any to $ext_tc50 port 445 -> 10.1.222.97 port 445BSD爱好者乐园p!GC vz2E$L
rdr on em0 proto tcp from any to $int_if port 3389 -> 192.168.251.10 port 3389
#bt.e*T OeQu,Hf!Qrdr on em0 proto tcp from any to $int_if port 3399 -> 192.168.251.11 port 3389BSD爱好者乐园(i&@k3d'w \'`S
uP"S1rhY*?# ********** PF Configure ******************* #
,xu(jl6V3S(x*{# ***** Deny all *****BSD爱好者乐园IYM:{-\"D
block in allBSD爱好者乐园gq-x[Co9u4I
block out allBSD爱好者乐园 ?h;d"V$Z@r@M"x
`}?D^7u` Y \(q# ***** Default Allow *****
wx whKm{&Vgpass quick on lo0 all
fR9a?%R j*x7j%nantispoof quick for { lo, $int_if }
}~(uTR,Lpass in on $ext_if inet proto 47 all
%W+^$l)TYpass in on $ext_if inet proto udp from any to any port 500BSD爱好者乐园 L/aTDX"S
pass in on $ext_if inet proto icmp from any to anyBSD爱好者乐园@wq/fQ
pass out on $ext_if inet proto 47 all
"Z|:kuwM5Xw0mz-Gpass out on $ext_if proto tcp all modulate state flags S/SA
hxlE hQ j|)Cpass out on $ext_if proto { udp, icmp } all keep stateBSD爱好者乐园A7w"k#_(V4L9e
t$@6F2i'^.R# ***** Allow testhost to pass *****BSD爱好者乐园4S9jTT6E.[YzIIL
pass in on $int_if inet from to any
fO{%J6Bi[#uVspass out on $int_if inet from any to BSD爱好者乐园["a+g#GJI7g _
#pass on $int_if inet from any to anyBSD爱好者乐园7^pd'w?(nFe/k4F)\
V8Xb d_k_.Qw/?R# ***** Allow sunwaylove to pass *****BSD爱好者乐园3yS(iAx
pass in quick on $int_if inet from 10.1.242.123 to anyBSD爱好者乐园k'}7q7m$IcRsN%S*M
pass in quick on $int_if inet from 10.1.29.138 to any
.D'V.n#H,rl&uT%Tpass out quick on $int_if inet from any to 10.1.242.123BSD爱好者乐园.j3_*?|?5r'G
pass out quick on $int_if inet from any to 10.1.29.138
`R9Na1e2M;c
{)y-z,YNae9HM# ***** Allow Proc port to pass *****BSD爱好者乐园'Ci6KMN
pass in on $ext_if inet proto tcp from 218.247.130.0 to any port 2222 flags S/SA keep stateBSD爱好者乐园e6|(AK1Qi7L
pass in on $ext_if inet proto tcp from any to any port 7777
X,e2As(jt/u^pass in on $ext_if inet proto tcp from any to any port 139BSD爱好者乐园5_:z3m%z1f/D5{+Fz;I
pass in on $ext_if inet proto tcp from any to any port 445
l!_:mB7w5_?
/f&K|6y i:T/{1X3q,D测试PF-NAT均衡
_3od*aG7KOrdr on em1 proto tcp from any to $ext_tc50 port 7777 -> $tc50_hosts port 7777BSD爱好者乐园L.vO{FW0t!WM#]*uD
)xM;d mb4L2台测试机发送方:连接数最后各为10000,总共20000
"sG:ec j3台测试机接收方:均衡后连接数各为6666左右。BSD爱好者乐园/Ad+mu7F c
ax{W+A9Z这时OpenBSD的性能状态:BSD爱好者乐园Ln_9Es\
#topBSD爱好者乐园$xCm9gdm&u
load averages: 0.08, 0.10, 0.08 19:08:15
2G:n8LONp16 processes: 1 running, 14 idle, 1 on processorBSD爱好者乐园)YV1n'}q`s
CPU0 states: 0.0% user, 0.0% nice, 0.0% system, 1.3% interrupt, 98.7% idleBSD爱好者乐园5qry+Q M
CPU1 states: 0.0% user, 0.0% nice, 0.0% system, 0.0% interrupt, 100% idleBSD爱好者乐园xtwq\Q{
CPU2 states: 0.0% user, 0.0% nice, 0.0% system, 0.0% interrupt, 100% idleBSD爱好者乐园6n4|d T,or`})uJ
CPU3 states: 0.0% user, 0.0% nice, 0.0% system, 0.0% interrupt, 100% idleBSD爱好者乐园)a)TW)f:ei
CPU4 states: 0.0% user, 0.0% nice, 0.0% system, 0.0% interrupt, 100% idleBSD爱好者乐园+r}d;nt$@
CPU5 states: 0.0% user, 0.0% nice, 0.0% system, 0.0% interrupt, 100% idle
v.}"r&x u#U/\1pCPU6 states: 0.0% user, 0.0% nice, 0.0% system, 0.0% interrupt, 100% idleBSD爱好者乐园s9R2J%E*ta ?vI
CPU7 states: 0.0% user, 0.0% nice, 0.0% system, 0.0% interrupt, 100% idleBSD爱好者乐园$@(spD.r!b
Memory: Real: 5804K/74M act/tot Free: 2943M Swap: 0K/1028M used/totBSD爱好者乐园3i+Ax*y9suY(R8c0o#X5BO0J
BSD爱好者乐园E"O-| Utr l:BS
PID USERNAME PRI NICE SIZE RES STATE WAIT TIME CPU COMMAND
.Cx{ hS0Q32611 root 28 0 1460K 1792K run/0 - 0:00 0.00% sshd2
kBPUq*{D29775 root 2 0 532K 428K idle netio 0:00 0.00% pflogdBSD爱好者乐园K0n?'G5~+r
23989 sunwei 10 0 584K 1196K idle wait 0:00 0.00%
(J.K?PD16629 _syslogd 2 0 384K 748K sleep/0 poll 0:00 0.00% syslogd
UN_e.a19339 root 10 0 584K 1300K sleep/0 wait 0:00 0.00% bashBSD爱好者乐园"A` w F:A
27134 root 2 0 564K 796K sleep/0 select 0:00 0.00% cron
6O3w]&i"c3FR32686 _pflogd 4 0 596K 340K sleep/0 bpf 0:00 0.00% pflogd
#ImR T~4Bv x12036 root 3 0 320K 724K idle ttyin 0:00 0.00% gettyBSD爱好者乐园~F3m1O@4G;[
16870 root 3 0 404K 708K idle ttyin 0:00 0.00% gettyBSD爱好者乐园Q oDG0o$[;c.C
24894 root 3 0 288K 712K idle ttyin 0:00 0.00% gettyBSD爱好者乐园m:n%v4V[ iT$N
24227 root 3 0 356K 720K idle ttyin 0:00 0.00% gettyBSD爱好者乐园6e1n ?I bp
2902 root 28 0 516K 1416K onproc/0 - 0:00 0.00% top
9@"xxnvEqQ14010 root 3 0 348K 716K idle ttyin 0:00 0.00% getty
ie V4V4]a)Zt 1 root 10 0 404K 332K idle wait 0:00 0.00% initBSD爱好者乐园9Z/Q3W _S(l`
5123 root 2 0 1292K 1144K idle select 0:00 0.00% sshd2
:i3Q ?DR%n"qW8E5822 root 2 0 340K 668K idle netio 0:00 0.00% syslogd
~1?D9u4_+[ c/AiBSD爱好者乐园"u R*tV7sOM \9cV
#vmstat –w 1
/r/q'[^:vprocs memory page disks traps cpuBSD爱好者乐园 X^2jl p$Y9?M,q
r b w avm fre flt re pi po fr sr sd0 cd0 int sys cs us sy id
v}g5n!pg0 0 0 5520 3013824 7 0 0 0 0 0 0 0 839 49 16 0 0 100
Pwvj`T0 0 0 5520 3013824 7 0 0 0 0 0 0 0 840 23 17 0 0 100
f`"HO"d-^*`*Q0 0 0 5520 3013824 7 0 0 0 0 0 0 0 855 23 12 0 0 100
n*z4@ b8MM b9C0 0 0 5520 3013824 7 0 0 0 0 0 0 0 848 23 12 0 0 100
I!XB is0 0 0 5520 3013824 7 0 0 0 0 0 0 0 838 23 12 0 0 100BSD爱好者乐园p6B4qESi-c
0 0 0 5520 3013824 7 0 0 0 0 0 0 0 841 23 12 0 0 100BSD爱好者乐园8M*X9W$WB$N/{8c;\
0 0 0 5520 3013824 7 0 0 0 0 0 0 0 836 23 13 0 0 100BSD爱好者乐园(hiT][!Mr*h
0 0 0 5520 3013824 7 0 0 0 0 0 0 0 863 23 13 0 0 100BSD爱好者乐园 dI7C w#`0p(uV
0 0 0 5520 3013824 7 0 0 0 0 0 0 0 828 23 12 0 0 100BSD爱好者乐园!M _?G(a2k0[M
BSD爱好者乐园7[ [hzXVa
CPU-8个内核 基本闲置
Kk$ZDy4ny;q F,LY内存也基本闲置状态BSD爱好者乐园[K6_sd:mi lF)wE
测试成功!BSD爱好者乐园Hu;gUBRT0D
五,负载均衡(3层)BSD爱好者乐园'y,WqLoh%D*K
1,配置PF的NAT策略BSD爱好者乐园2~N5h)zE6h2g
#vi /etc/pf.confBSD爱好者乐园)Ruo;w,p
将以上pf修改NAT规则,开启relayd的NAT,关闭原有RDR的均衡BSD爱好者乐园]g5m*v0x&w&G;~)\&U
# ********** NAT Configure ******************* #
3np7L(w-h&T ?rdr-anchor "relayd/*"BSD爱好者乐园Xn}4A5l _ u?
#nat on $ext_if inet from any to $ext_tc50 -> 10.1.222.97
1^G+r4j!n$UlP*Rp\#rdr on em1 proto tcp from any to $ext_tc50 port 7777 -> $tc50_hosts port 7777BSD爱好者乐园I4D;r9Us8C1px
BSD爱好者乐园;KT [0m4V9X+n
2,配置relayd(3层)均衡功能BSD爱好者乐园 {5LDHxS
#vi /etc/relayd.confBSD爱好者乐园%H"oB+Zu o7?L
BSD爱好者乐园4Dcf9W$Zn
# ******************************************** #
k/`*X-i.u8q^O# Edit By Sunwaylove #
A] o4g@W# Support:010-8513XXXX #BSD爱好者乐园8]R+C | uB}2t |
# Mail:sunwaylove@163.com #
}?,Lv4\f^# ******************************************** #BSD爱好者乐园1}$b,T/vAl-LG)i
"^mP8D9g.Mm w%o8w#***** Macros *****
Lpx mZ-{#@ext_addr="192.168.251.2"BSD爱好者乐园S`%P"B9RRr;Cr
tc50_hosts1="10.1.222.98"BSD爱好者乐园o l ~8k I| X
tc50_hosts2="10.1.222.97"BSD爱好者乐园/d7O3EQB$Iw;yW:@_
tc50_hosts3="10.1.222.95"
(H)v)ASbW ?5m X%S4h
\S1]\L gJ2|{3p#***** Global Options *****
u-_/Cm1Sinterval 10
Ar?'yx$~%Jtimeout 1000BSD爱好者乐园!t'Gsw:agy1u
prefork 5BSD爱好者乐园-Y.{"Z6_5uL
7w0Q!H+Uu*r6E# Each table will be mapped to a pf table.BSD爱好者乐园 p/a(kP [
table { $tc50_hosts1, $tc50_hosts2, $tc50_hosts3 }BSD爱好者乐园-V5|f7Hu s
table { 127.0.0.1 }BSD爱好者乐园p z4@+m ~
`;^pe,Fi[2V# Services will be mapped to a rdr rule.
i b Q*?H%~#|Rs
8wo r7E3Wvredirect webjy {BSD爱好者乐园P%C-n s&ST3m-Sf3sB
# Run as a simple TCP relayBSD爱好者乐园}z#_'Y*o6Io
listen on $ext_addr port 7777BSD爱好者乐园K!a/{6p ZRbsB
tag relayd
0YJY-_+`(y8sBSD爱好者乐园n:w1P"b4x#Uh
forward to check tcp
$BJ4V:L2UXE b1b`%x# forward to port 7777 mode roundrobin check tcpBSD爱好者乐园!sD_1ghq!vqts
# forward to check icmp
G E4GX L1Q4uJY}
5q|T~ k |A@ |BSD爱好者乐园|Y4or@?`9wt
启动relayd
9d"]})j|~ Sk}!|?#relayd –f relayd.conf
$E)]^LCr
'G4k%C |z o8Y*{;}观察启动状态BSD爱好者乐园Zo5o-V9}p
#relayctl show summaryBSD爱好者乐园 ] {N&h)z}B i8D
bash-2.04# relayctl show summary
*RX3] Q6`Id Type Name Avlblty StatusBSD爱好者乐园Xc*P E%P;z-t
0 redirect webjy active
o.I-TTUS*h[5MBB2 table webjy:7777 active (3 hosts up)
:e7T*z3q|0i-Q6Z6 host 10.1.222.98 100.00% up
d F6@.h6L1K!L5 host 10.1.222.97 100.00% upBSD爱好者乐园5j?1Y*r m%n
4 host 10.1.222.95 100.00% upBSD爱好者乐园yT9L7A3R H0bO
&D(k C_;S(Yo b1`开启测试压力工具,连接并发数总共20000BSD爱好者乐园oeW!i)?v;Q
这时候BSD状态:
ch2E7RCD#top
|%ri;|8W%C)\\-` Os wload averages: 0.12, 0.18, 0.15 19:20:55
T7N al;h*]+s32 processes: 1 running, 30 idle, 1 on processorBSD爱好者乐园1r.Z f e-}A|I
CPU0 states: 0.0% user, 0.0% nice, 0.0% system, 0.6% interrupt, 99.4% idle
6c}:P4f?o_&p{CPU1 states: 0.0% user, 0.0% nice, 0.0% system, 0.0% interrupt, 100% idle
z cqP:tM{2S'WCPU2 states: 0.0% user, 0.0% nice, 0.0% system, 0.0% interrupt, 100% idle
nl2^ jj mG"ci^CPU3 states: 0.0% user, 0.0% nice, 0.0% system, 0.0% interrupt, 100% idle
cP*\ugJ#bk'VZCPU4 states: 0.0% user, 0.0% nice, 0.0% system, 0.0% interrupt, 100% idle
$]1l'C \L6E)raCPU5 states: 0.0% user, 0.0% nice, 0.0% system, 0.0% interrupt, 100% idleBSD爱好者乐园;j;DJ6O.q~o+URc
CPU6 states: 0.0% user, 0.0% nice, 0.0% system, 0.0% interrupt, 100% idleBSD爱好者乐园 TE3}3[uP
CPU7 states: 0.0% user, 0.0% nice, 0.0% system, 0.0% interrupt, 100% idleBSD爱好者乐园$uE6N/R X
Memory: Real: 12M/84M act/tot Free: 2933M Swap: 0K/1028M used/tot
l K ?3lypX?
#LJ qL!\"A.p'H,~ PID USERNAME PRI NICE SIZE RES STATE WAIT TIME CPU COMMANDBSD爱好者乐园5dq&F%}u#Y nx
32611 root 28 0 1460K 1792K run/0 - 0:00 0.00% sshd2
:iH2c)UV|:N:c29775 root 2 0 532K 428K idle netio 0:00 0.00% pflogd
I"h4I9Eu#C9P23989 sunwei 10 0 584K 1196K idle wait 0:00 0.00% bashBSD爱好者乐园j.O5Ci+`"VReA
16629 _syslogd 2 0 384K 748K sleep/0 poll 0:00 0.00% syslogdBSD爱好者乐园(K t"bDDqdP
19339 root 10 0 584K 1304K sleep/0 wait 0:00 0.00% bash
1BlB:_9UQI*g27134 root 2 0 564K 796K idle select 0:00 0.00% cron
ccF,C!o4n uq"^32686 _pflogd 4 0 596K 340K sleep/0 bpf 0:00 0.00% pflogd
:f1C$bI:C}27664 _relayd 2 0 712K 1208K idle kqread 0:00 0.00% relayd
hBD HK;k"b(]20595 _relayd 2 0 712K 1292K idle kqread 0:00 0.00% relayd
a$q9\Ee%{4d:_k31953 _relayd 2 0 708K 1256K sleep/0 kqread 0:00 0.00% relaydBSD爱好者乐园,_0a3\&Y:}j
9744 _relayd 2 0 604K 1204K idle kqread 0:00 0.00% relayd
G*p r+_A]#[12731 _relayd 2 0 604K 1320K idle kqread 0:00 0.00% relaydBSD爱好者乐园Y&QY5A;o
19210 _relayd 2 0 1084K 1608K sleep/0 kqread 0:00 0.00% relayd
"q2cG d"W%U!tvT16058 _relayd 2 0 608K 1224K idle kqread 0:00 0.00% relaydBSD爱好者乐园Z4u`Y7P2QM/V
9807 _relayd 2 0 708K 1196K idle kqread 0:00 0.00% relayd
!E{}4T Iw28725 _relayd 2 0 712K 1208K idle kqread 0:00 0.00% relayd
$IS6h$F'X5]~[;Y 840 _relayd 2 0 604K 1288K sleep/0 kqread 0:00 0.00% relayd
I ~-_ `*L ? E?18995 root 2 0 1032K 1536K sleep/0 kqread 0:00 0.00% relayd
YV,u6M9w(n!B22692 root 2 0 936K 1572K sleep/0 kqread 0:00 0.00% relaydBSD爱好者乐园1p"Tr(QB%~([!mm
12036 root 3 0 320K 724K idle ttyin 0:00 0.00% gettyBSD爱好者乐园/K;U2V:qO)M${8B
15104 root 28 0 620K 1400K onproc/0 - 0:00 0.00% top
o&]s_*?HBSD爱好者乐园t.y^.DG
#vmstat –w 1
A7}6d]0A'h!W9H Sprocs memory page disks traps cpu
7GIf:Tf2m,{t]6kr b w avm fre flt re pi po fr sr sd0 cd0 int sys cs us sy id
SEAJ3b4aQ;L5^-t0 0 0 7200 3011256 7 0 0 0 0 0 0 0 471 49 17 0 0 100
)qGG/_'g:Yg?!M!U/N0 0 0 7200 3011256 7 0 0 0 0 0 0 0 477 129 29 0 0 100
Y)F F&X.F [:k_0 0 0 7200 3011256 7 0 0 0 0 0 0 0 476 23 12 0 0 100BSD爱好者乐园MS-@F3D{9}
0 0 0 7200 3011256 7 0 0 0 0 0 0 0 468 23 12 0 0 100
.u:nO gD&E)q0 0 0 7200 3011256 7 0 0 0 0 0 0 0 479 23 12 0 0 100
5mgnUw VV0 0 0 7200 3011256 7 0 0 0 0 0 0 0 459 26 14 0 0 100BSD爱好者乐园Z0W:V(B*FVow(y
0 0 0 7200 3011256 7 0 0 0 0 0 0 0 475 26 15 0 0 100BSD爱好者乐园+nL8gh%N s V o5P?
0 0 0 7200 3011256 7 0 0 0 0 0 0 0 475 23 12 0 0 100
3NH:W*DZj KBSD爱好者乐园~$Go-Y-l~P
CPU-8个内核 基本闲置BSD爱好者乐园q*x @S"OJeX
内存也基本闲置状态
x2~#FtJ/Y测试成功!
NF8DLA_8@[*R
Ne&k#mPt1K0k6y!|六,Relayd负载均衡(7层)BSD爱好者乐园2OfxmeH
1,配置PF的NAT策略BSD爱好者乐园^4{+deY'_
#vi /etc/pf.conf
1@%t p^fUv将以上pf修改NAT规则,开启relayd的NAT,关闭原有RDR的均衡
C/cH7KA }9Q8m-mmL"c# ********** NAT Configure ******************* #
5_vf ^vSrdr-anchor "relayd/*"BSD爱好者乐园5] T8F(X0P [
#nat on $ext_if inet from any to $ext_tc50 -> 10.1.222.97
Z}!@0H4WHp#rdr on em1 proto tcp from any to $ext_tc50 port 7777 -> $tc50_hosts port 7777BSD爱好者乐园$ld I @m.}
BSD爱好者乐园/Tb:M8U]nHZU}
2,配置relayd(7层)均衡功能
oWp(H:r#vi /etc/relayd.conf
BA~5g5A'{\ X+cBSD爱好者乐园7tH(CPnjg7U
# ******************************************** #
t3t-}L,_# Edit By Sunwaylove #
`A/zK&~|;u q# Support:010-8513XXXX #BSD爱好者乐园 X]9G8pb'W4q
# Mail:sunwaylove@163.com #BSD爱好者乐园G+o#NH'O3o,{7Vq
# ******************************************** #
J5mjKq$VM-eBSD爱好者乐园'\/hN%gqqd
# MacrosBSD爱好者乐园L#d;z8[3d&|0G X
ext_addr="192.168.251.2"
7P+R,s z8|T;x@'Ytc50_hosts1="10.1.222.98"
kITiiv G.Vtc50_hosts2="10.1.222.97"BSD爱好者乐园0Y8V-msT
tc50_hosts3="10.1.222.95"BSD爱好者乐园-}g+Y {"D"eg"xG
:a W0sd!g9|[)T F# Global OptionsBSD爱好者乐园N'Tz;`M(q
interval 10BSD爱好者乐园+N#m8y[.A o6Q
timeout 1000BSD爱好者乐园"pe'k$Q*J'|5mw
prefork 5
\-l4EeWgB.w
|zN\7k*HH# Each table will be mapped to a pf table.
5WA5]}'|;Ot(dtable { $tc50_hosts1, $tc50_hosts2, $tc50_hosts3 }BSD爱好者乐园Ll8Sk:@ N!ae'X
uM6uWG5w# Services will be mapped to a rdr rule.
h2Ph)j~protocol tc50 {
n~$[8E|w$^.u(` # The TCP_NODELAY option is required for "smooth" terminal sessionsBSD爱好者乐园#Porz b{Z.P r
tcp nodelay
/I'A&ZfxsC-P}BSD爱好者乐园#Y@ _Hh4c T5`W
$ak H(STOrelay webjy {BSD爱好者乐园:Tu8R9aw S&C(])h4p4G
# Run as a simple TCP relayBSD爱好者乐园?.h"J n~8b)J6F
listen on $ext_addr port 7777
8D {'E4|4q!K^8KH protocol tc50BSD爱好者乐园7s]'A/[0x-il
\0dCe"h2E(HE # Forward to the shared carp(4) address of an internal gateway
1b(uP-Cc wR#M forward to port 7777 mode roundrobin check tcpBSD爱好者乐园5?V'L|S K nd
}BSD爱好者乐园,e,A!| N Z&o|#\s'D
BSD爱好者乐园([ [d^ p(OB+KNh*cu
启动relaydBSD爱好者乐园 PpQ%G*\]a8i4Uq
#relayd –f relayd.confBSD爱好者乐园2Yp;gXUbA
BSD爱好者乐园 @G[ W2e
观察启动状态
{~.H2HXSd$WKu#relayctl show summaryBSD爱好者乐园 |:RY#HUU[+e
bash-2.04# relayctl show summaryBSD爱好者乐园cj@ x }[.r \
Id Type Name Avlblty Status
*vG&i@1N0 realy webjy activeBSD爱好者乐园Aq2}5[n%f7|d
2 table webjy:7777 active (3 hosts up)BSD爱好者乐园 Xw"TecGR~^E
6 host 10.1.222.98 100.00% up
W#r!c;^K Hb$b5 host 10.1.222.97 100.00% up
*FDO;TB~,c7S o4 host 10.1.222.95 100.00% up
K;b-i x adkJBSD爱好者乐园h;S*n7C*_*R7W
开启测试压力工具,连接并发数总共20000BSD爱好者乐园/IBN ptZx&bJ)p
这时候BSD状态:
r8w+v F+`I/I R;Ok#topBSD爱好者乐园b\+`.Vc*\V \
load averages: 0.12, 0.18, 0.15 19:20:55
vQx;^|9B:aK32 processes: 1 running, 30 idle, 1 on processorBSD爱好者乐园S j)v`r+B1U ~/k
CPU0 states: 0.0% user, 0.0% nice, 0.0% system, 0.6% interrupt, 99.6% idle
AN }/[7z3i`CPU1 states: 0.0% user, 0.0% nice, 0.0% system, 0.0% interrupt, 100% idleBSD爱好者乐园R'Qw/cO+P
CPU2 states: 0.0% user, 0.0% nice, 0.0% system, 0.0% interrupt, 100% idleBSD爱好者乐园&V Lh2K:kp/B
CPU3 states: 0.0% user, 0.0% nice, 0.0% system, 0.0% interrupt, 100% idleBSD爱好者乐园0zAg(UD/gp t
CPU4 states: 0.0% user, 0.0% nice, 0.0% system, 0.0% interrupt, 100% idleBSD爱好者乐园l8|ymigl/l
CPU5 states: 0.0% user, 0.0% nice, 0.0% system, 0.0% interrupt, 100% idle
/x|$v:ZWCPU6 states: 0.0% user, 0.0% nice, 0.0% system, 0.0% interrupt, 100% idleBSD爱好者乐园7tb&K*z,zG5^xTX2MT
CPU7 states: 0.0% user, 0.0% nice, 0.0% system, 0.0% interrupt, 100% idle
N9H:HI#mY:wMemory: Real: 12M/84M act/tot Free: 2933M Swap: 0K/1028M used/totBSD爱好者乐园 Ldq?l6E+b)@
'QM1S}2d PID USERNAME PRI NICE SIZE RES STATE WAIT TIME CPU COMMAND
Y;?G/TBe.FmBP32611 root 28 0 1460K 1792K run/0 - 0:00 0.00% sshd2BSD爱好者乐园+^ a'~iE.F}3x
29775 root 2 0 532K 428K idle netio 0:00 0.00% pflogd
jQ&eRO8xt`0A{2]23989 sunwei 10 0 584K 1196K idle wait 0:00 0.00% bashBSD爱好者乐园$`2\`l1P*j-M4E
16629 _syslogd 2 0 384K 748K sleep/0 poll 0:00 0.00% syslogdBSD爱好者乐园TbVT&h1QsZBM7L
19339 root 10 0 584K 1304K sleep/0 wait 0:00 0.00% bash
;~2F.p/A'uW27134 root 2 0 564K 796K idle select 0:00 0.00% cron
e#Ly-u p,}D POo32686 _pflogd 4 0 596K 340K sleep/0 bpf 0:00 0.00% pflogd
WC^4j8|D27664 _relayd 2 0 712K 1208K idle kqread 0:00 0.00% relayd
'z1qe{3ru20595 _relayd 2 0 712K 1292K idle kqread 0:00 0.00% relaydBSD爱好者乐园 k/\{ c8XQ i"[0k
31953 _relayd 2 0 708K 1256K sleep/0 kqread 0:00 0.00% relaydBSD爱好者乐园!cn:u/e9d
9744 _relayd 2 0 604K 1204K idle kqread 0:00 0.00% relayd
3@#m"}C!z+[XkQ12731 _relayd 2 0 604K 1320K idle kqread 0:00 0.00% relaydBSD爱好者乐园Ehr A4qFK
19210 _relayd 2 0 1084K 1608K sleep/0 kqread 0:00 0.00% relayd
G7V)@ Mbn16058 _relayd 2 0 608K 1224K idle kqread 0:00 0.00% relayd
5]3Bku]"^ V4Gp9807 _relayd 2 0 708K 1196K idle kqread 0:00 0.00% relayd
1u+_vw_28725 _relayd 2 0 712K 1208K idle kqread 0:00 0.00% relayd
pb)]C5D!] 840 _relayd 2 0 604K 1288K sleep/0 kqread 0:00 0.00% relaydBSD爱好者乐园5DG G;RGC!]b
18995 root 2 0 1032K 1536K sleep/0 kqread 0:00 0.00% relayd
AwAbQ,H1g22692 root 2 0 936K 1572K sleep/0 kqread 0:00 0.00% relayd
D*cyE8hM12036 root 3 0 320K 724K idle ttyin 0:00 0.00% getty
.S \(\h5b3PZy15104 root 28 0 620K 1400K onproc/0 - 0:00 0.00% top
3Acwkc2oK~u"k/Ag
$^+~+w3C;N8? ^t-t#vmstat –w 1BSD爱好者乐园 h Sr#h;f~K
procs memory page disks traps cpu
uM(d4e%uN7Vr b w avm fre flt re pi po fr sr sd0 cd0 int sys cs us sy id
y.Cb*K,H{6`x;z0 0 0 7200 3011256 7 0 0 0 0 0 0 0 471 49 17 0 0 100
|e;t%U|,m0 0 0 7200 3011256 7 0 0 0 0 0 0 0 477 129 29 0 0 100BSD爱好者乐园 q/x*PT,Kn
0 0 0 7200 3011256 7 0 0 0 0 0 0 0 476 23 12 0 0 100BSD爱好者乐园&q ^bz%T"q:}.l/^
0 0 0 7200 3011256 7 0 0 0 0 0 0 0 468 23 12 0 0 100
ZG8DPe9?*o4T}0 0 0 7200 3011256 7 0 0 0 0 0 0 0 479 23 12 0 0 100BSD爱好者乐园b(a*KTB1rG6D'l
0 0 0 7200 3011256 7 0 0 0 0 0 0 0 459 26 14 0 0 100
Ij.nT#Ck0 0 0 7200 3011256 7 0 0 0 0 0 0 0 475 26 15 0 0 100BSD爱好者乐园w+?*R ?^8l*L;z8@ q
0 0 0 7200 3011256 7 0 0 0 0 0 0 0 475 23 12 0 0 100BSD爱好者乐园e ~.Jc*zx @ yL
0 0 0 7200 3011256 7 0 0 0 0 0 0 0 471 23 12 0 0 100BSD爱好者乐园&XaaL+pg
BSD爱好者乐园8hZs%h7IH.GaE:E]
CPU-8个内核 基本闲置BSD爱好者乐园!c$L0shS(vD&q
内存也基本闲置状态
f{6n:K+]L测试成功!BSD爱好者乐园9w6l\+Lk+\
七,总结与Q&A
&jG y3Dq)E4C~kG0}目前测试OpenBSD-4.3防火墙功能基本成功。
b#s W&v1g,O c.hA,gBSD爱好者乐园 y[!v:g/H4_w$E
1,为什么要用做此次负载均衡试验?BSD爱好者乐园D ^rG1|
原因是 目前大多数主机托管业务IDC,均采用前端部署:一台硬件级防火墙 Juniper NS1000 (配置光纤模块后 单台 20万人民币)+硬件负载均衡 F5 (配上光纤模块 单台30万)。而且是不做HA的情况下,如果2台设备作HA,那就是总共2套4台设备,100万成本预算。BSD爱好者乐园.dqy.R s+|Xe)ZPN9Y
对于拥有多个IDC机房的金融企事业单位来说,每个站点光部署网络防火墙和负载均衡就需要投入50W~100W成本预算。而现在X86服务器+OpenBSD,成本才3~4万。
o%s^8K} m'x3Y0]
Ur"U~,ehPs此次测试的目的,是对现有硬件防火墙+负载均衡设备(standby,非HA的情况下)进行灾备准备。本人不赞成对正式环境,高并发量的情况下采用此方案,毕竟还不是很稳定、成熟,没有正式使用的先例,不确定因素太多。BSD爱好者乐园|[6[z2x yG
BSD爱好者乐园Q6i#l+uY/~
2,为什么采用OpenBSD做此次方案的?BSD爱好者乐园-rg(eD CIf
原因是OpenBSD相对linux、Unixware、Unix来说,其内核代码是最稳定、整洁的,而且是开源的。OpenBSD安全漏洞也是最少的操作系统,近10年来查到的漏洞数总共才2个。对于内核级防火墙来说,安全性、和稳定性是排在首位的。并且最新的OpenBSD4.3推出新的负载均衡功能relayd,正好适用于此次测试。因此在开始测试前就选定OpenBSD为主选防火墙操作系统。BSD爱好者乐园e4a#f7p]V)u
BSD爱好者乐园n#A"`rtXu!{
3,OpenBSD中的负载均衡功能 NAT 、relayd(3层模式redirect)、relayd(7层模式relays)有什么区别?BSD爱好者乐园7ucng UPk9w!Y
以下分别作说明:BSD爱好者乐园 X+z.["ox(T
a,pf的NAT-RDR负载均衡是基于PF下的NAT模式,基于network-3层结构上(4层也涉及),pf基于OpenBSD 内核级,因此效率理论上相对其他方式来说应该是最高的,但是这种模式的均衡系统无法检测后台系统的状况,也无法调整负载均衡的参数,优化负载均衡的功能。因此该模式,对于负载均衡要求不高的情况下可以满足,但对于后台负载设备很多,高网络流量的情况下,其负载均衡功能无法满足需求。
^M7[&a On/kBSD爱好者乐园6X#JR sf2}
b,Relayd 分为2种模式:3层和7层,效率来说 redirect模式基于3层,效率要比7层的relays高,比较适合简单的TCP应用负载均衡,提高效率。Relays模式基于7层,对HTTP/HTTPS/SSL等协议,有着多种方案的检验机制,功能更强更安全,适合HTTP 的网络负载均衡需求,相应的其开销要比3层模式多,效率较低。BSD爱好者乐园1se m_1z2T;urE"]$j
BSD爱好者乐园Qrb f&l o6k
4,最后总结
3WYQ+xq ?hh N此次测试,由于OpenBSD所安装的设备过于强大,测试机的数量不多,连接数压力并发最多也就2万,以上测试下来,BSD服务器开销均不大。因此,本方案说明,仅供参考,待日后正式考证。BSD爱好者乐园 meheM1KA6@
结论:如果是考虑实现防火墙+负载均衡功能,本人推荐首选OpenBSD4.3的 pf + relayd(3层模式redirect)方式。BSD爱好者乐园#|:CW-NGsOV/h8Z7vz
(谢谢)
阅读(1579) | 评论(0) | 转发(0) |