Postfix部署【2】传输代理

一、清理


  1. 卸载自带 postfix

    $ rpm -q postfix
    postfix-2.6.6-6.el6_5.x86_64
    $ rpm -ev postfix --nodeps
    

二、编译安装MySQL 5.1


  1. 安装编译环境

    $ yum -y groupinstall "Development Tools"
    
  2. 获取源码包

    $ cd /opt;wget https://cdn.mysql.com/archives/mysql-5.1/mysql-5.1.71.tar.gz
    
  3. 配置国内 yum 源

    $ wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-6.repo
    $ yum clean all
    $ yum makecache
    
  4. 编译安装

    - 创建用户、组
    $ groupadd mysql
    $ useradd mysql -s /sbin/nologin -g mysql -M
    
    - 安装依赖包
    $ yum -y install ncurses-devel
    
    - 创建安装目录
    $ mkdir -p /usr/local/mysql
    
    - 编译安装
    $ tar zxvf mysql-5.1.71.tar.gz
    $ cd mysql-5.1.71
    $ ./configure \
    --prefix=/usr/local/mysql/  \
    --with-unix-socket-path=/usr/local/mysql/tmp/mysql.sock \
    --localstatedir=/usr/local/mysql/data \
    --enable-assembler \
    --enable-thread-safe-client \
    --with-mysqld-user=mysql \
    --with-big-tables \
    --without-debug \
    --with-pthread \
    --enable-assembler \
    --with-extra-charsets=complex \
    --with-readline \
    --with-ssl \
    --with-embedded-server \
    --enable-local-infile \
    --with-plugins=partition,innobase \
    --with-mysqld-ldflags=-all-static \
    --with-client-ldflags=-all-static
    $ make && make install	
    
  5. 配置

    - 创建mysql数据文件目录
    $ mkdir -p /application/mysql/data
    
    - 创建配置文件
    $ cp /opt/mysql-5.1.71/support-files/my-medium.cnf /etc/my.cnf
    - 创建启动脚本
    $ cp -r /opt/mysql-5.1.71/support-files/mysql.server /etc/init.d/mysqld
    
    - 权限配置
    $ chown -R mysql:mysql /usr/local/mysql
    $ /usr/local/mysql/bin/mysql_install_db --user=mysql
    
    - 环境变量
    $ echo "export PATH=/usr/local/mysql/bin:$PATH" >> /etc/profile
    $ source /etc/profile
    
  6. 启动 MySQL

    -设置开机自动启动
    $ chkconfig --add mysqld
    $ chmod a+wrx /etc/init.d/mysqld
    $ /etc/init.d/mysqld start
    
  7. MySQL 初始化配置

    $ /usr/local/mysql/bin/mysql_secure_installation
    
    Enter current password for root (enter for none):		
    	# 输入当前 root 在 mysql 中的密码,一般为空,所以直接回车;
    
    Set root password? [Y/n] y			
    	# 是否为 root 设置密码?
    
    Remove anonymous users? [Y/n] y		
    	# 是否移除匿名用户?
    
    Disallow root login remotely? [Y/n] n	
    	# 是否拒绝 root 远程登录?
    
    Remove test database and access to it? [Y/n] y		
    	# 是否移除test库和对test库的访问权限?
    
    Reload privilege tables now? [Y/n] y	
    	# 是否刷新授权表使修改生效?
    
    

至此,MySQL安装完成;

三、安装 cyrus-sasl 并启动 saslauthd 服务


$ yum -y install cyrus-sasl cyrus-sasl-devel
$ service saslauthd start
$ chkconfig saslauthd on

四、编译安装 Postfix-2.11.7


4.1、编译安装 Postfix-2.11.11

  • 查看 postfix 用户
    $ id postfix
    uid=89(postfix) gid=89(postfix)=89(postfix),12(mail)
    
    发送邮件的用户,这里就使用系统自带的postfix用户,记住UID:89、GID:89,后面很多地方都要用到这两个ID号,如果此ID号更改了,那么Postfix安装方面会有很多目录权限都需要更改。
  • 编译安装
    - 安装依赖包
    $ yum -y install db4-devel 
    $ yum -y install openssl-devel
    $ yum -y install mysql-devel perl-DBD-MySQL
    
    - 编译安装
    $ wget ftp://ftp.cuhk.edu.hk/pub/packages/mail-server/postfix/official/postfix-2.11.11.tar.gz 
    $ tar zxvf postfix-2.11.11.tar.gz
    $ cd postfix-2.11.11
    $ make makefiles 'CCARGS=-DHAS_MYSQL -I/usr/include/mysql -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl  -DUSE_TLS ' 'AUXLIBS=-L/usr/lib64/mysql -lmysqlclient -lz -lm -L/usr/lib/sasl2 -lsasl2  -lssl -lcrypto'
    =======================================================================
    -DHAS_MYSQL -I/usr/include/mysql	| 启用Mysql存储,指定头文件
    -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl	| 启用SASL(cyrus)认证框架
    -DUSE_TLS	| 启用SSL功能
    AUXLIBS=-L/usr/lib64/mysql -lmysqlclient	| 找Mysql客户端库文件
    -lz		| 压缩裤文件
    -lm -L/usr/lib64/sasl2	| 模块文件
    -lsasl2 -lssl -lcrypto	| 加密库文件
    =======================================================================	
    有以下信息就表示配置成功了:
    
    [src/posttls-finger]
    cat ../../conf/makedefs.out Makefile.in >Makefile
    rm -f Makefile; (cat conf/makedefs.out Makefile.in) >Makefile
    
    $ make && make install
    
    按照以下的提示输入相关的路径([]号中的是缺省值,”]”后的是输入值,省略的表示采用默认值)
    install_root: [/]										#指定Postfix安装目录,默认
    tempdir: [/root/postfix-2.11.7] /tmp/postfix			#指定Postfix临时文件目录
    config_directory: [/etc/postfix]						#指定Postfix配置文件目录,默认
    command_directory: [/usr/sbin]							#指定Postfix二进制文件目录,默认
    daemon_directory: [/usr/libexec/postfix]				#指定Postfix服务器进程,默认
    data_directory: [/var/lib/postfix]						#指定Postfix可写文件目录,默认
    html_directory: [no] /var/www/html/postfix				#指定Postfix帮助文件,可以使用web服务器打开
    mail_owner: [postfix]									#指定Postfix属主,默认
    mailq_path: [/usr/bin/mailq]							#指定Postfix队列程序路径,默认
    manpage_directory: [/usr/local/man]
    newaliases_path: [/usr/bin/newaliases]					#指定Postfix生成别名命令位置,默认
    queue_directory: [/var/spool/postfix]					#指定Postfix队列目录,默认
    readme_directory: [no]
    sendmail_path: [/usr/sbin/sendmail]						#指定Postfix客户端(smtp),默认
    setgid_group: [postdrop]								#指定Postfix投递组(默认有这个组,但没有这个用户),默认
    
    【PS】如果输入错误可以按Ctrl+退格键删除字符。
    
  • 配置启动脚本
    $ vim /etc/init.d/postfix
    #!/bin/bash
    #
    # chkconfig: 2345 80 30
    # description: Postfix is a Mail Transport Agent, which is the program \
    # 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 postfix on
    $ service postfix start
    

4.2、Postfix 相关命令

  • 管理服务

    $ postfix start	启动服务
    $ postfix stop	关闭服务
    $ postfix reload	重载服务配置
    
  • 查看/检查服务配置

    $ postfix check	检查服务配置
    
    $ postconf [OPTION]
    -d:显示 postfix 默认的配置;
    -n:显示新修改的配置;
    -m:显示支持的存储文件类型如 hash,mysql 等;
    -a:显示支持 sasl 的客户端插件类型;
    

    如果上面没有使用UID为89的postfix用户,那么检查postfix时就会报如下错误。

    $ postfix check
    postsuper: fatal: scan_dir_push: open directory defer: Permission denied
    

    原因是一般编译安装时,Postfix队列目录/var/spoole/postfix/,下有几个目录会使用系统自带postfix的目录,由于系统默认使用postfix(UID:89)用户给删除了,所以这些目录就找不到postfix用户,开启时就会报错一些权限问题,把以下几个目录权限给修改以下就好了,如果还有一些别的目录一并修改即可。

    $ chown -R postfix.root /var/spool/postfix/defer/
    $ chown -R postfix.root /var/spool/postfix/deferred/
    $ chown -R postfix.root /var/spool/postfix/private/
    $ chown -R postfix.postdrop /var/spool/postfix/public/
    $ chown -R postfix.postdrop /var/spool/postfix/maildrop/
    $ chown -R postfix.root /var/lib/postfix/
    

4.3、Postfix 进程

  • master
    Postfix 邮件系统的大脑,它产生所有其他进程。

  • smtpd
    作为服务器端程序处理所有外部连进来的请求。

  • smtp
    作为客户端程序处理所有对外发起连接的请求。

  • qmgr
    Postfix 邮件系统的心脏,处理和控制邮件队列里面的所有消息。

  • local
    Postfix 自有的本地投递代理MDA,就是它负责把邮件保存到邮箱里。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值