Postfix on Ubuntu server 10.04

Postfix 是ubuntu服务器的默认MTA。快速,容易管理,安全。与 sendmail兼容。这里解释如何安装和配置postfix。解释如何使用安全连接建立起一个SMTP服务器(为了安全发送邮件)。

注意:这个指南没有说到如何建立 Postfix Virtual Domains,关于 Virtual Domains 和其他高级配置,参考 https://help.ubuntu.com/10.04/serverguide/C/postfix.html#postfix-references

安装

安装使用下面的命令行:

sudo apt-get install postfix

基本配置

配置 postfix, 运行下面的命令:

sudo dpkg-reconfigure postfix

用户界面出现,在每一屏上,选择下面的值:

Internet Site
mail.example.com
steve
mail.example.com, localhost.localdomain, localhost
No
127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 192.168.0.0/24
0
+
all

使用你接收邮件的域名来替换 mail.example.com, 实际的网络和类范围替换192.168.0.0/24 ,适当的用户名替换 steve。

现在,你可以确定使用哪一种mailbxo格式。缺省情况下,Postfix使用mbox作为默认的mailbox格式。无须直接编辑配置文件,你可以使用postconf命令来配置postfix参数。配置参数将保存在文件 /etc/postfix/main.cf 文件中。以后,你想重新配置 postfix, 你可以运行这个命令或者手动修改配置文件。

为 Maildir 配置 mailbox格式:

sudo postconf -e ‘home_mailbox = Maildir/’
这将把新邮件保存到 /home/username/Maildir , 因此你需要配置你的 Mail Deliery Agent(MDA)使用同一个路径。

SMTP 认证

SMTP-AUTH 允许客户通过一个认证机制(SASL)来标识自己。Transport Layer Security(TLS)对认证过程进行加密。一旦认证通过,SMTP服务器将允许客户来传递邮件。

1. 配置Postfix, SMTP-AUTH 使用 SASL(Devocot SASL)

sudo postconf -e ‘smtpd_sasl_type = dovecot’
sudo postconf -e ‘smtpd_sasl_path = private/auth-client’
sudo postconf -e ‘smtpd_sasl_local_domain =’
sudo postconf -e ‘smtpd_sasl_security_options = noanonymous’
sudo postconf -e ‘broken_sasl_auth_clients = yes’
sudo postconf -e ‘smtpd_sasl_auth_enable = yes’
sudo postconf -e ‘smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination’
sudo postconf -e ‘inet_interfaces = all’

注意: smtpd_sasl_path 配置是一个相对 Postfix queue 目录的路径。

2. 下一步,为TLS获得一个数字证书。参考 https://help.ubuntu.com/10.04/serverguide/C/certificates-and-security.html 获得更详细的信息。这个例子同样使用一个Certificate Authority(CA)。生成CA证书的方法,参考 https://help.ubuntu.com/10.04/serverguide/C/certificates-and-security.html#certificate-authority 。

注意:你可以从一个certificate authority 那里获得数字证书。不像 web 客户端, SMTP 客户很少抱怨 “self-signed certificates” 因此,你可以自己创建证书。参考 https://help.ubuntu.com/10.04/serverguide/C/certificates-and-security.html#creating-a-self-signed-certificate 获得更详细的信息。

3. 一旦你拥有证书,配置Postfix给进出的邮件提供TLS加密:

sudo postconf -e ‘smtpd_tls_auth_only = no’
sudo postconf -e ‘smtp_use_tls = yes’
sudo postconf -e ‘smtpd_use_tls = yes’
sudo postconf -e ‘smtp_tls_note_starttls_offer = yes’
sudo postconf -e ‘smtpd_tls_key_file = /etc/ssl/private/server.key’
sudo postconf -e ‘smtpd_tls_cert_file = /etc/ssl/certs/server.crt’
sudo postconf -e ‘smtpd_tls_loglevel = 1′
sudo postconf -e ‘smtpd_tls_received_header = yes’
sudo postconf -e ‘smtpd_tls_session_cache_timeout = 3600s’
sudo postconf -e ‘tls_random_source = dev:/dev/urandom’
sudo postconf -e ‘myhostname = mail.example.com’

4. 如果你使用自己的 Certificate Authority 来做签证,输入:

sudo postconf -e ‘smtpd_tls_CAfile = /etc/ssl/certs/cacert.pem’

更多关于证书的信息,参考 https://help.ubuntu.com/10.04/serverguide/C/certificates-and-security.html 。

注意: 运行执行所有的命令后,Postfix已经为 SMTP-AUTH 配置好了,已经为 TLS 加密创建了一个self-signed certificate 。

现在,文件 /etc/postfix/main.cf 看起来内容如下:

main.cf —————————-

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

smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = no

# appending .domain is the MUA’s job.
append_dot_mydomain = no

# Uncomment the next line to generate “delayed mail” warnings
#delay_warning_time = 4h

myhostname = server1.example.com
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = server1.example.com, localhost.example.com, localhost
relayhost =
mynetworks = 127.0.0.0/8
mailbox_command = procmail -a “$EXTENSION”
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
smtpd_sasl_local_domain =
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
broken_sasl_auth_clients = yes
smtpd_recipient_restrictions =
permit_sasl_authenticated,permit_mynetworks,reject _unauth_destination
smtpd_tls_auth_only = no
smtp_use_tls = yes
smtpd_use_tls = yes
smtp_tls_note_starttls_offer = yes
smtpd_tls_key_file = /etc/ssl/private/smtpd.key
smtpd_tls_cert_file = /etc/ssl/certs/smtpd.crt
smtpd_tls_CAfile = /etc/ssl/certs/cacert.pem
smtpd_tls_loglevel = 1
smtpd_tls_received_header = yes
smtpd_tls_session_cache_timeout = 3600s
tls_random_source = dev:/dev/urandom

———————————————-

postfix 的初始配置已经完成。运行下面的命令来重启 postfix 守护:

sudo /etc/init.d/postfix restart

Postfix支持SMTP-AUTH,基于SASL。然而,在使用SMTP-AUTH之前,仍然需要设置SASL认证。

配置SASL

Postfix 支持两种SASL实现,分别是 Cyrus SASL 和 Dovecot SASL 。要让 Dovecot SASL 能够工作,需要安装 dovecot-common 包。从一个终端提示符下输入:

sudo apt-get install dovecot-common

下一步编辑 /etc/dovecot/dovecot.conf 。在 auth default 段,取消 socket listen 的注释,并且修改如下:

socket listen {
#master {
# Master socket provides access to userdb information. It’s typically
# used to give Dovecot’s local delivery agent access to userdb so it
# can find mailbox locations.
#path = /var/run/dovecot/auth-master
#mode = 0600
# Default user/group is the one who started dovecot-auth (root)
#user =
#group =
#}
client {
# The client socket is generally safe to export to everyone. Typical use
# is to export it to your SMTP server so it can do SMTP AUTH lookups
# using it.
path = /var/spool/postfix/private/auth-client
mode = 0660
user = postfix
group = postfix
}
}

为了让 Outlook 客户端使用 SMTPAUTH,在 auth default 段增加 “login” :

mechanisms = plain login

一旦你的 Dovecot 配置完成,重启:

sudo /etc/init.d/dovecot restart

Postfix-Dovecot

使用 dovecot-postfix 包,是配置Postfix支持SMTP-AUTH的另一种方法。这个包将安装 Dovecot ,并且配置 Postfi 来用它,支持 SASL 认证和作为一个 MDA。这个同时配置 Dovecot 支持 IMAP,IMAPS,POP3和POP3S。

注意:你可能或者不可能在你的邮件服务器上运行 IMAP, IMPAS, POP3 或者 POP3S。例如,如果你配置你的服务器成为一个mail gateway,spam/virus filter等等。在这些例子中,很容易使用上面的命令来配置 Postfix 支持 SMTPAUTH。

要安装这个包,从一个终端提示符下输入:

sudo apt-get install dovecot-postfix

现在,你有个可工作的邮件服务器了,但还有一些选项,你希望更深入的自定义。例如,这个包使用来自 ssl-cert 包的 certificate 和 key ,在一个产品环境,你会使用为主机使用一个certificate和key。参考 https://help.ubuntu.com/10.04/serverguide/C/certificates-and-security.html 获得更详细的信息。

一旦你有一个主机自定义的 certificate 和 key,修改 /etc/postfix/main.cf 下面的选项:

smtpd_tls_cert_file = /etc/ssl/certs/ssl-mail.pem
smtpd_tls_key_file = /etc/ssl/private/ssl-mail.key

然后重启 Postfix :

sudo /etc/init.d/postfix restart

测试

SMTP-AUTH 配置完成,现在是时候测试了。

要查看 SMTP-AUTH 和 TLS 是否工作,运行下面的命令:

telnet mail.example.com 25

和 postfix mail server建立连接后,输入:

ehlo mail.example.com

如果你看到回显的信息中包含下面的内容,那么工作正常。输入quit退出。

250-STARTTLS
250-AUTH LOGIN PLAIN
250-AUTH=LOGIN PLAIN
250 8BITMIME

发现故障并修理

这一段讲述发现问题后,进行检测的一般方法。

+ Escaping chroot

出于安全的考虑,Ubuntu 的 postfix 缺省安装到一个 chroot 环境。当出现问题时,这会增加解决问题的难度。

要关闭 chroot 操作,找到 /etc/postfix/master.cf 配置文件的这一行:

smpt inet n - - - - smtpd

修改如下:

smtp inet n - n - - smtpd

然后,你使用新的配置来重启 postfix:

sudo /etc/init.d/postfix restart

+ Log File

三个文件:

/var/log/mail.log
/var/log/mail.err
/var/log/mail.warn

可使用tail -f 命令实时查看:

tail -f /var/log/mail.err

++ 修改TLS活动日志水平,设置 smtpd_tls_loglevel 选项的值,从 1 到 4。

sudo postconf -e ‘smtpd_tls_loglevel = 4′

++ 如果你无法发送或者接收某个域名的的邮件,你可以增加域名到 debug_peer_list 参数:

sudo postconf -e ‘debug_peer_list = problem.domain’

++ 你可以增加Postfix 守护进程的 verbosity,编辑 /etc/postfix/master.cf ,在条目后增加 -v。

smtp unix – – – – – smtp -v

修改配置后,需要 Postfix来重载。执行 sudo /etc/init.d/postfix reload

++ 当SASL发生问题时,需要增加日志的信息数量,在 /etc/dovecot/dovecot.conf 文件中设置下面的选项:

auth_debug=yes
auth_debug_passwords=yes

注意:修改 dovecot 的配置后,需要重载 : sudo /etc/init.d/dovecot reload

注意:上面的改动会彻底增加发送到日志文件的信息数量。记住在调试完毕后,将配置修改回来,并且进行重载。

+ References

管理一个 Postfix 服务器是非常复杂的任务。有时需要到Ubuntu社区获得更多有经验的帮助。

freenode.net 的 #ubuntu-server IRC

The Book of Postfix

http://www.postfix.org/documentation.html

Posted in Ubuntu | Leave a comment

Continuum 的分布式建造

介绍

对于基本的Continuum功能来讲,分布式建造是一个扩展,它让我们有能力处理多个独立的建造,超越单个服务器的处理能力。同时,让我们能够在多个不同的平台上执行建造,对所有的项目建造保持一个统一的视图。

架构

Continuum遵循一个使用XML-RPC的CS模式。然而,由于它使用 bi-directional XML-RPC 实现,我们使用Master和Build Agent来区分组件。

Master就是一个Continuum实例,它可以分配builds到已经注册的Build Agent。

Build Agent是一个Jetty-bundled webapp,监听来自Master的建造请求。

Master和Build Agents是一个一对多的关系。Master可有多个Build Agents,一个Build Agent只能有一个 Master。

行为

分布式建造发生在Continuum的项目组层次。当整个项目组在Master中建造,独立的项目被分发到单个Build Agent。

一个项目组是多个项目的混合,分布式的工作由下面几个步骤完成:

1. 在 Master,项目组的建造被触发。

2. 项目组的每一个独立项目都被标识,作为一个单独项目或者一个多模块项目。

3. 对于每一个独立项目,Master迭代已注册的Build Agent列表,查询其有效性。查询是一个 XML-RPC ping() ,跟在一个 getBuildSizeOfAgent() 调用之后。

4. 如果一个Build Agent 有效, Master 收集建造需要的信息(SCM URL ,项目ID,等等)后,在调用buildProducts(),将这些信息和它的队列中最小数值的任务传递到 Build Agent。

5. Build Agent 处理这个建造请求:这个建造被排队和执行。在执行之前,Build Agent搜先执行一个 SCM checkout 或者一个 SCM update,跟随着一个SCM 修改记录来获取最新更新的日期,然后开始正式的建造。

6. 到这一点,当建造运行,Master可以调用cancelBuild() ,返回一个临时的建造结果,调用 getBuildResult() 更新建造的输出(在Master)。

7. 建造后,Build Agent调用回调方法 returenBuildResult(),返回完整的建造结果给Master,Master集合后提供统一的项目视图。

设置

  • 安装和配置一个或者多个Build Agent
  • 在常规配置中,打开分布式建造的功能
  • 将你的Build Agent添加到Continuum Master
  • 将你的Build Agent添加到一个Build Agent 组
  • 将你的Build Agent 组添加到一个建造环境
  • 配置项目使用建造环境
  • 确保项目组的本地仓库已配置好。在这个例子,它应该指向Build Agent  安装和运行的仓库的路径

警告:你需要拥有一个远程仓库来保存Build Agent创建的成品,以致其他的agents能使用新的成品。

局限

  • 仅仅系统管理员可以打开和关闭分布式建造
  • 如果指定的话,证件(例如svn证件)跟随一起传递,但如果服务器缓存被使用,需要在Build Agents单独完成
  • 没有跟踪SCM的修改
  • Build Agent需要一个配置的web接口
  • 项目组的所有项目被分配到同一个Build Agent

将来增强的功能

  • 远程建造器
  • * 建造器在运程机器上安装,Continuum 管理者将发送动作来运行建造器。如果我们仅执行一个建造,一个动作将让所有的建造器(或者某些建造器,或者单个建造器)运行某些操作。动作将通过JMS发送,如果它们不想接收所有的动作,建造器可以应用一些过滤器。我们可以做一些并行的建造的同时,建造的顺序也需要遵从依赖树。要让依赖正确工作,每一个建造器需要使用一个中心本地仓库。可能我们能使用一个内部的Archiva。
  • * Continuum建造器做好了接收所有命令的配置,用户可以运行多平台的建造,每一个建造都定义了执行。
  • * Continuum建造器做好了接收某些项目类型的配置,用户可以根据项目组使用一个不同的建造器。在这里,项目的建造将被快速完成,因为命令被均衡到几个服务器。
  • *
    Continuum建造器可以为它能做的事情做好配置,用户可以在几台机器上安装建造器来均衡责任。在这里,可以运行一些并行的建造。
    ∘ 当建造器工作完成,将发送一条信息给管理者,通知处理结束。

    Continuum建造器可以为它能做的事情做好配置,用户可以在几台机器上安装建造器来均衡责任。在这里,可以运行一些并行的建造。∘ 当建造器工作完成,将发送一条信息给管理者,通知处理结束。

  • * 当建造器工作完成,将发送一条信息给管理者,通知处理结束。
  • * 通讯用的JMS,我们可以增加监听器来创建报告和统计,记录一些信息。
  • 基于规则的分发
  • * 下一个有效
  • * 负载均衡
  • * 目标环境匹配
Posted in Continuum | Leave a comment

Continuum 安装升级指南

系统需求
JDK > 1.5
内存 没有最小需求
磁盘 最少30MB,Checking out 和 building sources 时需要更多
操作系统 没有最小需求。在 Windows XP, Debian, Fedora Core, Solaris 和 Mac OSX都做过测试
不同的安装环境(standalone, webapp, service)
Standalone 独立运行的安装
基本原理和原则
1.下载standalone版本
2. 解压文件
3. 设置JAVA_HOME环境变量
定义JNDI资源
邮件服务器配置
在你启动Continuum之前,你必须配置你的SMTP配置来支持邮件通知。配置在 $CONTINUUM_HOME/conf/jetty.xml中进行:
<New id=”validation_mail”>
<Arg>mail/Session</Arg>
<Arg>
<New>
<Set name=”user”></Set>
<Set name=”password”></Set>
<Set name=”properties”>
<New>
<Put name=”mail.smtp.host”>localhost</Put>
</New>
</Set>
</New>
</Arg>
</New>
数据库配置
缺省情况下,Continuum使用一个嵌入的Derby数据库。如果你想使用其他的数据库,你可以修改 $CONTINUUM_HOME/conf/jetty.xml 的 JNDI 配置:
<!– continuum database –>
<New id=”continuum”>
<Arg>jdbc/continuum</Arg>
<Arg>
<New>
<Set name=”DatabaseName”><SystemProperty name=”appserver.base” default=”..”/>/data/databases/continuum</Set>
<Set name=”user”>sa</Set>
<Set name=”createDatabase”>create</Set>
</New>
</Arg>
</New>
<New id=”continuumShutdown”>
<Arg>jdbc/continuumShutdown</Arg>
<Arg>
<New>
<Set name=”DatabaseName”><SystemProperty name=”appserver.base” default=”..”/>/data/databases/continuum</Set>
<Set name=”user”>sa</Set>
<Set name=”shutdownDatabase”>shutdown</Set>
</New>
</Arg>
</New>
<!– Users / Security Database –>
<New id=”users”>
<Arg>jdbc/users</Arg>
<Arg>
<New>
<Set name=”DatabaseName”><SystemProperty name=”appserver.base” default=”..”/>/data/databases/users</Set>
<Set name=”user”>sa</Set>
<Set name=”createDatabase”>create</Set>
</New>
</Arg>
</New>
<New id=”usersShutdown”>
<Arg>jdbc/usersShutdown</Arg>
<Arg>
<New>
<Set name=”DatabaseName”><SystemProperty name=”appserver.base” default=”..”/>/data/databases/users</Set>
<Set name=”user”>sa</Set>
<Set name=”shutdownDatabase”>shutdown</Set>
</New>
</Arg>
</New>
安装Windows服务
1. 执行 continuum.bat install
2. 编辑 Apache continuum 服务
要查看你计算机上的服务,开始-》运行,输入 services.msc
3. 选择启动类型Startup Type
4. 打开 Log On 标签页,选择一个真实用户。真实用户需要,是因为你需要一个home目录来存放Maven仓库和其他的内容
5. 检查你的修改
安装Linux服务
• /etc/init.d 里面的基本脚本
在 /etc/init.d/ 创建一个 continuum 文件,内容如下,用你已有的帐号名取代 continuum_user:
#!/bin/sh
CONTINUUM_HOME=/opt/continuum-1.3
su – continuum_user -c “$CONTINUUM_HOME/bin/continuum console $@ &”
• 在基于Debian的系统
ln -s /usr/local/continuum-[VERSION]/bin/continuum /etc/init.d/continuum
在不同的运行级别上添加软连接,执行
update-rc.d -n continuum defaults 80
• 在基于RedHat的系统上
需要使用 chkconfig 命令来添加新的服务。需要增加一些注释到 /etc/rc.d/init.d/continuum 脚本,并且执行执行一些命令。编写一个chkconfig_install.sh 的脚本来完成上面的工作。内容如下,其中 _continuum_user_ 需要用你已有的帐号名来取代。
#! /bin/sh
#
# chkconfig_install.sh – install Continuum on a chkconfig-based system
#
# Author: Felipe Leme <felipeal at apache.org>
#
# figure out what’s Continuum’s directory
CONTINUUM_HOME=`dirname $0`
cd ${CONTINUUM_HOME}
CONTINUUM_HOME=`pwd`
INITD_SCRIPT=/etc/rc.d/init.d/continuum
if [ -f ${INITD_SCRIPT} ]
then
echo “File ${INITD_SCRIPT} already exists. Please remove it and try again.”
exit 1
fi
echo “Creating file ${INITD_SCRIPT}”
cat >> ${INITD_SCRIPT} <<EOF
#! /bin/sh
# chkconfig: 345 90 10
# description: Apache Continuum server
# uncoment to set JAVA_HOME as the value present when Continuum installed
#export JAVA_HOME=${JAVA_HOME}
if [ -z "\${JAVA_HOME}" ]
then
echo “Cannot manage Continuum without variable JAVA_HOME set”
echo ”  (try to set it on file ${INITD_SCRIPT})”
exit 1
fi
# run Continuum as root
cd ${CONTINUUM_HOME}
./bin/continuum \$*
# run Continuum as user _continuum_user_
#su – _continuum_user_ -c “cd ${CONTINUUM_HOME}; ./bin/continuum \$*”
EOF
chmod +x ${INITD_SCRIPT}
echo “Adding Continuum to chkconfig”
chkconfig –add continuum
echo “Enabling Continuum on chkconfig”
chkconfig continuum on
echo “Continuum set to start on run levels 3, 4 and 5.”
echo “To start Continuum now, run ‘service continuum start’”
Posted in Continuum | Leave a comment