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

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux课程第二十一天学习笔记相关的知识,希望对你有一定的参考价值。

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

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

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

--测试--
[[email protected] 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:[email protected]
250 2.1.0 Ok
rcpt to:[email protected]
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
[[email protected] postfix]# vim access
-----------------------------------------------
删除:
477 172.25.50.250 REJECT
:wq
-----------------------------------------------
[[email protected] postfix]# postmap access
[[email protected] postfix]# vim sender
-----------------------------------------------
  1 [email protected] REJECT
:wq
-----------------------------------------------
[[email protected] postfix]# postmap sender
[[email protected] postfix]# ls
access     canonical  header_checks  master.cf  sender     transport
access.db  generic    main.cf        relocated  sender.db  virtual
[[email protected] postfix]# postconf -d |grep sender
-----------------------------------------------
发现:
smtpd_sender_restrictions =
-----------------------------------------------
[[email protected] postfix]# postconf -e "smtpd_sender_restrictions = check_sender_access hash:/etc/postfix/sender"
[[email protected] postfix]# postconf -n |grep smtpd_sender_restrictions
smtpd_sender_restrictions = check_sender_access hash:/etc/postfix/sender
[[email protected] postfix]# tail -n 1 main.cf
smtpd_sender_restrictions = check_sender_access hash:/etc/postfix/sender
[[email protected] postfix]# systemctl restart postfix.service

--测试--
[[email protected] 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:[email protected]
250 2.1.0 Ok
rcpt to:[email protected]
554 5.7.1 <[email protected]>: Sender address rejected: Access denied
quit
221 2.0.0 Bye
Connection closed by foreign host.

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

--测试--
[[email protected] 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:[email protected]
250 2.1.0 Ok
rcpt to:[email protected]
554 5.7.1 <[email protected]>: Recipient address rejected: Access denied
quit
221 2.0.0 Bye
Connection closed by foreign host.

==恢复配置==
[[email protected] 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
-----------------------------------------------
[[email protected] postfix]# systemctl restart postfix.service

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


==dovecot配置==
[[email protected] ~]# yum install dovecot -y
......
[[email protected] ~]# cd /etc/dovecot
[[email protected] 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
-----------------------------------------------
[[email protected] dovecot]# cd conf.d/
[[email protected] 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
[[email protected] 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
-----------------------------------------------
[[email protected] conf.d]# ll /var/mail
lrwxrwxrwx. 1 root root 10 May  6  2014 /var/mail -> spool/mail
[[email protected] 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
[[email protected] conf.d]# systemctl start dovecot
[[email protected] conf.d]# systemctl enable dovecot
ln -s ‘/usr/lib/systemd/system/dovecot.service‘ ‘/etc/systemd/system/multi-user.target.wants/dovecot.service‘
[[email protected] 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        
[[email protected] conf.d]# useradd westos
[[email protected] 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.
[[email protected] conf.d]# > /var/log/maillog

[[email protected] Desktop]# yum install mutt -y
......
[[email protected] Desktop]# mutt -f pop://[email protected]
-- 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 [email protected]: westos
##认证失败

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

[[email protected] Desktop]# mutt -f pop://[email protected]
-- 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 [email protected]: westos
##认证失败,弹出

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

[[email protected] Desktop]# mutt -f pop://[email protected]
-- 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 [email protected]: westos
##认证成功,进入
##没有邮件,按"q"退出

[[email protected] postfix]# mail [email protected]
Subject: 111
111
111
.
EOT
[[email protected] postfix]# mail [email protected]
Subject: 222
222
222
.
EOT
[[email protected] postfix]# mail [email protected]
Subject: 333
333
333
.
EOT
[[email protected] postfix]# mailq
Mail queue is empty

[[email protected] Desktop]# mutt -f pop://[email protected]
-- 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 [email protected]: 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://[email protected]/ [Msgs:3 New:3 Post:2 2.1K]---(date/date)-
-----------------------------------------------
##按"上|下"选择邮件,按"Enter"查看邮件,按"q"退出

[[email protected] conf.d]# su - westos
Last login: Tue Dec  6 02:57:50 EST 2016 on pts/0
[[email protected] ~]$ l.
.   .bash_history  .bash_profile  .cache   .mozilla
..  .bash_logout   .bashrc        .config        ##大多是从"/etc/skel"下拷贝的用户骨架文件
[[email protected] ~]$ logout
[[email protected] conf.d]# cd /etc/skel/
[[email protected] skel]# ls -a
.  ..  .bash_logout  .bash_profile  .bashrc  .config  .mozilla
[[email protected] skel]# mkdir mail/.imap/ -p
[[email protected] skel]# touch mail/.imap/INBOX        ##把"mail/.imap/INBOX"直接放在这里
[[email protected] skel]# cd
[[email protected] ~]# useradd lee
[[email protected] ~]# 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.
[[email protected] ~]# su - lee
[[email protected] ~]$ ls
mail
[[email protected] ~]$ cd mail/
[[email protected] mail]$ ls -a
.  ..  .imap
[[email protected] mail]$ cd .imap/
[[email protected] .imap]$ ls
INBOX
[[email protected] .imap]$ ll
total 0
-rw-r--r--. 1 lee lee 0 Dec  6 03:06 INBOX
[[email protected] .imap]$ logout

[[email protected] Desktop]# mutt -f pop://[email protected]
-- 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 [email protected]:    lee
##认证成功,进入
##按"q"退出

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

[[email protected] ~]# cd /mnt
[[email protected] mnt]# ls
thunderbird-31.4.0.tar.bz2        ##源码安装包
[[email protected] mnt]# tar -jxf thunderbird-31.4.0.tar.bz2
[[email protected] mnt]# ls
thunderbird  thunderbird-31.4.0.tar.bz2
[[email protected] mnt]# cd thunderbird/
[[email protected] 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
[[email protected] thunderbird]# ./thunderbird
-bash: ./thunderbird: /lib/ld-linux.so.2: bad ELF interpreter: No such file or directory
[[email protected] 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



[[email protected] thunderbird]# yum install glibc-2.17-55.el7.i686 -y
......
>重复以上方法,直到装好
[[email protected] 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
-----------------------------------------------
[[email protected] thunderbird]# ./thunderbird &
##安装成功!

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

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

-->点击"写信"
【至】    [email protected]
【主旨】    444
【内文】
444
444
-->点击"传送"
-->点击[email protected]下的"收件匣"-->收到邮件:444

-->点击回复
【至】    [email protected]
【主旨】    555
【内文】
555
555
-->点击"传送"
-->点击[email protected]下的"收件匣"-->收到邮件:555

[[email protected] ~]# 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 [email protected]  Tue Dec  6 20:04:46 2016
Return-Path: <[email protected]>
X-Original-To: [email protected]
Delivered-To: [email protected]
Date: Tue, 06 Dec 2016 20:04:46 -0500
From: lee <[email protected]>
User-Agent: Mozilla/5.0 (X11; Linux i686 on x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0
To: [email protected]
Subject: 444
Content-Type: text/plain; charset=utf-8; format=flowed
Status: R

444
444

& q
Held 4 messages in /var/mail/westos
[[email protected] ~]# 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 [email protected]  Tue Dec  6 20:11:30 2016
Return-Path: <[email protected]>
X-Original-To: [email protected]
Delivered-To: [email protected]
Date: Tue, 06 Dec 2016 20:11:30 -0500
From: westos <[email protected]>
User-Agent: Mozilla/5.0 (X11; Linux i686 on x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0
To: lee <[email protected]>
Subject: 555
Content-Type: text/plain; charset=utf-8; format=flowed
Status: R

555
555

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

[[email protected] 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.
[[email protected] 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配置==
[[email protected] ~]# yum install mariadb-server httpd php php-mysql -y
......
[[email protected] ~]# systemctl start mariadb
[[email protected] ~]# systemctl enable mariadb
ln -s ‘/usr/lib/systemd/system/mariadb.service‘ ‘/etc/systemd/system/multi-user.target.wants/mariadb.service‘
[[email protected] ~]# mysql_secure_installation
......
##设定root用户的密码为westos,其它一路回车
[[email protected] ~]# systemctl restart mariadb

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

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

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

[[email protected] 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           |
+------------------+----------+------------+-------------------+
| [email protected] | 123      | westos.org | westos.org/admin/ |
| [email protected]   | 123      | westos.org | westos.org/lee/   |
+------------------+----------+------------+-------------------+
2 rows in set (0.00 sec)

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

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

MariaDB [(none)]> Ctrl-C -- exit!
Aborted
[[email protected] 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           |
+------------------+----------+------------+-------------------+
| [email protected] | 123      | westos.org | westos.org/admin/ |
| [email protected]   | 123      | westos.org | westos.org/lee/   |
+------------------+----------+------------+-------------------+
2 rows in set (0.01 sec)

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

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

==dovecot配置==
[[email protected] admin]# cd /etc/dovecot/conf.d/
[[email protected] 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
[[email protected] conf.d]# vim 10-mail.conf
-----------------------------------------------
 18 #   %n - user part in [email protected], same as %u if there‘s no domain
 19 #   %d - domain part in [email protected], 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
-----------------------------------------------
[[email protected] conf.d]# vim 10-auth.conf
-----------------------------------------------
123 !include auth-sql.conf.ext
:wq
-----------------------------------------------
[[email protected] conf.d]# vim auth-sql.conf.ext
-----------------------------------------------
  8   # Path for SQL configuration file, see example-config/dovecot-sql.conf.ext
:q
-----------------------------------------------
[[email protected] conf.d]# cd /usr/share/doc/dovecot-2.2.10/example-config/
[[email protected] 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
[[email protected] example-config]# cp dovecot-sql.conf.ext /etc/dovecot/
[[email protected] example-config]# cd /etc/dovecot/
[[email protected] dovecot]# ls
conf.d  dovecot.conf  dovecot-sql.conf.ext
[[email protected] 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
-----------------------------------------------
[[email protected] dovecot]# systemctl restart dovecot.service
[[email protected] 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.
[[email protected] dovecot]# tail -n 5 /var/log/maillog
/发现
Dec  7 01:51:54 mailwestos dovecot: auth: Fatal: Unknown database driver ‘mysql‘
[[email protected] 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.
[[email protected] dovecot]# yum install dovecot-mysql -y
......
[[email protected] dovecot]# systemctl restart dovecot.service

[[email protected] 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 [email protected]
+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
需要注意的是,在实验环境下可以清空日志,真正在企业里是不允许清空日志的
-----------------------------------------------
[[email protected] dovecot]# ls /home/vmail/westos.org/
admin

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

-->点中[email protected]>单击右键-->设定
-->帐号操作-->新增电子邮箱帐号
-->使用同样的方法添加账号"[email protected]"
-->点击"收件匣",自动收件-->没有新的邮件

-->点中"[email protected]"-->点击"写信"
【至】    [email protected]
【主旨】    123
【内文】
123
123
-->点击"传送"
-->点击[email protected]下的"收件匣"-->收到邮件:123

-->点中"[email protected]"-->点击"写信"
【至】    [email protected]
【主旨】    456
【内文】
456
456
-->点击"传送"
-->点击[email protected]下的"收件匣"-->收到邮件:456

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

以上是关于Linux课程第二十一天学习笔记的主要内容,如果未能解决你的问题,请参考以下文章

Linux课程第一天学习笔记

Linux课程第二十天学习笔记

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

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

Python学习笔记第二十一周

斯坦福大学数据可视化课程学习笔记:第二节 从数据到图像