﻿<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>学习日记 &#187; 开发工具</title>
	<atom:link href="https://www.softwareace.cn/?cat=2&#038;feed=rss2" rel="self" type="application/rss+xml" />
	<link>https://www.softwareace.cn</link>
	<description>时刻想着为自己的产品多做一些对他好的事情</description>
	<lastBuildDate>Fri, 20 Mar 2026 06:58:28 +0000</lastBuildDate>
	<language>zh-CN</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	
	<item>
		<title>GitLab修改root用户密码</title>
		<link>https://www.softwareace.cn/?p=1752</link>
		<comments>https://www.softwareace.cn/?p=1752#comments</comments>
		<pubDate>Tue, 17 Apr 2018 06:47:20 +0000</pubDate>
		<dc:creator><![CDATA[admin]]></dc:creator>
				<category><![CDATA[git]]></category>

		<guid isPermaLink="false">http://www.softwareace.cn/?p=1752</guid>
		<description><![CDATA[GitLab是一个私有的Git仓库，具有较好的项目管理和用户管理能力。 对于普通用户而言，通过系统的重置密码， [&#8230;]]]></description>
				<content:encoded><![CDATA[<p style="color: #4f4f4f;">GitLab是一个私有的Git仓库，具有较好的项目管理和用户管理能力。<br />
对于普通用户而言，通过系统的重置密码，接受邮件即可解决，可是GitLab的管理员账号，缺省的邮箱是一个不存在的邮箱地址，所以没有办法通过邮箱来复位。<br />
通过在服务器上，可以修改用户的密码：<br />
官方修改密码：(<a style="color: #6795b5;" href="http://docs.gitlab.com/ce/security/reset_root_password.html" target="_blank">http://docs.gitlab.com/ce/security/reset_root_password.html</a>)<br />
不过，笔者通过该方法是，发现，不能使用引号来包括密码。<br />
具体方法如下：<br />
1. 在root用户下，执行</p>
<p></p><pre class="crayon-plain-tag">gitlab-rails console production</pre><p>&nbsp;</p>
<ol style="color: #454545;">
<li>获得用户数据，修改用户密码</li>
<li>
<pre class="crayon-plain-tag">[root@svr34 bin]# gitlab-rails console production
Loading production environment (Rails 4.2.5.2)
irb(main):001:0&gt; user = User.where(id: 1).first
=&gt; #&lt;User id: 1, email: "admin@example.com", ...
irb(main):002:0&gt; user.password=12345678
=&gt; 12345678
irb(main):003:0&gt; user.password_confirmation=12345678
=&gt; 12345678
irb(main):004:0&gt; user.save!
=&gt; true
irb(main):005:0&gt; quit</pre><br />
&nbsp;</li>
</ol>
<p style="color: #4f4f4f;">注意：<span style="font-weight: bold;">密码没有使用引号</span>，奇怪的是使用单引号或双引号，密码就无效，估计是包含了这个字符，不包含，就没有问题。<br />
3. 保存用户数据</p>
<p></p><pre class="crayon-plain-tag">user.save!</pre><p></p>
<p style="color: #4f4f4f;">注意需要使用后面的<span style="font-weight: bold;">感叹号!</span></p>
]]></content:encoded>
			<wfw:commentRss>https://www.softwareace.cn/?feed=rss2&#038;p=1752</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing Apache, PHP and MySQL on IBM AIX 7.1</title>
		<link>https://www.softwareace.cn/?p=1651</link>
		<comments>https://www.softwareace.cn/?p=1651#comments</comments>
		<pubDate>Mon, 12 Jun 2017 09:58:05 +0000</pubDate>
		<dc:creator><![CDATA[admin]]></dc:creator>
				<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.softwareace.cn/?p=1651</guid>
		<description><![CDATA[I have recently had the pleasure of installing Apache,  [&#8230;]]]></description>
				<content:encoded><![CDATA[<div class="fusion-fullwidth fullwidth-box hundred-percent-fullwidth" style="color: #747474;">
<div class="fusion-builder-row fusion-row ">
<div class="fusion-layout-column fusion_builder_column fusion_builder_column_1_1  fusion-one-full fusion-column-first fusion-column-last fusion-column-no-min-height 1_1">
<div class="fusion-column-wrapper" data-bg-url="">
<div id="codeSnippetWrapper">I have recently had the pleasure of installing Apache, PHP and MySQL on a new Power 7+ 740 System running AIX 7.1 and no matter how many times I get involved with installing these products I tend to spend a lot of the day looking up the same old information and today I have decided that this is worthy of a blog post if only to serve as reminder for the next time that I will inevitably have to do this for another client.</div>
<p>Here is the process that I followed together with the various links that I have found useful in sourcing the open source products that I required to get the basic installations operational.</p>
<p>Firstly I created a separate filesystem for /usr/sys/inst.images and gave it a size of 5GB just to ensure that the /usr filesystem itself does not get too bloated with the install packages.</p>
<p>In order to avoid the “RPM Dependency Hell” that many of you are, I am in no doubt, more than familiar with I followed the instructions given at the following weblink:</p>
<p><a style="color: #aad75b;" title="http://www.perzl.org/aix/index.php?n=FAQs.FAQs#rpm-dependency-hell" href="http://www.perzl.org/aix/index.php?n=FAQs.FAQs#rpm-dependency-hell">http://www.perzl.org/aix/index.php?n=FAQs.FAQs#rpm-dependency-hell</a></p>
<p>…and installed wget-1.14-2aix5.1 together with its following list of dependencies (theres no getting around it) all of which are downloadable from <a style="color: #aad75b;" title="http://www.oss4aix.org/download/everything/RPMS/" href="http://www.oss4aix.org/download/everything/RPMS/">http://www.oss4aix.org/download/everything/RPMS/</a></p>
<p>bash-4.2-10.aix5.1.ppc.rpm</p>
<div id="advman-ad-1"></div>
<p><span style="font-weight: bold; color: black;">Installation of the httpd (Apache Server)</span></p>
<p>Lets start by creating the apache user and group which will be used for the running of the Web Server, although these can be changed later if required.</p>
<p># mkuser apache<br />
# mkgroup -A apache<br />
# mkdir /usr/sys/inst.images/httpd<br />
# cd /usr/sys/inst.images/httpd</p>
<p>Download httpd-2.4.4-1.aix5.1.ppc.deps from the following link:</p>
<p><a style="color: #aad75b;" title="http://www.oss4aix.org/download/rpmdb/deplists/aix71/httpd-2.4.3-1.aix5.1.ppc.deps" href="http://www.oss4aix.org/download/rpmdb/deplists/aix71/httpd-2.4.3-1.aix5.1.ppc.deps">http://www.oss4aix.org/download/rpmdb/deplists/aix71/httpd-2.4.3-1.aix5.1.ppc.deps</a></p>
<p>and the httpd-2.4.4-1.aix5.1.rpm from the following link:</p>
<p><a style="color: #aad75b;" title="http://www.oss4aix.org/download/everything/RPMS/httpd-2.4.3-1.aix5.1.ppc.rpm" href="http://www.oss4aix.org/download/everything/RPMS/httpd-2.4.3-1.aix5.1.ppc.rpm">http://www.oss4aix.org/download/everything/RPMS/httpd-2.4.3-1.aix5.1.ppc.rpm</a></p>
<p>and copy them into the directory created in the above step and then run the following:</p>
<p># wget -B http://www.oss4aix.org/download/everything/RPMS/ -i httpd-2.4.3-1.aix5.1.ppc.deps</p>
<p>Now install all the files as follows:</p>
<p># rpm -Uvh *.rpm</p>
<p>If you receive a message stating that any packages are already installed your can either use the –force option as follows:</p>
<p># rpm -Uvh –force *.rpm</p>
<p><span style="color: #ff0000;">* BEWARE *</span>  use the —force option with caution as this will replace and overwrite existing packages even if existing packages are NEWER than those being installed. An alternative method is to simply remove the files for which you receive an “already installed” message from the directory and run the rpm –Uvh *.rpm command again, thus ensuring that none of your previously installed packages will be overwritten. Verify that all of the files that you want to install are correct by issuing the following command and checking the output contains the files packages that you think you should have installed.</p>
<p># rpm -qa| sort | more</p>
<p>Once you are happy that the files you require have been installed you can start the Web Server with the following command:</p>
<p># /opt/freeware/sbin/apachectl start</p>
<p>You can then verify that the server has started and you should see something similar to the following output:</p>
<p># ps -ef|grep httpd</p>
<p>root 7077970 1 0 14:17:10 – 0:00 /opt/freeware/sbin/httpd -k start<br />
apache 8519684 7077970 0 14:17:11 – 0:00 /opt/freeware/sbin/httpd -k start<br />
apache 8585222 7077970 0 14:17:11 – 0:00 /opt/freeware/sbin/httpd -k start<br />
apache 8716298 7077970 0 14:17:11 – 0:00 /opt/freeware/sbin/httpd -k start</p>
<p>Now you should be able to browse to the IP address of your AIX server and see something similar to the following:</p>
<p><a style="color: #aad75b;" href="https://i2.wp.com/www.scheerer.co.uk/wp-content/uploads/2013/05/image1.png" data-caption=""><img title="image" src="https://i2.wp.com/www.scheerer.co.uk/wp-content/uploads/2013/05/image_thumb1.png?resize=630%2C184" alt="image" width="630" height="184" border="0" /></a></p>
<p>Now if you wish to have the Apache Server start every time the system is rebooted then you should enter the following command to add the required entry to the /etc/inittab</p>
<p># mkitab <span class="str">“apache:2:once:/opt/freeware/sbin/apachectl start &gt; /dev/null 2&gt;&amp;1”</span></p>
<p>…and Voila!!! Apache is installed and working, so as a little tidy up you can now remove the /usr/sys/inst.images/httpd directory and its contents.</p>
<h6 style="font-weight: 400;" data-fontsize="13" data-lineheight="17"></h6>
<h6 style="font-weight: 400;" data-fontsize="13" data-lineheight="17">Installing PHP for AIX</h6>
<p>The process for installing PHP is very similar and here is the process that I followed:</p>
<p># mkdir /usr/sys/inst.images/php<br />
# cd /usr/sys/inst.image/php</p>
<p>Now download the dependency list for mod_php_ap24-5.4.14-1.aix5.1.rpm from the following link:</p>
<p><a style="color: #aad75b;" title="http://www.oss4aix.org/download/rpmdb/deplists/aix71/mod_php_ap24-5.4.14-1.aix5.1.ppc.deps" href="http://www.oss4aix.org/download/rpmdb/deplists/aix71/mod_php_ap24-5.4.14-1.aix5.1.ppc.deps">http://www.oss4aix.org/download/rpmdb/deplists/aix71/mod_php_ap24-5.4.14-1.aix5.1.ppc.deps</a></p>
<p>and the mod_php_ap24-5.4.14-1.aix5.1.rpm package from the following link:</p>
<p><a style="color: #aad75b;" title="http://www.oss4aix.org/download/everything/RPMS/mod_php_ap24-5.4.14-1.aix5.1.ppc.rpm" href="http://www.oss4aix.org/download/everything/RPMS/mod_php_ap24-5.4.14-1.aix5.1.ppc.rpm">http://www.oss4aix.org/download/everything/RPMS/mod_php_ap24-5.4.14-1.aix5.1.ppc.rpm</a></p>
<p>and copy them into the directory that you created</p>
<p>Now run the following command to download the required files:</p>
<p># wget -B http://www.oss4aix.org/download/everything/RPMS/ -i mod_php_ap24-5.4.14-1.aix5.1.ppc.deps</p>
<p>and once the download is complete then run the following command to install the filesets:</p>
<p># rpm -Uvh *.rpm</p>
<p>If you receive a message stating that any packages are already installed your can either use the –force option as follows:</p>
<p># rpm -Uvh –force *.rpm</p>
<p><span style="color: #ff0000;">* BEWARE *</span>  use the —force option with caution as this will replace and overwrite existing packages even if existing packages are NEWER than those being installed. An alternative method is to simply remove the files for which you receive an “already installed” message from the directory and run the rpm –Uvh *.rpmcommand again, thus ensuring that none of your previously installed packages will be overwritten. Verify that all of the files that you want to install are correct by issuing the following command and checking the output contains the files packages that you think you should have installed.</p>
<p>If all of the filesets have been installed correctly then the required modifications will have been made to the /opt/freeware/etc/httpd/conf/httpd.conf which you can check by running the following command:</p>
<p># tail /opt/freeware/etc/httpd/conf/httpd.conf</p>
<p>the last 3 lines should look like the following:<br />
# PHP settings<br />
Include conf/extra/httpd-php.conf</p>
<p>now you can restart the Apache Web Server in order to activate the PHP with the following command:</p>
<p># /opt/freeware/sbin/apachectl restart</p>
<p>In order to test whether the PHP is actually being processed you can create a file /var/www/htdocs/testing.php which contains the following lines:</p>
<div id="advman-ad-3"></div>
<h1 style="font-weight: 400;" data-fontsize="34" data-lineheight="47">PHP testing</h1>
<p>phpinfo() ?&gt;</p>
<p>When you have done this you can then open a browser and navigate to the following web page where is the address of your server:</p>
<p><a style="color: #aad75b;" href="http://%3Cip/">http://&lt;ip&lt; a=&#8221;&#8221;&gt; address&gt;/testing.php</a></p>
<p>If everything is working then you should see the following:</p>
<p><a style="color: #aad75b;" href="https://i0.wp.com/www.scheerer.co.uk/wp-content/uploads/2013/05/image2.png" data-caption=""><img title="image" src="https://i2.wp.com/www.scheerer.co.uk/wp-content/uploads/2013/05/image_thumb2.png?resize=630%2C404" alt="image" width="630" height="404" border="0" /></a></p>
<p>Congratulations, you now have a working Apache Server with PHP Hypertext processing…</p>
<p>So the next and final step is to install the MySQL database.</p>
<p>In order to complete this step I followed the procedure as detailed on the IBM Power Systems – AIX and Open Source Wiki, which you can find by clicking <a style="color: #aad75b;" href="https://www.ibm.com/developerworks/community/wikis/home?lang=en#!/wiki/Power+Systems/page/AIX+and+Open+Source+-+old" target="_blank">HERE</a></p>
<p>For the purposes of my installation I have updated the procedure slightly for my own purposes as follows:</p>
<ol>
<li>Login as root</li>
<li>I created a new 2GB filesystem on the rootvg and mounted it to /usr/local</li>
<li>I substituted the MySQL version detailed in the IBM reference material with the current latest tar ball version 5.1.30 can be downloaded from the following website: http://ftp.nchu.edu.tw/MySQL/downloads/mysql/5.1.html#aixYou might also try the following link for the MySQL Version 5.1.61 distributionhttp://ftp.sunet.se/pub/unix/databases/relational/mysql/Downloads/MySQL-5.1/mysql-5.1.61-aix5.3-powerpc.tar.gzYou can also download most versions of MySQL for AIX from the following link directly from the Oracle MySQL Product Archiveshttp://downloads.mysql.com/archives.php?p=mysql-5.1&amp;o=aix</li>
<li> Make sure you have sufficient free space in /opt and /tmp (60MB+)</li>
<li>Download and Install the following<br />
* Prerequisite Tools –        http://www.ibm.com/servers/aix/products/aixos/linux/download.html<br />
* gcc-4.0.0-1.aix5.3.ppc.rpm<br />
* libgcc-4.0.0-1.aix5.3.ppc.rpm<br />
* gcc-cplusplus-4.0.0-1.aix5.3.ppc.rpm<br />
* libstdcplusplus-4.0.0-1.aix5.3.ppc.rpm<br />
* libstdcplusplus-devel-4.0.0-1.aix5.3.ppc.rpm<br />
* Install using rpm -Uvh rpm name<br />
* MySQL<br />
* Download: http://dev.mysql.com/downloads/mysql/5.0.html<br />
* Download the 32 bit version if you plan to use PHP. I was unable to compile PHP5 with the 64 bit MySQL libraries.<br />
* The file I downloaded was mysql-standard-5.0.27-aix5.2-powerpc.tar.gz. Your file may be newer.<br />
* For this example, we’ll assume you download the file to /usr/local<br />
* Caution: Use “compatible” versions of Apache, PHP and MySQL. Don’t mix old with new versions. They are not compatible. I used Apache2.2, PHP5 and MySQL5. (For example, PHP4 from the AIX Linux Toolbox is not compatible with the current versions of Apache and MySQL.)</li>
<li>Create MySQL UserID and Group<br />
* mkuser mysql<br />
* mkgroup -A mysql</li>
<li>Uncompress the MySQL File and Link the Directory to /usr/local/mysql<br />
* cd /usr/local<br />
* gunzip mysql-standard-5.0.27-aix5.2-powerpc.tar.gz<br />
* tar xf mysql-standard-5.0.27-aix5.2-powerpc.tar<br />
* This creates the directory mysql-standard-5.0.27-aix5.2-powerpc</li>
<li>Link Directory to /usr/local/mysql<br />
* ln -s mysql-standard-5.0.27-aix5.2-powerpc /usr/local/mysql</li>
<li>Configure MySQL<br />
* cd /usr/local/mysql<br />
* scripts/mysql_install_db –user=mysql<br />
* chown -R root.mysql .<br />
* chown -R mysql.mysql data<br />
* chgrp -R mysql . (redundant: chown -R root.mysql .)<br />
* nohup bin/mysqld_safe –user=mysql &amp;</li>
<li>Validate MySQL Installation by Logging into Database<br />
* mysql -u root<br />
* &gt;use mysql;<br />
* &gt;show tables;<br />
* &gt;exit;</li>
<li>Add MySQL Start-Up Script to /etc/rc.d<br />
* cp /usr/local/mysql/support-files/mysql.server to /etc/rc.d/init.d<br />
* chmod a+x /etc/rc.d/init.d/mysql.server<br />
* Add a link in rc2.d: cd /etc/rc.d/rc2.d; ln -s /etc/rc.d/init.d/mysql.server S10mysql.server K10mysql.server</li>
</ol>
<div>Although there will be much more work to do in configuring particular requirements for your own environments, that pretty much completes the basic installation of the Apache, PHP and MySQL to a point where everything is working.</div>
<div></div>
<div>All that remains is for a reboot to ensure that all your services start automatically as expected and your work is done, pass it off to the DBA….</div>
<div class="fusion-clearfix"></div>
</div>
</div>
</div>
</div>
<div class="fusion-fullwidth fullwidth-box nonhundred-percent-fullwidth" style="color: #747474;">
<div class="fusion-builder-row fusion-row ">
<div class="fusion-layout-column fusion_builder_column fusion_builder_column_1_1  fusion-one-full fusion-column-first fusion-column-last fusion-column-no-min-height 1_1">
<div class="fusion-column-wrapper" data-bg-url="">
<div class="fusion-title title fusion-title-size-one">
<h1 class="title-heading-left" style="font-weight: 400;" data-fontsize="34" data-lineheight="47">*** Update – June 2015 ***</h1>
<div class="title-sep-container"></div>
</div>
<p>I have received some interesting feedback from people that are following this guide in relation to the latest versions of PHP (namely the 5.4 version that is available from perzl.org).</p>
<p>This information has been kindly provided to me by Peter Barnett in relation to his recent attempts at installing mySQL and PHP.</p>
<p>&nbsp;</p>
<div id="advman-ad-4"></div>
<p>&nbsp;</p>
<p>Peter states that he encountered issues with the PHP connecting to the mySQL database and he received an error stating that PHP was unable to find model mysql_connect (or mysql_connect), unfortunately Peter did not provide the exact syntax of the error.</p>
<p>Peter has found that the PHP 5.4 Version available for download from perzl.org no longer contains the legacy mySQL libraries and instead now contains the mysqli-&gt;mysqlnd API which now uses mysql scripting.</p>
<p>Once Peter investigated the mysql scripting he found that he could get everything working as he needed to.</p>
<p>Peter found some useful tutorials at the following website:</p>
<p><a style="color: #aad75b;" href="http://www.w3schools.com/php/func_mysqli_connect.asp" target="_blank">http://www.w3schools.com/php/func_mysqli_connect.asp</a></p>
<p>I have not personally had the need to investigate this fully, but I hope that it may help some of you if you are struggling.</p>
<p>Happy to receive any comments, both positive or negative, life is a constant learning curve…</p>
<p>https://www.scheerer.co.uk/2013/05/installing-apache-php-and-mysql-on-ibm-aix-7-1/</p>
<p>&nbsp;</p>
</div>
</div>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>https://www.softwareace.cn/?feed=rss2&#038;p=1651</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>delphicbuilder_2010_3615_win</title>
		<link>https://www.softwareace.cn/?p=1608</link>
		<comments>https://www.softwareace.cn/?p=1608#comments</comments>
		<pubDate>Wed, 22 Mar 2017 03:40:55 +0000</pubDate>
		<dc:creator><![CDATA[admin]]></dc:creator>
				<category><![CDATA[破解工具]]></category>

		<guid isPermaLink="false">http://www.softwareace.cn/?p=1608</guid>
		<description><![CDATA[下载安装 http://pan.baidu.com/s/1o7CLrbO 输入激活码 HAAL-DANSGN- [&#8230;]]]></description>
				<content:encoded><![CDATA[<ol>
<li>下载安装 http://pan.baidu.com/s/1o7CLrbO</li>
<li>输入激活码 HAAL-DANSGN-FZR5AG-M3BS</li>
<li>运行 DelphiDistiller，选择delph2010下的tweak，打勾Remove license check.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>https://www.softwareace.cn/?feed=rss2&#038;p=1608</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>no matching key exchange method found. Their offer: diffie-hellman-group1-sha1</title>
		<link>https://www.softwareace.cn/?p=1599</link>
		<comments>https://www.softwareace.cn/?p=1599#comments</comments>
		<pubDate>Mon, 06 Mar 2017 03:39:40 +0000</pubDate>
		<dc:creator><![CDATA[admin]]></dc:creator>
				<category><![CDATA[git]]></category>

		<guid isPermaLink="false">http://www.softwareace.cn/?p=1599</guid>
		<description><![CDATA[解决：修改~/.ssh/config，加入 [crayon-69e02d4d5ab63442047972/]  [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>解决：修改~/.ssh/config，加入</p><pre class="crayon-plain-tag">Host *
    KexAlgorithms +diffie-hellman-group1-sha1</pre><p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>https://www.softwareace.cn/?feed=rss2&#038;p=1599</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>centos(7.0) 上 crontab 计划任务</title>
		<link>https://www.softwareace.cn/?p=1597</link>
		<comments>https://www.softwareace.cn/?p=1597#comments</comments>
		<pubDate>Fri, 03 Mar 2017 07:35:51 +0000</pubDate>
		<dc:creator><![CDATA[admin]]></dc:creator>
				<category><![CDATA[系统]]></category>

		<guid isPermaLink="false">http://www.softwareace.cn/?p=1597</guid>
		<description><![CDATA[[crayon-69e02d4d5ae55203431376/] &#160; 补充： 1、crontab相关 [&#8230;]]]></description>
				<content:encoded><![CDATA[<p></p><pre class="crayon-plain-tag">yum install vixie-cron
yum install crontabs
/bin/systemctl restart crond.service  #启动服务
/bin/systemctl reload  crond.service  #重新载入配置
/bin/systemctl status  crond.service  #查看crontab服务状态</pre><p>&nbsp;</p>
<p style="color: #444444;"><span style="color: #ff0000;"><strong>补充：</strong></span></p>
<p style="color: #444444;"><strong>1、crontab相关命令</strong></p>
<p style="color: #444444;"><strong>功能说明：</strong>设置计时器。</p>
<p style="color: #444444;"><strong>语　　法：</strong>crontab [-u &lt;用户名称&gt;][配置文件] 或 crontab [-u &lt;用户名称&gt;][-elr]</p>
<p style="color: #444444;"><strong>补充说明：</strong>cron是一个常驻服务，它提供计时器的功能，让用户在特定的时间得以执行预设的指令或程序。只要用户会编辑计时器的配置文件，就可以使用计时器的功能。</p>
<p style="color: #444444;"><strong>配置文件格式：</strong>Minute Hour Day Month DayOFWeek Command</p>
<p style="color: #444444;"><strong>参　　数： </strong><br />
-e 　编辑该用户的计时器设置。<br />
-l 　列出该用户的计时器设置。<br />
-r 　删除该用户的计时器设置。<br />
-u&lt;用户名称&gt; 　指定要设定计时器的用户名称。</p>
<p style="color: #444444;">
<p style="color: #444444;"><strong>2、crontab 配置文件格式</strong></p>
<p style="color: #444444;"><strong>　　基本格式 :</strong><br />
*      * 　 *　  *　  *　　command<br />
分　  时　 日　 月　 周　  命令</p>
<p style="color: #444444;">　　第1列表示分钟1～59 每分钟用*或者 */1表示<br />
第2列表示小时1～23（0表示0点）<br />
第3列表示日期1～31<br />
第4列表示月份1～12<br />
第5列标识号星期0～6（0表示星期天）<br />
第6列要运行的命令</p>
<p style="color: #444444;"> 除了数字还有几个个特殊的符号就是&#8221;*&#8221;、&#8221;/&#8221;和&#8221;-&#8221;、&#8221;,&#8221;，*代表所有的取值范围内的数字，&#8221;/&#8221;代表每的意思,&#8221;*/5&#8243;表示每5个单位，&#8221;-&#8221;代表从某个数字到某个数字,&#8221;,&#8221;分开几个离散的数字。</p>
<p style="color: #444444;"><strong>crontab文件的一些例子：</strong></p>
<p></p><pre class="crayon-plain-tag">30 21 * * * /usr/local/etc/rc.d/apache restart  #每晚的21:30 重启apache 

45 4 1,10,22 * * /usr/local/etc/rc.d/apache restart  #每月1、10、22日的4 : 45重启apache 

10 1 * * 6,0 /usr/local/etc/rc.d/apache restart #每周六、周日的1 : 10重启apache  

0,30 18-23 * * * /usr/local/etc/rc.d/apache restart  #每天18 : 00至23 : 00之间每隔30分钟重启apache  

0 23 * * 6 /usr/local/etc/rc.d/apache restart  #每星期六的11 : 00 pm重启apache

* 23-7/1 * * * /usr/local/etc/rc.d/apache restart  #晚上11点到早上7点之间，每隔一小时重启  apache

* */1 * * * /usr/local/etc/rc.d/apache restart  #每一小时重启apache   

0 11 4 * mon-wed /usr/local/etc/rc.d/apache restart #每月的4号与每周一到周三的11点重启apache   

0 4 1 jan * /usr/local/etc/rc.d/apache restart  #一月一号的4点重启apache  

*/30 * * * * /usr/sbin/ntpdate 210.72.145.44  #每半小时同步一下时间 

0 */2 * * * www /usr/bin/somecommand  &gt;&gt;  /dev/null 2&gt;&amp;1 #以用户www的身份每两小时就运行某个程序：</pre><p>&nbsp;</p>
<p><strong>3、其他任务调度</strong></p>
<p>cron默认配置了调度任务，分别为：hourly、daily、weekly、mouthly，默认配置文件为/etc/anacrontab</p>
<p>将需要执行的脚本放到相应的目录下即可，目录分别为：</p>
<p>/etc/cron.hourly</p>
<p>/etc/cron.daily</p>
<p>/etc/cron.weekly</p>
<p>/ect/cron.mouthly</p>
<p>&nbsp;</p>
<p style="color: #2d374b;">cron 的主配置文件是 /etc/crontab，它包括下面几行：</p>
<p></p><pre class="crayon-plain-tag">SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
&lt;span class=&quot;hljs-section&quot; style=&quot;color: #efef8f;&quot;&gt;#&nbsp;run-parts&lt;/span&gt;
01&nbsp;&lt;span class=&quot;hljs-bullet&quot; style=&quot;color: #dca3a3;&quot;&gt;*&nbsp;*&lt;/span&gt;&nbsp;&lt;span class=&quot;hljs-bullet&quot; style=&quot;color: #dca3a3;&quot;&gt;*&nbsp;*&lt;/span&gt;&nbsp;root&nbsp;run-parts&nbsp;/etc/cron.hourly
02&nbsp;4&nbsp;&lt;span class=&quot;hljs-bullet&quot; style=&quot;color: #dca3a3;&quot;&gt;*&nbsp;*&lt;/span&gt;&nbsp;*&nbsp;root&nbsp;run-parts&nbsp;/etc/cron.daily
22&nbsp;4&nbsp;&lt;span class=&quot;hljs-bullet&quot; style=&quot;color: #dca3a3;&quot;&gt;*&nbsp;*&lt;/span&gt;&nbsp;0&nbsp;root&nbsp;run-parts&nbsp;/etc/cron.weekly
42&nbsp;4&nbsp;1&nbsp;&lt;span class=&quot;hljs-bullet&quot; style=&quot;color: #dca3a3;&quot;&gt;*&nbsp;*&lt;/span&gt;&nbsp;root&nbsp;run-parts&nbsp;/etc/cron.monthly</pre><p></p>
<p style="color: #2d374b;">
<h3 id="h3_0" style="font-weight: 500; color: #3d464d;">4. 关于cron配置文件/etc/crontab</h3>
<p style="color: #2d374b;">cron 的主配置文件是 /etc/crontab，它包括下面几行：</p>
<p></p><pre class="crayon-plain-tag">SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
&lt;span class=&quot;hljs-section&quot; style=&quot;color: #efef8f;&quot;&gt;#&nbsp;run-parts&lt;/span&gt;
01&nbsp;&lt;span class=&quot;hljs-bullet&quot; style=&quot;color: #dca3a3;&quot;&gt;*&nbsp;*&lt;/span&gt;&nbsp;&lt;span class=&quot;hljs-bullet&quot; style=&quot;color: #dca3a3;&quot;&gt;*&nbsp;*&lt;/span&gt;&nbsp;root&nbsp;run-parts&nbsp;/etc/cron.hourly
02&nbsp;4&nbsp;&lt;span class=&quot;hljs-bullet&quot; style=&quot;color: #dca3a3;&quot;&gt;*&nbsp;*&lt;/span&gt;&nbsp;*&nbsp;root&nbsp;run-parts&nbsp;/etc/cron.daily
22&nbsp;4&nbsp;&lt;span class=&quot;hljs-bullet&quot; style=&quot;color: #dca3a3;&quot;&gt;*&nbsp;*&lt;/span&gt;&nbsp;0&nbsp;root&nbsp;run-parts&nbsp;/etc/cron.weekly
42&nbsp;4&nbsp;1&nbsp;&lt;span class=&quot;hljs-bullet&quot; style=&quot;color: #dca3a3;&quot;&gt;*&nbsp;*&lt;/span&gt;&nbsp;root&nbsp;run-parts&nbsp;/etc/cron.monthly</pre><p></p>
<p style="color: #2d374b;">前四行是用来配置 cron 任务运行环境的变量：</p>
<p style="color: #2d374b;">Shell 变量的值指定shell 环境（此处默认为 bash shell）；PATH 变量定义用来执行命令的程序路径；cron 任务的输出被邮寄给 MAILTO 变量定义的用户名，如果 MAILTO 变量被定义为空白字符串（MAILTO=&#8221;&#8221;），电子邮件就不会被寄出；HOME 变量可以用来设置在执行命令或脚本时使用的主目录。如在 /etc/crontab 文件中run-parts部分所示，它使用 run-parts 脚本来执行存在于 /etc/cron.hourly、/etc/cron.daily、/etc/cron.weekly 和 /etc/cron.monthly 目录中的脚本，这些脚本被相应地按照预设时间在每小时、每日、每周、或每月执行。这些目录中的文件应该是 shell 脚本，并且具有可执行权限(chmod +x filename)。</p>
<p style="color: #2d374b;">如果某 cron 任务需要根据调度来执行，而不是每小时、每日、每周、或每月地执行，它可以被添加到/etc/cron.d目录中。该目录中的所有文件使用和 /etc/crontab 中一样的语法。</p>
<p style="color: #2d374b;">每次编辑完某个用户的cron设置后，cron自动在/var/spool/cron下生成一个与此用户同名的文件，此用户的cron信息都记录在这个文件中，这个文件是不可以直接编辑的，只可以用crontab -e 来编辑。cron启动后每过一份钟读一次这个文件，检查是否要执行里面的命令。因此此文件修改后不需要重新启动cron服务。</p>
]]></content:encoded>
			<wfw:commentRss>https://www.softwareace.cn/?feed=rss2&#038;p=1597</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Windows 10 下载已经签名的程序，提示签名无效或损坏</title>
		<link>https://www.softwareace.cn/?p=1429</link>
		<comments>https://www.softwareace.cn/?p=1429#comments</comments>
		<pubDate>Wed, 20 Jan 2016 09:48:21 +0000</pubDate>
		<dc:creator><![CDATA[admin]]></dc:creator>
				<category><![CDATA[系统]]></category>

		<guid isPermaLink="false">http://www.softwareace.cn/?p=1429</guid>
		<description><![CDATA[原文  http://www.wosign.com/news/STOP_SHA1.htm 解决  SHA-1  [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>原文  http://www.wosign.com/news/STOP_SHA1.htm</p>
<p>解决  <strong>SHA-1 + <strong>SHA-2 双签名    </strong></strong></p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>https://www.softwareace.cn/?feed=rss2&#038;p=1429</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VS 2015 key 注册码</title>
		<link>https://www.softwareace.cn/?p=1372</link>
		<comments>https://www.softwareace.cn/?p=1372#comments</comments>
		<pubDate>Fri, 24 Jul 2015 03:23:05 +0000</pubDate>
		<dc:creator><![CDATA[admin]]></dc:creator>
				<category><![CDATA[破解工具]]></category>

		<guid isPermaLink="false">http://www.softwareace.cn/?p=1372</guid>
		<description><![CDATA[Visual Studio Enterprise 2015 HM6NR-QXX7C-DFW2Y-8B82K-W [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Visual Studio Enterprise 2015<br />
HM6NR-QXX7C-DFW2Y-8B82K-WTYJV</p>
<p>Visual Studio Professional 2015<br />
HMGNV-WCYXV-X7G9W-YCX63-B98R2</p>
]]></content:encoded>
			<wfw:commentRss>https://www.softwareace.cn/?feed=rss2&#038;p=1372</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Proxifier只代理部分程序，使用和汉化下载地址</title>
		<link>https://www.softwareace.cn/?p=1339</link>
		<comments>https://www.softwareace.cn/?p=1339#comments</comments>
		<pubDate>Mon, 01 Jun 2015 03:18:57 +0000</pubDate>
		<dc:creator><![CDATA[admin]]></dc:creator>
				<category><![CDATA[破解工具]]></category>

		<guid isPermaLink="false">http://www.softwareace.cn/?p=1339</guid>
		<description><![CDATA[ 教程http://jingyan.baidu.com/article/48b558e35e12f97f38c [&#8230;]]]></description>
				<content:encoded><![CDATA[<div class="exp-title clearfix">
<div> 教程<img src="file:///C:\Users\surou\AppData\Local\Temp\8LDO48C$8@[GWU0353$FOVS.png" alt="" />http://jingyan.baidu.com/article/48b558e35e12f97f38c09a28.html</div>
<div>下载 http://www.hanzify.org/software/13717.html</div>
</div>
]]></content:encoded>
			<wfw:commentRss>https://www.softwareace.cn/?feed=rss2&#038;p=1339</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VMware 11安装Mac OS X 10.10</title>
		<link>https://www.softwareace.cn/?p=1337</link>
		<comments>https://www.softwareace.cn/?p=1337#comments</comments>
		<pubDate>Wed, 27 May 2015 02:48:56 +0000</pubDate>
		<dc:creator><![CDATA[admin]]></dc:creator>
				<category><![CDATA[系统]]></category>

		<guid isPermaLink="false">http://www.softwareace.cn/?p=1337</guid>
		<description><![CDATA[VM11安装Mac OS X 10.10 网上竟没有搜到相似的内容，所以拿出来大家分享 工具/原料 1.VMw [&#8230;]]]></description>
				<content:encoded><![CDATA[<div class="exp-content-block">
<div class="exp-content-body exp-brief-step">
<div class="exp-content-listblock">
<div class="content-listblock-text">
<p>VM11安装Mac OS X 10.10</p>
<p>网上竟没有搜到相似的内容，所以拿出来大家分享</p>
</div>
</div>
</div>
</div>
<div class="exp-content-block">
<h2 class="exp-content-head"><a name="section-2"></a> 工具/原料</h2>
<div class="exp-content-body">
<ul class="exp-content-unorderlist ">
<li class="exp-content-list list-item-1">
<div class="content-list-text">1.VMware Workstation 11</div>
</li>
<li class="exp-content-list list-item-2">
<div class="content-list-text">2.unlocker 203（for OS X 插件补丁）</div>
</li>
<li class="exp-content-list list-item-3">
<div class="content-list-text">3.Mac OS X 10.10镜像</div>
</li>
</ul>
</div>
</div>
<h2 class="exp-content-head"><a name="section-3"></a> 方法/步骤</h2>
<ol class="exp-conent-orderlist">
<li class="exp-content-list list-item-1">
<div class="content-list-text">
<p>有图有真相，哈哈</p>
</div>
<div class="content-list-media">
<div class="content-list-image clearfix"><a class="exp-image-wraper" href="http://jingyan.baidu.com/album/ff411625b9011212e48237b4.html?picindex=1" target="_self"> <img class="exp-image-default" src="http://f.hiphotos.baidu.com/exp/w=500/sign=5e8b15d7dec451daf6f60ceb86fc52a5/b64543a98226cffc5b49323bba014a90f703eadc.jpg" alt="VMware 11安装Mac OS X 10.10" /> </a></div>
</div>
</li>
<li class="exp-content-list list-item-2">
<div class="content-list-text">
<p>一、下载以上文件</p>
<p>1. 百度软件下载即可</p>
<p>2. unlocker 203       链接：http://pan.baidu.com/s/1o6iI9tg  密码：km1c</p>
<p>3. Mac OS X 10.10镜像     链接：http://pan.baidu.com/s/1sj4ri5R 密码：y86w</p>
</div>
</li>
<li class="exp-content-list list-item-3">
<div class="content-list-text">
<p>二、基本步骤</p>
<p>1.虚拟机的安装</p>
<p>下载Vmare Workstation，以管理员身份运行，安装，一直下一步即可。VM安装好后，注册码百度一大堆。</p>
</div>
</li>
<li class="exp-content-list list-item-4">
<div class="content-list-text">
<p>2.插件安装</p>
<p>步骤一完成后，打开任务管理器，找到服务项，选择按名称排序，将框中四项全部停止运行。</p>
<p>然后打开下载的插件，解压unlock203.zip文件，找到 unlock203\win-install.cmd，右键以管理员身份运行，等待运行完即可。（完成这一步vmware才能识别OS X）。</p>
</div>
<div class="content-list-media">
<div class="content-list-image clearfix"><a class="exp-image-wraper" href="http://jingyan.baidu.com/album/ff411625b9011212e48237b4.html?picindex=2" target="_self"> <img class="exp-image-default" src="http://g.hiphotos.baidu.com/exp/w=500/sign=9558ed5e35d12f2ece05ae607fc3d5ff/9d82d158ccbf6c816ebea061bf3eb13532fa40aa.jpg" alt="VMware 11安装Mac OS X 10.10" /> </a></div>
</div>
</li>
<li class="exp-content-list list-item-5">
<div class="content-list-text">
<p>3.Mac OS X 10.10的载入</p>
<p>相信你以上步骤已做好了，开启下面旅程吧。基本都是图片，所以很容易，just follow。</p>
</div>
<div class="content-list-media">
<div class="content-list-image clearfix"><a class="exp-image-wraper" href="http://jingyan.baidu.com/album/ff411625b9011212e48237b4.html?picindex=3" target="_self"> <img class="exp-image-default" src="http://d.hiphotos.baidu.com/exp/w=500/sign=cc98c4880955b3199cf9827573a88286/1c950a7b02087bf4698adf60f1d3572c10dfcfd1.jpg" alt="VMware 11安装Mac OS X 10.10" /> </a></div>
<div class="content-list-image clearfix"><a class="exp-image-wraper" href="http://jingyan.baidu.com/album/ff411625b9011212e48237b4.html?picindex=4" target="_self"> <img class="exp-image-default" src="http://c.hiphotos.baidu.com/exp/w=500/sign=e87d72451d178a82ce3c7fa0c602737f/562c11dfa9ec8a13097cdf69f403918fa1ecc0d1.jpg" alt="VMware 11安装Mac OS X 10.10" /> </a></div>
<div class="content-list-image clearfix"><a class="exp-image-wraper" href="http://jingyan.baidu.com/album/ff411625b9011212e48237b4.html?picindex=5" target="_self"> <img class="exp-image-default" src="http://h.hiphotos.baidu.com/exp/w=500/sign=8c9f0afc40a98226b8c12b27ba83b97a/0bd162d9f2d3572c768414558913632763d0c3d1.jpg" alt="VMware 11安装Mac OS X 10.10" /> </a></div>
<div class="content-list-image clearfix"><a class="exp-image-wraper" href="http://jingyan.baidu.com/album/ff411625b9011212e48237b4.html?picindex=6" target="_self"> <img class="exp-image-default" src="http://h.hiphotos.baidu.com/exp/w=500/sign=f5ba4aba928fa0ec7fc7640d1696594a/359b033b5bb5c9ea82a48b6ad639b6003bf3b3e0.jpg" alt="VMware 11安装Mac OS X 10.10" /> </a></div>
<div class="content-list-image clearfix"><a class="exp-image-wraper" href="http://jingyan.baidu.com/album/ff411625b9011212e48237b4.html?picindex=7" target="_self"> <img class="exp-image-default" src="http://g.hiphotos.baidu.com/exp/w=500/sign=f54ddf69f403918fd7d13dca613c264b/2934349b033b5bb55f80a87735d3d539b700bce0.jpg" alt="VMware 11安装Mac OS X 10.10" /> </a></div>
<div class="content-list-image clearfix"><a class="exp-image-wraper" href="http://jingyan.baidu.com/album/ff411625b9011212e48237b4.html?picindex=8" target="_self"> <img class="exp-image-default" src="http://e.hiphotos.baidu.com/exp/w=500/sign=f78f0ea58401a18bf0eb124fae2e0761/4e4a20a4462309f7ec09259b710e0cf3d6cad6d1.jpg" alt="VMware 11安装Mac OS X 10.10" /> </a></div>
</div>
</li>
<li class="exp-content-list list-item-6">
<div class="content-list-text">
<p>4.开启安装</p>
<p>我遇到了如下问题，百度后知道 出现这种情况，只要找到并打开安装目录下的 XXXX.vmx 文件，使用记事本打开后，在 smc.present = &#8220;TRUE&#8221; 后添加“smc.version = 0”(建议您复制，不包括引号)后保存，问题即可解决。</p>
<p>重新启动</p>
</div>
<div class="content-list-media">
<div class="content-list-image clearfix"><a class="exp-image-wraper" href="http://jingyan.baidu.com/album/ff411625b9011212e48237b4.html?picindex=9" target="_self"> <img class="exp-image-default" src="http://e.hiphotos.baidu.com/exp/w=500/sign=c7a30de8fb1986184147ef847aec2e69/503d269759ee3d6d21430f4240166d224e4adeb6.jpg" alt="VMware 11安装Mac OS X 10.10" /> </a></div>
<div class="content-list-image clearfix"><a class="exp-image-wraper" href="http://jingyan.baidu.com/album/ff411625b9011212e48237b4.html?picindex=10" target="_self"> <img class="exp-image-default" src="http://h.hiphotos.baidu.com/exp/w=500/sign=f8d699c69d2f07085f052a00d925b865/91529822720e0cf3a8cac5720946f21fbe09aa7e.jpg" alt="VMware 11安装Mac OS X 10.10" /> </a></div>
<div class="content-list-image clearfix"><a class="exp-image-wraper" href="http://jingyan.baidu.com/album/ff411625b9011212e48237b4.html?picindex=11" target="_self"> <img class="exp-image-default" src="http://g.hiphotos.baidu.com/exp/w=500/sign=acdbefb6daf9d72a1764101de42b282a/77094b36acaf2edd155bc2608e1001e938019395.jpg" alt="VMware 11安装Mac OS X 10.10" /> </a></div>
</div>
</li>
<li class="exp-content-list list-item-7">
<div class="content-list-text">
<p>5.just follow。。。。。。。。。。</p>
<p>&nbsp;</p>
</div>
<div class="content-list-media">
<div class="content-list-image clearfix"><a class="exp-image-wraper" href="http://jingyan.baidu.com/album/ff411625b9011212e48237b4.html?picindex=12" target="_self"> <img class="exp-image-default" src="http://e.hiphotos.baidu.com/exp/w=500/sign=8ccc39a1357adab43dd01b43bbd5b36b/58ee3d6d55fbb2fb37c3d29b4c4a20a44723dc4b.jpg" alt="VMware 11安装Mac OS X 10.10" /> </a></div>
<div class="content-list-image clearfix"><a class="exp-image-wraper" href="http://jingyan.baidu.com/album/ff411625b9011212e48237b4.html?picindex=13" target="_self"> <img class="exp-image-default" src="http://c.hiphotos.baidu.com/exp/w=500/sign=bcbf99573e6d55fbc5c676265d234f40/d439b6003af33a877378f593c55c10385343b526.jpg" alt="VMware 11安装Mac OS X 10.10" /> </a></div>
<div class="content-list-image clearfix"><a class="exp-image-wraper" href="http://jingyan.baidu.com/album/ff411625b9011212e48237b4.html?picindex=14" target="_self"> <img class="exp-image-default" src="http://d.hiphotos.baidu.com/exp/w=500/sign=e50bc94e93529822053339c3e7cb7b3b/faf2b2119313b07e69a8a5810fd7912397dd8c26.jpg" alt="VMware 11安装Mac OS X 10.10" /> </a></div>
<div class="content-list-image clearfix"><a class="exp-image-wraper" href="http://jingyan.baidu.com/album/ff411625b9011212e48237b4.html?picindex=15" target="_self"> <img class="exp-image-default" src="http://g.hiphotos.baidu.com/exp/w=500/sign=8b880baa4a540923aa69637ea259d1dc/738b4710b912c8fcc5f70344ff039245d6882136.jpg" alt="VMware 11安装Mac OS X 10.10" /> </a></div>
</div>
</li>
<li class="exp-content-list list-item-8">
<div class="content-list-text">
<p>然后点击左上角的磁盘工具，选择退出磁盘工具。然后在安装界面点击继续,再点击安装，，，，静待佳音，，，，，，，，，，，，，，可以干点别的、、、、、、、、、、、、、、、、、、以后就是初次进入系统的配置了（省略一千字）</p>
</div>
</li>
<li class="exp-content-list list-item-9">
<div class="content-list-text">
<p>6.VMTool以及Darwin6.0.3的安装 以及共享文件夹。</p>
<p>以下是网上OS X 10.9的图，10.10也是一样的just follow。。。。。。。。。。</p>
<p>共享文件夹的说明：由于虚拟机无法访问本机的硬盘，所以需要设置共享文件夹来方便虚拟机读取电脑的物理内存。</p>
</div>
<div class="content-list-media">
<div class="content-list-image clearfix"><a class="exp-image-wraper" href="http://jingyan.baidu.com/album/ff411625b9011212e48237b4.html?picindex=16" target="_self"> <img class="exp-image-default" src="http://g.hiphotos.baidu.com/exp/w=500/sign=ab3ace6e922397ddd67998046983b216/ae51f3deb48f8c545aec32a639292df5e0fe7f78.jpg" alt="VMware 11安装Mac OS X 10.10" /> </a></div>
<div class="content-list-image clearfix"><a class="exp-image-wraper" href="http://jingyan.baidu.com/album/ff411625b9011212e48237b4.html?picindex=17" target="_self"> <img class="exp-image-default" src="http://c.hiphotos.baidu.com/exp/w=500/sign=f100cb6861d9f2d3201124ef99ee8a53/eaf81a4c510fd9f95ddea1e0262dd42a2934a46a.jpg" alt="VMware 11安装Mac OS X 10.10" /> </a></div>
<div class="content-list-image clearfix"><a class="exp-image-wraper" href="http://jingyan.baidu.com/album/ff411625b9011212e48237b4.html?picindex=18" target="_self"> <img class="exp-image-default" src="http://h.hiphotos.baidu.com/exp/w=500/sign=56e672a2b351f819f125034aeab64a76/09fa513d269759ee52999442b1fb43166c22df6a.jpg" alt="VMware 11安装Mac OS X 10.10" /> </a></div>
<div class="content-list-image clearfix"><a class="exp-image-wraper" href="http://jingyan.baidu.com/album/ff411625b9011212e48237b4.html?picindex=19" target="_self"> <img class="exp-image-default" src="http://h.hiphotos.baidu.com/exp/w=500/sign=c494cd8a8444ebf86d71643fe9fbd736/d1a20cf431adcbefd9fd8a8fafaf2edda2cc9f6a.jpg" alt="VMware 11安装Mac OS X 10.10" /> </a></div>
<div class="content-list-image clearfix"><a class="exp-image-wraper" href="http://jingyan.baidu.com/album/ff411625b9011212e48237b4.html?picindex=20" target="_self"> <img class="exp-image-default" src="http://f.hiphotos.baidu.com/exp/w=500/sign=e641085316ce36d3a20483300af13a24/b90e7bec54e736d192da788198504fc2d462696a.jpg" alt="VMware 11安装Mac OS X 10.10" /> </a></div>
<div class="content-list-image clearfix"><a class="exp-image-wraper" href="http://jingyan.baidu.com/album/ff411625b9011212e48237b4.html?picindex=21" target="_self"> <img class="exp-image-default" src="http://b.hiphotos.baidu.com/exp/w=500/sign=d4a197f79158d109c4e3a9b2e15accd0/c2cec3fdfc039245df7d15868494a4c27c1e256a.jpg" alt="VMware 11安装Mac OS X 10.10" /> </a></div>
<div class="content-list-image clearfix"><a class="exp-image-wraper" href="http://jingyan.baidu.com/album/ff411625b9011212e48237b4.html?picindex=22" target="_self"> <img class="exp-image-default" src="http://a.hiphotos.baidu.com/exp/w=500/sign=f8090277c0fdfc03e578e3b8e43d87a9/a50f4bfbfbedab6433bab949f436afc378311e6a.jpg" alt="VMware 11安装Mac OS X 10.10" /> </a></div>
<div class="content-list-image clearfix"><a class="exp-image-wraper" href="http://jingyan.baidu.com/album/ff411625b9011212e48237b4.html?picindex=23" target="_self"> <img class="exp-image-default" src="http://b.hiphotos.baidu.com/exp/w=500/sign=867308ae7c3e6709be0045ff0bc59fb8/34fae6cd7b899e512e46ce9d41a7d933c9950d6a.jpg" alt="VMware 11安装Mac OS X 10.10" /> </a></div>
<div class="content-list-image clearfix"><a class="exp-image-wraper" href="http://jingyan.baidu.com/album/ff411625b9011212e48237b4.html?picindex=24" target="_self"> <img class="exp-image-default" src="http://h.hiphotos.baidu.com/exp/w=500/sign=dbf6f314c8ef76093c0b999f1edca301/9825bc315c6034a889dd4f08c813495409237678.jpg" alt="VMware 11安装Mac OS X 10.10" /> </a></div>
</div>
</li>
<li class="exp-content-list list-item-10">
<div class="list-icon" style="visibility: visible;">10</div>
<div class="content-list-text">
<p>博主是不是很用心呢，嘿嘿，</p>
<p>当然要感谢网上已经提供的思路，赞一个</p>
<p>http://jingyan.baidu.com/article/ff411625b9011212e48237b4.html?qq-pf-to=pcqq.group</p>
</div>
</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>https://www.softwareace.cn/?feed=rss2&#038;p=1337</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Postfix+Dovecot+MySQL搭建邮件服务器</title>
		<link>https://www.softwareace.cn/?p=1325</link>
		<comments>https://www.softwareace.cn/?p=1325#comments</comments>
		<pubDate>Fri, 15 May 2015 03:44:23 +0000</pubDate>
		<dc:creator><![CDATA[admin]]></dc:creator>
				<category><![CDATA[系统]]></category>

		<guid isPermaLink="false">http://www.softwareace.cn/?p=1325</guid>
		<description><![CDATA[网上有很多使用Postfix搭建邮件服务器的文章，但目前貌似没有看到较为完整的一篇。本例将尝试在Ubuntu系 [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><span style="color: #000000;">网上有很多使用Postfix搭建邮件服务器的文章，但目前貌似没有看到较为完整的一篇。本例将尝试在Ubuntu系统中使用Postfix+Dovecot+MySQL搭建邮件服务器。</span></p>
<div class="BlogAnchor" style="color: #000000;">
<p style="color: #15a230;"><span id="AnchorContentToggle" class="corner" style="color: #ffffff;" title="点击收起目录">目录[-]</span></p>
<div id="AnchorContent" class="AnchorContent">
<ul>
<li class="osc_h2"><a style="color: #4466bb;" href="http://my.oschina.net/baratsemet/blog/413923#OSC_h2_1">开始之前</a></li>
<li class="osc_h2"><a style="color: #4466bb;" href="http://my.oschina.net/baratsemet/blog/413923#OSC_h2_2">工作原理</a></li>
<li class="osc_h3"><a style="color: #4466bb;" href="http://my.oschina.net/baratsemet/blog/413923#OSC_h3_3">服务器接收邮件的过程</a></li>
<li class="osc_h3"><a style="color: #4466bb;" href="http://my.oschina.net/baratsemet/blog/413923#OSC_h3_4">用户查收邮件的过程</a></li>
<li class="osc_h3"><a style="color: #4466bb;" href="http://my.oschina.net/baratsemet/blog/413923#OSC_h3_5">用户发送邮件的过程</a></li>
<li class="osc_h2"><a style="color: #4466bb;" href="http://my.oschina.net/baratsemet/blog/413923#OSC_h2_6">DNS配置</a></li>
<li class="osc_h2"><a style="color: #4466bb;" href="http://my.oschina.net/baratsemet/blog/413923#OSC_h2_7">SSL证书</a></li>
<li class="osc_h2"><a style="color: #4466bb;" href="http://my.oschina.net/baratsemet/blog/413923#OSC_h2_8">修改hostname</a></li>
<li class="osc_h2"><a style="color: #4466bb;" href="http://my.oschina.net/baratsemet/blog/413923#OSC_h2_9">MySQL安装及配置</a></li>
<li class="osc_h3"><a style="color: #4466bb;" href="http://my.oschina.net/baratsemet/blog/413923#OSC_h3_10">MySQL安装</a></li>
<li class="osc_h3"><a style="color: #4466bb;" href="http://my.oschina.net/baratsemet/blog/413923#OSC_h3_11">新建数据库及用户</a></li>
<li class="osc_h3"><a style="color: #4466bb;" href="http://my.oschina.net/baratsemet/blog/413923#OSC_h3_12">新建表格</a></li>
<li class="osc_h3"><a style="color: #4466bb;" href="http://my.oschina.net/baratsemet/blog/413923#OSC_h3_13">插入数据</a></li>
<li class="osc_h3"><a style="color: #4466bb;" href="http://my.oschina.net/baratsemet/blog/413923#OSC_h3_14">测试数据</a></li>
<li class="osc_h2"><a style="color: #4466bb;" href="http://my.oschina.net/baratsemet/blog/413923#OSC_h2_15">Postfix安装及配置</a></li>
<li class="osc_h3"><a style="color: #4466bb;" href="http://my.oschina.net/baratsemet/blog/413923#OSC_h3_16">Postfix的安装</a></li>
<li class="osc_h3"><a style="color: #4466bb;" href="http://my.oschina.net/baratsemet/blog/413923#OSC_h3_17">Postfix的配置</a></li>
<li class="osc_h2"><a style="color: #4466bb;" href="http://my.oschina.net/baratsemet/blog/413923#OSC_h2_18">Dovecot安装及配置</a></li>
<li class="osc_h3"><a style="color: #4466bb;" href="http://my.oschina.net/baratsemet/blog/413923#OSC_h3_19">Dovecot的安装</a></li>
<li class="osc_h3"><a style="color: #4466bb;" href="http://my.oschina.net/baratsemet/blog/413923#OSC_h3_20">Dovecot的配置</a></li>
<li class="osc_h3"><a style="color: #4466bb;" href="http://my.oschina.net/baratsemet/blog/413923#OSC_h3_21">修改/etc/dovecot/dovecot.conf文件</a></li>
<li class="osc_h3"><a style="color: #4466bb;" href="http://my.oschina.net/baratsemet/blog/413923#OSC_h3_22">修改/etc/dovecot/conf.d/10-mail.conf文件</a></li>
<li class="osc_h3"><a style="color: #4466bb;" href="http://my.oschina.net/baratsemet/blog/413923#OSC_h3_23">修改/etc/dovecot/conf.d/10-auth.conf文件</a></li>
<li class="osc_h3"><a style="color: #4466bb;" href="http://my.oschina.net/baratsemet/blog/413923#OSC_h3_24">修改/etc/dovecot/conf.d/auth-sql.conf.ext文件</a></li>
<li class="osc_h3"><a style="color: #4466bb;" href="http://my.oschina.net/baratsemet/blog/413923#OSC_h3_25">修改/etc/dovecot/dovecot-sql.conf.ext文件</a></li>
<li class="osc_h3"><a style="color: #4466bb;" href="http://my.oschina.net/baratsemet/blog/413923#OSC_h3_26">修改/etc/dovecot/conf.d/10-master.conf文件</a></li>
<li class="osc_h3"><a style="color: #4466bb;" href="http://my.oschina.net/baratsemet/blog/413923#OSC_h3_27">修改/etc/dovecot/conf.d/10-ssl.conf文件</a></li>
<li class="osc_h2"><a style="color: #4466bb;" href="http://my.oschina.net/baratsemet/blog/413923#OSC_h2_28">测试邮件服务器是否正常</a></li>
</ul>
</div>
</div>
<div class="BlogContent">
<p>说到邮件服务器，网上有许多不同解决方案。Window操作系统下常见的邮件服务器有<a style="color: #ff8373;" href="http://https//www.hmailserver.com/" rel="nofollow">hMailServer</a>、<a style="color: #ff8373;" href="http://www.mailenable.com/" rel="nofollow">MailEnable</a>、<a style="color: #ff8373;" href="http://www.evomailserver.com/" rel="nofollow">EVOMailServer</a>、<a style="color: #ff8373;" href="http://james.apache.org/" rel="nofollow">Apache James(纯Java跨平台)</a>等。</p>
<p>而在Linux/Unix系统中常用的邮件服务器也有不少选择，最经典也是最常见的莫过于Postfix。这篇文章将会讲述如何在Ubuntu系统之下，通过<a style="color: #ff8373;" href="http://www.postfix.org/" rel="nofollow">Postfix</a>、<a style="color: #ff8373;" href="http://www.dovecot.org/" rel="nofollow">Dovecot</a>、<a style="color: #ff8373;" href="https://www.mysql.com/" rel="nofollow">MySQL</a>整合实现普通意义上「邮件服务器」的大部分功能。</p>
<p><span id="OSC_h2_1"></span></p>
<h2>开始之前</h2>
<p>配置邮件服务器并不是一项简单的工作，其过程不仅需要一定的技术能力，同时也需要大家具有一定的耐心，同时也需要大家非常细心。为了能够「看懂」并「最终实践」这篇文章，大家还需要了解或掌握以下知识：</p>
<ul>
<li><strong>Postfix:</strong> 是一个标准的MTA「Mail Transfer Agent」服务器，它负责通过SMTP协议管理发送到本机的邮件以及由本机发向外界的邮件。在本例中，Postfix会把邮件的本地投递工作「接受到邮件之后将邮件存档到本地磁盘」交给Dovecot的LMTP服务「Local Mail Transfer Protocol service」处理。当然，当大家想通过服务器向外界发送邮件时，Postfix还将负责验证权限以确保服务器不被滥用。「很多邮件服务器根本没有对SMTP做用户验证，这将导致任何匿名用户都可以通过服务器向外界发送邮件，从而使得服务器变成垃圾中转站」</li>
<li><strong>Dovecot:</strong> 是一个非常优秀的IMAP/POP服务器用以接收外界发送到本机的邮件。通常，Dovecot的工作内容包括：验证用户身份以确保邮件不会被泄露。在本例中，Dovecot将负责所有的「身份验证」工作，我们会配置Dovecot查询本地的MySQL数据库以确认用户身份</li>
<li><strong>MySQL:</strong> 不必多说，它将存储所有的用户信息，其中包括：需要监听的域名信息、用户邮箱地址、登录密码、邮箱别名「alias」等</li>
<li><strong>Ubuntu:</strong> 本例中的OS将选择Ubuntu14.10作为标准，其他Linux发行版的相关操作不在描述</li>
</ul>
<p><span id="OSC_h2_2"></span></p>
<h2>工作原理</h2>
<p><span id="OSC_h3_3"></span></p>
<h3>服务器接收邮件的过程</h3>
<p>在开始讲述本例的内容之前，我们先来看看Postfix+Dovecot+MySQL是如何相互协作以实现邮件服务器的各项功能。我们假设 张三通过oschina.net的邮箱<code style="color: #40aa53;">zhangsan@oschina.net</code> 发送一份邮件给 李四<code style="color: #40aa53;">lisi@mydomain.com</code>，则服务器接收邮件的过程大致如下图所示：</p>
<p><a style="color: #ff8373;" href="http://static.oschina.net/uploads/space/2015/0511/165916_Tmyl_2340783.png" target="_blank"><img src="http://static.oschina.net/uploads/space/2015/0511/165916_Tmyl_2340783.png" alt="imcoming mail" /></a></p>
<ol>
<li><code style="color: #40aa53;">zhangsan@oschina.net</code>发送邮件到<code style="color: #40aa53;">lisi@mydomain.com</code></li>
<li>oschina.net服务器会通过DNS查询mydomain.com的MX记录并找到Postfix所在的服务器</li>
<li>邮件被发送给Postfix</li>
<li>Postfix转向MySQL求助，以查询mydomain.com是不是需要处理的域名</li>
<li>MySQL返回确认信息给Postfix</li>
<li>Postfix将接受到的邮件投递给Dovecot的LMTP服务以便做处理</li>
<li>Dovecot将邮件内容保存到<code style="color: #40aa53;">lisi@mydomain.com</code>用户对应的磁盘路径</li>
</ol>
<p><span id="OSC_h3_4"></span></p>
<h3>用户查收邮件的过程</h3>
<p>上述例子中我们看到了服务器接收邮件的过程，接下来我们看看，当大家通过用户名密码登录邮箱查看邮件时，会发生什么事情：</p>
<p><a style="color: #ff8373;" href="http://static.oschina.net/uploads/space/2015/0511/184339_NEpI_2340783.png" target="_blank"><img src="http://static.oschina.net/uploads/space/2015/0511/184339_NEpI_2340783.png" alt="checking mail" /></a></p>
<ol>
<li>邮件客户端 to Dovecot：尊敬的Dovecot大人，您好！我阔以建立一个IMAP加密连接吗？</li>
<li>Dovecot to 邮件客户端：当然阔以。这是我的SSL证书，请您告诉我帐号和密码！</li>
<li>邮件客户端 to Dovecot：好滴！这是我的用户名和密码，千万不要告诉别人哦！</li>
<li>Dovecot to MySQL：Hi 美女！请问下，这个用户名和密码是正确的嘛？</li>
<li>MySQL to Dovecot：好的，请稍后！呃……这个用户名和密码是正确的哦！</li>
<li>Dovecot打开存放在本地磁盘/var/mail/mydomain.com/llisi的mailbox</li>
<li>Dovecot获取到最新的邮件及其他相关信息</li>
<li>Dovecot将邮件及其相关的其他信息通过IMAP协议发送给客户端</li>
</ol>
<p><span id="OSC_h3_5"></span></p>
<h3>用户发送邮件的过程</h3>
<p>查收了最新的邮件之后，李四<code style="color: #40aa53;">lisi@mydomain.com</code>发现张三给他发来了邮件。现在，李四回复一封邮件给张三，会发生什么事情：</p>
<p><a style="color: #ff8373;" href="http://static.oschina.net/uploads/space/2015/0511/192105_DpWe_2340783.png" target="_blank"><img src="http://static.oschina.net/uploads/space/2015/0511/192105_DpWe_2340783.png" alt="sending mail" /></a></p>
<ol>
<li>邮件客户端 to Postfix：尊敬的Postfix大人，您好！我阔以建立一个安全的SMTP连接嘛？</li>
<li>Postfix to 邮件客户端：说人话！可以就是可以，干嘛要说「阔以」啊！你丫贱啊，找抽啊！想建立SMTP连接可以，不过要加密。这是我的SSL证书，告诉我你的帐号和密码，你个贱人！</li>
<li>邮件客户端 to Postfix：对不起，大人，我错鸟！这是我的帐号和密码，不要告诉别人哦！</li>
<li>Postfix to Dovecot：Hi 帅哥，帮我查一下这个帐号和密码！</li>
<li>Dovecot to MySQL：Hi 美女，这个帐号和密码是正确的呢？！还是正确的呢？！还是……</li>
<li>MySQL to Dovecot：好啦，你乖啦！我查过啦，这个帐号密码是正确的啦！表卖萌哦，Dovecot君！</li>
<li>Dovecot to Postfix：大锅，则个帐号密码斯正缺滴！</li>
<li>Postfix to 邮件客户端：贱人，过来！你给的帐号密码是正确的，允许你发送邮件！</li>
<li>邮件客户端将编写好的邮件通过SMTP协议发送给Postfix</li>
<li>Postfix将收到的邮件转发给对方</li>
</ol>
<p>以上，大家已经看到邮件收、发的整个过程。接下来看看如何才能成功配置邮件服务器。</p>
<p><span id="OSC_h2_6"></span></p>
<h2>DNS配置</h2>
<p>首先，你需要有一个域名。本例中假定我们的域名为<code style="color: #40aa53;">mydomain.com</code>，以此为基础去做后续的所有工作。<strong>请注意：在DNS相关配置没有成功之前，请勿尝试后续的操作。即使你配置好了Postifx，只要DNS相关配置没有成功，邮件服务器一样不能正常工作。</strong></p>
<p>其次，登录域名管理系统「强烈推荐使用<a style="color: #ff8373;" href="https://www.dnspod.cn/" rel="nofollow">DNSPod</a>做域名管理」，新增几条MX记录指向你的邮件服务器。</p>
<p>第三，关于TTL设置。在测试邮件服务器的过程中，大家大可把TTL时间设置的短一点，这样可以让DNS服务器在很短的时间之内就起作用。当测试阶段过后，请即使将TTL时间设置成较大的值。什么？你问为什么要这样？自己去Google一下看看吧！TTL设置的太短会带来什么安全隐患。</p>
<p>设置完以后，DNS的MX记录及TTL时间大致如下：</p><pre class="crayon-plain-tag">mydomain&lt;span class=&quot;hljs-class&quot;&gt;.com&lt;/span&gt;         MX     &lt;span class=&quot;hljs-number&quot; style=&quot;color: #3387cc;&quot;&gt;10&lt;/span&gt;      mydomain&lt;span class=&quot;hljs-class&quot;&gt;.com&lt;/span&gt;    
mydomain&lt;span class=&quot;hljs-class&quot;&gt;.com&lt;/span&gt;            MX      &lt;span class=&quot;hljs-number&quot; style=&quot;color: #3387cc;&quot;&gt;10&lt;/span&gt;      &lt;span class=&quot;hljs-number&quot; style=&quot;color: #3387cc;&quot;&gt;12.34&lt;/span&gt;.&lt;span class=&quot;hljs-number&quot; style=&quot;color: #3387cc;&quot;&gt;56.78&lt;/span&gt;  
mail&lt;span class=&quot;hljs-class&quot;&gt;.mydomain&lt;/span&gt;&lt;span class=&quot;hljs-class&quot;&gt;.com&lt;/span&gt;    MX     &lt;span class=&quot;hljs-number&quot; style=&quot;color: #3387cc;&quot;&gt;10&lt;/span&gt;      &lt;span class=&quot;hljs-number&quot; style=&quot;color: #3387cc;&quot;&gt;12.34&lt;/span&gt;.&lt;span class=&quot;hljs-number&quot; style=&quot;color: #3387cc;&quot;&gt;56.78&lt;/span&gt;</pre><p><span id="OSC_h2_7"></span></p>
<h2>SSL证书</h2>
<p>关于SSL认证的问题，大家可以根据自己的情况做决定。有人偏向于购买第三方权威的SSL认证，也有人使用OpenSSL自己制作签名。当然，上述两种方法本质上是没有什么区别的，唯一的区别在于：如果是自己制作的SSL证书，大部分的邮件客户端都会弹出提示框询问是否信任等。</p>
<p><span id="OSC_h2_8"></span></p>
<h2>修改hostname</h2>
<p>哈，终于进入了正题。现在，请大家打开终端「window系统用户可以选择使用putty等ssh工具连接服务器」并连接自己的服务器。</p><pre class="crayon-plain-tag">&lt;span class=&quot;hljs-title&quot; style=&quot;color: #e28964;&quot;&gt;ssh&lt;/span&gt; username@&lt;span class=&quot;hljs-number&quot; style=&quot;color: #3387cc;&quot;&gt;12.34.56.78&lt;/span&gt;</pre><p>连接成功以后，请第一时间执行下述命令切换到root用户：</p><pre class="crayon-plain-tag">sudo &lt;span class=&quot;hljs-operator&quot;&gt;-s&lt;/span&gt;</pre><p></p>
<blockquote><p><strong>请注意</strong><br />
为什么要切换到root用户？纯属个人爱好，因为我很懒，懒得每次执行命令时在命令的前面带上<code style="color: #40aa53;">sudo</code>这样的参数，因此直接切换到root用户好了。</p></blockquote>
<p>接下来，在命令行中输入如下命令查看hostname：</p><pre class="crayon-plain-tag">&lt;span class=&quot;hljs-title&quot; style=&quot;color: #e28964;&quot;&gt;hostname&lt;/span&gt;</pre><p>接着，在命令行输入如下命令查看FQDN「fully-qualified domain name」：</p><pre class="crayon-plain-tag">hostname &lt;span class=&quot;hljs-operator&quot;&gt;-f&lt;/span&gt;</pre><p>将上述两个名称记录下来，安装postfix时你将会使用到。</p>
<p>当然，上述的机器名是可以随时修改的，如果你想要修改，可以直接通过vi编辑器打开<code style="color: #40aa53;">/etc/hostname</code>文件，并将自己想要的机器名写入其中并保存即可</p>
<p><span id="OSC_h2_9"></span></p>
<h2>MySQL安装及配置</h2>
<p>本例中我们使用MySQL数据库保存Postfix需要服务的虚拟域名、用户帐号及密码、邮件别名三个重要的信息。</p>
<blockquote><p><strong>请注意：</strong><br />
其实Postfix和Dovecot是完全可以不使用数据库的，二者都可以通过各种配置文件完成「零数据库」的邮件服务器。但是，既然可以使用数据库这么方便，为什么不用呢？将这些需要配置的信息存储在数据库中「如：用户帐号及密码等」，对今后的维护来说是非常方便的事情。不是么？！</p></blockquote>
<p><span id="OSC_h3_10"></span></p>
<h3>MySQL安装</h3>
<p>在Ubuntu种安装软件，是再简单不过的事情了。安装MySQL请在命令行中执行如下命令：</p><pre class="crayon-plain-tag">apt-get &lt;span class=&quot;hljs-operator&quot;&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;install&lt;/span&gt; mysql-&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;server&lt;/span&gt;
&lt;/span&gt;</pre><p>安装过程中会需要你输入两次MySQL的root口令，请牢记该口令</p>
<p><a style="color: #ff8373;" href="http://static.oschina.net/uploads/space/2015/0511/195225_PcQr_2340783.png" target="_blank"><img src="http://static.oschina.net/uploads/space/2015/0511/195225_PcQr_2340783.png" alt="MySQL install" /></a></p>
<p><span id="OSC_h3_11"></span></p>
<h3>新建数据库及用户</h3>
<p>接下来，我们需要新建一个MySQL用户及一个数据库：</p>
<ol>
<li>使用root口令登录MySQL<br />
<pre class="crayon-plain-tag">mysql -u root -&lt;span class=&quot;hljs-tag&quot; style=&quot;color: #89bdff;&quot;&gt;p&lt;/span&gt;</pre>
</li>
<li>输入root口令</li>
<li>新建一个数据库，名称叫做mailserver：<br />
<pre class="crayon-plain-tag">&lt;span class=&quot;hljs-operator&quot;&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;create&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;database&lt;/span&gt; mailserver &lt;span class=&quot;hljs-built_in&quot;&gt;character&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;set&lt;/span&gt; utf8;&lt;/span&gt;</pre>
</li>
<li>输入如下命令以新建一个用户mailserver，并指定密码为mailserver123：<br />
<pre class="crayon-plain-tag">&lt;span class=&quot;hljs-operator&quot;&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;create&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;user&lt;/span&gt; mailserver@&lt;span class=&quot;hljs-string&quot; style=&quot;color: #65b042;&quot;&gt;'localhost'&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;identified&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;by&lt;/span&gt; &lt;span class=&quot;hljs-string&quot; style=&quot;color: #65b042;&quot;&gt;'mailserver123'&lt;/span&gt;;&lt;/span&gt;</pre>
</li>
<li>将数据库mailserver的所有权限赋给用户mailserver：<br />
<pre class="crayon-plain-tag">&lt;span class=&quot;hljs-operator&quot;&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;grant&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;all&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;on&lt;/span&gt; mailserver.* &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;to&lt;/span&gt; mailserver@&lt;span class=&quot;hljs-string&quot; style=&quot;color: #65b042;&quot;&gt;'localhost'&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;identified&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;by&lt;/span&gt; &lt;span class=&quot;hljs-string&quot; style=&quot;color: #65b042;&quot;&gt;'mailserver123'&lt;/span&gt;;&lt;/span&gt;</pre>
</li>
<li>退出root用户：<br />
<pre class="crayon-plain-tag">&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;exit&lt;/span&gt;;</pre>
</li>
<li>使用mailserver用户登录：<br />
<pre class="crayon-plain-tag">mysql -u mailserver -&lt;span class=&quot;hljs-tag&quot; style=&quot;color: #89bdff;&quot;&gt;p&lt;/span&gt;</pre>
</li>
<li>输入mailserver帐号的口令</li>
<li>将默认数据库切换为mailserver数据库：<br />
<pre class="crayon-plain-tag">&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;use&lt;/span&gt; &lt;span class=&quot;hljs-title&quot; style=&quot;color: #89bdff;&quot;&gt;mailserver&lt;/span&gt;;</pre>
</li>
</ol>
<p><span id="OSC_h3_12"></span></p>
<h3>新建表格</h3>
<ol>
<li>输入如下SQL语句以新建<code style="color: #40aa53;">virtual_domains</code>表，该表是本地服务器用以接收邮件的域名：<br />
<pre class="crayon-plain-tag">&lt;span class=&quot;hljs-operator&quot;&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;CREATE&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;TABLE&lt;/span&gt; &lt;span class=&quot;hljs-string&quot; style=&quot;color: #65b042;&quot;&gt;`virtual_domains`&lt;/span&gt; (  
  &lt;span class=&quot;hljs-string&quot; style=&quot;color: #65b042;&quot;&gt;`id`&lt;/span&gt; &lt;span class=&quot;hljs-built_in&quot;&gt;int&lt;/span&gt;(&lt;span class=&quot;hljs-number&quot; style=&quot;color: #3387cc;&quot;&gt;11&lt;/span&gt;) &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;NOT&lt;/span&gt; &lt;span class=&quot;hljs-literal&quot;&gt;NULL&lt;/span&gt; auto_increment,  
  &lt;span class=&quot;hljs-string&quot; style=&quot;color: #65b042;&quot;&gt;`name`&lt;/span&gt; &lt;span class=&quot;hljs-built_in&quot;&gt;varchar&lt;/span&gt;(&lt;span class=&quot;hljs-number&quot; style=&quot;color: #3387cc;&quot;&gt;50&lt;/span&gt;) &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;NOT&lt;/span&gt; &lt;span class=&quot;hljs-literal&quot;&gt;NULL&lt;/span&gt;,  
  &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;PRIMARY&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;KEY&lt;/span&gt; (&lt;span class=&quot;hljs-string&quot; style=&quot;color: #65b042;&quot;&gt;`id`&lt;/span&gt;))  
  &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;ENGINE&lt;/span&gt;=&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;InnoDB&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;DEFAULT&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;CHARSET&lt;/span&gt;=utf8;&lt;/span&gt;</pre>
</li>
<li>输入如下SQL语句以新建<code style="color: #40aa53;">virtual_users</code>表，该表邮件服务器的终端用户表，记录用户的邮件地址及密码「千万不要保存明文密码」：<br />
<pre class="crayon-plain-tag">&lt;span class=&quot;hljs-operator&quot;&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;CREATE&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;TABLE&lt;/span&gt; &lt;span class=&quot;hljs-string&quot; style=&quot;color: #65b042;&quot;&gt;`virtual_users`&lt;/span&gt; (  
&lt;span class=&quot;hljs-string&quot; style=&quot;color: #65b042;&quot;&gt;`id`&lt;/span&gt; &lt;span class=&quot;hljs-built_in&quot;&gt;int&lt;/span&gt;(&lt;span class=&quot;hljs-number&quot; style=&quot;color: #3387cc;&quot;&gt;11&lt;/span&gt;) &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;NOT&lt;/span&gt; &lt;span class=&quot;hljs-literal&quot;&gt;NULL&lt;/span&gt; auto_increment,  
&lt;span class=&quot;hljs-string&quot; style=&quot;color: #65b042;&quot;&gt;`domain_id`&lt;/span&gt; &lt;span class=&quot;hljs-built_in&quot;&gt;int&lt;/span&gt;(&lt;span class=&quot;hljs-number&quot; style=&quot;color: #3387cc;&quot;&gt;11&lt;/span&gt;) &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;NOT&lt;/span&gt; &lt;span class=&quot;hljs-literal&quot;&gt;NULL&lt;/span&gt;,  
&lt;span class=&quot;hljs-string&quot; style=&quot;color: #65b042;&quot;&gt;`password`&lt;/span&gt; &lt;span class=&quot;hljs-built_in&quot;&gt;varchar&lt;/span&gt;(&lt;span class=&quot;hljs-number&quot; style=&quot;color: #3387cc;&quot;&gt;106&lt;/span&gt;) &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;NOT&lt;/span&gt; &lt;span class=&quot;hljs-literal&quot;&gt;NULL&lt;/span&gt;,  
&lt;span class=&quot;hljs-string&quot; style=&quot;color: #65b042;&quot;&gt;`email`&lt;/span&gt; &lt;span class=&quot;hljs-built_in&quot;&gt;varchar&lt;/span&gt;(&lt;span class=&quot;hljs-number&quot; style=&quot;color: #3387cc;&quot;&gt;100&lt;/span&gt;) &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;NOT&lt;/span&gt; &lt;span class=&quot;hljs-literal&quot;&gt;NULL&lt;/span&gt;,  
&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;PRIMARY&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;KEY&lt;/span&gt; (&lt;span class=&quot;hljs-string&quot; style=&quot;color: #65b042;&quot;&gt;`id`&lt;/span&gt;),  
&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;UNIQUE&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;KEY&lt;/span&gt; &lt;span class=&quot;hljs-string&quot; style=&quot;color: #65b042;&quot;&gt;`email`&lt;/span&gt; (&lt;span class=&quot;hljs-string&quot; style=&quot;color: #65b042;&quot;&gt;`email`&lt;/span&gt;),  
&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;FOREIGN&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;KEY&lt;/span&gt; (domain_id) &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;REFERENCES&lt;/span&gt; virtual_domains(id) &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;ON&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;DELETE&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;CASCADE&lt;/span&gt;)  
&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;ENGINE&lt;/span&gt;=&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;InnoDB&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;DEFAULT&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;CHARSET&lt;/span&gt;=utf8;&lt;/span&gt;</pre>
</li>
<li>输入如下SQL语句以新建<code style="color: #40aa53;">virtual_aliases</code>表，该表是邮件服务器别名表「邮件服务器种的<code style="color: #40aa53;">别名alias</code>的概念大家可以Google一番」：<br />
<pre class="crayon-plain-tag">&lt;span class=&quot;hljs-operator&quot;&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;CREATE&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;TABLE&lt;/span&gt; &lt;span class=&quot;hljs-string&quot; style=&quot;color: #65b042;&quot;&gt;`virtual_aliases`&lt;/span&gt; (  
&lt;span class=&quot;hljs-string&quot; style=&quot;color: #65b042;&quot;&gt;`id`&lt;/span&gt; &lt;span class=&quot;hljs-built_in&quot;&gt;int&lt;/span&gt;(&lt;span class=&quot;hljs-number&quot; style=&quot;color: #3387cc;&quot;&gt;11&lt;/span&gt;) &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;NOT&lt;/span&gt; &lt;span class=&quot;hljs-literal&quot;&gt;NULL&lt;/span&gt; auto_increment,  
&lt;span class=&quot;hljs-string&quot; style=&quot;color: #65b042;&quot;&gt;`domain_id`&lt;/span&gt; &lt;span class=&quot;hljs-built_in&quot;&gt;int&lt;/span&gt;(&lt;span class=&quot;hljs-number&quot; style=&quot;color: #3387cc;&quot;&gt;11&lt;/span&gt;) &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;NOT&lt;/span&gt; &lt;span class=&quot;hljs-literal&quot;&gt;NULL&lt;/span&gt;,  
&lt;span class=&quot;hljs-string&quot; style=&quot;color: #65b042;&quot;&gt;`source`&lt;/span&gt; &lt;span class=&quot;hljs-built_in&quot;&gt;varchar&lt;/span&gt;(&lt;span class=&quot;hljs-number&quot; style=&quot;color: #3387cc;&quot;&gt;100&lt;/span&gt;) &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;NOT&lt;/span&gt; &lt;span class=&quot;hljs-literal&quot;&gt;NULL&lt;/span&gt;,  
&lt;span class=&quot;hljs-string&quot; style=&quot;color: #65b042;&quot;&gt;`destination`&lt;/span&gt; &lt;span class=&quot;hljs-built_in&quot;&gt;varchar&lt;/span&gt;(&lt;span class=&quot;hljs-number&quot; style=&quot;color: #3387cc;&quot;&gt;100&lt;/span&gt;) &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;NOT&lt;/span&gt; &lt;span class=&quot;hljs-literal&quot;&gt;NULL&lt;/span&gt;,  
&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;PRIMARY&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;KEY&lt;/span&gt; (&lt;span class=&quot;hljs-string&quot; style=&quot;color: #65b042;&quot;&gt;`id`&lt;/span&gt;),  
&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;FOREIGN&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;KEY&lt;/span&gt; (domain_id) &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;REFERENCES&lt;/span&gt; virtual_domains(id) &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;ON&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;DELETE&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;CASCADE&lt;/span&gt;)  
&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;ENGINE&lt;/span&gt;=&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;InnoDB&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;DEFAULT&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;CHARSET&lt;/span&gt;=utf8          
&lt;/span&gt;</pre><br />
<span id="OSC_h3_13"></span></p>
<h3>插入数据</h3>
<p>为了便于查看结果，接下来给上述三张表种插入一些测试数据：</li>
<li>给<code style="color: #40aa53;">virtual_domains</code>表插入测试数据，大致如下：</p><pre class="crayon-plain-tag">&lt;span class=&quot;hljs-operator&quot;&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;insert&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;into&lt;/span&gt; virtual_domains(id,name) &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;values&lt;/span&gt;(&lt;span class=&quot;hljs-number&quot; style=&quot;color: #3387cc;&quot;&gt;1&lt;/span&gt;,&lt;span class=&quot;hljs-string&quot; style=&quot;color: #65b042;&quot;&gt;'mail.mydomain.com'&lt;/span&gt;);&lt;/span&gt;     
&lt;span class=&quot;hljs-operator&quot;&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;insert&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;into&lt;/span&gt; virtual_domains(id,name) &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;values&lt;/span&gt;(&lt;span class=&quot;hljs-number&quot; style=&quot;color: #3387cc;&quot;&gt;2&lt;/span&gt;,&lt;span class=&quot;hljs-string&quot; style=&quot;color: #65b042;&quot;&gt;'mydomain.com'&lt;/span&gt;);&lt;/span&gt;</pre><p></p>
<blockquote><p><strong>请注意：</strong><br />
上述表种id字段是自增列，可以不赋值。但无论如何，接下来的两张表种我们将需要上述表种的逐渐列id的值。比如：我将要添加mydomain.com域名下的邮箱帐号，而mydomain.com在<code style="color: #40aa53;">virtual_domains</code>表种的id值为2。</p></blockquote>
</li>
<li>给<code style="color: #40aa53;">virtual_users</code>表添加用户数据：<br />
<pre class="crayon-plain-tag">&lt;span class=&quot;hljs-operator&quot;&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;insert&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;into&lt;/span&gt; virtual_users(id,domain_id,&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;password&lt;/span&gt;,email)  
&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;values&lt;/span&gt; (&lt;span class=&quot;hljs-number&quot; style=&quot;color: #3387cc;&quot;&gt;1&lt;/span&gt;,&lt;span class=&quot;hljs-number&quot; style=&quot;color: #3387cc;&quot;&gt;2&lt;/span&gt;,&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;ENCRYPT&lt;/span&gt;(&lt;span class=&quot;hljs-string&quot; style=&quot;color: #65b042;&quot;&gt;'zhangsan123456'&lt;/span&gt;, &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;CONCAT&lt;/span&gt;(&lt;span class=&quot;hljs-string&quot; style=&quot;color: #65b042;&quot;&gt;'$7$'&lt;/span&gt;, &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;SUBSTRING&lt;/span&gt;(&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;SHA&lt;/span&gt;(&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;RAND&lt;/span&gt;()), -&lt;span class=&quot;hljs-number&quot; style=&quot;color: #3387cc;&quot;&gt;16&lt;/span&gt;))),&lt;span class=&quot;hljs-string&quot; style=&quot;color: #65b042;&quot;&gt;'zhangsan@mydomain.com'&lt;/span&gt;);&lt;/span&gt;


&lt;span class=&quot;hljs-operator&quot;&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;insert&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;into&lt;/span&gt; virtual_users(id,domain_id,&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;password&lt;/span&gt;,email)  
&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;values&lt;/span&gt; (&lt;span class=&quot;hljs-number&quot; style=&quot;color: #3387cc;&quot;&gt;2&lt;/span&gt;,&lt;span class=&quot;hljs-number&quot; style=&quot;color: #3387cc;&quot;&gt;2&lt;/span&gt;,&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;ENCRYPT&lt;/span&gt;(&lt;span class=&quot;hljs-string&quot; style=&quot;color: #65b042;&quot;&gt;'123456lisi'&lt;/span&gt;, &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;CONCAT&lt;/span&gt;(&lt;span class=&quot;hljs-string&quot; style=&quot;color: #65b042;&quot;&gt;'$7$'&lt;/span&gt;, &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;SUBSTRING&lt;/span&gt;(&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;SHA&lt;/span&gt;(&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;RAND&lt;/span&gt;()), -&lt;span class=&quot;hljs-number&quot; style=&quot;color: #3387cc;&quot;&gt;16&lt;/span&gt;))),&lt;span class=&quot;hljs-string&quot; style=&quot;color: #65b042;&quot;&gt;'lisi@mydomain.com'&lt;/span&gt;);&lt;/span&gt;</pre>
</li>
<li>给<code style="color: #40aa53;">virtual_aliases</code>表添加别名数据：<br />
<pre class="crayon-plain-tag">&lt;span class=&quot;hljs-operator&quot;&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;insert&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;into&lt;/span&gt; virtual_aliases(id,domain_id,source,destination)  
&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;values&lt;/span&gt; (&lt;span class=&quot;hljs-number&quot; style=&quot;color: #3387cc;&quot;&gt;1&lt;/span&gt;,&lt;span class=&quot;hljs-number&quot; style=&quot;color: #3387cc;&quot;&gt;2&lt;/span&gt;,&lt;span class=&quot;hljs-string&quot; style=&quot;color: #65b042;&quot;&gt;'all@mydomain.com'&lt;/span&gt;,&lt;span class=&quot;hljs-string&quot; style=&quot;color: #65b042;&quot;&gt;'zhangsan@mydomain.com'&lt;/span&gt;);&lt;/span&gt;

&lt;span class=&quot;hljs-operator&quot;&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;insert&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;into&lt;/span&gt; virtual_aliases(id,domain_id,source,destination)  
&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;values&lt;/span&gt; (&lt;span class=&quot;hljs-number&quot; style=&quot;color: #3387cc;&quot;&gt;1&lt;/span&gt;,&lt;span class=&quot;hljs-number&quot; style=&quot;color: #3387cc;&quot;&gt;2&lt;/span&gt;,&lt;span class=&quot;hljs-string&quot; style=&quot;color: #65b042;&quot;&gt;'all@mydomain.com'&lt;/span&gt;,&lt;span class=&quot;hljs-string&quot; style=&quot;color: #65b042;&quot;&gt;'lisi@mydomain.com'&lt;/span&gt;);&lt;/span&gt;</pre></p>
<blockquote><p><strong>请注意：</strong><br />
通过上述别名表的数据，当有人给<code style="color: #40aa53;">all@mydomain.com</code>发送邮件时，系统将自动将邮件转发给<code style="color: #40aa53;">zhangsan@mydomain.com</code>和<code style="color: #40aa53;">lisi@mydomain.com</code><br />
这种场景，在公司内部「发送通知」等情况下适用</p></blockquote>
</li>
</ol>
<p><span id="OSC_h3_14"></span></p>
<h3>测试数据</h3>
<p>写几个SQL查询语句查看下结果吧</p><pre class="crayon-plain-tag">&lt;span class=&quot;hljs-operator&quot;&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;select&lt;/span&gt; * &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;from&lt;/span&gt; virtual_domains;&lt;/span&gt;  
&lt;span class=&quot;hljs-operator&quot;&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;select&lt;/span&gt; * &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;from&lt;/span&gt; virtual_users;&lt;/span&gt;  
&lt;span class=&quot;hljs-operator&quot;&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;select&lt;/span&gt; * &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;from&lt;/span&gt; virtual_aliases;&lt;/span&gt;</pre><p><span id="OSC_h2_15"></span></p>
<h2>Postfix安装及配置</h2>
<p>Postfix是邮件发送的核心服务器，所有向内、向外投递的邮件都需要经过Postfix通过SMTP协议完成。接下来的内容，大家需要修改Postfix相关的一些参数，它们是：</p>
<ul>
<li>告诉Postfix如何连接MySQL数据库，并让Postfix通过数据库种的表确定收发邮件的域名、用户帐号及密码、邮件别名等</li>
<li>告诉Postfix将收到的邮件转发给Dovecot的LMTP服务以完成本地投递</li>
<li>告诉Postfix所有的连接都需要STARTTLS加密，如果有必要「废话啊，当然必须这样」</li>
<li>开放本地端口25、465、587之一或全部</li>
</ul>
<p><span id="OSC_h3_16"></span></p>
<h3>Postfix的安装</h3>
<p>在命令行种执行以下命令以安装Postfix：</p><pre class="crayon-plain-tag">apt-&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;get&lt;/span&gt; install &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;postfix&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;postfix&lt;/span&gt;-mysql</pre><p>安装过程中需要选择Postfix的类型，请选择<code style="color: #40aa53;">Internet Site</code>：</p>
<p><a style="color: #ff8373;" href="http://static.oschina.net/uploads/space/2015/0511/205329_10Lq_2340783.png" target="_blank"><img src="http://static.oschina.net/uploads/space/2015/0511/205329_10Lq_2340783.png" alt="Postfix Config" /></a></p>
<p>Postfix安装过程中还会需要输入<strong>System mail name</strong>，这里请输入你要收发邮件的域名地址「随便写也可以，反正后面需要修改配置文件」</p>
<p><span id="OSC_h3_17"></span></p>
<h3>Postfix的配置</h3>
<ol>
<li>备份Postfix的配置文件<code style="color: #40aa53;">/etc/postfix/main.cf</code>，先！<br />
<pre class="crayon-plain-tag">cp /etc/postfix/main&lt;span class=&quot;hljs-class&quot;&gt;.cf&lt;/span&gt; /etc/postfix/main&lt;span class=&quot;hljs-class&quot;&gt;.cf_backup_20150511&lt;/span&gt;</pre></p>
<blockquote><p><strong>请注意</strong><br />
任何时候，对任何配置进行修改之前，先做好备份总是非常必要的<br />
同时，这也是一个非常良好的操作习惯</p></blockquote>
</li>
<li>使用vi编辑器打开<code style="color: #40aa53;">/etc/postfix/main.cf</code>文件<br />
<pre class="crayon-plain-tag">vi /etc/postfix/main&lt;span class=&quot;hljs-class&quot;&gt;.cf&lt;/span&gt;</pre>
</li>
<li>打开之后，按下<code style="color: #40aa53;">i</code>键进入编辑模式</li>
<li>鉴于我们没有打算使用Postfix做用户的权限验证「上述几个图种已经展示清楚」，我们将要把Postfix默认的用户验证参数屏蔽，因此请在如下几行前边加入<code style="color: #40aa53;">#</code>符号以注释：<br />
<pre class="crayon-plain-tag"># &lt;span class=&quot;hljs-class&quot;&gt;TLS&lt;/span&gt; parameters  
  &lt;span class=&quot;hljs-symbol&quot; style=&quot;color: #3387cc;&quot;&gt;#smtpd_tls_cert_file&lt;/span&gt;=/etc/ssl/certs/ssl-cert-snakeoil.pem  
  &lt;span class=&quot;hljs-symbol&quot; style=&quot;color: #3387cc;&quot;&gt;#smtpd_tls_key_file&lt;/span&gt;=/etc/ssl/private/ssl-cert-snakeoil.key  &lt;span class=&quot;hljs-symbol&quot; style=&quot;color: #3387cc;&quot;&gt;#smtpd_use_tls&lt;/span&gt;=yes  
  &lt;span class=&quot;hljs-symbol&quot; style=&quot;color: #3387cc;&quot;&gt;#smtpd_tls_session_cache_database&lt;/span&gt; = &lt;span class=&quot;hljs-method&quot;&gt;btree:&lt;/span&gt;&lt;span class=&quot;hljs-char&quot;&gt;${&lt;/span&gt;data_directory}/smtpd_scache  
  &lt;span class=&quot;hljs-symbol&quot; style=&quot;color: #3387cc;&quot;&gt;#smtp_tls_session_cache_database&lt;/span&gt; = &lt;span class=&quot;hljs-method&quot;&gt;btree:&lt;/span&gt;&lt;span class=&quot;hljs-char&quot;&gt;${&lt;/span&gt;data_directory}/smtp_scache</pre>
</li>
<li>复制如下内容，并将其插入到上述注释代码之后：<br />
<pre class="crayon-plain-tag">&lt;span class=&quot;hljs-constant&quot;&gt;smtpd_tls_cert_file&lt;/span&gt;=/etc/dovecot/dovecot.pem  
&lt;span class=&quot;hljs-constant&quot;&gt;smtpd_tls_key_file&lt;/span&gt;=/etc/dovecot/private/dovecot.pem  
&lt;span class=&quot;hljs-constant&quot;&gt;smtpd_use_tls&lt;/span&gt;=yes  
&lt;span class=&quot;hljs-constant&quot;&gt;smtpd_tls_auth_only&lt;/span&gt; = yes  

&lt;span class=&quot;hljs-comment&quot; style=&quot;font-style: italic; color: #aeaeae;&quot;&gt;#Enabling SMTP for authenticated users, and handing off authentication to Dovecot  &lt;/span&gt;
&lt;span class=&quot;hljs-constant&quot;&gt;smtpd_sasl_type&lt;/span&gt; = dovecot  
&lt;span class=&quot;hljs-constant&quot;&gt;smtpd_sasl_path&lt;/span&gt; = private/auth  
&lt;span class=&quot;hljs-constant&quot;&gt;smtpd_sasl_auth_enable&lt;/span&gt; = yes  
&lt;span class=&quot;hljs-constant&quot;&gt;smtpd_recipient_restrictions&lt;/span&gt; =  permit_sasl_authenticated, permit_mynetworks, reject_unauth_destination</pre></p>
<blockquote><p><strong>请注意：</strong><br />
上述几个参数的含义，请参照<a style="color: #ff8373;" href="http://www.postfix.org/documentation.html" rel="nofollow">Postfix配置文档</a></p></blockquote>
</li>
<li>按照如下方式修改<code style="color: #40aa53;">mydestination</code>一行的值：<br />
<pre class="crayon-plain-tag">&lt;span class=&quot;hljs-attribute&quot;&gt;mydestination &lt;/span&gt;=&lt;span class=&quot;hljs-string&quot; style=&quot;color: #65b042;&quot;&gt; localhost
&lt;/span&gt;</pre></p>
<blockquote><p><strong>请注意：</strong><br />
将<code style="color: #40aa53;">mydestination</code>的值修改为localhost，以便Postfix能够通过MySQL表中相关数据决定需要接受/发送邮件的域名，这样更具有通用性</p></blockquote>
</li>
<li>在文档种加入以下内容，以便告诉Postfix不要使用LDA「Local Delivery Agent」转而使用Dovecot的LMTP完成本地邮件投递：<br />
<pre class="crayon-plain-tag">#Handing off local delivery &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;to&lt;/span&gt; Dovecot's LMTP, &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;and&lt;/span&gt; telling it where &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;to&lt;/span&gt; store mail  
virtual_transport = lmtp:unix:&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;private&lt;/span&gt;/dovecot-lmtp</pre>
</li>
<li>在文档中加入以下内容，以便告诉Postfix去MySQL数据库种寻找域名、用户帐号密码及邮件别名等信息：<br />
<pre class="crayon-plain-tag">&lt;span class=&quot;hljs-id&quot;&gt;#Virtual&lt;/span&gt; domains, users, and aliases  
virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-mailbox-domains&lt;span class=&quot;hljs-class&quot;&gt;.cf&lt;/span&gt;  
virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-mailbox-maps&lt;span class=&quot;hljs-class&quot;&gt;.cf&lt;/span&gt;  
virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-alias-maps&lt;span class=&quot;hljs-class&quot;&gt;.cf&lt;/span&gt;</pre>
</li>
<li>最终，修改完成以后的<code style="color: #40aa53;">/etc/postfix/main.cf</code>文件大致应该如下：<br />
<pre class="crayon-plain-tag">&lt;span class=&quot;hljs-comment&quot; style=&quot;font-style: italic; color: #aeaeae;&quot;&gt;# See /usr/share/postfix/main.cf.dist for a commented, more complete version    &lt;/span&gt;

&lt;span class=&quot;hljs-comment&quot; style=&quot;font-style: italic; color: #aeaeae;&quot;&gt;# Debian specific:  Specifying a file name will cause the first  &lt;/span&gt;
&lt;span class=&quot;hljs-comment&quot; style=&quot;font-style: italic; color: #aeaeae;&quot;&gt;# line of that file to be used as the name.  The Debian default  &lt;/span&gt;
&lt;span class=&quot;hljs-comment&quot; style=&quot;font-style: italic; color: #aeaeae;&quot;&gt;# is /etc/mailname.  &lt;/span&gt;
&lt;span class=&quot;hljs-comment&quot; style=&quot;font-style: italic; color: #aeaeae;&quot;&gt;#myorigin = /etc/mailname  &lt;/span&gt;

&lt;span class=&quot;hljs-variable&quot; style=&quot;color: #3e87e3;&quot;&gt;smtpd_banner =&lt;/span&gt; $myhostname ESMTP $mail_name (Ubuntu)  
&lt;span class=&quot;hljs-variable&quot; style=&quot;color: #3e87e3;&quot;&gt;biff =&lt;/span&gt; no  

&lt;span class=&quot;hljs-comment&quot; style=&quot;font-style: italic; color: #aeaeae;&quot;&gt;# appending .domain is the MUA's job.  &lt;/span&gt;
&lt;span class=&quot;hljs-variable&quot; style=&quot;color: #3e87e3;&quot;&gt;append_dot_mydomain =&lt;/span&gt; no  

&lt;span class=&quot;hljs-comment&quot; style=&quot;font-style: italic; color: #aeaeae;&quot;&gt;# Uncomment the next line to generate &quot;delayed mail&quot; warnings  &lt;/span&gt;
&lt;span class=&quot;hljs-comment&quot; style=&quot;font-style: italic; color: #aeaeae;&quot;&gt;#delay_warning_time = 4h  &lt;/span&gt;

&lt;span class=&quot;hljs-variable&quot; style=&quot;color: #3e87e3;&quot;&gt;readme_directory =&lt;/span&gt; no  

&lt;span class=&quot;hljs-comment&quot; style=&quot;font-style: italic; color: #aeaeae;&quot;&gt;# TLS parameters    &lt;/span&gt;
&lt;span class=&quot;hljs-comment&quot; style=&quot;font-style: italic; color: #aeaeae;&quot;&gt;#smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem &lt;/span&gt;
&lt;span class=&quot;hljs-comment&quot; style=&quot;font-style: italic; color: #aeaeae;&quot;&gt;#smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key  &lt;/span&gt;
&lt;span class=&quot;hljs-comment&quot; style=&quot;font-style: italic; color: #aeaeae;&quot;&gt;#smtpd_use_tls=yes  &lt;/span&gt;
&lt;span class=&quot;hljs-comment&quot; style=&quot;font-style: italic; color: #aeaeae;&quot;&gt;#smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache  &lt;/span&gt;
&lt;span class=&quot;hljs-comment&quot; style=&quot;font-style: italic; color: #aeaeae;&quot;&gt;#smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache  &lt;/span&gt;

&lt;span class=&quot;hljs-variable&quot; style=&quot;color: #3e87e3;&quot;&gt;smtpd_tls_cert_file=&lt;/span&gt;/etc/dovecot/dovecot.pem  
&lt;span class=&quot;hljs-variable&quot; style=&quot;color: #3e87e3;&quot;&gt;smtpd_tls_key_file=&lt;/span&gt;/etc/dovecot/private/dovecot.pem  
&lt;span class=&quot;hljs-variable&quot; style=&quot;color: #3e87e3;&quot;&gt;smtpd_use_tls=&lt;/span&gt;yes  
&lt;span class=&quot;hljs-variable&quot; style=&quot;color: #3e87e3;&quot;&gt;smtpd_tls_auth_only =&lt;/span&gt; yes  

&lt;span class=&quot;hljs-comment&quot; style=&quot;font-style: italic; color: #aeaeae;&quot;&gt;#Enabling SMTP for authenticated users, and handing off authentication to Dovecot  &lt;/span&gt;
&lt;span class=&quot;hljs-variable&quot; style=&quot;color: #3e87e3;&quot;&gt;smtpd_sasl_type =&lt;/span&gt; dovecot  
&lt;span class=&quot;hljs-variable&quot; style=&quot;color: #3e87e3;&quot;&gt;smtpd_sasl_path =&lt;/span&gt; private/auth  
&lt;span class=&quot;hljs-variable&quot; style=&quot;color: #3e87e3;&quot;&gt;smtpd_sasl_auth_enable =&lt;/span&gt; yes  
&lt;span class=&quot;hljs-variable&quot; style=&quot;color: #3e87e3;&quot;&gt;smtpd_recipient_restrictions =&lt;/span&gt;  
    permit_sasl_authenticated,  
    permit_mynetworks,  
    reject_unauth_destination  

&lt;span class=&quot;hljs-comment&quot; style=&quot;font-style: italic; color: #aeaeae;&quot;&gt;# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for    &lt;/span&gt;
&lt;span class=&quot;hljs-comment&quot; style=&quot;font-style: italic; color: #aeaeae;&quot;&gt;# information on enabling SSL in the smtp client.      &lt;/span&gt;
&lt;span class=&quot;hljs-variable&quot; style=&quot;color: #3e87e3;&quot;&gt;myhostname =&lt;/span&gt; host.mydomain.com  
&lt;span class=&quot;hljs-variable&quot; style=&quot;color: #3e87e3;&quot;&gt;alias_maps =&lt;/span&gt; hash:/etc/aliases  
&lt;span class=&quot;hljs-variable&quot; style=&quot;color: #3e87e3;&quot;&gt;alias_database =&lt;/span&gt; hash:/etc/aliases  
&lt;span class=&quot;hljs-variable&quot; style=&quot;color: #3e87e3;&quot;&gt;myorigin =&lt;/span&gt; /etc/mailname  
&lt;span class=&quot;hljs-comment&quot; style=&quot;font-style: italic; color: #aeaeae;&quot;&gt;#mydestination = example.com, hostname.mydomain.com,localhost.mydomain.com, localhost  &lt;/span&gt;
&lt;span class=&quot;hljs-variable&quot; style=&quot;color: #3e87e3;&quot;&gt;mydestination =&lt;/span&gt; localhost  
&lt;span class=&quot;hljs-variable&quot; style=&quot;color: #3e87e3;&quot;&gt;relayhost =&lt;/span&gt;  
        &lt;span class=&quot;hljs-variable&quot; style=&quot;color: #3e87e3;&quot;&gt;mynetworks =&lt;/span&gt; &lt;span class=&quot;hljs-number&quot; style=&quot;color: #3387cc;&quot;&gt;127.0&lt;/span&gt;.&lt;span class=&quot;hljs-number&quot; style=&quot;color: #3387cc;&quot;&gt;0.0&lt;/span&gt;/&lt;span class=&quot;hljs-number&quot; style=&quot;color: #3387cc;&quot;&gt;8&lt;/span&gt; [::ffff:&lt;span class=&quot;hljs-number&quot; style=&quot;color: #3387cc;&quot;&gt;127.0&lt;/span&gt;.&lt;span class=&quot;hljs-number&quot; style=&quot;color: #3387cc;&quot;&gt;0.0&lt;/span&gt;]/&lt;span class=&quot;hljs-number&quot; style=&quot;color: #3387cc;&quot;&gt;104&lt;/span&gt; [::&lt;span class=&quot;hljs-number&quot; style=&quot;color: #3387cc;&quot;&gt;1&lt;/span&gt;]/&lt;span class=&quot;hljs-number&quot; style=&quot;color: #3387cc;&quot;&gt;128&lt;/span&gt;    
&lt;span class=&quot;hljs-variable&quot; style=&quot;color: #3e87e3;&quot;&gt;mailbox_size_limit =&lt;/span&gt; &lt;span class=&quot;hljs-number&quot; style=&quot;color: #3387cc;&quot;&gt;0&lt;/span&gt;  
&lt;span class=&quot;hljs-variable&quot; style=&quot;color: #3e87e3;&quot;&gt;recipient_delimiter =&lt;/span&gt; +  
&lt;span class=&quot;hljs-variable&quot; style=&quot;color: #3e87e3;&quot;&gt;inet_interfaces =&lt;/span&gt; all  

&lt;span class=&quot;hljs-comment&quot; style=&quot;font-style: italic; color: #aeaeae;&quot;&gt;#Handing off local delivery to Dovecot's LMTP, and telling it where to store mail  &lt;/span&gt;
&lt;span class=&quot;hljs-variable&quot; style=&quot;color: #3e87e3;&quot;&gt;virtual_transport =&lt;/span&gt; lmtp:unix:private/dovecot-lmtp  

&lt;span class=&quot;hljs-comment&quot; style=&quot;font-style: italic; color: #aeaeae;&quot;&gt;#Virtual domains, users, and aliases  &lt;/span&gt;
&lt;span class=&quot;hljs-variable&quot; style=&quot;color: #3e87e3;&quot;&gt;virtual_mailbox_domains =&lt;/span&gt; mysql:/etc/postfix/mysql-virtual-mailbox-domains.cf  
&lt;span class=&quot;hljs-variable&quot; style=&quot;color: #3e87e3;&quot;&gt;virtual_mailbox_maps =&lt;/span&gt; mysql:/etc/postfix/mysql-virtual-mailbox-maps.cf  
&lt;span class=&quot;hljs-variable&quot; style=&quot;color: #3e87e3;&quot;&gt;virtual_alias_maps =&lt;/span&gt; mysql:/etc/postfix/mysql-virtual-alias-maps.cf</pre>
</li>
<li>按下<code style="color: #40aa53;">ESC</code>键并输入如下内容以保存并退出<br />
<pre class="crayon-plain-tag">&lt;span class=&quot;hljs-function_or_atom&quot;&gt;wq&lt;/span&gt;&lt;span class=&quot;hljs-exclamation_mark&quot;&gt;!&lt;/span&gt;</pre>
</li>
<li><strong>新建<code style="color: #40aa53;">/etc/postfix/mysql-virtual-mailbox-domains.cf</code>文件并输入如下内容：</strong><br />
<pre class="crayon-plain-tag">&lt;span class=&quot;hljs-variable&quot; style=&quot;color: #3e87e3;&quot;&gt;user =&lt;/span&gt; mailserver   
&lt;span class=&quot;hljs-variable&quot; style=&quot;color: #3e87e3;&quot;&gt;password =&lt;/span&gt; mailserver123  
&lt;span class=&quot;hljs-variable&quot; style=&quot;color: #3e87e3;&quot;&gt;hosts =&lt;/span&gt; &lt;span class=&quot;hljs-number&quot; style=&quot;color: #3387cc;&quot;&gt;127.0&lt;/span&gt;.&lt;span class=&quot;hljs-number&quot; style=&quot;color: #3387cc;&quot;&gt;0.1&lt;/span&gt;  
&lt;span class=&quot;hljs-variable&quot; style=&quot;color: #3e87e3;&quot;&gt;dbname =&lt;/span&gt; mailserver  
&lt;span class=&quot;hljs-variable&quot; style=&quot;color: #3e87e3;&quot;&gt;query =&lt;/span&gt; SELECT &lt;span class=&quot;hljs-number&quot; style=&quot;color: #3387cc;&quot;&gt;1&lt;/span&gt; FROM virtual_domains WHERE &lt;span class=&quot;hljs-variable&quot; style=&quot;color: #3e87e3;&quot;&gt;name=&lt;/span&gt;'%s'</pre>
</li>
<li>重启Postfix服务<br />
<pre class="crayon-plain-tag">&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;service&lt;/span&gt; postfix &lt;span class=&quot;hljs-literal&quot;&gt;restart&lt;/span&gt;</pre>
</li>
<li>测试上述内容是否正确，如果上述内容配置正确，则如下命令执行后返回结果应该为<code style="color: #40aa53;">1</code>：<br />
<pre class="crayon-plain-tag">postmap -&lt;span class=&quot;hljs-tag&quot; style=&quot;color: #89bdff;&quot;&gt;q&lt;/span&gt; mydomain&lt;span class=&quot;hljs-class&quot;&gt;.com&lt;/span&gt; mysql:/etc/postfix/mysql-virtual-mailbox-domains&lt;span class=&quot;hljs-class&quot;&gt;.cf&lt;/span&gt;</pre>
</li>
<li><strong>新建<code style="color: #40aa53;">/etc/postfix/mysql-virtual-mailbox-maps.cf</code>文件并输入如下内容：</strong><br />
<pre class="crayon-plain-tag">&lt;span class=&quot;hljs-variable&quot; style=&quot;color: #3e87e3;&quot;&gt;user =&lt;/span&gt; mailserver    
&lt;span class=&quot;hljs-variable&quot; style=&quot;color: #3e87e3;&quot;&gt;password =&lt;/span&gt; mailserver123  
&lt;span class=&quot;hljs-variable&quot; style=&quot;color: #3e87e3;&quot;&gt;hosts =&lt;/span&gt; &lt;span class=&quot;hljs-number&quot; style=&quot;color: #3387cc;&quot;&gt;127.0&lt;/span&gt;.&lt;span class=&quot;hljs-number&quot; style=&quot;color: #3387cc;&quot;&gt;0.1&lt;/span&gt;  
&lt;span class=&quot;hljs-variable&quot; style=&quot;color: #3e87e3;&quot;&gt;dbname =&lt;/span&gt; mailserver  
&lt;span class=&quot;hljs-variable&quot; style=&quot;color: #3e87e3;&quot;&gt;query =&lt;/span&gt; SELECT &lt;span class=&quot;hljs-number&quot; style=&quot;color: #3387cc;&quot;&gt;1&lt;/span&gt; FROM virtual_users WHERE &lt;span class=&quot;hljs-variable&quot; style=&quot;color: #3e87e3;&quot;&gt;email=&lt;/span&gt;'%s'</pre>
</li>
<li>重启Postfix服务<br />
<pre class="crayon-plain-tag">&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;service&lt;/span&gt; postfix &lt;span class=&quot;hljs-literal&quot;&gt;restart&lt;/span&gt;</pre>
</li>
<li>测试上述配置是否正确，如果上述内容配置正确，则如下命令执行后返回结果应该为<code style="color: #40aa53;">1</code>：<br />
<pre class="crayon-plain-tag">postmap -&lt;span class=&quot;hljs-tag&quot; style=&quot;color: #89bdff;&quot;&gt;q&lt;/span&gt; lisi@mydomain&lt;span class=&quot;hljs-class&quot;&gt;.com&lt;/span&gt; mysql:/etc/postfix/mysql-virtual-mailbox-maps&lt;span class=&quot;hljs-class&quot;&gt;.cf&lt;/span&gt;</pre>
</li>
<li><strong>新建<code style="color: #40aa53;">/etc/postfix/mysql-virtual-alias-maps.cf</code>文件并输入如下内容：</strong><br />
<pre class="crayon-plain-tag">&lt;span class=&quot;hljs-variable&quot; style=&quot;color: #3e87e3;&quot;&gt;user =&lt;/span&gt; mailserver    
&lt;span class=&quot;hljs-variable&quot; style=&quot;color: #3e87e3;&quot;&gt;password =&lt;/span&gt; mailserver123  
&lt;span class=&quot;hljs-variable&quot; style=&quot;color: #3e87e3;&quot;&gt;hosts =&lt;/span&gt; &lt;span class=&quot;hljs-number&quot; style=&quot;color: #3387cc;&quot;&gt;127.0&lt;/span&gt;.&lt;span class=&quot;hljs-number&quot; style=&quot;color: #3387cc;&quot;&gt;0.1&lt;/span&gt;  
&lt;span class=&quot;hljs-variable&quot; style=&quot;color: #3e87e3;&quot;&gt;dbname =&lt;/span&gt; mailserver  
&lt;span class=&quot;hljs-variable&quot; style=&quot;color: #3e87e3;&quot;&gt;query =&lt;/span&gt; SELECT destination FROM virtual_aliases WHERE &lt;span class=&quot;hljs-variable&quot; style=&quot;color: #3e87e3;&quot;&gt;source=&lt;/span&gt;'%s'</pre>
</li>
<li>重启Postfix服务<br />
<pre class="crayon-plain-tag">&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;service&lt;/span&gt; postfix &lt;span class=&quot;hljs-literal&quot;&gt;restart&lt;/span&gt;</pre>
</li>
<li>测试上述配置是否正确，如果上述配置正确，则如下命令执行后返回结果应该是之前添加的别名帐号：<br />
<pre class="crayon-plain-tag">postmap -&lt;span class=&quot;hljs-tag&quot; style=&quot;color: #89bdff;&quot;&gt;q&lt;/span&gt; all@mydomain&lt;span class=&quot;hljs-class&quot;&gt;.com&lt;/span&gt; mysql:/etc/postfix/mysql-virtual-alias-maps&lt;span class=&quot;hljs-class&quot;&gt;.cf&lt;/span&gt;</pre>
</li>
<li>使用vi编辑器打开<code style="color: #40aa53;">/etc/postfix/master.cf</code>文件「<strong>请注意修改之前先备份</strong>」，找到<code style="color: #40aa53;">submission</code>和<code style="color: #40aa53;">smtps</code>所在的两行，并将其注释去掉。这样做的目的是允许Postfix通过587和465端口发送邮件</li>
<li>重启Postfix服务<br />
<pre class="crayon-plain-tag">&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;service&lt;/span&gt; postfix &lt;span class=&quot;hljs-literal&quot;&gt;restart&lt;/span&gt;</pre>
</li>
</ol>
<p>搞定，Postfix服务器应该配置完成了。<strong>相信到这里的时候，已经吓走了90%以上的朋友，剩下的10%朋友们，你们是好样的。</strong></p>
<p><span id="OSC_h2_18"></span></p>
<h2>Dovecot安装及配置</h2>
<p>Dovecot在本例中充当IMAP、POP服务器的角色，同时它也将负责用户登录时用户身份的验证「Dovecot会将真正的验证工作交给MySQL处理」。因为使用SSL，Dovecot将会使用993「IMAP协议」及995「POP协议」与外界交流，若服务器有iptable之类的玩意儿，请开放相关端口。</p>
<p>这部分的内容配置起来相对简单，但是需要配置的文件繁多。大体上，我们需要配置如下的信息：</p>
<ol>
<li>开启Dovecot的IMAP、POP3、LMTP协议</li>
<li>告知Dovecot本地邮件的投档路径</li>
<li>连接Dovecot和MySQL数据库以验证用户身份</li>
<li>配置SSL加密相关信息</li>
</ol>
<p><span id="OSC_h3_19"></span></p>
<h3>Dovecot的安装</h3>
<p>通过如下命令安装Dovecot最新版：</p><pre class="crayon-plain-tag">apt-&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;get&lt;/span&gt; install dovecot-core dovecot-imapd dovecot-pop3d dovecot-lmtpd dovecot-mysql</pre><p><span id="OSC_h3_20"></span></p>
<h3>Dovecot的配置</h3>
<p>需要修改的配置文件有：</p>
<ul>
<li><code style="color: #40aa53;">/etc/dovecot/dovecot.conf</code> Dovecot的主配置文件</li>
<li><code style="color: #40aa53;">/etc/dovecot/conf.d/10-mail.conf</code> Dovecot将要操作的磁盘路径相关配置信息</li>
<li><code style="color: #40aa53;">/etc/dovecot/conf.d/10-auth.conf</code> 用户验证相关配置信息</li>
<li><code style="color: #40aa53;">/etc/dovecot/conf.d/auth-sql.conf.ext</code> SQL-Type验证相关配置信息</li>
<li><code style="color: #40aa53;">/etc/dovecot/dovecot-sql.conf.ext</code> Dovecot与数据库连接相关配置信息</li>
<li><code style="color: #40aa53;">/etc/dovecot/conf.d/10-master.conf</code> Dovecot本地socket相关配置信息</li>
<li><code style="color: #40aa53;">/etc/dovecot/conf.d/10-ssl.conf</code> 关于SSL的相关配置信息</li>
</ul>
<blockquote><p><strong>请注意：</strong><br />
在修改上述文件之前，请一定先做好备份以方便恢复</p></blockquote>
<p><span id="OSC_h3_21"></span></p>
<h3>修改<code style="color: #40aa53;">/etc/dovecot/dovecot.conf</code>文件</h3>
<p>使用vi编辑器打开<code style="color: #40aa53;">/etc/dovecot/dovecot.conf</code>文件并在文件种加入如下内容：</p><pre class="crayon-plain-tag">!include conf.d/&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;*&lt;/span&gt;.conf

&lt;span class=&quot;hljs-comment&quot; style=&quot;font-style: italic; color: #aeaeae;&quot;&gt;# Enable installed  &lt;/span&gt;
protocols!include_try /usr/share/dovecot/protocols.d/&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;*&lt;/span&gt;.protocol  
protocols = imap pop3 lmtp</pre><p>如果以上内容已经存在，只需要把该行的<code style="color: #40aa53;">#</code>号去掉即可<br />
上述内容大致的意思是：<strong>告诉Dovecot启用所有<code style="color: #40aa53;">.conf</code>文件；并开启Dovecot的imap、pop3、lmtp等相关协议使之正常工作</strong></p>
<p><span id="OSC_h3_22"></span></p>
<h3>修改<code style="color: #40aa53;">/etc/dovecot/conf.d/10-mail.conf</code>文件</h3>
<p>打开文件并找到<code style="color: #40aa53;">mail_location</code>相关信息，将其指定到本地磁盘的某个路径，这个路径将来会存放收到的邮件，如下所示：</p><pre class="crayon-plain-tag">mail_location = &lt;span class=&quot;hljs-string&quot; style=&quot;color: #65b042;&quot;&gt;maildir:&lt;/span&gt;&lt;span class=&quot;hljs-regexp&quot; style=&quot;color: #e9c062;&quot;&gt;/var/&lt;/span&gt;mail&lt;span class=&quot;hljs-regexp&quot; style=&quot;color: #e9c062;&quot;&gt;/vhosts/&lt;/span&gt;%d/%n</pre><p>同时，找到文件中<code style="color: #40aa53;">mail_privileged_group</code>相关信息并将起修改为：</p><pre class="crayon-plain-tag">&lt;span class=&quot;hljs-attribute&quot;&gt;mail_privileged_group &lt;/span&gt;=&lt;span class=&quot;hljs-string&quot; style=&quot;color: #65b042;&quot;&gt; mail
&lt;/span&gt;</pre><p>保存文件并退出</p>
<p>在命令行种输入如下内容以查看<code style="color: #40aa53;">/var/mail</code>路径的权限：</p><pre class="crayon-plain-tag">&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;ls&lt;/span&gt; -ld /&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;var&lt;/span&gt;/mail</pre><p>显示的内容大致应该是：</p><pre class="crayon-plain-tag">drwxrwsr-x &lt;span class=&quot;hljs-number&quot; style=&quot;color: #3387cc;&quot;&gt;2&lt;/span&gt; root mail &lt;span class=&quot;hljs-number&quot; style=&quot;color: #3387cc;&quot;&gt;4096&lt;/span&gt; May  &lt;span class=&quot;hljs-number&quot; style=&quot;color: #3387cc;&quot;&gt;11&lt;/span&gt; &lt;span class=&quot;hljs-number&quot; style=&quot;color: #3387cc;&quot;&gt;15&lt;/span&gt;:&lt;span class=&quot;hljs-number&quot; style=&quot;color: #3387cc;&quot;&gt;08&lt;/span&gt; /&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;var&lt;/span&gt;/mail</pre><p>创建<code style="color: #40aa53;">/var/mail/vhosts/</code>文件夹给每个需要启用的域名：</p><pre class="crayon-plain-tag">mkdir -&lt;span class=&quot;hljs-tag&quot; style=&quot;color: #89bdff;&quot;&gt;p&lt;/span&gt; /var/mail/vhosts/mydomain&lt;span class=&quot;hljs-class&quot;&gt;.com&lt;/span&gt;</pre><p>输入如下命令以新建<code style="color: #40aa53;">vmail</code>用户组及用户并赋权限</p><pre class="crayon-plain-tag">groupadd -&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;g&lt;/span&gt; 5000 vmail  
useradd -&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;g&lt;/span&gt; vmail -&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;u&lt;/span&gt; 5000 vmail -&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;d&lt;/span&gt; /&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;var&lt;/span&gt;/mail</pre><p>接下来修改一下<code style="color: #40aa53;">/var/mail/</code>目录的权限，使<code style="color: #40aa53;">vmail</code>能够访问：</p><pre class="crayon-plain-tag">chown -R &lt;span class=&quot;hljs-string&quot; style=&quot;color: #65b042;&quot;&gt;vmail:&lt;/span&gt;vmail &lt;span class=&quot;hljs-regexp&quot; style=&quot;color: #e9c062;&quot;&gt;/var/&lt;/span&gt;mail</pre><p><span id="OSC_h3_23"></span></p>
<h3>修改<code style="color: #40aa53;">/etc/dovecot/conf.d/10-auth.conf</code>文件</h3>
<p>找到文件中<code style="color: #40aa53;">disable_plaintext_auth</code>并取消注释</p><pre class="crayon-plain-tag">&lt;span class=&quot;hljs-setting&quot;&gt;disable_plaintext_auth = &lt;span class=&quot;hljs-value&quot;&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;yes&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;</pre><p>找到文件中<code style="color: #40aa53;">auth_mechanisms</code>并将其修改为如下值：</p><pre class="crayon-plain-tag">&lt;span class=&quot;hljs-attribute&quot;&gt;auth_mechanisms &lt;/span&gt;=&lt;span class=&quot;hljs-string&quot; style=&quot;color: #65b042;&quot;&gt; plain login
&lt;/span&gt;</pre><p>默认情况下，Dovecot是允许Ubuntu系统用户登录使用的，我们需要将其禁用。找到文件种如下内容并将其注释：</p><pre class="crayon-plain-tag">&lt;span class=&quot;hljs-shebang&quot; style=&quot;color: #89bdff;&quot;&gt;#!include auth-system.conf.ext&lt;/span&gt;</pre><p>开启Dovecot的MySQL支持，取消<code style="color: #40aa53;">!include auth-sql.conf.ext</code>的注释符号：</p><pre class="crayon-plain-tag">&lt;span class=&quot;hljs-shebang&quot; style=&quot;color: #89bdff;&quot;&gt;#!include auth-system.conf.ext  &lt;/span&gt;
!include auth-sql.conf.ext  
&lt;span class=&quot;hljs-shebang&quot; style=&quot;color: #89bdff;&quot;&gt;#!include auth-ldap.conf.ext  &lt;/span&gt;
&lt;span class=&quot;hljs-shebang&quot; style=&quot;color: #89bdff;&quot;&gt;#!include auth-passwdfile.conf.ext  &lt;/span&gt;
&lt;span class=&quot;hljs-shebang&quot; style=&quot;color: #89bdff;&quot;&gt;#!include auth-checkpassword.conf.ext  &lt;/span&gt;
&lt;span class=&quot;hljs-shebang&quot; style=&quot;color: #89bdff;&quot;&gt;#!include auth-vpopmail.conf.ext  &lt;/span&gt;
&lt;span class=&quot;hljs-shebang&quot; style=&quot;color: #89bdff;&quot;&gt;#!include auth-static.conf.ext&lt;/span&gt;</pre><p><span id="OSC_h3_24"></span></p>
<h3>修改<code style="color: #40aa53;">/etc/dovecot/conf.d/auth-sql.conf.ext</code>文件</h3>
<p>在文件中加入如下内容：</p><pre class="crayon-plain-tag">passdb {  
    &lt;span class=&quot;hljs-variable&quot; style=&quot;color: #3e87e3;&quot;&gt;driver =&lt;/span&gt; sql  
    &lt;span class=&quot;hljs-variable&quot; style=&quot;color: #3e87e3;&quot;&gt;args =&lt;/span&gt; /etc/dovecot/dovecot-sql.conf.ext  
}  

userdb {  
    &lt;span class=&quot;hljs-variable&quot; style=&quot;color: #3e87e3;&quot;&gt;driver =&lt;/span&gt; static  
    &lt;span class=&quot;hljs-variable&quot; style=&quot;color: #3e87e3;&quot;&gt;args =&lt;/span&gt; &lt;span class=&quot;hljs-variable&quot; style=&quot;color: #3e87e3;&quot;&gt;uid=&lt;/span&gt;vmail &lt;span class=&quot;hljs-variable&quot; style=&quot;color: #3e87e3;&quot;&gt;gid=&lt;/span&gt;vmail &lt;span class=&quot;hljs-variable&quot; style=&quot;color: #3e87e3;&quot;&gt;home=&lt;/span&gt;/var/mail/vhosts/%d/%n  
}</pre><p><span id="OSC_h3_25"></span></p>
<h3>修改<code style="color: #40aa53;">/etc/dovecot/dovecot-sql.conf.ext</code>文件</h3>
<p>取消文件中<code style="color: #40aa53;">driver</code>行的注释，并将其修改为如下：</p><pre class="crayon-plain-tag">&lt;span class=&quot;hljs-attribute&quot;&gt;driver &lt;/span&gt;=&lt;span class=&quot;hljs-string&quot; style=&quot;color: #65b042;&quot;&gt; mysql
&lt;/span&gt;</pre><p>取消文件中<code style="color: #40aa53;">connect</code>行的注释，并将其修改为如下：</p><pre class="crayon-plain-tag">&lt;span class=&quot;hljs-variable&quot; style=&quot;color: #3e87e3;&quot;&gt;connect =&lt;/span&gt; &lt;span class=&quot;hljs-variable&quot; style=&quot;color: #3e87e3;&quot;&gt;host=&lt;/span&gt;&lt;span class=&quot;hljs-number&quot; style=&quot;color: #3387cc;&quot;&gt;127.0&lt;/span&gt;.&lt;span class=&quot;hljs-number&quot; style=&quot;color: #3387cc;&quot;&gt;0.1&lt;/span&gt; &lt;span class=&quot;hljs-variable&quot; style=&quot;color: #3e87e3;&quot;&gt;dbname=&lt;/span&gt;mailserver &lt;span class=&quot;hljs-variable&quot; style=&quot;color: #3e87e3;&quot;&gt;user=&lt;/span&gt;mailserver &lt;span class=&quot;hljs-variable&quot; style=&quot;color: #3e87e3;&quot;&gt;password=&lt;/span&gt;mailserver123</pre><p>取消文件中<code style="color: #40aa53;">default_pass_scheme</code>行的注释，并将其修改为如下：</p><pre class="crayon-plain-tag">&lt;span class=&quot;hljs-attribute&quot;&gt;default_pass_scheme &lt;/span&gt;=&lt;span class=&quot;hljs-string&quot; style=&quot;color: #65b042;&quot;&gt; SHA512-CRYPT
&lt;/span&gt;</pre><p>取消文件中<code style="color: #40aa53;">password_query</code>行的注释，并将起修改为如下：</p><pre class="crayon-plain-tag">password_query = &lt;span class=&quot;hljs-operator&quot;&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;SELECT&lt;/span&gt; email &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;user&lt;/span&gt;, &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;password&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;FROM&lt;/span&gt; virtual_users &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;WHERE&lt;/span&gt; email=&lt;span class=&quot;hljs-string&quot; style=&quot;color: #65b042;&quot;&gt;'%u'&lt;/span&gt;;&lt;/span&gt;</pre><p>保存退出</p>
<p>在命令行种输入如下内容以修改目录权限：</p><pre class="crayon-plain-tag">chown -R &lt;span class=&quot;hljs-string&quot; style=&quot;color: #65b042;&quot;&gt;vmail:&lt;/span&gt;dovecot &lt;span class=&quot;hljs-regexp&quot; style=&quot;color: #e9c062;&quot;&gt;/etc/&lt;/span&gt;dovecot

chmod -R o-rwx &lt;span class=&quot;hljs-regexp&quot; style=&quot;color: #e9c062;&quot;&gt;/etc/&lt;/span&gt;dovecot</pre><p><span id="OSC_h3_26"></span></p>
<h3>修改<code style="color: #40aa53;">/etc/dovecot/conf.d/10-master.conf</code>文件</h3>
<p>打开文件做如下修改「通过将端口设置为0，以禁用非SSL加密的IMAP和POP3协议」：</p><pre class="crayon-plain-tag">service imap-login {  
    inet_listener imap {  
        port = &lt;span class=&quot;hljs-number&quot; style=&quot;color: #3387cc;&quot;&gt;0&lt;/span&gt;   
    }  
    &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;...&lt;/span&gt;  
}  

service pop3-login {  
    inet_listener pop3 {  
        port = &lt;span class=&quot;hljs-number&quot; style=&quot;color: #3387cc;&quot;&gt;0&lt;/span&gt;  
    }  
    &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;...&lt;/span&gt;  
}</pre><p>找到文件中的<code style="color: #40aa53;">service lmtp</code>并将其修改如下：</p><pre class="crayon-plain-tag">&lt;span class=&quot;hljs-title&quot; style=&quot;color: #e28964;&quot;&gt;service&lt;/span&gt; lmtp {  
        &lt;span class=&quot;hljs-title&quot; style=&quot;color: #e28964;&quot;&gt;unix_listener&lt;/span&gt; /var/spool/postfix/private/dovecot-lmtp {  
        &lt;span class=&quot;hljs-title&quot; style=&quot;color: #e28964;&quot;&gt;mode&lt;/span&gt; = &lt;span class=&quot;hljs-number&quot; style=&quot;color: #3387cc;&quot;&gt;0600&lt;/span&gt;  
        user = postfix  
        group = postfix  
  }  

  &lt;span class=&quot;hljs-comment&quot; style=&quot;font-style: italic; color: #aeaeae;&quot;&gt;# Create inet listener only if you can't use the above UNIX socket  &lt;/span&gt;
  &lt;span class=&quot;hljs-comment&quot; style=&quot;font-style: italic; color: #aeaeae;&quot;&gt;#inet_listener lmtp {  &lt;/span&gt;
        &lt;span class=&quot;hljs-comment&quot; style=&quot;font-style: italic; color: #aeaeae;&quot;&gt;#Avoid making LMTP visible for the entire internet  &lt;/span&gt;
        &lt;span class=&quot;hljs-comment&quot; style=&quot;font-style: italic; color: #aeaeae;&quot;&gt;#address =  &lt;/span&gt;
        &lt;span class=&quot;hljs-comment&quot; style=&quot;font-style: italic; color: #aeaeae;&quot;&gt;#port =  &lt;/span&gt;
        &lt;span class=&quot;hljs-comment&quot; style=&quot;font-style: italic; color: #aeaeae;&quot;&gt;#}  &lt;/span&gt;
 }</pre><p>找到文件中<code style="color: #40aa53;">service auth</code>并将其内容修改如下：</p><pre class="crayon-plain-tag">service auth {  
    &lt;span class=&quot;hljs-comment&quot; style=&quot;font-style: italic; color: #aeaeae;&quot;&gt;# auth_socket_path points to this userdb socket by default. It's typically  &lt;/span&gt;
    &lt;span class=&quot;hljs-comment&quot; style=&quot;font-style: italic; color: #aeaeae;&quot;&gt;# used by dovecot-lda, doveadm, possibly imap process, etc. Its default  &lt;/span&gt;
    &lt;span class=&quot;hljs-comment&quot; style=&quot;font-style: italic; color: #aeaeae;&quot;&gt;# permissions make it readable only by root, but you may need to relax these  &lt;/span&gt;
    &lt;span class=&quot;hljs-comment&quot; style=&quot;font-style: italic; color: #aeaeae;&quot;&gt;# permissions. Users that have access to this socket are able to get a list  &lt;/span&gt;
    &lt;span class=&quot;hljs-comment&quot; style=&quot;font-style: italic; color: #aeaeae;&quot;&gt;# of all usernames and get results of everyone's userdb lookups.  &lt;/span&gt;

    unix_listener /var/spool/postfix/private/auth {  
            mode = 0666  
            &lt;span class=&quot;hljs-built_in&quot;&gt;user&lt;/span&gt; = postfix  
            group = postfix  
    }  

    unix_listener auth-userdb {  
            mode = 0600  
            &lt;span class=&quot;hljs-built_in&quot;&gt;user&lt;/span&gt; = vmail  
            &lt;span class=&quot;hljs-comment&quot; style=&quot;font-style: italic; color: #aeaeae;&quot;&gt;#group =  &lt;/span&gt;
    }  

    &lt;span class=&quot;hljs-comment&quot; style=&quot;font-style: italic; color: #aeaeae;&quot;&gt;# Postfix smtp-auth  &lt;/span&gt;
    &lt;span class=&quot;hljs-comment&quot; style=&quot;font-style: italic; color: #aeaeae;&quot;&gt;#unix_listener /var/spool/postfix/private/auth {  &lt;/span&gt;
    &lt;span class=&quot;hljs-comment&quot; style=&quot;font-style: italic; color: #aeaeae;&quot;&gt;#       mode = 0666  &lt;/span&gt;
    &lt;span class=&quot;hljs-comment&quot; style=&quot;font-style: italic; color: #aeaeae;&quot;&gt;#}  &lt;/span&gt;

    &lt;span class=&quot;hljs-comment&quot; style=&quot;font-style: italic; color: #aeaeae;&quot;&gt;# Auth process is run as this user.  &lt;/span&gt;
    &lt;span class=&quot;hljs-built_in&quot;&gt;user&lt;/span&gt; = dovecot  
}</pre><p>找到文件中<code style="color: #40aa53;">service auth-worker</code>内容并修改如下：</p><pre class="crayon-plain-tag">service auth-worker {  
    &lt;span class=&quot;hljs-comment&quot; style=&quot;font-style: italic; color: #aeaeae;&quot;&gt;# Auth worker process is run as root by default, so that it can access  &lt;/span&gt;
    &lt;span class=&quot;hljs-comment&quot; style=&quot;font-style: italic; color: #aeaeae;&quot;&gt;# /etc/shadow. If this isn't necessary, the user should be changed to  &lt;/span&gt;
    &lt;span class=&quot;hljs-comment&quot; style=&quot;font-style: italic; color: #aeaeae;&quot;&gt;# $default_internal_user.  &lt;/span&gt;

    &lt;span class=&quot;hljs-built_in&quot;&gt;user&lt;/span&gt; = vmail  
}</pre><p><span id="OSC_h3_27"></span></p>
<h3>修改<code style="color: #40aa53;">/etc/dovecot/conf.d/10-ssl.conf</code>文件</h3>
<p>找到文件中<code style="color: #40aa53;">ssl_cert</code>并修改内容如下「请确保dovecot的pem文件已经存在，如果大家使用了自己的SSL文件，请将如下内容修改为相应的路径」：</p><pre class="crayon-plain-tag">ssl_cert = &amp;lt;/etc/dovecot/dovecot&lt;span class=&quot;hljs-class&quot;&gt;.pem&lt;/span&gt;  
ssl_key = &amp;lt;/etc/dovecot/private/dovecot&lt;span class=&quot;hljs-class&quot;&gt;.pem&lt;/span&gt;</pre><p>强制用户使用SSL加密：</p><pre class="crayon-plain-tag">&lt;span class=&quot;hljs-attribute&quot;&gt;ssl &lt;/span&gt;=&lt;span class=&quot;hljs-string&quot; style=&quot;color: #65b042;&quot;&gt; required
&lt;/span&gt;</pre><p>重新启动Dovecot服务：</p><pre class="crayon-plain-tag">&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: #e28964;&quot;&gt;service&lt;/span&gt; dovecot &lt;span class=&quot;hljs-literal&quot;&gt;restart&lt;/span&gt;</pre><p><span id="OSC_h2_28"></span></p>
<h2>测试邮件服务器是否正常</h2>
<p>设置一个帐号，可以向MySQL对应的表中插入数据，接下来使用邮件客户端来测试一下。推荐使用<code style="color: #40aa53;">Thunderbird</code>邮件客户端或者<code style="color: #40aa53;">Foxmail</code>客户端等。请注意以下内容：</p>
<ul>
<li>邮箱的全称「包括后面的@mydomain.com」将作为用户名</li>
<li>邮箱密码是MySQL数据库种对应邮箱的密码</li>
<li>服务器相关接口是否全部开放？993、995、25等</li>
<li>邮件收发的所有协议，包括IMAP、POP3、SMTP全部都需要开启SSL加密</li>
</ul>
<p>配置好客户端之后即可连接获取、发送邮件。</p>
</div>
]]></content:encoded>
			<wfw:commentRss>https://www.softwareace.cn/?feed=rss2&#038;p=1325</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
