ubuntu上搭建postfix+extmail(实战笔记)

 

sudo aptitube install postfix-mysql courier-authlib-mysql courier-pop libsasl2-modules-sql maildrop apache2-suexec-custom libunix-syslog-perl rsync mailgraph ntpdate apache2 libapache2-mod-fcgid sasl2-bin libsasl2-2 libsasl2-modules postfix


上传到/var/soft目录

extmail-1.2.tar.gz

extman-1.1.tar.gz

解压

sudo tar zxvf extmail-1.2.tar.gz

sudo tar zxvf extman-1.1.tar.gz

复制

sudo cp -R extmail-1.2 /var/www/extmail

sudo cp -R extman-1.1 /var/www/extman

添加权限相关

sudo groupadd -g 1007 vgroup

sudo useradd -g 1007 -u 1007 -s /bin/false -d /home/domains vuser

sudo mkdir /home/domains/

sudo chown -R 1007:1007 /home/domains

sudo chown -R 1007:1007 /var/www/extmail/cgi/

sudo chown -R 1007:1007 /var/www/extman/cgi/

设置 Extmail & Extman 配置文件

sudo cp /var/www/extmail/webmail.cf.default /var/www/extmail/webmail.cf

sudo cp /var/www/extman/webman.cf.default /var/www/extman/webman.cf


修改extman配置文件

sudo vi /var/www/extman/webman.cf

修改默认文件中的

帐号的ID配置

# sys_default_uid, if not set, webman will ignore it

SYS_DEFAULT_UID = 1007

# sys_default_gid, if not set, webman will ignore it

SYS_DEFAULT_GID = 1007

修改MYSQL配置信息

# if mysql, all relate paramters should prefix as SYS_MYSQL

SYS_MYSQL_USER = webman

SYS_MYSQL_PASS = password  #修改成自己的密码

SYS_MYSQL_DB = extmail

SYS_MYSQL_HOST = localhost

SYS_MYSQL_SOCKET = /tmp/mysql.sock


修改exttmail配置文件

sudo vi /var/www/extmail/webmail.cf

修改MYSQL配置信息

# if mysql, all relate parameters should prefix as SYS_MYSQL

SYS_MYSQL_USER = extmail

SYS_MYSQL_PASS = password #这里设置为自己的密码

SYS_MYSQL_DB = extmail

SYS_MYSQL_HOST = localhost

SYS_MYSQL_SOCKET = /tmp/mysql.sock


准备导入数据库信息

sudo vi /var/www/extman/docs/extmail.sql

修改用户的ID号

  uidnumber int(6) NOT NULL default '1007',

  gidnumber int(6) NOT NULL default '1007',

导入Extmail数据库

sudo /usr/local/webserver/mysql/bin/mysql -uroot -p < /var/www/extman/docs/extmail.sql

sudo /usr/local/webserver/mysql/bin/mysql -uroot -p < /var/www/extman/docs/init.sql


apache配置

cd /etc/apache2/mods-enabled/

sudo ln -s ../mods-available/suexec.load ./suexec.load

cd /etc/apache2/sites-enabled/

sudo rm -rf /etc/apache2/sites-enabled/000-default  #删除了本来的默认站点信息

sudo vi /etc/apache2/sites-enabled/extmail

<VirtualHost *:1312>

ServerName mail.jiukewang.com

DocumentRoot /var/www/extmail/html/

ScriptAlias /extmail/cgi/       /var/www/extmail/cgi/

Alias /extmail                  /var/www/extmail/html/

ScriptAlias /extman/cgi/        /var/www/extman/cgi/

Alias /extman                   /var/www/extman/html/

# Suexec config

# 屏蔽这里,不知道为什么我加了这里一定出错,权限问题,不过我配置了的,没搞懂

#SuexecUserGroup vuser vgroup 

</VirtualHost>

修改apache2.conf配置文件

sudo vi /etc/apache2/apache2.conf

修改

# These need to be set in /etc/apache2/envvars

#User ${APACHE_RUN_USER}

#Group ${APACHE_RUN_GROUP}

User vuser

Group vgroup

这里修改使用这个用户来启动apache

 

因为端口我用的1312所以需要修改/etc/apache2/ports.conf

sudo vi /etc/apache2/ports.conf

NameVirtualHost *:1312

Listen 1312

关于端口配置这里个人需要根据自己的情况配置哈


postfix配置

cd /var/www/extman/docs/

sudo cp mysql_virtual_*.cf /etc/postfix/  #拷贝了需要的配置文件到postfix配置下

sudo chmod o= /etc/postfix/mysql_virtual_*.cf  

sudo chgrp postfix /etc/postfix/mysql_virtual_*.cf #这些配置文件组权限赋予postfix

cd /etc/postfix/

#替换这些文件中的localhost为127.0.0.1

#这一步后来没有用到,因为那些文件中的配置信息都改成了localhost,127.0.0.1链接总是有问题,可选

#sudo find ./ -name 'mysql_virtual_*' -exec sed --in-place 's/localhost/127.0.0.1/g' {} \;  

开始修改配置文件main.cf

文件内容如下:

# See /usr/share/postfix/main.cf.dist for a commented, more complete version

smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU)

biff = no

append_dot_mydomain = no

#本机机器名

myhostname = mail.jiukewang.com

#本机域名

mydomain = jiukewang.com

myorigin = $mydomain

alias_maps = hash:/etc/aliases

alias_database = hash:/etc/aliases

#收信域名,一定要有$mydomain不然不能使用[email protected]收信

mydestination =

relayhost =

#信任的,无须SMTP认证的地址范围

mynetworks = 127.0.0.0/8

mailbox_size_limit = 0

recipient_delimiter = +

inet_interfaces = all

#邮件的存储方式,一定要有此设置

home_mailbox = Maildir

append_dot_mydomain = no

append_at_myorigin = no

smtpd_helo_required = yes

ignore_mx_lookup_error = yes

message_size_limit = 31457280

#--------- virtual config --------------------------------------

#本地邮件的投递方式,也可以使用maildrop

local_transport = maildrop

#虚拟用户的投递方式,也可以使用maildrop

virtual_transport = maildrop

maildrop_destination_recipient_limit = 1

virtual_alias_domains =

virtual_alias_maps =

   proxy:mysql:/etc/postfix/mysql_virtual_sender_maps.cf,

   proxy:mysql:/etc/postfix/mysql_virtual_alias_maps.cf

virtual_mailbox_domains = proxy:mysql:/etc/postfix/mysql_virtual_domains_maps.cf

virtual_mailbox_maps = proxy:mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf

#邮件存储的根目录

virtual_mailbox_base = /home/domains

#虚拟用户的ID,(数值参考实际系统的postfix用户的ID值)

virtual_uid_maps = static:105

virtual_gid_maps = static:114

proxy_read_maps = $local_recipient_maps $mydestination $virtual_alias_maps $virtual_alias_domains $virtual_mailbox_maps $virtual_mailbox_domains $relay_recipient_maps $relay_domains $canonical_maps $sender_canonical_maps $smtpd_sender_login_maps $recipient_canonical_maps $relocated_maps transport_maps $mynetworks

# smtpd related config

smtpd_recipient_restrictions =

        permit_mynetworks,

        permit_sasl_authenticated,

        reject_non_fqdn_hostname,

        reject_non_fqdn_sender,

        reject_non_fqdn_recipient,

        reject_unauth_destination,

        reject_unauth_pipelining,

        reject_invalid_hostname,

# SMTP sender login matching config

smtpd_sender_restrictions =

        permit_mynetworks,

        reject_sender_login_mismatch,

        reject_authenticated_sender_login_mismatch,

        reject_unauthenticated_sender_login_mismatch

smtpd_sender_login_maps =

        mysql:/etc/postfix/mysql_virtual_sender_maps.cf,

        mysql:/etc/postfix/mysql_virtual_alias_maps.cf

# SMTP AUTH config here

broken_sasl_auth_clients = yes

smtpd_sasl_auth_enable = yes

smtpd_sasl_local_domain = $myhostname

smtpd_sasl_security_options = noanonymous

#main.cf end... ...

修改master.cf 文件

sudo vi /etc/postfix/master.cf

修改maildrop配置就是了

maildrop   unix        -       n        n        -        -        pipe

  flags=DRhu user=vuser argv=maildrop -w 90 -d ${user}@${nexthop} ${recipient} ${user} ${extension} {nexthop}


courier配置

sudo cp /etc/courier/authdaemonrc /etc/courier/authdaemonrc.bak

sudo vi /etc/courier/authdaemonrc

修改

authmodulelist="authmysql"

authmodulelistorig="authmysql"

sudo cp /etc/courier/authmysqlrc /etc/courier/authmysqlrc.bak

sudo vi /etc/courier/authmysqlrc

文件内容如下:

MYSQL_SERVER            localhost

MYSQL_USERNAME          extmail

MYSQL_PASSWORD          password  #数据库连接密码

MYSQL_SOCKET            /tmp/mysql.sock

MYSQL_PORT              3306

MYSQL_OPT               0

MYSQL_DATABASE          extmail

MYSQL_USER_TABLE        mailbox

MYSQL_CRYPT_PWFIELD     password

MYSQL_UID_FIELD         '1007'  # vuser ID号

MYSQL_GID_FIELD         '1007'  # vgroup ID号

MYSQL_LOGIN_FIELD       username

MYSQL_HOME_FIELD        concat("/home/domains/",homedir)  # 根据自己的目录配置

MYSQL_NAME_FIELD        name

MYSQL_MAILDIR_FIELD     concat("/home/domains/",homedir)  # 根据自己的目录配置

MYSQL_QUOTA_FIELD       quota

MYSQL_SELECT_CLAUSE     SELECT username,password,"",uidnumber,gidnumber,\

                        CONCAT('/home/domains/',homedir),               \

                        CONCAT('/home/domains/',maildir),               \

                        quota,                                          \

                        name                                            \

                        FROM mailbox                                    \

                        WHERE username = '$(local_part)@$(domain)'

#authmysqlrc end ... ...


配置sasl

创建/etc/postfix/sasl/smtpd.conf 加入下面的内容

sudo vi /etc/postfix/sasl/smtpd.conf

内容

pwcheck_method:authdaemond

log_level:3

mech_list:PLAIN LOGIN

allow_plaintext: true

authdaemond_path:/var/run/courier/authdaemon/socket


图形日志配置

sudo cp -R /var/www/extman/addon/mailgraph_ext /usr/local/mailgraph_ext

修改mailgraph-init

sudo vi /usr/local/mailgraph_ext/mailgraph-init

MAIL_LOG=/var/log/mail.log


添加开机自启动项

sudo vi /etc/rc.local

/usr/local/mailgraph_ext/mailgraph-init start

/var/www/extman/daemon/cmdserver -v -d

sudo chmod o+x /var/run/courier/authdaemon  #这个很重要,不要后来会因为权限问题,无法发送邮件

/etc/init.d/courier-authdaemon restart


在运行extman的时候有几个问题,一个是GD库问题,还有DBI问题,所以先把这些都装上吧

进入extman报错需要安装perl的DBI DBD::mysql

安装DBI

sudo wget http://search.cpan.org/CPAN/authors/id/T/TI/TIMB/DBI-1.615.tar.gz

sudo tar zxvf DBI-1.615.tar.gz

cd DBI-1.615/

sudo perl Makefile.PL

sudo make 

sudo make install

安装DBD::mysql报错所以只好手动

sudo wget http://search.cpan.org/CPAN/authors/id/C/CA/CAPTTOFU/DBD-mysql-4.018.tar.gz

sudo perl Makefile.PL --mysql_config=/usr/local/webserver/mysql/bin/mysql_config

sudo make 

sudo make install

安装GD

sudo wget http://search.cpan.org/CPAN/authors/id/L/LD/LDS/GD-2.45.tar.gz

sudo perl Makefile.PL

sudo make 

sudo make install


基本上就OK啦。搞了差不多一周时间,终于可以用上自己的邮件服务器了,真是历经千辛万苦呀。


最后一点因为用的nginx作为代理所以需要配置下让他转到apache

之所以用apache也是因为之前在nginx下配置extmail有问题,郁闷惨了

 server {

listen         80;

server_name    mail.jiukewang.com;

index index.html index.shtml;

error_log  /var/wwwlog/mail.jiukewang.com/error.log;

# access_log /var/wwwlog/mail.jiukewang.com/access.log;

location / {  

   proxy_redirect off;  

   proxy_set_header HOST $host;  

   proxy_set_header SERVER_ADDR $server_addr;  

   proxy_set_header SERVER_PORT $server_port;  

   proxy_set_header REMOTE_ADDR $remote_addr;  

   proxy_set_header REMOTE_PORT $remote_port;  

   proxy_pass   http://127.0.0.1:1312;  

}  

 }

 

你可能感兴趣的:(mysql,SQL Server,ubuntu,ext,perl)