Duangw

FreeBSD 8.0

 

主要内容:基本配置应用程序

 

1 基本配置

1.1 初始安装

这里安装的是i386版本。

用bootonly cd进行网络安装,采用standard标准模式。

安装软件包类型:Developer。

不安装ports,后面单独安装新的版本。

不安装引导管理器。

配置网络。启用ssh,其余网络服务都不开启。

建立普通用户,并加入wheel组。

参考:FreeBSD使用手册-安装FreeBSD

 

1.2 引导配置

这里FreeBSD不负责引导,而是通过别的系统上的引导管理器来进行引导。

对于grub,编辑grub所在系统的menu.lst,增加FreeBSD的启动项:

title FreeBSD/i386 8.0
	rootnoverify (hd1,1)
	chainloader +1

对于lilo,编辑lilo所在系统的/etc/lilo.conf,增加:

other=/dev/hdc2
	table=/dev/hdc
	loader=/boot/chain.b
	label=FreeBSD

完毕运行lilo,以slackware 13.0为例:

# lilo -P ignore

 

1.3 安装系统补丁

系统安装时,可能已经有补丁发布,要及时更新这些补丁。

安装系统补丁有两种方式:二进制方式和源代码补丁方式。

使用freebsd-update进行二进制方式的修补:

# freebsd-update fetch
# freebsd-update install

如果使用了定制的内核,则需通过源代码方式进行更新。从官方网站下载补丁patch,根据说明进行操作。

参考:FreeBSD使用手册-FreeBSD 安全公告

 

1.4 安装ports

安装ports的方法有很多,这里使用portsnap来安装。

可以编辑/etc/portsnap.conf,以选择一个快的镜像。这里使用缺省设置,不做更改。

初次安装:

# portsnap fetch
# portsnap extract

ports会不断更新,在后面的使用过程中,需要不定期的进行更新。

更新方法:

# portsnap fetch
# portsnap update

参考:FreeBSD使用手册-使用Ports Collection

 

1.5 关于packages和ports

安装第三方软件包有packages(预编译包)和ports(源代码)两种方式。

两种方式各有优缺点,如果需要快速大批量的安装软件包,则packages方式优势明显,但安装的软件包可能比较旧,有漏洞的话需要马上修补。如果喜欢追新,则需要ports安装,代价是巨大的时间和空间开销。

如果通过网络安装packages,则设置PACKAGEROOT环境变量,详情见pkg_add帮助页(man pkg_add)。如:

setenv  PACKAGEROOT     ftp://ftp.cn.freebsd.org

此时使用pkg_add要加参数-r。

如果通过ports编译安装,需要下载大量的源代码包,可以设置一些镜像服务器来提高下载速度,方法是设置MASTER_SITE_OVERRIDE等环境变量,详情见ports帮助页(man ports)。以FreeBSD中国镜像为例,编辑/etc/make.conf,增加:

MASTER_SITE_OVERRIDE?=ftp://ftp.cn.freebsd.org/pub/FreeBSD/ports/distfiles/${DIST_SUBDIR}/

这里设置两个符号连接,以方便共享源代码包和生成的二进制包:

# cd /usr/ports
# ln -s /pub/ftp/pub/FreeBSD/ports/distfiles/ distfiles
# ln -s /pub/ftp/pub/FreeBSD/ports/i386/packages-8.0-release/ packages

也可通过在/etc/make.conf中设置DISTDIR和PACKAGES变量来达到同样的目的。

参考:FreeBSD使用手册-软件安装预览

参考:FreeBSD使用手册-使用Packages系统

 

1.6 安装ports管理工具

编译安装,同时生成二进制包:

# cd /usr/ports/ports-mgmt/portmanager
# make install
# make package-recursive
# cd /usr/ports/ports-mgmt/portaudit
# make install
# make package-recursive

这些工具用来处理第三方软件包的升级和修补。

首次运行portaudit,需要下载当前的审计库:

# portaudit -Fda

平时需要不定期的运行portaudit,以发现可能存在的漏洞:

# portaudit -a

检查当前安装的软件包的版本情况:

$ pkg_version -v

对审计需要修补的软件包,要马上升级。以portmanager升级ruby18为例:

# portmanager lang/ruby18 -ui -l

升级所有软件包:

# portmanager -u -l

升级同时生成二进制安装包:

# portmanager -u -l -bu

强制编译所有依赖包(无论是否有新版本):

# portmanager x11/gnome2 -l -f

参考:FreeBSD使用手册-使用Ports Collection

 

 

2 应用程序

2.1 安装apache

这里安装集成mod_ssl的版本:

# cd /usr/ports/www/apache13-modssl
# make config-recursive
# make fetch-recursive
# make install
# make package-recursive

使用缺省配置。

编辑/etc/rc.conf,添加:

apache_enable="YES"
apache_flags=""

参考:FreeBSD使用手册-Apache HTTP 服务器

 

2.2 配置ftp服务器

这里配置一个匿名的ftp server。

通过sysinstall工具(configure --> networking --> anon ftp)来完成。

一些调整:

# cd /pub/ftp
# rm -rf etc incoming

编辑/etc/rc.conf(可参考/etc/defaults/rc.conf),增加:

ftpd_enable="YES"
ftpd_flags="-DllUSA"

参考:FreeBSD使用手册-文件传输协议 (FTP)

 

2.3 安装一些网络工具

以下安装都使用缺省配置。

2.3.1 安装lftp

# cd /usr/ports/ftp/lftp
# make config-recursive
# make fetch-recursive
# make install
# make package-recursive

2.3.2 安装lynx

# cd /usr/ports/www/lynx
# make config-recursive
# make fetch-recursive
# make install
# make package-recursive

2.3.3 安装arping

# cd /usr/ports/net/arping
# make config-recursive
# make fetch-recursive
# make install
# make package-recursive

2.3.4 安装nmap

# cd /usr/ports/security/nmap
# make config-recursive
# make fetch-recursive
# make install
# make package-recursive

2.3.5 安装tcptraceroute

# cd /usr/ports/net/tcptraceroute
# make config-recursive
# make fetch-recursive
# make install
# make package-recursive

2.3.6 安装fping

# cd /usr/ports/net/fping
# make config-recursive
# make fetch-recursive
# make install
# make package-recursive

2.3.7 安装ngrep

# cd /usr/ports/net/ngrep
# make config-recursive
# make fetch-recursive
# make install
# make package-recursive

2.3.8 安装httping

# cd /usr/ports/net/httping
# make config-recursive
# make fetch-recursive
# make install
# make package-recursive

2.3.9 安装iftop

# cd /usr/ports/net-mgmt/iftop
# make config-recursive
# make fetch-recursive
# make install
# make package-recursive

 

2.4 配置tftp服务器

这里配置tftp和下面的dhcp服务,是为了给其他机器提供网卡PXE启动服务。

通过sysinstall工具(configure --> networking --> inetd)来打开tftp,实质就是编辑/etc/inetd.conf,取消tftp的注释:

tftp dgram udp wait root /usr/libexec/tftpd tftpd -l -s /pub/tftpboot

并在/etc/rc.conf中增加:

inetd_enable="YES"

参考:FreeBSD使用手册-inetd “超级服务器”

 

2.5 安装dhcpd

# cd /usr/ports/net/isc-dhcp31-server
# make config-recursive
# make fetch-recursive
# make install
# make package-recursive

使用缺省配置。

编辑/etc/rc.conf,添加:

dhcpd_enable="YES"
dhcpd_ifaces="rl0"

按需要编写/usr/local/etc/dhcpd.conf。

参考:FreeBSD使用手册-网络自动配置 (DHCP)

 

2.6 安装rsync

# cd /usr/ports/net/rsync
# make config-recursive
# make fetch-recursive
# make install
# make package-recursive

使用缺省配置。

按需要编写/usr/local/etc/rsyncd.conf。

编辑/etc/rc.conf,添加:

rsyncd_enable="YES"

参考:FreeBSD使用手册-rsync 站点

 

2.7 安装squid

# cd /usr/ports/www/squid30
# make config-recursive
# make fetch-recursive
# make install
# make package-recursive

使用缺省配置。

按需要编写/usr/local/etc/squid/squid.conf。

编辑/etc/rc.conf,添加:

squid_enable="YES"