标签: FreeBSD

  • freebsd声卡安装

    1、kldload snd_driver #这是个meta 驱动,一次加载了最常见的设备驱动。这会提高搜索正确驱动的速度。

    2、cat /dev/sndstat 查看当前声卡类型。

    3、在/boot/defaults/loader.conf 中修改相关load snd driver为”YES”,将相关类型的声卡选项为”YES”

    vim /boot/defaults/loader.conf,找到这一 Sound modules 小节,

    如果不清楚的话就在最后把All sound drivers选项中的“NO”改为“YES”。(注意:如果在声卡驱动的这个小节,没有发现你的声卡类型,也可以手工自己加入一行,内容为你的声卡类型_load = “YES” )

    重启就OK了..

  • 让FreeBSD更安全(Securing FreeBSD)

    前几天我整理了过去的一些笔记,以及近几年收集的一些安全建议。我认为这可能对您有帮助,所以本周我就暂停文档系列的文章,写一点关于使你的FreeBSD系统更安全的内容。

    很明显,在这个领域我不可能用一篇文章全面地介绍所有的事情。另外,也不可能给出一个防止四海皆准的,保证任何系统都安全的方案。

    在我整理笔记的过程中,我注意到很多都是关于如何让FreeBSD服务器(如,Web服务器,邮件服务器,等等)更安全的方法。如果你用FreeBSD做为个人系统,并希望完全的桌面功能的话,这就不太够用了。你肯定不愿意因为某些强化安全的设置,造成某些功能无法使用,并在此后的一周内孤立无援地与计算机进行搏斗,直到找到问题的所在。

    因此,你将注意到,和许多其它安全教程不同,这份文档并不建议你修改FreeBSD系统中文件的权限。这是有意的。除非你正在强化一台生产服务器的安全性,并且十分明白自己在做什么,否则绝不要修改文件的权限。(如果你一定要做做实验的话,请在自己的home文件夹中作)。不然的话,一些东西可能就会停止工作,例如,电子邮件,X Window系统,声音。怪事会在不经意的时刻发生,让你头疼良久之后才意识到可能是一周前的某个权限设置造成的问题。

    我们都知道Internet并不总是一个友好的地方,而且你可能也不想让另一个地方的人拥有与你一样的访问许可权限。这意味着你可能不希望在没有某种防火墙的前提下访问Internet。幸运的是,你的FreeBSD系统支持良种防火墙:ipfw 和 ipfilter。更令人振奋的是,通俗易懂的文档正在迅速增加。如果你不在防火墙后面,那么请花一个周六下午的时间读一读如何在你的系统上配置防火墙的文章,并操练一把。你将为此感到愉快,以下是一部分可用的资源:

    man ipfw

    FreeBSD Handbook: Section 10.7 — Firewalls

    Setting Up a Dual-Homed Host using IPFW and NATD

    man ipf

    IPFilter and PF resources

    好的安全总是“层层设防”,这意味着如果一个机制失效了,仍然有备用的机制。即使你的系统已经受到了防火墙的保护,你仍然需要禁用所有服务,除了那些绝对需要的。在桌面系统中,不需要很多的服务。

    用下面的命令可以查看哪些服务正在试图监听连接你的系统:

    sockstat -4

    输出的差别可能很大,这取决于在安装的最后阶段选择的软件,以及之后自行安装的port和package。

    端口6000(X Window服务器)是输出中非常常见的;如果没看到它的话,启动一个X Window会话,然后重新运行 sockstat -4。不幸的是,在过去的几年中有很多针对X Window的攻击。幸运的是,使用X并不需要打开6000端口,不必担心,即使关闭了这个端口,仍然可以使用图形界面!

    许多方法可以关掉这个端口。我发现的最简单的方法是成为超级用户,并编辑 /usr/X11R6/bin/startx。找到 serverargs 那一行,并把它改为类似下面的样子:

    serverargs=”-nolisten tcp”

    保存修改之后,以普通用户身份运行X并执行 sockstat -4。如果没有打字错误,那么X会像往常那样启动,但 sockstat -4 输出中不会再出现端口6000。

    如果想了解6000端口打开的后果,请阅读 Crash Course in X Window Security。

    好了,现在 sockstat -4 输出中的服务少了一个。我们还需要处理一下邮件:端口 25 (smtp) 和 587 (submission)。收发邮件并不需要 587 端口,为了关闭它,我们需要修改 /etc/mail/sendmail.cf。查找这一行:

    O DaemonPortOptions=Port=587, Name=MSA, M=E

    然后在前面加上 #,并告诉 sendmail 变化:

    killall -HUP sendmail

    -HUP 不会杀掉 sendmail,但他会告诉sendmail重新处理 /etc/mail/sendmail.cf。重复sockstat -4,它将不再显示 587。

    那么端口25呢?你可能需要,也可能不需要打开这个端口,这取决于使用什么样的邮件程序来收发邮件。对于运行 FreeBSD 4.6-RELEASE 或更高版本的系统,在/etc/rc.conf中增加下面的行:

    sendmail_enable=”NO”

    将告诉 sendmail 只监听 localhost,这允许所有的邮件客户程序发送邮件。如果你知道你的邮件客户程序带有内置的SMTP代理,或者喜欢冒险,那么可以尝试一下:

    sendmail_enable=”NONE”

    这将彻底关闭25端口。检查一下这是否让你无法发送邮件是很重要的,确保已经关掉了所有应用程序,随后,以超级用户身份执行:

    shutdown now

    收到提示后按回车、exit。重新登录后给自己发一封邮件,如果收不到,那么把NONE改回NO。

    如果你的”sockstat”显示端口111打开,那么把下面几行加到 /etc/rc.conf (或者,如果已经有这些行,把 YES 改为 NO):

    nfs_server_enable=”NO”

    nfs_client_enable=”NO”

    portmap_enable=”NO”

    Portmap只有在运行NFS时才是必需的,而这往往不是FreeBSD桌面系统的需要。历史上它有过很多安全问题,因此除非你绝对需要它,否则就别用。

    syslog (端口 514) 也可能出现在你的输出结果中。我们可能并不希望完全关掉 syslog,因为它提供的消息记录是我们需要的。但我们并不需要为此打开端口。在 /etc/rc.conf 文件中增加下面的选项:

    syslogd_enable=”YES”

    syslogd_flags=”-ss”

    标志中的ss (确认用了两个s,而不是一个) 将禁止来自远程主机的记录并关闭端口,但仍然允许 localhost 进行日志记录。

    随后,确认 /etc/rc.conf 中inetd_enable不是YES。如果sockstat输出中有inetd,那么/etc/inetd.conf中肯定有什么项目没有被注释掉,如果不需要的话,那么把那一行前面加上#,并 killall inetd。

    如果需要使用DHCP自动获取地址,那么请保持dhclient (udp 68)打开,否则将不能刷新地址。

    如果在 sockstat 输出中发现了其他东西,那么请看看 man rc.conf 里面有没有关于如何关掉这些东西的提示。如果没有的话,那么很可能是某个启动脚本启动了一些服务程序,请执行:

    cd /usr/local/etc/rc.d

    来看看你的系统中的启动脚本。绝大多数 packages/ports 会安装一个扩展名为sample的示范脚本用于启动服务,这些脚本并不被执行;也有一些直接安装能够执行的脚本,它们会在计算机启动的时候加载。禁止某个脚本知性最简单的方法是把它的扩展名改为sample,随后杀掉守护程序,这样sockstat就不会再说什么了。 举例来说,我最近安装了 ethereal 结果发现 snmpd 出现在 sockstat -4 的输出中,这个程序在安全方面名声不佳,因此我把自己升级为root并执行了下面的命令:

    cd /usr/local/etc/rc.d

    mv snmpd.sh snmpd.sh.sample killall snmpd

    你可能会希望把下面的选项加入 /etc/rc.conf:

    tcp_drop_synfin=”YES”

    这个选项可以挫败诸如OS指纹识别的企图(译注:这个选项对最新的nmap无效)。如果你打算开启这个选项,那么,还需要在内核编译配置文件中加入:

    options TCP_DROP_SYNFIN

    还有两个相关的选项:

    icmp_drop_redirect=”YES”

    icmp_log_redirect=”YES”

    ICMP 重定向可以被利用完成DoS攻击。这篇 ARP and ICMP redirection games article 介绍了具体的一些情况。

    在打开 icmp_log_redirect 选项时请务必小心,因为它会记录每一个ICMP重定向,如果你遭到了这样的攻击,那么日志很可能会塞满记录。

    建好防火墙之后,请考虑加入下面的选项:

    log_in_vain=”YES”

    这个选项会记录每一个到关闭端口的连接企图。另一个比较有意思的选项是:

    accounting_enable=”YES”

    这将打开系统审计功能,如果你不熟悉他们,那么请阅读 man sa 和 man lastcomm。

    最后,下面的选项可能非常有用:

    clear_tmp_enable=”YES”

    因为它在系统启动时将清空 /tmp,这永远是一件值得去做的事情。

    让我们来研究一下其他能够加强安全的设置。我比较喜欢把默认的口令加密算法改为Blowfish,因为它在提供最佳安全性的前提下,也提供了最快的速度。这里有一份 comparison of algorithms[几种密码学算法的比较]。

    当然,如果你对这类东西感兴趣的话,看看 Cryptogram newsletter,它是Blowfish作者写的。

    为了启用 Blowfish 散列,编辑 /etc/login.conf 并把 passwd_format 一行改成下面这样:

    :passwd_format=blf:\

    保存设置,重新创建登录数据库:

    cap_mkdb /etc/login.conf

    随后需要修改每一个用户的口令,以便让这些口令都使用 Blowfish 散列值。以超级用户的身份执行下面的命令:

    passwd username

    需要修改所有用户的口令,包括root自己。

    完成了这些操作之后,重新检查一下确认自己没有遗漏什么:

    more /etc/master.passwd

    所有用户的口令应该以$2.开始

    最后,重新配置 adduser 程序,让它在以后使用Blowfish。修改 /etc/auth.conf,找到 crypt_default 一行,改为:

    crypt_default=blf

    你可能已经注意到,每次登录的时候FreeBSD都会提示你,你在用的那个系统是FreeBSD,以及它的版权信息,包括内核的编译时间,等等。这些信息可能有用,但相当烦人,特别是当别人可以登录的时候,它可能会暴露一些你不希望暴露的信息。

    可以通过编辑 /etc/motd 来阻止计算机说出一些不该说的东西,或者宣扬你的一些想法,包括你喜欢看的 sci-fi 文摘,或者其他一些——总之你想写什么就写什么。

    随后,删除版权信息:

    touch /etc/COPYRIGHT

    随后,还可以修改登录提示,编辑 /etc/gettytab. 找到 default:\ 小节,它以下面的文字开头:

    :cb:ce:ck:lc

    小心地修改 \r\n\ \r\n\r\nr\n: 之间的文字来适应自己的需要。请仔细检查 \r 和 \n 的数量,并保存修改。例如,我的登录提示是这样的:

    I’m a node in cyberspace. Who are you?

    login:

    可以在其他终端上尝试登录,以确认正确性。

    最后,即使你已经修改了motd并从中删除了内核版本信息,默认情况下FreeBSD仍然会在启动之后把这些东西加入 /etc/motd。因此需要修改 /etc/rc.conf 并加入下面的设置:

    update_motd=”NO”

    这个设置需要重新启动才会生效。

    此外,限制登录也是非常重要的。因为这些变动会改变 login 程序的行为,因此需要非常谨慎。比较好的习惯是保持一个以root身份登录的终端,用其他终端尝试。这样如果由于某种原因造成问题,你仍然可以改正。

    包括你自己在内的任何人都不应该直接以root身份登录。修改 /etc/ttys。你将注意到 ttyv0 到 ttyv8的一系列设置。把后面的 secure 改为 insecure。注意,这个文件肯定是你不希望有任何错误的一个文件,因此请仔细地进行测试。如果设置正确,root登录将收到 “Login incorrect”。

    我个人倾向于使用所有的9个终端。如果你不打算这样,请把对应的 “on” 改为 “off”,当然,只是一部分 ttys。切记保持至少1个 “on,” 否则你会无法登录,这将导致系统无法使用。ttyv8 默认情况下是 “off”,这意味着你需要手动打开X,如果希望自动启动,那么把它改为”on.”。

    最后一个我想说的限制是阻止从其他地方登录,这是通过编辑 /etc/login.access 实现的。

    你可能希望禁止一切远程登录(这意味着你必须物理地坐在机器前面),删除下面这一行前面的#号:

    #-:wheel:ALL EXCEPT LOCAL .win.tue.nl

    把 .win.tue.nl 去掉,于是它看起来将像这样:

    -:wheel:ALL EXCEPT LOCAL

    如果你需要从远程登录,那么把.win.tue.nl 替换为相应的IP或域名。如果有多个地址,用空格分开。

    如果只有一两个用户的话,那么可以拒绝其他人登录:

    -:ALL EXCEPT user1 user2:ttyv0 ttyv1 ttyv2 ttyv3 ttyv4

    用具体的用户名替换掉 user1 user2。如果需要的话,增加相应的tty。

    另外,也可以把用户组方在这里。首先,编辑 /etc/group 并增加下面的行:

    mygroup:*:100:genisis,dlavigne6,biko

    当增加组时,需要保证GID的唯一性。

    随后,修改 /etc/login.access:

    -:ALL EXCEPT mygroup:ttyv0 ttyv1 ttyv2 ttyv3 ttyv4 ttyv5

    测试它非常重要,一定要留一个终端。测试每一个终端上的登录,确认其效果。

  • Apache/MySQL/PHP/phpMyAdmin on FreeBSD

    1. Introduction:

    This article describes how to setup Apache, MySQL, PHP and phpMyAdmin on a server running FreeBSD. The article was written for the software versions below but is likely to work on newer versions without too much difficulty.

     2. Software:

    Operating System:        FreeBSD 7.0 for i386      Download

    Apache:                           2.2.8                                Installed from Ports Collection

    MySQL Server:            5.0.51a                             Installed from Ports Collection

    PHP & Extensions:        5.2.5                                Installed from Ports Collection

    phpMyAdmin:              2.11.5                               Installed from Ports Collection

    3. Before you begin:

    This article assumes you have a working install of FreeBSD 6.2 for i386 logged in as root (or another user in the wheel group and you have used “su”) with the ports collection installed. You can use sysinstall, cvsup or portsnap to install the ports distribution if you have not already done so. See point 2 below.

    Update your ports collection (portsnap fetch, portsnap extract.) (See the FreeBSD Handbook Section 4.5.1)

    4. Installing MySQL:

    (1)  Go to the mysql50-server port directory by typing the command:

                     cd /usr/ports/databases/mysql50-server

     (2) Build the port by typing: (This takes AGES – good time for some food.)

    make BUILD_OPTIMIZED=yes BUILD_STATIC=yes

    (3) Install by typing:

                 make install clean

    (4)Open /etc/rc.conf with your favourite text editor and add the line shown below. This will ensure mysql is enabled and starts on boot.

                    mysql_enable=”YES”

     (5)Start mysql manually to avoid having to reboot now by typing:

             /usr/local/etc/rc.d/mysql-server start

     (6)Set a password for the MySQL root user by executing the command, subtituting your own password in place of new-password:

        /usr/local/bin/mysqladmin -uroot password ‘new-password’

      And you’re done! MySQL is installed.

    5.Installing Apache

    (1)Go to the apache22 port directory by typing the command:

    cd /usr/ports/www/apache22

    (2)Build and install the port by typing: (This takes a while, coffee time!)

    make install clean

    Note: You may want to disable the two DAV options if you don’t need them when prompted

    (3)Open /etc/rc.conf with your favourite text editor and add the line shown below. This will ensure apache is enabled and starts on boot.

    apache22_enable=”YES”

    6.Installing PHP

    (1)Go to the php5 port directory by typing the command:

    cd /usr/ports/lang/php5

    (2)Build and install the port by typing: (Just accept the default options, this takes a while, more coffee.)

    make install clean

    Make sure the APACHE (Build Apache module) option is ticked when configuring the build, leaving all other options as default, before selecting OK.

    (3)Go to the php5-extentions meta port directory by typing the command:

    cd /usr/ports/lang/php5-extentions

    (4)Build and install the port by typing: (Just accept the defaults here, phpMyAdmin will install any other extensions required itself)

    make install clean

    (5)Install the php.ini file:

    cp /usr/local/etc/php.ini-dist /usr/local/etc/php.ini

    版本不同,只面的文件可能有所改变

    php.ini-production对应于php.ini-recommended

    php.ini-development对应于php.ini-dist

    php.ini-development 开发用的,php.ini-produciton 生产机用的,如果做站的话,我觉得应该将php.ini-produciton改为php.ini,用php.ini-produciton可能会出现无法支持PHP,修改php.ini中的短标签开关short_open_tag=Off在作怪,改成On就行了

    (6)Edit your Apache configuration file (/usr/local/etc/apache22/httpd.conf) and add the following lines to the end of the file:

    AddType application/x-httpd-php .php

    AddType application/x-httpd-php-source .phps

     Note: You can add additional extenions other than .php (eg .phtml) seperated by spaces.

    Note: The second line is optional, it will show colour highlighted PHP source for .phps files.

    (7)You should also search for the line that reads:

    DirectoryIndex index.html

    and change it to read:

    DirectoryIndex index.php index.html

    Note: You may also add index.phtml or any other default page if you added additional extentions in the previous step.

    (8)Enable language settings by searching for the line:

    #Include etc/apache22/extra/httpd-languages.conf

    and removing the # comment mark so it reads:

    Include etc/apache22/extra/httpd-languages.conf

    (9)Edit the language settings file (/usr/local/etc/apache22/extra/httpd-languages.conf) and add the following line at the end of the file:

    AddDefaultCharset On

    (10)Start Apache using the startup script:

    /usr/local/etc/rc.d/apache22 start

    And you’re done! Apache with PHP is installed.

    安装Zend Optimizer

    cd /usr/ports/devel/ZendOptimizer/

    make install clean

    ===> ZendOptimizer-3.3.0.a cannot install: doesn’t work with PHP version : 5 (Doesn’t support PHP 5).

    *** Error code 1

    Stop in /usr/ports/devel/ZendOptimizer.

    注:如果你用的是FreeBsd8.0版本的可能会出现上面的情况,这里可以使用使用pkg_add命令来安装Zend Optimizer.

    #pkg_add -r ZendOptimizer

    #rehash

    执行结果将类似如下:

    Fetching ftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages-8.0-release/Latest/ZendOptimizer.tbz… Done.

    pkg_add: warning: package ‘ZendOptimizer-3.3.0.a’ requires ‘libxml2-2.7.5’, but ‘libxml2-2.7.7’ is installed

    pkg_add: warning: package ‘ZendOptimizer-3.3.0.a’ requires ‘php5-5.2.11’, but ‘php5-5.3.2’ is installed

     

    ********************************************************************************

     

    You have installed the ZendOptimizer package.

     

    Edit /usr/local/etc/php.ini and add:

     

    [Zend]

    zend_optimizer.optimization_level=15

    zend_extension_manager.optimizer=”/usr/local/lib/php/20060613/Optimizer”

    zend_extension_manager.optimizer_ts=”/usr/local/lib/php/20060613/Optimizer_TS”

    zend_extension=”/usr/local/lib/php/20060613/ZendExtensionManager.so”

    zend_extension_ts=”/usr/local/lib/php/20060613/ZendExtensionManager_TS.so”

     

    NOTE: PHP should be compiled in non-debug mode (default).

     

    ********************************************************************************

    虽然居然成功了,但也可能用phpinfo时候还是不行的![可惜最后还是不行,得到的教训是,不要用太新的版本,这样资料和环境的支持会很不完善。]

     

    7.Installing phpMyAdmin

    (1)Got to the phpmyadmin port directory by typing the command:

    cd /usr/ports/databases/phpmyadmin

    (2)Build and install the port by typing: (Just accept the default options)

    make install clean

    (3)phpMyAdmin is now installed in /usr/local/www/phpMyAdmin. To use it we need to create Alias and Directory entries in /usr/local/etc/apache22/httpd.conf. To do this, add the following lines to the <IfModule alias_module> section (just search for where all the other Alias commands are.)

    Alias /phpmyadmin /usr/local/www/phpMyAdmin

    (4)As /usr/local/www/phpMyadmin is outside of the Apache <DocumentRoot> you will have to make a <Directory> entry for it too. Add the following lines to the end of the <Directory> section: (just search for </Directory>)

    <Directory “/usr/local/www/phpMyAdmin”>

    Order allow,deny

    Allow from all

    </Directory>

     Note:You may prefer to put the Alias entry inside a <VirtualHost> entry if you are hosting multiple sites using name based virtual hosting and do not wish to enable phpMyAdmin on all the sites.

    (5)Create a config directory for phpMyAdmin and make it globally read/write/executable by typing the commands:

    cd /usr/local/www/phpMyAdmin

    mkdir config

    chmod 777 config

    (6)Restart Apache so that the Alias and Directory entries take effect by typing:

    /usr/local/etc/rc.d/apache22 restart

    (7)Configure phpMyAdmin by going to http://hostname/phpmyadmin/scripts/setup.php in your browser and set at least the following:

    • Add Server
      • Change the “Authentication type” dropdown to http to have phpMyAdmin prompt you for a username and password.
      • Delete root from the “User for config” auth textbox so it is blank.
      • You can leave all other settings as they are (even if they are blank.)
      • Click the “Add” button to add the new server

    Save the configuration using the Save button in the Configuration section.

    (8)For the changes to take effect you must copy the generated config file from the phpMyAdmin/config directory to the phpMyAdmin directory by typing the following command: (Note the space dot at the end of the command)

    cp config/config.inc.php .

    (9)You can now delete the config directory you created earlier and reset the permissions on the config.inc.php file to read only typing the commands:

    rm -rf config

    chmod 444 config.inc.php

    (10)That’s it! You can place your web site in /usr/local/www/data/ and access phpMyAdmin at http://hostname/phpmyadmin/ in your web browser and logging in using username root and the MySQL password you set earlier.

    以上安装完,可能有所出入,特别是Apache22可能无法启动,以下两点是一些总结:

    1:注意:apache22有个bug,不能启动FreeBSD自带的一个基于http端口过滤的模块。这个模块的作用很不错——检查HTTP请求是否完整,符合规则accpt一个Http进程,否则就扔掉。你会遇到如下提示

    [Sat Jan 23 22:47:29 2010] [warn] (2)No such file or directory: Failed to enable the ‘httpready’ Accept Filter    解决方法是:

    #kldload accf_http  或者将/boot/defaults/loader.conf==> accf_httpd_load=”YES”

    2.apache22无法启动时,进入/var/logo查看httpd_error.log, 如果出现以下提示:

    [alert] (EAI 8)hostname nor servname provided, or not known: mod_unique_id: unable to find IPv4 address of “shao  Configuration Failed

    解决方法:进入/usr/local/etc/apache22    ee ./httpd.conf

    将LoadModule unique_id_module libexec/apache2/mod_unique_id.so注释掉

    然后启动/usr/local/etc/rc.d/apache22  start即可.

    一个IP多个域名添加方法

    在httpd.conf中去掉httpd-vhosts.conf那一栏注释,然后进入/usr/local/etc/apache22/extra/修改httpd-vhosts.conf网站域名对应的目录,还要加

    <Directory “/usr/home/www/jpeps.com”>

    Options FollowSymLinks

    AllowOverride None

    Order allow,deny

    Allow from all

    </Directory>

    <IfModule dir_module>

    DirectoryIndex index.html index.htm index.php

    </IfModule>

    添加php.ini 被禁用的函数(disable_functions)

    passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_restore,dl,pfsockopen,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,fsocket,fsockopen

  • FreeBSD安装后配置

    安装及更新ports树

    ports如何使用,我们以后再讲,先不要着急使用portsnap。先完成以下步骤,你会发现,ports会更快,安装软件也会更快。

    #cd /etc

    #vi portsnap.conf

    找到portsnap.FreeBSD.org

    将其改为portsnap3.hshh.org

    保存退出

    我是网通用户,所以用3号镜像。镜像列表如下

    portsnap.hshh.org(电信)

    portsnap2.hshh.org(电信)

    portsnap3.hshh.org(网通)

    portsnap4.hshh.org(电信)

    这是国内的portsnap镜像,更新速度会更快。我见过无数linux装好后就再也不更新,导致漏洞一大堆,并不完全是系统管理员的问题,这跟yum或者apt的包维护也有关系。FreeBSD完全不用担心这一点,只要你自动设定portsnap,自动upgrade,即便你放在那里一年,你的软件也会是最新的。不过一般不建议这样做。后面会讲到。

    然后,执行下述命令:portsnap fetch extract

    更新你的ports树吧,国内的镜像速度飞快。大约会下载63-64M的port包。然后等待解压缩完成即可。现在,你的ports树就是最新的了,尽管去编译安装软件吧。需要更新,可以运行下述命令

    portsnap fetch update

    portsnap采用增量更新的方式,第一次需要执行fetch extract,以后只需要执行fetch update即可,增量更新的更新量很小,速度飞快。

    更新FreeBSD系统文件

    没有人能保证操作系统完美无缺,即便是发行版也不能,但在发现补丁后及时打上,是最明智的做法。这一点上FreeBSD也做得相当人性。那么,更新系统文件之前,我们也需要改一个配置文件,会让你变得更快。

    cd /etc

    #vi freebsd-update.conf

    找到ServerName update.FreeBSD.org

    将update.freebsd.org

    改为freebsd-updates.mirrors.163.com

    保存退出

    然后就可以了,运行下面的命令更新吧,更新之前可以看一下uname -a,以8.2为例,会显示FreeBSD 8.2-RELEASE

    #freebsd-update fetch

    #freebsd-update install

    更新完成后重启,再打uname -a,会显示FreeBSD 8.2-RELEASE-p4,显示系统补丁已经打上了。

    这些命令,你都可以加入到crontab中定期自动运行

    软件安装源配置

    编辑一个文件,这个文件在新装的freebsd系统中是不存在的,除非你用ports安装过软件,否则不会生成这个文件。所以,在新装系统中需要手动创建这个文件。

    vi /etc/make.conf

    然后输入以下内容

    MASTER_SITE_BACKUP?=http://mirrors.163.com/FreeBSD/distfiles/${DIST_SUBDIR}/

    MASTER_SITE_OVERRIDE?=${MASTER_SITE_BACKUP}

    保存退出,这样你在用ports安装的时候,就会直接连接到163的镜像,速度会更快。不过有一个缺点,就是最新的软件发行包通常不会及时更新,大概需要3-4天或者更长的时间,163镜像才会与freebsd同步过来,不过,however,有国内镜像总比没有强

    一般不推荐用pkg_add方式直接安装二进制文件,这样不够优化,最好是通过ports树进行编译安装。除非有特殊的要求,所以我先不写PACKAGESITE变量的设置。

    软件安装

    这是我最欣赏freebsd的优点之一,软件收集全面,分类明确,安装简便,编译安装方式足够适应系统并优化。配置文件集中管理,绝对节省人类的时间,比起LINUX到处找编译文件要强太多了。

    举例,比如我要需要安装nginx,我在这里假设你已经更新过ports树了,在我写这个文章的时候,最新的frebbsd nginx版本为1.0.8,1。

    运行下列命令进行安装

    #cd /usr/ports/www/nginx

    #make install clean

    会弹出选项,按照需求进行选择,然后OK,等待编译完成吧,这个软件就装完了。安装过程中会自动检测依赖关系,并自动下载依赖软件编译。这比糟糕透顶yum强不知多少倍,且不论yum是安装二进制文件,而且经常找不到依赖包,装完之后你还需要find配置文件,浪费时间!freebsd的配置文件全部集中管理。无论你通过ports安装什么软件,如果他存在配置文件,请到下面这个路径里找

    #cd /usr/local/etc

    ubuntu好像也是这个路径,但是,我用apt-get安装后,基本这个路径里什么都没有。

    运行你安装的软件

    这里有一点小麻烦,但绝对不大,只占用你大约不到30秒的时间。如果你安装了应用软件,比如nginx,请按照下列步骤完成

    #vi /etc/rc.conf

    然后新起一行,输入

    nginx_enable=”YES”

    保存退出

    然后运行下面的命令

    #cd /usr/local/etc/rc.d

    #./nginx start

    你的nginx就启动了,访问你的服务器,看看welcome to nginx吧。

    安全设置

    其实我觉得安全更加重要一些。不过其实即便你不配置下列内容,freebsd也是很安全的。但是你配了不是会更好么。

    rc.conf里面与安全相关的设置

    1.关闭不必要的端口和服务以及调整系统日志的记录,是网络安全的第一步。

    #vi /etc/rc.conf

    加入

    sendmail_enable=”NONE”

    #YES为打开,NO为仅监听本机,NONE为彻底关闭port 25

    sendmail_submit_enable=”NO”

    sendmail_outbound_enable=”NO”

    sendmail_msp_queue_enable=”NO”

    nfs_server_enable=”NO”

    nfs_client_enable=”NO”

    portmap_enable=”NO”

    #关闭NFS系统

    syslogd_enable=”YES”

    syslogd_flag=”-ss”

    #打开syslog日志

    log_in_vain=”YES”

    accounting_enable=”YES”

    #帐号保护

    update_motd=”NO”

    #关闭对Motion Of Today,文件是/etc/motd,建议删除该文件所有内容。

    icmp_drop_redirect=”YES”

    #禁止ping,不建议禁用,并且需要重新编译内核才可支持。