1、安装前的准备工做:html
1.卸载系统默认安装postfix
node
# service postfix stop # chkconfig postfix off # rpm -e postfix --nodeps
2.安装所需的rpm包,这包括如下这些mysql
db4-devel, openssl-devel, cyrus-sasl-develsql
2、启动依赖的服务:
一、启动mysql数据库,并给mysql的root用户设置密码:
数据库
# service mysqld start # chkconfig mysqld on # mysqladmin -uroot password 'your_password'
二、启动saslauthd服务,并将其加入到自动启动队列:
vim
# service saslauthd start # chkconfig saslauthd on
3、安装配置postfix
bash
# 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 zxvf postfix-2.9.3.tar.gz # cd postfix-2.9.3 # make makefiles 'CCARGS=-DHAS_MYSQL -I/usr/local/mysql/include -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl -DUSE_TLS ' 'AUXLIBS=-L/usr/local/mysql/lib -lmysqlclient -lz -lm -L/usr/lib/sasl2 -lsasl2 -lssl -lcrypto' # make # make install
注:MySQL经过通用二进制安装在/usr/local/mysql下网络
按照如下的提示输入相关的路径([]号中的是缺省值,”]”后的是输入值,省略的表示采用默认值)
dom
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]
生成别名二进制文件:
# newaliaseside
2.进行一些基本配置,测试启动postfix并进行发信
# vim /etc/postfix/main.cf
修改如下几项为您须要的配置
myhostname = mail.magedu.com
myorigin = magedu.com
mydomain = magedu.com
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
mynetworks = 192.168.1.0/24, 127.0.0.0/8
说明:
myorigin参数用来指明发件人所在的域名,即作发件地址假装;
mydestination参数指定postfix接收邮件时收件人的域名,即您的postfix系统要接收到哪一个域名的邮件;
myhostname 参数指定运行postfix邮件系统的主机的主机名,默认状况下,其值被设定为本地机器名;
mydomain 参数指定您的域名,默认状况下,postfix将myhostname的第一部分删除而做为mydomain的值;
mynetworks 参数指定你所在的网络的网络地址,postfix系统根据其值来区别用户是远程的仍是本地的,若是是本地网络用户则容许其访问;
inet_interfaces 参数指定postfix系统监听的网络接口;
注意:
一、在postfix的配置文件中,参数行和注释行是不能处在同一行中的;
二、任何一个参数的值都不须要加引号,不然,引号将会被看成参数值的一部分来使用;
三、每修改参数及其值后执行 postfix reload 便可令其生效;但若修改了inet_interfaces,则需从新启动postfix;
四、若是一个参数的值有多个,能够将它们放在不一样的行中,只须要在其后的每一个行前多置一个空格便可 , postfix会把第一个字符为空格或tab的文本行视为上一行的延续;
4、为postfix提供SysV服务脚本/etc/rc.d/init.d/postfix,内容以下(#END 以前):
#!/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/rc.d/init.d/postfix将postfix服务添加至服务列表:# chkconfig --add postfix设置其开机自动启动:# chkconfig postfix on使用此脚本从新启动服务,以测试其可否正常执行:# service postfix restart此时可以使用本地用户测试邮件收发了。