FreeBSD的可玩性还是很高的.
本文将介绍一下FreeBSD在vmware中的安装, 物理机的安装和这个差不多.
我们这里将要用到zfs的root disk mirror. 所以虚拟机环境中需要2块物理设备.
如果是物理机器的话, 建议使用RAID的JBOD模式. (原因参见
http://blog.163.com/digoal@126/blog/static/163877040201441694022110/)
首先我们要下载freebsd 的iso, 本文用到的是10.0 x64的版本.
ftp://ftp.freebsd.org/pub/FreeBSD/releases/amd64/amd64/ISO-IMAGES/10.0/FreeBSD-10.0-RELEASE-amd64-dvd1.iso
然后需要安装vmware workstation. 我这里用到的是10的版本.
创建虚拟机
内存建议配大一点, 至少1G, 最好有2GB, 如果使用ZFS的话, 最好大于4GB.
创建磁盘
这里只创建了1块磁盘, 所以使用ZFS的话, 无法选择mirror模式.
最好创建2块一样的磁盘, 实际生产机中, 如果底层设备是RAID模式的, 那么没有必要使用MIRROR模式.
如果底层设备不是RAID模式, 那么建议使用JBOD+mirror模式.
准备安装, 选择1.
配置键盘
配置主机名
配置要安装的包
选择磁盘分区, 建议使用ZFS.
选择Install, 配置ZPOOL
因为例子中只有1块硬盘, 选择mirror后会导致无法进行安装.
关闭虚拟机, 新建一个硬盘.
现在可以选择mirror了, 选中两块硬盘作为mirror vdev.
开始安装包
安装完成后, 提示你设置root用户的密码
然后是配置网卡
配置时钟, 时区.
配置BSD启动后, 开启哪些常用的服务, 例如sshd, ntpd
询问是否新增一个普通用户, 可以在后面使用adduser命令添加.
是否安装handbook, 可选.
询问是否进入SHELL进行配置, 可以配置, 也可以直接exit退出
重启服务器.
接下来要配置一下sshd_config, 让root用户可以使用密码认证, 使用远程登录.
重启sshd服务
创建普通用户举例
root@my-domain:~ # adduser
Username: digoal 输入用户名
Full name: digoal.zhou 输入全名
Uid (Leave empty for default):
Login group [digoal]:
Login group is digoal. Invite digoal into other groups? []: 类似linux 的useradd -G , 是否加入其他组
Login class [default]:
Shell (sh csh tcsh nologin) [sh]: csh 使用csh
Home directory [/home/digoal]:
Home directory permissions (Leave empty for default):
Use password-based authentication? [yes]: 是否使用基于密码的认证
Use an empty password? (yes/no) [no]:
Use a random password? (yes/no) [no]:
Enter password:
Enter password again:
Lock out the account after creation? [no]: 创建完后是否锁住用户
Username : digoal
Password : *****
Full Name : digoal.zhou
Uid : 1002
Class :
Groups : digoal
Home : /home/digoal
Home Mode :
Shell : /bin/csh
Locked : no
OK? (yes/no): yes
adduser: INFO: Successfully added (digoal) to the user database.
Add another user? (yes/no): no 是否继续创建其他用户
Goodbye!
root@my-domain:~ # id digoal
uid=1002(digoal) gid=1002(digoal) groups=1002(digoal)
查找包举例
pkg search $packagename
第一次使用pkg, 如果没有安装的话, 会提示安装.
root@digoal:~ # pkg search postgresql 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 from pkg+http://pkg.FreeBSD.org/freebsd:10:x86:64/latest, please wait...
Verifying signature with trusted certificate pkg.freebsd.org.2013102301... done Installing pkg-1.2.7_2... done If you are upgrading from the old package format, first run: # pkg2ng
root@my-domain:~ # pkg search postgresql
exim-postgresql-4.82
ja-postgresql82-man-8.2.4
libgda4-postgresql-4.2.12
libgda5-postgresql-5.0.3
p5-Test-postgresql-0.09
pgtcl-postgresql90-2.0.0
pgtcl-postgresql91-2.0.0
pgtcl-postgresql92-2.0.0
pgtcl-postgresql93-2.0.0
pgtcl-postgresql94-2.0.0
postgresql-jdbc-9.1.902_1
postgresql-libpgeasy-3.0.4_1
postgresql-libpqxx-4.0.1_1
postgresql-libpqxx3-3.1.1_1
postgresql-odbc-09.01.0200_1
postgresql-pllua-1.0
postgresql-plproxy-2.5
postgresql-plruby-0.5.4_2
postgresql-plv8js-1.4.1
postgresql-relay-1.3.2_1
postgresql-repmgr-2.0_1
postgresql84-client-8.4.21
postgresql84-contrib-8.4.21_1
postgresql84-docs-8.4.21
postgresql84-plperl-8.4.21_1
postgresql84-plpython-8.4.21_1
postgresql84-pltcl-8.4.21
postgresql84-server-8.4.21_1
postgresql9-client-9.4.b1_1
postgresql9-contrib-9.4.b1_1
postgresql9-docs-9.4.b1
postgresql9-plperl-9.4.b1
postgresql9-plpython-9.4.b1
postgresql9-pltcl-9.4.b1
postgresql9-server-9.4.b1_1
postgresql90-client-9.0.17
postgresql90-contrib-9.0.17
postgresql90-docs-9.0.17
postgresql90-plperl-9.0.17
postgresql90-plpython-9.0.17
postgresql90-pltcl-9.0.17
postgresql90-server-9.0.17
postgresql91-client-9.1.13_1
postgresql91-contrib-9.1.13_1
postgresql91-docs-9.1.13
postgresql91-plperl-9.1.13_1
postgresql91-plpython-9.1.13_1
postgresql91-pltcl-9.1.13
postgresql91-server-9.1.13_1
postgresql92-client-9.2.8_1
postgresql92-contrib-9.2.8_1
postgresql92-docs-9.2.8
postgresql92-plperl-9.2.8_1
postgresql92-plpython-9.2.8_1
postgresql92-pltcl-9.2.8
postgresql92-server-9.2.8_1
postgresql93-client-9.3.4
postgresql93-contrib-9.3.4_1
postgresql93-docs-9.3.4
postgresql93-plperl-9.3.4
postgresql93-plpython-9.3.4
postgresql93-pltcl-9.3.4
postgresql93-server-9.3.4
postgresql_autodoc-1.41
py33-postgresql-1.1.0_1
安装包举例
pkg install $packagename
例如安装我们上面查到的postgresql 9.3.4
root@my-domain:~ # pkg install postgresql93-server-9.3.4
Updating repository catalogue
The following 2 packages will be installed:
Installing postgresql93-client: 9.3.4
Installing postgresql93-server: 9.3.4
The installation will require 25 MB more space
5 MB to be downloaded
Proceed with installing packages [y/N]: y
postgresql93-client-9.3.4.txz 100% 1968KB 43.7KB/s 108.1KB/s 00:45
postgresql93-server-9.3.4.txz 100% 3196KB 47.0KB/s 55.5KB/s 01:08
Checking integrity... done
[1/2] Installing postgresql93-client-9.3.4... done
[2/2] Installing postgresql93-server-9.3.4...===> Creating users and/or groups.
Creating group 'pgsql' with gid '70'.
Creating user 'pgsql' with uid '70'.
=========== BACKUP YOUR DATA! =============
As always, backup your data before
upgrading. If the upgrade leads to a higher
minor revision (e.g. 8.3.x -> 8.4), a dump
and restore of all databases is
required. This is *NOT* done by the port!
Press ctrl-C *now* if you need to pg_dump.
===========================================
done
The PostgreSQL port has a collection of "side orders":
postgresql-docs
For all of the html documentation
p5-Pg
A perl5 API for client access to PostgreSQL databases.
postgresql-tcltk
If you want tcl/tk client support.
postgresql-jdbc
For Java JDBC support.
postgresql-odbc
For client access from unix applications using ODBC as access
method. Not needed to access unix PostgreSQL servers from Win32
using ODBC. See below.
ruby-postgres, py-PyGreSQL
For client access to PostgreSQL databases using the ruby & python
languages.
postgresql-plperl, postgresql-pltcl & postgresql-plruby
For using perl5, tcl & ruby as procedural languages.
postgresql-contrib
Lots of contributed utilities, postgresql functions and
datatypes. There you find pg_standby, pgcrypto and many other cool
things.
etc...
For procedural languages and postgresql functions, please note that
you might have to update them when updating the server.
If you have many tables and many clients running, consider raising
kern.maxfiles using sysctl(8), or reconfigure your kernel
appropriately.
The port is set up to use autovacuum for new databases, but you might
also want to vacuum and perhaps backup your database regularly. There
is a periodic script, /usr/local/etc/periodic/daily/502.pgsql, that
you may find useful. You can use it to backup and perfom vacuum on all
databases nightly. Per default, it perfoms `vacuum analyze'. See the
script for instructions. For autovacuum settings, please review
~pgsql/data/postgresql.conf.
If you plan to access your PostgreSQL server using ODBC, please
consider running the SQL script /usr/local/share/postgresql/odbc.sql
to get the functions required for ODBC compliance.
Please note that if you use the rc script,
/usr/local/etc/rc.d/postgresql, to initialize the database, unicode
(UTF-8) will be used to store character data by default. Set
postgresql_initdb_flags or use login.conf settings described below to
alter this behaviour. See the start rc script for more info.
To set limits, environment stuff like locale and collation and other
things, you can set up a class in /etc/login.conf before initializing
the database. Add something similar to this to /etc/login.conf:
---
postgres:\
:lang=en_US.UTF-8:\
:setenv=LC_COLLATE=C:\
:tc=default:
---
and run `cap_mkdb /etc/login.conf'.
Then add 'postgresql_class="postgres"' to /etc/rc.conf.
======================================================================
To initialize the database, run
/usr/local/etc/rc.d/postgresql initdb
You can then start PostgreSQL by running:
/usr/local/etc/rc.d/postgresql start
For postmaster settings, see ~pgsql/data/postgresql.conf
NB. FreeBSD's PostgreSQL port logs to syslog by default
See ~pgsql/data/postgresql.conf for more info
======================================================================
To run PostgreSQL at startup, add
'postgresql_enable="YES"' to /etc/rc.conf
root@my-domain:~ # su - pgsql
$ which psql
/usr/local/bin/psql
$ psql -V
psql (PostgreSQL) 9.3.4
这个pg的编译参数
$ pg_config --configure
'--with-libraries=/usr/local/lib' '--with-includes=/usr/local/include' '--enable-thread-safety' '--with-openssl' '--with-libxml' '--enable-nls' '--without-gssapi' '--prefix=/usr/local' '--mandir=/usr/local/man' '--infodir=/usr/local/info/' '--build=amd64-portbld-freebsd10.0' 'build_alias=amd64-portbld-freebsd10.0' 'CC=cc' 'CFLAGS=-O2 -pipe -fno-strict-aliasing' 'LDFLAGS= -L/usr/local/lib -Wl,-rpath,/usr/lib:/usr/local/lib' 'CPPFLAGS=' 'CPP=cpp' 'LDFLAGS_SL='
删除包举例
root@my-domain:~ # pkg remove postgresql93-server-9.3.4
Deinstallation has been requested for the following 1 packages:
postgresql93-server-9.3.4
The deinstallation will free 17 MB
Proceed with deinstalling packages [y/N]: y
[1/1] Deleting postgresql93-server-9.3.4...==> You should manually remove the "pgsql" user.
done
提示用户需要手工删除
root@my-domain:~ # id pgsql
uid=70(pgsql) gid=70(pgsql) groups=70(pgsql)
手工删除用户
root@my-domain:~ # rmuser pgsql
Matching password entry:
pgsql:*:70:70::0:0:PostgreSQL pseudo-user:/usr/local/pgsql:/bin/sh
Is this the entry you wish to remove? yes
Remove user's home directory (/usr/local/pgsql)?
Remove user's home directory (/usr/local/pgsql)? ys
Remove user's home directory (/usr/local/pgsql)? yes
Removing user (pgsql): mailspool home passwd.
root@my-domain:~ # rm
rm rmail rmd160 rmdir rmextattr rmt rmuser
root@my-domain:~ # id pgsql
id: pgsql: no such user
下载软件举例
freebsd默认没有安装wget, 可以使用fetch命令下载软件.
fetch http://ftp.postgresql.org/pub/source/v9.3.4/postgresql-9.3.4.tar.bz2
如果要用wget的话, 可以使用pkg安装wget.
pkg install wget
[参考]
4. ftp://ftp.freebsd.org/pub/FreeBSD/releases/amd64/amd64/ISO-IMAGES/10.0/FreeBSD-10.0-RELEASE-amd64-dvd1.iso
6. ftp://ftp.freebsd.org/pub/FreeBSD/doc/en_US.ISO8859-1/books/