Linux mail server construction experiment

Linux mail server construction experiment

Preface

This article focuses on the construction process in the back. The principle and work flow of the mail service will be briefly introduced in the front. If there are any errors or omissions, you are welcome to correct and criticize, thank you.

Basic theory description

E-mail server is a general term for software and hardware facilities that handle mail exchanges, including e-mail programs, e-mail boxes, etc. It is an e-mail system based on E-mail service for users, and people can exchange e-mails by accessing the server. At the same time, mail has legal benefits and can provide proof, but instant messaging software cannot do this. Some companies build internal mail services for information security.

Common mail server

Sendmail、Qmail、Postfix、Zmailer、Exchange(MS)、Notes/Domino(IBM)
、Coremail、U-Mail、盈世。

Mail server composition

The email system consists of many parts, four of which are briefly introduced below.

MUA (Mail User Agent)

Refers to mail client programs such as Foxmail, Outlook, etc.

MTA (Mail Transfer Agent)

MTA (Mail Transfer Agent), MTA means "mail transfer agent", MTA is the software used on the mail host, it is also the main mail server. The main functions of MTA are as follows. It receives letters from external hosts and helps users send (send) letters. MTA will send letters to the destination MTA instead of the destination MUA. Common MTA software Postfix, Coremail, Sendmail, etc.
MDA (Mail Distribution Agent)

MDA (Mail Delivery Agent), the main function of "Mail Delivery Agent" is to place the letter received by the MTA into the mail file (inbox) under the local account according to the flow of the letter (where to send it), or Send the letter to the next MTA via the MTA. If the flow of mail is to the local machine, the function of this mail agent is not only to place the mail sent by the MTA into each user's inbox, it can also have mail filtering and other related functions, common MDA software : Maildrop
MRA (mail acquisition agent)

MRA (Mail Retrieval Agent) obtains their own emails for users. The “Mail Retrieval Agent” asks for services that enable MUA to obtain emails remotely, such as qpoper, cyrus-imap, courier-imap, dovecot, etc., in order to save emails. The format is compatible, and the mail delivery agent order MDA is often requested in the MRA order. The protocols used by MRA are POP3 and IMAP4. POP3 allows users to download emails from the server and read them offline. IMAP4 is used for those users who don't have foreign mailboxes, and has the ability to operate mailboxes remotely. IMAP4 allows multiple client machines to access a mailbox at the same time.

Protocol used

Sending protocol MUA》 MTA

SMTP: Simple Mail Transfer Protocol, TCP 25 port, use TCP 465 port for encryption

Receiving Agreement MUA》 MRA

POP3: The third version of the post office protocol, TCP port 110, use TCP 995 port when encrypting
IMAP4: the fourth version of Internet Message Access Protocol, TCP port 143, use TCP 993 port when encrypting

Experimental steps

The purpose of the experiment: master the basic mail service architecture.

Experiment preparation: one C6 standard test machine (firewall and selinux are closed)

Experimental planning: 192.168.10.14 (mail server)

​ 192.168.10.15 (access test)

Experiment related installation package: mail service

ps: For standard virtual machine installation, please refer to the Centos6 installation guide in the network phase

One, configure DNS service

yum install -y bind

Edit the main configuration file

vim /etc/named.conf

Modified to accept all addresses

Edit zone file

vim /etc/named.rfc1912.zones

Configure forward and reverse analysis zones

zone "extmail.org." IN {
    
    
        type master;
        file "extmail.zheng";
        allow-update {
    
     none; };
};


zone "10.168.192.in-addr.arpa" IN {
    
    
        type master;
        file "extmail.fan";
        allow-update {
    
     none; };
};

Create parse file

cd /var/named/
cp -a named.localhost extmail.zheng
cp -a named.loopback extmail.fan

Forward file configuration

vim extmail.zheng
$TTL 1D
@       IN SOA  extmail.org. rname.invalid. (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
        NS      dns.extmail.org.
        MX  3   mail.extmail.org.
mail    A       192.168.10.14
dns     A       192.168.10.14

Reverse file parsing

vim extmail.fan
$TTL 1D
@       IN SOA  extmail.org. rname.invalid. (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
        NS      dns.extmail.org.
        MX   3  mail.extmail.org.
14      PTR     dns.extmail.org.
14      PTR     mail.extmail.org.

Start the service, set it to self-start after booting, and test whether the DNS configuration is successful.

service named start
chkconfig named on
echo "DNS1=192.168.10.14" >> /etc/sysconfig/network-scripts/ifcfg-eth0
service network restart
nslookup

The test passed, and both the forward analysis and reverse analysis were set successfully.

Two, configure MySQL service

yum install mysql mysql-server mailx httpd -y

Start the service and set it to start at boot

service mysqld start
chkconfig mysqld on

Set initial password

mysqladmin -uroot password 123

Connect to the database test

mysql -uroot -p123

The database is set up.

Three, configure the Apache service

yum -y install httpd lrzsz

Create mail service web file directory

mkdir /var/www/extsuite

Prepare the extmail installation image (download link above), create a mount directory, and mount the installation image.

mkdir /mnt/iso
mount -o loop EXTMAIL.iso /mnt/iso/

Copy all files in the mirror to the root directory

cd
cp -a /mnt/iso/* .

Unzip the file to the corresponding directory

tar -zxf extmail-1.2.tar.gz -C /var/www/extsuite/
tar -zxf extman-1.1.tar.gz -C /var/www/extsuite/

Simplify the directory name for easy access.

cd /var/www/extsuite/
mv extmail-1.2 extmail
mv extman-1.1 extman

Perform administrator configuration and generate encrypted passwords.

grub-md5-crypt

Replace the administrator password with the generated encrypted password.

vim init.sql

Restore the two database files to the database

mysql -uroot -p < extmail.sql
mysql -uroot -p < init.sql

Fourth, configure POSTFIX service

Copy the template file to the specified location

cp mysql_virtual_alias_maps.cf mysql_virtual_domains_maps.cf mysql_virtual_mailbox_maps.cf /etc/postfix/

Configure specified users

useradd -u 600 vmail
postconf -e inet_interfaces=all
postconf -e virtual_mailbox_base=/home/vmail
postconf -e virtual_uid_maps=static:600
postconf -e virtual_gid_maps=static:600

Configure the template file and start the service.

postconf -e virtual_alias_maps=mysql:/etc/postfix/mysql_virtual_alias_maps.cf
postconf -e virtual_mailbox_domains=mysql:/etc/postfix/mysql_virtual_domains_maps.cf
postconf -e virtual_mailbox_maps=mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
service postfix restart

Perform email sending test

echo "hello world" | mail -s test [email protected]

Enter the specified file to view

cd /home/vmail/
cat extmail.org/postmaster/Maildir/new/*localdomain

Email successfully received

Five, configure MRA service

Download dovecot and mysql combined use tool

yum install dovecot dovecot-mysql -y

Edit dovecot disk path related configuration

cd /etc/dovecot/conf.d/
vim 10-mail.conf
#修改24行
mail_location = maildir:/home/vmail/%d/%n/Maildir
#修改167行,指定运行用户uid
first_valid_uid = 600

Save and exit

Edit dovecot user authentication related configuration information

vim 10-auth.conf

Uncomment the 120 lines to make it authenticated by the database.

Save and exit, return to the upper-level directory, copy dovecot and MySQL combined configuration file to the current directory.

cp /usr/share/doc/dovecot-2.0.9/example-config/dovecot-sql.conf.ext  .

Edit Dovecot and database connection related configuration

vim dovecot-sql.conf.ext:
#修改29行
driver = mysql
#修改63行
connect = host=localhost dbname=extmail user=extmail password=extmail
#取消73行注释
defaulf_pass_scheme = MD5
#修改102行
password_query = \
  SELECT username, domain, password \
  FROM mailbox WHERE username = '%u' AND domain = '%d'
#修改120行
user_query = SELECT maildir, 600 AS uid, 600 AS gid FROM mailbox WHERE username = '%u'

Save and exit, restart the service and start the test.

/etc/init.d/dovecot start

Download the test software and perform a connection test

yum -y install telnet
telnet localhost 110
user [email protected]
pass extmail
list
retr 1

Successfully connected.

Six, configure the wed interface

Edit the main Apache configuration file

vim /etc/httpd/conf/httpd.conf

Configure the virtual host, uncomment line 990 and add the following information at the end of the file.

<VirtualHost *:80>
          ServerName mail.extmail.org
          DocumentRoot /var/www/extsuite/extmail/html/
          ScriptAlias /extmail/cgi /var/www/extsuite/extmail/cgi
          Alias /extmail /var/www/extsuite/extmail/html
          ScriptAlias /extman/cgi /var/www/extsuite/extman/cgi
          Alias /extman /var/www/extsuite/extman/html
          SuexecUserGroup vmail vmail
</VirtualHost>

Edit settings mail wed page file

cd /var/www/extsuite/extmail
chown vmail.vmail cgi/ -R
cp webmail.cf.default webmail.cf

Edit the main configuration file to complete the basic settings.

vim wedmail.cf
#修改127行:(当前邮件目录)
SYS_MAILDIR_BASE = /home/vmail
#修改136行:(当前数据库密码存储方式)
SYS_CRYPT_TYPE = plain
#修改139、140行:(数据库名与密码)
SYS_MYSQL_USER = extmail
SYS_MYSQL_PASS = extmail

Edit the configuration file of the administrator of the set mail wed page

cd /var/www/extsuite/extman
chown vmail.vmail cgi/ -R
cp webman.cf.default webman.cf

Edit the email wed page administrator configuration file to complete the basic settings.

vim webman.cf
#修改12行:(当前邮件目录)
SYS_MAILDIR_BASE = /home/vmail
#修改18行:(缓存目录)
SYS_SESS_DIR = /tmp/
#修改27行:(随机认证码长度)
SYS_CAPTCHA_LEN = 4
#修改124行:(当前数据库密码存储方式)
SYS_CRYPT_TYPE = plain

Seven, visit test.

1. Mail server settings

Install missing dependencies

cd
yum install *CGI  perl-GD gcc* -y
yum -y install perl-GD-2.44-3.el6.x86_64.rpm

Installation log creation component

tar zxf Unix-Syslog-1.1.tar.gz
cd Unix-Syslog-1.1
perl Makefile.PL
make test
make install

Create storage directory

/var/www/extsuite/extman/daemon/cmdserver -d

Restart Apache service

service httpd restart

2. Client configuration

Configure DNS and restart the network card.

echo "DNS1=192.168.10.14" >> /etc/sysconfig/network-scripts/ifcfg-eth0
service network restart

Perform analytical testing

nslookup 192.168.10.14

Successfully analyze, open the graphical interface, and start to access the test.

init 5

3. Access test

Open the browser and enter the web address for ordinary users.

mail.extmail.org

Enter test account and default password

测试账户
postmaster
默认密码
extmail

Landed successfully

Test administrator login

mail.extmail.org/extman

Enter the set password

Carry out functional test and mass mailing test.

Log in to the test user to see if you have received it.

The group mail is successfully received, and the mail service is set up.

This article was reorganized by Vonmerlot on October 31, 2020.

Reprinting must indicate the source.

Guess you like

Origin blog.csdn.net/qq_46680028/article/details/109398967