网络安全 频道

FreeBSD网站平台建设全过程(上)

前言 
写本文的初衷主要是记录下我一段时间学习使用FreeBSD建设网站平台的一些经验和体会。因为本人是菜鸟,所以很多地方不够完善。本文权当给初学者提供一个具体可操作的实例。所有操作步骤都是我边做边写。避免出现遗漏或一些不必要的小错误,给初学者带来麻烦。 
本网站平台建设全过程包括FreeBSD系统的安装,web、ftp、mail、proxy服务器、视频点播服务器等。所有过程都在FreeBSD4.7环境下测试通过。 
由于写本文时参考了网上太多前辈和大侠的资料,无法一一列举。还请作者原谅。 
本连载文章前后关联很紧密,建议初学者一步一步来做。 
试验环境如下: 
硬件环境:普通pc机,双网卡。配制不需要高,主要是稳定,并能适应长时间开机。听前辈介绍AMD k6的cpu运行FreeBSD好像有点问题。不过我没有试验。建议用intel的。 
软件环境:操作系统:FreeBSD4.7(4.8) 
web服务器:Apache 1.3.27+modssl +mod_php4+mod_gzip+mod_fastcgi +mod_perl +mysql3.23 
ftp服务器:Proftpd1.2.7+proftpd-mod-quotatab-1.2.4+mysql 
mail服务器: iceblood前辈制作的qmail安装包(经过修改)+vqregister-2.5 
proxy服务器:使用FreeBSD内置的NAT和PPP拨号+squid 
视频点播服务器:Helix Universal Servevr (realserver9.01) 
网络环境:我用的是adsl动态拨号方式,因为动态ip所存在的一些问题,我把所有的服务都装在一台机器上,且这台机器要直接与外网相连。静态ip更方便一些。(本文两种方式都会讨论) 

第一步:安装系统 
关于安装过程网上有很多文章,这里不作详述。仅提出几点建议供大家参考: 
1、 采用最小化安装。 
2、 安装时启用inetd,并在编辑inetd.conf文件时,把带有“ftp”的行前面的“#”号去掉。这样作是为了以后安装软件时可以用ftp上传文件。 
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地址)。以下除系统安装部分,我都是采用终端方式操作。 
4、 分区时将/home、/usr和/var划的大一些,因为/usr为程序目录,/var要存放日志,/home是用户主目录,我的用户文件如网页、ftp上传文件等都放在这里。还有最好保留一部分空间留作以后需要的时候用。我的机器上有2块硬盘,一快18.2G SCSI硬盘,一块40G IDE硬盘。我是这样划分的。 
128M / 
20G /home 
2G /ftp 
256M /tmp 
6G /usr 
5G /var 
其中/ftp是为匿名ftp用户访问专用。剩余空间留作备用。当然如果硬盘空间少的话,做我们的试验也是够用的。 
关于安装方面的文章,大家也可以参考delphij写的《FreeBSD服务器的安装与优化》。http://community.freebsdchina.org/catalog.php?forum=34 一文。 
安装完系统后,要重新编译内核。目的是要系统支持Firrwall和提高运行效率。 
首先确认系统是否安装了FreeBSD的内核支持。如果是最小安装,则需要运行/stand/sysinstall命令安装内核支持。方法如下: 
# /stand/sysinstall 
选Configure—Distributions—src—sys,内核文件将被安装在/usr/src/sys目录中。 
注意:这之后的过程在终端上操作要方便许多。SecureCRT支持在终端界面上直接拷贝和粘贴文本内容。 
转到内核文件目录 
# cd /usr/src/sys/i386/conf 
编辑内核文件 
# vi kernel_wwwx # kernel_wwwx为我的内核文件名 
我的内核文件如下: 

# GENERIC -- Generic kernel configuration file for FreeBSD/i386 

# For more information on this file, please read the handbook section on 
# Kernel Configuration Files: 

#http://www.FreeBSD.org/doc/en_US.IS...fig-config.html 

# The handbook is also available locally in /usr/share/doc/handbook 
# if you"ve installed the doc distribution, otherwise always see the 
# FreeBSD World Wide Web server (http://www.FreeBSD.org/) for the 
# latest information. 

# An exhaustive list of options and more detailed explanations of the 
# device lines is also present in the ./LINT configuration file. If you are 
# in doubt as to the purpose or necessity of a line, check first in LINT. 

# $FreeBSD: src/sys/i386/conf/GENERIC,v 1.246.2.48 2002/08/31 20:28:26 obrien Exp $ 

machine i386 
cpu I586_CPU 
cpu I686_CPU 
ident kernel_wwwx #内核文件名,这个要和你的内核文件名一致 
maxusers 0 

options INET #InterNETworking 
options FFS #Berkeley Fast Filesystem 
options FFS_ROOT #FFS usable as root device [keep this!] 
options SOFTUPDATES #Enable FFS soft updates support 
options UFS_DIRHASH #Improve performance on big directories 
options PROCFS #Process filesystem 
options COMPAT_43 #Compatible with BSD 4.3 [KEEP THIS!] 
options SCSI_DELAY=15000 #Delay (in ms) before probing SCSI 
options SYSVSHM #SYSV-style shared memory 
options SYSVMSG #SYSV-style message queues 
options SYSVSEM #SYSV-style semaphores 
options P1003_1B #Posix P1003_1B real-time extensions 
options _KPOSIX_PRIORITY_SCHEDULING 
options ICMP_BANDLIM #Rate limit bad replies 
options AHC_REG_PRETTY_PRINT # Print register bitfields in debug 
# output. Adds ~128k to driver. 
options AHD_REG_PRETTY_PRINT # Print register bitfields in debug 
# output. Adds ~215k to driver. 

device tun 1 
options IPFIREWALL #防火墙 
options IPFIREWALL_FORWARD #允许透明代理 
options IPFIREWALL_VERBOSE #允许防火墙日志 
options IPFIREWALL_VERBOSE_LIMIT=100 #限制日志 
options IPFIREWALL_DEFAULT_TO_ACCEPT #默认允许所有IP包 
options IPDIVERT #启用由ipfw divert使用的转向IP套接字 

# To make an SMP kernel, the next two are needed 
#options SMP # Symmetric MultiProcessor Kernel 
#options APIC_IO # Symmetric (APIC) I/O 

device isa 
device eisa 
device pci 


# ATA and ATAPI devices 
device ata 
device atadisk # ATA disk drives 


# SCSI Controllers #没有SCSI设备不需要这段 
device ahb # EISA AHA1742 family 
device ahc # AHA2940 and onboard AIC7xxx devices 
device ahd # AHA39320/29320 and onboard AIC79xx devices 
device amd # AMD 53C974 (Tekram DC-390(T)) 
device isp # Qlogic family 
device mpt # LSI-Logic MPT/Fusion 
device ncr # NCR/Symbios Logic 
device sym # NCR/Symbios Logic (newer chipsets) 
options SYM_SETUP_LP_PROBE_MAP=0x40 
# Allow ncr to attach legacy NCR devices when 
# both sym and ncr are configured 

device adv0 at isa? 
device adw 
device bt0 at isa? 
device aha0 at isa? 
device aic0 at isa? 

device ncv # NCR 53C500 
device nsp # Workbit Ninja SCSI-3 
device stg # TMC 18C30/18C50 

# SCSI peripherals #没有SCSI设备不需要这段 
device scbus # SCSI bus (required) 
device da # Direct Access (disks) 
device sa # Sequential Access (tape etc) 
device cd # CD 
device pass # Passthrough device (direct SCSI access) 

# atkbdc0 controls both the keyboard and the PS/2 mouse 
device atkbdc0 at isa? port IO_KBD 
device atkbd0 at atkbdc? irq 1 flags 0x1 

device vga0 at isa? 


# syscons is the default console driver, resembling an SCO console 
device sc0 at isa? flags 0x100 


# Floating point support - do not disable. 
device npx0 at nexus? port IO_NPX irq 13 


# Serial (COM) ports 
device sio0 at isa? port IO_COM1 flags 0x10 irq 4 

# 我用的是8139和Dlink DFE-530TX网卡,大家可根据自己的网卡型号保留或删除 
# 使用公共的MII总线控制器代码的PCI以太网适配器 
# 注意:一定要保留"device miibus"以确保可用 
# PCI Ethernet NICs that use the common MII bus controller code. 
# NOTE: Be sure to keep the "device miibus" line in order to use these NICs! 
device miibus # MII bus support 
device fxp # Intel EtherExpress PRO/100B (82557, 82558) 
device rl # RealTek 8129/8139 
device vr # VIA Rhine, Rhine II 
device xl # 3Com 3c90x (``Boomerang"", ``Cyclone"") 

# Pseudo devices - the number indicates how many units to allocate. 
pseudo-device loop # Network loopback 
pseudo-device ether # Ethernet support 
pseudo-device sl 1 # Kernel SLIP 
pseudo-device ppp 1 # Kernel PPP 
pseudo-device tun # Packet tunnel. 
pseudo-device pty # Pseudo-ttys (telnet etc) 
pseudo-device md # Memory "disks" 
pseudo-device gif # IPv6 and IPv4 tunneling 
pseudo-device faith 1 # IPv6-to-IPv4 relaying (translation) 

# The `bpf" pseudo-device enables the Berkeley Packet Filter. 
# Be aware of the administrative consequences of enabling this! 
pseudo-device bpf #Berkeley packet filter 
(完) 

我用的是8139网卡和Dlink DFE-530TX网卡,如果你用其他型号的网卡,需要察看当前目录的GENERIC 内核文件,找到描述自己的网卡型号的段并将其添加到新的内核文件里。其他的不改直接拷贝过来就可以用了。 
接下来编译安装新内核: 
# /usr/sbin/config kernel_wwwx #kernel_wwwx为你的内核文件名 
# cd ../../compile/kernel_wwwx 
# make depend 
# make 
# make install 
重新启动(reboot) 

如果系统升级过源代码树,按下面方法编译内核: 
# cd /usr/src 
# make kernel KERNCONF=kernel_wwwx #kernel_wwwx为你的内核文件名 
重新启动

第二步:接入Internet并配制代理服务 
使用adsl接入Internet有两种情况,通过拨号获取动态ip或服务商直接给定静态ip。后者配制起来较容易。本文先讨论动态ip如何设置。 
由于第一步重新编译内核时已经加进了对Firewall的支持。这里就可以通过直接编辑/etc/ppp/ppp.conf文件和/etc/rc.conf文件就可以上网并支持NAT方式透明代理了。 
# vi /etc/ppp/ppp.conf 
我的ppp.conf文件内容如下:(注意set前要留空格) 
default: 
set log Phase tun command 
set ifaddr 10.0.0.1/0 10.0.0.2/0 
adsl: # 配置代号 
set device PPPoE:vr0 # vr0 改成你连接ADSL modem的网卡名 
set mru 1492 
set mtu 1492 
set authname username # username是拨号用户名 
set authkey password # password是拨号密码 
set dial 
set login 
add default HISADDR 
(完) 

# vi /etc/rc.conf 
我的rc.conf文件内容如下:(动态ip) 
# -- sysinstall generated deltas -- # Tue Jul 15 21:20:28 1997 
# Created: Tue Jul 15 21:20:28 1997 
# Enable network daemons for user convenience. 
# Please make all changes to this file, not to /etc/defaults/rc.conf. 
# This file now contains just the overrides from /etc/defaults/rc.conf. 
hostname="wwwx.3322.org" # 你的主机域名 
ifconfig_fxp0="inet 192.168.0.1 netmask 255.255.255.0" #内网网卡ip地址,fxp0是网卡名 
inetd_enable="YES" # 开机加载inetd 
kern_securelevel_enable="NO" 
linux_enable="YES" 
nfs_reserved_port_only="NO" 
sendmail_enable="NO" 
sshd_enable="YES" 
usbd_enable="NO" 
gateway_enable="YES" 
firewall_enable="YES" #启用防火墙 
firewall_script="/etc/rc.firewall" 
firewall_type="open" 
firewall_quiet="YES" 
firewall_logging_enable="YES" 
ppp_enable="YES" # 开机自动拨号 
ppp_mode="ddial" 
ppp_nat="YES" # 启用透明代理 
ppp_profile="adsl" # 配置代号 
# -- sysinstall generated deltas -- # Wed Jul 16 06:52:13 1997 
(完) 

0
相关文章