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:~ # adduserUsername: 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 使用cshHome 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 : digoalPassword : *****Full Name : digoal.zhouUid : 1002Class :Groups : digoalHome : /home/digoalHome Mode :Shell : /bin/cshLocked : noOK? (yes/no): yesadduser: INFO: Successfully added (digoal) to the user database.Add another user? (yes/no): no 是否继续创建其他用户Goodbye!root@my-domain:~ # id digoaluid=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 postgresqlexim-postgresql-4.82ja-postgresql82-man-8.2.4libgda4-postgresql-4.2.12libgda5-postgresql-5.0.3p5-Test-postgresql-0.09pgtcl-postgresql90-2.0.0pgtcl-postgresql91-2.0.0pgtcl-postgresql92-2.0.0pgtcl-postgresql93-2.0.0pgtcl-postgresql94-2.0.0postgresql-jdbc-9.1.902_1postgresql-libpgeasy-3.0.4_1postgresql-libpqxx-4.0.1_1postgresql-libpqxx3-3.1.1_1postgresql-odbc-09.01.0200_1postgresql-pllua-1.0postgresql-plproxy-2.5postgresql-plruby-0.5.4_2postgresql-plv8js-1.4.1postgresql-relay-1.3.2_1postgresql-repmgr-2.0_1postgresql84-client-8.4.21postgresql84-contrib-8.4.21_1postgresql84-docs-8.4.21postgresql84-plperl-8.4.21_1postgresql84-plpython-8.4.21_1postgresql84-pltcl-8.4.21postgresql84-server-8.4.21_1postgresql9-client-9.4.b1_1postgresql9-contrib-9.4.b1_1postgresql9-docs-9.4.b1postgresql9-plperl-9.4.b1postgresql9-plpython-9.4.b1postgresql9-pltcl-9.4.b1postgresql9-server-9.4.b1_1postgresql90-client-9.0.17postgresql90-contrib-9.0.17postgresql90-docs-9.0.17postgresql90-plperl-9.0.17postgresql90-plpython-9.0.17postgresql90-pltcl-9.0.17postgresql90-server-9.0.17postgresql91-client-9.1.13_1postgresql91-contrib-9.1.13_1postgresql91-docs-9.1.13postgresql91-plperl-9.1.13_1postgresql91-plpython-9.1.13_1postgresql91-pltcl-9.1.13postgresql91-server-9.1.13_1postgresql92-client-9.2.8_1postgresql92-contrib-9.2.8_1postgresql92-docs-9.2.8postgresql92-plperl-9.2.8_1postgresql92-plpython-9.2.8_1postgresql92-pltcl-9.2.8postgresql92-server-9.2.8_1postgresql93-client-9.3.4postgresql93-contrib-9.3.4_1postgresql93-docs-9.3.4postgresql93-plperl-9.3.4postgresql93-plpython-9.3.4postgresql93-pltcl-9.3.4postgresql93-server-9.3.4postgresql_autodoc-1.41py33-postgresql-1.1.0_1
安装包举例
pkg install $packagename
例如安装我们上面查到的postgresql 9.3.4
root@my-domain:~ # pkg install postgresql93-server-9.3.4Updating repository catalogueThe following 2 packages will be installed:
Installing postgresql93-client: 9.3.4Installing postgresql93-server: 9.3.4
The installation will require 25 MB more space
5 MB to be downloaded
Proceed with installing packages [y/N]: ypostgresql93-client-9.3.4.txz 100% 1968KB 43.7KB/s 108.1KB/s 00:45postgresql93-server-9.3.4.txz 100% 3196KB 47.0KB/s 55.5KB/s 01:08Checking 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 higherminor revision (e.g. 8.3.x -> 8.4), a dumpand restore of all databases isrequired. This is *NOT* done by the port!
Press ctrl-C *now* if you need to pg_dump.===========================================doneThe PostgreSQL port has a collection of "side orders":
postgresql-docsFor all of the html documentation
p5-PgA perl5 API for client access to PostgreSQL databases.
postgresql-tcltkIf you want tcl/tk client support.
postgresql-jdbcFor Java JDBC support.
postgresql-odbcFor client access from unix applications using ODBC as accessmethod. Not needed to access unix PostgreSQL servers from Win32using ODBC. See below.
ruby-postgres, py-PyGreSQLFor client access to PostgreSQL databases using the ruby & pythonlanguages.
postgresql-plperl, postgresql-pltcl & postgresql-plrubyFor using perl5, tcl & ruby as procedural languages.
postgresql-contribLots of contributed utilities, postgresql functions anddatatypes. There you find pg_standby, pgcrypto and many other coolthings.
etc...For procedural languages and postgresql functions, please note thatyou might have to update them when updating the server.
If you have many tables and many clients running, consider raisingkern.maxfiles using sysctl(8), or reconfigure your kernelappropriately.
The port is set up to use autovacuum for new databases, but you mightalso want to vacuum and perhaps backup your database regularly. Thereis a periodic script, /usr/local/etc/periodic/daily/502.pgsql, thatyou may find useful. You can use it to backup and perfom vacuum on alldatabases nightly. Per default, it perfoms `vacuum analyze'. See thescript for instructions. For autovacuum settings, please review~pgsql/data/postgresql.conf.
If you plan to access your PostgreSQL server using ODBC, pleaseconsider running the SQL script /usr/local/share/postgresql/odbc.sqlto 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 toalter this behaviour. See the start rc script for more info.
To set limits, environment stuff like locale and collation and otherthings, you can set up a class in /etc/login.conf before initializingthe 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 defaultSee ~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 -Vpsql (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.4Deinstallation 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 pgsqluid=70(pgsql) gid=70(pgsql) groups=70(pgsql)
手工删除用户
root@my-domain:~ # rmuser pgsqlMatching password entry:
pgsql:*:70:70::0:0:PostgreSQL pseudo-user:/usr/local/pgsql:/bin/sh
Is this the entry you wish to remove? yesRemove user's home directory (/usr/local/pgsql)?Remove user's home directory (/usr/local/pgsql)? ysRemove user's home directory (/usr/local/pgsql)? yesRemoving user (pgsql): mailspool home passwd.root@my-domain:~ # rmrm rmail rmd160 rmdir rmextattr rmt rmuserroot@my-domain:~ # id pgsqlid: 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/