<?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:trackback="http://madskills.com/public/xml/rss/module/trackback/">
<channel>
	<title>flyinweb's blog</title>
	<link>http://www.517sou.net/</link>
	<language>zh-CN</language>
	<webMaster>shanyiwan@msn.com(flyinweb)</webMaster>
	<pubDate>Mon, 15 Jun 2009 19:31:16 GMT</pubDate>
	<copyright>Copyright 2007-2009. All rights reserved.</copyright>
	<generator>Bitrac Free Version</generator>
	<description>桃李无言，下自成蹊</description>
	<image>
		<title>flyinweb&apos;s blog</title>
		<url>http://www.517sou.net/Client/Banner.gif</url>
		<link>http://www.517sou.net/</link>
		<description>桃李无言，下自成蹊</description>
	</image>
	<item>
		<link>http://www.517sou.net/Article/vCenter-Converter-Network-Error.aspx</link>
		<title>VMware vCenter Converter导入计算机时出错</title>
		<author>shanyiwan@live.com(flyinweb)</author>
		<category>云计算与虚拟化</category>
		<pubDate>Fri, 03 Feb 2012 03:20:11 GMT</pubDate>
		<description>&lt;p&gt;VMware vCenter Converter导入计算机时出错，对话框内容如下：&lt;/p&gt;&lt;p&gt;---------------------------&lt;br /&gt;VMware vCenter Converter&lt;br /&gt;---------------------------&lt;br /&gt;出现错误。此错误的原因可能由网络连接故障所致。&lt;br /&gt;向导将立即关闭。&lt;br /&gt;请检查网络连接并重试。&lt;br /&gt;---------------------------&lt;br /&gt;确定&amp;nbsp;&amp;nbsp; &lt;br /&gt;---------------------------&lt;/p&gt;&lt;p&gt;解决办法：&lt;/p&gt;&lt;p&gt;重启以下服务：&lt;/p&gt;&lt;p&gt;&lt;li&gt;VMware vCenter Converter Integrated Server&lt;/li&gt;&lt;li&gt;VMware vCenter Converter Integrated Worker&lt;/li&gt;&lt;/p&gt;</description>
		<guid>http://www.517sou.net/Article/vCenter-Converter-Network-Error.aspx</guid>
		<trackback:ping>http://www.517sou.net/Article/757/Trackback.ashx</trackback:ping>
		<comments>http://www.517sou.net/Article/vCenter-Converter-Network-Error.aspx#CommentPostAnchor</comments>
		<wfw:commentRss>http://www.517sou.net/Article/757/Feeds.ashx</wfw:commentRss>
	</item>
	<item>
		<link>http://www.517sou.net/Article/mysql-mmm-Installation-Guide.aspx</link>
		<title>mysql-mmm Installation Guide</title>
		<author>shanyiwan@live.com(flyinweb)</author>
		<category>数据库技术</category>
		<pubDate>Tue, 31 Jan 2012 08:19:48 GMT</pubDate>
		<description>&lt;p&gt;A basic installation contains at least 2 database servers and 1 monitoring server. In this guide, I used 5 servers with Debian Lenny (5.0)&lt;/p&gt;&lt;div class=&quot;table sectionedit2&quot;&gt;&lt;table class=&quot;inline&quot;&gt;&lt;tbody&gt;&lt;tr class=&quot;row0&quot;&gt;&lt;th class=&quot;col0 leftalign&quot;&gt;function&lt;/th&gt;&lt;th class=&quot;col1 leftalign&quot;&gt;ip&lt;/th&gt;&lt;th class=&quot;col2&quot;&gt;hostname&lt;/th&gt;&lt;th class=&quot;col3&quot;&gt;server id&lt;/th&gt;&lt;/tr&gt;&lt;tr class=&quot;row1&quot;&gt;&lt;td class=&quot;col0&quot;&gt;monitoring host&lt;/td&gt;&lt;td class=&quot;col1&quot;&gt;192.168.0.10&lt;/td&gt;&lt;td class=&quot;col2 leftalign&quot;&gt;mon&lt;/td&gt;&lt;td class=&quot;col3 centeralign&quot;&gt;-&lt;/td&gt;&lt;/tr&gt;&lt;tr class=&quot;row2&quot;&gt;&lt;td class=&quot;col0 leftalign&quot;&gt;master 1&lt;/td&gt;&lt;td class=&quot;col1&quot;&gt;192.168.0.11&lt;/td&gt;&lt;td class=&quot;col2 leftalign&quot;&gt;db1&lt;/td&gt;&lt;td class=&quot;col3 centeralign&quot;&gt;1&lt;/td&gt;&lt;/tr&gt;&lt;tr class=&quot;row3&quot;&gt;&lt;td class=&quot;col0 leftalign&quot;&gt;master 2&lt;/td&gt;&lt;td class=&quot;col1&quot;&gt;192.168.0.12&lt;/td&gt;&lt;td class=&quot;col2 leftalign&quot;&gt;db2&lt;/td&gt;&lt;td class=&quot;col3 centeralign&quot;&gt;2&lt;/td&gt;&lt;/tr&gt;&lt;tr class=&quot;row4&quot;&gt;&lt;td class=&quot;col0 leftalign&quot;&gt;slave 1&lt;/td&gt;&lt;td class=&quot;col1&quot;&gt;192.168.0.13&lt;/td&gt;&lt;td class=&quot;col2 leftalign&quot;&gt;db3&lt;/td&gt;&lt;td class=&quot;col3 centeralign&quot;&gt;3&lt;/td&gt;&lt;/tr&gt;&lt;tr class=&quot;row5&quot;&gt;&lt;td class=&quot;col0 leftalign&quot;&gt;slave 2&lt;/td&gt;&lt;td class=&quot;col1&quot;&gt;192.168.0.14&lt;/td&gt;&lt;td class=&quot;col2 leftalign&quot;&gt;db4&lt;/td&gt;&lt;td class=&quot;col3 centeralign&quot;&gt;4&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p&gt;I used the following &lt;em&gt;virtual&lt;/em&gt; IPs. They will be distributed across the hosts by &lt;acronym title=&quot;MySQL Multi-Master Replication Manager&quot;&gt;MMM&lt;/acronym&gt;.&lt;/p&gt;&lt;div class=&quot;table sectionedit3&quot;&gt;&lt;table class=&quot;inline&quot;&gt;&lt;tbody&gt;&lt;tr class=&quot;row0&quot;&gt;&lt;th class=&quot;col0 leftalign&quot;&gt;ip&lt;/th&gt;&lt;th class=&quot;col1 leftalign&quot;&gt;role&lt;/th&gt;&lt;th class=&quot;col2&quot;&gt;description&lt;/th&gt;&lt;/tr&gt;&lt;tr class=&quot;row1&quot;&gt;&lt;td class=&quot;col0&quot;&gt;192.168.0.100&lt;/td&gt;&lt;td class=&quot;col1&quot;&gt;writer&lt;/td&gt;&lt;td class=&quot;col2&quot;&gt;Your application should connect to this IP for write queries.&lt;/td&gt;&lt;/tr&gt;&lt;tr class=&quot;row2&quot;&gt;&lt;td class=&quot;col0&quot;&gt;192.168.0.101&lt;/td&gt;&lt;td class=&quot;col1&quot;&gt;reader&lt;/td&gt;&lt;td class=&quot;col2&quot; rowspan=&quot;4&quot;&gt;Your application should connect to one of these four IPs for read queries&lt;/td&gt;&lt;/tr&gt;&lt;tr class=&quot;row3&quot;&gt;&lt;td class=&quot;col0&quot;&gt;192.168.0.102&lt;/td&gt;&lt;td class=&quot;col1&quot;&gt;reader&lt;/td&gt;&lt;/tr&gt;&lt;tr class=&quot;row4&quot;&gt;&lt;td class=&quot;col0&quot;&gt;192.168.0.103&lt;/td&gt;&lt;td class=&quot;col1&quot;&gt;reader&lt;/td&gt;&lt;/tr&gt;&lt;tr class=&quot;row5&quot;&gt;&lt;td class=&quot;col0&quot;&gt;192.168.0.104&lt;/td&gt;&lt;td class=&quot;col1&quot;&gt;reader&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;h2 class=&quot;sectionedit4&quot;&gt;&lt;a id=&quot;basic_configuration_of_master_1&quot; name=&quot;basic_configuration_of_master_1&quot;&gt;&lt;font color=&quot;#000000&quot;&gt;Basic &lt;span class=&quot;search_hit&quot;&gt;configuration&lt;/span&gt; of master 1&lt;/font&gt;&lt;/a&gt;&lt;/h2&gt;&lt;div class=&quot;level2&quot;&gt;&lt;p&gt;First we install MySQL on all hosts:&lt;/p&gt;&lt;pre class=&quot;code&quot;&gt;
aptitude install mysql-server&lt;/pre&gt;&lt;p&gt;Then we edit the &lt;span class=&quot;search_hit&quot;&gt;configuration&lt;/span&gt; file /etc/mysql/my.cnf and add the following lines - be sure to use different server ids for all hosts:&lt;/p&gt;&lt;pre class=&quot;code&quot;&gt;
server_id           = 1
log_bin             = /var/log/mysql/mysql-bin.log 
log_bin_index       = /var/log/mysql/mysql-bin.log.index 
relay_log           = /var/log/mysql/mysql-relay-bin 
relay_log_index     = /var/log/mysql/mysql-relay-bin.index 
expire_logs_days    = 10 
max_binlog_size     = 100M 
log_slave_updates   = 1&lt;/pre&gt;&lt;p&gt;Then remove the following entry:&lt;/p&gt;&lt;pre class=&quot;code&quot;&gt;
bind-address = 127.0.0.1&lt;/pre&gt;&lt;p&gt;Do not bind of any specific IP, use 0.0.0.0 instead:&lt;/p&gt;&lt;pre class=&quot;code&quot;&gt;
bind-address = 0.0.0.0&lt;/pre&gt;&lt;p&gt;Afterwards we need to restart MySQL for our changes to take effect:&lt;/p&gt;&lt;pre class=&quot;code&quot;&gt;
/etc/init.d/mysql restart&lt;/pre&gt;&lt;/div&gt;&lt;h2 class=&quot;sectionedit5&quot;&gt;&lt;a id=&quot;create_users&quot; name=&quot;create_users&quot;&gt;&lt;font color=&quot;#000000&quot;&gt;Create users&lt;/font&gt;&lt;/a&gt;&lt;/h2&gt;&lt;div class=&quot;level2&quot;&gt;&lt;p&gt;Now we can create the required users. We&apos;ll need 3 different users:&lt;/p&gt;&lt;div class=&quot;table sectionedit6&quot;&gt;&lt;table class=&quot;inline&quot;&gt;&lt;tbody&gt;&lt;tr class=&quot;row0&quot;&gt;&lt;th class=&quot;col0 leftalign&quot;&gt;function&lt;/th&gt;&lt;th class=&quot;col1&quot;&gt;description&lt;/th&gt;&lt;th class=&quot;col2&quot;&gt;privileges&lt;/th&gt;&lt;/tr&gt;&lt;tr class=&quot;row1&quot;&gt;&lt;td class=&quot;col0 leftalign&quot;&gt;monitor user&lt;/td&gt;&lt;td class=&quot;col1&quot;&gt;used by the mmm monitor to check the health of the MySQL servers&lt;/td&gt;&lt;td class=&quot;col2&quot;&gt;REPLICATION CLIENT&lt;/td&gt;&lt;/tr&gt;&lt;tr class=&quot;row2&quot;&gt;&lt;td class=&quot;col0 leftalign&quot;&gt;agent user&lt;/td&gt;&lt;td class=&quot;col1&quot;&gt;used by the mmm agent to change read-only mode, replication master, etc.&lt;/td&gt;&lt;td class=&quot;col2&quot;&gt;SUPER, REPLICATION CLIENT, PROCESS&lt;/td&gt;&lt;/tr&gt;&lt;tr class=&quot;row3&quot;&gt;&lt;td class=&quot;col0&quot;&gt;relication user&lt;/td&gt;&lt;td class=&quot;col1&quot;&gt;used for replication&lt;/td&gt;&lt;td class=&quot;col2&quot;&gt;REPLICATION SLAVE&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;pre class=&quot;code&quot;&gt;
GRANT REPLICATION CLIENT                 ON *.* TO &apos;mmm_monitor&apos;@&apos;192.168.0.%&apos; IDENTIFIED BY &apos;monitor_password&apos;;
GRANT SUPER, REPLICATION CLIENT, PROCESS ON *.* TO &apos;mmm_agent&apos;@&apos;192.168.0.%&apos;   IDENTIFIED BY &apos;agent_password&apos;;
GRANT REPLICATION SLAVE                  ON *.* TO &apos;replication&apos;@&apos;192.168.0.%&apos; IDENTIFIED BY &apos;replication_password&apos;;&lt;/pre&gt;&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; We could be more restrictive here regarding the hosts from which the users are allowed to connect: mmm_monitor is used from 192.168.0.10. mmm_agent and replication are used from 192.168.0.11 - 192.168.0.14.&lt;/p&gt;&lt;/div&gt;&lt;h2 class=&quot;sectionedit7&quot;&gt;&lt;a id=&quot;synchronisation_of_data_between_both_databases&quot; name=&quot;synchronisation_of_data_between_both_databases&quot;&gt;&lt;font color=&quot;#000000&quot;&gt;Synchronisation of data between both databases&lt;/font&gt;&lt;/a&gt;&lt;/h2&gt;&lt;div class=&quot;level2&quot;&gt;&lt;p&gt;I&apos;ll assume that db1 contains the correct data. If you have an empty database, you still have to syncronize the accounts we have just created.&lt;/p&gt;&lt;p&gt;First make sure that no one is altering the data while we create a backup.&lt;/p&gt;&lt;pre class=&quot;code&quot;&gt;
(db1) mysql&amp;gt; FLUSH TABLES WITH READ LOCK;&lt;/pre&gt;&lt;p&gt;Then get the current position in the binary-log. We will need this values when we setup the replication on db2, db3 and db4.&lt;/p&gt;&lt;pre class=&quot;code&quot;&gt;
(db1) mysql&amp;gt; SHOW MASTER STATUS;
+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+ 
| mysql-bin.000002 |      374 |              |                  | 
+------------------+----------+--------------+------------------+ 
1 row in set (0.00 sec) &lt;/pre&gt;&lt;p&gt;&lt;strong&gt;DON&apos;T CLOSE this mysql-shell.&lt;/strong&gt; If you close it, the database lock will be removed. Open a second console and type:&lt;/p&gt;&lt;pre class=&quot;code&quot;&gt;
db1$ mysqldump -u root -p --all-databases &amp;gt; /tmp/database-backup.sql&lt;/pre&gt;&lt;p&gt;Now we can remove the database-lock. Go to the first shell:&lt;/p&gt;&lt;pre class=&quot;code&quot;&gt;
(db1) mysql&amp;gt; UNLOCK TABLES;&lt;/pre&gt;&lt;p&gt;Copy the database backup to db2, db3 and db4.&lt;/p&gt;&lt;pre class=&quot;code&quot;&gt;
db1$ scp /tmp/database-backup.sql &amp;lt;user&amp;gt;@192.168.0.12:/tmp
db1$ scp /tmp/database-backup.sql &amp;lt;user&amp;gt;@192.168.0.13:/tmp
db1$ scp /tmp/database-backup.sql &amp;lt;user&amp;gt;@192.168.0.14:/tmp&lt;/pre&gt;&lt;p&gt;Then import this into db2, db3 and db4:&lt;/p&gt;&lt;pre class=&quot;code&quot;&gt;
db2$ mysql -u root -p &amp;lt; /tmp/database-backup.sql
db3$ mysql -u root -p &amp;lt; /tmp/database-backup.sql
db4$ mysql -u root -p &amp;lt; /tmp/database-backup.sql&lt;/pre&gt;&lt;p&gt;Then flush the privileges on db2, db3 and db4. We have altered the user-table and mysql has to reread this table.&lt;/p&gt;&lt;pre class=&quot;code&quot;&gt;
(db2) mysql&amp;gt; FLUSH PRIVILEGES;
(db3) mysql&amp;gt; FLUSH PRIVILEGES;
(db4) mysql&amp;gt; FLUSH PRIVILEGES;&lt;/pre&gt;&lt;p&gt;On debian and ubuntu, copy the passwords in /etc/mysql/debian.cnf from db1 to db2, db3 and db4. This password is used for starting and stopping mysql.&lt;/p&gt;&lt;p&gt;Both databases now contain the same data. We now can setup replication to keep it that way.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Import just only &lt;em class=&quot;u&quot;&gt;add&lt;/em&gt; records from dump file. You should &lt;a class=&quot;urlextern&quot; title=&quot;http://dev.mysql.com/doc/refman/5.0/en/drop-database.html&quot; href=&quot;http://dev.mysql.com/doc/refman/5.0/en/drop-database.html&quot; rel=&quot;nofollow&quot; target=&quot;_blank&quot;&gt;&lt;u&gt;&lt;font color=&quot;#0066cc&quot;&gt;drop&lt;/font&gt;&lt;/u&gt;&lt;/a&gt; all databases before import dump file.&lt;/p&gt;&lt;/div&gt;&lt;h2 class=&quot;sectionedit8&quot;&gt;&lt;a id=&quot;setup_replication&quot; name=&quot;setup_replication&quot;&gt;&lt;font color=&quot;#000000&quot;&gt;Setup replication&lt;/font&gt;&lt;/a&gt;&lt;/h2&gt;&lt;div class=&quot;level2&quot;&gt;&lt;p&gt;Configure replication on db2, db3 and db4 with the following commands:&lt;/p&gt;&lt;pre class=&quot;code&quot;&gt;
(db2) mysql&amp;gt; CHANGE MASTER TO master_host=&apos;192.168.0.11&apos;, master_port=3306, master_user=&apos;replication&apos;, 
              master_password=&apos;replication_password&apos;, master_log_file=&apos;&amp;lt;file&amp;gt;&apos;, master_log_pos=&amp;lt;position&amp;gt;;
(db3) mysql&amp;gt; CHANGE MASTER TO master_host=&apos;192.168.0.11&apos;, master_port=3306, master_user=&apos;replication&apos;, 
              master_password=&apos;replication_password&apos;, master_log_file=&apos;&amp;lt;file&amp;gt;&apos;, master_log_pos=&amp;lt;position&amp;gt;;
(db4) mysql&amp;gt; CHANGE MASTER TO master_host=&apos;192.168.0.11&apos;, master_port=3306, master_user=&apos;replication&apos;, 
              master_password=&apos;replication_password&apos;, master_log_file=&apos;&amp;lt;file&amp;gt;&apos;, master_log_pos=&amp;lt;position&amp;gt;;&lt;/pre&gt;&lt;p&gt;Please insert the values return by “show master status” on db1 at the &amp;lt;file&amp;gt; and &amp;lt;position&amp;gt; tags.&lt;/p&gt;&lt;p&gt;Start the slave-process on all 3 hosts:&lt;/p&gt;&lt;pre class=&quot;code&quot;&gt;
(db2) mysql&amp;gt; START SLAVE;
(db3) mysql&amp;gt; START SLAVE;
(db4) mysql&amp;gt; START SLAVE;&lt;/pre&gt;&lt;p&gt;Now check if the replication is running correctly on all hosts:&lt;/p&gt;&lt;pre class=&quot;code&quot;&gt;
(db2) mysql&amp;gt; SHOW SLAVE STATUS\G
*************************** 1. row *************************** 
             Slave_IO_State: Waiting for master to send event 
                Master_Host: 192.168.0.11
                Master_User: replication
                Master_Port: 3306 
              Connect_Retry: 60 
…
(db3) mysql&amp;gt; SHOW SLAVE STATUS\G
*************************** 1. row *************************** 
             Slave_IO_State: Waiting for master to send event 
                Master_Host: 192.168.0.11
                Master_User: replication
                Master_Port: 3306 
              Connect_Retry: 60 
…
(db4) mysql&amp;gt; SHOW SLAVE STATUS\G
*************************** 1. row *************************** 
             Slave_IO_State: Waiting for master to send event 
                Master_Host: 192.168.0.11
                Master_User: replication
                Master_Port: 3306 
              Connect_Retry: 60 
…&lt;/pre&gt;&lt;p&gt;Now we have to make db1 replicate from db2. First we have to determine the values for master_log_file and master_log_pos:&lt;/p&gt;&lt;pre class=&quot;code&quot;&gt;
(db2) mysql&amp;gt; SHOW MASTER STATUS;
+------------------+----------+--------------+------------------+ 
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | 
+------------------+----------+--------------+------------------+ 
| mysql-bin.000001 |       98 |              |                  |
+------------------+----------+--------------+------------------+ 
1 row in set (0.00 sec) &lt;/pre&gt;&lt;p&gt;Now we configure replication on db1 with the following command:&lt;/p&gt;&lt;pre class=&quot;code&quot;&gt;
(db1) mysql&amp;gt; CHANGE MASTER TO master_host = &apos;192.168.0.12&apos;, master_port=3306, master_user=&apos;replication&apos;,
              master_password=&apos;replication_password&apos;, master_log_file=&apos;&amp;lt;file&amp;gt;&apos;, master_log_pos=&amp;lt;position&amp;gt;;&lt;/pre&gt;&lt;p&gt;Now insert the values return by “show master status” on db2 at the &amp;lt;file&amp;gt; and &amp;lt;position&amp;gt; tags.&lt;/p&gt;&lt;p&gt;Start the slave-process:&lt;/p&gt;&lt;pre class=&quot;code&quot;&gt;
(db1) mysql&amp;gt; START SLAVE;&lt;/pre&gt;&lt;p&gt;Now check if the replication is running correctly on db1:&lt;/p&gt;&lt;pre class=&quot;code&quot;&gt;
(db1) mysql&amp;gt; SHOW SLAVE STATUS\G
*************************** 1. row *************************** 
             Slave_IO_State: Waiting for master to send event 
                Master_Host: 192.168.0.12
                Master_User: &amp;lt;replication&amp;gt;
                Master_Port: 3306 
              Connect_Retry: 60 
…&lt;/pre&gt;&lt;p&gt;Replication between the nodes should now be complete. Try it by inserting some data into both db1 and db2 and check that the data will appear on all other nodes.&lt;/p&gt;&lt;/div&gt;&lt;h2 class=&quot;sectionedit9&quot;&gt;&lt;a id=&quot;install_mmm&quot; name=&quot;install_mmm&quot;&gt;&lt;font color=&quot;#000000&quot;&gt;Install MMM&lt;/font&gt;&lt;/a&gt;&lt;/h2&gt;&lt;h3 class=&quot;sectionedit10&quot;&gt;&lt;a id=&quot;create_user&quot; name=&quot;create_user&quot;&gt;&lt;font color=&quot;#000000&quot;&gt;Create user&lt;/font&gt;&lt;/a&gt;&lt;/h3&gt;&lt;div class=&quot;level3&quot;&gt;&lt;p&gt;Optional: Create user that will be the owner of the &lt;acronym title=&quot;MySQL Multi-Master Replication Manager&quot;&gt;MMM&lt;/acronym&gt; scripts and &lt;span class=&quot;search_hit&quot;&gt;configuration&lt;/span&gt; files. This will provide an easier method to securely manage the monitor scripts.&lt;/p&gt;&lt;pre class=&quot;code&quot;&gt;
useradd --comment &amp;quot;MMM Script owner&amp;quot; --shell /sbin/nologin mmmd&lt;/pre&gt;&lt;/div&gt;&lt;h3 class=&quot;sectionedit11&quot;&gt;&lt;a id=&quot;monitoring_host&quot; name=&quot;monitoring_host&quot;&gt;&lt;font color=&quot;#000000&quot;&gt;Monitoring host&lt;/font&gt;&lt;/a&gt;&lt;/h3&gt;&lt;div class=&quot;level3&quot;&gt;&lt;p&gt;First install dependencies:&lt;/p&gt;&lt;pre class=&quot;code&quot;&gt;
aptitude install liblog-log4perl-perl libmailtools-perl liblog-dispatch-perl libclass-singleton-perl libproc-daemon-perl libalgorithm-diff-perl libdbi-perl libdbd-mysql-perl&lt;/pre&gt;&lt;p&gt;Then fetch the latest &lt;span class=&quot;search_hit&quot;&gt;mysql-mmm&lt;/span&gt;-common*.deb and &lt;span class=&quot;search_hit&quot;&gt;mysql-mmm&lt;/span&gt;-monitor*.deb and install it:&lt;/p&gt;&lt;pre class=&quot;code&quot;&gt;
dpkg -i &lt;span class=&quot;search_hit&quot;&gt;mysql-mmm&lt;/span&gt;-common_*.deb &lt;span class=&quot;search_hit&quot;&gt;mysql-mmm&lt;/span&gt;-monitor*.deb&lt;/pre&gt;&lt;/div&gt;&lt;h3 class=&quot;sectionedit12&quot;&gt;&lt;a id=&quot;database_hosts&quot; name=&quot;database_hosts&quot;&gt;&lt;font color=&quot;#000000&quot;&gt;Database hosts&lt;/font&gt;&lt;/a&gt;&lt;/h3&gt;&lt;div class=&quot;level3&quot;&gt;&lt;p&gt;&lt;strong&gt;On Ubuntu&lt;/strong&gt;First install dependencies:&lt;/p&gt;&lt;pre class=&quot;code&quot;&gt;
aptitude install liblog-log4perl-perl libmailtools-perl liblog-dispatch-perl iproute libnet-arp-perl libproc-daemon-perl libalgorithm-diff-perl libdbi-perl libdbd-mysql-perl&lt;/pre&gt;&lt;p&gt;Then fetch the latest &lt;span class=&quot;search_hit&quot;&gt;mysql-mmm&lt;/span&gt;-common*.deb and &lt;span class=&quot;search_hit&quot;&gt;mysql-mmm&lt;/span&gt;-agent*.deb and install it:&lt;/p&gt;&lt;pre class=&quot;code&quot;&gt;
dpkg -i &lt;span class=&quot;search_hit&quot;&gt;mysql-mmm&lt;/span&gt;-common_*.deb &lt;span class=&quot;search_hit&quot;&gt;mysql-mmm&lt;/span&gt;-agent_*.deb&lt;/pre&gt;&lt;p&gt;&lt;strong&gt;On RedHat&lt;/strong&gt;&lt;/p&gt;&lt;pre class=&quot;code&quot;&gt;
yum install -y &lt;span class=&quot;search_hit&quot;&gt;mysql-mmm&lt;/span&gt;-agent&lt;/pre&gt;&lt;p&gt;This will take care of all the dependencies, which may include:&lt;/p&gt;&lt;p&gt;Installed:&lt;/p&gt;&lt;pre class=&quot;code&quot;&gt;&lt;span class=&quot;search_hit&quot;&gt;mysql-mmm&lt;/span&gt;-agent.noarch 0:2.2.1-1.el5                                          &lt;/pre&gt;&lt;p&gt;Dependency Installed:&lt;/p&gt;&lt;pre class=&quot;code&quot;&gt;
libart_lgpl.x86_64 0:2.3.17-4                                                 
&lt;span class=&quot;search_hit&quot;&gt;mysql-mmm&lt;/span&gt;.noarch 0:2.2.1-1.el5                                                
perl-Algorithm-Diff.noarch 0:1.1902-2.el5                                     
perl-DBD-mysql.x86_64 0:4.008-1.rf                                            
perl-DateManip.noarch 0:5.44-1.2.1                                            
perl-IPC-Shareable.noarch 0:0.60-3.el5                                        
perl-Log-Dispatch.noarch 0:2.20-1.el5                                         
perl-Log-Dispatch-FileRotate.noarch 0:1.16-1.el5                              
perl-Log-Log4perl.noarch 0:1.13-2.el5                                         
perl-MIME-Lite.noarch 0:3.01-5.el5                                            
perl-Mail-Sender.noarch 0:0.8.13-2.el5.1                                      
perl-Mail-Sendmail.noarch 0:0.79-9.el5.1                                      
perl-MailTools.noarch 0:1.77-1.el5                                            
perl-Net-ARP.x86_64 0:1.0.6-2.1.el5                                           
perl-Params-Validate.x86_64 0:0.88-3.el5                                      
perl-Proc-Daemon.noarch 0:0.03-1.el5                                          
perl-TimeDate.noarch 1:1.16-5.el5                                             
perl-XML-DOM.noarch 0:1.44-2.el5                                              
perl-XML-Parser.x86_64 0:2.34-6.1.2.2.1                                       
perl-XML-RegExp.noarch 0:0.03-2.el5                                           
rrdtool.x86_64 0:1.2.27-3.el5                                                 
rrdtool-perl.x86_64 0:1.2.27-3.el5 &lt;/pre&gt;&lt;/div&gt;&lt;h3 class=&quot;sectionedit13&quot;&gt;&lt;a id=&quot;configure_mmm&quot; name=&quot;configure_mmm&quot;&gt;&lt;font color=&quot;#000000&quot;&gt;Configure MMM&lt;/font&gt;&lt;/a&gt;&lt;/h3&gt;&lt;div class=&quot;level3&quot;&gt;&lt;p&gt;All generic &lt;span class=&quot;search_hit&quot;&gt;configuration&lt;/span&gt;-options are grouped in a separate file called /etc/&lt;span class=&quot;search_hit&quot;&gt;mysql-mmm&lt;/span&gt;/mmm_common.conf. This file will be the same on all hosts in the system:&lt;/p&gt;&lt;pre class=&quot;code&quot;&gt;
active_master_role          writer
&amp;lt;host default&amp;gt;
    cluster_interface       eth0
    pid_path                /var/run/mmmd_agent.pid
    bin_path                /usr/lib/&lt;span class=&quot;search_hit&quot;&gt;mysql-mmm&lt;/span&gt;/
    replication_user        replication
    replication_password    replication_password
    agent_user              mmm_agent
    agent_password          agent_password
&amp;lt;/host&amp;gt;
&amp;lt;host db1&amp;gt;
    ip                      192.168.0.11
    mode                    master
    peer                    db2
&amp;lt;/host&amp;gt;
&amp;lt;host db2&amp;gt;
    ip                      192.168.0.12
    mode                    master
    peer                    db1
&amp;lt;/host&amp;gt;
&amp;lt;host db3&amp;gt;
    ip                      192.168.0.13
    mode                    slave
&amp;lt;/host&amp;gt;
&amp;lt;host db4&amp;gt;
    ip                      192.168.0.14
    mode                    slave
&amp;lt;/host&amp;gt;
&amp;lt;role writer&amp;gt;
    hosts                   db1, db2
    ips                     192.168.0.100
    mode                    exclusive
&amp;lt;/role&amp;gt;
&amp;lt;role reader&amp;gt;
    hosts                   db1, db2, db3, db4
    ips                     192.168.0.101, 192.168.0.102, 192.168.0.103, 192.168.0.104
    mode                    balanced
&amp;lt;/role&amp;gt;&lt;/pre&gt;&lt;p&gt;Don&apos;t forget to copy this file to all other hosts (including the monitoring host).&lt;/p&gt;&lt;p&gt;On the database hosts we need to edit /etc/&lt;span class=&quot;search_hit&quot;&gt;mysql-mmm&lt;/span&gt;/mmm_agent.conf. Change “db1” accordingly on the other hosts:&lt;/p&gt;&lt;pre class=&quot;code&quot;&gt;
include mmm_common.conf
this db1&lt;/pre&gt;&lt;p&gt;On the monitor host we need to edit /etc/&lt;span class=&quot;search_hit&quot;&gt;mysql-mmm&lt;/span&gt;/mmm_mon.conf:&lt;/p&gt;&lt;pre class=&quot;code&quot;&gt;
include mmm_common.conf
&amp;lt;monitor&amp;gt;
    ip                      127.0.0.1
    pid_path                /var/run/mmmd_mon.pid
    bin_path                /usr/lib/&lt;span class=&quot;search_hit&quot;&gt;mysql-mmm&lt;/span&gt;/
    status_path             /var/lib/misc/mmmd_mon.status
    ping_ips                192.168.0.1, 192.168.0.11, 192.168.0.12, 192.168.0.13, 192.168.0.14
&amp;lt;/monitor&amp;gt;
&amp;lt;host default&amp;gt;
    monitor_user            mmm_monitor
    monitor_password        monitor_password
&amp;lt;/host&amp;gt;
debug 0&lt;/pre&gt;&lt;p&gt;ping_ips are some ips that are pinged to determine whether the network connection of the monitor is ok. I used my switch (192.168.0.1) and the four database server.&lt;/p&gt;&lt;/div&gt;&lt;h2 class=&quot;sectionedit14&quot;&gt;&lt;a id=&quot;start_mmm&quot; name=&quot;start_mmm&quot;&gt;&lt;font color=&quot;#000000&quot;&gt;Start MMM&lt;/font&gt;&lt;/a&gt;&lt;/h2&gt;&lt;h3 class=&quot;sectionedit15&quot;&gt;&lt;a id=&quot;start_the_agents&quot; name=&quot;start_the_agents&quot;&gt;&lt;font color=&quot;#000000&quot;&gt;Start the agents&lt;/font&gt;&lt;/a&gt;&lt;/h3&gt;&lt;div class=&quot;level3&quot;&gt;&lt;p&gt;&lt;strong&gt;(On the database hosts)&lt;/strong&gt;&lt;/p&gt;&lt;/div&gt;&lt;h4&gt;&lt;a id=&quot;debian_ubuntu&quot; name=&quot;debian_ubuntu&quot;&gt;&lt;font color=&quot;#000000&quot;&gt;Debian/Ubuntu&lt;/font&gt;&lt;/a&gt;&lt;/h4&gt;&lt;div class=&quot;level4&quot;&gt;&lt;p&gt;Edit /etc/default/&lt;span class=&quot;search_hit&quot;&gt;mysql-mmm&lt;/span&gt;-agent to enable the agent:&lt;/p&gt;&lt;pre class=&quot;code&quot;&gt;
ENABLED=1&lt;/pre&gt;&lt;/div&gt;&lt;h4&gt;&lt;a id=&quot;red_hat&quot; name=&quot;red_hat&quot;&gt;&lt;font color=&quot;#000000&quot;&gt;Red Hat&lt;/font&gt;&lt;/a&gt;&lt;/h4&gt;&lt;div class=&quot;level4&quot;&gt;&lt;p&gt;RHEL/Fedora does not enable packages to start at boot time per default policy, so you might have to turn it on manually so the agents will start automatically when server is rebooted:&lt;/p&gt;&lt;pre class=&quot;code&quot;&gt;
chkconfig &lt;span class=&quot;search_hit&quot;&gt;mysql-mmm&lt;/span&gt;-agent on&lt;/pre&gt;&lt;p&gt;Then start it:&lt;/p&gt;&lt;pre class=&quot;code&quot;&gt;
/etc/init.d/&lt;span class=&quot;search_hit&quot;&gt;mysql-mmm&lt;/span&gt;-agent start&lt;/pre&gt;&lt;/div&gt;&lt;h3 class=&quot;sectionedit16&quot;&gt;&lt;a id=&quot;start_the_monitor&quot; name=&quot;start_the_monitor&quot;&gt;&lt;font color=&quot;#000000&quot;&gt;Start the monitor&lt;/font&gt;&lt;/a&gt;&lt;/h3&gt;&lt;div class=&quot;level3&quot;&gt;&lt;p&gt;&lt;strong&gt;(On the monitoring host)&lt;/strong&gt;Edit /etc/default/&lt;span class=&quot;search_hit&quot;&gt;mysql-mmm&lt;/span&gt;-monitor to enable the monitor:&lt;/p&gt;&lt;pre class=&quot;code&quot;&gt;
ENABLED=1&lt;/pre&gt;&lt;p&gt;Then start it:&lt;/p&gt;&lt;pre class=&quot;code&quot;&gt;
/etc/init.d/&lt;span class=&quot;search_hit&quot;&gt;mysql-mmm&lt;/span&gt;-monitor start&lt;/pre&gt;&lt;p&gt;Wait some seconds for mmmd_mon to start up. After a few seconds you can use mmm_control to check the status of the cluster:&lt;/p&gt;&lt;pre class=&quot;code&quot;&gt;
mon$ mmm_control show
  db1(192.168.0.11) master/AWAITING_RECOVERY. Roles: 
  db2(192.168.0.12) master/AWAITING_RECOVERY. Roles: 
  db3(192.168.0.13) slave/AWAITING_RECOVERY. Roles: 
  db4(192.168.0.14) slave/AWAITING_RECOVERY. Roles: &lt;/pre&gt;&lt;p&gt;Because its the first startup the monitor does not know our hosts, so it sets all hosts to state AWAITING_RECOVERY and logs a warning message:&lt;/p&gt;&lt;pre class=&quot;code&quot;&gt;
mon$ tail /var/log/&lt;span class=&quot;search_hit&quot;&gt;mysql-mmm&lt;/span&gt;/mmmd_mon.warn
…
2009/10/28 23:15:28  WARN Detected new host &apos;db1&apos;: Setting its initial state to &apos;AWAITING_RECOVERY&apos;. Use &apos;mmm_control set_online db1&apos; to switch it online.
2009/10/28 23:15:28  WARN Detected new host &apos;db2&apos;: Setting its initial state to &apos;AWAITING_RECOVERY&apos;. Use &apos;mmm_control set_online db2&apos; to switch it online.
2009/10/28 23:15:28  WARN Detected new host &apos;db3&apos;: Setting its initial state to &apos;AWAITING_RECOVERY&apos;. Use &apos;mmm_control set_online db3&apos; to switch it online.
2009/10/28 23:15:28  WARN Detected new host &apos;db4&apos;: Setting its initial state to &apos;AWAITING_RECOVERY&apos;. Use &apos;mmm_control set_online db4&apos; to switch it online.&lt;/pre&gt;&lt;p&gt;Now we set or hosts online (db1 first, because the slaves replicate from this host):&lt;/p&gt;&lt;pre class=&quot;code&quot;&gt;
mon$ mmm_control set_online db1
OK: State of &apos;db1&apos; changed to ONLINE. Now you can wait some time and check its new roles!
mon$ mmm_control set_online db2
OK: State of &apos;db2&apos; changed to ONLINE. Now you can wait some time and check its new roles!
mon$ mmm_control set_online db3
OK: State of &apos;db3&apos; changed to ONLINE. Now you can wait some time and check its new roles!
mon$ mmm_control set_online db4
OK: State of &apos;db4&apos; changed to ONLINE. Now you can wait some time and check its new roles!&lt;/pre&gt;&lt;/div&gt;</description>
		<guid>http://www.517sou.net/Article/mysql-mmm-Installation-Guide.aspx</guid>
		<trackback:ping>http://www.517sou.net/Article/756/Trackback.ashx</trackback:ping>
		<comments>http://www.517sou.net/Article/mysql-mmm-Installation-Guide.aspx#CommentPostAnchor</comments>
		<wfw:commentRss>http://www.517sou.net/Article/756/Feeds.ashx</wfw:commentRss>
	</item>
	<item>
		<link>http://www.517sou.net/Article/mysql-mmm-implement-HA.aspx</link>
		<title>mysql-mmm实现mysql高可用</title>
		<author>shanyiwan@live.com(flyinweb)</author>
		<category>数据库技术</category>
		<pubDate>Tue, 31 Jan 2012 08:04:20 GMT</pubDate>
		<description>&lt;p style=&quot;text-indent: -21pt; margin-left: 21pt&quot; class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;一、&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;MMM&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;简介：&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p style=&quot;text-indent: 21pt&quot; class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;MMM&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;即&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Master-Master Replication Manager for MySQL&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;（&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;mysql&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;主主复制管理器）关于&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;mysql&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;主主复制配置的监控、故障转移和管理的一套可伸缩的脚本套件（在任何时候只有一个节点可以被写入），这个套件也能对居于标准的主从配置的任意数量的从服务器进行读负载均衡，所以你可以用它来在一组居于复制的服务器启动虚拟&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;ip&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;，除此之外，它还有实现数据备份、节点之间重新同步功能的脚本。&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-indent: 21pt&quot; class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;MySQL&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;本身没有提供&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;replication failover&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;的解决方案，通过&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;MMM&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;方案能实现服务器的故障转移，从而实现&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;mysql&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;的高可用。&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;MMM&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;项目来自&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt; Google&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;：&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;a href=&quot;http://blog.chinaunix.net/link.php?url=http://code.google.com%2Fp%2Fmysql-master-master&quot; target=&quot;_blank&quot;&gt;&lt;u&gt;&lt;font color=&quot;#0066cc&quot;&gt;http://code.google.com/p/mysql-master-master&lt;/font&gt;&lt;/u&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;官方网站为：&lt;/span&gt;&lt;a href=&quot;http://blog.chinaunix.net/link.php?url=http://mysql-mmm.org%2F&quot; target=&quot;_blank&quot;&gt;&lt;u&gt;&lt;font color=&quot;#0066cc&quot;&gt;http://mysql-mmm.org&lt;/font&gt;&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;Mmm&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;主要功能由下面三个脚本提供&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-indent: -21pt; margin-left: 21pt&quot; class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: Wingdings&quot; lang=&quot;EN-US&quot;&gt;&lt;span&gt;l&lt;span style=&quot;font: 7pt &apos;Times New Roman&apos;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;mmm_mond&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;负责所有的监控工作的监控守护进程，决定节点的移除等等&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-indent: -21pt; margin-left: 21pt&quot; class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: Wingdings&quot; lang=&quot;EN-US&quot;&gt;&lt;span&gt;l&lt;span style=&quot;font: 7pt &apos;Times New Roman&apos;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;mmm_agentd&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;运行在&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;mysql&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;服务器上的代理守护进程，通过简单远程服务集提供给监控节点&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-indent: -21pt; margin-left: 21pt&quot; class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: Wingdings&quot; lang=&quot;EN-US&quot;&gt;&lt;span&gt;l&lt;span style=&quot;font: 7pt &apos;Times New Roman&apos;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;mmm_control&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;通过命令行管理&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;mmm_mond&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;进程&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-indent: -21pt; margin-left: 21pt&quot; class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;二、&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;mysql-mmm&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;架构的搭建&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p style=&quot;text-indent: -18pt; margin-left: 39pt&quot; class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;1、&lt;span style=&quot;font: 7pt &apos;Times New Roman&apos;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;先介绍下本文的环境：&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 39pt&quot; class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;系统环境：&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;CentOS release 5.4&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;（&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;32bit&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;）&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 39pt&quot; class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;server1 ip: 192.168.1.161 virtual read ip:192.168.1.111 &lt;br /&gt;server2 ip: 192.168.1.162 virtual read ip:192.168.1.112 &lt;br /&gt;server3 ip: 192.168.1.163 virtual write ip: 192.168.1.113&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-indent: -18pt; margin-left: 39pt&quot; class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;2、&lt;span style=&quot;font: 7pt &apos;Times New Roman&apos;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;mysql-mmm&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;架构配置简介：&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-indent: -21pt; margin-left: 63pt&quot; class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: Wingdings&quot; lang=&quot;EN-US&quot;&gt;&lt;span&gt;u&lt;span style=&quot;font: 7pt &apos;Times New Roman&apos;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;在&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;server1&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;、&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;server2&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;上安装&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;mysql&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;，并配置为&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;master-master&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;架构（就是互为主从）&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;----------&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;配置很简单，就不对着部分进行详细解释，有问题的话请查看：&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;a href=&quot;http://blog.chinaunix.net/link.php?url=http://blog.chinaunix.net%2Fu3%2F93755%2Fshowart.php%3Fid%3D2213538&quot; target=&quot;_blank&quot;&gt;&lt;u&gt;&lt;font color=&quot;#0066cc&quot;&gt;http://blog.chinaunix.net/u3/93755/showart.php?id=2213538&lt;/font&gt;&lt;/u&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-indent: -21pt; margin-left: 63pt&quot; class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: Wingdings&quot; lang=&quot;EN-US&quot;&gt;&lt;span&gt;u&lt;span style=&quot;font: 7pt &apos;Times New Roman&apos;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;在&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;server1&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;、&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;server2&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;，&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;server3&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;上安装&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;mmm&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;，并配置：&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;mmm_common.conf&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;、&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;mmm_agent.conf&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;以及&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;mmm_mon.conf&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;文件&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-indent: -18pt; margin-left: 39pt&quot; class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;span&gt;3、&lt;span style=&quot;font: 7pt &apos;Times New Roman&apos;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;Mysql-mmm&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;实战&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 39pt&quot; class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;前提：&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;server1&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;和&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;server2&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;上已经配置好&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;mysql&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;主主同步&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-indent: -21pt; margin-left: 63pt&quot; class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: Wingdings&quot; lang=&quot;EN-US&quot;&gt;&lt;span&gt;u&lt;span style=&quot;font: 7pt &apos;Times New Roman&apos;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;安装&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;mysql-mmm&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 59.95pt&quot; class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;CentOS&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;软件仓库默认是不含这些软件的，必须要有&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;epel&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;这个包的支持。故我们必须先安装&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;epel&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;：&lt;/span&gt;&lt;/p&gt;&lt;div style=&quot;border-bottom: rgb(255,153,204) 1pt solid; border-left: rgb(255,153,204) 1pt solid; padding-bottom: 1pt; padding-left: 4pt; padding-right: 4pt; background: rgb(224,224,224); margin-left: 57pt; border-top: rgb(255,153,204) 1pt solid; margin-right: 0cm; border-right: rgb(255,153,204) 1pt solid; padding-top: 1pt&quot;&gt;&lt;p style=&quot;border-bottom: medium none; border-left: medium none; padding-bottom: 0cm; text-indent: 3pt; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); margin-left: 0cm; border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;wget &lt;a href=&quot;http://blog.chinaunix.net/link.php?url=http://download.fedora.redhat.com%2Fpub%2Fepel%2F5%2Fi386%2Fepel-release-5-4.noarch.rpm&quot; target=&quot;_blank&quot;&gt;&lt;u&gt;&lt;font color=&quot;#0066cc&quot;&gt;http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm&lt;/font&gt;&lt;/u&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; border-left: medium none; padding-bottom: 0cm; text-indent: 3pt; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); margin-left: 0cm; border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;rpm -Uvh epel-release-5-4.noarch.rpm&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; border-left: medium none; padding-bottom: 0cm; text-indent: 3pt; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); margin-left: 0cm; border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;yum -y install mysql-mmm*&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;p style=&quot;text-indent: -21pt; margin-left: 63pt&quot; class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: Wingdings&quot; lang=&quot;EN-US&quot;&gt;&lt;span&gt;u&lt;span style=&quot;font: 7pt &apos;Times New Roman&apos;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;配置&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;mmm&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;代理和监控账号的权限&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 63pt&quot; class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;在&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;server1&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;和&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;server2&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;上分别执行：&lt;/span&gt;&lt;/p&gt;&lt;div style=&quot;border-bottom: rgb(255,153,204) 1pt solid; border-left: rgb(255,153,204) 1pt solid; padding-bottom: 1pt; padding-left: 4pt; padding-right: 4pt; background: rgb(224,224,224); margin-left: 63pt; border-top: rgb(255,153,204) 1pt solid; margin-right: 0cm; border-right: rgb(255,153,204) 1pt solid; padding-top: 1pt&quot;&gt;&lt;p style=&quot;border-bottom: medium none; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); margin-left: 0cm; border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;GRANT REPLICATION CLIENT ON *.* TO &apos;mmm_monitor&apos;@&apos;192.168.1.%&apos; IDENTIFIED BY &apos;monitor_password&apos;;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); margin-left: 0cm; border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;GRANT SUPER, REPLICATION CLIENT, PROCESS ON *.* TO &apos;mmm_agent&apos;@&apos;192.168.1.%&apos;&lt;span&gt;&lt;/span&gt;IDENTIFIED BY &apos;agent_password&apos;;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); margin-left: 0cm; border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;flush privileges;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;p style=&quot;text-indent: -21pt; margin-left: 63pt&quot; class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: Wingdings&quot; lang=&quot;EN-US&quot;&gt;&lt;span&gt;u&lt;span style=&quot;font: 7pt &apos;Times New Roman&apos;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;配置&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;mysql-mmm&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 63pt&quot; class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;所有的配置选项都集合在了一个叫&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;/etc/mysql-mmm/mmm_common.conf&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;的单独文件中，&lt;span class=&quot;ttag&quot;&gt;系统&lt;/span&gt;中所有主机的该文件内容都是一样的&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;配置完后不要忘记了拷贝这个文件到所有的主机（包括监控主机）！，内容如下：&lt;/span&gt;&lt;/p&gt;&lt;div style=&quot;border-bottom: rgb(255,153,204) 1pt solid; border-left: rgb(255,153,204) 1pt solid; padding-bottom: 1pt; padding-left: 4pt; padding-right: 4pt; background: rgb(224,224,224); margin-left: 63pt; border-top: rgb(255,153,204) 1pt solid; margin-right: 0cm; border-right: rgb(255,153,204) 1pt solid; padding-top: 1pt&quot;&gt;&lt;p style=&quot;border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); margin-left: 0cm; border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family: &apos;Courier New&apos;; font-size: 9pt&quot;&gt;active_master_role&lt;span&gt;&lt;/span&gt;writer&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); margin-left: 0cm; border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family: &apos;Courier New&apos;; font-size: 9pt&quot;&gt;&amp;lt;host default&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); margin-left: 0cm; border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family: &apos;Courier New&apos;; font-size: 9pt&quot;&gt;cluster_interface&lt;span&gt;&lt;/span&gt;eth0&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); margin-left: 0cm; border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family: &apos;Courier New&apos;; font-size: 9pt&quot;&gt;pid_path&lt;span&gt;&lt;/span&gt;/var/run/mysql-mmm/mmm_agentd.pid&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0cm; text-indent: 18pt; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); margin-left: 0cm; border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family: &apos;Courier New&apos;; font-size: 9pt&quot;&gt;bin_path&lt;span&gt;&lt;/span&gt;/usr/libexec/mysql-mmm/&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0cm; text-indent: 18pt; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); margin-left: 0cm; border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family: &apos;Courier New&apos;; font-size: 9pt&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; font-size: 9pt&quot;&gt;同步的帐号（这些要和前面设置的保持一致！）&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); margin-left: 0cm; border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family: &apos;Courier New&apos;; font-size: 9pt&quot;&gt;replication_user&lt;span&gt;&lt;/span&gt;replication&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); margin-left: 0cm; border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family: &apos;Courier New&apos;; font-size: 9pt&quot;&gt;replication_password&lt;span&gt;&lt;/span&gt;123456&lt;span&gt;&lt;/span&gt;#&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; font-size: 9pt&quot;&gt;同步的密码&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); margin-left: 0cm; border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family: &apos;Courier New&apos;; font-size: 9pt&quot;&gt;agent_user&lt;span&gt;&lt;/span&gt;mmm_agent&lt;span&gt;&lt;/span&gt;#mmm-agent&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; font-size: 9pt&quot;&gt;用户名&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); margin-left: 0cm; border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family: &apos;Courier New&apos;; font-size: 9pt&quot;&gt;agent_password&lt;span&gt;&lt;/span&gt;agent_password&lt;span&gt;&lt;/span&gt;#mmm-agent&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; font-size: 9pt&quot;&gt;用户密码&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); margin-left: 0cm; border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family: &apos;Courier New&apos;; font-size: 9pt&quot;&gt;&amp;lt;/host&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); margin-left: 0cm; border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family: &apos;Courier New&apos;; font-size: 9pt&quot;&gt;&amp;lt;host db1&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); margin-left: 0cm; border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family: &apos;Courier New&apos;; font-size: 9pt&quot;&gt;ip&lt;span&gt;&lt;/span&gt;192.168.1.161&lt;span&gt;&lt;/span&gt;#db1&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; font-size: 9pt&quot;&gt;的&lt;/span&gt;&lt;span style=&quot;font-family: &apos;Courier New&apos;; font-size: 9pt&quot;&gt;ip&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); margin-left: 0cm; border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family: &apos;Courier New&apos;; font-size: 9pt&quot;&gt;mode&lt;span&gt;&lt;/span&gt;master&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); margin-left: 0cm; border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family: &apos;Courier New&apos;; font-size: 9pt&quot;&gt;peer&lt;span&gt;&lt;/span&gt;db2&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); margin-left: 0cm; border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family: &apos;Courier New&apos;; font-size: 9pt&quot;&gt;&amp;lt;/host&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); margin-left: 0cm; border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family: &apos;Courier New&apos;; font-size: 9pt&quot;&gt;&amp;lt;host db2&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); margin-left: 0cm; border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family: &apos;Courier New&apos;; font-size: 9pt&quot;&gt;ip&lt;span&gt;&lt;/span&gt;192.168.1.162&lt;span&gt;&lt;/span&gt;#db2&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; font-size: 9pt&quot;&gt;的&lt;/span&gt;&lt;span style=&quot;font-family: &apos;Courier New&apos;; font-size: 9pt&quot;&gt;ip&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); margin-left: 0cm; border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family: &apos;Courier New&apos;; font-size: 9pt&quot;&gt;mode&lt;span&gt;&lt;/span&gt;master&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); margin-left: 0cm; border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family: &apos;Courier New&apos;; font-size: 9pt&quot;&gt;peer&lt;span&gt;&lt;/span&gt;db1&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); margin-left: 0cm; border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family: &apos;Courier New&apos;; font-size: 9pt&quot;&gt;&amp;lt;/host&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); margin-left: 0cm; border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family: &apos;Courier New&apos;; font-size: 9pt&quot;&gt;&amp;lt;role writer&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); margin-left: 0cm; border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family: &apos;Courier New&apos;; font-size: 9pt&quot;&gt;hosts&lt;span&gt;&lt;/span&gt;db1, db2&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); margin-left: 0cm; border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family: &apos;Courier New&apos;; font-size: 9pt&quot;&gt;ips&lt;span&gt;&lt;/span&gt;192.168.1.113&lt;span&gt;&lt;/span&gt;#&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; font-size: 9pt&quot;&gt;设置写如的虚拟&lt;/span&gt;&lt;span style=&quot;font-family: &apos;Courier New&apos;; font-size: 9pt&quot;&gt;IP&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); margin-left: 0cm; border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family: &apos;Courier New&apos;; font-size: 9pt&quot;&gt;mode&lt;span&gt;&lt;/span&gt;exclusive&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); margin-left: 0cm; border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family: &apos;Courier New&apos;; font-size: 9pt&quot;&gt;&amp;lt;/role&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); margin-left: 0cm; border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family: &apos;Courier New&apos;; font-size: 9pt&quot;&gt;&amp;lt;role reader&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); margin-left: 0cm; border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family: &apos;Courier New&apos;; font-size: 9pt&quot;&gt;hosts&lt;span&gt;&lt;/span&gt;db1, db2&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); margin-left: 0cm; border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family: &apos;Courier New&apos;; font-size: 9pt&quot;&gt;ips&lt;span&gt;&lt;/span&gt;192.168.1.111, 192.168.1.112&lt;span&gt;&lt;/span&gt;#&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; font-size: 9pt&quot;&gt;设置读取的虚拟&lt;/span&gt;&lt;span style=&quot;font-family: &apos;Courier New&apos;; font-size: 9pt&quot;&gt;IP&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); margin-left: 0cm; border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family: &apos;Courier New&apos;; font-size: 9pt&quot;&gt;mode&lt;span&gt;&lt;/span&gt;balanced&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); margin-left: 0cm; border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family: &apos;Courier New&apos;; font-size: 9pt&quot;&gt;&amp;lt;/role&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;p style=&quot;margin-left: 63pt&quot; class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;在数据库主机上我们需要编辑&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;/etc/mysql-mmm/mmm_agent.conf&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;文件，根据其他主机的不同更改&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;db1&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;的值（&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;db2&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;就将&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;db1&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;更改成&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;db2&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;）：&lt;/span&gt;&lt;/p&gt;&lt;div style=&quot;border-bottom: rgb(255,153,204) 1pt solid; border-left: rgb(255,153,204) 1pt solid; padding-bottom: 1pt; padding-left: 4pt; padding-right: 4pt; background: rgb(224,224,224); margin-left: 63pt; border-top: rgb(255,153,204) 1pt solid; margin-right: 0cm; border-right: rgb(255,153,204) 1pt solid; padding-top: 1pt&quot;&gt;&lt;p style=&quot;border-bottom: medium none; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;include mmm_common.conf&lt;br /&gt;this db1&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;p style=&quot;margin-left: 63pt&quot; class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;在监控主机上我们需要编辑&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;/etc/mysql-mmm/mmm_mon.conf&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;文件：&lt;/span&gt;&lt;/p&gt;&lt;div style=&quot;border-bottom: rgb(255,153,204) 1pt solid; border-left: rgb(255,153,204) 1pt solid; padding-bottom: 1pt; padding-left: 4pt; padding-right: 4pt; background: rgb(224,224,224); margin-left: 63pt; border-top: rgb(255,153,204) 1pt solid; margin-right: 0cm; border-right: rgb(255,153,204) 1pt solid; padding-top: 1pt&quot;&gt;&lt;p style=&quot;border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); margin-left: 0cm; border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family: &apos;Courier New&apos;; font-size: 9pt&quot;&gt;include mmm_common.conf&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); margin-left: 0cm; border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family: &apos;Courier New&apos;; font-size: 9pt&quot;&gt;&amp;lt;monitor&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); margin-left: 0cm; border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family: &apos;Courier New&apos;; font-size: 9pt&quot;&gt;ip&lt;span&gt;&lt;/span&gt;127.0.0.1&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); margin-left: 0cm; border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family: &apos;Courier New&apos;; font-size: 9pt&quot;&gt;pid_path&lt;span&gt;&lt;/span&gt;/var/run/mysql-mmm/mmm_mond.pid&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); margin-left: 0cm; border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family: &apos;Courier New&apos;; font-size: 9pt&quot;&gt;bin_path&lt;span&gt;&lt;/span&gt;/usr/libexec/mysql-mmm&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); margin-left: 0cm; border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family: &apos;Courier New&apos;; font-size: 9pt&quot;&gt;status_path&lt;span&gt;&lt;/span&gt;/var/lib/mysql-mmm/mmm_mond.status&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); margin-left: 0cm; border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family: &apos;Courier New&apos;; font-size: 9pt&quot;&gt;ping_ips&lt;span&gt;&lt;/span&gt;192.168.1.161,192.168.1.162&lt;span&gt;&lt;/span&gt;#&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; font-size: 9pt&quot;&gt;监控服务器&lt;/span&gt;&lt;span style=&quot;font-family: &apos;Courier New&apos;; font-size: 9pt&quot;&gt;ip&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); margin-left: 0cm; border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family: &apos;Courier New&apos;; font-size: 9pt&quot;&gt;auto_set_online&lt;span&gt;&lt;/span&gt;60&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); margin-left: 0cm; border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family: &apos;Courier New&apos;; font-size: 9pt&quot;&gt;# The kill_host_bin does not exist by default, though the monitor will&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); margin-left: 0cm; border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family: &apos;Courier New&apos;; font-size: 9pt&quot;&gt;# throw a warning about it missing.&lt;span&gt;&lt;/span&gt;See the section 5.10 &amp;quot;Kill Host &lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); margin-left: 0cm; border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family: &apos;Courier New&apos;; font-size: 9pt&quot;&gt;# Functionality&amp;quot; in the PDF documentation.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); margin-left: 0cm; border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family: &apos;Courier New&apos;; font-size: 9pt&quot;&gt;#&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); margin-left: 0cm; border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family: &apos;Courier New&apos;; font-size: 9pt&quot;&gt;# kill_host_bin&lt;span&gt;&lt;/span&gt;/usr/libexec/mysql-mmm/monitor/kill_host&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); margin-left: 0cm; border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family: &apos;Courier New&apos;; font-size: 9pt&quot;&gt;#&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); margin-left: 0cm; border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family: &apos;Courier New&apos;; font-size: 9pt&quot;&gt;&amp;lt;/monitor&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); margin-left: 0cm; border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family: &apos;Courier New&apos;; font-size: 9pt&quot;&gt;&amp;lt;host default&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); margin-left: 0cm; border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family: &apos;Courier New&apos;; font-size: 9pt&quot;&gt;monitor_user&lt;span&gt;&lt;/span&gt;mmm_monitor&lt;span&gt;&lt;/span&gt;#mmm_monitor&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; font-size: 9pt&quot;&gt;用户名&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); margin-left: 0cm; border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family: &apos;Courier New&apos;; font-size: 9pt&quot;&gt;monitor_password&lt;span&gt;&lt;/span&gt;monitor_password #mmm_monitor&lt;/span&gt;&lt;span style=&quot;font-family: 宋体; font-size: 9pt&quot;&gt;密码&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); margin-left: 0cm; border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot; align=&quot;left&quot;&gt;&lt;span style=&quot;font-family: &apos;Courier New&apos;; font-size: 9pt&quot;&gt;&amp;lt;/host&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); margin-left: 0cm; border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: &apos;Courier New&apos;; font-size: 9pt&quot;&gt;debug 0&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;p style=&quot;text-indent: -21pt; margin-left: 63pt&quot; class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: Wingdings&quot; lang=&quot;EN-US&quot;&gt;&lt;span&gt;u&lt;span style=&quot;font: 7pt &apos;Times New Roman&apos;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;启动&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;MMM&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 63pt&quot; class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;启动代理：&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 63pt&quot; class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;（在数据库服务器上&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;server1&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;、&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;）编辑&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;/etc/default/mysql-mmm-agent&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;来开启：&lt;/span&gt;&lt;/p&gt;&lt;div style=&quot;border-bottom: rgb(255,153,204) 1pt solid; border-left: rgb(255,153,204) 1pt solid; padding-bottom: 1pt; padding-left: 4pt; padding-right: 4pt; background: rgb(224,224,224); margin-left: 63pt; border-top: rgb(255,153,204) 1pt solid; margin-right: 0cm; border-right: rgb(255,153,204) 1pt solid; padding-top: 1pt&quot;&gt;&lt;p style=&quot;border-bottom: medium none; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;ENABLED=1&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;p style=&quot;margin-left: 63pt&quot; class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;然后启动它：&lt;/span&gt;&lt;/p&gt;&lt;div style=&quot;border-bottom: rgb(255,153,204) 1pt solid; border-left: rgb(255,153,204) 1pt solid; padding-bottom: 1pt; padding-left: 4pt; padding-right: 4pt; background: rgb(224,224,224); margin-left: 63pt; border-top: rgb(255,153,204) 1pt solid; margin-right: 0cm; border-right: rgb(255,153,204) 1pt solid; padding-top: 1pt&quot;&gt;&lt;p style=&quot;border-bottom: medium none; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;/etc/init.d/mysql-mmm-agent start&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;p style=&quot;margin-left: 63pt&quot; class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;启动监控（在监控机上）：&lt;/span&gt;&lt;/p&gt;&lt;div style=&quot;border-bottom: rgb(255,153,204) 1pt solid; border-left: rgb(255,153,204) 1pt solid; padding-bottom: 1pt; padding-left: 4pt; padding-right: 4pt; background: rgb(224,224,224); margin-left: 63pt; border-top: rgb(255,153,204) 1pt solid; margin-right: 0cm; border-right: rgb(255,153,204) 1pt solid; padding-top: 1pt&quot;&gt;&lt;p style=&quot;border-bottom: medium none; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;/etc/init.d/mysql-mmm-monitor start&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;p style=&quot;text-indent: -21pt; margin-left: 63pt&quot; class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: Wingdings&quot; lang=&quot;EN-US&quot;&gt;&lt;span&gt;u&lt;span style=&quot;font: 7pt &apos;Times New Roman&apos;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;利用&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;mmm_control&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;监控&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;mysql&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;服务器状态：&lt;/span&gt;&lt;/p&gt;&lt;div style=&quot;border-bottom: rgb(255,153,204) 1pt solid; border-left: rgb(255,153,204) 1pt solid; padding-bottom: 1pt; padding-left: 4pt; padding-right: 4pt; background: rgb(224,224,224); margin-left: 63pt; border-top: rgb(255,153,204) 1pt solid; margin-right: 0cm; border-right: rgb(255,153,204) 1pt solid; padding-top: 1pt&quot;&gt;&lt;p style=&quot;border-bottom: medium none; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;[root@server3 mysql-mmm]# mmm_control show&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;db1(192.168.1.161) master/ONLINE. Roles: reader(192.168.1.112), writer(192.168.1.113)&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;db2(192.168.1.162) master/ONLINE. Roles: reader(192.168.1.111)&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;p style=&quot;text-indent: -21pt; margin-left: 63pt&quot; class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: Wingdings&quot; lang=&quot;EN-US&quot;&gt;&lt;span&gt;u&lt;span style=&quot;font: 7pt &apos;Times New Roman&apos;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;测试看两个&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;mysql&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;服务器能否实现故障自动切换&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 63pt&quot; class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;停掉作为写的&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;db1&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;上的&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;mysql&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;，查看写的服务器会不会自动转移到&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;db2&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;上去&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 63pt&quot; class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;停掉几秒钟后用&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;mmm_control show&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;查看：&lt;/span&gt;&lt;/p&gt;&lt;div style=&quot;border-bottom: rgb(255,153,204) 1pt solid; border-left: rgb(255,153,204) 1pt solid; padding-bottom: 1pt; padding-left: 4pt; padding-right: 4pt; background: rgb(224,224,224); margin-left: 63pt; border-top: rgb(255,153,204) 1pt solid; margin-right: 0cm; border-right: rgb(255,153,204) 1pt solid; padding-top: 1pt&quot;&gt;&lt;p style=&quot;border-bottom: medium none; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;[root@server3 mysql-mmm]# mmm_control show&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;db1(192.168.1.161) master/HARD_OFFLINE. Roles:&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;db2(192.168.1.162) master/ONLINE. Roles: reader(192.168.1.111), reader(192.168.1.112), writer(192.168.1.113)&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;p style=&quot;margin-left: 63pt&quot; class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;我们可以看到已经把&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;db2&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;当作主写服务器&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-left: 39pt&quot; class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;再来看看&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;db1&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;恢复后会是什么情况：&lt;/span&gt;&lt;/p&gt;&lt;div style=&quot;border-bottom: rgb(255,153,204) 1pt solid; border-left: rgb(255,153,204) 1pt solid; padding-bottom: 1pt; padding-left: 4pt; padding-right: 4pt; background: rgb(224,224,224); margin-left: 59.95pt; border-top: rgb(255,153,204) 1pt solid; margin-right: 0cm; border-right: rgb(255,153,204) 1pt solid; padding-top: 1pt&quot;&gt;&lt;p style=&quot;border-bottom: medium none; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); margin-left: 0cm; border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;[root@server3 mysql-mmm]# mmm_control show&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); margin-left: 0cm; border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;db1(192.168.1.161) master/ONLINE. Roles: reader(192.168.1.111)&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); margin-left: 0cm; border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;db2(192.168.1.162) master/ONLINE. Roles: reader(192.168.1.112), writer(192.168.1.113)&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;p style=&quot;margin-left: 53.25pt&quot; class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;我们可以看到当&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;db1&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;恢复后就充当&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;slave&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;的角色了！只有当&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;db2&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;挂了以后&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;db1&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;又会担当起主服务器的写入功能&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-indent: -21pt; margin-left: 63pt&quot; class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: Wingdings&quot; lang=&quot;EN-US&quot;&gt;&lt;span&gt;u&lt;span style=&quot;font: 7pt &apos;Times New Roman&apos;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;mmm_control&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;命令简介&lt;/span&gt;&lt;/p&gt;&lt;div style=&quot;border-bottom: rgb(255,153,204) 1pt solid; border-left: rgb(255,153,204) 1pt solid; padding-bottom: 1pt; padding-left: 4pt; padding-right: 4pt; background: rgb(224,224,224); margin-left: 63pt; border-top: rgb(255,153,204) 1pt solid; margin-right: 0cm; border-right: rgb(255,153,204) 1pt solid; padding-top: 1pt&quot;&gt;&lt;p style=&quot;border-bottom: medium none; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;[root@server3 mysql-mmm]# mmm_control help&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;Valid commands are:&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;help&lt;span&gt;&lt;/span&gt;- show this message&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;查看帮助信息&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; border-left: medium none; padding-bottom: 0cm; text-indent: 21pt; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;ping&lt;span&gt;&lt;/span&gt;- ping monitor&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; border-left: medium none; padding-bottom: 0cm; text-indent: 21pt; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;#ping&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;监控&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; border-left: medium none; padding-bottom: 0cm; text-indent: 21pt; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;show&lt;span&gt;&lt;/span&gt;- show status&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; border-left: medium none; padding-bottom: 0cm; text-indent: 21pt; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;查看状态信息&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; border-left: medium none; padding-bottom: 0cm; text-indent: 21pt; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;checks [&amp;lt;host&amp;gt;|all [&amp;lt;check&amp;gt;|all]] - show checks status&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; border-left: medium none; padding-bottom: 0cm; text-indent: 21pt; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;显示检查状态，包括（&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;ping&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;、&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;mysql&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;、&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;rep_threads&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;、&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;rep_backlog&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;）&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; border-left: medium none; padding-bottom: 0cm; text-indent: 21pt; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;set_online &amp;lt;host&amp;gt;&lt;span&gt;&lt;/span&gt;- set host &amp;lt;host&amp;gt; online&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; border-left: medium none; padding-bottom: 0cm; text-indent: 21pt; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;设置某&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;host&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;为&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;online&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;状态&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; border-left: medium none; padding-bottom: 0cm; text-indent: 21pt; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;set_offline &amp;lt;host&amp;gt;&lt;span&gt;&lt;/span&gt;- set host &amp;lt;host&amp;gt; offline&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; border-left: medium none; padding-bottom: 0cm; text-indent: 21pt; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;设置某&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;host&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;为&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;offline&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;状态&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; border-left: medium none; padding-bottom: 0cm; text-indent: 21.75pt; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;mode&lt;span&gt;&lt;/span&gt;- print current mode.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; border-left: medium none; padding-bottom: 0cm; text-indent: 21.75pt; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;打印当前的模式，是&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;ACTIVE&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;、&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;MANUAL&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;、&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;PASSIVE&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;？&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; border-left: medium none; padding-bottom: 0cm; text-indent: 21.75pt; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;默认&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;ACTIVE&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;模式&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; border-left: medium none; padding-bottom: 0cm; text-indent: 21pt; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;set_active&lt;span&gt;&lt;/span&gt;- switch into active mode.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; border-left: medium none; padding-bottom: 0cm; text-indent: 21pt; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;更改为&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;active&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;模式&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; border-left: medium none; padding-bottom: 0cm; text-indent: 21pt; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;set_manual&lt;span&gt;&lt;/span&gt;- switch into manual mode.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; border-left: medium none; padding-bottom: 0cm; text-indent: 21pt; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;更改为&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;manual&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;模式&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; border-left: medium none; padding-bottom: 0cm; text-indent: 21pt; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;set_passive&lt;span&gt;&lt;/span&gt;- switch into passive mode.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; border-left: medium none; padding-bottom: 0cm; text-indent: 21pt; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;更改为&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;passive&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;模式&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;move_role [--force] &amp;lt;role&amp;gt; &amp;lt;host&amp;gt; - move exclusive role &amp;lt;role&amp;gt; to host &amp;lt;host&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;更改&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;host&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;的模式，比如更改处于&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;slave&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;的&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;mysql&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;数据库角色为&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;write&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; border-left: medium none; padding-bottom: 0cm; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;(Only use --force if you know what you are doing!)&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; border-left: medium none; padding-bottom: 0cm; text-indent: 21pt; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;set_ip &amp;lt;ip&amp;gt; &amp;lt;host&amp;gt;&lt;span&gt;&lt;/span&gt;- set role with ip &amp;lt;ip&amp;gt; to host &amp;lt;host&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;border-bottom: medium none; border-left: medium none; padding-bottom: 0cm; text-indent: 21pt; padding-left: 0cm; padding-right: 0cm; background: rgb(224,224,224); border-top: medium none; border-right: medium none; padding-top: 0cm&quot; class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;为&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;host&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;设置&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;ip&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;，只有&lt;/span&gt;&lt;span lang=&quot;EN-US&quot;&gt;passive&lt;/span&gt;&lt;span style=&quot;font-family: 宋体&quot;&gt;模式的时候才允许更改！&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;</description>
		<guid>http://www.517sou.net/Article/mysql-mmm-implement-HA.aspx</guid>
		<trackback:ping>http://www.517sou.net/Article/755/Trackback.ashx</trackback:ping>
		<comments>http://www.517sou.net/Article/mysql-mmm-implement-HA.aspx#CommentPostAnchor</comments>
		<wfw:commentRss>http://www.517sou.net/Article/755/Feeds.ashx</wfw:commentRss>
	</item>
	<item>
		<link>http://www.517sou.net/Article/windows-memory-diagnostic-tool.aspx</link>
		<title>Diagnosing Windows Memory Problems</title>
		<author>shanyiwan@live.com(flyinweb)</author>
		<category>技术文摘</category>
		<pubDate>Mon, 30 Jan 2012 02:39:19 GMT</pubDate>
		<description>&lt;h2&gt;Overview&lt;/h2&gt;&lt;p&gt;I can remember way back when how amazed I was to order a new desktop computer with 2MB of RAM. Even the days of ordering a server with 64MB of RAM seemed like sooooo much memory. And in case you missed it, those are values in megabytes. Naturally today’s systems are in another class altogether. And while I’d like to think the quality of memory manufacturing has also increased over the years, things can still go wrong.&lt;/p&gt;&lt;p&gt;Failing or faulty memory doesn’t always manifest itself with a huge announcement. In the event that Windows 7 or Windows Server 2008 detects such a problem, it will most likely prompt you to run the Windows Memory Diagnostic tool. But you can also manually run this tool anytime you’d like if you prefer to be a bit more proactive.&lt;/p&gt;&lt;h2&gt;Using the Windows Memory Diagnostic Tool&lt;/h2&gt;&lt;p&gt;You can manually launch the Windows Memory Diagnostic tool from the Administrator Tools menu short cut. Or if you prefer a command line approach run this:&lt;/p&gt;&lt;pre&gt;
C:\&amp;gt; mdsched&lt;/pre&gt;&lt;p&gt;Alas, there do not appear to be any command line parameters. However you launch it you should get something like Figure 1.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;http://www.petri.co.il/windows-memory-diagnostic-tool.htm/memorydiag-1&quot; rel=&quot;attachment wp-att-22672&quot; target=&quot;_blank&quot;&gt;&lt;img title=&quot;MemoryDiag-1&quot; width=&quot;426&quot; height=&quot;350&quot; class=&quot;Image&quot; alt=&quot;&quot; src=&quot;http://www.517sou.net/Attach/month_1201/c4dnqb_MemoryDiag-1.png&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Figure 1 Windows Memory Diagnostic&lt;/p&gt;&lt;div id=&quot;adkit_freestyle&quot; class=&quot;adkit freestyle&quot;&gt;&lt;div style=&quot;min-height: 46px&quot;&gt;&lt;p style=&quot;padding-bottom: 10px; background-color: rgb(255,255,237); padding-left: 10px; padding-right: 10px; font-weight: bold; padding-top: 10px&quot;&gt;&lt;a href=&quot;http://www.petri.co.il/uri/?id=2766&amp;amp;host=petri.co.il&quot; target=&quot;_blank&quot;&gt;&lt;u&gt;&lt;font color=&quot;#0066cc&quot;&gt;See Also » Windows on iPad with OnLive Desktop&lt;/font&gt;&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;As the dialog suggests you can either reboot immediately or schedule the diagnostic for the next reboot. Whichever option you choose, upon reboot, the memory diagnostic will launch automatically and begin running. You will see something like Figure 2.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;http://www.petri.co.il/windows-memory-diagnostic-tool.htm/memdiag-2&quot; rel=&quot;attachment wp-att-22673&quot; target=&quot;_blank&quot;&gt;&lt;img title=&quot;MemDiag-2&quot; alt=&quot;Running Windows Memory Diagnostic&quot; width=&quot;1024&quot; height=&quot;768&quot; class=&quot;Image&quot; src=&quot;http://www.517sou.net/Attach/month_1201/0xkujx_MemDiag-2.png&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Figure 2 Running Memory Diagnostic&lt;/p&gt;&lt;p&gt;Press F1 to customize the tools. You can modify what tools are run and how many passes. Figure 3 shows the Basic tests that will be run. These tests run pretty quickly.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;http://www.petri.co.il/windows-memory-diagnostic-tool.htm/memdiag-basic&quot; rel=&quot;attachment wp-att-22674&quot; target=&quot;_blank&quot;&gt;&lt;img title=&quot;MemDiag-Basic&quot; alt=&quot;Windows Basic Memory Tests&quot; width=&quot;1024&quot; height=&quot;768&quot; class=&quot;Image&quot; src=&quot;http://www.517sou.net/Attach/month_1201/qg9a8w_MemDiag-Basic.png&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Figure 3 Basic Memory Tests&lt;/p&gt;&lt;p&gt;Figure 4 shows the Standard tests. This is the default behavior.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;http://www.petri.co.il/windows-memory-diagnostic-tool.htm/memdiag-standard&quot; rel=&quot;attachment wp-att-22675&quot; target=&quot;_blank&quot;&gt;&lt;img title=&quot;MemDiag-Standard&quot; alt=&quot;Windows Standard Memory Tests&quot; width=&quot;1024&quot; height=&quot;768&quot; class=&quot;Image&quot; src=&quot;http://www.517sou.net/Attach/month_1201/nwd0ma_MemDiag-Standard.png&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Figure 4 Standard Memory Tests&lt;/p&gt;&lt;p&gt;If you prefer a more thorough examination, select the Extended test mix, as shown in Figure 5.&lt;/p&gt;&lt;p&gt;By default, the diagnostic will run two passes, but you can tab down to the Pass Count section and put in a number between 0 and 99. I wish there was a way to set this when configuring the scheduled task, but I have yet to fine one.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;http://www.petri.co.il/windows-memory-diagnostic-tool.htm/memdiag-extended&quot; rel=&quot;attachment wp-att-22676&quot; target=&quot;_blank&quot;&gt;&lt;img title=&quot;MemDiag-Extended&quot; alt=&quot;Windows Extended Memory Tests&quot; width=&quot;1024&quot; height=&quot;768&quot; class=&quot;Image&quot; src=&quot;http://www.517sou.net/Attach/month_1201/9wvbwa_MemDiag-Extended.png&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Figure 5 Extended Memory Tests&lt;/p&gt;&lt;p&gt;Now, it would be nice to have a more granular selection of tests or even an explanation about what all these acronyms mean. But I guess that’s why we have search engines. In any event, all that really matters is if you pass or fail. Upon completion, the computer will automatically reboot. After you logon, you should get a balloon message in the system tray. It may take a few minutes for it to appear and it will fade away as Figure 6 demonstrates.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;http://www.petri.co.il/windows-memory-diagnostic-tool.htm/memdiag-results&quot; rel=&quot;attachment wp-att-22677&quot; target=&quot;_blank&quot;&gt;&lt;img title=&quot;MemDiag-Results&quot; alt=&quot;Memory Diagnostic Result&quot; width=&quot;407&quot; height=&quot;154&quot; class=&quot;Image&quot; src=&quot;http://www.517sou.net/Attach/month_1201/o2n7ff_MemDiag-Results.png&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Figure 6 Memory Diagnostic Result&lt;/p&gt;&lt;p&gt;But at least I have no issues. You can also check the Windows event log for the results. Open the Event Viewer Management Console and select the System Event Log. Then do a search for MemoryDiagnostics-Results. Or if you’re using PowerShell, run a command like this:&lt;/p&gt;&lt;pre&gt;
PS C:\&amp;gt; get-eventlog system -after &amp;quot;12/26/2011 12:00PM&amp;quot;
-source Microsoft-Windows-MemoryDiagnostics-Results |
Select EntryType,InstanceID,Message |
format-list
EntryType : Information
InstanceId : 1201
Message : The Windows Memory Diagnostic tested the computer&apos;s memory
and detected no errors
EntryType : Information
InstanceId : 1101
Message : The Windows Memory Diagnostic tested the computer&apos;s memory
and detected no errors&lt;/pre&gt;&lt;p&gt;I’m using the –After parameter to speed up my search to only return results from the last run.&lt;/p&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;You can run this tool on both Windows 7 and Windows Server 2008. It is a simple tool in some regards but it is free and readily available. I expect most of you will have vendor or OEM supplied tools for this sort of diagnostic, but if not this is a good place to start.&lt;/p&gt;</description>
		<guid>http://www.517sou.net/Article/windows-memory-diagnostic-tool.aspx</guid>
		<trackback:ping>http://www.517sou.net/Article/754/Trackback.ashx</trackback:ping>
		<comments>http://www.517sou.net/Article/windows-memory-diagnostic-tool.aspx#CommentPostAnchor</comments>
		<wfw:commentRss>http://www.517sou.net/Article/754/Feeds.ashx</wfw:commentRss>
	</item>
	<item>
		<link>http://www.517sou.net/Article/Apache-compile-fails-and-its-solution.aspx</link>
		<title>Apache编译失败及其解决方案</title>
		<author>shanyiwan@live.com(flyinweb)</author>
		<category>WEB服务器</category>
		<pubDate>Fri, 13 Jan 2012 02:47:45 GMT</pubDate>
		<description>&lt;p&gt;1、checking for SSL_set_cert_store... no&lt;br /&gt;configure: error: ... Error, SSL/TLS libraries were missing or unusable&lt;/p&gt;&lt;p&gt;安装openssl,在编译参数中添加--with-ssl=/usr/local/ssl （ssl安装路径，根据安装的实际路径设置）&lt;/p&gt;</description>
		<guid>http://www.517sou.net/Article/Apache-compile-fails-and-its-solution.aspx</guid>
		<trackback:ping>http://www.517sou.net/Article/753/Trackback.ashx</trackback:ping>
		<comments>http://www.517sou.net/Article/Apache-compile-fails-and-its-solution.aspx#CommentPostAnchor</comments>
		<wfw:commentRss>http://www.517sou.net/Article/753/Feeds.ashx</wfw:commentRss>
	</item>
	<item>
		<link>http://www.517sou.net/Article/Nginx-as-an-IMAP-and-POP3-proxy.aspx</link>
		<title>Nginx as an IMAP/POP3 proxy</title>
		<author>shanyiwan@live.com(flyinweb)</author>
		<category>WEB服务器</category>
		<pubDate>Thu, 12 Jan 2012 03:55:12 GMT</pubDate>
		<description>&lt;p&gt;At Gigahost we are managing a lot of mailboxes for our users.&lt;/p&gt;&lt;p&gt;At the moment these are all located on one high speced server with the outgoing &lt;span class=&quot;caps&quot;&gt;SMTP&lt;/span&gt; split to another server.&lt;/p&gt;&lt;p&gt;We allow our users to connect via both &lt;span class=&quot;caps&quot;&gt;IMAP&lt;/span&gt; and POP3 and support &lt;span class=&quot;caps&quot;&gt;STARTTLS&lt;/span&gt; on ports 110/143 and &lt;span class=&quot;caps&quot;&gt;SSL&lt;/span&gt;/&lt;span class=&quot;caps&quot;&gt;TLS&lt;/span&gt; on ports 993/995.&lt;/p&gt;&lt;p&gt;Since we are constantly adding new users and these in turn add new mailboxes we are running out of options as to upgrade the current server. Hosting mailboxes via Courier, Dovecot or similar is very IO intensive and therefore in the long run disk IO becomes a problem.&lt;/p&gt;&lt;p&gt;The solution to this is ofcourse to scale the setup to more servers. Some hosting providers do this by simply adding users to a new mail server eg. &lt;code&gt;mail2.example.com&lt;/code&gt;, &lt;code&gt;mail3.example.com&lt;/code&gt; and so on.&lt;/p&gt;&lt;p&gt;What we would like to do is use a reverse proxy so that the user always connects to &lt;code&gt;mail.gigahost.dk&lt;/code&gt; and the proxy ensures that the user is send to the correct server.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Enter nginx&lt;/strong&gt;.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;http://wiki.nginx.org/Main&quot; target=&quot;_blank&quot;&gt;&lt;u&gt;&lt;font color=&quot;#0066cc&quot;&gt;nginx&lt;/font&gt;&lt;/u&gt;&lt;/a&gt; is mostly known as the reverse proxy that drives sites such as youtube.com, wordpress.com, hulu.com, github.com and many many more.&lt;/p&gt;&lt;p&gt;But nginx can also act as an &lt;span class=&quot;caps&quot;&gt;IMAP&lt;/span&gt;/POP3 proxy and does quite a good job at it.&lt;/p&gt;&lt;p&gt;Using nginx you can authenticate the mail user before she/he reaches the mailserver and specify i) if the user can be authenticated, ii) what server the user should be send to. You can infact also alter the username and do other magic stuff.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;excerpt from nginx.conf&lt;/strong&gt;&lt;/p&gt;&lt;pre class=&quot;brush: plain&quot;&gt;
                http {
                  perl_modules  perl/lib;
                  perl_require  mailauth.pm;
            
                  server {
                    location /auth {
                      perl  mailauth::handler;
                    }
                  }
                }
            
                mail {
                  auth_http  127.0.0.1:80/auth;
                  auth_http_header X-NGX-Auth-Key &amp;quot;some secret&amp;quot;;
            
                  imap_auth plain login cram-md5;
                  pop3_auth plain apop cram-md5;
                }
              &lt;/pre&gt;&lt;p&gt;In the above excerpts you will see that I use the embedded perl module in nginx (you must add this a compile time). This serves up the &lt;code&gt;mailauth.pm&lt;/code&gt; script on port 80.&lt;/p&gt;&lt;p&gt;Be aware that the embedded perl parser blocks the current nginx process – so you might consider running a few and ensure that the script executes fast.&lt;/p&gt;&lt;p&gt;The &lt;code&gt;auth_http&lt;/code&gt; setting in the nginx config is where the magic happens. This points to the &lt;span class=&quot;caps&quot;&gt;HTTP&lt;/span&gt; server that handles the authentication and find the server the connection should be proxied to.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;mailauth.pm&lt;/strong&gt;&lt;/p&gt;&lt;pre class=&quot;brush: perl&quot;&gt;
                package mailauth;
                use Digest::HMAC_MD5 qw/ hmac_md5_hex /;
                use nginx;
                use DBI;
                use URI::Escape;
                my $dsn=&amp;quot;DBI:mysql:database=postfix;host=10.0.0.1&amp;quot;;
                our $dbh=DBI-&amp;gt;connect_cached($dsn, &apos;mail-proxy&apos;, &apos;p@ssword&apos;, {AutoCommit =&amp;gt; 1, mysql_auto_reconnect =&amp;gt; 1});
              
                our $auth_ok;
                our $protocol_ports={};
                $protocol_ports-&amp;gt;{&apos;pop3&apos;}=110;
                $protocol_ports-&amp;gt;{&apos;imap&apos;}=143;
                $protocol_ports-&amp;gt;{&apos;smtp&apos;}=25;
              
                sub handler {
                  if (!$dbh-&amp;gt;ping()) {
                    ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
                    $dbh=DBI-&amp;gt;connect_cached($dsn, &apos;mail-proxy&apos;, &apos;p@ssword&apos;, {AutoCommit =&amp;gt; 1, mysql_auto_reconnect =&amp;gt; 1});
                    printf STDERR &amp;quot;%4d/%02d/%02d %02d:%02d:%02d [notice] : MySQL server connection lost. Reconnecting.\n&amp;quot;, $year+1900,$mon+1,$mday,$hour,$min,$sec;
                  }
                  
                  my $r = shift;
              
                  my $auth_method = $r-&amp;gt;header_in(&amp;quot;Auth-Method&amp;quot;);
                  my $username = uri_unescape($r-&amp;gt;header_in(&amp;quot;Auth-User&amp;quot;));
                  my $password = uri_unescape($r-&amp;gt;header_in(&amp;quot;Auth-Pass&amp;quot;));
                  my $salt = $r-&amp;gt;header_in(&amp;quot;Auth-Salt&amp;quot;);
              
                  our $sth=$dbh-&amp;gt;prepare(&amp;quot;select clear from users where email=? limit 1&amp;quot;); 
                  $sth-&amp;gt;execute($username);
                  my $hash=$sth-&amp;gt;fetchrow_hashref();
                  my $real_password = $hash-&amp;gt;{&apos;clear&apos;};
              
                  # Authorize user
                  if (($auth_method eq &amp;quot;plain&amp;quot; &amp;amp;&amp;amp; $password eq $real_password) or
                    ($auth_method eq &amp;quot;cram-md5&amp;quot; &amp;amp;&amp;amp; $password eq hmac_md5_hex($salt, $real_password))) {
                    # Auth OK, find mail server
                    our $sth=$dbh-&amp;gt;prepare(&amp;quot;select destination_mailstore from transport where domain=? limit 1&amp;quot;); 
                    my $domain = $r-&amp;gt;header_in(&amp;quot;Auth-User&amp;quot;);
                    $domain =~ s/^.*@//; # remove @ and everything before 
                    $sth-&amp;gt;execute($domain);
                    my $hash=$sth-&amp;gt;fetchrow_hashref();
                    my $mailserver = $hash-&amp;gt;{&apos;destination_mailstore&apos;};
                    $mailserver =~ s/smtp://;
              
                    $r-&amp;gt;header_out(&amp;quot;Auth-User&amp;quot;, $username);
                    $r-&amp;gt;header_out(&amp;quot;Auth-Pass&amp;quot;, $real_password);
                    $r-&amp;gt;header_out(&amp;quot;Auth-Status&amp;quot;, &amp;quot;OK&amp;quot;);
                    $r-&amp;gt;header_out(&amp;quot;Auth-Server&amp;quot;, $mailserver);
                    $r-&amp;gt;header_out(&amp;quot;Auth-Port&amp;quot;, $protocol_ports-&amp;gt;{$r-&amp;gt;header_in(&amp;quot;Auth-Protocol&amp;quot;)});
                    
                    # Shared secret to ensure that the request comes from this script
                    $r-&amp;gt;header_out(&amp;quot;X-NGX-Auth-Key&amp;quot;, &amp;quot;some secret&amp;quot;);
                  } else {
                    $r-&amp;gt;header_out(&amp;quot;Auth-Status&amp;quot;, &amp;quot;Invalid login or password&amp;quot;);
                  }
              
                  $r-&amp;gt;send_http_header(&amp;quot;text/html&amp;quot;);
              
                  return OK;
                }
              
                1;
                __END__
              &lt;/pre&gt;&lt;p&gt;The above script supports both plain and &lt;span class=&quot;caps&quot;&gt;CRAM&lt;/span&gt;-MD5 authentication. The request headers set by nginx are visible as &lt;code&gt;header_in(&amp;quot;...&amp;quot;)&lt;/code&gt; and the response headers that the script sets are &lt;code&gt;header_out&lt;/code&gt;.&lt;/p&gt;&lt;p&gt;It should be pretty self-explanatory what the script does and how. The main feature here is ofcourse setting the &lt;code&gt;Auth-Server&lt;/code&gt; response header to the mailserver where you would like to point the user.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span class=&quot;caps&quot;&gt;UPDATE&lt;/span&gt; 2011/02/08:&lt;/strong&gt;&lt;br /&gt;nginx sends the &lt;span class=&quot;caps&quot;&gt;HTTP&lt;/span&gt; headers for the auth script &lt;em&gt;urlencoded&lt;/em&gt;. Therefore it is emparative that they be decoded so passwords like &lt;code&gt;my little p%ony&lt;/code&gt; works.&lt;/p&gt;&lt;p&gt;I’ve updated the script here to make use of the Perl uri library (you might have to install this).&lt;/p&gt;&lt;p&gt;Also I’ve added a small check to ensure that the MySQL connection is still alive and if not reconnect.&lt;/p&gt;&lt;p&gt;It seems that either my Perl script or the nginx embedded Perl module suffers from memory leaks.&lt;/p&gt;&lt;p&gt;Now, the easy way to fix this would be to run a &lt;code&gt;/etc/init.d/nginx restart&lt;/code&gt; every so often. However, that would of course suck.&lt;/p&gt;&lt;p&gt;So I started looking into alternative ways, using FastCGI to serve the authentication script.&lt;/p&gt;&lt;p&gt;The normal &lt;code&gt;fcgiwrapper&lt;/code&gt; in Debian was way to slow though. Handling only about 30 requests/sec.&lt;/p&gt;&lt;p&gt;Enter &lt;a href=&quot;http://search.cpan.org/~onlyjob/FCGI-Daemon-0.20111014/lib/FCGI/Daemon.pm&quot; target=&quot;_blank&quot;&gt;&lt;u&gt;&lt;font color=&quot;#0066cc&quot;&gt;&lt;span class=&quot;caps&quot;&gt;FCGI&lt;/span&gt;-Daemon&lt;/font&gt;&lt;/u&gt;&lt;/a&gt; by Dmitry Smirnov. It works by keeping the processes alive not respawning Perl on every request.&lt;/p&gt;&lt;p&gt;With this I was able to achieve 2500-3000 request/sec. More than enough to handle &lt;span class=&quot;caps&quot;&gt;IMAP&lt;/span&gt;/POP3 authentications.&lt;/p&gt;&lt;p&gt;I’ve included an updated authentication script for use with this.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;auth.pl&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;&lt;pre class=&quot;brush: perl&quot;&gt;
               #!/usr/bin/perl
            
               use Digest::HMAC_MD5 qw/ hmac_md5_hex /;
               use DBI;
               use URI::Escape;
               use CGI;
            
               print &amp;quot;Content-type: text/html\n&amp;quot;;
            
               my $q = CGI-&amp;gt;new;
               my $auth_shared_secret = $q-&amp;gt;http(&amp;quot;X-NGX-Auth-Key&amp;quot;);
            
               # Shared secret to ensure that the request comes from nginx
               if ( $auth_shared_secret ne &amp;quot;your secret&amp;quot; ) {
                 print &amp;quot;Auth-Status: Authentication failed.\n\n&amp;quot;;
                 print STDERR &amp;quot;Wrong X-NGC-Auth-Key $auth_shared_secret&amp;quot;;
                 exit(0);
               }
            
               my $dsn = &amp;quot;DBI:mysql:database=postfix;host=1.2.3.4&amp;quot;;
               our $dbh =
                 DBI-&amp;gt;connect_cached( $dsn, &apos;mailproxy&apos;, &apos;p@ssw0rd&apos;,
                   { AutoCommit =&amp;gt; 1, mysql_auto_reconnect =&amp;gt; 1 } );
            
               our $auth_ok;
               our $protocol_ports = {};
               $protocol_ports-&amp;gt;{&apos;pop3&apos;} = 110;
               $protocol_ports-&amp;gt;{&apos;imap&apos;} = 143;
               $protocol_ports-&amp;gt;{&apos;smtp&apos;} = 25;
            
               if ( !defined $dbh || !$dbh-&amp;gt;ping() ) {
                   ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) =
                     localtime(time);
                   $dbh =
                     DBI-&amp;gt;connect_cached( $dsn, &apos;mailproxy&apos;, &apos;p@ssw0rd&apos;,
                       { AutoCommit =&amp;gt; 1, mysql_auto_reconnect =&amp;gt; 1 } );
                   printf STDERR
               &amp;quot;%4d/%02d/%02d %02d:%02d:%02d [notice] : MySQL server connection lost. Reconnecting.\n&amp;quot;,
                     $year + 1900, $mon + 1, $mday, $hour, $min, $sec;
               }
            
               my $auth_method = $q-&amp;gt;http(&amp;quot;Auth-Method&amp;quot;);
               my $username    = uri_unescape( $q-&amp;gt;http(&amp;quot;Auth-User&amp;quot;) );
               my $password    = uri_unescape( $q-&amp;gt;http(&amp;quot;Auth-Pass&amp;quot;) );
               my $salt        = $q-&amp;gt;http(&amp;quot;Auth-Salt&amp;quot;);
            
               our $sth = $dbh-&amp;gt;prepare(&amp;quot;select clear from users where email=? limit 1&amp;quot;);
               $sth-&amp;gt;execute($username);
               my $hash          = $sth-&amp;gt;fetchrow_hashref();
               my $real_password = $hash-&amp;gt;{&apos;clear&apos;};
            
               # Authorize user
               if (
                   ( $auth_method eq &amp;quot;plain&amp;quot; &amp;amp;&amp;amp; $password eq $real_password )
                   or (   $auth_method eq &amp;quot;cram-md5&amp;quot;
                       &amp;amp;&amp;amp; $password eq hmac_md5_hex( $salt, $real_password ) )
                 )
               {
            
                   # Auth OK, find mail server
                   our $sth = $dbh-&amp;gt;prepare(
                       &amp;quot;select destination_mailstore from transport where domain=? limit 1&amp;quot;);
                   my $domain = $q-&amp;gt;http(&amp;quot;Auth-User&amp;quot;);
            
                   # remove @ and everything before
                   $domain =~ s/^.*@//;
                   $sth-&amp;gt;execute($domain);
                   my $hash       = $sth-&amp;gt;fetchrow_hashref();
                   my $mailserver = $hash-&amp;gt;{&apos;destination_mailstore&apos;};
                   $mailserver =~ s/smtp://;
            
                   print &amp;quot;Auth-User: $username\n&amp;quot;;
                   print &amp;quot;Auth-Pass: $real_password\n&amp;quot;;
                   print &amp;quot;Auth-Status: OK\n&amp;quot;;
                   print &amp;quot;Auth-Server: $mailserver\n&amp;quot;;
                   $auth_port = $protocol_ports-&amp;gt;{ $q-&amp;gt;http(&amp;quot;Auth-Protocol&amp;quot;) };
                   print &amp;quot;Auth-Port: $auth_port\n&amp;quot;;
               }
               else {
                   print &amp;quot;Auth-Status: Authentication failed.\n&amp;quot;;
               }
            
               print &amp;quot;\n&amp;quot;;&lt;/pre&gt;&lt;p&gt;&lt;/p&gt;&lt;pre&gt;
#!/usr/bin/perl
use Digest::HMAC_MD5 qw/ hmac_md5_hex /;
use DBI;
use URI::Escape;
use CGI;
print &amp;quot;Content-type: text/html\n&amp;quot;;
my $q = CGI-&amp;gt;new;
my $auth_shared_secret = $q-&amp;gt;http(&amp;quot;X-NGX-Auth-Key&amp;quot;);
# Shared secret to ensure that the request comes from nginx
if ( $auth_shared_secret ne &amp;quot;your secret&amp;quot; ) {
  print &amp;quot;Auth-Status: Authentication failed.\n\n&amp;quot;;
  print STDERR &amp;quot;Wrong X-NGC-Auth-Key $auth_shared_secret&amp;quot;;
  exit(0);
}
my $dsn = &amp;quot;DBI:mysql:database=postfix;host=1.2.3.4&amp;quot;;
our $dbh =
  DBI-&amp;gt;connect_cached( $dsn, &apos;mailproxy&apos;, &apos;p@ssw0rd&apos;,
    { AutoCommit =&amp;gt; 1, mysql_auto_reconnect =&amp;gt; 1 } );
our $auth_ok;
our $protocol_ports = {};
$protocol_ports-&amp;gt;{&apos;pop3&apos;} = 110;
$protocol_ports-&amp;gt;{&apos;imap&apos;} = 143;
$protocol_ports-&amp;gt;{&apos;smtp&apos;} = 25;
if ( !defined $dbh || !$dbh-&amp;gt;ping() ) {
    ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) =
      localtime(time);
    $dbh =
      DBI-&amp;gt;connect_cached( $dsn, &apos;mailproxy&apos;, &apos;p@ssw0rd&apos;,
        { AutoCommit =&amp;gt; 1, mysql_auto_reconnect =&amp;gt; 1 } );
    printf STDERR
&amp;quot;%4d/%02d/%02d %02d:%02d:%02d [notice] : MySQL server connection lost. Reconnecting.\n&amp;quot;,
      $year + 1900, $mon + 1, $mday, $hour, $min, $sec;
}
my $auth_method = $q-&amp;gt;http(&amp;quot;Auth-Method&amp;quot;);
my $username    = uri_unescape( $q-&amp;gt;http(&amp;quot;Auth-User&amp;quot;) );
my $password    = uri_unescape( $q-&amp;gt;http(&amp;quot;Auth-Pass&amp;quot;) );
my $salt        = $q-&amp;gt;http(&amp;quot;Auth-Salt&amp;quot;);
our $sth = $dbh-&amp;gt;prepare(&amp;quot;select clear from users where email=? limit 1&amp;quot;);
$sth-&amp;gt;execute($username);
my $hash          = $sth-&amp;gt;fetchrow_hashref();
my $real_password = $hash-&amp;gt;{&apos;clear&apos;};
# Authorize user
if (
    ( $auth_method eq &amp;quot;plain&amp;quot; &amp;amp;&amp;amp; $password eq $real_password )
    or (   $auth_method eq &amp;quot;cram-md5&amp;quot;
        &amp;amp;&amp;amp; $password eq hmac_md5_hex( $salt, $real_password ) )
  )
{
    # Auth OK, find mail server
    our $sth = $dbh-&amp;gt;prepare(
        &amp;quot;select destination_mailstore from transport where domain=? limit 1&amp;quot;);
    my $domain = $q-&amp;gt;http(&amp;quot;Auth-User&amp;quot;);
    # remove @ and everything before
    $domain =~ s/^.*@//;
    $sth-&amp;gt;execute($domain);
    my $hash       = $sth-&amp;gt;fetchrow_hashref();
    my $mailserver = $hash-&amp;gt;{&apos;destination_mailstore&apos;};
    $mailserver =~ s/smtp://;
    print &amp;quot;Auth-User: $username\n&amp;quot;;
    print &amp;quot;Auth-Pass: $real_password\n&amp;quot;;
    print &amp;quot;Auth-Status: OK\n&amp;quot;;
    print &amp;quot;Auth-Server: $mailserver\n&amp;quot;;
    $auth_port = $protocol_ports-&amp;gt;{ $q-&amp;gt;http(&amp;quot;Auth-Protocol&amp;quot;) };
    print &amp;quot;Auth-Port: $auth_port\n&amp;quot;;
}
else {
    print &amp;quot;Auth-Status: Authentication failed.\n&amp;quot;;
}
print &amp;quot;\n&amp;quot;;
&lt;/pre&gt;</description>
		<guid>http://www.517sou.net/Article/Nginx-as-an-IMAP-and-POP3-proxy.aspx</guid>
		<trackback:ping>http://www.517sou.net/Article/752/Trackback.ashx</trackback:ping>
		<comments>http://www.517sou.net/Article/Nginx-as-an-IMAP-and-POP3-proxy.aspx#CommentPostAnchor</comments>
		<wfw:commentRss>http://www.517sou.net/Article/752/Feeds.ashx</wfw:commentRss>
	</item>
	<item>
		<link>http://www.517sou.net/Article/Nginx-as-an-IMAP-SMTP-POP3-Reverse-Proxy.aspx</link>
		<title>基于nginx的pop3/imap/smtp的反向代理解决方案</title>
		<author>shanyiwan@live.com(flyinweb)</author>
		<category>技术文摘</category>
		<pubDate>Thu, 12 Jan 2012 03:44:05 GMT</pubDate>
		<description>&lt;p&gt;&lt;b&gt;&lt;span id=&quot;Using_a_php_script_on_apache_server_as_the_auth_backend&quot; class=&quot;mw-headline&quot;&gt;1、Using a php script on apache server as the auth backend &lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Start with the configuration from NginxImapProxyExample. For detail information about different configuration parameters, see the &lt;a href=&quot;http://wiki.nginx.org/MailCoreModule&quot; target=&quot;_blank&quot;&gt;NginxMailCoreModule&lt;/a&gt; page.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;ol&gt;&lt;li&gt;Your Proxy server for pop/imap is running on 192.168.1.1&lt;/li&gt;&lt;li&gt;You have 2 backend pop/imap servers: 192.168.1.22 and 192.168.1.33&lt;/li&gt;&lt;li&gt;You have a webserver that you will use for the authentication and redirection logic 192.168.1.44.&lt;/li&gt;&lt;li&gt;The authentication script is /mail/auth.php &lt;/li&gt;&lt;/ol&gt;&lt;p&gt;nginx.conf&lt;/p&gt;&lt;pre&gt;&lt;ol class=&quot;dp-other&quot;&gt;&lt;li class=&quot;alt&quot;&gt;&lt;span&gt;&lt;span&gt;user&amp;nbsp;&amp;nbsp;nobody; &amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span&gt;worker_processes&amp;nbsp;&amp;nbsp;1; &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class=&quot;alt&quot;&gt;&lt;span&gt;error_log&amp;nbsp;&amp;nbsp;logs/error.log&amp;nbsp;&amp;nbsp;info; &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span&gt;pid&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;logs/nginx.pid; &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class=&quot;alt&quot;&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span&gt;events&amp;nbsp;{ &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class=&quot;alt&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;worker_connections&amp;nbsp;&amp;nbsp;1024; &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;multi_accept&amp;nbsp;on; &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class=&quot;alt&quot;&gt;&lt;span&gt;} &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class=&quot;alt&quot;&gt;&lt;span&gt;mail&amp;nbsp;{ &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;auth_http&amp;nbsp;&amp;nbsp;192.168.1.44:80/mail/auth.php; &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class=&quot;alt&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;pop3_capabilities&amp;nbsp;&amp;nbsp;&amp;quot;TOP&amp;quot;&amp;nbsp;&amp;nbsp;&amp;quot;USER&amp;quot;; &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;imap_capabilities&amp;nbsp;&amp;nbsp;&amp;quot;IMAP4rev1&amp;quot;&amp;nbsp;&amp;nbsp;&amp;quot;UIDPLUS&amp;quot;; &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class=&quot;alt&quot;&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;server&amp;nbsp;{ &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class=&quot;alt&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;listen&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;110; &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;protocol&amp;nbsp;&amp;nbsp;&amp;nbsp;pop3; &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class=&quot;alt&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;proxy&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;on; &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;} &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class=&quot;alt&quot;&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;server&amp;nbsp;{ &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class=&quot;alt&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;listen&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;143; &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;protocol&amp;nbsp;&amp;nbsp;&amp;nbsp;imap; &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class=&quot;alt&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;proxy&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;on; &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;} &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class=&quot;alt&quot;&gt;&lt;span&gt;}&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/pre&gt;&lt;div style=&quot;text-align: left&quot; dir=&quot;ltr&quot; class=&quot;mw-geshi&quot;&gt;&lt;div class=&quot;nginx source-nginx&quot;&gt;/mail/auth.php&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left&quot; dir=&quot;ltr&quot; class=&quot;mw-geshi&quot;&gt;&lt;div class=&quot;php source-php&quot;&gt;&lt;pre&gt;&lt;ol class=&quot;dp-c&quot;&gt;&lt;li class=&quot;alt&quot;&gt;&lt;span&gt;&lt;span&gt;&amp;lt;?php &amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class=&quot;comment&quot;&gt;/* &lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;li class=&quot;alt&quot;&gt;&lt;span&gt;&lt;span class=&quot;comment&quot;&gt;Nginx&amp;nbsp;sends&amp;nbsp;headers&amp;nbsp;as &lt;/span&gt;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span&gt;&lt;span class=&quot;comment&quot;&gt;Auth-User:&amp;nbsp;somuser &lt;/span&gt;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class=&quot;alt&quot;&gt;&lt;span&gt;&lt;span class=&quot;comment&quot;&gt;Auth-Pass:&amp;nbsp;somepass &lt;/span&gt;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span&gt;&lt;span class=&quot;comment&quot;&gt;On&amp;nbsp;my&amp;nbsp;php&amp;nbsp;app&amp;nbsp;server&amp;nbsp;these&amp;nbsp;are&amp;nbsp;seen&amp;nbsp;as &lt;/span&gt;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class=&quot;alt&quot;&gt;&lt;span&gt;&lt;span class=&quot;comment&quot;&gt;HTTP_AUTH_USER&amp;nbsp;and&amp;nbsp;HTTP_AUTH_PASS &lt;/span&gt;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span&gt;&lt;span class=&quot;comment&quot;&gt;*/&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class=&quot;alt&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt;&lt;span&gt;&amp;nbsp;(!isset(&lt;/span&gt;&lt;span class=&quot;vars&quot;&gt;$_SERVER&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;&amp;quot;HTTP_AUTH_USER&amp;quot;&lt;/span&gt;&lt;span&gt;]&amp;nbsp;)&amp;nbsp;||&amp;nbsp;!isset(&lt;/span&gt;&lt;span class=&quot;vars&quot;&gt;$_SERVER&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;&amp;quot;HTTP_AUTH_PASS&amp;quot;&lt;/span&gt;&lt;span&gt;]&amp;nbsp;)){ &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;fail(); &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class=&quot;alt&quot;&gt;&lt;span&gt;} &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class=&quot;vars&quot;&gt;$username&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span class=&quot;vars&quot;&gt;$_SERVER&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;&amp;quot;HTTP_AUTH_USER&amp;quot;&lt;/span&gt;&lt;span&gt;]&amp;nbsp;; &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class=&quot;alt&quot;&gt;&lt;span class=&quot;vars&quot;&gt;$userpass&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span class=&quot;vars&quot;&gt;$_SERVER&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;&amp;quot;HTTP_AUTH_PASS&amp;quot;&lt;/span&gt;&lt;span&gt;]&amp;nbsp;; &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class=&quot;vars&quot;&gt;$protocol&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span class=&quot;vars&quot;&gt;$_SERVER&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;&amp;quot;HTTP_AUTH_PROTOCOL&amp;quot;&lt;/span&gt;&lt;span&gt;]&amp;nbsp;; &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class=&quot;alt&quot;&gt;&lt;span class=&quot;comment&quot;&gt;//&amp;nbsp;default&amp;nbsp;backend&amp;nbsp;port &lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class=&quot;vars&quot;&gt;$backend_port&lt;/span&gt;&lt;span&gt;=110; &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class=&quot;alt&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt;&lt;span&gt;&amp;nbsp;(&lt;/span&gt;&lt;span class=&quot;vars&quot;&gt;$protocol&lt;/span&gt;&lt;span&gt;==&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;&amp;quot;imap&amp;quot;&lt;/span&gt;&lt;span&gt;)&amp;nbsp;{ &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;vars&quot;&gt;$backend_port&lt;/span&gt;&lt;span&gt;=143; &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class=&quot;alt&quot;&gt;&lt;span&gt;} &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt;&lt;span&gt;&amp;nbsp;(&lt;/span&gt;&lt;span class=&quot;vars&quot;&gt;$protocol&lt;/span&gt;&lt;span&gt;==&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;&amp;quot;smtp&amp;quot;&lt;/span&gt;&lt;span&gt;)&amp;nbsp;{ &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class=&quot;alt&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;vars&quot;&gt;$backend_port&lt;/span&gt;&lt;span&gt;=25; &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span&gt;} &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class=&quot;alt&quot;&gt;&lt;span class=&quot;comment&quot;&gt;//&amp;nbsp;nginx&amp;nbsp;likes&amp;nbsp;ip&amp;nbsp;address&amp;nbsp;so&amp;nbsp;if&amp;nbsp;your &lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class=&quot;comment&quot;&gt;//&amp;nbsp;application&amp;nbsp;gives&amp;nbsp;back&amp;nbsp;hostname,&amp;nbsp;convert&amp;nbsp;it&amp;nbsp;to&amp;nbsp;ip&amp;nbsp;address&amp;nbsp;here &lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class=&quot;alt&quot;&gt;&lt;span class=&quot;vars&quot;&gt;$backend_ip&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;&amp;quot;mailhost01&amp;quot;&lt;/span&gt;&lt;span&gt;]&amp;nbsp;=&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;&amp;quot;192.168.1.22&amp;quot;&lt;/span&gt;&lt;span&gt;; &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class=&quot;vars&quot;&gt;$backend_ip&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;&amp;quot;mailhost02&amp;quot;&lt;/span&gt;&lt;span&gt;]&amp;nbsp;=&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;&amp;quot;192.168.1.33&amp;quot;&lt;/span&gt;&lt;span&gt;; &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class=&quot;alt&quot;&gt;&lt;span class=&quot;comment&quot;&gt;//&amp;nbsp;Authenticate&amp;nbsp;the&amp;nbsp;user&amp;nbsp;or&amp;nbsp;fail &lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt;&lt;span&gt;&amp;nbsp;(!authuser(&lt;/span&gt;&lt;span class=&quot;vars&quot;&gt;$username&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;vars&quot;&gt;$userpass&lt;/span&gt;&lt;span&gt;)){ &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class=&quot;alt&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;fail(); &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;func&quot;&gt;exit&lt;/span&gt;&lt;span&gt;; &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class=&quot;alt&quot;&gt;&lt;span&gt;} &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class=&quot;comment&quot;&gt;//&amp;nbsp;Get&amp;nbsp;the&amp;nbsp;server&amp;nbsp;for&amp;nbsp;this&amp;nbsp;user&amp;nbsp;if&amp;nbsp;we&amp;nbsp;have&amp;nbsp;reached&amp;nbsp;so&amp;nbsp;far &lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class=&quot;alt&quot;&gt;&lt;span class=&quot;vars&quot;&gt;$userserver&lt;/span&gt;&lt;span&gt;=getmailserver(&lt;/span&gt;&lt;span class=&quot;vars&quot;&gt;$username&lt;/span&gt;&lt;span&gt;); &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class=&quot;comment&quot;&gt;//&amp;nbsp;Get&amp;nbsp;the&amp;nbsp;ip&amp;nbsp;address&amp;nbsp;of&amp;nbsp;the&amp;nbsp;server &lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class=&quot;alt&quot;&gt;&lt;span class=&quot;comment&quot;&gt;//&amp;nbsp;We&amp;nbsp;are&amp;nbsp;assuming&amp;nbsp;that&amp;nbsp;you&amp;nbsp;backend&amp;nbsp;returns&amp;nbsp;hostname &lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class=&quot;comment&quot;&gt;//&amp;nbsp;We&amp;nbsp;try&amp;nbsp;to&amp;nbsp;get&amp;nbsp;the&amp;nbsp;ip&amp;nbsp;else&amp;nbsp;return&amp;nbsp;what&amp;nbsp;we&amp;nbsp;got&amp;nbsp;back &lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class=&quot;alt&quot;&gt;&lt;span class=&quot;vars&quot;&gt;$server_ip&lt;/span&gt;&lt;span&gt;=(isset(&lt;/span&gt;&lt;span class=&quot;vars&quot;&gt;$backend_ip&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;vars&quot;&gt;$userserver&lt;/span&gt;&lt;span&gt;]))?&lt;/span&gt;&lt;span class=&quot;vars&quot;&gt;$backend_ip&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;vars&quot;&gt;$userserver&lt;/span&gt;&lt;span&gt;]&amp;nbsp;:&lt;/span&gt;&lt;span class=&quot;vars&quot;&gt;$userserver&lt;/span&gt;&lt;span&gt;; &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class=&quot;comment&quot;&gt;//&amp;nbsp;Pass! &lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class=&quot;alt&quot;&gt;&lt;span&gt;pass(&lt;/span&gt;&lt;span class=&quot;vars&quot;&gt;$server_ip&lt;/span&gt;&lt;span&gt;,&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;vars&quot;&gt;$backend_port&lt;/span&gt;&lt;span&gt;); &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class=&quot;alt&quot;&gt;&lt;span class=&quot;comment&quot;&gt;//END &lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class=&quot;alt&quot;&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;&lt;span&gt;&amp;nbsp;authuser(&lt;/span&gt;&lt;span class=&quot;vars&quot;&gt;$user&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;vars&quot;&gt;$pass&lt;/span&gt;&lt;span&gt;){ &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class=&quot;alt&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;comment&quot;&gt;//&amp;nbsp;put&amp;nbsp;your&amp;nbsp;logic&amp;nbsp;here&amp;nbsp;to&amp;nbsp;authen&amp;nbsp;the&amp;nbsp;user&amp;nbsp;to&amp;nbsp;any&amp;nbsp;backend &lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;comment&quot;&gt;//&amp;nbsp;you&amp;nbsp;want&amp;nbsp;(datbase,&amp;nbsp;ldap,&amp;nbsp;etc) &lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class=&quot;alt&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;comment&quot;&gt;//&amp;nbsp;for&amp;nbsp;example,&amp;nbsp;we&amp;nbsp;will&amp;nbsp;just&amp;nbsp;return&amp;nbsp;true; &lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt;&lt;span&gt;&amp;nbsp;true; &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class=&quot;alt&quot;&gt;&lt;span&gt;} &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class=&quot;alt&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;&lt;span&gt;&amp;nbsp;getmailserver(&lt;/span&gt;&lt;span class=&quot;vars&quot;&gt;$user&lt;/span&gt;&lt;span&gt;){ &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;comment&quot;&gt;//&amp;nbsp;put&amp;nbsp;the&amp;nbsp;logic&amp;nbsp;here&amp;nbsp;to&amp;nbsp;get&amp;nbsp;the&amp;nbsp;mailserver &lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class=&quot;alt&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;comment&quot;&gt;//&amp;nbsp;backend&amp;nbsp;for&amp;nbsp;the&amp;nbsp;user.&amp;nbsp;You&amp;nbsp;can&amp;nbsp;get&amp;nbsp;this&amp;nbsp;from &lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;comment&quot;&gt;//&amp;nbsp;some&amp;nbsp;database&amp;nbsp;or&amp;nbsp;ldap&amp;nbsp;etc &lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class=&quot;alt&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;comment&quot;&gt;//&amp;nbsp;dummy&amp;nbsp;logic,&amp;nbsp;all&amp;nbsp;users&amp;nbsp;that&amp;nbsp;start&amp;nbsp;with&amp;nbsp;a,c,f&amp;nbsp;and&amp;nbsp;g&amp;nbsp;get&amp;nbsp;mailhost01 &lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;comment&quot;&gt;//&amp;nbsp;the&amp;nbsp;others&amp;nbsp;get&amp;nbsp;mailhost02 &lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class=&quot;alt&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt;&lt;span&gt;&amp;nbsp;in_array(&lt;/span&gt;&lt;span class=&quot;func&quot;&gt;substr&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;vars&quot;&gt;$user&lt;/span&gt;&lt;span&gt;,0,1),&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;keyword&quot;&gt;array&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;&amp;quot;a&amp;quot;&lt;/span&gt;&lt;span&gt;,&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;&amp;quot;c&amp;quot;&lt;/span&gt;&lt;span&gt;,&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;&amp;quot;f&amp;quot;&lt;/span&gt;&lt;span&gt;,&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;&amp;quot;g&amp;quot;&lt;/span&gt;&lt;span&gt;)){ &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;&amp;quot;mailhost01&amp;quot;&lt;/span&gt;&lt;span&gt;; &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class=&quot;alt&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;keyword&quot;&gt;else&lt;/span&gt;&lt;span&gt;&amp;nbsp;{ &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;&amp;quot;mailhost02&amp;quot;&lt;/span&gt;&lt;span&gt;; &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class=&quot;alt&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;} &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span&gt;} &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class=&quot;alt&quot;&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;&lt;span&gt;&amp;nbsp;fail(){ &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class=&quot;alt&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;header(&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;&amp;quot;Auth-Status:&amp;nbsp;Invalid&amp;nbsp;login&amp;nbsp;or&amp;nbsp;password&amp;quot;&lt;/span&gt;&lt;span&gt;); &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;func&quot;&gt;exit&lt;/span&gt;&lt;span&gt;; &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class=&quot;alt&quot;&gt;&lt;span&gt;} &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class=&quot;alt&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;&lt;span&gt;&amp;nbsp;pass(&lt;/span&gt;&lt;span class=&quot;vars&quot;&gt;$server&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;vars&quot;&gt;$port&lt;/span&gt;&lt;span&gt;){ &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;header(&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;&amp;quot;Auth-Status:&amp;nbsp;OK&amp;quot;&lt;/span&gt;&lt;span&gt;); &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class=&quot;alt&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;header(&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;&amp;quot;Auth-Server:&amp;nbsp;$server&amp;quot;&lt;/span&gt;&lt;span&gt;); &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;header(&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;&amp;quot;Auth-Port:&amp;nbsp;$port&amp;quot;&lt;/span&gt;&lt;span&gt;); &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class=&quot;alt&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;func&quot;&gt;exit&lt;/span&gt;&lt;span&gt;; &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span&gt;} &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li class=&quot;alt&quot;&gt;&lt;span&gt;?&amp;gt;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;printfooter&quot;&gt;Retrieved from &amp;quot;&lt;a href=&quot;http://wiki.nginx.org/index.php?title=ImapAuthenticateWithApachePhpScript&amp;amp;oldid=178&quot; target=&quot;_blank&quot;&gt;&lt;u&gt;&lt;font color=&quot;#0066cc&quot;&gt;http://wiki.nginx.org/index.php?title=ImapAuthenticateWithApachePhpScript&amp;amp;oldid=178&lt;/font&gt;&lt;/u&gt;&lt;/a&gt;&amp;quot;&lt;/div&gt;&lt;div class=&quot;printfooter&quot;&gt;&lt;b&gt;2、基于nginx的pop3/imap/smtp的反向代理解决方案&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;printfooter&quot;&gt;&lt;strong&gt;本文介绍基于nginx的邮局反向代理配置方案。nginx对来源于客户端的pop3/smtp/imap请求予以转发到后端postfix，后端邮件服务器采用postfix 2.8.0，已配置并正常运行。&lt;/strong&gt;&lt;/div&gt;&lt;div class=&quot;printfooter&quot;&gt;&lt;strong&gt;配置nginx.conf&lt;/strong&gt;：&lt;blockquote&gt;&lt;p&gt;#user nobody;&lt;br /&gt;worker_processes 1;&lt;br /&gt;error_log logs/error.log info;&lt;br /&gt;events {&lt;br /&gt;worker_connections 1024;&lt;br /&gt;}&lt;br /&gt;mail {&lt;br /&gt;auth_http 指定IP:80/auth.php;&lt;br /&gt;pop3_capabilities &amp;quot;TOP&amp;quot; &amp;quot;USER&amp;quot;;&lt;br /&gt;imap_capabilities &amp;quot;IMAP4rev1&amp;quot; &amp;quot;UIDPLUS&amp;quot;;&lt;br /&gt;&lt;br /&gt;server {&lt;br /&gt;listen 110;&lt;br /&gt;protocol pop3;&lt;br /&gt;proxy on;&lt;br /&gt;}&lt;br /&gt;server {&lt;br /&gt;listen 143;&lt;br /&gt;protocol imap;&lt;br /&gt;proxy on;&lt;br /&gt;}&lt;br /&gt;server {&lt;br /&gt;listen 25;&lt;br /&gt;protocol smtp;&lt;br /&gt;proxy on;&lt;br /&gt;smtp_auth login plain;&lt;br /&gt;xclient off;&lt;br /&gt;}&lt;br /&gt;}&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;strong&gt;说明：&lt;/strong&gt;&lt;br /&gt;1.安装nginx时禁掉了http（–without-http），因为我们的目标只是转发pop3/smtp/imap请求，故nginx.conf也是相当简单，只有mail模块。如果还需要代理80端口（例如webmail），可以自行编译对http的支持。&lt;/p&gt;&lt;p&gt;2.smtp的配置模块里必须加入xclient off，否则当nginx向后转发smtp请求时，postfix将报“lost connection after XCLIENT”，同时nginx报“550 5.7.0 Error: insufficient authorization”. nginx对smtp的代理，与pop3/imap是不同的，详细见后文。&lt;/p&gt;&lt;p&gt;3.指定IP是用于认证的，需要放认证脚本auth.php. 认证脚本的作用就是验证用户和密码，一般自定义，可以放在任意的服务器上。本方案中选择放在后端邮件服务器上，便于管理。&lt;/p&gt;&lt;p&gt;这里有一个问题，postfix本身已经集成了认证机制（本人采用的是cyrus sasl2+courier-authlib），为什么加了反向代理，认证过程就要移动到反向代理上呢？这样岂不是就变成非透明代理了吗？为什么不作纯碎的透明代理呢？&lt;br /&gt;根据测试，如果这个认证脚本不设验证，直接透传所有pop3/imap请求到后端，在后端邮件服务器还会进行一次认证，但是对于smtp请求，将不再认证，而直接按照转发规则进行转发（因为反向代理的ip加到了postfix的mynetworks中，见后文）。这两种不同的差异应该是跟协议有关。&lt;br /&gt;为了保持统一，在本文的方案中，auth.php集成了pop3/imap/smtp的三种认证。这样的功能架构类似于游戏服务器的，登录服务器和游戏服务器是分开的。&lt;/p&gt;&lt;p&gt;4.在邮件服务器postfix/etc/main.cf中，修改mynetworks值，加入本反向代理的ip，并重载postfix：postfix -s reload&lt;/p&gt;&lt;p&gt;关于xclient：xclient的作用，是将前端的服务器模拟作为一个邮件客户端，而向后端的postfix进行认证和执行发送，但是postfix还需要一个打patch才能完美支持xclient。&lt;br /&gt;关于此问题的讨论可以参见 &lt;a href=&quot;http://forum.nginx.org/read.php?2,173197,173246#msg-173246&quot; target=&quot;_blank&quot;&gt;&lt;u&gt;&lt;font color=&quot;#0066cc&quot;&gt;http://forum.nginx.org/read.php?2,173197,173246#msg-173246&lt;/font&gt;&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;auth.php：&lt;/strong&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&amp;lt;?php&lt;br /&gt;/**&lt;br /&gt;* @see xiabaibai.net&lt;br /&gt;*/&lt;br /&gt;if(!isset($_SERVER [&amp;quot;HTTP_AUTH_USER&amp;quot;] ) || ! isset($_SERVER [&amp;quot;HTTP_AUTH_PASS&amp;quot;] )) {&lt;br /&gt;fail(0);&lt;br /&gt;}&lt;br /&gt;$username = $_SERVER [&amp;quot;HTTP_AUTH_USER&amp;quot;];&lt;br /&gt;$userpass = $_SERVER [&amp;quot;HTTP_AUTH_PASS&amp;quot;];&lt;br /&gt;$protocol = $_SERVER [&amp;quot;HTTP_AUTH_PROTOCOL&amp;quot;];&lt;/p&gt;&lt;p&gt;$backend_port = 110;&lt;br /&gt;if($protocol == &amp;quot;imap&amp;quot;) {&lt;br /&gt;$backend_port = 143;&lt;br /&gt;} elseif ($protocol == &amp;quot;smtp&amp;quot;) {&lt;br /&gt;$backend_port = 25;&lt;br /&gt;}&lt;/p&gt;&lt;p&gt;list($uid, $domain) = explode(&amp;quot;@&amp;quot;, $username);&lt;/p&gt;&lt;p&gt;$auth = authuser($username, $userpass);&lt;br /&gt;if(!$auth) fail (-2);&lt;/p&gt;&lt;p&gt;pass($_SERVER[&amp;quot;SERVER_ADDR&amp;quot;], $backend_port);&lt;/p&gt;&lt;p&gt;//自定义认证，sql查询或者api&lt;br /&gt;function authuser($user, $pass) {&lt;br /&gt;return true;&lt;br /&gt;}&lt;/p&gt;&lt;p&gt;function fail($code) {&lt;br /&gt;switch($code){&lt;br /&gt;case 0: header(&amp;quot;Auth-Status: Parameter lost&amp;quot;); break;&lt;br /&gt;case -1: header(&amp;quot;Auth-Status: No Back-end Server&amp;quot;); break;&lt;br /&gt;case -2: header(&amp;quot;Auth-Status: Invalid login or password&amp;quot; ); break;&lt;br /&gt;}&lt;br /&gt;exit();&lt;br /&gt;}&lt;/p&gt;&lt;p&gt;function pass($server, $port) {&lt;br /&gt;header(&amp;quot;Auth-Status: OK&amp;quot; );&lt;br /&gt;header(&amp;quot;Auth-Server: $server&amp;quot; );&lt;br /&gt;header(&amp;quot;Auth-Port: $port&amp;quot; );&lt;br /&gt;exit();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;?&amp;gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;</description>
		<guid>http://www.517sou.net/Article/Nginx-as-an-IMAP-SMTP-POP3-Reverse-Proxy.aspx</guid>
		<trackback:ping>http://www.517sou.net/Article/751/Trackback.ashx</trackback:ping>
		<comments>http://www.517sou.net/Article/Nginx-as-an-IMAP-SMTP-POP3-Reverse-Proxy.aspx#CommentPostAnchor</comments>
		<wfw:commentRss>http://www.517sou.net/Article/751/Feeds.ashx</wfw:commentRss>
	</item>
	<item>
		<link>http://www.517sou.net/Article/PHP-compile-errors.aspx</link>
		<title>PHP编译错误及其解决方案</title>
		<author>shanyiwan@live.com(flyinweb)</author>
		<category>技术文摘</category>
		<pubDate>Wed, 11 Jan 2012 07:48:36 GMT</pubDate>
		<description>&lt;p&gt;本专题主题收集PHP编译过程中的错误及其解决方案。&lt;br /&gt;1、编译php出错&lt;br /&gt;/php-5.3.2/ext/fileinfo/libmagic/apprentice.c:147:internal compiler error:Segmentation fault&lt;br /&gt;Please submit a full bug report,&lt;br /&gt;with preprocessed source if appropriate.&lt;br /&gt;See &amp;lt;&lt;a href=&quot;http://bugzilla.redhat.com/bugzilla&quot; target=&quot;_blank&quot;&gt;URL:http://bugzilla.redhat.com/bugzilla&lt;/a&gt;&amp;gt; for instructions.&lt;br /&gt;The bug is not reproducible,so it is likely a hardware or OS problem.&lt;br /&gt;make:*** [ext/fileinfo/libmagic/apprentice.lo] Error 1&lt;br /&gt;解决方法：内存大于1G即可，这是php5.3.2的一个bug&lt;br /&gt;--------------------------------------------------------------------&lt;br /&gt;2、重新构造configure文件出错&lt;br /&gt;./buildconf --force&lt;br /&gt;Forcing buildconf&lt;br /&gt;buildconf:checking installation…&lt;br /&gt;buildconf:autoconf version 2.59 （ok）&lt;br /&gt;buildconf:Your version of autoconf likely contains buggy cache code.&lt;br /&gt;Running vcsclean for you.&lt;br /&gt;To avoid this,install autoconf-2.13.&lt;br /&gt;Can&apos;t figure out your VCS, not cleaning.&lt;br /&gt;解决方法：编译安装autoconf-2.13&lt;br /&gt;再将autoconf-2.13的auotconf文件至/usr/local/autoconf&lt;/p&gt;&lt;p&gt;&lt;br /&gt;--------------------------------------------------------------------&lt;br /&gt;3、编译时缺少库&lt;br /&gt;configure: error: libXpm.（a|so） not found.&lt;br /&gt;解决方法：yum install libXpm-devel&lt;br /&gt;--------------------------------------------------------------------&lt;br /&gt;4、编译时缺少gmp.h文件&lt;br /&gt;configure: error: Unable to locate gmp.h&lt;br /&gt;解决方法：yum install gmp-devel&lt;br /&gt;--------------------------------------------------------------------&lt;br /&gt;5、Configure: error: xml2-config not found. Please check your libxml2 installation.&lt;br /&gt;解决方法：&lt;br /&gt;#yum install libxml2 libxml2-devel （For Redhat &amp;amp; Fedora）&lt;br /&gt;# aptitude install libxml2-dev&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; （For ubuntu）&lt;br /&gt;--------------------------------------------------------------------&lt;br /&gt;6、Checking for pkg-config… /usr/bin/pkg-config&lt;br /&gt;configure: error: Cannot find OpenSSL’s &amp;lt;evp.h&amp;gt;&lt;br /&gt;解决方法：&lt;br /&gt;#yum install openssl openssl-devel&lt;br /&gt;--------------------------------------------------------------------&lt;br /&gt;7、Configure: error: Please reinstall the BZip2 distribution&lt;br /&gt;解决方法：&lt;br /&gt;# yum install bzip2 bzip2-devel&lt;br /&gt;--------------------------------------------------------------------&lt;br /&gt;8、Configure: error: Please reinstall the libcurl distribution -&lt;br /&gt;easy.h should be in &amp;lt;curl-dir&amp;gt;/include/curl/&lt;br /&gt;解决方法：&lt;br /&gt;# yum install curl curl-devel&amp;nbsp;&amp;nbsp; （For Redhat &amp;amp; Fedora）&lt;br /&gt;# install libcurl4-gnutls-dev&amp;nbsp;&amp;nbsp;&amp;nbsp; （For Ubuntu）&lt;br /&gt;--------------------------------------------------------------------&lt;br /&gt;9、Configure: error: libjpeg.（also） not found.&lt;br /&gt;解决方法：&lt;br /&gt;# yum install libjpeg libjpeg-devel&lt;br /&gt;--------------------------------------------------------------------&lt;br /&gt;10、Configure: error: libpng.（also） not found.&lt;br /&gt;--------------------------------------------------------------------&lt;br /&gt;解决方法：&lt;br /&gt;# yum install libpng libpng-devel&lt;br /&gt;--------------------------------------------------------------------&lt;br /&gt;11、Configure: error: freetype.h not found.&lt;br /&gt;解决方法：&lt;br /&gt;#yum install freetype-devel&lt;br /&gt;--------------------------------------------------------------------&lt;br /&gt;12、Configure: error: Unable to locate gmp.h&lt;br /&gt;解决方法：&lt;br /&gt;# yum install gmp-devel&lt;br /&gt;--------------------------------------------------------------------&lt;br /&gt;13、Configure: error: Cannot find MySQL header files under /usr.&lt;br /&gt;Note that the MySQL client library is not bundled anymore!&lt;br /&gt;解决方法：&lt;br /&gt;# yum install mysql-devel&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; （For Redhat &amp;amp; Fedora）&lt;br /&gt;# apt-get install libmysql++-dev&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; （For Ubuntu）&lt;br /&gt;--------------------------------------------------------------------&lt;br /&gt;14、Configure: error: Please reinstall the ncurses distribution&lt;br /&gt;解决方法：&lt;br /&gt;# yum install ncurses ncurses-devel&lt;br /&gt;--------------------------------------------------------------------&lt;br /&gt;15、Checking for unixODBC support… configure: error: ODBC header file ‘/usr/include/sqlext.h’ not found!&lt;br /&gt;解决方法：&lt;br /&gt;# yum install unixODBC-devel&lt;br /&gt;--------------------------------------------------------------------&lt;br /&gt;16、Configure: error: Cannot find pspell&lt;br /&gt;解决方法：&lt;br /&gt;# yum install pspell-devel&lt;br /&gt;--------------------------------------------------------------------&lt;br /&gt;17、configure: error: mcrypt.h not found. Please reinstall libmcrypt.&lt;br /&gt;解决方法：&lt;br /&gt;# yum install libmcrypt libmcrypt-devel&amp;nbsp;&amp;nbsp;&amp;nbsp; （For Redhat &amp;amp; Fedora）&lt;br /&gt;# apt-get install libmcrypt-dev&lt;br /&gt;--------------------------------------------------------------------&lt;br /&gt;18、Configure: error: snmp.h not found. Check your SNMP installation.&lt;br /&gt;解决方法：&lt;br /&gt;# yum install net-snmp net-snmp-devel&lt;br /&gt;--------------------------------------------------------------------&lt;br /&gt;19、configure:error:Cannot find ldap.h&lt;br /&gt;解决方法：&lt;br /&gt;#yum install openldap-devel openldap&lt;br /&gt;&lt;/p&gt;&lt;p&gt;20、configure:error:xslt-config not found. Please reinstall the libxslt &amp;gt;= 1.1.0 distribution&lt;br /&gt;解决方法：&lt;br /&gt;#yum install libxslt libxslt-devel&lt;br /&gt;&lt;/p&gt;&lt;p&gt;21、checking for libevent &amp;gt;=1.4.11 install prefix… configure: error: Could not find libevent &amp;gt;=1.4.11 in /usr/local/php&lt;br /&gt;解决方法：&lt;br /&gt;安装libevent-1.4.11以上版本至/usr/local&lt;br /&gt;tar xzvf libevent-1.4.14-stable.tar.gz&lt;br /&gt;cd libevent-1.4.14-stable&lt;br /&gt;./configure --prefix=/usr/local&lt;br /&gt;make&amp;amp;&amp;amp;make install&lt;br /&gt;在编译。/configure时添加--with-libevent-dir=/usr/local即可&lt;br /&gt;&lt;/p&gt;&lt;p&gt;22、cc1: out of memory allocating 2036 bytes after a total of 81846272 bytes&lt;br /&gt;make: *** [ext/date/lib/parse_date.lo] Error 1&lt;br /&gt;报错：&lt;br /&gt;/usr/bin/ld: cannot find -lltdl&lt;br /&gt;collect2: ld returned 1 exit status&lt;br /&gt;make:*** [sapi/fpm/php-fpm] Error 1&lt;br /&gt;解决方法：&lt;br /&gt;安装ltdl&lt;br /&gt;#cd /libmcrypt-2.5.7/libltdl/&lt;br /&gt;#./configure --enable-ltdl-install&lt;br /&gt;#ldconfig&lt;br /&gt;#cd php-5.3.6&lt;br /&gt;#make ZEND_EXTRA_LIBS=&apos;-liconv&apos;&lt;/p&gt;&lt;p&gt;23、configure: error: utf8_mime2text() has new signature, but U8T_CANONICAL is missing.&lt;br /&gt;yum install libc-client-devel&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;24、libiconv相关的未定义引用&lt;/p&gt;&lt;p&gt;/libxmlrpc/encoding.c:101:undefined reference to &apos;libiconv_close&apos;&lt;br /&gt;collect2: ld returned 1 exit status&lt;br /&gt;make:*** [sapi/fpm/php-fpm] Error 1&lt;br /&gt;解决方法：&lt;br /&gt;#make ZEND_EXTRA_LIBS=&apos;-liconv&apos;&lt;/p&gt;&lt;p&gt;/usr/local/src/php-5.2.17/ext/iconv/iconv.c:2615: undefined reference to `libiconv&apos;&lt;br /&gt;/usr/local/src/php-5.2.17/ext/iconv/iconv.c:2537: undefined reference to `libiconv&apos;&lt;br /&gt;ext/iconv/.libs/iconv.o: In function `php_iconv_stream_filter_ctor&apos;:&lt;br /&gt;/usr/local/src/php-5.2.17/ext/iconv/iconv.c:2491: undefined reference to `libiconv_open&apos;&lt;br /&gt;collect2: ld returned 1 exit status&lt;br /&gt;make: *** [sapi/cli/php] Error 1&lt;/p&gt;&lt;p&gt;原因：可能是由于系统中手工编译了libiconv&lt;/p&gt;&lt;p&gt;解决办法：&lt;br /&gt;./configure ............&lt;br /&gt;vi Makefile&lt;br /&gt;找到下面这行：&lt;br /&gt;EXTRA_LIBS = -lcrypt ...在最后添加-liconv保存&lt;/p&gt;&lt;p&gt;make&lt;br /&gt;make instal&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description>
		<guid>http://www.517sou.net/Article/PHP-compile-errors.aspx</guid>
		<trackback:ping>http://www.517sou.net/Article/750/Trackback.ashx</trackback:ping>
		<comments>http://www.517sou.net/Article/PHP-compile-errors.aspx#CommentPostAnchor</comments>
		<wfw:commentRss>http://www.517sou.net/Article/750/Feeds.ashx</wfw:commentRss>
	</item>
	<item>
		<link>http://www.517sou.net/Article/How-To-Verify-SSL-Certificate-From-A-Shell-Prompt.aspx</link>
		<title>How To Verify SSL Certificate From A Shell Prompt</title>
		<author>shanyiwan@live.com(flyinweb)</author>
		<category>Linux</category>
		<pubDate>Tue, 10 Jan 2012 01:50:32 GMT</pubDate>
		<description>&lt;p&gt;&lt;span class=&quot;drop_cap&quot;&gt;H&lt;/span&gt;ow do I verify and diagnosis SSL certification installation from a Linux / UNIX shell prompt? How do I validate SSL Certificate installation and save hours of troubleshooting headaches without using a browser? How do I confirm I&apos;ve the correct and working SSL certificates?&lt;br /&gt;&lt;br /&gt;OpenSSL comes with a generic SSL/TLS client which can establish a transparent connection to a remote server speaking SSL/TLS. It’s intended for testing purposes only and provides only rudimentary interface functionality but internally uses mostly all functionality of the OpenSSL ssl library. For testing purpose I will use &lt;a href=&quot;https://mail.nixcraft.net/&quot;&gt;&lt;u&gt;&lt;font color=&quot;#0066cc&quot;&gt;mail.nixcraft.net:443&lt;/font&gt;&lt;/u&gt;&lt;/a&gt; SSL certificate which is issued by Go Daddy.&lt;/p&gt;&lt;h2&gt;Step # 1: Getting The Certificate&lt;/h2&gt;&lt;p&gt;Create directory to store certificate:&lt;br /&gt;&lt;code&gt;$ mkdir -p ~/.cert/mail.nixcraft.net/&lt;br /&gt;$ cd ~/.cert/mail.nixcraft.net/&lt;/code&gt;&lt;br /&gt;Retrieve the mail.nixcraft.net certificate provided by the nixcraft HTTPD mail server:&lt;br /&gt;&lt;code&gt;$ openssl s_client -showcerts -connect mail.nixcraft.net:443&lt;/code&gt;&lt;br /&gt;Sample output:&lt;/p&gt;&lt;pre&gt;
CONNECTED(00000003)
depth=0 /O=mail.nixcraft.net/CN=mail.nixcraft.net/OU=Domain Control Validated
verify error:num=20:unable to get local issuer certificate
verify return:1
depth=0 /O=mail.nixcraft.net/CN=mail.nixcraft.net/OU=Domain Control Validated
verify error:num=27:certificate not trusted
verify return:1
depth=0 /O=mail.nixcraft.net/CN=mail.nixcraft.net/OU=Domain Control Validated
verify error:num=21:unable to verify the first certificate
verify return:1
---
Certificate chain
 0 s:/O=mail.nixcraft.net/CN=mail.nixcraft.net/OU=Domain Control Validated
   i:/C=US/ST=Arizona/L=Scottsdale/O=GoDaddy.com, Inc./OU=http://certificates.godaddy.com/repository/CN=Go Daddy Secure Certification Authority/serialNumber=07969287
-----BEGIN CERTIFICATE-----
MIIE5zCCA8+gAwIBAgIEAOJk2zANBgkqhkiG9w0BAQUFADCByjELMAkGA1UEBhMC
VVMxEDAOBgNVBAgTB0FyaXpvbmExEzARBgNVBAcTClNjb3R0c2RhbGUxGjAYBgNV
BAoTEUdvRGFkZHkuY29tLCBJbmMuMTMwMQYDVQQLEypodHRwOi8vY2VydGlmaWNh
dGVzLmdvZGFkZHkuY29tL3JlcG9zaXRvcnkxMDAuBgNVBAMTJ0dvIERhZGR5IFNl
Y3VyZSBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTERMA8GA1UEBRMIMDc5NjkyODcw
HhcNMDkwMTE4MjEyMjMxWhcNMTEwMTE4MjEyMjMxWjBbMRowGAYDVQQKExFtYWls
Lm5peGNyYWZ0Lm5ldDEaMBgGA1UEAxMRbWFpbC5uaXhjcmFmdC5uZXQxITAfBgNV
BAsTGERvbWFpbiBDb250cm9sIFZhbGlkYXRlZDCBnzANBgkqhkiG9w0BAQEFAAOB
jQAwgYkCgYEA0LhCDXvNXhTHov9Szh474Cv3Nz7QspVOI4p5M+zZt18VTVCHJz0Z
TleJum8RblpU4NPHJgOauIb1CAE3vLSKySV2DjHMt2L2/NUatJiKjDQKAEloKwQK
t75BP0mAGFPZmHlMNUQ32Sr/0byxxM4ElL2SSBasJE3PPVkSBOtLfssCAwEAAaOC
AcUwggHBMA8GA1UdEwEB/wQFMAMBAQAwHQYDVR0lBBYwFAYIKwYBBQUHAwEGCCsG
AQUFBwMCMA4GA1UdDwEB/wQEAwIFoDAyBgNVHR8EKzApMCegJaAjhiFodHRwOi8v
Y3JsLmdvZGFkZHkuY29tL2dkczEtMS5jcmwwUwYDVR0gBEwwSjBIBgtghkgBhv1t
AQcXATA5MDcGCCsGAQUFBwIBFitodHRwOi8vY2VydGlmaWNhdGVzLmdvZGFkZHku
Y29tL3JlcG9zaXRvcnkvMIGABggrBgEFBQcBAQR0MHIwJAYIKwYBBQUHMAGGGGh0
dHA6Ly9vY3NwLmdvZGFkZHkuY29tLzBKBggrBgEFBQcwAoY+aHR0cDovL2NlcnRp
ZmljYXRlcy5nb2RhZGR5LmNvbS9yZXBvc2l0b3J5L2dkX2ludGVybWVkaWF0ZS5j
cnQwHwYDVR0jBBgwFoAU/axhMpNsRdbi7oVfmrrndplozOcwMwYDVR0RBCwwKoIR
bWFpbC5uaXhjcmFmdC5uZXSCFXd3dy5tYWlsLm5peGNyYWZ0Lm5ldDAdBgNVHQ4E
FgQUAYML0uoVH8Sn8JZ3xbR9NLzE0tYwDQYJKoZIhvcNAQEFBQADggEBAJ/1/mGM
tF/UPwOvmiNE0i46qXCJDs6Ui7kCxWWQzC+CbT6x3fe8VwZ2/9OVeScw5aGkG7sU
kfid0XmfXxYrqkVsubrhQt/1MKKowB35M5a/wRd7E0h2ucYhBF3dnTQ29yJ9ppHC
HOvsUDGOan+e7japMyTYn9PU9Y8QtnzovRXk55iYfL4p57YvPwk4yMnBtc/krQcd
m6ZdvmY+zbbjWaDyarfIp3fQCL2HD/lC5rJaGUn633GIT0OrrQ4Gfy6hQ98UC+Pt
I8LFuzs02dJlCpDhGquvQ0W6o4uuvjSP28HfGBcmKholG0GT9wyZZCBvUlFyV6kq
/KNTisOW4so6I+Q=
-----END CERTIFICATE-----
---
Server certificate
subject=/O=mail.nixcraft.net/CN=mail.nixcraft.net/OU=Domain Control Validated
issuer=/C=US/ST=Arizona/L=Scottsdale/O=GoDaddy.com, Inc./OU=http://certificates.godaddy.com/repository/CN=Go Daddy Secure Certification Authority/serialNumber=07969287
---
No client certificate CA names sent
---
SSL handshake has read 1823 bytes and written 316 bytes
---
New, TLSv1/SSLv3, Cipher is DHE-RSA-AES256-SHA
Server public key is 1024 bit
Compression: NONE
Expansion: NONE
SSL-Session:
    Protocol  : TLSv1
    Cipher    : DHE-RSA-AES256-SHA
    Session-ID: BF3662B2C597A7473E477D0CAD2D5002FCC370661BA5A7364BDCDD9C1247C0F5
    Session-ID-ctx:
    Master-Key: BFF4A2556DB4D7810D63DFF1905A97215185E94A791A2385A20290067F60208F108E54B0BC194E5AEBD130B9CB092B46
    Key-Arg   : None
    Start Time: 1243050920
    Timeout   : 300 (sec)
    Verify return code: 21 (unable to verify the first certificate)
&lt;/pre&gt;&lt;p&gt;Copy from the &amp;quot;-----BEGIN CERTIFICATE-----&amp;quot; to the &amp;quot;-----END CERTIFICATE-----&amp;quot; , and save it in your ~/.cert/mail.nixcraft.net/ directory as mail.nixcraft.net.pem.&lt;/p&gt;&lt;h2&gt;Step # 2: Getting The Certificate Of The Issuer&lt;/h2&gt;&lt;p&gt;This certificate was issued by Go Daddy, so you need to get &amp;quot;Certification Authority Root Certificate&amp;quot; (visit your CA&apos;s website to get root certificate):&lt;br /&gt;&lt;code&gt;$ wget https://certs.godaddy.com/repository/gd_bundle.crt -O ~/.cert/mail.nixcraft.net/gd.pem&lt;/code&gt;&lt;/p&gt;&lt;h2&gt;Step # 3: Rehashing The Certificates&lt;/h2&gt;&lt;p&gt;Create symbolic links to files named by the hash values using c_rehash, enter:&lt;br /&gt;&lt;code&gt;$ c_rehash ~/.cert/mail.nixcraft.net/&lt;/code&gt;&lt;br /&gt;Sample output:&lt;/p&gt;&lt;pre&gt;
Doing  ~/.cert/mail.nixcraft.net/
mail.nixcraft.net.pem =&amp;gt; 1d97af50.0
gd.pem =&amp;gt; 219d9499.0&lt;/pre&gt;&lt;h2&gt;Test It&lt;/h2&gt;&lt;p&gt;To confirm you have the correct and working certificates, enter:&lt;br /&gt;&lt;code&gt;$ openssl s_client -CApath ~/.cert/mail.nixcraft.net/ -connect mail.nixcraft.net:443&lt;/code&gt;&lt;br /&gt;Sample output:&lt;/p&gt;&lt;pre&gt;
CONNECTED(00000003)
depth=3 /L=ValiCert Validation Network/O=ValiCert, Inc./OU=ValiCert Class 2 Policy Validation Authority/CN=http://www.valicert.com//emailAddress=info@valicert.com
verify return:1
depth=2 /C=US/O=The Go Daddy Group, Inc./OU=Go Daddy Class 2 Certification Authority
verify return:1
depth=1 /C=US/ST=Arizona/L=Scottsdale/O=GoDaddy.com, Inc./OU=http://certificates.godaddy.com/repository/CN=Go Daddy Secure Certification Authority/serialNumber=07969287
verify return:1
depth=0 /O=mail.nixcraft.net/CN=mail.nixcraft.net/OU=Domain Control Validated
verify return:1
---
Certificate chain
 0 s:/O=mail.nixcraft.net/CN=mail.nixcraft.net/OU=Domain Control Validated
   i:/C=US/ST=Arizona/L=Scottsdale/O=GoDaddy.com, Inc./OU=http://certificates.godaddy.com/repository/CN=Go Daddy Secure Certification Authority/serialNumber=07969287
---
Server certificate
-----BEGIN CERTIFICATE-----
MIIE5zCCA8+gAwIBAgIEAOJk2zANBgkqhkiG9w0BAQUFADCByjELMAkGA1UEBhMC
VVMxEDAOBgNVBAgTB0FyaXpvbmExEzARBgNVBAcTClNjb3R0c2RhbGUxGjAYBgNV
BAoTEUdvRGFkZHkuY29tLCBJbmMuMTMwMQYDVQQLEypodHRwOi8vY2VydGlmaWNh
dGVzLmdvZGFkZHkuY29tL3JlcG9zaXRvcnkxMDAuBgNVBAMTJ0dvIERhZGR5IFNl
Y3VyZSBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTERMA8GA1UEBRMIMDc5NjkyODcw
HhcNMDkwMTE4MjEyMjMxWhcNMTEwMTE4MjEyMjMxWjBbMRowGAYDVQQKExFtYWls
Lm5peGNyYWZ0Lm5ldDEaMBgGA1UEAxMRbWFpbC5uaXhjcmFmdC5uZXQxITAfBgNV
BAsTGERvbWFpbiBDb250cm9sIFZhbGlkYXRlZDCBnzANBgkqhkiG9w0BAQEFAAOB
jQAwgYkCgYEA0LhCDXvNXhTHov9Szh474Cv3Nz7QspVOI4p5M+zZt18VTVCHJz0Z
TleJum8RblpU4NPHJgOauIb1CAE3vLSKySV2DjHMt2L2/NUatJiKjDQKAEloKwQK
t75BP0mAGFPZmHlMNUQ32Sr/0byxxM4ElL2SSBasJE3PPVkSBOtLfssCAwEAAaOC
AcUwggHBMA8GA1UdEwEB/wQFMAMBAQAwHQYDVR0lBBYwFAYIKwYBBQUHAwEGCCsG
AQUFBwMCMA4GA1UdDwEB/wQEAwIFoDAyBgNVHR8EKzApMCegJaAjhiFodHRwOi8v
Y3JsLmdvZGFkZHkuY29tL2dkczEtMS5jcmwwUwYDVR0gBEwwSjBIBgtghkgBhv1t
AQcXATA5MDcGCCsGAQUFBwIBFitodHRwOi8vY2VydGlmaWNhdGVzLmdvZGFkZHku
Y29tL3JlcG9zaXRvcnkvMIGABggrBgEFBQcBAQR0MHIwJAYIKwYBBQUHMAGGGGh0
dHA6Ly9vY3NwLmdvZGFkZHkuY29tLzBKBggrBgEFBQcwAoY+aHR0cDovL2NlcnRp
ZmljYXRlcy5nb2RhZGR5LmNvbS9yZXBvc2l0b3J5L2dkX2ludGVybWVkaWF0ZS5j
cnQwHwYDVR0jBBgwFoAU/axhMpNsRdbi7oVfmrrndplozOcwMwYDVR0RBCwwKoIR
bWFpbC5uaXhjcmFmdC5uZXSCFXd3dy5tYWlsLm5peGNyYWZ0Lm5ldDAdBgNVHQ4E
FgQUAYML0uoVH8Sn8JZ3xbR9NLzE0tYwDQYJKoZIhvcNAQEFBQADggEBAJ/1/mGM
tF/UPwOvmiNE0i46qXCJDs6Ui7kCxWWQzC+CbT6x3fe8VwZ2/9OVeScw5aGkG7sU
kfid0XmfXxYrqkVsubrhQt/1MKKowB35M5a/wRd7E0h2ucYhBF3dnTQ29yJ9ppHC
HOvsUDGOan+e7japMyTYn9PU9Y8QtnzovRXk55iYfL4p57YvPwk4yMnBtc/krQcd
m6ZdvmY+zbbjWaDyarfIp3fQCL2HD/lC5rJaGUn633GIT0OrrQ4Gfy6hQ98UC+Pt
I8LFuzs02dJlCpDhGquvQ0W6o4uuvjSP28HfGBcmKholG0GT9wyZZCBvUlFyV6kq
/KNTisOW4so6I+Q=
-----END CERTIFICATE-----
subject=/O=mail.nixcraft.net/CN=mail.nixcraft.net/OU=Domain Control Validated
issuer=/C=US/ST=Arizona/L=Scottsdale/O=GoDaddy.com, Inc./OU=http://certificates.godaddy.com/repository/CN=Go Daddy Secure Certification Authority/serialNumber=07969287
---
No client certificate CA names sent
---
SSL handshake has read 1823 bytes and written 316 bytes
---
New, TLSv1/SSLv3, Cipher is DHE-RSA-AES256-SHA
Server public key is 1024 bit
Compression: NONE
Expansion: NONE
SSL-Session:
    Protocol  : TLSv1
    Cipher    : DHE-RSA-AES256-SHA
    Session-ID: 37E5AF0EE1745AB2DACAEE0FB7824C178A58C6AEF7A0EF93609643F16A20EE51
    Session-ID-ctx:
    Master-Key: 7B9F8A79D3CC3A41CA572ED266076A1531E12EE8D07D859D65F24368ABA0D2CAE670AA0652433D9E0585E566D9C16FCF
    Key-Arg   : None
    Start Time: 1243051912
    Timeout   : 300 (sec)
&lt;span style=&quot;color: rgb(255,0,0)&quot;&gt;    Verify return code: 0 (ok)&lt;/span&gt;
---
&lt;/pre&gt;&lt;p&gt;There should be lots of data, however the important thing to note down is that the final line &amp;quot;Verify return code: 0 (ok)&amp;quot;. I&apos;m using the same certificate for dovecot IMAP mail server, type the following to verify mail server SSL certificate:&lt;br /&gt;&lt;code&gt;$ openssl s_client -CApath ~/.cert/mail.nixcraft.net/ -connect mail.nixcraft.net:993&lt;/code&gt;&lt;br /&gt;Sample output:&lt;/p&gt;&lt;pre&gt;
CONNECTED(00000003)
depth=2 /C=US/O=The Go Daddy Group, Inc./OU=Go Daddy Class 2 Certification Authority
verify return:1
depth=1 /C=US/ST=Arizona/L=Scottsdale/O=GoDaddy.com, Inc./OU=http://certificates.godaddy.com/repository/CN=Go Daddy Secure Certification Authority/serialNumber=07969287
verify return:1
depth=0 /O=mail.nixcraft.net/CN=mail.nixcraft.net/OU=Domain Control Validated
verify return:1
---
Certificate chain
 0 s:/O=mail.nixcraft.net/CN=mail.nixcraft.net/OU=Domain Control Validated
   i:/C=US/ST=Arizona/L=Scottsdale/O=GoDaddy.com, Inc./OU=http://certificates.godaddy.com/repository/CN=Go Daddy Secure Certification Authority/serialNumber=07969287
 1 s:/C=US/ST=Arizona/L=Scottsdale/O=GoDaddy.com, Inc./OU=http://certificates.godaddy.com/repository/CN=Go Daddy Secure Certification Authority/serialNumber=07969287
   i:/C=US/O=The Go Daddy Group, Inc./OU=Go Daddy Class 2 Certification Authority
---
Server certificate
-----BEGIN CERTIFICATE-----
MIIE5zCCA8+gAwIBAgIEAOJk2zANBgkqhkiG9w0BAQUFADCByjELMAkGA1UEBhMC
VVMxEDAOBgNVBAgTB0FyaXpvbmExEzARBgNVBAcTClNjb3R0c2RhbGUxGjAYBgNV
BAoTEUdvRGFkZHkuY29tLCBJbmMuMTMwMQYDVQQLEypodHRwOi8vY2VydGlmaWNh
dGVzLmdvZGFkZHkuY29tL3JlcG9zaXRvcnkxMDAuBgNVBAMTJ0dvIERhZGR5IFNl
Y3VyZSBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTERMA8GA1UEBRMIMDc5NjkyODcw
HhcNMDkwMTE4MjEyMjMxWhcNMTEwMTE4MjEyMjMxWjBbMRowGAYDVQQKExFtYWls
Lm5peGNyYWZ0Lm5ldDEaMBgGA1UEAxMRbWFpbC5uaXhjcmFmdC5uZXQxITAfBgNV
BAsTGERvbWFpbiBDb250cm9sIFZhbGlkYXRlZDCBnzANBgkqhkiG9w0BAQEFAAOB
jQAwgYkCgYEA0LhCDXvNXhTHov9Szh474Cv3Nz7QspVOI4p5M+zZt18VTVCHJz0Z
TleJum8RblpU4NPHJgOauIb1CAE3vLSKySV2DjHMt2L2/NUatJiKjDQKAEloKwQK
t75BP0mAGFPZmHlMNUQ32Sr/0byxxM4ElL2SSBasJE3PPVkSBOtLfssCAwEAAaOC
AcUwggHBMA8GA1UdEwEB/wQFMAMBAQAwHQYDVR0lBBYwFAYIKwYBBQUHAwEGCCsG
AQUFBwMCMA4GA1UdDwEB/wQEAwIFoDAyBgNVHR8EKzApMCegJaAjhiFodHRwOi8v
Y3JsLmdvZGFkZHkuY29tL2dkczEtMS5jcmwwUwYDVR0gBEwwSjBIBgtghkgBhv1t
AQcXATA5MDcGCCsGAQUFBwIBFitodHRwOi8vY2VydGlmaWNhdGVzLmdvZGFkZHku
Y29tL3JlcG9zaXRvcnkvMIGABggrBgEFBQcBAQR0MHIwJAYIKwYBBQUHMAGGGGh0
dHA6Ly9vY3NwLmdvZGFkZHkuY29tLzBKBggrBgEFBQcwAoY+aHR0cDovL2NlcnRp
ZmljYXRlcy5nb2RhZGR5LmNvbS9yZXBvc2l0b3J5L2dkX2ludGVybWVkaWF0ZS5j
cnQwHwYDVR0jBBgwFoAU/axhMpNsRdbi7oVfmrrndplozOcwMwYDVR0RBCwwKoIR
bWFpbC5uaXhjcmFmdC5uZXSCFXd3dy5tYWlsLm5peGNyYWZ0Lm5ldDAdBgNVHQ4E
FgQUAYML0uoVH8Sn8JZ3xbR9NLzE0tYwDQYJKoZIhvcNAQEFBQADggEBAJ/1/mGM
tF/UPwOvmiNE0i46qXCJDs6Ui7kCxWWQzC+CbT6x3fe8VwZ2/9OVeScw5aGkG7sU
kfid0XmfXxYrqkVsubrhQt/1MKKowB35M5a/wRd7E0h2ucYhBF3dnTQ29yJ9ppHC
HOvsUDGOan+e7japMyTYn9PU9Y8QtnzovRXk55iYfL4p57YvPwk4yMnBtc/krQcd
m6ZdvmY+zbbjWaDyarfIp3fQCL2HD/lC5rJaGUn633GIT0OrrQ4Gfy6hQ98UC+Pt
I8LFuzs02dJlCpDhGquvQ0W6o4uuvjSP28HfGBcmKholG0GT9wyZZCBvUlFyV6kq
/KNTisOW4so6I+Q=
-----END CERTIFICATE-----
subject=/O=mail.nixcraft.net/CN=mail.nixcraft.net/OU=Domain Control Validated
issuer=/C=US/ST=Arizona/L=Scottsdale/O=GoDaddy.com, Inc./OU=http://certificates.godaddy.com/repository/CN=Go Daddy Secure Certification Authority/serialNumber=07969287
---
No client certificate CA names sent
---
SSL handshake has read 3076 bytes and written 316 bytes
---
New, TLSv1/SSLv3, Cipher is DHE-RSA-AES256-SHA
Server public key is 1024 bit
Compression: NONE
Expansion: NONE
SSL-Session:
    Protocol  : TLSv1
    Cipher    : DHE-RSA-AES256-SHA
    Session-ID: 509D310C0184E0540FC24F60F36D3E2A62C1F98D6367DBC62E8432FFDC79757A
    Session-ID-ctx:
    Master-Key: 72013A336DAFAF16917C4082785D3D9ADA3D0D3420B63FC5A6C9E5F44117D340A1051653849179A5ADEA57BE2BD65A24
    Key-Arg   : None
    Start Time: 1243052074
    Timeout   : 300 (sec)
    &lt;span style=&quot;color: rgb(255,0,0)&quot;&gt;Verify return code: 0 (ok)&lt;/span&gt;
---
&lt;span style=&quot;color: rgb(255,0,0)&quot;&gt;* OK [CAPABILITY IMAP4rev1 SASL-IR SORT THREAD=REFERENCES MULTIAPPEND UNSELECT LITERAL+ IDLE CHILDREN NAMESPACE LOGIN-REFERRALS UIDPLUS LIST-EXTENDED I18NLEVEL=1 QUOTA AUTH=PLAIN AUTH=LOGIN] Dovecot ready.&lt;/span&gt;&lt;/pre&gt;&lt;p&gt;Again the final &amp;quot;Dovecot ready&amp;quot; line along with 0 return code indicates that everything is working fine.&lt;/p&gt;</description>
		<guid>http://www.517sou.net/Article/How-To-Verify-SSL-Certificate-From-A-Shell-Prompt.aspx</guid>
		<trackback:ping>http://www.517sou.net/Article/749/Trackback.ashx</trackback:ping>
		<comments>http://www.517sou.net/Article/How-To-Verify-SSL-Certificate-From-A-Shell-Prompt.aspx#CommentPostAnchor</comments>
		<wfw:commentRss>http://www.517sou.net/Article/749/Feeds.ashx</wfw:commentRss>
	</item>
	<item>
		<link>http://www.517sou.net/Article/Creating-Certificate-Authorities-and-self-signed-SSL-certificates.aspx</link>
		<title>Creating Certificate Authorities and self-signed SSL certificates</title>
		<author>shanyiwan@live.com(flyinweb)</author>
		<category>WEB服务器</category>
		<pubDate>Sat, 07 Jan 2012 08:35:20 GMT</pubDate>
		<description>&lt;div class=&quot;textPlain&quot;&gt;Following is a step-by-step guide to creating your own CA (Certificate Authority) -- and also self-signed SSL server certificates -- with openssl on Linux. Self-signing is the simpler route to take, but making one&apos;s own CA allows the signing of multiple server certificates using the same CA and involves only a few extra steps. &lt;br /&gt;&lt;br /&gt;After using openssl to generate the necessary files, you&apos;ll need to integrate them into Apache. This process differs between Linux distros and versions of Apache. Additional references exist at the end of this document. My instructions for &lt;a href=&quot;http://www.tc.umn.edu/~brams006/selfsign_ubuntu.html&quot; target=&quot;_blank&quot;&gt;&lt;u&gt;&lt;font color=&quot;#0066cc&quot;&gt;Setting up SSL: Ubuntu and Apache 2&lt;/font&gt;&lt;/u&gt;&lt;/a&gt; are kept most current, and will carry you through to completion. &lt;br /&gt;&lt;br /&gt;Making a homemade CA or self-signed certificate will cause the client web browser to prompt with a message whether to trust the certificate signing authority (yourself) permanently (store it in the browser), temporarily for that session, or to reject it. The message &amp;quot;web site certified by an unknown authority... accept?&amp;quot; may be a business liability for general public usage, although it&apos;s simple enough for the client to accept the certificate permanently. &lt;br /&gt;&lt;br /&gt;Whichever route you take, you&apos;ll save the periodic expense of paying a recognized signing authority. This is purely for name recognition -- they&apos;ve paid the major browser producers to have their CA pre-loaded into them. So if you&apos;re on a budget, have a special need or small audience, this may be useful.&lt;/div&gt;&lt;p&gt;&lt;br /&gt;&lt;b&gt;Before you start&lt;/b&gt;&lt;br /&gt;You need &lt;a href=&quot;http://www.apache.org/&quot; target=&quot;_blank&quot;&gt;&lt;u&gt;&lt;font color=&quot;#0066cc&quot;&gt;Apache&lt;/font&gt;&lt;/u&gt;&lt;/a&gt; and &lt;a href=&quot;http://www.openssl.org/&quot; target=&quot;_blank&quot;&gt;&lt;u&gt;&lt;font color=&quot;#0066cc&quot;&gt;openssl&lt;/font&gt;&lt;/u&gt;&lt;/a&gt;. Compiling them from source, handling dependencies, etc. is beyond the scope of this document. You can consult their documentation, or go with a mainstream Linux distro that will do the preliminary work for you. &lt;br /&gt;&lt;br /&gt;Now you need to decide whether you&apos;ll make a CA (Certificate Authority) and sign a server certificate with it -- or just self-sign a server certificate. Both procedures are detailed below.&lt;/p&gt;&lt;hr /&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class=&quot;textPlain&quot;&gt;&lt;b&gt;(1A) Create a self-signed certificate.&lt;/b&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;Complete this section if you do NOT want to make a CA (Certificate Authority). If you want to make a CA, skip 1A entirely and go to 1B instead. &lt;br /&gt;&lt;br /&gt;Some steps in this document require priviledged access, and you&apos;ll want to limit access to the cert files to all but the root user. So you should su to root and create a working directory that only root has read/write access to (for example: mkdir certwork, chmod 600 certwork). Go to that directory. &lt;br /&gt;&lt;br /&gt;Generate a server key: &lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class=&quot;textHighlight&quot;&gt;openssl genrsa -des3 -out server.key 4096&lt;/div&gt;&lt;p&gt;&lt;br /&gt;Then create a certificate signing request with it. This command will prompt for a series of things (country, state or province, etc.). Make sure that &amp;quot;Common Name (eg, YOUR name)&amp;quot; matches the registered fully qualified domain name of your box (or your IP address if you don&apos;t have one). I also suggest not making a challenge password at this point, since it&apos;ll just mean more typing for you. &lt;br /&gt;&lt;br /&gt;The default values for the questions ([AU], Internet Widgits Pty Ltd, etc.) are stored here: /etc/ssl/openssl.cnf. So if you&apos;ve got a large number of certificate signing requests to process you probably want to carefully edit that file where appropriate. Otherwise, just execute the command below and type what needs to be typed: &lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class=&quot;textHighlight&quot;&gt;openssl req -new -key server.key -out server.csr&lt;/div&gt;&lt;p&gt;&lt;br /&gt;Now sign the certificate signing request. This example lasts 365 days: &lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class=&quot;textHighlight&quot;&gt;openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt&lt;/div&gt;&lt;p&gt;&lt;br /&gt;Make a version of the server.key which doesn&apos;t need a password: &lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class=&quot;textHighlight&quot;&gt;openssl rsa -in server.key -out server.key.insecure&lt;br /&gt;mv server.key server.key.secure&lt;br /&gt;mv server.key.insecure server.key&lt;/div&gt;&lt;p&gt;&lt;br /&gt;These files are quite sensitive and should be guarded for permissions very carefully. Chown them to root, if you&apos;re not already sudo&apos;d to root. I&apos;ve found that you can chmod 000 them. That is, root will always retain effective 600 (read) rights on everything. &lt;br /&gt;&lt;br /&gt;Now that you&apos;ve just completed Step 1A, skip ahead to Step 2. &lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class=&quot;textHeader&quot;&gt;(1B) Generate your own CA (Certificate Authority).&lt;/div&gt;&lt;p&gt;&lt;br /&gt;Complete this section if you want to make a CA (Certificate Authority) and sign a server certificate with it. The steps for making a server certificate are also included here. If you&apos;d rather one-time self-sign a server certificate, skip this step entirely and go to 1A instead. &lt;br /&gt;&lt;br /&gt;Some steps in this document require priviledged access, and you&apos;ll want to limit access to the cert files to all but the root user. So you should su to root and create a working directory that only root has read/write access to (for example: mkdir certwork, chmod 600 certwork). Go to that directory. &lt;br /&gt;&lt;br /&gt;In this step you&apos;ll take the place of VeriSign, Thawte, etc. You&apos;ll first build the CA key, then build the certificate itself. &lt;br /&gt;&lt;br /&gt;The Common Name (CN) of the CA and the Server certificates must NOT match or else a naming collision will occur and you&apos;ll get errors later on. In this step, you&apos;ll provide the CA entries. In a step below, you&apos;ll provide the Server entries. In this example, I just added &amp;quot;CA&amp;quot; to the CA&apos;s CN field, to distinguish it from the Server&apos;s CN field. Use whatever schema you want, just make sure the CA and Server entries are not identical. &lt;br /&gt;&lt;br /&gt;CA:&lt;br /&gt;Common Name (CN): www.somesite.edu CA&lt;br /&gt;Organization (O): Somesite&lt;br /&gt;Organizational Unit (OU): Development &lt;br /&gt;&lt;br /&gt;Server:&lt;br /&gt;Common Name (CN): www.somesite.edu&lt;br /&gt;Organization (O): Somesite&lt;br /&gt;Organizational Unit (OU): Development &lt;br /&gt;&lt;br /&gt;If you don&apos;t have a fully qualified domain name, you should use the IP that you&apos;ll be using to access your SSL site for Common Name (CN). But, again, make sure that something differentiates the entry of the CA&apos;s CN from the Server&apos;s CN. &lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class=&quot;textHighlight&quot;&gt;openssl genrsa -des3 -out ca.key 4096&lt;br /&gt;openssl req -new -x509 -days 365 -key ca.key -out ca.crt&lt;br /&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class=&quot;textHeader&quot;&gt;Generate a server key and request for signing (csr).&lt;/div&gt;&lt;p&gt;&lt;br /&gt;This step creates a server key, and a request that you want it signed (the .csr file) by a Certificate Authority (the one you just created in Step #1B above.)&lt;br /&gt;&lt;br /&gt;Think carefully when inputting a Common Name (CN) as you generate the .csr file below. This should match the DNS name, or the IP address you specify in your Apache configuration. If they don&apos;t match, client browsers will get a &amp;quot;domain mismatch&amp;quot; message when going to your https web server. If you&apos;re doing this for home use, and you don&apos;t have a static IP or DNS name, you might not even want worry about the message (but you sure will need to worry if this is a production/public server). For example, you could match it to an internal and static IP you use behind your router, so that you&apos;ll never get the &amp;quot;domain mismatch&amp;quot; message if you&apos;re accessing the computer on your home LAN, but will always get that message when accessing it elsewhere. Your call -- is your IP stable, do you want to repeat these steps every time your IP changes, do you have a DNS name, do you mainly use it inside your home or LAN, or outside? &lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class=&quot;textHighlight&quot;&gt;openssl genrsa -des3 -out server.key 4096&lt;br /&gt;openssl req -new -key server.key -out server.csr&lt;br /&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class=&quot;textHeader&quot;&gt;Sign the certificate signing request (csr) with the self-created Certificate Authority (CA) that you made earlier.&lt;/div&gt;&lt;p&gt;&lt;br /&gt;Note that 365 days is used here. After a year you&apos;ll need to do this again. &lt;br /&gt;&lt;br /&gt;Note also that I set the serial number of the signed server certificate to &amp;quot;01&amp;quot;. Each time you do this, especially if you do this before a previously-signed certificate expires, you&apos;ll need to change the serial key to something else -- otherwise everyone who&apos;s visited your site with a cached version of your certificate will get a browser warning message to the effect that your certificate signing authority has screwed up -- they&apos;ve signed a new key/request, but kept the old serial number. There are a couple ways to rectify that. crl&apos;s (certificate revocation list) is one method, but beyond the scope of the document. Another method is for all clients which have stored the CA certificate to go into their settings and delete the old one manually. But for the purposes of this document, we&apos;ll just avoid the problem. (If you&apos;re a sysadmin of a production system and your server.key is compromised, you&apos;ll certainly need to worry.) &lt;br /&gt;&lt;br /&gt;The command below does a number of things. It takes your signing request (csr) and makes a one-year valid signed server certificate (crt) out of it. In doing so, we need to tell it which Certificate Authority (CA) to use, which CA key to use, and which Server key to sign. We set the serial number to 01, and output the signed key in the file named server.crt. If you do this again after people have visited your site and trusted your CA (storing it in their browser), you might want to use 02 for the next serial number, and so on. You might create some scheme to make the serial number more &amp;quot;official&amp;quot; in appearance or makeup but keep in mind that it is fully exposed to the public in their web browsers, so it offers no additional security in itself. &lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class=&quot;textHighlight&quot;&gt;openssl x509 -req -days 365 -in server.csr -CA ca.crt -CAkey ca.key -set_serial 01 -out server.crt&lt;br /&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;To examine the components if you&apos;re curious: &lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class=&quot;textHighlight&quot;&gt;openssl rsa -noout -text -in server.key&lt;br /&gt;openssl req -noout -text -in server.csr&lt;br /&gt;openssl rsa -noout -text -in ca.key&lt;br /&gt;openssl x509 -noout -text -in ca.crt&lt;br /&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class=&quot;textHeader&quot;&gt;Make a server.key which doesn&apos;t cause Apache to prompt for a password.&lt;/div&gt;&lt;p&gt;&lt;br /&gt;Here we create an insecure version of the server.key. The insecure one will be used for when Apache starts, and will not require a password with every restart of the web server. But keep in mind that while this means you don&apos;t have to type in a password when restarting Apache (or worse -- coding it somewhere in plaintext), it does mean that anyone obtaining this insecure key will be able to decrypt your transmissions. Guard it for permissions VERY carefully.&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class=&quot;textHighlight&quot;&gt;openssl rsa -in server.key -out server.key.insecure&lt;br /&gt;mv server.key server.key.secure&lt;br /&gt;mv server.key.insecure server.key&lt;br /&gt;&lt;/div&gt;&lt;p&gt;&lt;br /&gt;These files are quite sensitive and should be guarded for permissions very carefully. Chown them to root, if you&apos;re not already sudo&apos;d to root. I&apos;ve found that you can chmod 000 them. That is, root will always retain effective 600 (read) rights on everything. &lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class=&quot;textHeader&quot;&gt;(2) Copy files into position and tweak Apache.&lt;/div&gt;&lt;p&gt;&lt;br /&gt;Some professors like to pause for a moment after a long lecture, and do a little recap. It&apos;s a good pedagogical tool, so let&apos;s do so here. If you took route 1A above, you should have four files in a working directory: &lt;br /&gt;&lt;br /&gt;server.crt: The self-signed server certificate.&lt;br /&gt;server.csr: Server certificate signing request.&lt;br /&gt;server.key: The private server key, does not require a password when starting Apache.&lt;br /&gt;server.key.secure: The private server key, it does require a password when starting Apache. &lt;br /&gt;&lt;br /&gt;If you took route 1B and created a CA, you&apos;ll have two additional files: &lt;br /&gt;&lt;br /&gt;ca.crt: The Certificate Authority&apos;s own certificate.&lt;br /&gt;ca.key: The key which the CA uses to sign server signing requests. &lt;br /&gt;&lt;br /&gt;The CA files are important to keep if you want to sign additional server certificates and preserve the same CA. You can reuse these so long as they remain secure, and haven&apos;t expired. &lt;br /&gt;&lt;br /&gt;At a bare minimum, the following considerations must now be addressed: &lt;br /&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;You&apos;ll need a virtual host and document root set up for the SSL instance.&lt;/li&gt;&lt;li&gt;You&apos;ll need to turn on the SSL engine and enable/load the SSL module.&lt;/li&gt;&lt;li&gt;Apache must reference server.crt and server.key somewhere in its configuration.&lt;/li&gt;&lt;li&gt;Apache must be listening to a port for which SSL is enabled (443 is default).&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;The particulars differ between Linux distros and versions of Apache. I&apos;m only able to keep the &lt;a href=&quot;http://www.tc.umn.edu/~brams006/selfsign_ubuntu.html&quot; target=&quot;_blank&quot;&gt;&lt;u&gt;&lt;font color=&quot;#0066cc&quot;&gt;Setting up SSL: Ubuntu and Apache 2&lt;/font&gt;&lt;/u&gt;&lt;/a&gt; documentation current due to time constraints. Those steps should apply broadly to Debian-based distros with little or no modification. Red Hat and openSUSE commentary is kept online here for historical purposes.&lt;/p&gt;</description>
		<guid>http://www.517sou.net/Article/Creating-Certificate-Authorities-and-self-signed-SSL-certificates.aspx</guid>
		<trackback:ping>http://www.517sou.net/Article/748/Trackback.ashx</trackback:ping>
		<comments>http://www.517sou.net/Article/Creating-Certificate-Authorities-and-self-signed-SSL-certificates.aspx#CommentPostAnchor</comments>
		<wfw:commentRss>http://www.517sou.net/Article/748/Feeds.ashx</wfw:commentRss>
	</item>
</channel>
</rss>
