freebsd6升级到freebsd7

Upgrading from FreeBSD 6.X to FreeBSD 7.X
=========================================

Author:   Ralf S. Engelschall 
Created:  2007-05-24
Modified: 2009-08-01
Version:  1.3

ATTENTION: THIS UPGRADE PROCEDURE MIGHT NOT WORK FOR YOU AS YOUR
ENVIRONMENT IS DIFFERENT. ALSO, THIS UPGRADE PROCEDURES MIGHT DESTROY
YOUR SYSTEM AND YOU POTENTIALLY MIGHT LOOSE DATA. NO WARRANTY AT ALL.
USE IT AT YOUR OWN RISK!

This upgrades from FreeBSD 6.4-STABLE to 7.2-STABLE.

---- PROLOG -----------------------------------------------------------------

o # reboot once to make sure OLD system is at least
  # able to still successfully reboot autonomous at all
  # SORRY, THIS IS _NOT_ A JOKE -- THIS IS A VERY SERIOUS ISSUE!
  $ shutdown -r now

---- BUILD ------------------------------------------------------------------

o # switch to a reasonable run-time environment
  $ cd /; exec `/usr/bin/which bash sh | head -1`
  $ PATH=/bin:/usr/bin:/sbin:/usr/sbin; umask 022; unset TMOUT

o # install backward compatibility files 
  # ("locale data" to /usr/local/share/compat/, "libraries" to /usr/local/lib/compat/)
  # notice: via binary packages as FreeBSD 7.x ports cannot be installed under FreeBSD 6.X
  $ url="ftp://ftp.freebsd.org/pub/FreeBSD/ports/`uname -m`/packages-7-stable/All"; \
    ( cd /tmp; for pkg in localedata-5.4.tbz compat6x-`uname -m`-6.4.604000.200810.tbz; do \
        fetch -p $url/$pkg; pkg_add $pkg; rm -f $pkg; \
    done )

o # install latest FreeBSD Upgrade Toolkit
  $ cd /usr; \
    fetch http://people.freebsd.org/~rse/dist/freebsd-adm-1.2.2.tar.gz; \
    rm -rf adm; gunzip > RELENG_7

o # upgrade /usr/src (already required for "mergemaster -p" below!)
  $ (cd /usr/src && make cleandir); \
    (cd /usr/adm && make update)

o # upgrade kernel configuration
  $ vi /sys/`uname -m`/conf/`hostname -s | tr 'a-z' 'A-Z'`

  >> options        COMPAT_FREEBSD6
  >> options        SCTP            # Stream Transmission Control Protocol
  >> options        UFS_GJOURNAL    # Enable gjournal-based UFS
  >> options        STOP_NMI        # Stop CPUS using NMI instead of IPI
  >> options        AUDIT           # Security event auditing
  >> options        GEOM_LABEL      # Provides labelization

  << options        GEOM_GPT        # GUID Partition Tables.
  >> options        GEOM_PART_GPT   # GUID Partition Tables.

  << options        COMPAT_43       # Compatible with BSD 4.3 [KEEP THIS!]
  >> options        COMPAT_43TTY    # BSD 4.3 TTY compat [KEEP THIS!]

  << options        NTFS

  >> options        STACK           # stack(9) support

  >> device         uart            # Generic UART driver

  << device         lnc             # NE2100, NE32-VL Lance Ethernet cards
  >> device         le              # AMD Am7900 LANCE and Am79C9xx PCnet

  >> device         firmware        # firmware assist module

  >> device         dcons           # Dumb console driver
  >> device         dcons_crom      # Configuration ROM for dcons

  << device         rr232x          # Highpoint RocketRAID 232x

o # prepare the upgrade
  # (mainly create "ftp" group)
  $ mergemaster -p

o # build new system
  $ cd /usr/adm && make world-build kernel-build

---- INSTALL ----------------------------------------------------------------

o # upgrade system 
  $ make world-install kernel-install

o # cleanup system (part 1)
  $ rm -f /etc/rc.d/ike /etc/rc.d/pccard /etc/rc.d/pcvt /etc/rc.d/ramdisk
  $ rm -f /etc/rc.d/ramdisk-own /etc/rc.d/usbd /etc/rc.d/nfslocking
  $ make etc
  $ make clean

o # reboot into upgraded system
  $ shutdown -r now

---- CLEANUP ----------------------------------------------------------------

o # switch to a reasonable run-time environment
  $ cd /; exec `/usr/bin/which bash sh | head -1`
  $ PATH=/bin:/usr/bin:/sbin:/usr/sbin; umask 022; unset TMOUT

o # cleanup system (part 2)
  $ ( for dir in /bin /sbin /usr/bin /usr/sbin /usr/libexec /usr/libdata; do \
      find $dir -mtime +2 -type f -xdev -print; \
      find $dir -mtime +2 -type l -xdev -print; \
      done ) >/tmp/remove
  $ vi /tmp/remove
  # REVIEW FILES TO REMOVE MANUALLY
  $ cat /tmp/remove | xargs rm -f
  $ ( for dir in /lib /usr/lib; do \
      find $dir -mtime +2 -type f -xdev -print; \
      find $dir -mtime +2 -type l -xdev -print; \
      done ) | grep -v /usr/lib/compat >/tmp/move
  $ vi /tmp/move
  # REVIEW FILES TO MOVE MANUALLY
  $ for x in `cat /tmp/move`; do chflags noschg $x; mv $x /usr/lib/compat/; done
  $ cd /usr/src; make BATCH_DELETE_OLD_FILES=YES delete-old delete-old-libs

---- EPILOG ----------------------------------------------------------------

o # reboot into cleaned system
  # (mainly to reload the shared library cache and to
  # make sure everything really still works fine)
  $ shutdown -r now

freebsd7升级到freebsd8

Upgrading from FreeBSD 7.X to FreeBSD 8.X
=========================================

Author:   Ralf S. Engelschall 
Created:  2009-01-01
Modified: 2011-01-29
Version:  1.4

ATTENTION: THIS UPGRADE PROCEDURE MIGHT NOT WORK FOR YOU AS YOUR
ENVIRONMENT IS DIFFERENT. ALSO, THIS UPGRADE PROCEDURES MIGHT DESTROY
YOUR SYSTEM AND YOU POTENTIALLY MIGHT LOOSE DATA. NO WARRANTY AT ALL.
USE IT AT YOUR OWN RISK!

This upgrades from FreeBSD 7.3-STABLE to 8.2-STABLE.

---- PREPARE ----------------------------------------------------------------

o # reboot once to make sure OLD system is at least
  # able to still successfully reboot autonomous at all
  # SORRY, THIS IS _NOT_ A JOKE -- THIS IS A VERY SERIOUS ISSUE!
  $ shutdown -r now

---- BUILD ------------------------------------------------------------------

o # switch to a reasonable run-time environment
  $ cd /; exec `/usr/bin/which bash sh | head -1`
  $ PATH=/bin:/usr/bin:/sbin:/usr/sbin; umask 022; unset TMOUT

o # install backward compatibility files 
  # ("locale data" to /usr/local/share/compat/, "libraries" to /usr/local/lib/compat/)
  # notice: via binary packages as FreeBSD 8.X ports cannot be installed under FreeBSD 7.X
  $ url="ftp://ftp.freebsd.org/pub/FreeBSD/ports/`uname -m`/packages-8-stable/All"; \
    ( cd /tmp; for pkg in localedata-5.4.tbz \
      compat6x-`uname -m`-6.4.604000.200810_3.tbz \
      compat7x-`uname -m`-7.3.703000.201008_1.tbz; do \
        fetch -p $url/$pkg; pkg_add $pkg; rm -f $pkg; \
    done )

o # install latest FreeBSD Upgrade Toolkit
  $ cd /usr; \
    fetch http://people.freebsd.org/~rse/dist/freebsd-adm-1.2.2.tar.gz; \
    rm -rf adm; gunzip > RELENG_8

o # upgrade /usr/src (already required for "mergemaster -p" below!)
  $ (cd /usr/src && make cleandir); \
    (cd /usr/adm && make update)

o # upgrade kernel configuration
  $ vi /sys/`uname -m`/conf/`hostname -s | tr 'a-z' 'A-Z'`

  << options        ADAPTIVE_GIANT
  << options        STOP_NMI
  << device         sio
  << device         ugen
  << device         uscanner
  << device         isa
  << device         mem
  << device         io
  << device         sl
  << device         ppp

  >> options        COMPAT_FREEBSD6
  >> options        COMPAT_FREEBSD7
  >> options        P1003_1B_SEMAPHORES
  >> options        PRINTF_BUFR_SIZE=128
  >> options        HWPMC_HOOKS
  >> options        MAC
  >> options        FLOWTABLE
  >> device         acpi
  >> device         uart

o # prepare the upgrade
  # (just to be sure, should be not really necessary this time)
  $ mergemaster -p

o # build new system
  $ cd /usr/adm && make world-build && make kernel-build

---- INSTALL ----------------------------------------------------------------

o # workaround 1/3 for "bad system call" during usage of ln(1) in "make etc"
  $ cp -p /bin/ln /bin/ln.old

o # upgrade system 
  $ make world-install && make kernel-install

o # workaround 2/3 for "bad system call" during usage of ln(1) in "make etc"
  $ cp -p /bin/ln /bin/ln.new
  $ cp -p /bin/ln.old /bin/ln

o # cleanup system (part 1)
  $ rm -f /etc/rc.d/early.sh /etc/rc.d/idmapd /etc/rc.d/isdnd /etc/rc.d/nfslocking /etc/rc.d/ip6fw
  $ make etc
  $ make clean

o # workaround 3/3 for "bad system call" during usage of ln(1) in "make etc"
  $ cp -p /bin/ln.new /bin/ln
  $ rm -f /bin/ln.old

o # regenerate /etc/localtime
  $ tzsetup

o # reboot into upgraded system
  $ shutdown -r now

---- CLEANUP ----------------------------------------------------------------

o # switch to a reasonable run-time environment
  $ cd /; exec `/usr/bin/which bash sh | head -1`
  $ PATH=/bin:/usr/bin:/sbin:/usr/sbin; umask 022; unset TMOUT

o # cleanup system (part 2)
  $ ( for dir in /bin /sbin /usr/bin /usr/sbin /usr/libexec /usr/libdata /usr/lib32; do \
      find $dir -mtime +2 -type f -xdev -print; \
      find $dir -mtime +2 -type l -xdev -print; \
      done ) >/tmp/remove
  $ vi /tmp/remove
  # REVIEW FILES TO REMOVE MANUALLY
  $ cat /tmp/remove | xargs chflags noschg
  $ cat /tmp/remove | xargs rm -f
  $ ( for dir in /lib /usr/lib; do \
      find $dir -mtime +2 -type f -xdev -print; \
      find $dir -mtime +2 -type l -xdev -print; \
      done ) | grep -v /usr/lib/compat >/tmp/move
  $ vi /tmp/move
  # REVIEW FILES TO MOVE MANUALLY
  $ for x in `cat /tmp/move`; do chflags noschg $x; mv $x /usr/lib/compat/; done
  $ cd /usr/src; make BATCH_DELETE_OLD_FILES=YES delete-old delete-old-libs

o # reboot into cleaned system
  # (mainly to reload the shared library cache and to
  # make sure everything really still works fine)
  $ shutdown -r now

freebsd8升级到freebsd9

Upgrading from FreeBSD 8.X to FreeBSD 9.X
=========================================

Author:   Ralf S. Engelschall 
Created:  2011-09-30
Modified: 2011-09-30
Version:  1.0

ATTENTION: THIS UPGRADE PROCEDURE MIGHT NOT WORK FOR YOU AS YOUR
ENVIRONMENT IS DIFFERENT. ALSO, THIS UPGRADE PROCEDURES MIGHT DESTROY
YOUR SYSTEM AND YOU POTENTIALLY MIGHT LOOSE DATA. NO WARRANTY AT ALL.
USE IT AT YOUR OWN RISK!

This upgrades from FreeBSD 8.2-STABLE to 9.0-BETA3.

---- PREPARE ----------------------------------------------------------------

o # reboot once to make sure OLD system is at least
  # able to still successfully reboot autonomous at all
  # SORRY, THIS IS _NOT_ A JOKE -- THIS IS A VERY SERIOUS ISSUE!
  $ shutdown -r now

---- BUILD ------------------------------------------------------------------

o # switch to a reasonable run-time environment
  $ cd /; exec `/usr/bin/which bash sh | head -1`
  $ PATH=/bin:/usr/bin:/sbin:/usr/sbin; umask 022; unset TMOUT

o # install backward compatibility files 
  # ("locale data" to /usr/local/share/compat/, "libraries" to /usr/local/lib/compat/)
  # notice: via binary packages as FreeBSD 9.X ports cannot be installed under FreeBSD 8.X
  $ url="ftp://ftp.freebsd.org/pub/FreeBSD/ports/`uname -m`/packages-9-current/All"; \
    ( cd /tmp; for pkg in localedata-5.4.tbz \
      compat6x-`uname -m`-6.4.604000.200810_3.tbz \
      compat7x-`uname -m`-7.3.703000.201008_1.tbz \
      compat8x-`uname -m`-8.2.802000.201109.tbz; do \
        (fetch -p $url/$pkg; if [ -f $pkg ]; then pkg_add $pkg; rm -f $pkg; fi) || true; \
    done )

o # install latest FreeBSD Upgrade Toolkit
  $ cd /usr; \
    fetch http://people.freebsd.org/~rse/dist/freebsd-adm-1.2.2.tar.gz; \
    rm -rf adm; gunzip > RELENG_9

o # upgrade /usr/src (already required for "mergemaster -p" below!)
  $ (cd /usr/src && make cleandir); \
    (cd /usr/adm && make update)

o # upgrade kernel configuration
  $ vi /sys/`uname -m`/conf/`hostname -s | tr 'a-z' 'A-Z'`

  >> options        COMPAT_FREEBSD6
  >> options        COMPAT_FREEBSD7

o # prepare the upgrade
  # (just to be sure, should be not really necessary this time)
  $ mergemaster -p

o # build new system
  $ cd /usr/adm && make world-build && make kernel-build

---- INSTALL ----------------------------------------------------------------

o # upgrade system 
  $ make world-install && make kernel-install

o # cleanup system (part 1)
  $ make etc
  $ make clean

o # regenerate /etc/localtime
  $ tzsetup

o # reboot into upgraded system
  $ shutdown -r now

---- CLEANUP ----------------------------------------------------------------

o # switch to a reasonable run-time environment
  $ cd /; exec `/usr/bin/which bash sh | head -1`
  $ PATH=/bin:/usr/bin:/sbin:/usr/sbin; umask 022; unset TMOUT

o # cleanup system (part 2)
  $ ( for dir in /bin /sbin /usr/bin /usr/sbin /usr/libexec /usr/libdata /usr/lib32; do \
      find $dir -mtime +2 -type f -xdev -print; \
      find $dir -mtime +2 -type l -xdev -print; \
      done ) >/tmp/remove
  $ vi /tmp/remove
  # REVIEW FILES TO REMOVE MANUALLY
  $ cat /tmp/remove | xargs chflags noschg
  $ cat /tmp/remove | xargs rm -f
  $ ( for dir in /lib /usr/lib; do \
      find $dir -mtime +2 -type f -xdev -print; \
      find $dir -mtime +2 -type l -xdev -print; \
      done ) | grep -v /usr/lib/compat >/tmp/move
  $ vi /tmp/move
  # REVIEW FILES TO MOVE MANUALLY
  $ for x in `cat /tmp/move`; do chflags noschg $x; mv $x /usr/lib/compat/; done
  $ cd /usr/src; make BATCH_DELETE_OLD_FILES=YES delete-old delete-old-libs

o # reboot into cleaned system
  # (mainly to reload the shared library cache and to
  # make sure everything really still works fine)
  $ shutdown -r now

freebsd无线配置静态ip

修改 /etc/rc.conf 写入

静态ip

wlans_ath0="wlan0"
ifconfig_wlan0="WPA inet 192.168.1.100 netmask 255.255.255.0"

dhcp 获取

wlans_ath0="wlan0"
ifconfig_wlan0="WPA DHCP"

wpa 配置 /etc/wpa_supplicant.conf

network={
  ssid="YourAPssid"
  psk="YourAPpassword"
}

完成,可以上网喽

apache 403 错误 client denied by server

由于前段时间给一台服务器在前加了个 nginx 做代理,今天大量用户反应网站出现 403 服务器日志显示 client denied by server 看一下访问日志都是 127.0.0.1 这才想起应该是 apache 防 ddos 模块的问题,把每个 vhost 的链接都当做 一个链接了,先去掉 mod_evasive ,恢复正常,为了上 apache 得到真实 ip 要安装 mod_rpaf 这个模块就 OK 了,

cd /usr/ports/www/mod_rpaf
make install clean

安装模块, freebsd 就是让人偷懒呀。编译完成 修改 httpd.conf
打开 mod_rpaf 模块 ,去掉 mod_rpaf 的 # 号, 添加

RPAFenable On
RPAFsethostname On
RPAFproxy_ips 127.0.0.1
RPAFheader X-Forwarded-For

 

重起 apache ,终于一切正常了,收工回家.

nginx freebsd 官方网站优化

OS & Hardware
FreeBSD 7.1
AMD64, dual-core CPU
4GB RAM
Purpose
Web server & reverse proxy
Load description
45K inactive keep-alive connections
HTTP request is about 5,000 req/s, mostly small static files, all are cached by VM
System config
/boot/loader.conf:

vm.kmem_size=1844M
kern.maxbcache=64M
kern.ipc.maxpipekva=4M

/etc/sysctl.conf:

kern.ipc.nmbjumbop=192000
kern.ipc.nmbclusters=229376
kern.ipc.maxsockets=204800
net.inet.tcp.maxtcptw=163840
kern.maxfiles=204800

kern.ipc.somaxconn=4096

Retrieved from “http://wiki.nginx.org/FreeBSDOptimizations”

freebsd下 nginx 日志每天分割

#!/bin/sh
date
today=`date +"%Y_%m_%d"`
logdir=/pub/log
daydir=/pub/log/$today
expdays=7
if [ ! -d $daydir ] ; then
 mkdir -p $daydir
fi

cp /pub/log/wwwlogs.log $daydir/wwwlogs.log

#清空当前日志
/usr/bin/true > /pub/log/wwwlogs.log
#删除7天前的过期文件
#find $daydir -type d -mtime +$expdays -maxdepth 1 | xargs rm -rf

#每天12点运行
#0      0       *       *       *       /cut_nginx_log.sh

freebsd下在一块网卡下增加删除ip

在bge0网卡上增加ip别名:

ifconfig bge0 add alias xxx.xxx.xxx.xxx netmask xxx.xxx.xxx.xxx up  

说明:这里掩码的设定是这样的,同一个网断的第一个ip掩码按照真实的掩码设置。在这个网段下面再增加ip时,掩码就是255.255.255.255了!切记!

在bge0网卡上删除ip别名:

ifconfig bge0 -alias xxx.xxx.xxx.xxx 

下路由配置

配置路由
在同一个局域网上的计算机是直接连通的,但是不同的网络上的计算机并没有直接相连,只能通过一台特殊的专用计算机 -路由器来完成连通。路由器连接有多个网络界面,每一个网络界面连接到一个相应的网络上,具有一个这个网络上的IP地址,因此,网络内部的计算机可以和路由器本身相互通信。
当网络内部的计算机要向外连接的时候,数据包实际是交给路由器的,路由器再将数据包从连接外部网络的网络界面上转发出去,数据包经过这样一个一个的转发过程,直到到达目的地。对于网络内部的计算机来讲,没有必要了解数据包的整个转发的路径和经过的所有路由器的信息,只需要知道第一步需要将数据包交给哪一个路由器就可以了。因此,计算机必须知道与它直接相连接的路由器的有关信息,这个过程就是路由配置的过程。
进行路由配置有两种途径,一种是由管理员设置所有的路由信息,由于数据是手工设置,因此称为静态路由设置。另一个是启动一个支持路由交换协议的进程,自动侦测网络上的所有路由器及其相关信息,这称为动态路由设置。
在 FreeBSD系统不用做专门路由器的情况下,一般地说使用静态路由设置足够满足网络通信的需要。
1) 缺省网关
在最简单的情况下,一个网络向外通过一个路由器完成向外连接,这个路由器被称为缺省网关,它负责几乎所有的向外连接任务。假设缺省网关的地址为 192.168.1.254,
则设置缺省网关的命令为:

freebsd# route add default 192.168.1.254
add net default: gateway 192.168.1.254     //成功配置缺省网关
add net default: gateway 192.168.1.254: File exists   //如果系统已经设置了缺省网关,那么系统会报告错误
freebsd# route delete default
delete net default    //成功删除缺省网关 
freebsd# route flush     //清除所有路由
default 192.168.1.254 done  

上述命令执行之后立即生效,因此,可能会影响已经建立的连接。为了保存缺省网关的配置,同样也需要将配置写入系统配置文件 rc.conf。
defaultrouter=”192.168.1.254″
仅仅配置缺省网关的大部分情况是在计算机处于整个互联网的边缘,网络中仅仅需要一个路由器接入互联网就可以了。
2) 其他静态路由设置
更复杂的情况下,计算机所处的网络与多个网络相连接,网络中存在多个路由器,每个路由器负责到一些网络的转发任务,而不负责到全部网络的转发任务。这种情况下,如果将所有的数据都发给一个路由器,那么原则上它只能正确转发目的是它自己负责的网络的数据。实际使用当中,路由器将使用 ICMP协议,向发送数据的主机报告路由错误。
因此,应该在计算机中配置这个网络上所有路由器及这些路由器负责的相应网络的路由数据,以便计算机选择正确的路由器转发数据包。同样,也必须使用 route命令增加到各个网络的静态路由数据。

freebsd# route add 192.168.10.0/24 192.168.1.253
freebsd# route add 192.168.20.0/24 192.168.1.253
freebsd# route add 192.168.30.0/25 192.168.1.253
freebsd# route add 192.168.30.128 192.168.1.253
freebsd# route add 192.168.40.0 -netmask 255.255.255.0 192.168.1.253

上面指令给出了几种不同的情况, IP地址之后的 ′ /24 ′ 指明子网掩码的长度是 24位,它代表二进制方式的网络掩码前面非0位的长度,24个非0位的掩码等价于255.255.255.0,也可以忽略这个部分,系统使用网络地址的缺省掩码,例如192.168.20.0属于一个C类地址,因此网络掩码是255.255.255.0。但是,如果不是标准的A、B、C类地址,而是一个被划分过的子网,就必须指明子网掩码,例如192.168.30.0/25,必须指明掩码长度是25位,否则系统使用缺省的掩码。如果不使用掩码长度的形式,则可以使用 ′ -netmask ′ 参数的形式指明网络掩码。
即便如此,上面的指令也不是没有问题。对于标准的网络地址, route指令能确定网络地址和掩码,但是对于象192.168.30.128这样的地址,在通常情况下,它属于一个计算机的普通IP地址,route指令也能设置通向单独计算机的路由,因此上面的命令将设置一个通向192.168.30.128这一个主机的路由。系统将返回:

freebsd# route add 192.168.30.128 192.168.1.253
add host 192.168.30.128: gateway 192.168.1.253

而其他情况下将返回 ” add net …” ,表明地址代表一个网络而不是一个单独的计算机。然而,很多情况下,这个地址被用作一个网络地址,是一个代表从 192.168.30.128到192.168.30.255整个网络的网络地址,它的掩码为25位长的255.255.255.128。
甚至在一些极端的情况下,地址 192.168.10.0也可以用来代表一个具体的计算机的IP地址,而不是一个网络地址。
为了指定这些非标准情况,必须使用额外的参数。

freebsd# route add -net 192.168.10.0/24 192.168.1.253
freebsd# route add -net 192.168.20.0 192.168.1.253

上面指令中的 -net参数是一个可选参数,它明确指出这个路由是通向一个网络的路由数据,否则route只能从所给予的IP地址中判断它是网络还是计算机,就有可能发生与管理员想法并不一致的设置。同样可以指定-host参数为一个单独的远程计算机指定路由。

freebsd# route add -host 192.168.20.0 192.168.1.253

非缺省网关的静态路由设置同样也需要保存在 rc.conf中,以备下次启动时自动配置。

static_routes="static1 static2"
route_static1="-net 192.168.10.0/24 192.168.1.253"
route_static2="-net 192.168.20.0/24 192.168.1.253"

保存静态路由的方法略为复杂,这是因为静态路由的数量并不确定,因此首先给静态路由确定一个名字,例如 static1、static2等,使static_routes变量中包含这些名字,然后将具体的路由设置保存在route_static1等类似的由静态路由的名字组成的变量中。
3) 查看路由信息
设置完路由表之后,可以使用 netstat -r命令来查看当前的路由表的内容。

# netstat -nr
Routing tables
Internet:
Destination Gateway Flags Refs Use Netif Expire
default 192.168.1.254 UGSc 1 941 xl0
127.0.0.1 127.0.0.1 UH 1 644 lo0
192.168.1 link#1 UC 0 0 xl0
192.168.1.254 0:e0:1e:ce:85:a9 UHLW 2 0 xl0
192.168.1.64 0:90:27:4e:f6:67 UHLW 1 6 lo0
192.168.1.253 link#1 UHLW 2 0 xl0
192.168.10 192.168.1.253 UGSc 0 0 xl0
192.168.20 192.168.1.253 UGSc 0 0 xl0

http://blog.csdn.net/marcolu/archive/2004/08/05/66012.aspx
http://bbs.itzero.com/redirect.php?tid=97614&goto=lastpost

Find 指令用法教學

筆記一下自己常用的 find 指令,適用於 FreeBSD 或者是 Linux 各大 distribution,系統管理這個指令就相當重要了,在搭配 grep,sed,awk,perl 可以快速找到自己要的檔案。我自己本身很常用到 grep,find,awk 這些撰寫 shell script。

底下先來介紹一下 find:

1. 找出 . 底下的 php 檔案

#
#
find . -name "*.php"

2. 找出 . 底下非 php 副檔名檔案

#
#
find . -not -name "*.php"

3. 刪除 . 底下 php 檔案,有兩種作法

#
# 系統詢問之後才刪除
# 先把 -exec 後面的東西先清掉, 用 -print 來先確認輸出
# rm 可以多用 -i 的參數來加以確認
find . -name "*.php" -exec rm -i {} \;
#
# 系統直接刪除
find . -delete -name "*.php"
find . -name "*.php" | xargs /bin/rm -rf

4. 如何刪除 7 天前之料呢?

find /path_name -type f -mtime +7 -exec rm '{}' \;
find /path_name -type f -mtime +7  | xargs /bin/rm -rf
find /path_name -delete -type f -mtime +7

5. 找出7天以內修改的資料

#
#
find . -type f -mtime -7 -name "*.php"

6. find 後只顯示目錄名稱不顯示路徑

find . -maxdepth 1 -type d  -exec basename {} \;
find . -maxdepth 1 -type d | awk -F"/" '{print $NF}'
find . -maxdepth 1 -type d | sed 's!.*\/\([^\/]*\).*!\1!g'

7. find 後只顯示目錄名稱不顯示路徑,也不顯示第一個 . 目錄

#
#
find . -maxdepth 1 -mindepth 1 -type d -exec basename {} \;

8. -mmin (minutes) or -mtime (24 hour periods, starting from now)
For example:

find . -mtime 0   # find files modified between now and 1 day ago
                  # (i.e., within the past 24 hours)
find . -mtime -1  # find files modified less than 1 day ago
                  # (i.e., within the past 24 hours, as before)
find . -mtime 1   # find files modified between 24 and 48 hours ago
find . -mtime +1  # find files modified more than 48 hours ago

find . -mmin +5 -mmin -10 # find files modifed between
                          # 6 and 9 minutes ago

參考資料
http://content.hccfl.edu/pollock/Unix/FindCmd.htm
http://www.linux.ie/newusers/beginners-linux-guide/find.php

原文 http://blog.wu-boy.com/2009/01/13/712/

利用 portmaster 升級 PHP 5.26 -> 5.28

之前在 大神 那边看到一篇 升级 PHP 5.2.8 的一些小细节,就来把我的机器升级一下,发现 php 5.2.7 之后已经把 pcre extension 纳入在裡面,参考 /usr/ports/UPDATING 裡面的 20081211 这个项目,可以利用 portupgrade 或者是 portmaster 来升级,之前都是利用 ruby 写的 portupgrade 来升级系统或者是更新安全性,现在利用 portmaster 这一套也是不错用,portmaster 是用 sh 写出来的,在 gslin 大神这一篇:portupgrade、portmaster、portconf 说到速度方面比 portupgrade 还要好,这我没有实际测试过,自己在实际用了一下,还蛮方便的。

安装 portmaster 跟 portconf 搭配:

cd /usr/ports/ports-mgmt/portconf
make install clean
cd /usr/ports/ports-mgmt/portmaster
make install clean

先找出需要升级的套件:

pkg_version -v
在利用 portmaster 升级 php5

pkg_delete -f php5-pcre\*
portmaster pecl\*
portmaster php5\*

如果是利用 portupgrade:

pkg_delete -f php5-pcre-*
pkgdb -F
portupgrade -f php5*
portupgrade -f pecl*

之前还没升级的时候,利用 portaudit 检查套件的安全性,发现 php5-gd 在 5.2.6 版有安全性的问题,所以就顺便一起升级到 5.2.8_1

安装 portaudit:

cd /usr/ports/ports-mgmt/portaudit/
make install clean
升级 php5-gd:
#
# -C:升级之前先清除套件 make clean
# -G:升级之前先检查 make config
# -i:升级安装套件之前,先询问使用者
# -d:安装之后清除套件
portmaster -CGid php5-gd-5.2.6

原文 http://blog.wu-boy.com/2009/02/23/829/