星期六, 十月 23, 2010

Mail server install on Ubuntu

1, postfix的安装

1.1 从安装源安装
sudo apt-get install postfix

1.2 编辑/etc/postfix/main.cf
如果没有,可以运行dpkg-reconfigure postfix来重新生成配置信息。
sudo vim /etc/postfix/main.cf
修改:mydestination 和 mynetworks。

添加:
home_mailbox = Maildir/
mailbox_command =

1.3 测试postfix的安装
sudo /etc/init.d/postfix restart

1.4 安装测试用命令工具
sudo apt-get install mailutils

测试smtp是否正常
netcat localhost 25 (telnet localhost 25)
ehlo localhost
mail from: bulain@localhost
rcpt to: bulain@localhost
data
Subject: My first mail for my domain
Hi,
Are you there?
regards,
Admin
. (and Enter In a new Line)
quit

测试邮件目录mailbox
su - bulain
cd Maildir/new
ls

2,courier-pop,courier-imap的安装

2.1 从安装源安装
sudo apt-get install courier-pop courier-imap

2.2 测试pop3是否正常
netcat localhost 110
Connected to localhost (127.0.0.1).
Escape character is '^]'.
+OK Hello there.
user bulain
+OK Password required.
pass password
+OK logged in.
quit

2.3 测试IMAP是否正常
netcat localhost 143
* OK [CAPABILITY IMAP4rev1 UIDPLUS CHILDREN NAMESPACE THREAD=ORDEREDSUBJECT THREAD=REFERENCES SORT QUOTA IDLE ACL ACL2=UNION STARTTLS XCOURIEROUTBOX=INBOX.Outbox] Courier-IMAP ready. Copyright 1998-2005 Double Precision, Inc. See COPYING for distribution information.
a login bulain password
a OK LOGIN Ok.
a logout



3,mysql的安装

3.1 从安装源安装
sudo apt-get install mysql-server mysql-client

3.2 测试mysql的安装
mysql -u root -p
连接成功代表安装成功。


4, PHP的安装

4.1 从安装源安装
sudo apt-get install php5

5, apache2的安装

5.1 从安装源安装
sudo apt-get install apache2

5.2 测试apache2的安装
sudo /etc/init.d/apache restart
打开 http://localhost 代表成功。

6,phpmyadmin的安装

6.1 从安装源安装
sudo apt-get install phpmyadmin

6.2 配置apache2
ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf.d/phpmyadmin

6.3 测试phpmyadmin
打开http://localhost/phpmyadmin
输入mysql用户名,密码,登陆成功代表登陆成功。

7,postfixadmin的安装

7.1 从安装源安装
sudo apt-get install postfixadmin
sudo apt-get install postfix-mysql
sudo apt-get install courier-authlib-mysql

7.2 添加mysql数据库
mysql -u root -p
create database postfix;
grant all on postfix.* to postfixadmin@localhost identified by 'postfixadmin';
grant select on postfix.* to postfix@localhost identified by 'postfix';
flush privileges;

7.3 配置postfixadmin
sudo vim /etc/postfixadmin/config.inc.php
找到如下地方,进行修改。
$CONF['database_type'] = 'mysqli';
$CONF['database_host'] = 'localhost';
$CONF['database_user'] = 'postfixadmin';
$CONF['database_password'] = 'postfixadmin';
$CONF['database_name'] = 'postfix';
$CONF['database_prefix'] = '';

7.4 配置apache2
ln -s /etc/postfixadmin/apache.conf /etc/apache2/conf.d/postfixadmin

7.5 测试postfixadmin
打开http://localhost/postfixadmin/
能够打开页面代表成功。
根据提示进行修改即可(并修改页面上的连接)。

7.6 修改postfix存取数据库。
sudo vim /etc/postfix/mysql_relay_domains_maps.cf
添加以下内容
user = postfix
password = postfix
hosts = 127.0.0.1
dbname = postfix
table = domain
select_field = domain
where_field = domain
additional_conditions = and backupmx = '1'

sudo vim /etc/postfix/mysql_virtual_alias_maps.cf
添加以下内容
user = postfix
password = postfix
hosts = 127.0.0.1
dbname = postfix
table = alias
select_field = goto
where_field = address

sudo vim /etc/postfix/mysql_virtual_domains_maps.cf
添加以下内容
user = postfix
password = postfix
hosts = 127.0.0.1
dbname = postfix
table = domain
select_field = domain
where_field = domain
#additional_conditions = and backupmx = '0' and active = '1'

sudo vim /etc/postfix/mysql_virtual_mailbox_limit_maps.cf
添加以下内容
user = postfix
password = postfix
hosts = 127.0.0.1
dbname = postfix
table = mailbox
select_field = quota
where_field = username
#additional_conditions = and active = '1'


sudo vim /etc/postfix/mysql_virtual_mailbox_maps.cf
添加以下内容
user = postfix
password = postfix
hosts = 127.0.0.1
dbname = postfix
table = mailbox
select_field = maildir
where_field = username
#additional_conditions = and active = '1'


修改/etc/postfix/main.cf
sudo vim /etc/postfix/main.cf
添加以下内容。

# Virtual Mailbox Domain Settings
virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf
virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
virtual_mailbox_limit = 51200000
virtual_minimum_uid = 5000
virtual_uid_maps = static:5000
virtual_gid_maps = static:5000
virtual_mailbox_base = /home/vmail
virtual_transport = virtual

# Additional for quota support
virtual_create_maildirsize = yes
virtual_mailbox_extended = yes
virtual_mailbox_limit_maps = mysql:/etc/postfix/mysql_virtual_mailbox_limit_maps.cf
virtual_mailbox_limit_override = yes
virtual_maildir_limit_message = Sorry, the your maildir has overdrawn your diskspace quota, please free up some of spaces of your mailbox try again.
virtual_overquota_bounce = yes

修改/etc/courier/authdaemonrc
sudo vim /etc/courier/authdaemonrc
修改一下内容:
authmodulelist="authmysql"

修改/etc/courier/authmysqlrc
sudo vim /etc/courier/authmysqlrc
修改一下内容:
MYSQL_SERVER localhost
MYSQL_USERNAME postfix
MYSQL_PASSWORD postfix
MYSQL_SOCKET /var/run/mysqld/mysqld.sock
MYSQL_OPT 0
MYSQL_DATABASE postfix
MYSQL_USER_TABLE mailbox
MYSQL_CRYPT_PWFIELD password
MYSQL_UID_FIELD '5000'
MYSQL_GID_FIELD '5000'
MYSQL_LOGIN_FIELD name
MYSQL_HOME_FIELD '/home/vmail'
MYSQL_NAME_FIELD name
MYSQL_MAILDIR_FIELD maildir

修改:/etc/postfix/main.cf
sudo vim /etc/postfix/main.cf
修改内容如下:
mydestination=
mynetworks=

7.7 测试postfix收发邮件。
注意:新建域名时用互联网上存在的域名,如:gmail.com

8,squirrelmail的安装

8.1 从安装源安装
sudo apt-get install squirrelmail

8.2 配置apache2
ln -s /etc/squirrelmail/apache.conf /etc/apache2/conf.d/squirrelmail

8.3 测试squirrelmail
打开http://localhost/squirrelmail/
能够登陆代表成功。


9,roundcube的安装

9.1 下载roundcubemail-0.3.1.tar.gz

9.2 安装roundcube
tar zxvf roundcubemail-0.3.1.tar.gz
sudo mv roundcubemail /usr/share/roundcubemail
sudo chown www-data:www-data {/usr/share/roundcubemail/logs, /usr/share/roundcubemail/temp}

9.3 创建mysql数据库
mysql -u root -p
create database roundcube;
grant all on roundcube.* to roundcube@localhost identified by 'roundcube';
flush privileges;

9.4 建表
mysql -u root -p
use roundcube;
source /usr/share/roundcubemail/SQL/mysql.initial.sql;

9.5 修改roundcube配置。
sudo cp /usr/share/roundcubemail/config/db.inc.php.dist /usr/share/roundcubemail/config/db.inc.php
sudo vim /usr/share/roundcubemail/config/db.inc.php
修改以下地方:
$rcmail_config['db_dsnw'] = 'mysql://roundcube:roundcube@localhost/roundcube';

sudo cp /usr/share/roundcubemail/config/main.inc.php.dist /usr/share/roundcubemail/config/main.inc.php
sudo vim /usr/share/roundcubemail/config/main.inc.php
修改以下地方:
$rcmail_config['smtp_user'] = '%u';
$rcmail_config['smtp_pass'] = '';
$rcmail_config['enable_installer'] = true;

9.6 测试roundcube
打开http://localhost/roundcube/installer
根据提示进行配置。

没有评论: