1. 系统配置
a) 安装cvsup
#cd /usr/ports/net/cvsup-without-gui
#make install clean
#reboot
#cvsup -gL 2 -h cvsup4.freebsdchina.org /usr/share/examples/cvsup/ports-supfile
这个过程大概要40分钟
b) 配置主机名
编辑/etc/rc.conf,修改文件中以下内容
ifconfig_em0="inet 61.186.252.144 netmask 255.255.255.224"
defaultrouter="61.186.252.129"
hostname="mail2.csdn.net"
2. 安装Mysql、Apache、PHP、FTP
a) 安装Mysql
#cd /usr/ports/databases/mysql41-server
#make install clean
#在/etc/rc.conf 中加入下面内容,以便msyql 在开机时随系统启动。
mysql_enable=”YES”
cp /usr/local/share/mysql/my-small.cnf /usr/local/etc/my.cnf
在my.cnf 里增加地址的绑定,以提高安全性。(如果你的数据库只限在本地操作)
[mysqld]
bind_address=127.0.0.1
测试Mysql
#mysql
#mysqladmin -u root password ******
b) 安装Apache2
#cd /usr/ports/www/apahce2
#make install clean
在/etc/rc.conf 中加入下面内容。
apache2_enable=”YES”
c) 安装mod_php4
#cd /usr/ports/www/mod_php4
#make install clean
安装完成后,在/usr/local/etc/apahce2/httpd.conf 加入下面的内容
DirectoryIndex index.html index.html.var index.php
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
#/usr/local/etc/rc.d/apache2.sh restart
d) 安装php4-extensions
#cd /usr/ports/lang/php4-extensions
#make install clean
我选择了下面的模块:
[X]BCMATH
[X]BZ2
[X]CRACK
[X]CTYPE
[X]CURL
[X]FTP
[X]GETTEXT
[X]IMAP
[X]LDAP
[X]MCRYPT
[X]MYSQL (注一定要选上)
[X]OVERLOAD
[X]PCRE
[X]POSIX
[X]SESSION
[X]TOKENIZER
[X]XML
[X]XMLRPC
[X]ZIP
[X]ZLIB
PHP 支持的模块可以参考/usr/local/etc/php/extensions.ini
e) 安装Zend
由于版权问题, 系统不会自动下载该软件包。需要到zend 的网站
(https://www.zend.com/store/free_download.php?pid=13)下载FreeBSD 的版本,放到
/usr/ports/distfiles 中,再进行安装。
#cd /usr/ports/devel/ZendOptimizer
#make install clean
安装完成后在/usr/local/etc/php.ini 添加下面的内容。
[Zend]
zend_optimizer.optimization_level=15
zend_extension_manager.optimizer="/usr/local/lib/php/20020429/Optimizer"
zend_extension_manager.optimizer_ts="/usr/local/lib/php/20020429/Optimizer_TS"
zend_extension="/usr/local/lib/php/20020429/ZendExtensionManager.so"
zend_extension_ts="/usr/local/lib/php/20020429/ZendExtensionManager_TS.so"
f) 安装openssl
#cd /usr/ports/security/openssl-beta
#make install clean
g) 安装phpmyadmin
#cd /usr/ports/databases/phpmyadmin
#make fetch
下载完成后,进入/usr/port/distfiles 目录解压,并移动或复制到/usr/local/www/data 目录中
#cd /usr/ports/distfiles
#tar jxvf phpMyAdmin-<chsdate w:st="on" year="1899" month="12" day="30" islunardate="False" isrocdate="False">2.6.4</chsdate>-pl3.tar.bz2
# mv phpMyAdmin-<chsdate w:st="on" year="1899" month="12" day="30" islunardate="False" isrocdate="False">2.6.4</chsdate>-pl3 /usr/local/www/data/phpmyadmin
配置phpmyadmin 打开/usr/local/www/data/phpmyadmin/config.inc.php 修改
$cfg['Servers'][$i]['auth_type'] = 'http';
h) 测试PHP 与apache
安装完成后,在/usr/loca/www/data/目录中建立phpinfo.php 以测试apache 与php
的安装是否成功。
#cd /usr/local/www/data/
# echo '<?phpinfo ()?>'>phpinfo.php
打开浏览器输入http://61.186.252.144/phpinfo.php
为了安全成见,测试完后把此文件删除
i) 安装pure-ftp
在系统中常常需要使用到FTP 进行上传文件,所以加进来,当成平时的笔记吧。
#cd /usr/ports/ftp/pure-ftpd
#make install clean
#在/etc/rc.conf 添加
pureftpd_enable=”YES”
复制配置文件,此配置使用的是系统用户。上传文件的位置在/home/你自己的帐号中
#cp /usr/local/etc/pure-ftpd.conf.sample /usr/local/etc/pure-ftpd.conf
#下面的网址有详细的pure-ftp + mysql 安装教程
http://machiel.generaal.net/index.php?subject=pureftpd&language=eng
3. 安装邮件系统软件
a) 设置数据库
本系统使用extman 作为系统数据库,将Extman 上传到机器中解压后执行下面命令。
Extman 下载地址:http://www.extmail.org/cgi-bin/download.cgi
# tar xzfv extman-0.12.tar.gz
#cd extman-0.12-20051216/docs
导入数mysql 数据
#mysql –u root –p
#mysql –u root –p <init.sql></init.sql>
打开phpmyadmin 可看到多了一个数据库,并有一条记录
Extman 密码在用户名和密码在init.sql 可以打开修改。
b) 安装courier-imap
# cd /usr/ports/mail/courier-imap/
# make install clean
只选择 OPENSSL 及 AUTH_MYSQL
在/etc/rc.conf 加入
courier_authdaemond_enable="YES"
courier_imap_pop3d_enable="YES"
courier_imap_imapd_enable="YES"
复制配置文件
#cd /usr/local/etc/courier-imap
#cp imapd.cnf.dist imapd.cnf
#cp pop3d.cnf.dist pop3d.cnf
启动authdaemond
#/usr/local/etc/rc.d/courier-authdaemond.sh start
注意如果你在/etc/rc.conf 配置文件中写错了服务名,执行脚本会出现 no found关于服务名可以打开 /usr/local/etc/rc.d/ 下对应的sh 文件,查找name 这一项。如 name="courier_imap_imapd"#authdaemond 运行后会在/var/run/authdaemond/下产生socket,如果没有产生,则认证无法通过。
#chmod +x /var/run/authdaemond
c) 安装cyrus-sasl
#cd /usr/ports/security/cyrus-sasl2
#make install WITH_AUTHDAEMON=yes
创建/usr/local/lib/sasl2/smtpd.conf 输入下面的内容
pwcheck_method:authdaemond
log_level:3
mech_list:PLAIN LOGIN
authdaemond_path:/var/run/authdaemond/socket
d) 安装postfix
#cd /usr/ports/mail/postfix
# make install clean
选择SASL2 TLS MYSQL VDA
回答下面的问题
You need user "postfix" added to group "mail".(你必须将用户postfix 加入到mail 组里)
Would you like me to add it [y]? y (你希望添加吗?)
Would you like to activate Postfix in /etc/mail/mailer.conf [n]? n
#在/etc/rc.conf 添加下面的内容
sendmail_enable="YES" #这一句可以不要。
sendmail_flags="-bd"
sendmail_pidfile="/var/spool/postfix/pid/master.pid"
sendmail_outbound_enable="NO"
sendmail_submit_enable="NO"
sendmail_msp_queue_enable="NO"
做相关连接.
#cd /usr/local/etc/rc.d
#ln -s /usr/local/sbin/postfix postfix.sh
#ln -s /usr/local/sbin/sendmail /usr/sbin/sendmail
#注,如果/usr/sbin/sendmail 存在,先删了再做连接.
#echo postfix: root >> /etc/aliases
#/usr/local/bin/newaliases
#chown postfix:postfix /etc/opiekeys
4. 配置服务器
a) 创建/etc/periodic.conf
daily_clean_hoststat_enable="NO"
daily_status_mail_rejects_enable="NO"
daily_status_include_submit_mailq="NO"
daily_submit_queuerun="NO"
b) 配置postfix
修改/usr/local/etc/postfix/main.cf 在文件最后加入下面内容。
smtp_helo_required = yes
strict_rfc821_evelopes = yes
smtp_etrn_restrictions = permit_mynetworks,reject
###################BASE##################
myhostname=mail2.csdn.net
mydomain = csdn.net
mydestination = $myhostname
local_recipient_maps =
command_directory = /usr/local/sbin
local_transport = virtual
message_size_limit = 10240000
#################MySQL################
virtual_alias_maps =mysql:/usr/local/etc/postfix/mysql_virtual_alias_maps.cf
virtual_gid_maps = static:125
virtual_mailbox_base = /home/domains
virtual_mailbox_domains =mysql:/usr/local/etc/postfix/mysql_virtual_domains_maps.cf
virtual_mailbox_limit = 104857600
virtual_mailbox_maps = mysql:/usr/local/etc/postfix/mysql_virtual_mailbox_maps.cf
virtual_minimum_uid = 125
virtual_transport = virtual
virtual_uid_maps = static:125
################Quota################
virtual_create_maildirsize = yes
virtual_mailbox_extended = yes
virtual_mailbox_limit_maps =mysql:/usr/local/etc/postfix/mysql_virtual_mailbox_limit_maps.cf
virtual_mailbox_limit_override = yes
virtual_maildir_limit_message = Sorry,the user's Maildir has overdrawn his diskspace
quota ,please tray again later.
virtual_overquota_bounce = yes
##############SASL####################
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_clients = noanonymous
broken_sasl_auth_clients = yes
smtpd_delay_reject = yes
smtpd_recipient_restrictions = permit_sasl_authenticated
reject_non_fqdn_sender
reject_unknown_sender_domain
reject_unknown_recipient_domain
reject_non_fqdn_recipient
reject_unauth_destination
smtpd_client_restrictions = permit_sasl_authenticated
确认/usr/local/etc/postfix/master.cf 有下面的内容。
virtual unix - n n - - virtual
将extman docs 目录下mysql_virtual 开头的文件复制到/usr/local/etc/postfix/
#cp mysql_virtual_* /usr/local/etc/postfix/
修改extman以支持激活及磁盘限额,以下用cat看到的文件内容
mail# cat /usr/local/etc/postfix/mysql_virtual_alias_maps.cf
user = extmail
password = extmail
hosts = localhost
dbname = extmail
#table = alias
#select_field = goto
#where_field = address
query = SELECT goto FROM alias WHERE address= '%s' AND active = 1
mail# cat /usr/local/etc/postfix/mysql_virtual_domains_maps.cf
user = extmail
password = extmail
hosts = localhost
dbname = extmail
#table = domain
#select_field = description
#where_field = domain
query = SELECT description FROM domain WHERE domain ='%s' AND active = 1
mail# cat /usr/local/etc/postfix/mysql_virtual_mailbox_limit_maps.cf
user = extmail
password = extmail
hosts = localhost
dbname = extmail
#table = mailbox
#select_field = quota
#where_field = username
#additional_conditions = and active = '1'
query = SELECT quota FROM mailbox WHERE username='%s' AND active = 1
mail# cat /usr/local/etc/postfix/mysql_virtual_mailbox_maps.cf
user = extmail
password = extmail
hosts = localhost
dbname = extmail
#table = mailbox
#select_field = maildir
#where_field = username
#additional_conditions = and active = '1'
query = SELECT maildir FROM mailbox WHERE username = '%s' AND active = 1
c) 配置Courier-imap
修改Courier 相关设置,/usr/local/etc/courier-imap/imapd:
IMAP_CAPABILITY="IMAP4rev1 CHILDREN NAMESPACE THREAD=ORDEREDSUBJECT THREAD=REFERENCES SORT QUOTA"
修改/usr/local/etc/courier-imap/pop3d
POP3AUTH="LOGIN CRAM-MD5 CRAM-SHA1"
修改/usr/local/etc/authlib/authmysqlrc
注意中间的是tab 键
MYSQL_SERVER localhost
MYSQL_USERNAME extmail
MYSQL_PASSWORD extmail
MYSQL_PORT 0
MYSQL_OPT 0
MYSQL_DATABASE extmail
MYSQL_USER_TABLE mailbox
MYSQL_CRYPT_PWFIELD password
MYSQL_UID_FIELD '125'
MYSQL_GID_FIELD '125'
MYSQL_LOGIN_FIELD username
MYSQL_HOME_FIELD concat('/home/domains/',homedir)
MYSQL_NAME_FIELD name
MYSQL_MAILDIR_FIELD concat('/home/domains/',maildir)
MYSQL_QUOTA_FIELD quota
修改/usr/local/etc/authlib/authdaemonrc
authmodulelist="authmysql"
authmodulelistorig="authmysql"
version="authdaemond.mysql"
daemons=5
authdaemover=/var/run/authdaemond
subsystem=mail
DEBUG_LOGIN=0
DEFAULTOPTIONS="wbnodsn=1"
至此邮件系统的基本已经安装完成。重启系统后开始测试。
5. 测试邮件系统
#chown postfix:postfix /home/domains
a) 打开maillog
maillog 是测试邮件是否成功的重要信息。每一个邮件动作都会在maillog 里生成一条记录。
b) 安装p5-MIME-Base64
因为系统在认证时使用的是BASE64 编码,此时需要对用名和密码进行展换。如果你觉得不好用,可
以使用下面的网站。
http://www.sharesky.cn/base64.php?en=填你要编码的内容。
#cd /usr/ports/converters/p5-MIME-Base64/
#make install clean
进行BASE64 编码,extmail 里有一个测试用户,用户名为[email protected] 密码为test
#perl -MMIME::Base64 -e 'print encode_base64("test\@extmail.org");'
dGVzdEBleHRtYWlsLm9yZw==
# perl -MMIME::Base64 -e 'print encode_base64("test");'
dGVzdA==
#tail –f /var/log/maillog #注意,不要退出来。
c) 发送测试
以#开头的为要输入的部分
#telnet localhost 25
#ehlo mail #问候,后面mail 是主机名,可以用localhost 代替
250-mail2.csdn.net
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-AUTH LOGIN PLAIN
250-AUTH=LOGIN PLAIN
250 8BITMIME
#auth login #认证
334 VXNlcm5hbWU6
#dGVzdEBleHRtYWlsLm9yZw== #用户名 [email protected]
334 UGFzc3dvcmQ6
#dGVzdA== #密码 test
235 Authentication successful
#mail from:[email protected] #寄件人
250 Ok
#rcpt to: [email protected] #收件人
250 Ok
#data #开始输入邮件内容。
354 End data with <cr><lf>.<cr><lf></lf></cr></lf></cr>
#this is a test! #邮件内容。
. #注意,这个点是结束这封邮件的输入。
250 Ok: queued as 491851D #放入到邮件队列里。
#quit #发送完成,退出。
221 Bye
Connection closed by foreign host.
d) 收信测试
e) 配置extman和extmail
#mv extman-0.12 extman
#cp extman /usr/home/httpd/mail/extman/
#cd /usr/home/httpd/mail/extman/libs/Ext
#rm CGI.pm Session.pm Config.pm Utils.pm Lang.pm RFC822.pm
下载extmail
#tar xzfv extmail-0.23-20060104.tar.gz
#mv extmail-0.23-20060104 extmail
#mv extmail /home/httpd/mail/
#cd /home/httpd/mail/extmail/libs/Ext/
#cp CGI.pm Session.pm Config.pm Utils.pm Lang.pm RFC822.pm /home/httpd/mail/extman/libs/Ext/
#cd /usr/home/httpd/mail/extman
修改 /home/httpd/mail/extman/webman.cf
#vi webman.cf
SYS_CONFIG = /home/httpd/mail/extman/
SYS_LANGDIR = /home/httpd/mail/extman/lang
SYS_TEMPLDIR = /home/httpd/mail/extman/html
安装p5-Apache-DBI
#cd /usr/ports/www/p5-Apache-DBI
#make install clean
安装p5-DBD-mysql
#/usr/ports/databases/p5-DBD-mysql41
#make install clean
配置Apache,编辑 httpd.conf
#vi httpd.conf
<virtualhost></virtualhost>
Mso
评论