四、安装并调试postfix
1、安装postfix软件
- # groupadd -g 2525 postfix
- # useradd -g postfix -u 2525 -s /sbin/nologin -M postfix
- # groupadd -g 2526 postdrop
- # useradd -g postdrop -u 2526 -s /sbin/nologin -M postdrop
- # tar xf postfix-2.9.6.tar.gz
- # cd postfix-2.9.6
注:编译安装之前要注意系统时间是否一致;
- #hwclock -s #将虚拟机时间和硬件时间同步
- # make makefiles 'CCARGS=-DHAS_MYSQL -I/usr/include/mysql -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl -DUSE_TLS ' 'AUXLIBS=-L/usr/lib/mysql -lmysqlclient -lz -lm -L/usr/lib/sasl2 -lsasl2 -lssl -lcrypto'
- # make
- # make install
按照以下的提示输入相关的路径([]号中的是缺省值,”]”后的是输入值,省略的表示采用默认值)
- install_root: [/] /
- tempdir: [/root/postfix-2.9.3] /tmp/postfix
- config_directory: [/etc/postfix] /etc/postfix
- daemon_directory: [/usr/libexec/postfix]
- command_directory: [/usr/sbin]
- queue_directory: [/var/spool/postfix]
- sendmail_path: [/usr/sbin/sendmail]
- newaliases_path: [/usr/bin/newaliases]
- mailq_path: [/usr/bin/mailq]
- mail_owner: [postfix]
- setgid_group: [postdrop]
- html_directory: [no]/var/www/html/postfix
- manpages: [/usr/local/man]
- readme_directory: [no]
2、调试并配置postfix软件,测试使用情况
- # vim /etc/init.d/postfix #添加服务启动脚本
- #!/bin/bash
- #
- # postfix Postfix Mail Transfer Agent
- #
- # chkconfig: 2345 80 30
- # description: Postfix is a Mail Transport Agent, which is the program \
- # that moves mail from one machine to another.
- # processname: master
- # pidfile: /var/spool/postfix/pid/master.pid
- # config: /etc/postfix/main.cf
- # config: /etc/postfix/master.cf
- # Source function library.
- . /etc/rc.d/init.d/functions
- # Source networking configuration.
- . /etc/sysconfig/network
- # Check that networking is up.
- [ $NETWORKING = "no" ] && exit 3
- [ -x /usr/sbin/postfix ] || exit 4
- [ -d /etc/postfix ] || exit 5
- [ -d /var/spool/postfix ] || exit 6
- RETVAL=0
- prog="postfix"
- start() {
- # Start daemons.
- echo -n $"Starting postfix: "
- /usr/bin/newaliases >/dev/null 2>&1
- /usr/sbin/postfix start 2>/dev/null 1>&2 && success || failure $"$prog start"
- RETVAL=$?
- [ $RETVAL -eq 0 ] && touch /var/lock/subsys/postfix
- echo
- return $RETVAL
- }
- stop() {
- # Stop daemons.
- echo -n $"Shutting down postfix: "
- /usr/sbin/postfix stop 2>/dev/null 1>&2 && success || failure $"$prog stop"
- RETVAL=$?
- [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/postfix
- echo
- return $RETVAL
- }
- reload() {
- echo -n $"Reloading postfix: "
- /usr/sbin/postfix reload 2>/dev/null 1>&2 && success || failure $"$prog reload"
- RETVAL=$?
- echo
- return $RETVAL
- }
- abort() {
- /usr/sbin/postfix abort 2>/dev/null 1>&2 && success || failure $"$prog abort"
- return $?
- }
- flush() {
- /usr/sbin/postfix flush 2>/dev/null 1>&2 && success || failure $"$prog flush"
- return $?
- }
- check() {
- /usr/sbin/postfix check 2>/dev/null 1>&2 && success || failure $"$prog check"
- return $?
- }
- restart() {
- stop
- start
- }
- # See how we were called.
- case "$1"in
- start)
- start
- ;;
- stop)
- stop
- ;;
- restart)
- stop
- start
- ;;
- reload)
- reload
- ;;
- abort)
- abort
- ;;
- flush)
- flush
- ;;
- check)
- check
- ;;
- status)
- status master
- ;;
- condrestart)
- [ -f /var/lock/subsys/postfix ] && restart || :
- ;;
- *)
- echo $"Usage: $0 {start|stop|restart|reload|abort|flush|check|status|condrestart}"
- exit 1
- esac
- exit $?
- # END
- # chmod +x /etc/init.d/postfix #添加执行权限
- # chkconfig --add postfix #添加服务启动级别
- # chkconfig --add postfix #将postfix服务添加至服务列表:
- # chkconfig postfix on #设置其开机自动启动:
- # service postfix restart #使用此脚本重新启动服务,以测试其能否正常执行:
- # newaliases #生成别名二进制文件:
3、配置postfix文件
- # cd /etc/postfix/
- # vim main.cf
- 修改以下几项为您需要的配置
- myhostname = mail.wangej.com #指定允许postfix的主机名,默认为本机名
- myorigin = wangej.com #指定发件人所在的域,做地址伪装
- mydomain = wangej.com #指定自身所在的域
- mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain, ns.$mydomain
- mynetworks = 172.16.0.0/16, 127.0.0.0/8#指定所在网络,postfix以此来判断是本地用户或远程
- # postconf -n #查看配置选项
注:
1、在postfix的配置文件中,参数行和注释行是不能处在同一行中的;
2、任何一个参数的值都不需要加引号,否则,引号将会被当作参数值的一部分来使用;
3、每修改参数及其值后执行 postfix reload 即可令其生效;但若修改了inet_interfaces,则需重新启动postfix;
4、如果一个参数的值有多个,可以将它们放在不同的行中,只需要在其后的每个行前多置一个空格即可;postfix会把第一个字符为空格或tab的文本行视为上一行的延续;
此时可以使用本地用户发送邮件,测试一下。
