Netkiller FreeBSD 手札

netkiller Neo Chan

<netkiller(at)msn(dot)com>

版权 © 2008, 2009, 2010, 2011, 2012, 2013 Copyright netkiller

版权声明

转载请与作者联系，转载时请务必标明文章原始出处和作者信息及本声明。
文档出处:
http://netkiller.github.io
http://netkiller.sourceforge.net

我的系列文档

Netkiller Architect 手札 | Netkiller Developer 手札 | Netkiller PHP 手札 | Netkiller Python 手札 | Netkiller Testing 手札 | Netkiller Cryptography 手札
Netkiller Linux 手札 | Netkiller CentOS 手札 | Netkiller FreeBSD 手札 | Netkiller Security 手札 | Netkiller Version 手札 | Netkiller Web 手札
Netkiller Monitoring 手札 | Netkiller Storage 手札 | Netkiller Mail 手札 | Netkiller Shell 手札 | Netkiller Network 手札 | Netkiller Database 手札
Netkiller PostgreSQL 手札 | Netkiller MySQL 手札 | Netkiller NoSQL 手札 | Netkiller LDAP 手札 | Netkiller Cisco IOS 手札 | Netkiller H3C 手札
Netkiller Multimedia 手札 | Netkiller Docbook 手札 | Netkiller 开源软件 手札 |  |  |

您可以使用iBook阅读当前文档

QQ群：128659835 请注明“读者”

目录

自述
1. 系列文档
2. 作者简介
3. 写给读者
1. FreeBSD Install
1.1. Welcome
1.2. partitioning
1.3. password
1.4. network
1.5. timezone
1.6. complete
1.7. FreeBSD 初始化设置
1.8. sysinstall 工具
I. System Administration
2. Packages System
2.1. Using the Packages System
2.1.1. PACKAGESROOT / PKG_PATH 环境变量
2.1.2. Installing a Package
2.1.3. Managing Packages
2.1.4. Deleting a Package
2.2. Updating and Upgrading FreeBSD
2.2.1. update
2.2.2. upgrade
2.2.3. update ports
2.3. ports
2.3.1. install
2.3.2. remove
2.3.3. config menu
2.4. PKGNG - Pkgng is the Next Generation package management tool for FreeBSD.
2.4.1. 安装 pkgng
2.4.2. 转换数据库
2.4.3. install
2.4.4. delete
2.4.5. info
2.4.6. query
2.4.7. upgrade
3. 编辑器 (editors)
3.1. vim
4. terminal
4.1. 分辨率
4.2. 屏幕保护
4.3. 键盘设置
5. FreeBSD 开机启动
5.1. /etc/rc.conf
6. Date
7. shell
7.1. Bash
7.2. zsh
7.2.1. 初始化 zsh
7.2.2. prompt
8. Users and Basic Account Management
8.1. 添加用户
8.2. 删除用户
8.3. 修改用户信息
8.4. su - root
8.5. profile
8.5.1. shell
8.5.2. Changing user information
8.6. passwd file
9. Network
9.1. DHCP
9.2. IP Address
9.3. alias
9.4. Default Gateway
9.5. DNS
9.6. netstart
9.7. Route
10. Debug
10.1. lsof - list open files
II. File System
11. Windows 文件系统
11.1. msdos/fat16 文件系统
11.1.1. 分区格式化
11.1.2. 挂载 msdoc 分区
12. ZFS
12.1. 初始化
12.2. Creating a Basic Filesystem
12.3. Creating a Storage Pool
12.3.1. Mirrored Pool
12.3.2. RAID-Z Pool
12.3.3. Querying Pool Status
12.3.4. Destroying Pools
12.4. Creating a Filesystem Hierarchy
12.4.1. Creating a Filesystem
12.4.2. Setting Quotas
12.4.3. Setting Reservations
12.4.4. Querying Filesystem Information
12.4.5. Renaming a Filesystem
12.4.6. Destroying a Filesystem
12.5. zfs mount/umount
12.5.1. Temporary Mount Properties
12.5.2. Mounting File Systems
12.5.3. Unmounting File Systems
12.5.4. Legacy Mount Points
12.6. Sharing ZFS File Systems
12.6.1. Controlling Share Semantics
12.6.2. Unsharing Filesystems
12.6.3. Sharing Filesystems
12.7. Device Management
12.7.1. Adding Devices to a Pool
12.7.2. Onlining and Offlining Devices
12.7.3. Replacing Devices
12.8. I/O Statistics
12.8.1. Virtual Device Statistics
12.9. Health Status
12.9.1. Basic Health Status
12.9.2. Detailed Health Status
12.10. Storage Pool Migration
12.10.1. Exporting a Pool
12.10.2. Importing Pools
12.11. Querying Properties
12.12. Backing Up and Restoring ZFS Data
12.12.1. Backing Up a ZFS Snapshot
12.12.2. Restoring a ZFS Snapshot
12.12.3. Remote Replication of a ZFS File System
12.13. ZFS Snapshots and Clones
12.13.1. ZFS Snapshots
12.13.2. ZFS Clones
12.14. Emulated Volumes
13. Network Communication
13.1. wget
13.2. rsync
13.2.1. rsyncd.conf
13.3. curl
13.4. NTPD
13.5. SNMP
13.6. Network Manager
13.6.1. ntop
III. Web Server
14. Lighttpd
14.1. install lighttpd
14.2. install php5
14.3. xcache
14.4. Zend Optimizer
15. nginx
15.1. port install
15.1.1. php
15.1.2. /etc/rc.conf
15.1.3. /usr/local/etc/nginx/nginx.conf
15.1.4. start
15.2. 编译安装 php 与 php-fpm
15.2.1. php-5.2.x
15.2.2. php-5.3.x
16. Apache
16.1. install
17. mysql
17.1. install
18. log
18.1. cronolog
18.1.1. Apache
18.1.2. Lighttpd
18.2. logrotate
19. Cache
19.1. Memcache
19.2. PHP Memcache
20. MySQL
20.1. Installation
21. textproc
21.1. docbook
22. devel
22.1. subversion
23. FAQ
23.1. Linux用户使用FreeBSD，问FreeBSD ulimit怎么设置？
23.2. su: Sorry


自述

目录

1. 系列文档
2. 作者简介
3. 写给读者

目前技术书籍的价格一路飙升，动则80，100，少则50，60. 技术书籍有时效性，随着技术的革新或淘汰，大批书记成为废纸垃圾。并且这些书技术内容雷同，相互抄袭，质量越来越差，甚至里面给出的例子错误百出，只能购买影印版，或者翻译的版本。

在这种背景下我便萌生了自己写书的想法，资料主要来源是我的笔记与例子。我并不想出版，只为分享，所有我制作了基于CC License 发行的系列电子书。

本书注重例子，少理论，只要你对这例子一步一步操作，就会成功，会让你有成就感并能坚持学下去，因为很多人遇到障碍就会放弃，其实我就是这种人，只要让他看到希望，就能坚持下去。

为什么写这篇文章

有很多想法,工作中也用不到所以未能实现，所以想写出来,和大家分享.有一点写一点,写得也不好,只要能看懂就行,就当学习笔记了.

开始零零碎碎写过一些文档，也向维基百科供过稿，但维基经常被ZF封锁，后来发现sf.net可以提供主机存放文档，便做了迁移。并开始了我的写作生涯。

这篇文档是作者10年来对工作的总结,是作者一点一滴的积累起来的，有些笔记已经丢失，所以并不完整。

因为工作太忙整理比较缓慢。目前的工作涉及面比较窄所以新文档比较少。

我现在花在技术上的时间越来越少，兴趣转向摄影，无线电。也想写写摄影方面的心得体会。

写作动力:

曾经在网上看到外国开源界对中国的评价，中国人对开源索取无度，但贡献却微乎其微.这句话一直记在我心中，发誓要为中国开源事业做我仅有的一点微薄贡献

另外写文档也是知识积累，还可以增加在圈内的影响力.

人跟动物的不同,就是人类可以把自己学习的经验教给下一代人.下一代在上一代的基础上再创新,不断积累才有今天.

所以我把自己的经验写出来,可以让经验传承

没有内容的章节:

目前我自己一人维护所有文档，写作时间有限，当我发现一个好主题就会加入到文档中，待我有时间再完善章节，所以你会发现很多章节是空无内容的.

文档目前几乎是流水帐试的写作，维护量很大，先将就着看吧.

我想到哪写到哪,你会发现文章没一个中心,今天这里写点,明天跳过本章写其它的.
文中例子绝对多,对喜欢复制然后粘贴朋友很有用,不用动手写,也省时间.
理论的东西,网上大把,我这里就不写了,需要可以去网上查.
我爱写错别字,还有一些是打错的,如果发现请指正.
文中大部分试验是在Debian/Ubuntu/Redhat AS上完成.

1. 系列文档

下面是我多年积累下来的经验总结，整理成文档供大家参考:

HTML 格式

http://netkiller.github.com/home/technology.html

http://netkiller.sourceforge.net/home/technology.html

PDF 格式

Download PDF Document 下载PDF文档1

Download PDF Document 下载PDF文档2

EPUB 格式

http://netkiller.sourceforge.net/technology.html

通过 GIT 镜像整个网站

https://github.com/netkiller/netkiller.github.com.git

$ git clone https://github.com/netkiller/netkiller.github.com.git

其他方式

获得光盘介质，RPM包，DEB包，如有特别需要，请联系我


2. 作者简介

陈景峰 (ㄔㄣ ㄐ丨ㄥ ㄈㄥ)

Nickname：netkiller | English name: Neo chen | Nippon name: ちんけいほう (音訳) | Korean name: 천징봉 | Thailand name: ภูมิภาพภูเขา

Callsign: BG7NYT | QTH: ZONE CQ24 ITU44 ShenZhen, China

程序猿，攻城狮，挨踢民工， UNIX like Evangelist, 业余无线电爱好者（呼号：BG7NYT）,户外运动，山地骑行以及摄影爱好者。

《Netkiller 系列 手札》的作者

1981年1月19日(庚申年腊月十四)出生于黑龙江省青冈县建设乡双富大队第一小队

1989年9岁随父母迁居至黑龙江省伊春市

1996年第一次接触UNIX操作系统，BSD UNIX, Microsoft Xinux(盖茨亲自写的微软Unix，知道的人不多)

1997年第自学BASIC语言，Turbo C语言，苦于没有电脑，后来学校建了微机室才第一次使用QBASIC(DOS 6.22 自带命令)，那个年代只能通过软盘拷贝转播Trubo C编译器始终没有搞到，

1997年第一次上Internet网速只有9600Bps, 当时全国兴起各种信息港域名格式是www.xxxx.info.net, 访问的第一个网站是NASA下载了很多火星探路者拍回的照片，还有“淞沪”sohu的前身

1998~2000年在哈尔宾学习计算机，充足的上机时间，但老师让我们练打字（明伦五笔/WT）打字不超过80个/每分钟还要强化训练，不过这个给我的键盘功夫打了好底。

1999年学校的电脑终于安装了光驱，在一张工具盘上终于找到了Turbo C与Quick Basic编译器，当时对VGA图形编程非常感兴趣，通过INT33中断控制鼠标，使用绘图函数模仿windows界面。还有操作 UCDOS 中文字库，绘制矢量与点阵字体。

2000年沉迷于Windows NT与Back Office各种技术，神马主域控制器，DHCP，WINS，IIS，域名服务器，Exchange邮件服务器，MS Proxy, NetMeeting...以及ASP+MS SQL开发

职业生涯

2001年来深圳进城打工,成为一名外来务工者. 在一个4人公司做PHP开发，当时PHP的版本是2。0, 开始使用Linux Redhat 6.2.当时很多门户网站都是用FreeBSD,但很难搞到安装盘，在网易社区认识了一个网友,从广州给我寄了一张光盘，FreeBSD 3.2

2002年我发现不能埋头苦干,还要学会"做人".同住辗转广州工作了半年。

2003年这年最惨,公司拖欠工资16000元,打过两次官司2005才付清.

2004年开始加入分布式计算团队,目前成绩

2004-10月开始玩户外和摄影

2005-6月成为中国无线电运动协会会员,呼号BG7NYT,进了一部Yaesu FT-60R手台。

2006年单身生活了这么多年,终于找到归宿.

2007物价上涨,金融危机，休息了4个月（其实是找不到工作）,关外很难上439.460中继，搞了一台Yaesu FT-7800.

2008终于找到英文学习方法，， 《Netkiller Developer 手札》，《Netkiller Document 手札》

2008-8-8 08:08:08 结婚,后全家迁居湖南省常德市

2009《Netkiller Database 手札》,年底拿到C1驾照

2010对电子打击乐产生兴趣，计划学习爵士鼓

2011 平凡的一年，户外运动停止，电台很少开，中继很少上，摄影主要是拍女儿与家人，年末买了一辆山地车

2012 对油笔画产生了兴趣，活动基本是骑行银湖山绿道，

2013开始学习民谣吉他，同时对电吉他也极有兴趣；最终都放弃了。这一年深圳开始推数字中继2013-7-6日入手Motorola MOTOTRBO XIR P8668

职业生涯路上继续打怪升级

联系作者

http://netkiller.github.io/

http://netkiller.sourceforge.net/

Mobile: +86 13113668890

Tel: +86 755 2981-2080

Callsign: BG7NYT QTH: Shenzhen, China

注：请不要问我安装问题！

Email: netkiller@msn.com

MSN: netkiller@msn.com

ICQ: 101888222

QQ: 13721218

Yahoo/AIM/GTalk: bg7nyt

IRC: irc://irc.freenode.net /nickname netkiller or neo

CQ CQ CQ DE BG7NYT

写给火腿:

欢迎无线电爱好者和我QSO,我的QTH在深圳宝安区龙华镇溪山美地12B7CD,设备YAESU FT-50R,FT-60R,FT-7800 144-430双段机, ,拉杆天线/GP天线 Nagoya MAG-79EL-3W/Yagi

如果这篇文章对你有所帮助,请寄给我一张QSL卡片,qrz.cn or qrz.com or hamcall.net

Personal Amateur Radiostations of P.R.China

ZONE CQ24 ITU44 ShenZhen, China

Best Regards, VY 73! OP. BG7NYT

Blogger

Twitter: http://twitter.com/bg7nyt

Digg: http://www.digg.com/netkiller

Facebook: https://www.facebook.com/bg7nyt

LinkedIn: http://cn.linkedin.com/in/netkiller

Flickr: http://www.flickr.com/photos/bg7nyt/

Disqus: http://disqus.com/netkiller/

solidot: http://solidot.org/~netkiller/

ITEYE: http://netkiller-github-com.iteye.com

51CTO: http://bg7nyt.blog.51cto.com/|http://g.51cto.com/netkiller

pengyou: http://www.pengyou.com/netkiller

weibo: http://weibo.com/bg7nyt

163 Blog: http://t.163.com/netkiller

Mailing List

http://groups.google.com/group/netkiller

Send email to this group: netkiller@googlegroups.com

RSS http://groups.google.com/group/netkiller/feed/rss_v2_0_topics.xml?num=50


3. 写给读者

写给读者

欢迎提出宝贵的建议,如有问题请到 邮件列表 讨论

至读者：
我不知道什么时候，我不再更新文档或者退出IT行业去从事其他工作，我必须给这些文档找一个归宿，让他能持续更新下去。
我想捐赠给某些基金会继续运转，或者建立一个团队维护它。
我用了10年时间坚持不停地写作，持续更新，才有今天你看到的《Netkiller 手扎》系列文档，在中国能坚持10年，同时没有任何收益的技术类文档，是非常不容易的。
有很多时候想放弃，看到外国读者的支持与国内社区的影响，我坚持了下来。
中国开源事业需要各位参与，不要成为局外人，不要让外国人说：中国对开源索取无度，贡献却微乎其微。
我们参与内核的开发还比较遥远，但是进个人能力，写一些文档还是可能的。


第 1 章 FreeBSD Install

目录

1.1. Welcome
1.2. partitioning
1.3. password
1.4. network
1.5. timezone
1.6. complete
1.7. FreeBSD 初始化设置
1.8. sysinstall 工具

1.1. Welcome

回车即可

选择 Install 按钮后回车

选择 No

输入 Hostname


1.2. partitioning

回车即可

选择 Guided

选择 Entire Dist 便是使用整个磁盘，

使用光标键移动按钮到 Auto 然后回车，表示自动分区

选择 Finish 回车，完成分区设置

再选择 Commit 确认，最后就会格式化磁盘

开始安装


1.3. password

设置root密码

确认密码，再输入一次


1.4. network

网络接口选择，这是只有一个网卡，如果你有多个网卡，这里应该是一个选择列表

问你是否开启IPv4 选Yes

问题是否使用DHCP获取IP地址。这里选择 No

输入IP地址，子网掩码，网关

设置DNS服务器


1.5. timezone

问你是否使用UTC时间，选择 No

选择时区，我一般使用Hongkong 或者 Harbin

回车

选择 Yes


1.6. complete

额外的软件包安装

sshd当然需要，还有ntpd, moused 也不错可以在控制台上使用鼠标，可以快速复制粘贴控制台上的内容。

对于普通用户，这个基本用不到 No

添加一个普通帐号，选择Yes

根据提示输入即可

到此 FreeBSD 安装完成，如果你想修改前面那些配置可以在这里修改。这个界面让很多菜鸟搞得蒙头转向，挑不出安全程序，一边又一遍的安装FreeBSD. 这里你放心的 Exit 菜单上回车即可。

选择 Yes 回车

选择 Reboot 回车


1.7. FreeBSD 初始化设置

刚刚添加了一个neo用户，但这个用户并不能 su - root， 默认配置下 FreeBSD在安全性方面做得比Linux好很多，你需要做下面的操作将neo 添加到 wheel组才能使用su命令

# pw usermod neo -G wheel
# id neo
uid=1001(neo) gid=1001(neo) groups=1001(neo),0(wheel)


1.8. sysinstall 工具

例如安装 FreeBSD src 源码包

sysinstall -> Configure -> Distributions -> src -> ALL -> Install from a FreeBSD CD/DVD


部分 I. System Administration

目录

2. Packages System
2.1. Using the Packages System
2.1.1. PACKAGESROOT / PKG_PATH 环境变量
2.1.2. Installing a Package
2.1.3. Managing Packages
2.1.4. Deleting a Package
2.2. Updating and Upgrading FreeBSD
2.2.1. update
2.2.2. upgrade
2.2.3. update ports
2.3. ports
2.3.1. install
2.3.2. remove
2.3.3. config menu
2.4. PKGNG - Pkgng is the Next Generation package management tool for FreeBSD.
2.4.1. 安装 pkgng
2.4.2. 转换数据库
2.4.3. install
2.4.4. delete
2.4.5. info
2.4.6. query
2.4.7. upgrade
3. 编辑器 (editors)
3.1. vim
4. terminal
4.1. 分辨率
4.2. 屏幕保护
4.3. 键盘设置
5. FreeBSD 开机启动
5.1. /etc/rc.conf
6. Date
7. shell
7.1. Bash
7.2. zsh
7.2.1. 初始化 zsh
7.2.2. prompt
8. Users and Basic Account Management
8.1. 添加用户
8.2. 删除用户
8.3. 修改用户信息
8.4. su - root
8.5. profile
8.5.1. shell
8.5.2. Changing user information
8.6. passwd file
9. Network
9.1. DHCP
9.2. IP Address
9.3. alias
9.4. Default Gateway
9.5. DNS
9.6. netstart
9.7. Route
10. Debug
10.1. lsof - list open files


第 2 章 Packages System

目录

2.1. Using the Packages System
2.1.1. PACKAGESROOT / PKG_PATH 环境变量
2.1.2. Installing a Package
2.1.3. Managing Packages
2.1.4. Deleting a Package
2.2. Updating and Upgrading FreeBSD
2.2.1. update
2.2.2. upgrade
2.2.3. update ports
2.3. ports
2.3.1. install
2.3.2. remove
2.3.3. config menu
2.4. PKGNG - Pkgng is the Next Generation package management tool for FreeBSD.
2.4.1. 安装 pkgng
2.4.2. 转换数据库
2.4.3. install
2.4.4. delete
2.4.5. info
2.4.6. query
2.4.7. upgrade

2.1. Using the Packages System

2.1.1. PACKAGESROOT / PKG_PATH 环境变量

setenv PACKAGESROOT ftp://ftp.freebsdchina.org
pkg_add -r libxml2 gmake autoconf262

export PKG_PATH=ftp://ftp.freebsd.org/pub/FreeBSD/8.2/packages/i386/
pkg_add mysql-server php5-fastcgi php5-gd-5.2.6-no_x11 lighttpd-1.4.19p3 nginx pecl-APC

2.1.2. Installing a Package

# pkg_add -r lsof

2.1.3. Managing Packages

# pkg_info
libiconv-1.13.1_1   A character set conversion library
libxml2-2.7.7       XML parser library for GNOME
lighttpd-1.4.26_3   A secure, fast, compliant, and very flexible Web Server
pcre-8.02           Perl Compatible Regular Expressions library
php5-5.3.2_1        PHP Scripting Language
pkg-config-0.23_1   A utility to retrieve information about installed libraries
spawn-fcgi-1.6.3    spawn-fcgi is used to spawn fastcgi applications

freebsd0# pkg_version
libiconv                            =
libxml2                             =
lighttpd                            =
pcre                                =
php5                                =
pkg-config                          =
spawn-fcgi                          =

#  pkg_version -v
libiconv-1.13.1_1                   =   up-to-date with port
libxml2-2.7.7                       =   up-to-date with port
lighttpd-1.4.26_3                   =   up-to-date with port
pcre-8.02                           =   up-to-date with port
php5-5.3.2_1                        =   up-to-date with port
php5-ctype-5.3.2_1                  =   up-to-date with port
php5-dom-5.3.2_1                    =   up-to-date with port
php5-extensions-1.4                 =   up-to-date with port
php5-filter-5.3.2_1                 =   up-to-date with port
php5-hash-5.3.2_1                   =   up-to-date with port
php5-iconv-5.3.2_1                  =   up-to-date with port
php5-json-5.3.2_1                   =   up-to-date with port
php5-pdo-5.3.2_1                    =   up-to-date with port
php5-pdo_sqlite-5.3.2_1             =   up-to-date with port
php5-posix-5.3.2_1                  =   up-to-date with port
php5-session-5.3.2_1                =   up-to-date with port
php5-simplexml-5.3.2_1              =   up-to-date with port
php5-sqlite-5.3.2_1                 =   up-to-date with port
php5-tokenizer-5.3.2_1              =   up-to-date with port
php5-xml-5.3.2_1                    =   up-to-date with port
php5-xmlreader-5.3.2_1              =   up-to-date with port
php5-xmlwriter-5.3.2_1              =   up-to-date with port
pkg-config-0.23_1                   =   up-to-date with port
spawn-fcgi-1.6.3                    =   up-to-date with port
sqlite3-3.6.23.1_1                  =   up-to-date with port

2.1.4. Deleting a Package

# pkg_delete php5-5.3.2_1


2.2. Updating and Upgrading FreeBSD

2.2.1. update

安全补丁

# freebsd-update fetch
# freebsd-update install

如果出现错误回滚

# freebsd-update rollback

freebsd# rehash
freebsd# freebsd-update fetch
Looking up update.FreeBSD.org mirrors... 3 mirrors found.
Fetching public key from update5.FreeBSD.org... done.
Fetching metadata signature for 8.0-RELEASE from update5.FreeBSD.org... done.
Fetching metadata index... done.
Fetching 2 metadata files... done.
Inspecting system... done.
Preparing to download files... done.
Fetching 35 patches.....10....20....30.. done.
Applying patches... done.

The following files will be updated as part of updating to 8.0-RELEASE-p3:
/boot/kernel/ip_mroute.ko
/boot/kernel/ip_mroute.ko.symbols
/boot/kernel/kernel
/boot/kernel/kernel.symbols
/boot/kernel/krpc.ko
/boot/kernel/krpc.ko.symbols
/boot/kernel/nfsclient.ko
/boot/kernel/nfsclient.ko.symbols
/boot/kernel/zfs.ko
/boot/kernel/zfs.ko.symbols
/etc/mtree/BSD.var.dist
/lib/libzpool.so.2
/libexec/ld-elf.so.1
/usr/bin/dig
/usr/bin/host
/usr/bin/nslookup
/usr/bin/nsupdate
/usr/lib/libopie.a
/usr/lib/libopie.so.6
/usr/lib/libssl.a
/usr/lib/libssl.so.6
/usr/lib/libzpool.a
/usr/sbin/dnssec-dsfromkey
/usr/sbin/dnssec-keyfromlabel
/usr/sbin/dnssec-keygen
/usr/sbin/dnssec-signzone
/usr/sbin/freebsd-update
/usr/sbin/jail
/usr/sbin/lwresd
/usr/sbin/named
/usr/sbin/named-checkconf
/usr/sbin/named-checkzone
/usr/sbin/named-compilezone
/usr/sbin/ntpd
/usr/sbin/rndc-confgen
/usr/share/man/man2/mount.2.gz
/usr/share/man/man2/nmount.2.gz
/usr/share/man/man2/unmount.2.gz
/var/db/freebsd-update
/var/db/mergemaster.mtree

freebsd# freebsd-update install
Installing updates... done.

2.2.2. upgrade

寻找版本

http://update5.freebsd.org/

升级至9.1-RELEASE

freebsd# freebsd-update upgrade -r 9.1-RELEASE

Looking up update.FreeBSD.org mirrors... 3 mirrors found.
Fetching metadata signature for 9.1-RC3 from update5.freebsd.org... done.
Fetching metadata index... done.
Fetching 1 metadata files... done.
Inspecting system... done.

The following components of FreeBSD seem to be installed:
kernel/generic world/base world/games world/lib32

The following components of FreeBSD do not seem to be installed:
src/src world/doc

Does this look reasonable (y/n)? y

Fetching metadata signature for 9.1-RELEASE from update5.freebsd.org... done.
Fetching metadata index... done.
Fetching 1 metadata patches. done.
Applying metadata patches... done.
Fetching 1 metadata files... done.
Inspecting system... done.
Fetching files from 9.1-RC3 for merging... done.
Preparing to download files...

freebsd# freebsd-update install

2.2.3. update ports

update your port tree by typing following commands:

# portsnap fetch
# portsnap update


2.3. ports

2.3.1. install

# cd /usr/ports/lang/php5
# make install

reinstall

# make reinstall

2.3.2. remove

# make deinstall

如果用make install clean 安装，请用 pkg_delete 卸载

2.3.3. config menu

# cd /usr/ports/lang/php5
# make config
# make install


2.4. PKGNG - Pkgng is the Next Generation package management tool for FreeBSD.

https://mebsd.com/make-build-your-freebsd-word/pkgng-first-look-at-freebsds-new-package-manager.html

http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/pkgng-intro.html

https://wiki.freebsd.org/pkgng

2.4.1. 安装 pkgng

方法一：

# /usr/sbin/pkg
The package management tool is not yet installed on your system.
Do you want to fetch and install it now? [y/N]: y
Bootstrapping pkg please wait
Installing pkg-1.0.11... done
If you are upgrading from the old package format, first run:

  # pkg2ng
usage: pkg [-v] [-d] [-j <jail name or id>|-c <chroot path>] <command> [<args>]

Global options supported:
    -d             Increment debug level
    -j             Execute pkg(1) inside a jail(8)
    -c             Execute pkg(1) inside a chroot(8)
    -v             Display pkg(1) version

Commands supported:
    add            Registers a package and installs it on the system
    audit          Reports vulnerable packages
    autoremove     Removes orphan packages
    backup         Backs-up and restores the local package database
    check          Checks for missing dependencies and database consistency
    clean          Cleans old packages from the cache
    create         Creates software package distributions
    delete         Deletes packages from the database and the system
    fetch          Fetches packages from a remote repository
    help           Displays help information
    info           Displays information about installed packages
    install        Installs packages from remote package repositories
    query          Queries information about installed packages
    register       Registers a package into the local database
    remove         Deletes packages from the database and the system
    repo           Creates a package repository catalogue
    rquery         Queries information in repository catalogues
    search         Performs a search of package repository catalogues
    set            Modifies information about packages in the local database
    shell          Opens a debug shell
    shlib          Displays which packages link against a specific shared library
    stats          Displays package database statistics
    update         Updates package repository catalogues
    updating       Displays UPDATING information for a package
    upgrade        Performs upgrades of packaged software distributions
    version        Displays the versions of installed packages
    which          Displays which package installed a specific file

For more information on the different commands see 'pkg help <command>'.

方法二：

# portsnap fetch update
# cd /usr/ports/ports-mgmt/pkg
# make
# make install clean

方法三

# pkg_add -r pkg

2.4.2. 转换数据库

运行 pkg2ng 命令

# pkg2ng

设置 make.conf 文件

cat >> /etc/make.conf <<EOF

WITH_PKGNG=yes
EOF

2.4.3. install

安装包

# pkg install curl

2.4.4. delete

删除包

# pkg delete curl

2.4.5. info

显示所有包信息

pkg info

显示包之间的依赖关系

# pkg info -d subversion
subversion-1.7.7 depends on:
expat-2.0.1_2
pkgconf-0.8.9
sqlite3-3.7.14.1
gdbm-1.9.1
db42-4.2.52_5
libiconv-1.14
gettext-0.18.1.1

显示包中的文件

# pkg info -l subversion
subversion-1.7.7 owns the following files:
/usr/local/bin/svn
/usr/local/bin/svnadmin
/usr/local/bin/svndumpfilter
/usr/local/bin/svnlook
/usr/local/bin/svnrdump
/usr/local/bin/svnserve
/usr/local/bin/svnsync
/usr/local/bin/svnversion
/usr/local/etc/rc.d/svnserve

2.4.6. query

# pkg query "Package name = %n, Version = %v, Size = %sh" libxml2
Package name = libxml2, Version = 2.7.8_5, Size = 4 MB

# pkg query -a "Package name = %n, Version = %v, Size = %sh"

# pkg query "\
    package[%n]\n\
    version[%v]\n\
    origin[%o]\n\
    prefix[%p]\n\
    maintainer[%m]\n\
    comment[%c]\n\
    www[%w]\n\
    licenselogic[%l]\n\
    flatsize[%sh]\n\
    flatsizebytes[%sb]\n\
    orphan[%a]\n\
    message[%M]\n\
" libxml2

typescript package[libxml2]

typescript version[2.7.8_5]

typescript origin[textproc/libxml2]

typescript prefix[/usr/local]

typescript maintainer[gnome@FreeBSD.org]

typescript comment[XML parser library for GNOME]

typescript www[http://xmlsoft.org/]

typescript licenselogic[single]

typescript flatsize[4 MB]

typescript flatsizebytes[4258960]

typescript orphan[0]

typescript message[]

2.4.7. upgrade

# pkg upgrade


第 3 章 编辑器 (editors)

目录

3.1. vim

3.1. vim

# pkg_add -r vim

# cd /usr/ports/editors/vim
# make install


第 4 章 terminal

目录

4.1. 分辨率
4.2. 屏幕保护
4.3. 键盘设置

4.1. 分辨率

使用下面的命令获得本机支持的显示模式

vidcontrol -i mode < /dev/ttyv0

root@netkiller:/root # vidcontrol -i mode < /dev/ttyv0
    mode#     flags   type    size       font      window      linear buffer
------------------------------------------------------------------------------
  0 (0x000) 0x00000001 T 40x25           8x8   0xb8000 32k 32k 0x00000000 32k
  1 (0x001) 0x00000001 T 40x25           8x8   0xb8000 32k 32k 0x00000000 32k
  2 (0x002) 0x00000001 T 80x25           8x8   0xb8000 32k 32k 0x00000000 32k
  3 (0x003) 0x00000001 T 80x25           8x8   0xb8000 32k 32k 0x00000000 32k
  4 (0x004) 0x00000003 G 320x200x2 C     8x8   0xb8000 32k 32k 0x00000000 32k
  5 (0x005) 0x00000003 G 320x200x2 C     8x8   0xb8000 32k 32k 0x00000000 32k
  6 (0x006) 0x00000003 G 640x200x1 C     8x8   0xb8000 32k 32k 0x00000000 32k
 13 (0x00d) 0x00000003 G 320x200x4 4     8x8   0xa0000 64k 64k 0x00000000 256k
 14 (0x00e) 0x00000003 G 640x200x4 4     8x8   0xa0000 64k 64k 0x00000000 256k
 16 (0x010) 0x00000003 G 640x350x2 2     8x14  0xa0000 64k 64k 0x00000000 128k
 18 (0x012) 0x00000003 G 640x350x4 4     8x14  0xa0000 64k 64k 0x00000000 256k
 19 (0x013) 0x00000001 T 40x25           8x14  0xb8000 32k 32k 0x00000000 32k
 20 (0x014) 0x00000001 T 40x25           8x14  0xb8000 32k 32k 0x00000000 32k
 21 (0x015) 0x00000001 T 80x25           8x14  0xb8000 32k 32k 0x00000000 32k
 22 (0x016) 0x00000001 T 80x25           8x14  0xb8000 32k 32k 0x00000000 32k
 23 (0x017) 0x00000001 T 40x25           8x16  0xb8000 32k 32k 0x00000000 32k
 24 (0x018) 0x00000001 T 80x25           8x16  0xb8000 32k 32k 0x00000000 32k
 26 (0x01a) 0x00000003 G 640x480x4 4     8x16  0xa0000 64k 64k 0x00000000 256k
 27 (0x01b) 0x00000003 G 640x480x4 4     8x16  0xa0000 64k 64k 0x00000000 256k
 28 (0x01c) 0x00000003 G 320x200x8 P     8x8   0xa0000 64k 64k 0x00000000 64k
 30 (0x01e) 0x00000001 T 80x50           8x8   0xb8000 32k 32k 0x00000000 32k
 32 (0x020) 0x00000001 T 80x30           8x16  0xb8000 32k 32k 0x00000000 32k
 34 (0x022) 0x00000001 T 80x60           8x8   0xb8000 32k 32k 0x00000000 32k
 37 (0x025) 0x00000003 G 320x240x8 V     8x8   0xa0000 64k 64k 0x00000000 256k
112 (0x070) 0x00000000 T 80x43           8x8   0xb8000 32k 32k 0x00000000 32k
113 (0x071) 0x00000001 T 80x43           8x8   0xb8000 32k 32k 0x00000000 32k
257 (0x101) 0x0000000f G 640x480x8 P     8x16  0xa0000 64k 64k 0x80000000 300k
259 (0x103) 0x0000000f G 800x600x8 P     8x16  0xa0000 64k 64k 0x80000000 487k
261 (0x105) 0x0000000f G 1024x768x8 P    8x16  0xa0000 64k 64k 0x80000000 768k
273 (0x111) 0x0000000f G 640x480x16 D    8x16  0xa0000 64k 64k 0x80000000 600k
274 (0x112) 0x0000000f G 640x480x32 D    8x16  0xa0000 64k 64k 0x80000000 1200k
276 (0x114) 0x0000000f G 800x600x16 D    8x16  0xa0000 64k 64k 0x80000000 937k
277 (0x115) 0x0000000f G 800x600x32 D    8x16  0xa0000 64k 64k 0x80000000 1875k
279 (0x117) 0x0000000f G 1024x768x16 D   8x16  0xa0000 64k 64k 0x80000000 1536k
280 (0x118) 0x0000000f G 1024x768x32 D   8x16  0xa0000 64k 64k 0x80000000 3072k

使用下面命令改变当前屏幕的分辨率 280 为 1024x768x32

# vidcontrol MODE_280

启动时生效，就在 /etc/rc.conf 加入

allscreens_flags="MODE_280"


4.2. 屏幕保护

方法一，编辑 /etc/rc.conf 文件加入

blanktime=”60″
saver=”daemon”

方法二，sysinstall

选择
Configure——Console——Saver—–Timeout（设置屏保时间60秒）
在选则 Daemon

屏保文件

# ls /boot/kernel/*saver* | grep -v symbols
/boot/kernel/beastie_saver.ko
/boot/kernel/blank_saver.ko
/boot/kernel/daemon_saver.ko
/boot/kernel/dragon_saver.ko
/boot/kernel/fade_saver.ko
/boot/kernel/fire_saver.ko
/boot/kernel/green_saver.ko
/boot/kernel/logo_saver.ko
/boot/kernel/rain_saver.ko
/boot/kernel/snake_saver.ko
/boot/kernel/star_saver.ko
/boot/kernel/warp_saver.ko

屏保预览

# kldload logo_saver
# kldload fire_saver
# kldload rain_saver

kldload 不能重复运行，已经载入的屏保不能再重新载入，使用下面命令查看详情。

# kldstat
Id Refs Address            Size     Name
 1   22 0xffffffff80200000 1323388  kernel
 5    1 0xffffffff81612000 861      snake_saver.ko
 6    1 0xffffffff81613000 a2d      fire_saver.ko
 7    1 0xffffffff81614000 e89      dragon_saver.ko
 8    1 0xffffffff81615000 11ad     daemon_saver.ko
 9    1 0xffffffff81617000 4dd      star_saver.ko
10    1 0xffffffff81618000 9cd      rain_saver.ko
11    1 0xffffffff81619000 c4d      warp_saver.ko


4.3. 键盘设置

使用linux的用户转到BSD很不适应终端键盘设置

bindkey "^[[1~" beginning-of-line
bindkey "^[[4~" end-of-line
bindkey "^[[3~" delete-char


第 5 章 FreeBSD 开机启动

目录

5.1. /etc/rc.conf

将开机运行脚本写入

/etc/rc.local

将关机前运行脚本写入

/etc/rc.shutdown.local

测试

/etc/rc.d/local start
/etc/rc.d/local stop

5.1. /etc/rc.conf

修改 /etc/rc.conf 生效

sh /etc/rc


第 6 章 Date

# date -v -1d +%Y%m%d
20060326
# date -v -1m +%Y%m%d
20060227
# date -v -1y +%Y%m%d
20050327


第 7 章 shell

目录

7.1. Bash
7.2. zsh
7.2.1. 初始化 zsh
7.2.2. prompt

7.1. Bash

install bash

freebsd# cd /usr/ports/shells/bash
freebsd# make install clean

change shell

$ chsh -s /usr/local/bin/bash
Password:
chsh: user information updated
$ exit


7.2. zsh

freebsd# pkg_add -r zsh
freebsd# chsh -s /usr/local/bin/zsh

7.2.1. 初始化 zsh

# compinstall -Uz compinit
# compinit
# compinstall

7.2.2. prompt

zsh prompt colors:

autoload colors; colors
export PS1="%B[%{$fg[red]%}%n%{$reset_color%}%b@%B%{$fg[cyan]%}%m%b%{$reset_color%}:%~%B]%b "


第 8 章 Users and Basic Account Management

目录

8.1. 添加用户
8.2. 删除用户
8.3. 修改用户信息
8.4. su - root
8.5. profile
8.5.1. shell
8.5.2. Changing user information
8.6. passwd file

8.1. 添加用户

# pw useradd www
# passwd www

添加新用户jerry并允许他su到root用户

# pw useradd jerry -G wheel
# passwd jerry

# pw useradd -n tom -s /bin/csh -m
# passwd tom


8.2. 删除用户

rmuser 命令

root@freebsd:~ # pw adduser test
root@freebsd:~ # rmuser test
Matching password entry:

test:*:1002:1002::0:0:User :/home/test:/bin/sh

Is this the entry you wish to remove? y
Remove user's home directory (/home/test)? y
Removing user (test): mailspool home passwd.

pw userdel 命令

root@freebsd:~ # pw adduser test
root@freebsd:~ # pw userdel test

# pw userdel -n tom -r


8.3. 修改用户信息

root@freebsd:~ # chpass neo
#Changing user information for neo.
Login: neo
Password: $6$d9faZkqxd3xQ5AqB$hqAXYv4xbZKz11AHqrva8WoCDstruFmqW2d3Lhzu.9s36tuAiqVfOaNSy9mDFP5I.VaKWhQUjUEgiXF183uVm0
Uid [#]: 1001
Gid [# or name]: 1001
Change [month day year]:
Expire [month day year]:
Class:
Home directory: /home/neo
Shell: /bin/sh
Full Name: neo chen
Office Location:
Office Phone:
Home Phone:
Other information:


8.4. su - root

add a user to wheel group

root@freebsd:~ # pw usermod neo -G wheel
root@freebsd:~ # id neo
uid=1001(neo) gid=1001(neo) groups=1001(neo),0(wheel)

freebsd# grep 'wheel' /etc/group
wheel:*:0:root,neo


8.5. profile

8.5.1. shell

Finally, change your account to use zsh as your default shell
FreeBSD users:
# chpass -s /usr/local/bin/zsh

8.5.2. Changing user information

#Changing user information for neo.
Shell: /usr/local/bin/zsh
Full Name: Neo Chen
Office Location:
Office Phone:
Home Phone:
Other information:


8.6. passwd file

freebsd 不能直接改/etc/passwd 需要使用 vipw，否则不生效
# vipw


第 9 章 Network

目录

9.1. DHCP
9.2. IP Address
9.3. alias
9.4. Default Gateway
9.5. DNS
9.6. netstart
9.7. Route
vi /etc/rc.conf

9.1. DHCP

hostname="freebse.example.com"
ifconfig_em0="DHCP"


9.2. IP Address

hostname="freebse.example.com"
ifconfig_em0="inet 192.168.3.71  netmask 255.255.255.0"
defaultrouter="192.168.3.1"


9.3. alias

[root@freebsd0:~] ifconfig bce0 alias 172.16.1.81 netmask 255.255.255.0
[root@freebsd0:~] ifconfig bce0
bce0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
        options=c01bb<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,JUMBO_MTU,VLAN_HWCSUM,TSO4,VLAN_HWTSO,LINKSTATE>
        ether 00:22:19:5f:52:0b
        inet 172.16.1.27 netmask 0xffffff00 broadcast 172.16.1.255
        inet 172.16.1.81 netmask 0xffffff00 broadcast 172.16.1.255
        media: Ethernet autoselect (100baseTX <full-duplex>)
        status: active

vim /etc/rc.conf
ifconfig_bce0_alias0="inet 172.16.1.81 netmask 255.255.255.0"


9.4. Default Gateway

defaultrouter="192.168.3.1"


9.5. DNS

freebse# cat /etc/resolv.conf
domain  example.com
nameserver      202.96.134.133


9.6. netstart

restart network

/etc/netstart


9.7. Route

route table

netstat -nr

Default Routes

freebsd# route add  default 172.16.0.254
add net default: gateway 172.16.0.254

添加静态路由

route add 172.16.3.0/24 172.16.1.240

编辑/etc/rc.conf使上面命令开机时执行

static_routes="static1"
route_static1="-net 172.16.3.0/24 172.16.1.240"


第 10 章 Debug

目录

10.1. lsof - list open files

10.1. lsof - list open files

[root@freebsd:~] pkg_add -r lsof
Fetching ftp://ftp.freebsd.org/pub/FreeBSD/ports/amd64/packages-8.1-release/Latest/lsof.tbz... Done.


部分 II. File System

目录

11. Windows 文件系统
11.1. msdos/fat16 文件系统
11.1.1. 分区格式化
11.1.2. 挂载 msdoc 分区
12. ZFS
12.1. 初始化
12.2. Creating a Basic Filesystem
12.3. Creating a Storage Pool
12.3.1. Mirrored Pool
12.3.2. RAID-Z Pool
12.3.3. Querying Pool Status
12.3.4. Destroying Pools
12.4. Creating a Filesystem Hierarchy
12.4.1. Creating a Filesystem
12.4.2. Setting Quotas
12.4.3. Setting Reservations
12.4.4. Querying Filesystem Information
12.4.5. Renaming a Filesystem
12.4.6. Destroying a Filesystem
12.5. zfs mount/umount
12.5.1. Temporary Mount Properties
12.5.2. Mounting File Systems
12.5.3. Unmounting File Systems
12.5.4. Legacy Mount Points
12.6. Sharing ZFS File Systems
12.6.1. Controlling Share Semantics
12.6.2. Unsharing Filesystems
12.6.3. Sharing Filesystems
12.7. Device Management
12.7.1. Adding Devices to a Pool
12.7.2. Onlining and Offlining Devices
12.7.2.1. Taking a Device Offline
12.7.2.2. Bringing a Device Online
12.7.3. Replacing Devices
12.8. I/O Statistics
12.8.1. Virtual Device Statistics
12.9. Health Status
12.9.1. Basic Health Status
12.9.2. Detailed Health Status
12.10. Storage Pool Migration
12.10.1. Exporting a Pool
12.10.2. Importing Pools
12.11. Querying Properties
12.12. Backing Up and Restoring ZFS Data
12.12.1. Backing Up a ZFS Snapshot
12.12.2. Restoring a ZFS Snapshot
12.12.3. Remote Replication of a ZFS File System
12.13. ZFS Snapshots and Clones
12.13.1. ZFS Snapshots
12.13.1.1. Creating ZFS Snapshots
12.13.1.2. Destroying ZFS Snapshots
12.13.1.3. Renaming ZFS Snapshots
12.13.1.4. Displaying and Accessing ZFS Snapshots
12.13.1.5. Rolling Back to a Snapshot
12.13.2. ZFS Clones
12.13.2.1. Creating a Clone
12.13.2.2. Destroying a Clone
12.14. Emulated Volumes


第 11 章 Windows 文件系统

目录

11.1. msdos/fat16 文件系统
11.1.1. 分区格式化
11.1.2. 挂载 msdoc 分区

11.1. msdos/fat16 文件系统

11.1.1. 分区格式化

进入 sysinstall 给硬盘分区

sysinstall - confgure - fdisk

格式化分区

newfs_msdos /dev/da0s1

11.1.2. 挂载 msdoc 分区

mount -t msdos /dev/da0s1 /mnt

mount_msdosfs /dev/da0s1 /mnt


第 12 章 ZFS

目录

12.1. 初始化
12.2. Creating a Basic Filesystem
12.3. Creating a Storage Pool
12.3.1. Mirrored Pool
12.3.2. RAID-Z Pool
12.3.3. Querying Pool Status
12.3.4. Destroying Pools
12.4. Creating a Filesystem Hierarchy
12.4.1. Creating a Filesystem
12.4.2. Setting Quotas
12.4.3. Setting Reservations
12.4.4. Querying Filesystem Information
12.4.5. Renaming a Filesystem
12.4.6. Destroying a Filesystem
12.5. zfs mount/umount
12.5.1. Temporary Mount Properties
12.5.2. Mounting File Systems
12.5.3. Unmounting File Systems
12.5.4. Legacy Mount Points
12.6. Sharing ZFS File Systems
12.6.1. Controlling Share Semantics
12.6.2. Unsharing Filesystems
12.6.3. Sharing Filesystems
12.7. Device Management
12.7.1. Adding Devices to a Pool
12.7.2. Onlining and Offlining Devices
12.7.2.1. Taking a Device Offline
12.7.2.2. Bringing a Device Online
12.7.3. Replacing Devices
12.8. I/O Statistics
12.8.1. Virtual Device Statistics
12.9. Health Status
12.9.1. Basic Health Status
12.9.2. Detailed Health Status
12.10. Storage Pool Migration
12.10.1. Exporting a Pool
12.10.2. Importing Pools
12.11. Querying Properties
12.12. Backing Up and Restoring ZFS Data
12.12.1. Backing Up a ZFS Snapshot
12.12.2. Restoring a ZFS Snapshot
12.12.3. Remote Replication of a ZFS File System
12.13. ZFS Snapshots and Clones
12.13.1. ZFS Snapshots
12.13.1.1. Creating ZFS Snapshots
12.13.1.2. Destroying ZFS Snapshots
12.13.1.3. Renaming ZFS Snapshots
12.13.1.4. Displaying and Accessing ZFS Snapshots
12.13.1.5. Rolling Back to a Snapshot
12.13.2. ZFS Clones
12.13.2.1. Creating a Clone
12.13.2.2. Destroying a Clone
12.14. Emulated Volumes

12.1. 初始化

echo "zfs_enable=YES" >> /etc/rc.conf
echo 'daily_status_zfs_enable="YES"' >> /etc/periodic.conf

freebsd# vi /etc/rc.conf
zfs_enable="YES"

freebsd# /etc/rc.d/zfs faststart


12.2. Creating a Basic Filesystem

# zpool create tank c0t0d0
# zfs create tank/fs

# mkfile 100m /tank/fs/foo
# df -h /tank/fs
Filesystem             size   used  avail capacity  Mounted on
tank/fs                 80G   100M    80G     1%    /tank/fs

# zpool create tank c0t0d0 c1t0d0


12.3. Creating a Storage Pool

12.3.1. Mirrored Pool

# zpool create tank mirror c0t0d0 c0t0d1
freebsd# zpool create tank mirror ad1 ad3
freebsd# zpool status tank
  pool: tank
 state: ONLINE
 scrub: none requested
config:

        NAME        STATE     READ WRITE CKSUM
        tank        ONLINE       0     0     0
          mirror    ONLINE       0     0     0
            ad1     ONLINE       0     0     0
            ad3     ONLINE       0     0     0

errors: No known data errors

12.3.2. RAID-Z Pool

freebsd# zpool create zfs raidz ad1 ad3
freebsd# zpool status zfs
  pool: zfs
 state: ONLINE
 scrub: none requested
config:

        NAME        STATE     READ WRITE CKSUM
        zfs         ONLINE       0     0     0
          raidz1    ONLINE       0     0     0
            ad1     ONLINE       0     0     0
            ad3     ONLINE       0     0     0

errors: No known data errors

12.3.3. Querying Pool Status

You can see that your pool was successfully created by using the zpool list command:

freebsd# zpool list
NAME   SIZE   USED  AVAIL    CAP  HEALTH  ALTROOT
zfs   3.97G   234K  3.97G     0%  ONLINE  -

12.3.4. Destroying Pools

Pools are destroyed by using the zpool destroy command. This command destroys the pool even if it contains mounted datasets.

# zpool destroy tank

Destroying a Pool With Faulted Devices

# zpool destroy tank
cannot destroy 'tank': pool is faulted
use '-f' to force destruction anyway
# zpool destroy -f tank


12.4. Creating a Filesystem Hierarchy

12.4.1. Creating a Filesystem

freebsd# zfs create zfs/www
freebsd# mount
/dev/ad0s1a on / (ufs, local)
devfs on /dev (devfs, local, multilabel)
/dev/ad0s1e on /tmp (ufs, local, soft-updates)
/dev/ad0s1f on /usr (ufs, local, soft-updates)
/dev/ad0s1d on /var (ufs, local, soft-updates)
zfs on /zfs (zfs, local)
zfs/www on /zfs/www (zfs, local)

freebsd# zfs set compression=gzip zfs/www

12.4.2. Setting Quotas

we want to give bonwick a quota of 10 Gbytes

# zfs set quota=10G tank/home/bonwick

12.4.3. Setting Reservations

# zfs set reservation=5G tank/home/moore
# zfs get reservation tank/home/moore
NAME             PROPERTY      VALUE                      SOURCE
tank/home/moore  reservation   5.00G                      local

12.4.4. Querying Filesystem Information

freebsd# zfs list
NAME       USED  AVAIL  REFER  MOUNTPOINT
tank      97.5K  1.95G    18K  /tank
tank/neo    18K  1.95G    18K  /tank/neo

12.4.5. Renaming a Filesystem

# zfs rename tank/home/maybee tank/ws/maybee

12.4.6. Destroying a Filesystem

# zfs destroy tank/home/tabriz

# zfs destroy tank/home/ahrens
cannot unmount 'tank/home/ahrens': Device busy

# zfs destroy -f tank/home/ahrens

# zfs destroy -r tank/home/schrock
cannot destroy 'tank/home/schrock': filesystem has dependant clones
use '-R' to destroy the following datasets:
tank/clones/schrock-clone

# zfs destroy -R tank/home/schrock


12.5. zfs mount/umount

Legacy mount points must be managed through legacy tools. An attempt to use ZFS tools result in an error.

# zfs mount pool/home/billm
cannot mount 'pool/home/billm': legacy mountpoint
use mount(1M) to mount this filesystem
# mount -F zfs tank/home/billm

12.5.1. Temporary Mount Properties

# zfs mount -o ro tank/home/perrin
# zfs mount -o remount,noatime tank/home/perrin
# zfs get atime tank/home/perrin
NAME             PROPERTY      VALUE                      SOURCE
tank/home/perrin atime         off                        temporary

12.5.2. Mounting File Systems

mount

freebsd# zfs mount zfs/www
freebsd# mount
/dev/ad0s1a on / (ufs, local)
devfs on /dev (devfs, local, multilabel)
/dev/ad0s1e on /tmp (ufs, local, soft-updates)
/dev/ad0s1f on /usr (ufs, local, soft-updates)
/dev/ad0s1d on /var (ufs, local, soft-updates)
zfs on /zfs (zfs, local)
zfs/www on /zfs/www (zfs, local)

The -a option can be used to mount all ZFS managed filesystems. Legacy managed filesystems are not mounted.

# zfs mount -a

12.5.3. Unmounting File Systems

umount

freebsd# zfs umount /zfs/www
freebsd# mount
/dev/ad0s1a on / (ufs, local)
devfs on /dev (devfs, local, multilabel)
/dev/ad0s1e on /tmp (ufs, local, soft-updates)
/dev/ad0s1f on /usr (ufs, local, soft-updates)
/dev/ad0s1d on /var (ufs, local, soft-updates)
zfs on /zfs (zfs, local)

12.5.4. Legacy Mount Points

freebsd# zfs set mountpoint=/tank  tank
freebsd# zfs mount -a
freebsd# mount
/dev/ad0s1a on / (ufs, local)
devfs on /dev (devfs, local, multilabel)
/dev/ad0s1e on /tmp (ufs, local, soft-updates)
/dev/ad0s1f on /usr (ufs, local, soft-updates)
/dev/ad0s1d on /var (ufs, local, soft-updates)
tank on /tank (zfs, local)


12.6. Sharing ZFS File Systems

12.6.1. Controlling Share Semantics

freebsd# zfs set sharenfs=on zfs/www

12.6.2. Unsharing Filesystems

freebsd# zfs unshare zfs/www

This command unshares the zpool filesystem. To unshare all ZFS filesystems on the system, run:

freebsd# zfs unshare -a

12.6.3. Sharing Filesystems

freebsd# zfs share zfs/www

You can also share all ZFS filesystems on the system:

# zfs share -a


12.7. Device Management

12.7.1. Adding Devices to a Pool

# zpool add scoop mirror c0t1d0 c1t1d0

12.7.2. Onlining and Offlining Devices

12.7.2.1. Taking a Device Offline

# zpool offline tank c0t0d0
bringing device 'c0t0d0' offline

12.7.2.2. Bringing a Device Online

# zpool online tank c0t0d0
bringing device 'c0t0d0' online

12.7.3. Replacing Devices

You can replace a device in a storage pool by using the zpool replace command.

# zpool replace tank c0t0d0 c0t0d1

In the above example, the previous device, c0t0d0, is replaced by c0t0d1.


12.8. I/O Statistics

freebsd# zpool iostat
               capacity     operations    bandwidth
pool         used  avail   read  write   read  write
----------  -----  -----  -----  -----  -----  -----
tank        73.5K  1.98G      0      2    119  2.10K

freebsd# zpool iostat
               capacity     operations    bandwidth
pool         used  avail   read  write   read  write
----------  -----  -----  -----  -----  -----  -----
tank        73.5K  1.98G      0      2    119  2.10K
freebsd# zpool iostat tank 2
               capacity     operations    bandwidth
pool         used  avail   read  write   read  write
----------  -----  -----  -----  -----  -----  -----
tank        73.5K  1.98G      0      1     84  1.48K
tank        73.5K  1.98G      0      0      0      0
tank        73.5K  1.98G      0      0      0      0
tank        73.5K  1.98G      0      0      0      0
tank        73.5K  1.98G      0      0      0      0
tank        73.5K  1.98G      0      0      0      0
tank        73.5K  1.98G      0      0      0      0
tank        73.5K  1.98G      0      0      0      0
tank        73.5K  1.98G      0      0      0      0
tank        73.5K  1.98G      0      0      0      0
tank        73.5K  1.98G      0      0      0      0
tank        73.5K  1.98G      0      0      0      0
tank        73.5K  1.98G      0      0      0      0

12.8.1. Virtual Device Statistics

freebsd# zpool iostat -v
               capacity     operations    bandwidth
pool         used  avail   read  write   read  write
----------  -----  -----  -----  -----  -----  -----
tank        73.5K  1.98G      0      0     45    824
  mirror    73.5K  1.98G      0      0     45    824
    ad1         -      -      0      0  1.12K  9.04K
    ad3         -      -      0      0    778  9.04K
----------  -----  -----  -----  -----  -----  -----

freebsd# zpool iostat -v tank 5
               capacity     operations    bandwidth
pool         used  avail   read  write   read  write
----------  -----  -----  -----  -----  -----  -----
tank         124K  1.98G      0      0     12    367
  mirror     124K  1.98G      0      0     12    367
    ad1         -      -      0      0    297    773
    ad3         -      -      0      0    270    773
----------  -----  -----  -----  -----  -----  -----

               capacity     operations    bandwidth
pool         used  avail   read  write   read  write
----------  -----  -----  -----  -----  -----  -----
tank         124K  1.98G      0      0      0      0
  mirror     124K  1.98G      0      0      0      0
    ad1         -      -      0      0      0      0
    ad3         -      -      0      0      0      0
----------  -----  -----  -----  -----  -----  -----


12.9. Health Status

12.9.1. Basic Health Status

freebsd# zpool status -x
all pools are healthy
freebsd#

12.9.2. Detailed Health Status

freebsd# zpool status -x
all pools are healthy
freebsd# zpool status -v tank
  pool: tank
 state: ONLINE
 scrub: none requested
config:

        NAME        STATE     READ WRITE CKSUM
        tank        ONLINE       0     0     0
          mirror    ONLINE       0     0     0
            ad1     ONLINE       0     0     0
            ad3     ONLINE       0     0     0

errors: No known data errors


12.10. Storage Pool Migration

12.10.1. Exporting a Pool

# zpool export tank

# zpool export tank
cannot unmount '/export/home/eschrock': Device busy
# zpool export -f tank

12.10.2. Importing Pools

# zpool import tank


12.11. Querying Properties

freebsd# zfs get all tank
NAME  PROPERTY              VALUE                  SOURCE
tank  type                  filesystem             -
tank  creation              Sat Jun 19 17:49 2010  -
tank  used                  98.5K                  -
tank  available             1.95G                  -
tank  referenced            19K                    -
tank  compressratio         1.00x                  -
tank  mounted               yes                    -
tank  quota                 none                   default
tank  reservation           none                   default
tank  recordsize            128K                   default
tank  mountpoint            /tank                  default
tank  sharenfs              off                    default
tank  checksum              on                     default
tank  compression           off                    default
tank  atime                 on                     default
tank  devices               on                     default
tank  exec                  on                     default
tank  setuid                on                     default
tank  readonly              off                    default
tank  jailed                off                    default
tank  snapdir               hidden                 default
tank  aclmode               groupmask              default
tank  aclinherit            restricted             default
tank  canmount              on                     default
tank  shareiscsi            off                    default
tank  xattr                 off                    temporary
tank  copies                1                      default
tank  version               3                      -
tank  utf8only              off                    -
tank  normalization         none                   -
tank  casesensitivity       sensitive              -
tank  vscan                 off                    default
tank  nbmand                off                    default
tank  sharesmb              off                    default
tank  refquota              none                   default
tank  refreservation        none                   default
tank  primarycache          all                    default
tank  secondarycache        all                    default
tank  usedbysnapshots       0                      -
tank  usedbydataset         19K                    -
tank  usedbychildren        79.5K                  -
tank  usedbyrefreservation  0                      -


12.12. Backing Up and Restoring ZFS Data

12.12.1. Backing Up a ZFS Snapshot

# zfs backup tank/dana@111505 > /dev/rmt/0

# zfs backup pool/fs@snap | gzip > backupfile.gz

12.12.2. Restoring a ZFS Snapshot

# zfs backup tank/gozer@111105 > /dev/rmt/0
.
.
.
# zfs restore tank/gozer2@today < /dev/rmt/0
# zfs rename tank/gozer tank/gozer.old
# zfs rename tank/gozer2 tank/gozer

# zfs rollback tank/dana@111505
cannot rollback to 'tank/dana@111505': more recent snapshots exist
use '-r' to force deletion of the following snapshots:
tank/dana@now
# zfs rollback -r tank/dana@111505
# zfs restore tank/dana < /dev/rmt/0

12.12.3. Remote Replication of a ZFS File System

# zfs backup tank/neo@today | ssh newsys zfs restore sandbox/restfs@today


12.13. ZFS Snapshots and Clones

12.13.1. ZFS Snapshots

filesystem@snapname, volume@snapname

12.13.1.1. Creating ZFS Snapshots

The following example creates a snapshot of tank/neo that is named friday.

freebsd# zfs snapshot tank/neo@friday

12.13.1.2. Destroying ZFS Snapshots

Snapshots are destroyed by using the zfs destroy command.

# zfs destroy tank/home/ahrens@friday

12.13.1.3. Renaming ZFS Snapshots

# zfs rename tank/home/cindys@111205 pool/home/cindys@today

12.13.1.4. Displaying and Accessing ZFS Snapshots

freebsd# zfs list -t snapshot
NAME              USED  AVAIL  REFER  MOUNTPOINT
tank/neo@friday      0      -    18K  -

12.13.1.5. Rolling Back to a Snapshot

# zfs rollback pool/home/ahrens@tuesday
cannot rollback to 'pool/home/ahrens@tuesday': more recent snapshots exist
use '-r' to force deletion of the following snapshots:
pool/home/ahrens@wednesday
pool/home/ahrens@thursday
# zfs rollback -r pool/home/ahrens@tuesday

12.13.2. ZFS Clones

12.13.2.1. Creating a Clone

# zfs clone pool/ws/gate@yesterday pool/home/ahrens/bug123

# zfs snapshot projects/newproject@today
# zfs clone projects/newproject@today projects/teamA/tempuser
# zfs set sharenfs=on projects/teamA/tempuser
# zfs set quota=5G projects/teamA/tempuser

12.13.2.2. Destroying a Clone

ZFS clones are destroyed with the zfs destroy command.

# zfs destroy pool/home/ahrens/bug123

Clones must be destroyed before the parent snapshot can be destroyed.


12.14. Emulated Volumes

# zfs create -V 5gb tank/vol


第 13 章 Network Communication

目录

13.1. wget
13.2. rsync
13.2.1. rsyncd.conf
13.3. curl
13.4. NTPD
13.5. SNMP
13.6. Network Manager
13.6.1. ntop

13.1. wget

freebsd1# pkg_add -r wget


13.2. rsync

pkg_add -r rsync

# cd /usr/ports/net/rsync
# make install clean

13.2.1. rsyncd.conf

/usr/local/etc/rsyncd.conf

/usr/local/etc/rc.d/rsyncd start
Starting rsyncd.

sockstat | grep rsync
root     rsync      60491 3  dgram  -> /var/run/logpriv
root     rsync      60491 4  tcp6   *:873                 *:*
root     rsync      60491 5  tcp4   *:873                 *:*

#vi /etc/rc.conf //加入以下内容

rsyncd_enable="YES"


13.3. curl


13.4. NTPD

FreeBSD NTPD

ntpd_enable="YES"
ntpdate_enable="YES"


13.5. SNMP

cd /usr/ports/net-mgmt/net-snmp
make install

pkg_add -r net-snmp

cp /usr/local/share/snmp/snmpd.conf.example /usr/local/etc/snmp/snmpd.conf

vim /etc/rc.conf

snmpd_enable="YES"
snmpd_flags="-a"
snmpd_conffile="/usr/local/etc/snmp/snmpd.conf"
snmptrapd_enable="YES"
snmptrapd_flags="-a -p /var/run/snmptrapd.pid"

###############################################################################
#
# snmpd.conf:
#   An example configuration file for configuring the ucd-snmp snmpd agent.
#
###############################################################################
#
# This file is intended to only be as a starting point.  Many more
# configuration directives exist than are mentioned in this file.  For
# full details, see the snmpd.conf(5) manual page.
#
# All lines beginning with a '#' are comments and are intended for you
# to read.  All other lines are configuration commands for the agent.

###############################################################################
# Access Control
###############################################################################

# As shipped, the snmpd demon will only respond to queries on the
# system mib group until this file is replaced or modified for
# security purposes.  Examples are shown below about how to increase the
# level of access.

# By far, the most common question I get about the agent is "why won't
# it work?", when really it should be "how do I configure the agent to
# allow me to access it?"
#
# By default, the agent responds to the "public" community for read
# only access, if run out of the box without any configuration file in
# place.  The following examples show you other ways of configuring
# the agent so that you can change the community names, and give
# yourself write access to the mib tree as well.
#
# For more information, read the FAQ as well as the snmpd.conf(5)
# manual page.

####
# First, map the community name "public" into a "security name"

#       sec.name  source          community
com2sec notConfigUser  default       public

####
# Second, map the security name into a group name:

#       groupName      securityModel securityName
group   notConfigGroup v1           notConfigUser
group   notConfigGroup v2c           notConfigUser

####
# Third, create a view for us to let the group have rights to:

# Make at least  snmpwalk -v 1 localhost -c public system fast again.
#       name           incl/excl     subtree         mask(optional)
view    systemview    included   .1.3.6.1.2.1.1
view    systemview    included   .1.3.6.1.2.1.25.1.1

####
# Finally, grant the group read-only access to the systemview view.

#       group          context sec.model sec.level prefix read   write  notif
#access  notConfigGroup ""      any       noauth    exact  systemview none none
access  notConfigGroup ""      any       noauth    exact  all none none

# -----------------------------------------------------------------------------

# Here is a commented out example configuration that allows less
# restrictive access.

# YOU SHOULD CHANGE THE "COMMUNITY" TOKEN BELOW TO A NEW KEYWORD ONLY
# KNOWN AT YOUR SITE.  YOU *MUST* CHANGE THE NETWORK TOKEN BELOW TO
# SOMETHING REFLECTING YOUR LOCAL NETWORK ADDRESS SPACE.

##       sec.name  source          community
#com2sec local     localhost       COMMUNITY
#com2sec mynetwork NETWORK/24      COMMUNITY

##     group.name sec.model  sec.name
#group MyRWGroup  any        local
#group MyROGroup  any        mynetwork
#
#group MyRWGroup  any        otherv3user
#...

##           incl/excl subtree                          mask
view all    included  .1                               80

## -or just the mib2 tree-

#view mib2   included  .iso.org.dod.internet.mgmt.mib-2 fc

##                context sec.model sec.level prefix read   write  notif
#access MyROGroup ""      any       noauth    0      all    none   none
#access MyRWGroup ""      any       noauth    0      all    all    all

###############################################################################
# Sample configuration to make net-snmpd RFC 1213.
# Unfortunately v1 and v2c don't allow any user based authentification, so
# opening up the default config is not an option from a security point.
#
# WARNING: If you uncomment the following lines you allow write access to your
# snmpd daemon from any source! To avoid this use different names for your
# community or split out the write access to a different community and
# restrict it to your local network.
# Also remember to comment the syslocation and syscontact parameters later as
# otherwise they are still read only (see FAQ for net-snmp).
#

# First, map the community name "public" into a "security name"
#       sec.name        source          community
#com2sec notConfigUser   default         public

# Second, map the security name into a group name:
#       groupName       securityModel   securityName
#group   notConfigGroup  v1              notConfigUser
#group   notConfigGroup  v2c             notConfigUser

# Third, create a view for us to let the group have rights to:
# Open up the whole tree for ro, make the RFC 1213 required ones rw.
#       name            incl/excl       subtree mask(optional)
#view    roview          included        .1
#view    rwview          included        system.sysContact
#view    rwview          included        system.sysName
#view    rwview          included        system.sysLocation
#view    rwview          included        interfaces.ifTable.ifEntry.ifAdminStatus
#view    rwview          included        at.atTable.atEntry.atPhysAddress
#view    rwview          included        at.atTable.atEntry.atNetAddress
#view    rwview          included        ip.ipForwarding
#view    rwview          included        ip.ipDefaultTTL
#view    rwview          included        ip.ipRouteTable.ipRouteEntry.ipRouteDest
#view    rwview          included        ip.ipRouteTable.ipRouteEntry.ipRouteIfIndex
#view    rwview          included        ip.ipRouteTable.ipRouteEntry.ipRouteMetric1
#view    rwview          included        ip.ipRouteTable.ipRouteEntry.ipRouteMetric2
#view    rwview          included        ip.ipRouteTable.ipRouteEntry.ipRouteMetric3
#view    rwview          included        ip.ipRouteTable.ipRouteEntry.ipRouteMetric4
#view    rwview          included        ip.ipRouteTable.ipRouteEntry.ipRouteType
#view    rwview          included        ip.ipRouteTable.ipRouteEntry.ipRouteAge
#view    rwview          included        ip.ipRouteTable.ipRouteEntry.ipRouteMask
#view    rwview          included        ip.ipRouteTable.ipRouteEntry.ipRouteMetric5
#view    rwview          included        ip.ipNetToMediaTable.ipNetToMediaEntry.ipNetToMediaIfIndex
#view    rwview          included        ip.ipNetToMediaTable.ipNetToMediaEntry.ipNetToMediaPhysAddress
#view    rwview          included        ip.ipNetToMediaTable.ipNetToMediaEntry.ipNetToMediaNetAddress
#view    rwview          included        ip.ipNetToMediaTable.ipNetToMediaEntry.ipNetToMediaType
#view    rwview          included        tcp.tcpConnTable.tcpConnEntry.tcpConnState
#view    rwview          included        egp.egpNeighTable.egpNeighEntry.egpNeighEventTrigger
#view    rwview          included        snmp.snmpEnableAuthenTraps

# Finally, grant the group read-only access to the systemview view.
#       group          context sec.model sec.level prefix read   write  notif
#access  notConfigGroup ""      any       noauth    exact  roview rwview none

###############################################################################
# System contact information
#

# It is also possible to set the sysContact and sysLocation system
# variables through the snmpd.conf file:

syslocation Unknown (edit /etc/snmp/snmpd.conf)
syscontact Root <root@localhost> (configure /etc/snmp/snmp.local.conf)

# Example output of snmpwalk:
#   % snmpwalk -v 1 localhost -c public system
#   system.sysDescr.0 = "SunOS name sun4c"
#   system.sysObjectID.0 = OID: enterprises.ucdavis.ucdSnmpAgent.sunos4
#   system.sysUpTime.0 = Timeticks: (595637548) 68 days, 22:32:55
#   system.sysContact.0 = "Me <me@somewhere.org>"
#   system.sysName.0 = "name"
#   system.sysLocation.0 = "Right here, right now."
#   system.sysServices.0 = 72

# -----------------------------------------------------------------------------

###############################################################################
# Process checks.
#
#  The following are examples of how to use the agent to check for
#  processes running on the host.  The syntax looks something like:
#
#  proc NAME [MAX=0] [MIN=0]
#
#  NAME:  the name of the process to check for.  It must match
#         exactly (ie, http will not find httpd processes).
#  MAX:   the maximum number allowed to be running.  Defaults to 0.
#  MIN:   the minimum number to be running.  Defaults to 0.

#
#  Examples (commented out by default):
#

#  Make sure mountd is running
#proc mountd

#  Make sure there are no more than 4 ntalkds running, but 0 is ok too.
#proc ntalkd 4

#  Make sure at least one sendmail, but less than or equal to 10 are running.
#proc sendmail 10 1

#  A snmpwalk of the process mib tree would look something like this:
#
# % snmpwalk -v 1 localhost -c public .1.3.6.1.4.1.2021.2
# enterprises.ucdavis.procTable.prEntry.prIndex.1 = 1
# enterprises.ucdavis.procTable.prEntry.prIndex.2 = 2
# enterprises.ucdavis.procTable.prEntry.prIndex.3 = 3
# enterprises.ucdavis.procTable.prEntry.prNames.1 = "mountd"
# enterprises.ucdavis.procTable.prEntry.prNames.2 = "ntalkd"
# enterprises.ucdavis.procTable.prEntry.prNames.3 = "sendmail"
# enterprises.ucdavis.procTable.prEntry.prMin.1 = 0
# enterprises.ucdavis.procTable.prEntry.prMin.2 = 0
# enterprises.ucdavis.procTable.prEntry.prMin.3 = 1
# enterprises.ucdavis.procTable.prEntry.prMax.1 = 0
# enterprises.ucdavis.procTable.prEntry.prMax.2 = 4
# enterprises.ucdavis.procTable.prEntry.prMax.3 = 10
# enterprises.ucdavis.procTable.prEntry.prCount.1 = 0
# enterprises.ucdavis.procTable.prEntry.prCount.2 = 0
# enterprises.ucdavis.procTable.prEntry.prCount.3 = 1
# enterprises.ucdavis.procTable.prEntry.prErrorFlag.1 = 1
# enterprises.ucdavis.procTable.prEntry.prErrorFlag.2 = 0
# enterprises.ucdavis.procTable.prEntry.prErrorFlag.3 = 0
# enterprises.ucdavis.procTable.prEntry.prErrMessage.1 = "No mountd process running."
# enterprises.ucdavis.procTable.prEntry.prErrMessage.2 = ""
# enterprises.ucdavis.procTable.prEntry.prErrMessage.3 = ""
# enterprises.ucdavis.procTable.prEntry.prErrFix.1 = 0
# enterprises.ucdavis.procTable.prEntry.prErrFix.2 = 0
# enterprises.ucdavis.procTable.prEntry.prErrFix.3 = 0
#
#  Note that the errorFlag for mountd is set to 1 because one is not
#  running (in this case an rpc.mountd is, but thats not good enough),
#  and the ErrMessage tells you what's wrong.  The configuration
#  imposed in the snmpd.conf file is also shown.
#
#  Special Case:  When the min and max numbers are both 0, it assumes
#  you want a max of infinity and a min of 1.
#

# -----------------------------------------------------------------------------

###############################################################################
# Executables/scripts
#

#
#  You can also have programs run by the agent that return a single
#  line of output and an exit code.  Here are two examples.
#
#  exec NAME PROGRAM [ARGS ...]
#
#  NAME:     A generic name.
#  PROGRAM:  The program to run.  Include the path!
#  ARGS:     optional arguments to be passed to the program

# a simple hello world

#exec echotest /bin/echo hello world

# Run a shell script containing:
#
# #!/bin/sh
# echo hello world
# echo hi there
# exit 35
#
# Note:  this has been specifically commented out to prevent
# accidental security holes due to someone else on your system writing
# a /tmp/shtest before you do.  Uncomment to use it.
#
#exec shelltest /bin/sh /tmp/shtest

# Then,
# % snmpwalk -v 1 localhost -c public .1.3.6.1.4.1.2021.8
# enterprises.ucdavis.extTable.extEntry.extIndex.1 = 1
# enterprises.ucdavis.extTable.extEntry.extIndex.2 = 2
# enterprises.ucdavis.extTable.extEntry.extNames.1 = "echotest"
# enterprises.ucdavis.extTable.extEntry.extNames.2 = "shelltest"
# enterprises.ucdavis.extTable.extEntry.extCommand.1 = "/bin/echo hello world"
# enterprises.ucdavis.extTable.extEntry.extCommand.2 = "/bin/sh /tmp/shtest"
# enterprises.ucdavis.extTable.extEntry.extResult.1 = 0
# enterprises.ucdavis.extTable.extEntry.extResult.2 = 35
# enterprises.ucdavis.extTable.extEntry.extOutput.1 = "hello world."
# enterprises.ucdavis.extTable.extEntry.extOutput.2 = "hello world."
# enterprises.ucdavis.extTable.extEntry.extErrFix.1 = 0
# enterprises.ucdavis.extTable.extEntry.extErrFix.2 = 0

# Note that the second line of the /tmp/shtest shell script is cut
# off.  Also note that the exit status of 35 was returned.

# -----------------------------------------------------------------------------

###############################################################################
# disk checks
#

# The agent can check the amount of available disk space, and make
# sure it is above a set limit.

# disk PATH [MIN=100000]
#
# PATH:  mount path to the disk in question.
# MIN:   Disks with space below this value will have the Mib's errorFlag set.
#        Default value = 100000.

# Check the / partition and make sure it contains at least 10 megs.

#disk / 10000

# % snmpwalk -v 1 localhost -c public .1.3.6.1.4.1.2021.9
# enterprises.ucdavis.diskTable.dskEntry.diskIndex.1 = 0
# enterprises.ucdavis.diskTable.dskEntry.diskPath.1 = "/" Hex: 2F
# enterprises.ucdavis.diskTable.dskEntry.diskDevice.1 = "/dev/dsk/c201d6s0"
# enterprises.ucdavis.diskTable.dskEntry.diskMinimum.1 = 10000
# enterprises.ucdavis.diskTable.dskEntry.diskTotal.1 = 837130
# enterprises.ucdavis.diskTable.dskEntry.diskAvail.1 = 316325
# enterprises.ucdavis.diskTable.dskEntry.diskUsed.1 = 437092
# enterprises.ucdavis.diskTable.dskEntry.diskPercent.1 = 58
# enterprises.ucdavis.diskTable.dskEntry.diskErrorFlag.1 = 0
# enterprises.ucdavis.diskTable.dskEntry.diskErrorMsg.1 = ""

# -----------------------------------------------------------------------------

###############################################################################
# load average checks
#

# load [1MAX=12.0] [5MAX=12.0] [15MAX=12.0]
#
# 1MAX:   If the 1 minute load average is above this limit at query
#         time, the errorFlag will be set.
# 5MAX:   Similar, but for 5 min average.
# 15MAX:  Similar, but for 15 min average.

# Check for loads:
#load 12 14 14

# % snmpwalk -v 1 localhost -c public .1.3.6.1.4.1.2021.10
# enterprises.ucdavis.loadTable.laEntry.loadaveIndex.1 = 1
# enterprises.ucdavis.loadTable.laEntry.loadaveIndex.2 = 2
# enterprises.ucdavis.loadTable.laEntry.loadaveIndex.3 = 3
# enterprises.ucdavis.loadTable.laEntry.loadaveNames.1 = "Load-1"
# enterprises.ucdavis.loadTable.laEntry.loadaveNames.2 = "Load-5"
# enterprises.ucdavis.loadTable.laEntry.loadaveNames.3 = "Load-15"
# enterprises.ucdavis.loadTable.laEntry.loadaveLoad.1 = "0.49" Hex: 30 2E 34 39
# enterprises.ucdavis.loadTable.laEntry.loadaveLoad.2 = "0.31" Hex: 30 2E 33 31
# enterprises.ucdavis.loadTable.laEntry.loadaveLoad.3 = "0.26" Hex: 30 2E 32 36
# enterprises.ucdavis.loadTable.laEntry.loadaveConfig.1 = "12.00"
# enterprises.ucdavis.loadTable.laEntry.loadaveConfig.2 = "14.00"
# enterprises.ucdavis.loadTable.laEntry.loadaveConfig.3 = "14.00"
# enterprises.ucdavis.loadTable.laEntry.loadaveErrorFlag.1 = 0
# enterprises.ucdavis.loadTable.laEntry.loadaveErrorFlag.2 = 0
# enterprises.ucdavis.loadTable.laEntry.loadaveErrorFlag.3 = 0
# enterprises.ucdavis.loadTable.laEntry.loadaveErrMessage.1 = ""
# enterprises.ucdavis.loadTable.laEntry.loadaveErrMessage.2 = ""
# enterprises.ucdavis.loadTable.laEntry.loadaveErrMessage.3 = ""

# -----------------------------------------------------------------------------

###############################################################################
# Extensible sections.
#

# This alleviates the multiple line output problem found in the
# previous executable mib by placing each mib in its own mib table:

# Run a shell script containing:
#
# #!/bin/sh
# echo hello world
# echo hi there
# exit 35
#
# Note:  this has been specifically commented out to prevent
# accidental security holes due to someone else on your system writing
# a /tmp/shtest before you do.  Uncomment to use it.
#
# exec .1.3.6.1.4.1.2021.50 shelltest /bin/sh /tmp/shtest

# % snmpwalk -v 1 localhost -c public .1.3.6.1.4.1.2021.50
# enterprises.ucdavis.50.1.1 = 1
# enterprises.ucdavis.50.2.1 = "shelltest"
# enterprises.ucdavis.50.3.1 = "/bin/sh /tmp/shtest"
# enterprises.ucdavis.50.100.1 = 35
# enterprises.ucdavis.50.101.1 = "hello world."
# enterprises.ucdavis.50.101.2 = "hi there."
# enterprises.ucdavis.50.102.1 = 0

# Now the Output has grown to two lines, and we can see the 'hi
# there.' output as the second line from our shell script.
#
# Note that you must alter the mib.txt file to be correct if you want
# the .50.* outputs above to change to reasonable text descriptions.

# Other ideas:
#
# exec .1.3.6.1.4.1.2021.51 ps /bin/ps
# exec .1.3.6.1.4.1.2021.52 top /usr/local/bin/top
# exec .1.3.6.1.4.1.2021.53 mailq /usr/bin/mailq

# -----------------------------------------------------------------------------

###############################################################################
# Pass through control.
#

# Usage:
#   pass MIBOID EXEC-COMMAND
#
# This will pass total control of the mib underneath the MIBOID
# portion of the mib to the EXEC-COMMAND.
#
# Note:  You'll have to change the path of the passtest script to your
# source directory or install it in the given location.
#
# Example:  (see the script for details)
#           (commented out here since it requires that you place the
#           script in the right location. (its not installed by default))

# pass .1.3.6.1.4.1.2021.255 /bin/sh /usr/local/local/passtest

# % snmpwalk -v 1 localhost -c public .1.3.6.1.4.1.2021.255
# enterprises.ucdavis.255.1 = "life the universe and everything"
# enterprises.ucdavis.255.2.1 = 42
# enterprises.ucdavis.255.2.2 = OID: 42.42.42
# enterprises.ucdavis.255.3 = Timeticks: (363136200) 42 days, 0:42:42
# enterprises.ucdavis.255.4 = IpAddress: 127.0.0.1
# enterprises.ucdavis.255.5 = 42
# enterprises.ucdavis.255.6 = Gauge: 42
#
# % snmpget -v 1 localhost public .1.3.6.1.4.1.2021.255.5
# enterprises.ucdavis.255.5 = 42
#
# % snmpset -v 1 localhost public .1.3.6.1.4.1.2021.255.1 s "New string"
# enterprises.ucdavis.255.1 = "New string"
#

# For specific usage information, see the man/snmpd.conf.5 manual page
# as well as the local/passtest script used in the above example.

# Added for support of bcm5820 cards.
pass .1.3.6.1.4.1.4413.4.1 /usr/bin/ucd5820stat

###############################################################################
# Further Information
#
#  See the snmpd.conf manual page, and the output of "snmpd -H".


13.6. Network Manager

http://www.panabit.com/

13.6.1. ntop

cd /usr/ports/net/ntop/ && make install clean

 ┌────────────────────────────────────────────────────────────────────┐
 │                    Options for ntop 3.3.10_5                       │
 │ ┌────────────────────────────────────────────────────────────────┐ │
 │ │         [ ] LOCALE      Enable locale (i18n) support.          │ │
 │ │         [X] PCAP_PORT   Use libpcap from ports.                │ │
 │ │         [X] XMLDUMP     Enable XML Dump support.               │ │
 │ │         [X] TCPWRAPPER  Enable TCP wrapper support             │ │
 │ │                                                                │ │
 │ │                                                                │ │
 │ │                                                                │ │
 │ │                                                                │ │
 │ │                                                                │ │
 │ │                                                                │ │
 │ │                                                                │ │
 │ │                                                                │ │
 │ │                                                                │ │
 │ │                                                                │ │
 │ │                                                                │ │
 ├─└────────────────────────────────────────────────────────────────┘─┤
 │                       [  OK  ]       Cancel                        │
 └────────────────────────────────────────────────────────────────────┘


部分 III. Web Server

目录

14. Lighttpd
14.1. install lighttpd
14.2. install php5
14.3. xcache
14.4. Zend Optimizer
15. nginx
15.1. port install
15.1.1. php
15.1.1.1. php-fpm
15.1.2. /etc/rc.conf
15.1.3. /usr/local/etc/nginx/nginx.conf
15.1.4. start
15.2. 编译安装 php 与 php-fpm
15.2.1. php-5.2.x
15.2.2. php-5.3.x
16. Apache
16.1. install
17. mysql
17.1. install
18. log
18.1. cronolog
18.1.1. Apache
18.1.2. Lighttpd
18.2. logrotate
19. Cache
19.1. Memcache
19.2. PHP Memcache


第 14 章 Lighttpd

目录

14.1. install lighttpd
14.2. install php5
14.3. xcache
14.4. Zend Optimizer

14.1. install lighttpd

# cd /usr/ports/www/
# pkg_add -r lighttpd

/etc/rc.conf

[root@freebsd ~]# echo lighttpd_enable=\"YES\" >> /etc/rc.conf

[root@freebsd ~]# cat /etc/rc.conf
lighttpd_enable="YES"

fastcgi.server             = ( ".php" =>
                               ( "localhost" =>
                                 (
                                   "socket" => "/tmp/php-fastcgi.socket",
                                   "bin-path" => "/usr/local/bin/php-cgi"
                                 )
                               )
                            )

server.document-root        = "/www/htdocs/"
server.errorlog             = "/www/logs/lighttpd.error.log"
accesslog.filename          = "/www/logs/access.log"

chown -R www:www /www/
# touch /www/logs/lighttpd.error.log
# chown www:www /www/logs/lighttpd.error.log

start

freebsd0# /usr/local/etc/rc.d/spawn-fcgi start
Starting spawn_fcgi.
spawn-fcgi: child spawned successfully: PID: 79056
freebsd0# /usr/local/etc/rc.d/spawn-fcgi stop
Stopping spawn_fcgi.
Waiting for PIDS: 79056.
freebsd0# /usr/local/etc/rc.d/spawn-fcgi start
Starting spawn_fcgi.
spawn-fcgi: child spawned successfully: PID: 79084
freebsd0# /usr/local/etc/rc.d/spawn-fcgi restart
Stopping spawn_fcgi.
Starting spawn_fcgi.
spawn-fcgi: child spawned successfully: PID: 79109

# /usr/local/etc/rc.d/lighttpd start
Starting lighttpd.


14.2. install php5

# pkg_add -r php5
# pkg_add -r php5-extensions
# pkg_add -r php5-curl
# pkg_add -r php5-mcrypt
# pkg_add -r php5-mbstring

# pkg_add -r php5-mysql
# pkg_add -r php5-gd

# pkg_add -r php5-zlib
# pkg_add -r php5-zip


14.3. xcache

# portsnap fetch update
# cd /usr/ports/www/xcache
# make install clean

Enable xache

# cp /usr/local/share/examples/xcache/xcache.ini /usr/local/etc/php/
# cd /usr/local/etc/php/
# vi xcache.ini

Type the following command to restart lighttpd

# /usr/local/etc/rc.d/lighttpd restart


14.4. Zend Optimizer

# cd /usr/ports/devel/ZendOptimizer/
# make
# cd /usr/ports/devel/ZendOptimizer/work/ZendOptimizer-*
#./install-tty

不要选择apache

php.ini

# vi /usr/local/etc/php.ini

[Zend]
zend_extension_manager.optimizer=/usr/local/Zend/lib/Optimizer-3.3.0
zend_extension_manager.optimizer_ts=/usr/local/Zend/lib/Optimizer_TS-3.3.0
zend_optimizer.version=3.3.0a
zend_extension=/usr/local/Zend/lib/ZendExtensionManager.so
zend_extension_ts=/usr/local/Zend/lib/ZendExtensionManager_TS.so


第 15 章 nginx

目录

15.1. port install
15.1.1. php
15.1.1.1. php-fpm
15.1.2. /etc/rc.conf
15.1.3. /usr/local/etc/nginx/nginx.conf
15.1.4. start
15.2. 编译安装 php 与 php-fpm
15.2.1. php-5.2.x
15.2.2. php-5.3.x
pkg_add -r nginx

location / {
        root   /usr/local/www/nginx;
        index  index.html index.htm;
}

location ~ \.php$ {
        root           html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /usr/local/www/nginx$fastcgi_script_name;
        include        fastcgi_params;
}

15.1. port install

# cd /usr/ports/www/nginx

# make install

HTTP_MODULE
HTTP_REWRITE_MODULE
HTTP_STATUS_MODULE

15.1.1. php

ports 安装 php-fpm 适合 php-5.2.10, 高于这个版本请跳过这节, 采用编译安装。

# cd /usr/ports/lang/php5
# make install

extensions

# cd /usr/ports/lang/php5-extensions/
# make install
# ln -s /usr/local/etc/php.ini-production /usr/local/etc/php.ini

php-fpm - FastCGI Process Manager

homepage: http://php-fpm.org/downloads/freebsd-port/

# tar xvzf php-5.2.10-fpm-0.5.13.tar.gz --directory=/usr/ports/lang
x php5-fpm/
x php5-fpm/files/
x php5-fpm/Makefile
x php5-fpm/distinfo
x php5-fpm/pkg-descr
x php5-fpm/pkg-plist
x php5-fpm/files/php-fpm.sh.in
x php5-fpm/files/patch-scripts::phpize.in
x php5-fpm/files/patch-TSRM_threads.m4
x php5-fpm/files/patch-Zend::zend.h
x php5-fpm/files/patch-Zend_zend_list.c
x php5-fpm/files/patch-Zend_zend_list.h
x php5-fpm/files/patch-ext_standard_array.c
x php5-fpm/files/patch-ext_standard_basic_functions.c
x php5-fpm/files/patch-ext_standard_dns.h
x php5-fpm/files/patch-ext_standard_image.c
x php5-fpm/files/patch-php.ini-dist
x php5-fpm/files/patch-php.ini-recommended
x php5-fpm/files/patch-main::php_config.h.in
x php5-fpm/files/patch-main_SAPI.c
x php5-fpm/files/patch-acinclude.m4
x php5-fpm/files/patch-configure.in

# cd /usr/ports/lang/php5-fpm/ && make install

15.1.1.1. php-fpm

                        Unix user of processes
                        <value name="user">www</value>

                        Unix group of processes
                        <value name="group">www</value>

15.1.2. /etc/rc.conf

vim /etc/rc.conf
php_fpm_enable="YES"
nginx_enable="YES"

15.1.3. /usr/local/etc/nginx/nginx.conf

ee /usr/local/etc/nginx/nginx.conf

        location / {
            root   /www;
            index  index.html index.htm index.php;
        }

        location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /www$fastcgi_script_name;
            include        fastcgi_params;
        }

15.1.4. start

/usr/local/etc/rc.d/php-fpm start
/usr/local/etc/rc.d/nginx start


15.2. 编译安装 php 与 php-fpm

提示

PHP 5.3.3 后续版本已经集成php-fpm 不需要打补丁再安装.

15.2.1. php-5.2.x

http://php-fpm.org/downloads/

[root@freebsd1:~] cd /usr/src/
[root@freebsd1:/usr/src]

wget http://php-fpm.org/downloads/php-5.2.14-fpm-0.5.14.diff.gz
wget http://www.php.net/get/php-5.2.14.tar.gz/from/cn.php.net/mirror

[root@freebsd1:/usr/src] tar zxf php-5.2.14.tar.gz

gzip -cd php-5.2.14-fpm-0.5.14.diff.gz | patch -d php-5.2.14 -p1

[root@freebsd1:/usr/src] cd php-5.2.14

./configure --prefix=/usr/local/php-5.2.14 \
--with-config-file-path=/usr/local/php-5.2.14/etc \
--enable-fastcgi --enable-fpm \
--with-curl \
--with-gd \
--with-jpeg-dir=/usr/lib64 \
--with-iconv \
--with-mcrypt \
--with-zlib \
--with-pear \
--with-xmlrpc \
--with-openssl \
--with-mysql \
--with-mysqli \
--with-pdo-mysql \
--enable-zip \
--enable-sockets \
--enable-soap \
--enable-mbstring \
--enable-magic-quotes \
--enable-inline-optimization \
--enable-xml \
--enable-ftp

make && make install

配置php.ini与php-fpm.conf

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

include_path = ".:/www/includes:/usr/local/php-5.2.14/lib/php"

vim /usr/local/php-5.2.14/etc/php-fpm.conf

    <value name="owner">www</value>
    <value name="group">www</value>

<value name="user">www</value>
<value name="group">www</value>

/usr/local/php-5.2.14/sbin/php-fpm start

15.2.2. php-5.3.x

安装zlib
===========================================================
./configure
make test
make install

安装gd
===========================================================
cd /usr/ports/graphic/gd
make install

安装libpng
===========================================================
cd /usr/ports/graphics/png
make install
===========================================================

安装jpeg
===========================================================
cd /usr/ports/graphics/jpeg
make install
===========================================================

安装freetype
===========================================================
cd /usr/ports/print/freetype
make install

./configure --prefix=/usr/local/php-5.3.5 \
--with-config-file-path=/usr/local/php-5.3.5/etc \
--with-config-file-scan-dir=/usr/local/php-5.3.5/etc/conf.d \
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
--with-pear \
--with-curl \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-iconv \
--with-mcrypt \
--with-mhash \
--with-zlib \
--with-xmlrpc \
--with-xsl \
--with-openssl \
--with-mysql \
--with-mysqli \
--with-pdo-mysql \

--disable-debug \
--enable-zip \
--enable-sockets \
--enable-soap \
--enable-mbstring \
--enable-magic-quotes \
--enable-inline-optimization \
--enable-memory-limit
--enable-xml \

--enable-ftp \
--enable-exif \
--enable-wddx \
--enable-bcmath \
--enable-calendar \
--enable-sqlite-utf8 \
--enable-shmop \
--enable-dba \
--enable-sysvsem \
--enable-sysvshm \
--enable-sysvmsg

make
make install

php.ini

include_path=.:/usr/local/php-5.3.5/lib/php

php-fpm.conf

cp /usr/local/php-5.3.5/etc/php-fpm.conf.default /usr/local/php-5.3.5/etc/php-fpm.conf
cp /usr/src/php-5.3.5/sapi/fpm/init.d.php-fpm /usr/local/etc/rc.d/php-fpm
chmod +x /usr/local/etc/rc.d/php-fpm

vim /usr/local/php-5.3.5/etc/php-fpm.conf
pid = run/php-fpm.pid

user = www
group = www

pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35


第 16 章 Apache

目录

16.1. install

16.1. install

# cd /usr/ports/www/
# pkg_add -r apache


第 17 章 mysql

目录

17.1. install

17.1. install

17.1. install

freebsd# pkg_add -r mysql51-server
freebsd# /usr/local/bin/mysql_install_db
freebsd# chown -R mysql /var/db/mysql

/etc/rc.conf

freebsd# vi /etc/rc.conf
mysql_enable="YES"

start

freebsd# /usr/local/etc/rc.d/mysql-server start
Starting mysql.

set password

freebsd# /usr/local/bin/mysqladmin -u root password 'chen'

freebsd# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.1.39 FreeBSD port: mysql-server-5.1.39

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>


第 18 章 log

目录

18.1. cronolog
18.1.1. Apache
18.1.2. Lighttpd
18.2. logrotate

18.1. cronolog

cd /usr/ports/sysutils/cronolog/
make install clean

18.1.1. Apache

CustomLog "|/usr/local/sbin/cronolog /data/log/domain/%Y%m%d.log" combined
CustomLog "|/usr/local/sbin/cronolog /var/log/www/%Y%m/%d_access_log" combined

18.1.2. Lighttpd

accesslog.filename = "| /usr/local/sbin/cronolog /var/log/lighttpd/%Y/%m/%d/access.log"


18.2. logrotate


第 19 章 Cache

目录

19.1. Memcache
19.2. PHP Memcache

19.1. Memcache

cd /usr/ports/databases/memcached; make install clean

vi /etc/rc.conf
# start memcached
memcached_enable="YES"

你也可不使用vi，使用下面命令快速添加

echo "memcached_enable=\"YES\"" >> /etc/rc.conf

Memcache

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


19.2. PHP Memcache

cd /usr/ports/databases/pecl-memcache; make install clean

确认Memcache是否安装成功

cat /usr/local/etc/php/extensions.ini | grep memcache

php -m | grep memcache
memcache


第 20 章 MySQL

目录

20.1. Installation

20.1. Installation

pkg_add -r mysql55-server
pkg_add -r mysql55-client
pkg_add -r mysql55-scripts

/usr/local/bin/mysql_install_db
chown -R mysql /var/db/mysql/
chgrp -R mysql /var/db/mysql/
/usr/local/bin/mysqld_safe -user=mysql &
/usr/local/bin/mysqladmin -u root password ‘newpassword’

mysql_enable="YES"


第 21 章 textproc

目录

21.1. docbook

21.1. docbook

cd /usr/ports/textproc/libxslt
make install

cd /usr/ports/textproc/docbook-xml
make install

cd /usr/ports/textproc/docbook-xsl
make install

通过xsltproc生成html文件

$ xsltproc /usr/local/share/xsl/docbook/xhtml/chunk.xsl book.xml


第 22 章 devel

目录

22.1. subversion

22.1. subversion

cd /usr/ports/devel/subversion
make install


第 23 章 FAQ

目录

23.1. Linux用户使用FreeBSD，问FreeBSD ulimit怎么设置？
23.2. su: Sorry

23.1. Linux用户使用FreeBSD，问FreeBSD ulimit怎么设置？

首先说明FreeBSD默认Shell是csh没有ulimit命令，但C Shell有limit命令。如果你想使用ulimit命令可以安装Bourne shell，Bash，Zsh

limit,ulimit比较

[neo@freebsd:~] limit
cputime         unlimited
filesize        unlimited
datasize        32768MB
stacksize       512MB
coredumpsize    unlimited
memoryuse       unlimited
memorylocked    unlimited
maxproc         5547
descriptors     65536
sockbufsize     unlimited
vmemorysize     unlimited
NPTS            unlimited
SWAP            unlimited

[neo@freebsd:~] env | grep SHELL
SHELL=/usr/local/bin/zsh

[neo@freebsd:~] ulimit -a
-t: cpu time (seconds)         unlimited
-f: file size (blocks)         unlimited
-d: data seg size (kbytes)     33554432
-s: stack size (kbytes)        524288
-c: core file size (blocks)    unlimited
-m: resident set size (kbytes) unlimited
-l: locked-in-memory size (kb) unlimited
-u: processes                  5547
-n: file descriptors           65536
-N  9: socket buffer size (kb) unlimited
-v: virtual memory size (kb)   unlimited
-N 11:                         unlimited
-N 12:                         unlimited

在Freebsd上，你能使用sysctl命令：

以 nofile - max number of open files 为例，limit、ulimit、sysctl实现同样的功能。

csh% limit descriptors unlimited
或者
csh% limit descriptors 4096

sh$ ulimit -n unlimited
或者
sh$ ulimit -n 4096

sysctl kern.maxfiles=65536
sysctl kern.maxfilesperproc=65536

写入配置文件 sysctl.conf

[neo@freebsd:~] cat /etc/sysctl.conf
# $FreeBSD: src/etc/sysctl.conf,v 1.8.34.1.4.1 2010/06/14 02:09:06 kensmith Exp $
#
#  This file is read when going to multi-user and its contents piped thru
#  ``sysctl'' to adjust kernel values.  ``man 5 sysctl.conf'' for details.
#

# Uncomment this to prevent users from seeing information about processes that
# are being run under another UID.
#security.bsd.see_other_uids=0

#vm.pmap.shpgperproc: 2000
#vm.pmap.pv_entry_max: 13338058
kern.ipc.shm_use_phys=1
kern.maxfiles=65536
kern.maxfilesperproc=65536
kern.ipc.somaxconn=2048

[neo@freebsd:~] /etc/rc.d/sysctl reload

[neo@freebsd:~] sysctl -a | grep maxfiles
kern.maxfiles: 65536
kern.maxfilesperproc: 65536


23.2. su: Sorry

root@freebsd:/root # pw groupmod wheel -m test

root@freebsd:/root # cat /etc/group | grep test
wheel:*:0:root,neo,test
test:*:1002:

root@freebsd:/root # pw usermod test -g wheel

root@freebsd:/root # cat /etc/passwd | grep test
test:*:1002:0:test:/home/test:/bin/csh

或者直接修改/etc/group文件，把相应的用户加到wheell组就可以

wheel:*:0:root,username