码迷,mamicode.com
首页 > 系统相关 > 详细

Linux课程第二十一天学习笔记

时间:2016-12-09 01:12:45      阅读:253      评论:0      收藏:0      [点我收藏+]

标签:linux学习   linux笔记   linux课程   

#####################
#####   SMTP    #####
#####################

重新配置DNS,以及SMTP基本配置(略)

####################MTA配置####################
9)access
[root@maillinux ~]# cd /etc/postfix/
[root@maillinux postfix]# ls
access     generic        main.cf    relocated  virtual
canonical  header_checks  master.cf  transport
[root@maillinux postfix]# vim access
-----------------------------------------------
477 172.25.50.250 REJECT
:wq
-----------------------------------------------
[root@maillinux postfix]# postmap access
[root@maillinux postfix]# ls
access     canonical  header_checks  master.cf  transport
access.db  generic    main.cf        relocated  virtual
[root@maillinux postfix]# postconf -d |grep client
-----------------------------------------------
发现:
smtpd_client_restrictions =
-----------------------------------------------
[root@maillinux postfix]# postconf -e "smtpd_client_restrictions = check_client_access hash:/etc/postfix/access"
[root@maillinux postfix]# postconf -n |grep smtpd_client_restrictions
smtpd_client_restrictions = check_client_access hash:/etc/postfix/access
[root@maillinux postfix]# tail -n 1 main.cf
smtpd_client_restrictions = check_client_access hash:/etc/postfix/access
[root@maillinux postfix]# systemctl restart postfix.service

--测试--
[root@foundation50 Desktop]# telnet 172.25.50.100 25
Trying 172.25.50.100...
Connected to 172.25.50.100.
Escape character is ‘^]‘.
220 maillinux.linux.com ESMTP Postfix
mail from:root@linux.com
250 2.1.0 Ok
rcpt to:root@westos.com
554 5.7.1 <unknown[172.25.50.250]>: Client host rejected: Access denied
quit
221 2.0.0 Bye
Connection closed by foreign host.

10)sender
[root@maillinux postfix]# vim access
-----------------------------------------------
删除:
477 172.25.50.250 REJECT
:wq
-----------------------------------------------
[root@maillinux postfix]# postmap access
[root@maillinux postfix]# vim sender
-----------------------------------------------
  1 student@linux.com REJECT
:wq
-----------------------------------------------
[root@maillinux postfix]# postmap sender
[root@maillinux postfix]# ls
access     canonical  header_checks  master.cf  sender     transport
access.db  generic    main.cf        relocated  sender.db  virtual
[root@maillinux postfix]# postconf -d |grep sender
-----------------------------------------------
发现:
smtpd_sender_restrictions =
-----------------------------------------------
[root@maillinux postfix]# postconf -e "smtpd_sender_restrictions = check_sender_access hash:/etc/postfix/sender"
[root@maillinux postfix]# postconf -n |grep smtpd_sender_restrictions
smtpd_sender_restrictions = check_sender_access hash:/etc/postfix/sender
[root@maillinux postfix]# tail -n 1 main.cf
smtpd_sender_restrictions = check_sender_access hash:/etc/postfix/sender
[root@maillinux postfix]# systemctl restart postfix.service

--测试--
[root@foundation50 Desktop]# telnet 172.25.50.100 25
Trying 172.25.50.100...
Connected to 172.25.50.100.
Escape character is ‘^]‘.
220 maillinux.linux.com ESMTP Postfix
mail from:student@linux.com
250 2.1.0 Ok
rcpt to:root@westos.com
554 5.7.1 <student@linux.com>: Sender address rejected: Access denied
quit
221 2.0.0 Bye
Connection closed by foreign host.

11)recipient
[root@maillinux postfix]# vim recip
-----------------------------------------------
  1 student@linux.com REJECT
:wq
-----------------------------------------------
[root@maillinux postfix]# postmap recip
[root@maillinux postfix]# ls
access     canonical  header_checks  master.cf  recip.db   sender     transport
access.db  generic    main.cf        recip      relocated  sender.db  virtual
[root@maillinux postfix]# postconf -d |grep recip
-----------------------------------------------
发现:
smtpd_recipient_restrictions =
-----------------------------------------------
[root@maillinux postfix]# postconf -e "smtpd_recipient_restrictions = check_recipient_access hash:/etc/postfix/recip"
[root@maillinux postfix]# postconf -n |grep smtpd_recipient_restrictions
smtpd_recipient_restrictions = check_recipient_access hash:/etc/postfix/recip
[root@maillinux postfix]# tail -n 1 main.cf
smtpd_recipient_restrictions = check_recipient_access hash:/etc/postfix/recip
[root@maillinux postfix]# systemctl restart postfix.service

--测试--
[root@foundation50 Desktop]# telnet 172.25.50.100 25
Trying 172.25.50.100...
Connected to 172.25.50.100.
Escape character is ‘^]‘.
220 maillinux.linux.com ESMTP Postfix
mail from:root@linux.com
250 2.1.0 Ok
rcpt to:student@linux.com
554 5.7.1 <student@linux.com>: Recipient address rejected: Access denied
quit
221 2.0.0 Bye
Connection closed by foreign host.

==恢复配置==
[root@maillinux postfix]# vim main.cf
-----------------------------------------------
删除:
680 smtpd_client_restrictions = check_client_access hash:/etc/postfix/access
681 smtpd_sender_restrictions = check_sender_access hash:/etc/postfix/sender
682 smtpd_recipient_restrictions = check_recipient_access hash:/etc/postfix/recip
:wq
-----------------------------------------------
[root@maillinux postfix]# systemctl restart postfix.service

####################Dovecot配置####################
Dovecot提供的服务有:
imap 143  pop3 110  imaps 993  pop3s 995


==dovecot配置==
[root@mailwestos ~]# yum install dovecot -y
......
[root@mailwestos ~]# cd /etc/dovecot
[root@mailwestos dovecot]# vim dovecot.conf
-----------------------------------------------
 24 protocols = imap pop3 lmtp

 44 # Space separated list of trusted network ranges. Connections from these
 45 # IPs are allowed to override their IP addresses and ports (for logging and
 46 # for authentication checks). disable_plaintext_auth is also ignored for
 47 # these networks. Typically you‘d specify your IMAP proxy servers here.
 48 login_trusted_networks = 0.0.0.0/0
 49 disable_plaintext_auth = no        ##不支持明文的话,不能用imap和pop3
:wq
-----------------------------------------------
[root@mailwestos dovecot]# cd conf.d/
[root@mailwestos conf.d]# ls
10-auth.conf       20-imap.conf                 auth-dict.conf.ext
10-director.conf   20-lmtp.conf                 auth-ldap.conf.ext
10-logging.conf    20-pop3.conf                 auth-master.conf.ext
10-mail.conf       90-acl.conf                  auth-passwdfile.conf.ext
10-master.conf     90-plugin.conf               auth-sql.conf.ext
10-ssl.conf        90-quota.conf                auth-static.conf.ext
15-lda.conf        auth-checkpassword.conf.ext  auth-system.conf.ext
15-mailboxes.conf  auth-deny.conf.ext           auth-vpopmail.conf.ext
[root@mailwestos conf.d]# vim 10-mail.conf
-----------------------------------------------
 17 #   %u - username

 25 #   mail_location = mbox:~/mail:INBOX=/var/mail/%u

 30 mail_location = mbox:~/mail:INBOX=/var/mail/%u
:wq
-----------------------------------------------
[root@mailwestos conf.d]# ll /var/mail
lrwxrwxrwx. 1 root root 10 May  6  2014 /var/mail -> spool/mail
[root@mailwestos conf.d]# ll /var/mail/
total 0
-rw-------. 1 root    mail 0 Dec  5 21:12 root
-rw-rw----. 1 rpc     mail 0 May  6  2014 rpc
-rw-rw----. 1 student mail 0 Dec  5 21:12 student
[root@mailwestos conf.d]# systemctl start dovecot
[root@mailwestos conf.d]# systemctl enable dovecot
ln -s ‘/usr/lib/systemd/system/dovecot.service‘ ‘/etc/systemd/system/multi-user.target.wants/dovecot.service‘
[root@mailwestos conf.d]# netstat -antlpe |grep dovecot
tcp        0      0 0.0.0.0:993             0.0.0.0:*               LISTEN      0          59186      4509/dovecot        
tcp        0      0 0.0.0.0:995             0.0.0.0:*               LISTEN      0          59162      4509/dovecot        
tcp        0      0 0.0.0.0:110             0.0.0.0:*               LISTEN      0          59160      4509/dovecot        
tcp        0      0 0.0.0.0:143             0.0.0.0:*               LISTEN      0          59184      4509/dovecot        
tcp6       0      0 :::993                  :::*                    LISTEN      0          59187      4509/dovecot        
tcp6       0      0 :::995                  :::*                    LISTEN      0          59163      4509/dovecot        
tcp6       0      0 :::110                  :::*                    LISTEN      0          59161      4509/dovecot        
tcp6       0      0 :::143                  :::*                    LISTEN      0          59185      4509/dovecot        
[root@mailwestos conf.d]# useradd westos
[root@mailwestos conf.d]# passwd westos
Changing password for user westos.
New password: westos
BAD PASSWORD: The password is shorter than 8 characters
Retype new password: westos
passwd: all authentication tokens updated successfully.
[root@mailwestos conf.d]# > /var/log/maillog

[root@foundation50 Desktop]# yum install mutt -y
......
[root@foundation50 Desktop]# mutt -f pop://westos@172.25.50.200
-- Mutt: SSL Certificate check (certificate 1 of 1 in chain)
(r)eject, accept (o)nce, (a)ccept always
##按"o"
-- Mutt: SSL Certificate check (certificate 1 of 1 in chain)
Password for westos@172.25.50.200: westos
##认证失败

[root@mailwestos conf.d]# cat /var/log/maillog
发现:
Error: chown(/home/westos/mail/.imap, group=12(mail)) failed: Operation not permitted
[root@mailwestos conf.d]# su - westos
[westos@mailwestos ~]$ ls
mail
[westos@mailwestos ~]$ cd mail/
[westos@mailwestos mail]$ ls
[westos@mailwestos mail]$ mkdir .imap
[westos@mailwestos mail]$ exit
logout
[root@mailwestos conf.d]# > /var/log/maillog

[root@foundation50 Desktop]# mutt -f pop://westos@172.25.50.200
-- Mutt: SSL Certificate check (certificate 1 of 1 in chain)
(r)eject, accept (o)nce, (a)ccept always
##按"o"
-- Mutt: SSL Certificate check (certificate 1 of 1 in chain)
Password for westos@172.25.50.200: westos
##认证失败,弹出

[root@mailwestos conf.d]# cat /var/log/maillog
发现:
Error: chown(/home/westos/mail/.imap/INBOX, group=12(mail)) failed: Operation not permitted
[root@mailwestos conf.d]# su - westos
Last login: Mon Dec  5 22:51:26 EST 2016 on pts/0
[westos@mailwestos ~]$ touch /home/westos/mail/.imap/INBOX
[westos@mailwestos ~]$ exit
logout

[root@foundation50 Desktop]# mutt -f pop://westos@172.25.50.200
-- Mutt: SSL Certificate check (certificate 1 of 1 in chain)
(r)eject, accept (o)nce, (a)ccept always
##按"o"
-- Mutt: SSL Certificate check (certificate 1 of 1 in chain)
Password for westos@172.25.50.200: westos
##认证成功,进入
##没有邮件,按"q"退出

[root@maillinux postfix]# mail westos@westos.com
Subject: 111
111
111
.
EOT
[root@maillinux postfix]# mail westos@westos.com
Subject: 222
222
222
.
EOT
[root@maillinux postfix]# mail westos@westos.com
Subject: 333
333
333
.
EOT
[root@maillinux postfix]# mailq
Mail queue is empty

[root@foundation50 Desktop]# mutt -f pop://westos@172.25.50.200
-- Mutt: SSL Certificate check (certificate 1 of 1 in chain)
(r)eject, accept (o)nce, (a)ccept always
##按"o"
-- Mutt: SSL Certificate check (certificate 1 of 1 in chain)
Password for westos@172.25.50.200: westos
-----------------------------------------------
q:Quit  d:Del  u:Undel  s:Save  m:Mail  r:Reply  g:Group  ?:Help
   1 N   Dec 06 root            (0.1K) 111
   2 N   Dec 06 root            (0.1K) 222
   3 N   Dec 06 root            (0.1K) 333



---Mutt: pop://westos@172.25.50.200/ [Msgs:3 New:3 Post:2 2.1K]---(date/date)-
-----------------------------------------------
##按"上|下"选择邮件,按"Enter"查看邮件,按"q"退出

[root@mailwestos conf.d]# su - westos
Last login: Tue Dec  6 02:57:50 EST 2016 on pts/0
[westos@mailwestos ~]$ l.
.   .bash_history  .bash_profile  .cache   .mozilla
..  .bash_logout   .bashrc        .config        ##大多是从"/etc/skel"下拷贝的用户骨架文件
[westos@mailwestos ~]$ logout
[root@mailwestos conf.d]# cd /etc/skel/
[root@mailwestos skel]# ls -a
.  ..  .bash_logout  .bash_profile  .bashrc  .config  .mozilla
[root@mailwestos skel]# mkdir mail/.imap/ -p
[root@mailwestos skel]# touch mail/.imap/INBOX        ##把"mail/.imap/INBOX"直接放在这里
[root@mailwestos skel]# cd
[root@mailwestos ~]# useradd lee
[root@mailwestos ~]# passwd lee
Changing password for user lee.
New password: lee
BAD PASSWORD: The password is shorter than 8 characters
Retype new password: lee
passwd: all authentication tokens updated successfully.
[root@mailwestos ~]# su - lee
[lee@mailwestos ~]$ ls
mail
[lee@mailwestos ~]$ cd mail/
[lee@mailwestos mail]$ ls -a
.  ..  .imap
[lee@mailwestos mail]$ cd .imap/
[lee@mailwestos .imap]$ ls
INBOX
[lee@mailwestos .imap]$ ll
total 0
-rw-r--r--. 1 lee lee 0 Dec  6 03:06 INBOX
[lee@mailwestos .imap]$ logout

[root@foundation50 Desktop]# mutt -f pop://lee@172.25.50.200
-- Mutt: SSL Certificate check (certificate 1 of 1 in chain)
(r)eject, accept (o)nce, (a)ccept always
##按"o"
-- Mutt: SSL Certificate check (certificate 1 of 1 in chain)
Password for lee@172.25.50.200:    lee
##认证成功,进入
##按"q"退出

==Thunderbird的安装==
[root@foundation50 software]# pwd
/root/Documents/RHCE/老李LFTP/pub/docs/software
[root@foundation50 software]# scp thunderbird-31.4.0.tar.bz2 root@172.25.50.100:/mnt
root@172.25.50.100‘s password:
thunderbird-31.4.0.tar.bz2                    100%   35MB  35.2MB/s   00:01

[root@maillinux ~]# cd /mnt
[root@maillinux mnt]# ls
thunderbird-31.4.0.tar.bz2        ##源码安装包
[root@maillinux mnt]# tar -jxf thunderbird-31.4.0.tar.bz2
[root@maillinux mnt]# ls
thunderbird  thunderbird-31.4.0.tar.bz2
[root@maillinux mnt]# cd thunderbird/
[root@maillinux thunderbird]# ls
application.ini     libldif60.so      libxul.so
blocklist.xml       libmozalloc.so    mozilla-xremote-client
chrome              libmozsqlite3.so  omni.ja
chrome.manifest     libnspr4.so       platform.ini
components          libnss3.so        plugin-container
crashreporter       libnssckbi.so     precomplete
crashreporter.ini   libnssdbm3.chk    removed-files
defaults            libnssdbm3.so     run-mozilla.sh
dependentlibs.list  libnssutil3.so    searchplugins
dictionaries        libplc4.so        Throbber-small.gif
extensions          libplds4.so       thunderbird
icons               libprldap60.so    thunderbird-bin
isp                 libsmime3.so      updater
libfreebl3.chk      libsoftokn3.chk   updater.ini
libfreebl3.so       libsoftokn3.so    update-settings.ini
libldap60.so        libssl3.so
[root@maillinux thunderbird]# ./thunderbird
-bash: ./thunderbird: /lib/ld-linux.so.2: bad ELF interpreter: No such file or directory
[root@maillinux thunderbird]# yum whatprovides /lib/ld-linux.so.2
Loaded plugins: langpacks
rhel_dvd/filelists_db                                    | 3.0 MB     00:00     
glibc-2.17-55.el7.i686 : The GNU libc libraries
Repo        : rhel_dvd
Matched from:
Filename    : /lib/ld-linux.so.2



[root@maillinux thunderbird]# yum install glibc-2.17-55.el7.i686 -y
......
>重复以上方法,直到装好
[root@maillinux thunderbird]# history
-----------------------------------------------
  144  ./thunderbird
  145  yum whatprovides /lib/ld-linux.so.2
  146  yum install glibc-2.17-55.el7.i686 -y
  147  ./thunderbird
  148  yum whatprovides */libstdc++.so.6
  149  yum install libstdc++-4.8.2-16.el7.i686 -y
  150  ./thunderbird
  151  yum whatprovides */libXrender.so.1
  152  yum install libXrender-0.9.8-2.1.el7.i686 -y
  153  ./thunderbird
  154  yum whatprovides */libasound.so.2
  155  yum install alsa-lib-1.0.27.2-3.el7.i686 -y
  156  ./thunderbird
  157  yum whatprovides */libdbus-glib-1.so.2
  158  yum install dbus-glib-0.100-7.el7.i686 -y
  159  ./thunderbird
  160  yum whatprovides */libgtk-x11-2.0.so.0
  161  yum install gtk2-2.24.22-5.el7.i686 -y
  162  ./thunderbird
  163  yum whatprovides */libXt.so.6
  164  yum install libXt-1.1.4-6.1.el7.i686 -y
  165  ./thunderbird
-----------------------------------------------
[root@maillinux thunderbird]# ./thunderbird &
##安装成功!

==Thunderbird的设置==
打开Thunderbird
-->点击"使用我现有的账号"
【您的大名】    /westos
【电子邮件地址】    /westos@westos.com
【密码】        /westos
【记住密码】    (打钩)
-->点击"继续"-->如果过不去,点击"手动设定"
            【私服器主机名称】    【埠】    【SSL】    【认证】
【收件】         IMAP     172.25.50.200     143      无    自动检测
【寄件】         SMTP     172.25.50.200     25      无    自动检测
【使用者名称】    【收件】     westos            【寄件】    westos
-->点击"重新测试"-->点击"完成"
【我了解危险性】    (打钩)
-->完成
-->点击"收件匣",自动收件-->收到三封邮件:111,222,333

-->点中westos@westos.com-->单击右键-->设定-->帐号操作-->新增电子邮箱帐号
-->使用同样的方法添加账号"lee@westos.com"
-->确定
-->点击"收件匣",自动收件-->没有新的邮件

-->点击"写信"
【至】    westos@westos.com
【主旨】    444
【内文】
444
444
-->点击"传送"
-->点击westos@westos.com下的"收件匣"-->收到邮件:444

-->点击回复
【至】    lee@westos.com
【主旨】    555
【内文】
555
555
-->点击"传送"
-->点击lee@westos.com下的"收件匣"-->收到邮件:555

[root@mailwestos ~]# mail -u westos
Heirloom Mail version 12.5 7/5/10.  Type ? for help.
"/var/mail/westos": 4 messages 1 new
    1 root                  Tue Dec  6 02:24  25/846   "111"
    2 root                  Tue Dec  6 02:28  24/811   "222"
    3 root                  Tue Dec  6 02:28  24/811   "333"
>N  4 lee                   Tue Dec  6 20:04  20/680   "444"
& 4
Message  4:
From lee@westos.com  Tue Dec  6 20:04:46 2016
Return-Path: <lee@westos.com>
X-Original-To: westos@westos.com
Delivered-To: westos@westos.com
Date: Tue, 06 Dec 2016 20:04:46 -0500
From: lee <lee@westos.com>
User-Agent: Mozilla/5.0 (X11; Linux i686 on x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0
To: westos@westos.com
Subject: 444
Content-Type: text/plain; charset=utf-8; format=flowed
Status: R

444
444

& q
Held 4 messages in /var/mail/westos
[root@mailwestos ~]# mail -u lee
Heirloom Mail version 12.5 7/5/10.  Type ? for help.
"/var/mail/lee": 1 message 1 new
>N  1 westos                Tue Dec  6 20:11  22/771   "555"
& 1
Message  1:
From westos@westos.com  Tue Dec  6 20:11:30 2016
Return-Path: <westos@westos.com>
X-Original-To: lee@westos.com
Delivered-To: lee@westos.com
Date: Tue, 06 Dec 2016 20:11:30 -0500
From: westos <westos@westos.com>
User-Agent: Mozilla/5.0 (X11; Linux i686 on x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0
To: lee <lee@westos.com>
Subject: 555
Content-Type: text/plain; charset=utf-8; format=flowed
Status: R

555
555

& q
Held 1 message in /var/mail/lee

[root@foundation50 Desktop]# telnet 172.25.50.200 110
Trying 172.25.50.200...
Connected to 172.25.50.200.
Escape character is ‘^]‘.
+OK [XCLIENT] Dovecot ready.
user student
+OK
pass student
-ERR [SYS/PERM] Permission denied    ##没有权限
Connection closed by foreign host.
[root@foundation50 Desktop]# telnet 172.25.50.200 110
Trying 172.25.50.200...
Connected to 172.25.50.200.
Escape character is ‘^]‘.
+OK [XCLIENT] Dovecot ready.
user lee
+OK
pass lee
+OK Logged in.
quit
+OK Logging out.
Connection closed by foreign host.

####################虚拟账号####################
==mysql配置==
[root@mailwestos ~]# yum install mariadb-server httpd php php-mysql -y
......
[root@mailwestos ~]# systemctl start mariadb
[root@mailwestos ~]# systemctl enable mariadb
ln -s ‘/usr/lib/systemd/system/mariadb.service‘ ‘/etc/systemd/system/multi-user.target.wants/mariadb.service‘
[root@mailwestos ~]# mysql_secure_installation
......
##设定root用户的密码为westos,其它一路回车
[root@mailwestos ~]# systemctl restart mariadb

[root@foundation50 software]# pwd
/root/Documents/RHCE/老李LFTP/pub/docs/software
[root@foundation50 software]# scp phpMyAdmin-3.4.0-all-languages.tar.bz2 root@172.25.50.200:/var/www/html
root@172.25.50.200‘s password:
phpMyAdmin-3.4.0-all-languages.tar.bz2        100% 4441KB   4.3MB/s   00:00    

[root@mailwestos ~]# cd /var/www/html/
[root@mailwestos html]# ls
phpMyAdmin-3.4.0-all-languages.tar.bz2
[root@mailwestos html]# tar -jxf phpMyAdmin-3.4.0-all-languages.tar.bz2
[root@mailwestos html]# ls
phpMyAdmin-3.4.0-all-languages  phpMyAdmin-3.4.0-all-languages.tar.bz2
[root@mailwestos html]# rm -fr phpMyAdmin-3.4.0-all-languages.tar.bz2
[root@mailwestos html]# mv phpMyAdmin-3.4.0-all-languages myadmin
[root@mailwestos html]# cd myadmin/
[root@mailwestos myadmin]# cp -p config.sample.inc.php config.inc.php
[root@mailwestos myadmin]# vim config.inc.php
-----------------------------------------------
 17 $cfg[‘blowfish_secret‘] = ‘westos‘; /* YOU MUST FILL IN THIS FOR COOKIE AUTH    ! */
:wq
-----------------------------------------------
[root@mailwestos myadmin]# systemctl start httpd
[root@mailwestos myadmin]# systemctl enable httpd
ln -s ‘/usr/lib/systemd/system/httpd.service‘ ‘/etc/systemd/system/multi-user.target.wants/httpd.service‘
[root@mailwestos myadmin]# firefox &

>进入网址:http://172.25.50.100/myadmin
>登陆后,配置email库,muser表,4个字段(username,password,domain,maildir)
>插入用户信息admin@westos.org/123/westos.org/"westos.org/admin/"
>插入用户信息lee@westos.org/123/westos.org/"westos.org/lee/"
##注意:表用户的域(org)一定要和本机的域(com)区分开

[root@mailwestos myadmin]# mysql -uroot -pwestos
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 22
Server version: 5.5.35-MariaDB MariaDB Server

Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

MariaDB [(none)]> DESC email.muser;
+----------+--------------+------+-----+---------+-------+
| Field    | Type         | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+-------+
| username | varchar(50)  | NO   |     | NULL    |       |
| password | varchar(50)  | NO   |     | NULL    |       |
| domain   | varchar(50)  | NO   |     | NULL    |       |
| maildir  | varchar(100) | NO   |     | NULL    |       |
+----------+--------------+------+-----+---------+-------+
4 rows in set (0.00 sec)

MariaDB [(none)]> SELECT * FROM email.muser;
+------------------+----------+------------+-------------------+
| username         | password | domain     | maildir           |
+------------------+----------+------------+-------------------+
| admin@westos.org | 123      | westos.org | westos.org/admin/ |
| lee@westos.org   | 123      | westos.org | westos.org/lee/   |
+------------------+----------+------------+-------------------+
2 rows in set (0.00 sec)

MariaDB [(none)]> CREATE USER postfix@localhost identified by ‘postfix‘;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> GRANT INSERT,UPDATE,SELECT on email.* to postfix@localhost;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> Ctrl-C -- exit!
Aborted
[root@mailwestos myadmin]# mysql -upostfix -ppostfix
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 24
Server version: 5.5.35-MariaDB MariaDB Server

Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

MariaDB [(none)]> SELECT * FROM email.muser;
+------------------+----------+------------+-------------------+
| username         | password | domain     | maildir           |
+------------------+----------+------------+-------------------+
| admin@westos.org | 123      | westos.org | westos.org/admin/ |
| lee@westos.org   | 123      | westos.org | westos.org/lee/   |
+------------------+----------+------------+-------------------+
2 rows in set (0.01 sec)

MariaDB [(none)]> Ctrl-C -- exit!
Aborted

==postfix配置==
[root@mailwestos myadmin]# cd /etc/postfix/
[root@mailwestos postfix]# vim mysql-users.cf
-----------------------------------------------
  1 hosts = localhost
  2 user = postfix
  3 password = postfix
  4 dbname = email
  5 table = muser
  6 select_field = username
  7 where_field = username
:wq
-----------------------------------------------
[root@mailwestos postfix]# postmap -q "admin@westos.org" mysql:/etc/postfix/mysql-users.cf
admin@westos.org    ##查询成功
[root@mailwestos postfix]# cp mysql-users.cf mysql-domain.cf
[root@mailwestos postfix]# cp mysql-users.cf mysql-maildir.cf
[root@mailwestos postfix]# vim mysql-domain.cf
-----------------------------------------------
  6 select_field = domain
  7 where_field = domain
:wq
-----------------------------------------------
[root@mailwestos postfix]# postmap -q "westos.org" mysql:/etc/postfix/mysql-domain.cf
westos.org,westos.org    ##查询成功
[root@mailwestos postfix]# vim mysql-maildir.cf
-----------------------------------------------
  6 select_field = maildir
  7 where_field = username
:wq
-----------------------------------------------
[root@mailwestos postfix]# postmap -q "admin@westos.org" mysql:/etc/postfix/mysql-maildir.cf
westos.org/admin/    ##查询成功
[root@mailwestos postfix]# groupadd vmail -g 666
[root@mailwestos postfix]# useradd -u 666 -g 666 -s /sbin/nologin vmail
[root@mailwestos postfix]# postconf -d | grep virtual
......
##后面使用"postconf -e"命令,参数容易敲错,推荐从这里复制粘贴
[root@mailwestos postfix]# postconf -e "virtual_gid_maps = static:666"
[root@mailwestos postfix]# postconf -e "virtual_uid_maps = static:666"
[root@mailwestos postfix]# postconf -e "virtual_mailbox_base = /home/vmail"
[root@mailwestos postfix]# postconf -e "virtual_alias_maps = mysql:/etc/postfix/mysql-users.cf"
[root@mailwestos postfix]# postconf -e "virtual_mailbox_domains = mysql:/etc/postfix/mysql-domain.cf"
[root@mailwestos postfix]# postconf -e "virtual_mailbox_maps = mysql:/etc/postfix/mysql-maildir.cf"
[root@mailwestos postfix]# postconf -n | grep virtual
virtual_alias_maps = mysql:/etc/postfix/mysql-users.cf
virtual_gid_maps = static:666
virtual_mailbox_base = /home/vmail
virtual_mailbox_domains = mysql:/etc/postfix/mysql-domain.cf
virtual_mailbox_maps = mysql:/etc/postfix/mysql-maildir.cf
virtual_uid_maps = static:666
[root@mailwestos postfix]# systemctl restart postfix.service
[root@mailwestos postfix]# cd /home
[root@mailwestos home]# ls
lee  student  vmail  westos
[root@mailwestos home]# cd vmail/
[root@mailwestos vmail]# ls
mail                ##"mail"是受之前实验影响,自动生成的目录,和本次实验无关,不用管
[root@mailwestos vmail]# mail admin@westos.org
Subject: test
test
test
.
EOT
[root@mailwestos vmail]# mailq
Mail queue is empty
[root@mailwestos vmail]# ls
mail  westos.org        ##建立目录"westos.org"
[root@mailwestos vmail]# cd westos.org/
[root@mailwestos westos.org]# ls
admin                ##建立目录"admin"
[root@mailwestos westos.org]# cd admin/
[root@mailwestos admin]# ls
cur  new  tmp            ##建立目录"cur,new,tmp"

==dovecot配置==
[root@mailwestos admin]# cd /etc/dovecot/conf.d/
[root@mailwestos conf.d]# ls
10-auth.conf       20-imap.conf                 auth-dict.conf.ext
10-director.conf   20-lmtp.conf                 auth-ldap.conf.ext
10-logging.conf    20-pop3.conf                 auth-master.conf.ext
10-mail.conf       90-acl.conf                  auth-passwdfile.conf.ext
10-master.conf     90-plugin.conf               auth-sql.conf.ext
10-ssl.conf        90-quota.conf                auth-static.conf.ext
15-lda.conf        auth-checkpassword.conf.ext  auth-system.conf.ext
15-mailboxes.conf  auth-deny.conf.ext           auth-vpopmail.conf.ext
[root@mailwestos conf.d]# vim 10-mail.conf
-----------------------------------------------
 18 #   %n - user part in user@domain, same as %u if there‘s no domain
 19 #   %d - domain part in user@domain, empty if there‘s no domain

 30 mail_location = maildir:/home/vmail/%d/%n

168 first_valid_uid = 666

175 first_valid_gid = 666
:wq
-----------------------------------------------
[root@mailwestos conf.d]# vim 10-auth.conf
-----------------------------------------------
123 !include auth-sql.conf.ext
:wq
-----------------------------------------------
[root@mailwestos conf.d]# vim auth-sql.conf.ext
-----------------------------------------------
  8   # Path for SQL configuration file, see example-config/dovecot-sql.conf.ext
:q
-----------------------------------------------
[root@mailwestos conf.d]# cd /usr/share/doc/dovecot-2.2.10/example-config/
[root@mailwestos example-config]# ls
conf.d        dovecot-dict-auth.conf.ext  dovecot-ldap.conf.ext
dovecot.conf  dovecot-dict-sql.conf.ext   dovecot-sql.conf.ext
[root@mailwestos example-config]# cp dovecot-sql.conf.ext /etc/dovecot/
[root@mailwestos example-config]# cd /etc/dovecot/
[root@mailwestos dovecot]# ls
conf.d  dovecot.conf  dovecot-sql.conf.ext
[root@mailwestos dovecot]# vim dovecot-sql.conf.ext
-----------------------------------------------
 32 driver = mysql

 71 connect = host=localhost dbname=email user=postfix password=postfix

 78 default_pass_scheme = PLAIN            ##明文

107 password_query = \
108   SELECT username, domain, password \
109   FROM muser WHERE username = ‘%u‘ AND domain = ‘%d‘

125 user_query = SELECT maildir, 666 AS uid, 666 AS gid FROM muser WHERE username = ‘%u‘
:wq
-----------------------------------------------
[root@mailwestos dovecot]# systemctl restart dovecot.service
[root@mailwestos dovecot]# telnet 172.25.50.200 110
Trying 172.25.50.200...
Connected to 172.25.50.200.
Escape character is ‘^]‘.
-ERR Disconnected: Auth process broken
Connection closed by foreign host.
[root@mailwestos dovecot]# tail -n 5 /var/log/maillog
/发现
Dec  7 01:51:54 mailwestos dovecot: auth: Fatal: Unknown database driver ‘mysql‘
[root@mailwestos dovecot]# yum search dovecot
Loaded plugins: langpacks
============================= N/S matched: dovecot =============================
dovecot-mysql.x86_64 : MySQL back end for dovecot
dovecot-pgsql.x86_64 : Postgres SQL back end for dovecot
dovecot-pigeonhole.x86_64 : Sieve and managesieve plug-in for dovecot
dovecot.i686 : Secure imap and pop3 server
dovecot.x86_64 : Secure imap and pop3 server

  Name and summary matches only, use "search all" for everything.
[root@mailwestos dovecot]# yum install dovecot-mysql -y
......
[root@mailwestos dovecot]# systemctl restart dovecot.service

[root@mailwestos dovecot]# telnet 172.25.50.200 110
Trying 172.25.50.200...
Connected to 172.25.50.200.
Escape character is ‘^]‘.
+OK [XCLIENT] Dovecot ready.
user admin@westos.org
+OK
pass 123
+OK Logged in.
quit
+OK Logging out.
Connection closed by foreign host.
-----------------------------------------------
如果telnet测试不成功,证明dovecot配置有问题,检查dovecot的配置
排错方法:
> /var/log/maillog
cat /var/log/maillog
需要注意的是,在实验环境下可以清空日志,真正在企业里是不允许清空日志的
-----------------------------------------------
[root@mailwestos dovecot]# ls /home/vmail/westos.org/
admin

==使用Thunderbird登陆虚拟账号==
[root@maillinux thunderbird]# ./thunderbird &
打开Thunderbird,首先移除上之前实验使用的账号
-->点中"westos@westos.com"-->单击右键-->设定
-->点中"westos@westos.com"-->账号操作-->移除帐号-->确定
-->点中"lee@westos.com"-->账号操作-->移除帐号-->确定
-->点中"SMTP寄件服务器"-->点中"lee - 172.25.50.200"-->移除-->是
-->点中"westos - 172.25.50.200(预设)"-->编辑
【使用者名称】    /admin@westos.org
-->确定
-->帐号操作-->新增电子邮箱帐号
【您的大名】    /admin@westos.org
【电子邮件地址】    /admin@westos.org
【密码】        /123
【记住密码】    (打钩)
-->点击"继续"-->如果过不去,点击"手动设定"
            【私服器主机名称】    【埠】    【SSL】    【认证】
【收件】         IMAP     172.25.50.200     143      无    自动检测
【寄件】         SMTP     172.25.50.200     25      无    自动检测
【使用者名称】    【收件】     admin@westos.org    【寄件】    admin@westos.org
-->点击"重新测试"-->点击"完成"
【我了解危险性】    (打钩)
-->完成
-->确定
-->点击"收件匣",自动收件-->收到一封邮件:test

-->点中admin@westos.org-->单击右键-->设定
-->帐号操作-->新增电子邮箱帐号
-->使用同样的方法添加账号"lee@westos.org"
-->点击"收件匣",自动收件-->没有新的邮件

-->点中"admin@westos.org"-->点击"写信"
【至】    lee@westos.org
【主旨】    123
【内文】
123
123
-->点击"传送"
-->点击lee@westos.org下的"收件匣"-->收到邮件:123

-->点中"lee@westos.org"-->点击"写信"
【至】    admin@westos.org
【主旨】    456
【内文】
456
456
-->点击"传送"
-->点击admin@westos.org下的"收件匣"-->收到邮件:456

本文出自 “施超Linux学习笔记” 博客,谢绝转载!

Linux课程第二十一天学习笔记

标签:linux学习   linux笔记   linux课程   

原文地址:http://shichao.blog.51cto.com/5804953/1880874

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!