FreeBSD是一款高性能、高可靠性的UNIX操作系统,它继承了BSD系统的纯净性和高性能,其软件包装和发布也比Linux系统更加严谨,同时也具有更佳的安全性,正是因为这些特性使得FreeBSD操作系统在服务器环境中有比较广泛的应用。下面,我就给大家介绍一下如何在FreeBSD平台下架设一台邮件服务器,希望能够对大家有所帮助。   一、安装webmin   下载webmin-1.070.tar.gz   #tar zxvf webmin-1.070.tar.gz   #cd webmin-1.070   #./setup.sh   安装后可以对mysql数据库进行管理,比如添加用户,向表里添加数据。   二、数据库的设置   1、安装mysql数据库   本系统使用的是FreeBSD 4.7下ports安装的mysql数据库(当时使用原码安装时在安装postfix时出错,所以使用ports安装就解决了该问题)。   #cd /usr/ports/databases/mysql323-server/   #make install   #cd work/mysql-3.23.52/   #scripts/mysql_install_db   #cp support-files/my-medium.cnf /etc/my.cnf   #echo “/usr/local/bin/safe_mysqld --user=mysql &” >> /etc/rc.local   #/usr/local/bin/safe_mysqld --user=mysql & 启动mysql服务  2、设置数据库   添加mysql用户:   1)使用webmin->mysql数据库服务器->用户权限,添加用户postfix, 密码postfix,主机localhost,并设置拥有相应的权限。   2)使用SQL语句添加用户:   #cd /usr/local/bin   #./mysql CD mysql Cp   Password:   mysql>INSERT INTO user (host,user,password)   ->VALUES (‘localhost’,‘postfix’,’’);   Query OK. I row affected (0.00 sec)   mysql>UPDATA user SET password=password(‘postfix’)   ->WHERE user=’postfix’;   Rows matched: 1 Changed: 1 Warnings: 0   mysql>FLUSH PRIVILEGES;   Query OK. 0 rows affected (0.01 sec)   mysql>GRANT select,insert,update on mail.* TO postfix   Query OK. 0 rows affected (0.01 sec)   mysql>exit  向数据库中添加表:   #cd /usr/local/bin/   #ee postfix.sql   CREATE DATABASE;   GRANT ALL ON mail.* mail@localhost IDENTIFIED BY “postfix”;   FLUSH PRIVILEGES;   use mail;   CREATE TABLE forward (   username varchar(255) NOT NULL default ‘’, //本机地址   forward_addr varchar(255) default NULL, //转发地址   PRIMARY KEY (username)   ) TYPE=MyISAM;   CREATE TABLE transport (   domain varchar(255) NOT NULL default ‘’, //邮件域   transport varchar(icon_cool.gif default NULL, //处理方式   PRIMARY KEY (domain)   ) TYPE=MyISAM;   CREATE TABLE users (   username varchar(128) NOT NULL default ‘’, //用户名   domain varchar(128) NOT NULL default ‘’, //邮件域  address varchar(128) NOT NULL default ‘’, //邮件地址   password varchar(128) NOT NULL default ‘’, //用户密码(明文)   uid int(6) NOT NULL default ‘1024’, //uid   gid int(6) NOT NULL default ‘1024’, //gid   home varchar(255) NOT NULL default ‘/’, //home目录   maildir varchar(255) NOT NULL default ‘’, //maildir目录   quota varchar(255) NOT NULL default ‘’, //邮箱容量   mailok tinyint(3) NOT NULL default ‘1’,   bool1 tinyint(3) NOT NULL default ‘1’,   bool2 tinyint(3) NOT NULL default ‘1’,   PRIMARY KEY (address),   UNIQUE KEY address (address),   KEY address_2 (address)   ) TYPE=MyISAM;   输入完毕后保存退出。   #./mysql Cu postfix Cp < postfix.sql   #password:postfix   向表中添加数据:   #/usr/local/bin   #./mysql Cu postfix Cp  password:******   mysql>use mail   mysql>INSERT INTO transport (domain,transport)   ->VALUES (’localhost.com’,’virtual:’);   mysql>INSERT INTO users (username,domain,address,password,uid,gid,   home,maildir,quota,mailok,bool1,bool2)   ->VALUES (‘test’,’localhost.com’,’test.localhost.com’, ’test’,’1024’,’1024’,’/’,’/var/postfix_mail/test/Maildir/’,’5000000’,’1’,’1’,’1’);   mysql>exit   三、安装CYRUS-SASL   #tar Czxvf cyrus-sasl-1.5.27   #cd cyrus-sasl-1.5.27   #./configure --with-pwcheck=/var/pwcheck --enable-login   --enable-plain   #make   #make install   #echo /usr/local/lib/ >> /etc/ld.so.conf   #echo /usr/local/lib/mysql/ >> /etc/ld.so.conf   #ldconfig   #cp /usr/local/include/* /usr/include  #cp /usr/local/lib/lib*.* /usr/lib   #ln Cs /usr/local/lib/sasl /usr/lib/sasl   #ln Cs /usr/local/include/mysql /usr/include/mysql   #ln Cs /usr/local/lib/mysql /usr/lib/mysql   在/usr/local/lib/sasl下建立文件smtpd.conf,添加一下内容:   pwcheck_method:mysql   mysql_user:postfix   mysql_passwd:postfix   mysql_host:localhost   mysql_database:mail   mysql_table:users   mysql_uidcol:address   mysql_pwdcol:password   四、安装和设置postfix   1、安装postfix   1)编译/etc/rc.conf,设置sendmail_enable=”NO”   #mv /usr/bin/newaliases /usr/bin/newaliases.OFF   #mv /usr/bin/mailq /usr/bin/mailq.OFF   #mv /usr/sbin/sendmail /usr/sbin/sendmail.OFF  #pw groupadd postfix Cg 1024   #pw groupadd postdrop Cg 1025   #pw useradd postfix Cu 1024 Cg postfix   #echo ‘postfix:root’ >> /etc/aliases   2)安装postfix和相应的quota补丁   #tar zxvf postfix-1.1.11.tar.gz   #patch < postfix-1.1.11_quota_maildirsize.patch   #make Cf Makefile.init makefiles ‘CCARGS=-DUSE_SASL_AUTH   CDHAS_MYSQL CI/usr/include/mysql’ ‘AUXLIBS=-L/usr/lib/mysql   Clmysqlclient Clasal Clz Clm’   #make   #make install 按照默认路径一路回车就可以安装成功postfix,如果出错,在提示“tempdir”时输入:/tmp,这样一般就可以通过。   2、设置postfix   postfix默认安装到/etc/postfix目录下,设置文件也在这   #cd /etc/postfix   1)编译主配置文件main.cf   #ee main.cf 添加如下内容   #Base configure   myhostname = mail.localhost.com //本机的机器名  mydomain = local.com //域名   mynetworks = 127.0.0.0/8 192.168.0.0/16 //允许不经smtp认证能发信的ip段   home_mailbox = Maildir/ //使用的邮箱格式为Maildir/   smtpd_banner = Welcome to localhost.com mail system! //smtp的欢迎信息   #Mysql configure   transport_maps = mysql:/etc/postfix/transport.cf   //指定那些域的邮件可以被postfix收下来   virtual_mailbox_base =/ //指定用户邮箱所在的根目录   virtual_uid_maps = mysql:/etc/postfix/ids.cf //指定postfix帐号的ID   virtual_gid_maps = mysql:/etc/postfix/gds.cf //指定postfix组的ID   virtual_mailbox_maps = mysql:/etc/postfix/users.cf //指定用户邮箱的目录   virtual_maps = mysql:/etc/postfix/forward.cf //指定自动转发邮件的设置   #Quota configure   message_size_limit = 5000000 //单个邮件大小的限制   virtual_mailbox_limit = 5000000 //默认的邮箱大小   virtual_mailbox_limit_maps = mysql:/etc/postfix/quota.cf   //每个用户的邮箱大小   virtual_mailbox_limit_override = yes //是否允许覆盖默认的邮箱大小   #smtp configure   smtpd_sasl_auth_enable = yes   smtpd_sasl_local_domain = $myhostname   smtpd_recipient_restrictions = permit_mynetworks   permit_sasl_authenticated permit_auth_destination reject   smtpd_sasl_security_options = noanonymous   smtpd_client_restrictions = permit_sasl_authenticated   inet_interfaces = all //监听所有端口   inet_interfaces = 192.168.80.21 //是外面的用户也可以发送邮件   2)查看master.cf文件必须包含下面一行   Virtual unix - n n - - virtual   3)编译transport.cf   #touch transport.cf   #ee transport.cf 添加如下内容   user = postfix   password = postfix   dbname = mail   table = transport   select_field = transport   where_field = domain   hosts = localhost

4)编译ids.cf   #touch ids.cf   #ee ids.cf   user = postfix   password = postfix   dbname = mail   table = users   select_field = uid   where_field = address   hosts = localhost   5)编译gds.cf   #touch gds.cf   #ee gds.cf   user = postfix   password = postfix   dbname = mail   table = users   select_field = gid   where_field = address   hosts = localhost  6)编译forward.cf   #touch forward.cf   #ee forward.cf   user = postfix   password = postfix   dbname = mail   table = forward   select_field = forward_addr   where_field = username   hosts = localhost   7)编译users.cf   #touch users.cf   #ee users.cf   user = postfix   password = postfix   dbname = mail   table = users   select_field = maildir   where_field = address   hosts = localhost  8)编译quota.cf   #touch quota.cf   #ee quota.cf   user = postfix   password = postfix   dbname = mail   table = users   select_field = quota   where_field = address   hosts = localhost   3、启动postfix   #/usr/sbin/postfix start   postfix/postfix-script: starting the Postfix mail system   #echo “/usr/sbin/postfix start” >> /etc/rc.local   #telnet localhost 25   Connected to localhost.localhost.com.   Escape character is ‘^]’.   220 Welcome to localhost mail system!   4、测试postfix   1)建立mail邮件存放目   #cd /var   #mkdir postfix_mail   #chown CR postfix:postfix /var/postfix_mail   2)使用客户端发邮件   此时可以使用客户端的foxmail或者outlook向用户test.localhost.com发送邮件,然后到/var/postfix/test/Maildir/下查看邮件,如果能收到说明SMTP已经工作正常了,如果有问题仔细检查自己的每个步骤。

03-14 23:43