(一、系统安装)
R_vF$X'O w fn~Jc~[G| F['<;} 5x2m]u 前言
,\DSi&T ^$D2fS r(VGdG sTb@nrRxH 写本文的初衷主要是记录下我一段时间学习使用FreeBSD建设网站平台的一些经验和体会。因为本人是菜鸟,所以很多地方不够完善。本文权当给初学者提供一个具体可操作的实例。所有操作步骤都是我边做边写。避免出现遗漏或一些不必要的小错误,给初学者带来麻烦。
:L6,=# Iq[
d5)M4 本网站平台建设全过程包括FreeBSD系统的安装,web、ftp、mail、proxy服务器、视频点播服务器等。所有过程都在FreeBSD4.7环境下测试通过。
,S%DHT !eC]=PoY 由于写本文时参考了网上太多前辈和大侠的资料,无法一一列举。还请作者原谅。
%3@a|#g ru 5T0w";V 本连载文章前后关联很紧密,建议初学者一步一步来做。
L'@@ewA Lj,!025 试验环境如下:
sN8)p%'Lg j1sgvh]D 硬件环境:普通pc机,双网卡。配制不需要高,主要是稳定,并能适应长时间开机。听前辈介绍AMD k6的cpu运行FreeBSD好像有点问题。不过我没有试验。建议用intel的。
"Yy)&zKr :&'[#%h8 软件环境:操作系统:FreeBSD4.7(4.8)
~stG2^"[ Cu`uP[# ch web服务器:Apache 1.3.27+modssl +mod_php4+mod_gzip+mod_fastcgi +mod_perl +mysql3.23
kWKAtv5@w 1M<;}hJ{/ ftp服务器:Proftpd1.2.7+proftpd-mod-quotatab-1.2.4+mysql
)/Mk\``j )_H>d<di mail服务器: iceblood前辈制作的qmail安装包(经过修改)+vqregister-2.5
xV+cX*4h jg3X6 /' proxy服务器:使用FreeBSD内置的NAT和PPP拨号+squid
d>YX18'<Q px~ :'U 视频点播服务器:Helix Universal Servevr (realserver9.01)
.}4^b\ lI&5.,2MP 网络环境:我用的是adsl动态拨号方式,因为动态ip所存在的一些问题,我把所有的服务都装在一台机器上,且这台机器要直接与外网相连。静态ip更方便一些。(本文两种方式都会讨论)
ro8c-[V ;&~9k?v7L ,mY3oyu rF:l+I] 第一步:安装系统
<AN=@`+ C
U 8s* 关于安装过程网上有很多文章,这里不作详述。仅提出几点建议供大家参考:
: 6|nXL
j
+u3VP 1、 采用最小化安装。
O,Sqh$6U }%lk$g'; 2、 安装时启用inetd,并在编辑inetd.conf文件时,把带有“ftp”的行前面的“#”号去掉。这样作是为了以后安装软件时可以用ftp上传文件。
&~MM\,KML -SeHz.`N 3、 添加一个wheel组的用户,这样在系统工作正常后可以在windows系统上通过终端登录软件(如SecureCRT)进行所有操作。FreeBSD4.7在最小安装时支持SSH终端登录,所以我们需要使用支持SSH协议的终端软件,如SecureCRT。例如我添加的用户名是ylf,隶属wheel系统组。系统产生一个用户目录/home/ylf。我可以通过SecureCRT以ylf身份登录到系统,然后通过su命令切换到root用户。同时我也可以在IE浏览器内键入
ftp://192.168.0.1 ,并输入ylf用户名和密码登录ftp将需要的文件上传到自己的用户目录里。(192.168.0.1是我的服务器连接内网的网卡ip地址)。以下除系统安装部分,我都是采用终端方式操作。
j}F;Bfq! '0tNo.8K 4、 分区时将/home、/usr和/var划的大一些,因为/usr为程序目录,/var要存放日志,/home是用户主目录,我的用户文件如网页、ftp上传文件等都放在这里。还有最好保留一部分空间留作以后需要的时候用。我的机器上有2块硬盘,一快18.2G SCSI硬盘,一块40G IDE硬盘。我是这样划分的。
)N}.n2Y8W enB2-)<K 128M /
E8Y(C_:s |jw{7\+ 20G /home
p8bAz |3K]>Lio 2G /ftp
J*zm*~8\ |k[hk 256M /tmp
hha!uD~( dZ;rn!dg> 6G /usr
s^lm
81; ^a # 5G /var
C%T$l8$ \*i[m&3;q 其中/ftp是为匿名ftp用户访问专用。剩余空间留作备用。当然如果硬盘空间少的话,做我们的试验也是够用的。
ZhnRsn9 FrL
;1zt 关于安装方面的文章,大家也可以参考delphij写的《FreeBSD服务器的安装与优化》。
http://community.freebsdchina.org/catalog.php?forum=34 一文。
#_9Jam%M Nxr %xTD 安装完系统后,要重新编译内核。目的是要系统支持Firrwall和提高运行效率。
{Hr
P;) 5y8ajae: 首先确认系统是否安装了FreeBSD的内核支持。如果是最小安装,则需要运行/stand/sysinstall命令安装内核支持。方法如下:
e00s*LdC gg+!e#-X # /stand/sysinstall
DMpNmF> FXO{i:Zo 选Configure—Distributions—src—sys,内核文件将被安装在/usr/src/sys目录中。
kgGMA 7Jy t}m"rMbt 注意:这之后的过程在终端上操作要方便许多。SecureCRT支持在终端界面上直接拷贝和粘贴文本内容。
@S#Ls="G wVac6q
转到内核文件目录
QKt+Orz =Dc9|WuHN # cd /usr/src/sys/i386/conf
C[2LP$6*/ 1yT\|2ARZ% 编辑内核文件
I>n2# -8 hutdw> # vi kernel_wwwx # kernel_wwwx为我的内核文件名
hY}.2 a&)4Dv0 我的内核文件如下:
_a&Mk <v+M ~"%V #
OtD!@GQ6 Q|&Wcxq2! # GENERIC -- Generic kernel configuration file for FreeBSD/i386
cjyb:gAO $?Z-BD1 #
,Jqk0cW2 ("T8 mt[w> # For more information on this file, please read the handbook section on
?I}0[+)V NWt5)xl # Kernel Configuration Files:
Ou,Eu05jt' & 8'QD~ #
aX,ux9# k`;&?? #
http://www.FreeBSD.org/doc/en_US.IS...fig-config.html O od?ifA l~j{i/> #
OdHl)"# MB3 0.V/\ # The handbook is also available locally in /usr/share/doc/handbook
,?(IRiq% Wt $q{g{C # if you've installed the doc distribution, otherwise always see the
%o4HCzId< \L4+Dv<z # FreeBSD World Wide Web server (
http://www.FreeBSD.org/) for the
/aX#j`PrH $]I",ef # latest information.
e(~Y!:Q#O \h UE,^ #
; w+<yW}EL ^eHf'^Cvvu # An exhaustive list of options and more detailed explanations of the
<F#/wU^9 f3M~2jbv'p # device lines is also present in the ./LINT configuration file. If you are
kf>L 6S6E
1~ # in doubt as to the purpose or necessity of a line, check first in LINT.
0\a;}
S'g# &Rxy]kBA #
lgei<\6~n5 g4CdzN~ # $FreeBSD: src/sys/i386/conf/GENERIC,v 1.246.2.48 2002/08/31 20:28:26 obrien Exp $
= }6l.9
avwhGys# ;y%C\YB# HS[N]'dc machine i386
t]PO4GA UCDvN cpu I586_CPU
u[yUUYe ?KF.v1w7 cpu I686_CPU
]id5jVY zyF[I6Gs ident kernel_wwwx #内核文件名,这个要和你的内核文件名一致
*oP&'$P &9,<_1~ maxusers 0
2}HS`) / b{i7FRR>o4 nd?R|._R -Yf pfNt options INET #InterNETworking
jm$v0=W9# 5p5S_%R$e options FFS #Berkeley Fast Filesystem
?Rg8u B}A7Usm options FFS_ROOT #FFS usable as root device [keep this!]
Bvy(vc=UDW q" %;),@ options SOFTUPDATES #Enable FFS soft updates support
"i3Q)$"S FdVWj
5 $a options UFS_DIRHASH #Improve performance on big directories
+5C*i@v )Og,VXEB options PROCFS #Process filesystem
KtY_m`DY4R ecl$z6'c options COMPAT_43 #Compatible with BSD 4.3 [KEEP THIS!]
IsjD-t \/
8
V|E options SCSI_DELAY=15000 #Delay (in ms) before probing SCSI
Gkq<?q({t d}e/f)( options SYSVSHM #SYSV-style shared memory
J;S@Q/s is,r: options SYSVMSG #SYSV-style message queues
]/C1pG*o yg-uL48q options SYSVSEM #SYSV-style semaphores
Tr@} SpG^kI # options P1003_1B #Posix P1003_1B real-time extensions
)s';m$ 9azk(OL6 options _KPOSIX_PRIORITY_SCHEDULING
#7~i.8L |[]"{Eo"} options ICMP_BANDLIM #Rate limit bad replies
2n`OcXCh/ #Kp/AN5YC options AHC_REG_PRETTY_PRINT # Print register bitfields in debug
oztfr<cUH std4Nyp # output. Adds ~128k to driver.
sG~5O\,E h0)Wy>B=, options AHD_REG_PRETTY_PRINT # Print register bitfields in debug
qp@:Zqz8 wt@q+9: # output. Adds ~215k to driver.
{}TR'Y4 R0v5mD$:G z9#iU>@ 1*!`G5c,} device tun 1
{Noa4i ua-cX3E options IPFIREWALL #防火墙
(8*& 42W Y"U -Rc options IPFIREWALL_FORWARD #允许透明代理
i C
nWb k_c8\::p# options IPFIREWALL_VERBOSE #允许防火墙日志
2Hp#~cE+. 8yDu(.Q options IPFIREWALL_VERBOSE_LIMIT=100 #限制日志
kN)m"}gX ~+GMn[h options IPFIREWALL_DEFAULT_TO_ACCEPT #默认允许所有IP包
LOkNDmj 6k=ink-/ options IPDIVERT #启用由ipfw divert使用的转向IP套接字
T"2D<7frbo ;&Oma`Ec 9rn[46s` >|[74#}7 # To make an SMP kernel, the next two are needed
MOIH%lpe `<C/-Au #options SMP # Symmetric MultiProcessor Kernel
B0^0d*8t|@ B0KZdBRx} #options APIC_IO # Symmetric (APIC) I/O
mt+IB4` 0O,l
rF0 ' 4ZK8Y[]Lv 54 Baz device isa
xM/B"SG2 i7fQj,
q device eisa
poqx
O Jz!8Xg%a device pci
n~#%>C7 hK+Iow- P>dMET 8W]6/st?] pOCLyM9c ueiXY| # ATA and ATAPI devices
Q`Q%;%t tBp146` device ata
GB(o)I#h A(mU,^ device atadisk # ATA disk drives
"(hhb>V1Wl R^.oM1qu| =-`}(b2N *:q3<\y{ pN)9GO5 @eRR#S # SCSI Controllers #没有SCSI设备不需要这段
l!plw,PYC &sp7YkaW device ahb # EISA AHA1742 family
_91g=pM 1Z +3=$P device ahc # AHA2940 and onboard AIC7xxx devices
()Z! u%j
`5:Wv b>| device ahd # AHA39320/29320 and onboard AIC79xx devices
/3!KfG $T\z device amd # AMD 53C974 (Tekram DC-390(T))
c]>s(/}T :t6w+h
device isp # Qlogic family
5'/Ney9N SsDe\"?Q device mpt # LSI-Logic MPT/Fusion
ThX%Uzd"[; ?v>!wuiP device ncr # NCR/Symbios Logic
x.CNDG /HsJyp+t device sym # NCR/Symbios Logic (newer chipsets)
*7Ct#GC +s:!\(BM options SYM_SETUP_LP_PROBE_MAP=0x40
-v4kW0G a
W`q # Allow ncr to attach legacy NCR devices when
_-&\~w ~Cx07I_lf # both sym and ncr are configured
[lpzUB}<Yp .$/Su3]K/ 1nb]~{l l@a>"\><i* device adv0 at isa?
:=BFx"Y Wc4F'}s device adw
Sni Ck*T, ')w:`8Tl device bt0 at isa?
!>g_9'n' oZxC.;xJ device aha0 at isa?
Ll%CeP 5Xu2MY= device aic0 at isa?
EX%KfWDr _ cK"y2 IcMfZ{H1 {)j3Pn device ncv # NCR 53C500
`H6-g=C 5-M EOy( device nsp # Workbit Ninja SCSI-3
b-8{bP]n _ji"##K device stg # TMC 18C30/18C50
n*6Oa/JG7 cv(9v =](
C9[Jr)QX hPa:>e # SCSI peripherals #没有SCSI设备不需要这段
^uIP tCAh?nR device scbus # SCSI bus (required)
k{<]J5{7 <(dHh9$~ device da # Direct Access (disks)
&v7$*n27 cXiNO
ke& device sa # Sequential Access (tape etc)
_5(lp} s &FF%VUfQJ device cd # CD
+jePp_3$O v1Tla]d device pass # Passthrough device (direct SCSI access)
>4>!zZ ld8 E!t[ S>isWte iB;EV8E ES[H^}|Gi K,{P
b? 'M>QA"*48E LeDty_ # atkbdc0 controls both the keyboard and the PS/2 mouse
ezn%*X
y, MaDdiyeC device atkbdc0 at isa? port IO_KBD
1*\JqCR XdX1GH*C device atkbd0 at atkbdc? irq 1 flags 0x1
fvn`$ DD`Bl1) &~of]A O4w6\y3U device vga0 at isa?
?ACflU_k +eSNwR= %UDz4?zx o2 x%Ph``XI
C7#ji"t # syscons is the default console driver, resembling an SCO console
)[&'\SOO ocCq$%Ka device sc0 at isa? flags 0x100
#@s[!4)_I lXH?* @X@?jj& Y;$wD9W {"T$jV:GB tHAr9 # Floating point support - do not disable.
P;_}nbB t*Hr(|. device npx0 at nexus? port IO_NPX irq 13
Z<L|WRe hTZ& f]Jn\7j4 W^{zlg ~9%L)nC2' _m .u@+g # Serial (COM) ports
DX>Yf} 4D+S\S0bk device sio0 at isa? port IO_COM1 flags 0x10 irq 4
d:C|laZHn 1t&LNIc|^ a6\0XVU N 4Kj)E@ # 我用的是8139和Dlink DFE-530TX网卡,大家可根据自己的网卡型号保留或删除
2d),*Cvf nn[OC=cDN # 使用公共的MII总线控制器代码的PCI以太网适配器
?=zF]J:G1w A[W3.$s # 注意:一定要保留'device miibus'以确保可用
h9<*+T 6Ih8~Hu # PCI Ethernet NICs that use the common MII bus controller code.
g{|F<2rd[m \4$V;C/n, # NOTE: Be sure to keep the 'device miibus' line in order to use these NICs!
\ZN> 7?Vs ncw)VH;_- device miibus # MII bus support
SI_u0j4%* |^l17veA@ device fxp # Intel EtherExpress PRO/100B (82557, 82558)
n
hT%_se4 mhh^kwW device rl # RealTek 8129/8139
P/%5J3_, yN-o?[o device vr # VIA Rhine, Rhine II
X5[.X()M4 v\&C]W] device xl # 3Com 3c90x (``Boomerang'', ``Cyclone'')
"[A]tklP ^j~CYzmt =CBY_ MZJ@qIg[Y # Pseudo devices - the number indicates how many units to allocate.
v_U+wga i2bkgyzB. pseudo-device loop # Network loopback
Xy(8} `Hlv*" w$ pseudo-device ether # Ethernet support
Z`jc*jgy $2!|e,x pseudo-device sl 1 # Kernel SLIP
}4$k-,1S ENoGV;WG pseudo-device ppp 1 # Kernel PPP
eKpWFP0 8d|/^U.w~V pseudo-device tun # Packet tunnel.
DIAHIV< fHFy5j0H pseudo-device pty # Pseudo-ttys (telnet etc)
|| p>O ''p7!V? pseudo-device md # Memory "disks"
prypo.RI 4Nylc.2mi pseudo-device gif # IPv6 and IPv4 tunneling
q>X30g lftT55Tki pseudo-device faith 1 # IPv6-to-IPv4 relaying (translation)
KOv?p@d U5[,UrC 62s0$vw ~)fd+~4L # The `bpf' pseudo-device enables the Berkeley Packet Filter.
n]nb+_-97 Z'Uc}M'U # Be aware of the administrative consequences of enabling this!
Fu%D2%V$/ i!yu%>:M pseudo-device bpf #Berkeley packet filter
VbU*&{j Nbyc,a[o (完)
xZ=6 0,{tBo [B_(,/? &$H7vdWNy 我用的是8139网卡和Dlink DFE-530TX网卡,如果你用其他型号的网卡,需要察看当前目录的GENERIC 内核文件,找到描述自己的网卡型号的段并将其添加到新的内核文件里。其他的不改直接拷贝过来就可以用了。
TyGsSc NzBX2 接下来编译安装新内核:
0&21'K)pW z5tOsU # /usr/sbin/config kernel_wwwx #kernel_wwwx为你的内核文件名
(Ts#^qC zn+5pn&? # cd ../../compile/kernel_wwwx
rl__3q ;o#wK>pk%M # make depend
.&Ik(792Z& .\rJ|HpZ1J # make
?xTdL738 ,qUOPW?= # make install
|g`:K0BI AQ<2 "s 重新启动(reboot)
'uBagd>* W{!Slf gH
u!~l Au"7w=G`f 如果系统升级过源代码树,按下面方法编译内核:
C@F3iwTtp
26[. te9 # cd /usr/src
7eU|iDYo ^630%YO # make kernel KERNCONF=kernel_wwwx #kernel_wwwx为你的内核文件名
(?ofL|Cg( e$Npo<u 重新启动
vyhxS .[9 9{-
Sa 6\5"36&/rQ $`'%1;y@ FreeBSD网站平台建设全过程(二、接入Internet并配制代理服务)
=5kTzH. Om,M8!E <