<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[回忆未来[张宴]]]></title> 
<link>http://blog.s135.com/index.php</link> 
<description><![CDATA[网络系统研究室]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[回忆未来[张宴]]]></copyright>
<item>
<link>http://blog.s135.com/read.php?356</link>
<title><![CDATA[MySQL中文全文索引插件 mysqlcft 1.0.0 安装使用文档[原创]]]></title> 
<author>张宴 &lt;net@s135.com&gt;</author>
<category><![CDATA[纯粹技术]]></category>
<pubDate>Tue, 01 Jul 2008 14:57:58 +0000</pubDate> 
<guid>http://blog.s135.com/read.php?356</guid> 
<description>
<![CDATA[ 
	　　[文章+程序 作者：张宴 本文版本：v1.0 最后修改：2008.07.01 转载请注明原文链接：<a href="http://blog.s135.com/read.php/356.htm" target="_blank">http://blog.s135.com/read.php/356.htm</a>]<br/><br/>　　MySQL在高并发连接、数据库记录数较多的情况下，SELECT ... WHERE ... LIKE '%...%'的全文搜索方式不仅效率差，而且以通配符%和_开头作查询时，使用不到索引，需要全表扫描，对数据库的压力也很大。MySQL针对这一问题提供了一种全文索引解决方案，这不仅仅提高了性能和效率（因为MySQL对这些字段做了索引来优化搜索），而且实现了更高质量的搜索。但是，至今为止，MySQL对中文全文索引无法正确支持。<br/><br/>　　中文与西方文字如英文的一个重要区别在于，西方文字以单词为单位，单词与单词之间以空格分隔。而中文以字为单位，词由一个或多个字组成，词与词之间没有空格分隔。当试图在一个含有中文字符的字段中使用全文搜索时，不会得到正确的结果，原因在于中文中没有像英文空格那样对词定界，不能以空格作为分割，对中文词语进行索引。<br/><br/>　　引用《<a href="http://dev.mysql.com/doc/refman/5.1/zh/index.html" target="_blank">MySQL 5.1参考手册</a>》中的一段话：<br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content">12.7. 全文搜索功能（<a href="http://dev.mysql.com/doc/refman/5.1/zh/functions.html" target="_blank">http://dev.mysql.com/doc/refman/5.1/zh/functions.html</a>）<br/>● MySQL支持全文索引和搜索功能。MySQL中的全文索引类型FULLTEXT的索引。FULLTEXT 索引仅可用于 MyISAM 表；他们可以从CHAR、 VARCHAR或TEXT列中作为CREATE TABLE语句的一部分被创建，或是随后使用ALTER TABLE 或 CREATE INDEX被添加。对于较大的数据集，将你的资料输入一个没有FULLTEXT索引的表中，然后创建索引， 其速度比把资料输入现有FULLTEXT索引的速度更为快。<br/><br/>● FULLTEXT分析程序会通过寻找某些分隔符来确定单词的起始位置和结束位置，例如' ' (间隔符号)、 , (逗号)以及 . (句号 )。假如单词没有被分隔符分开，(例如在中文里 ), 则 FULLTEXT 分析程序不能确定一个词的起始位置和结束位置。为了能够在这样的语言中向FULLTEXT 索引添加单词或其它编入索引的术语，你必须对它们进行预处理，使其被一些诸如"之类的任意分隔符分隔开。<br/><br/>● 诸如汉语和日语这样的表意语言没有自定界符。因此， FULLTEXT分析程序不能确定在这些或其它的这类语言中词的起始和结束的位置。</div></div><br/><br/>　　国内已有的MySQL中文全文索引解决方案有两个：一是海量科技的<a href="http://www.hylanda.com/server/" target="_blank">MySQL5.0.37--LinuxX86-Chinese+</a>，二是hightman开发的<a href="http://www.hightman.cn/bbs/viewthread.php?tid=18&extra=page%3D1" target="_blank">mysql-5.1.11-ft-hightman</a>，两者都是基于中文分词技术，对中文语句进行拆分。但是，两者都有弊端，一是不支持64位操作系统；二是对修改了MySQL源码，只支持某一MySQL版本，不便于跟进新版本；三是词库不能做到很大很全，对于专业性质较强的数据库内容（例如搜索“颐和园路东口”、“清华东路西口”等公交站点，“莱镇香格里”、“碧海云天”等楼盘名称），基于中文分词的全文索引经常搜索不出来任何内容，即使添加分词词库，也不会很全面。<br/><br/>　　由于业务上精准全文查询的需要，我借鉴了二元交叉切分算法的思想，用自创的“三字节交叉切分算法”，写出了这款“MySQL中文全文索引插件──mysqlcft 1.0.0”。由于开发时间仓促，难免存在未发现的问题，这将后续的版本中不断完善。对于百万条记录的MySQL表进行全文检索，mysqlcft已经够用。<br/><br/>　　Mysqlcft 网址：<a href="http://code.google.com/p/mysqlcft/" target="_blank">http://code.google.com/p/mysqlcft/</a><br/>　　Mysqlcft 作者：张宴<br/><br/><hr/><br/>　　<strong>一、MySQL中文全文索引插件mysqlcft的特点：</strong><br/>　　1、优点：<br/>　　①、精准度很高：采用自创的“三字节交叉切分算法”，对中文语句进行分割，无中文分词词库，搜索精准度远比中文分词算法高，能达到LIKE '%...%"的准确率。<br/>　　②、查询速度快：查询速度比LIKE '%...%"搜索快3～50倍，文章末尾有测试结果；<br/>　　③、标准插件式：以MySQL 5.1全文索引的标准插件形式开发，不修改MySQL源代码，不影响MySQL的其他功能，可快速跟进MySQL新版本；<br/>　　④、支持版本多：支持所有的MySQL 5.1 Release Candidate版本，即MySQL 5.1.22 RC～最新的MySQL 5.1.25 RC；<br/>　　⑤、支持字符集：支持包括GBK、GB2312、UTF-8、Latin1、BIG5在内的MySQL字符集（其他字符集没有测试过）；<br/>　　⑥、系统兼容好：具有i386和x86_64两个版本，支持32位（i386）和64位（x86_64）CPU及Linux系统；<br/>　　⑦、适合分布式：非常适合MySQL Slave分布式系统架构，无词库维护成本，不存在词库同步问题。<br/><br/>　　2、缺点：<br/>　　①、mysqlcft中文全文索引只适用于MyISAM表，因为MySQL只支持对MyISAM表建立FULLTEXT索引；<br/>　　②、MySQL不能静态编译安装，否则无法安装mysqlcft插件；<br/>　　③、基于“三字节交叉切分算法”的索引文件会比海量、ft-hightman等基于“中文分词算法”的索引文件稍大，但不是大很多。根据我的测试，mysqlcft全文索引的.MYI索引文件是.MYD数据文件的2～5倍。<br/><br/><hr/><br/>　　<strong>二、mysqlcft的核心思想──“三字节交叉切分算法”</strong><br/><br/>　　<a href="http://blog.s135.com/attachment/200807/mysqlcft.gif" target="_blank"><img src="http://blog.s135.com/attachment/200807/mysqlcft.gif" class="insertimage" alt="点击在新窗口中浏览此图片" title="点击在新窗口中浏览此图片" border="0"/></a><br/><br/>　　注：本文以0～7数字序号代表“英文”、“数字”和“半个汉字”，以便说明。<br/>　　1、按三字节对中文语句进行切分，建立全文索引：<br/>　　例如：“全文索引”或“1台x光机”四个字会被交叉分拆为6份，建立反向索引：<br/>　　012　　123　　234　　345　　456　　567<br/><br/>　　2、按三字节对搜索的关键字进行切分，在全文索引中找出对应信息：<br/>　　例①：搜索关键字“文索”，用数字序号表示就是“2～5”，那么它将被切分成：<br/>　　234　　345<br/>　　这样，就与全文索引对上了。<br/><br/>　　例②：搜索关键字“x光机”，用数字序号表示就是“3～7”，那么它将被切分成：<br/>　　345　　456　　567<br/>　　这样，也与全文索引对上了。<br/><br/>　　例③：搜索关键字“1台 光机”，用数字序号表示就是“0～2”和“4～7”，那么它将被切分成：<br/>　　012　　456　　567<br/>　　这样，多关键字搜索也与全文索引对上了。<br/><br/><hr/><br/>　　<strong>三、编译安装MySQL</strong>（如果已经装有不是静态编译安装的MySQL 5.1.22 RC～MySQL 5.1.25 RC，此步骤可省略）<br/>　　1、下载并编译安装MySQL 5.1.25 RC<br/>　　在<a href="http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.25-rc.tar.gz/from/pick" target="_blank">http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.25-rc.tar.gz/from/pick</a>（点击No thanks, just take me to the downloads!链接），选择一个镜像，下载MySQL 5.1.25 RC源码包：<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">tar zxvf mysql-5.1.25-rc.tar.gz<br/>cd mysql-5.1.25-rc/<br/>./configure --prefix=/usr/local/mysqlcft/ --without-debug --enable-assembler --with-extra-charsets=all --with-pthread --enable-thread-safe-client<br/>make && make install<br/><br/>/usr/sbin/groupadd mysql<br/>/usr/sbin/useradd -g mysql mysql<br/>chmod +w /usr/local/mysqlcft<br/>chown -R mysql:mysql /usr/local/mysqlcft</div><br/><br/>　　2、创建MySQL数据文件存放目录/mysql/3306<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">mkdir -p /mysql/3306<br/>chmod +w /mysql/3306<br/>chown -R mysql:mysql /mysql/3306<br/>mkdir -p /mysql/3306/data<br/>chmod +w /mysql/3306/data<br/>chown -R mysql:mysql /mysql/3306/data<br/>chown -R mysql:mysql /mysql<br/>#cp support-files/my-medium.cnf /mysql/3306/my.cnf<br/>cd ../</div><br/><br/>　　3、创建配置文件/mysql/3306/my.cnf<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">vi /mysql/3306/my.cnf</div><br/>　　输入以下内容（<font color="red">注意：必须设置ft_min_word_len = 1</font>）：<br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content">[client]<br/>#password &nbsp; &nbsp; &nbsp; = your_password<br/>port &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= 3306<br/>socket &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= /mysql/3306/mysql.sock<br/>default-character-set = gbk<br/><br/>[mysqld_safe]<br/>datadir = /mysql/3306/data<br/>log-error = /mysql/3306/mysql_error.log<br/>pid-file = /mysql/3306/mysql.pid<br/><br/>[mysqld]<br/>port &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= 3306<br/>socket &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= /mysql/3306/mysql.sock<br/>default-character-set = gbk<br/>#init_connect = 'SET NAMES gbk'<br/>skip-locking<br/>#skip-slave-start<br/>key_buffer = 512M<br/>max_allowed_packet = 2M<br/>table_cache = 1024<br/>sort_buffer_size = 32M<br/>read_buffer_size = 2M<br/>read_rnd_buffer_size = 32M<br/>max_length_for_sort_data = 64<br/>myisam_sort_buffer_size = 128M<br/>thread_cache = 8<br/>query_cache_size = 64M<br/># Try number of CPU's*2 for thread_concurrency<br/>thread_concurrency = 8<br/>#skip-name-resolve<br/>set-variable = max_connections=1000<br/>open_files_limit = 51200<br/>ft_min_word_len = 1<br/><br/>low_priority_updates = 1<br/>slave-skip-errors = 1032,1062,126<br/>server-id &nbsp; &nbsp; &nbsp; = 9<br/>#master-host &nbsp; &nbsp; = &nbsp; host<br/>#master-user &nbsp; &nbsp; = &nbsp; user<br/>#master-password = &nbsp; password<br/>#master-port &nbsp; &nbsp; = &nbsp;3306<br/>#replicate-do-db = db1<br/>#replicate-do-db = db2<br/><br/>[mysqldump]<br/>quick<br/>max_allowed_packet = 16M<br/><br/>[mysql]<br/>no-auto-rehash<br/># Remove the next comment character if you are not familiar with SQL<br/>#safe-updates<br/><br/>[isamchk]<br/>key_buffer = 256M<br/>sort_buffer_size = 256M<br/>read_buffer = 2M<br/>write_buffer = 2M<br/><br/>[myisamchk]<br/>key_buffer = 256M<br/>sort_buffer_size = 256M<br/>read_buffer = 2M<br/>write_buffer = 2M<br/><br/>[mysqlhotcopy]<br/>interactive-timeout</div></div><br/><br/>　　附：MySQL配置文件在全文索引应用中的优化<br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content">[mysqld]<br/># key_buffer 指定用于索引的缓冲区大小，在全文索引中，增加它可得到更好的索引处理与查询性能<br/>key_buffer = 512M<br/><br/># sort_buffer_size 为查询排序时所能使用的缓冲区大小，全文索引的SQL语句之后通常会使用ORDER BY排序，增加它可以加快SQL语句执行时间。该参数对应的分配内存是每连接独占，100个连接使用的内存将是32M*100=3200M<br/>sort_buffer_size = 32M<br/><br/># 对大于可用内存的表执行GROUP BY或ORDER BY操作，应增加read_rnd_buffer_size的值以加速排序操作后面的行读取<br/>read_rnd_buffer_size = 64M<br/><br/># 如果表出现故障或索引出错，REPAIR TABLE时用到的缓冲区大小<br/>myisam_sort_buffer_size = 128M<br/><br/># 确定使用的filesort算法的索引值大小的限值<br/>max_length_for_sort_data = 64<br/><br/># MySQL全文索引查询所用关键词最小长度限制（不要改变这项值）<br/>ft_min_word_len = 1<br/><br/># 降低UPDATE优先级，设置查询优先<br/>low_priority_updates = 1</div></div><br/><br/>　　4、以mysql用户帐号的身份建立数据表<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">/usr/local/mysqlcft/bin/mysql_install_db --defaults-file=/mysql/3306/my.cnf --basedir=/usr/local/mysqlcft --datadir=/mysql/3306/data --user=mysql --pid-file=/mysql/3306/mysql.pid --skip-locking --port=3306 --socket=/mysql/3306/mysql.sock</div><br/><br/>　　5、启动MySQL<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">/bin/sh /usr/local/mysqlcft/bin/mysqld_safe --defaults-file=/mysql/3306/my.cnf &</div><br/><br/>　　附：停止MySQL<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">/usr/local/mysqlcft/bin/mysqladmin -u root -p -S /mysql/3306/mysql.sock shutdown</div><br/><br/><hr/><br/>　　<strong>四、安装mysqlcft中文全文索引插件</strong><br/>　　1、从命令行登入MySQL服务器：<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">/usr/local/mysqlcft/bin/mysql -u root -p -S /mysql/3306/mysql.sock</div><br/><br/>　　2、查看MySQL插件目录的默认路径的SQL语句：<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">SHOW VARIABLES LIKE 'plugin_dir';</div><br/>　　<a href="http://blog.s135.com/attachment/200807/mysqlcft1.png" target="_blank"><img src="http://blog.s135.com/attachment/200807/mysqlcft1.png" class="insertimage" alt="点击在新窗口中浏览此图片" title="点击在新窗口中浏览此图片" border="0"/></a><br/><br/>　　3、下载mysqlcft中文全文索引插件，解压后拷贝mysqlcft.so文件到MySQL插件目录<br/>　　①、32位Linux操作系统：<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">wget <a href="http://mysqlcft.googlecode.com/files/mysqlcft-1.0.0-i386-bin.tar.gz" target="_blank">http://mysqlcft.googlecode.com/files/mysqlcft-1.0.0-i386-bin.tar.gz</a><br/>tar zxvf mysqlcft-1.0.0-i386-bin.tar.gz<br/>mkdir -p /usr/local/mysqlcft/lib/mysql/plugin/<br/>cp mysqlcft.so /usr/local/mysqlcft/lib/mysql/plugin/</div><br/><br/>　　②、64位Linux操作系统：<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">wget <a href="http://mysqlcft.googlecode.com/files/mysqlcft-1.0.0-x86_64-bin.tar.gz" target="_blank">http://mysqlcft.googlecode.com/files/mysqlcft-1.0.0-x86_64-bin.tar.gz</a><br/>tar zxvf mysqlcft-1.0.0-x86_64-bin.tar.gz<br/>mkdir -p /usr/local/mysqlcft/lib/mysql/plugin/<br/>cp mysqlcft.so /usr/local/mysqlcft/lib/mysql/plugin/</div><br/><br/>　　4、安装mysqlcft.so插件<br/>　　①、从命令行登入MySQL服务器：<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">/usr/local/mysqlcft/bin/mysql -u root -p -S /mysql/3306/mysql.sock</div><br/><br/>　　②、安装mysqlcft.so插件的SQL语句：<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">INSTALL PLUGIN mysqlcft SONAME 'mysqlcft.so';</div><br/><br/>　　③、查看mysqlcft.so插件是否安装成功的SQL语句：<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">SELECT * FROM mysql.plugin;<br/>SHOW PLUGINS;</div><br/>　　<a href="http://blog.s135.com/attachment/200807/mysqlcft2.png" target="_blank"><img src="http://blog.s135.com/attachment/200807/mysqlcft2.png" class="insertimage" alt="点击在新窗口中浏览此图片" title="点击在新窗口中浏览此图片" border="0"/></a><br/><br/>　　附：如果要卸载mysqlcft.so插件，执行以下SQL语句（如果已经创建了mysqlcft索引，请先删除mysqlcft索引，再卸载mysqlcft.so插件）：<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">UNINSTALL PLUGIN mysqlcft;</div><br/><br/><hr/><br/>　　<strong>五、为已经存在的表添加mysqlcft中文全文索引</strong><br/>　　1、创建单列全文索引SQL语句<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">ALTER IGNORE TABLE 数据库名.表名 ADD FULLTEXT INDEX 全文索引名 (字段名) <font color="red">WITH PARSER mysqlcft</font>;</div><br/><br/>　　2、创建全文联合索引SQL语句<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">ALTER IGNORE TABLE 数据库名.表名 ADD FULLTEXT INDEX 全文联合索引名 (字段名1,字段名2) <font color="red">WITH PARSER mysqlcft</font>;</div><br/><br/><hr/><br/>　　<strong>六、重建mysqlcft中文全文索引（索引损坏时需要用到）</strong><br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">REPAIR TABLE 数据库名.表名 QUICK;</div><br/><br/><hr/><br/>　　<strong>七、建表时创建mysqlcft中文全文索引＋全文搜索测试</strong><br/>　　1、以latin1字符集为例<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">CREATE DATABASE `mysqlcft_latin1` DEFAULT CHARACTER SET latin1;<br/>USE `mysqlcft_latin1`;<br/>CREATE TABLE `test` (<br/>`id` int(10) unsigned NOT NULL AUTO_INCREMENT,<br/>`title` varchar(200) DEFAULT NULL,<br/>`body` mediumtext,<br/>PRIMARY KEY (`id`),<br/>FULLTEXT KEY `title_body` (`title`,`body`) <font color="red">WITH PARSER mysqlcft</font><br/>) ENGINE=MyISAM DEFAULT CHARSET=latin1;<br/><br/>INSERT INTO `mysqlcft_latin1`.`test` (`id`, `title`, `body`) VALUES (NULL, '北京房价', '北京市统计局、国家统计局北京调查总队近日联合对外发布消息，今年以来，北京的商品房价格一直呈上升趋势，五环路以内住宅期房均价已涨至13754元/平方米。');<br/>INSERT INTO `mysqlcft_latin1`.`test` (`id`, `title`, `body`) VALUES (NULL, '北京中心城区今起可无线宽带上网 奥运期间免费', '新浪科技讯 6月25日消息，北京无线城市一期网络今日起试运行，即日起北京市民和海外游客可以通过无线网络在北京中心城区接入互联网。');<br/>INSERT INTO `mysqlcft_latin1`.`test` (`id`, `title`, `body`) VALUES (NULL, '数据库', '欢迎使用MySQL中文全文索引插件mysqlcft！');<br/><br/>SELECT * FROM mysqlcft_latin1.test WHERE MATCH(title,body) AGAINST ('13754元/平方米' IN BOOLEAN MODE);<br/>SELECT * FROM mysqlcft_latin1.test WHERE MATCH(title,body) AGAINST ('6月25日' IN BOOLEAN MODE);<br/>SELECT * FROM mysqlcft_latin1.test WHERE MATCH(title,body) AGAINST ('北京' IN BOOLEAN MODE);<br/>SELECT * FROM mysqlcft_latin1.test WHERE MATCH(title,body) AGAINST ('北京 宽带' IN BOOLEAN MODE);<br/>SELECT * FROM mysqlcft_latin1.test WHERE MATCH(title,body) AGAINST ('mysqlcft' IN BOOLEAN MODE);<br/>SELECT * FROM mysqlcft_latin1.test WHERE MATCH(title,body) AGAINST ('数据' IN BOOLEAN MODE);</div><br/><br/>　　2、以UTF-8字符集为例<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">CREATE DATABASE `mysqlcft_utf8` CHARACTER SET utf8;<br/>USE `mysqlcft_utf8`;<br/>CREATE TABLE `test` (<br/>`id` int(10) unsigned NOT NULL AUTO_INCREMENT,<br/>`title` varchar(200) DEFAULT NULL,<br/>`body` mediumtext,<br/>PRIMARY KEY (`id`),<br/>FULLTEXT KEY `title_body` (`title`,`body`) <font color="red">WITH PARSER mysqlcft</font><br/>) ENGINE=MyISAM DEFAULT CHARSET=utf8;<br/><br/>INSERT INTO `mysqlcft_utf8`.`test` (`id`, `title`, `body`) VALUES (NULL, '北京房价', '北京市统计局、国家统计局北京调查总队近日联合对外发布消息，今年以来，北京的商品房价格一直呈上升趋势，五环路以内住宅期房均价已涨至13754元/平方米。');<br/>INSERT INTO `mysqlcft_utf8`.`test` (`id`, `title`, `body`) VALUES (NULL, '北京中心城区今起可无线宽带上网 奥运期间免费', '新浪科技讯 6月25日消息，北京无线城市一期网络今日起试运行，即日起北京市民和海外游客可以通过无线网络在北京中心城区接入互联网。');<br/>INSERT INTO `mysqlcft_utf8`.`test` (`id`, `title`, `body`) VALUES (NULL, '数据库', '欢迎使用MySQL中文全文索引插件mysqlcft！');<br/><br/>SELECT * FROM mysqlcft_utf8.test WHERE MATCH(title,body) AGAINST ('13754元/平方米' IN BOOLEAN MODE);<br/>SELECT * FROM mysqlcft_utf8.test WHERE MATCH(title,body) AGAINST ('6月25日' IN BOOLEAN MODE);<br/>SELECT * FROM mysqlcft_utf8.test WHERE MATCH(title,body) AGAINST ('北京' IN BOOLEAN MODE);<br/>SELECT * FROM mysqlcft_utf8.test WHERE MATCH(title,body) AGAINST ('北京 宽带' IN BOOLEAN MODE);<br/>SELECT * FROM mysqlcft_utf8.test WHERE MATCH(title,body) AGAINST ('mysqlcft' IN BOOLEAN MODE);<br/>SELECT * FROM mysqlcft_utf8.test WHERE MATCH(title,body) AGAINST ('数据' IN BOOLEAN MODE);</div><br/><br/>　　3、以gbk字符集为例<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">CREATE DATABASE `mysqlcft_gbk` DEFAULT CHARACTER SET gbk;<br/>USE `mysqlcft_gbk`;<br/>CREATE TABLE `test` (<br/>`id` int(10) unsigned NOT NULL AUTO_INCREMENT,<br/>`title` varchar(200) DEFAULT NULL,<br/>`body` mediumtext,<br/>PRIMARY KEY (`id`),<br/>FULLTEXT KEY `title_body` (`title`,`body`) <font color="red">WITH PARSER mysqlcft</font><br/>) ENGINE=MyISAM DEFAULT CHARSET=gbk;<br/><br/>INSERT INTO `mysqlcft_gbk`.`test` (`id`, `title`, `body`) VALUES (NULL, '北京房价', '北京市统计局、国家统计局北京调查总队近日联合对外发布消息，今年以来，北京的商品房价格一直呈上升趋势，五环路以内住宅期房均价已涨至13754元/平方米。');<br/>INSERT INTO `mysqlcft_gbk`.`test` (`id`, `title`, `body`) VALUES (NULL, '北京中心城区今起可无线宽带上网 奥运期间免费', '新浪科技讯 6月25日消息，北京无线城市一期网络今日起试运行，即日起北京市民和海外游客可以通过无线网络在北京中心城区接入互联网。');<br/>INSERT INTO `mysqlcft_gbk`.`test` (`id`, `title`, `body`) VALUES (NULL, '数据库', '欢迎使用MySQL中文全文索引插件mysqlcft！');<br/><br/>SELECT * FROM mysqlcft_gbk.test WHERE MATCH(title,body) AGAINST ('13754元/平方米' IN BOOLEAN MODE);<br/>SELECT * FROM mysqlcft_gbk.test WHERE MATCH(title,body) AGAINST ('6月25日' IN BOOLEAN MODE);<br/>SELECT * FROM mysqlcft_gbk.test WHERE MATCH(title,body) AGAINST ('北京' IN BOOLEAN MODE);<br/>SELECT * FROM mysqlcft_gbk.test WHERE MATCH(title,body) AGAINST ('北京 宽带' IN BOOLEAN MODE);<br/>SELECT * FROM mysqlcft_gbk.test WHERE MATCH(title,body) AGAINST ('mysqlcft' IN BOOLEAN MODE);<br/>SELECT * FROM mysqlcft_gbk.test WHERE MATCH(title,body) AGAINST ('数据' IN BOOLEAN MODE);</div><br/><br/><hr/><br/>　　<strong>八、性能测试报告</strong><br/>　　服务器：DELL PowerEdge 6850 (四颗双核Xeon 3.0GHz，8GB内存) 4U机架式服务器<br/>　　操作系统：RedHat AS4 (x86_64位)<br/>　　数据库：MySQL 5.1.25 RC + mysqlcft 1.0.0<br/>　　数据表：超过80万条(807346条)记录的表，字段“id”为int类型，主键；字段“title”为varchar类型，字段“body”为text类型。“title”和“body”分别建有INDEX普通单列索引、INDEX联合索引，FULLTEXT单字段全文索引、FULLTEXT联合全文索引。<br/><br/>　　1、在字段“title”中搜索中文关键字：<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">SELECT * FROM database.table WHERE MATCH(title) AGAINST ('朝阳区' IN BOOLEAN MODE) limit 0,30;<br/>30 rows in set (0.04 sec)<br/>SELECT * FROM database.table WHERE title LIKE '%朝阳区%' limit 0,30;<br/>30 rows in set (6.56 sec)<br/><br/>SELECT * FROM database.table WHERE MATCH(title) AGAINST ('通州区' IN BOOLEAN MODE) ORDER BY id DESC limit 0,30;<br/>30 rows in set (0.13 sec)<br/>SELECT * FROM database.table WHERE title LIKE '%通州区%' ORDER BY id DESC limit 0,30;<br/>30 rows in set (8.15 sec)<br/><br/>SELECT * FROM database.table WHERE MATCH(title) AGAINST ('建国门外' IN BOOLEAN MODE) ORDER BY id DESC limit 0,30;<br/>30 rows in set (0.08 sec)<br/>SELECT * FROM database.table WHERE title LIKE '%建国门外%' ORDER BY id DESC limit 0,30;<br/>30 rows in set (5.34 sec)<br/><br/>SELECT * FROM database.table WHERE MATCH(title) AGAINST ('靠近通惠河' IN BOOLEAN MODE) ORDER BY id DESC limit 0,30;<br/>4 row in set (0.06 sec)<br/>SELECT * FROM database.table WHERE title LIKE '%靠近通惠河%' ORDER BY id DESC limit 0,30;<br/>4 row in set (12.88 sec)</div><br/><br/>　　2、在字段“body”中搜索中文关键字：<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">SELECT * FROM database.table WHERE MATCH(body) AGAINST ('海淀区' IN BOOLEAN MODE) ORDER BY id DESC limit 0,30;<br/>30 rows in set (0.23 sec)<br/>SELECT * FROM database.table WHERE body LIKE '%海淀区%' ORDER BY id DESC limit 0,30;<br/>30 rows in set (15.71 sec)<br/><br/>SELECT * FROM database.table WHERE MATCH(body) AGAINST ('莱镇香格里' IN BOOLEAN MODE) ORDER BY id DESC limit 0,30;<br/>6 rows in set (0.18 sec)<br/>SELECT * FROM database.table WHERE body LIKE '%莱镇香格里%' ORDER BY id DESC limit 0,30;<br/>6 row in set (13.34 sec)</div><br/><br/>　　3、在字段“title”和“body”中，搜索包含“西城区”和“商场”两个关键字的记录：<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">SELECT * FROM database.table WHERE MATCH(title,body) AGAINST ('西城区 商场' IN BOOLEAN MODE) ORDER BY id DESC limit 0,30;<br/>13 rows in set (0.27 sec)<br/>SELECT * FROM database.table WHERE title LIKE '%西城区%商场%' OR body LIKE '%西城区%商场%' ORDER BY id DESC limit 0,30;<br/>13 rows in set (51.74 sec)</div><br/>Tags - <a href="tag.php?tag=mysqlcft" rel="tag">mysqlcft</a> , <a href="tag.php?tag=linux" rel="tag">linux</a> , <a href="tag.php?tag=mysql" rel="tag">mysql</a> , <a href="tag.php?tag=fulltext" rel="tag">fulltext</a> , <a href="tag.php?tag=%E5%85%A8%E6%96%87%E7%B4%A2%E5%BC%95" rel="tag">全文索引</a> , <a href="tag.php?tag=%E5%85%A8%E6%96%87%E6%A3%80%E7%B4%A2" rel="tag">全文检索</a> , <a href="tag.php?tag=%E5%85%A8%E6%96%87%E6%90%9C%E7%B4%A2" rel="tag">全文搜索</a> , <a href="tag.php?tag=%E6%90%9C%E7%B4%A2%E5%BC%95%E6%93%8E" rel="tag">搜索引擎</a>
]]>
</description>
</item><item>
<link>http://blog.s135.com/read.php?355</link>
<title><![CDATA[视频：托雷斯绝杀一击，西班牙1-0德国，问鼎2008欧洲杯冠军]]></title> 
<author>张宴 &lt;net@s135.com&gt;</author>
<category><![CDATA[生活琐事]]></category>
<pubDate>Mon, 30 Jun 2008 00:16:04 +0000</pubDate> 
<guid>http://blog.s135.com/read.php?355</guid> 
<description>
<![CDATA[ 
	　　北京时间6月30日凌晨，2008欧洲杯决赛打响，德国战车对阵西班牙斗牛士，第33分钟，哈维直塞，托雷斯首开纪录。以下是托雷斯进球视频。 <br/><br/>此处包含一个多媒体文件，请用网页方式查看。<br/><br/>Tags - <a href="tag.php?tag=%E6%AC%A7%E6%B4%B2%E6%9D%AF" rel="tag">欧洲杯</a> , <a href="tag.php?tag=%E5%86%B3%E8%B5%9B" rel="tag">决赛</a> , <a href="tag.php?tag=2008" rel="tag">2008</a> , <a href="tag.php?tag=%E5%86%A0%E5%86%9B" rel="tag">冠军</a> , <a href="tag.php?tag=%E5%BE%B7%E5%9B%BD" rel="tag">德国</a> , <a href="tag.php?tag=%E8%A5%BF%E7%8F%AD%E7%89%99" rel="tag">西班牙</a>
]]>
</description>
</item><item>
<link>http://blog.s135.com/read.php?354</link>
<title><![CDATA[Linux服务器系统监控框架与MSN、E-mail、手机短信报警的实现[原创]]]></title> 
<author>张宴 &lt;net@s135.com&gt;</author>
<category><![CDATA[纯粹技术]]></category>
<pubDate>Wed, 25 Jun 2008 00:10:34 +0000</pubDate> 
<guid>http://blog.s135.com/read.php?354</guid> 
<description>
<![CDATA[ 
	　　[文章作者：张宴 本文版本：v1.0 最后修改：2008.06.25 转载请注明原文链接：<a href="http://blog.s135.com/read.php/354.htm" target="_blank">http://blog.s135.com/read.php/354.htm</a>]<br/><br/>　　最近，在我原有的“Linux服务器系统监控程序”基础上，完善了HTTP、TCP、MySQL主动监控与MSN、E-mail、手机短信报警。监控程序以shell和PHP程序编写，以下为主要框架与部分代码：<br/><br/>　　一、系统监控接口程序（interface.php）具有的报警方式<br/>　　１、MSN实时报警<br/>　　①、监控程序每次检测到故障存在、或者故障恢复，都会发送短消息到管理员的MSN。<br/>　　<a href="http://blog.s135.com/attachment/200806/server_monitor1.png" target="_blank"><img src="http://blog.s135.com/attachment/200806/server_monitor1.png" class="insertimage" alt="点击在新窗口中浏览此图片" title="点击在新窗口中浏览此图片" border="0"/></a><br/><br/>　　<a href="http://blog.s135.com/attachment/200806/server_monitor2.png" target="_blank"><img src="http://blog.s135.com/attachment/200806/server_monitor2.png" class="insertimage" alt="点击在新窗口中浏览此图片" title="点击在新窗口中浏览此图片" border="0"/></a><br/><br/>　　发送MSN短消息用了一个PHP类：<a href="http://www.fanatic.net.nz/2005/02/15/send-a-message-using-php/" target="_blank">sendMsg</a>，使用该PHP类发消息，必须将发送、接收双方的MSN加为联系人，发送中文时，先用iconv将字符集转为UTF-8：<div class="quote"><div class="quote-title">引用</div><div class="quote-content">$sendMsg->sendMessage(iconv("GBK", "UTF-8", $message), 'Times New Roman', '008000');</div></div><br/><br/><hr/><br/>　　２、手机短信报警<br/>　　①、工作日早上10点之前，晚上6点之后，以及周六、周日，监控程序检测到故障，会调用手机短信接口，发送短信给管理员的手机。<br/>　　②、如果监控程序多次检测到同一台服务器的同一类故障，只会在第一次检测到故障时发送一条“故障报警”短信。服务器故障恢复后，监控程序会再发送一条“故障恢复”短信。<br/><br/>　　如果没有手机短信网关接口，可以试试中国移动通信的<a href="http://www.139.com" target="_blank">www.139.com</a>邮箱，具有<span style="color: #FF0000;">免费</span>的邮件到达手机短信通知功能，可以将收到的邮件标题以短信的形式发送到手机上。<br/><br/><hr/><br/>　　３、电子邮件报警<br/>　　①、如果监控程序多次检测到同一台服务器的同一类故障，只会在第一次检测到故障时发送一封“故障报警”邮件。服务器故障恢复后，监控程序会再发送一封“故障恢复”邮件。<br/><br/>　　系统监控接口程序interface.php（核心部分，仅提供部分代码）：<br/>[codes=php]<?php<br/>//HTTP服务器监控<br/>if (htmlspecialchars($_POST["menu"]) == "http") &nbsp; <br/>{ &nbsp; <br/> &nbsp; &nbsp;$date = htmlspecialchars($_POST["date"]); &nbsp; <br/> &nbsp; &nbsp;$ip = htmlspecialchars($_POST["ip"]);<br/> &nbsp; &nbsp;$port = htmlspecialchars($_POST["port"]);<br/> &nbsp; &nbsp;$status = htmlspecialchars($_POST["status"]);//状态，0表示无法访问，1表示正常，2表示无法访问但能ping通<br/> &nbsp; &nbsp;//...下一步处理（省略）... &nbsp;<br/>}<br/><br/>//TCP服务器监控<br/>if (htmlspecialchars($_POST["menu"]) == "tcp") &nbsp; <br/>{ &nbsp; <br/> &nbsp; &nbsp;$date = htmlspecialchars($_POST["date"]); &nbsp; <br/> &nbsp; &nbsp;$ip = htmlspecialchars($_POST["ip"]);<br/> &nbsp; &nbsp;$port = htmlspecialchars($_POST["port"]);<br/> &nbsp; &nbsp;$status = htmlspecialchars($_POST["status"]);//状态，0表示无法访问，1表示正常，2表示无法访问但能ping通<br/> &nbsp; &nbsp;//...下一步处理（省略）...<br/>}<br/><br/>//MySQL服务器监控<br/>if (htmlspecialchars($_POST["menu"]) == "mysql") &nbsp; <br/>{ &nbsp; <br/> &nbsp; &nbsp;$date = htmlspecialchars($_POST["date"]); &nbsp; <br/> &nbsp; &nbsp;$ip = htmlspecialchars($_POST["ip"]);<br/> &nbsp; &nbsp;$port = htmlspecialchars($_POST["port"]);<br/> &nbsp; &nbsp;$abstract = htmlspecialchars($_POST["abstract"]);//故障摘要（必须为全角）<br/> &nbsp; &nbsp;$info = htmlspecialchars($_POST["info"]);//故障详细描述<br/> &nbsp; &nbsp;$failback = htmlspecialchars($_POST["failback"]);//如果服务器存活，此处接收的值为active<br/> &nbsp; &nbsp;//...下一步处理（省略）...<br/>}<br/>?>[/codes]<hr/><br/>　　二、主动探测监控（“监控机”主动探测“被监控机”）<br/>　　１、HTTP服务器监控<br/>　　脚本：/data0/monitor/http.sh<br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content">#!/bin/sh<br/>LANG=C<br/><br/>#被监控服务器、端口列表<br/>server_all_list=(&#92;<br/>192.168.1.1:80 &#92;<br/>192.168.1.2:80 &#92;<br/>192.168.1.3:80 &#92;<br/>)<br/><br/>date=$(date -d "today" +"%Y-%m-%d_%H:%M:%S")<br/><br/>#采用HTTP POST方式发送检测信息给接口程序interface.php，接口程序负责分析信息，决定是否发送报警MSN消息、手机短信、电子邮件。<br/>send_msg_to_interface()<br/>{<br/> &nbsp; &nbsp;/usr/bin/curl -m 600 -d menu=http -d date=$date -d ip=$server_ip -d port=$server_port -d status=$status <a href="http://127.0.0.1:8888/interface.php" target="_blank">http://127.0.0.1:8888/interface.php</a><br/>}<br/><br/>server_all_len=${#server_all_list[*]}<br/>i=0<br/>while &nbsp;[ $i -lt $server_all_len ]<br/>do<br/> &nbsp; &nbsp;server_ip=$(echo ${server_all_list[$i]} &#124; awk -F ':' '{print $1}')<br/> &nbsp; &nbsp;server_port=$(echo ${server_all_list[$i]} &#124; awk -F ':' '{print $2}')<br/> &nbsp; &nbsp;if curl -m 10 -G <a href="http://$" target="_blank">http://$</a>{server_all_list[$i]}/ > /dev/null 2>&1<br/> &nbsp; &nbsp;then<br/> &nbsp; &nbsp; &nbsp;#status: &nbsp; &nbsp;0,http down &nbsp; &nbsp;1,http ok &nbsp; &nbsp;2,http down but ping ok <br/> &nbsp; &nbsp; &nbsp;status=1<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;echo "服务器${server_ip}，端口${server_port}能够正常访问！"<br/> &nbsp; &nbsp;else<br/> &nbsp; &nbsp; &nbsp; &nbsp;if curl -m 30 -G <a href="http://$" target="_blank">http://$</a>{server_all_list[$i]}/ > /dev/null 2>&1<br/> &nbsp; &nbsp; &nbsp; &nbsp;then<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;status=1<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;echo "服务器${server_ip}，端口${server_port}能够正常访问！"<br/> &nbsp; &nbsp; &nbsp; &nbsp;else<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if ping -c 1 $server_ip > /dev/null 2>&1<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;then<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;status=2<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;echo "服务器${server_ip}，端口${server_port}无法访问，但是能够Ping通！"<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;status=0<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;echo "服务器${server_ip}，端口${server_port}无法访问，并且无法Ping通！"<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;fi<br/> &nbsp; &nbsp; &nbsp; &nbsp;fi<br/> &nbsp; &nbsp;fi<br/> &nbsp;send_msg_to_interface<br/> &nbsp; &nbsp;let i++<br/>done</div></div><br/><hr/><br/>　　２、TCP服务器监控<br/>　　脚本：/data0/monitor/tcp.sh<br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content">#!/bin/sh<br/>LANG=C<br/><br/>#被监控服务器、端口列表<br/>server_all_list=(&#92;<br/>192.168.1.4:11211 &#92;<br/>192.168.1.5:11211 &#92;<br/>192.168.1.6:25 &#92;<br/>192.168.1.7:25 &#92;<br/>)<br/><br/>date=$(date -d "today" +"%Y-%m-%d_%H:%M:%S")<br/><br/>#采用HTTP POST方式发送检测信息给接口程序interface.php，接口程序负责分析信息，决定是否发送报警MSN消息、手机短信、电子邮件。<br/>send_msg_to_interface()<br/>{<br/> &nbsp; &nbsp;/usr/bin/curl -m 600 -d menu=tcp -d date=$date -d ip=$server_ip -d port=$server_port -d status=$status <a href="http://127.0.0.1:8888/interface.php" target="_blank">http://127.0.0.1:8888/interface.php</a><br/>}<br/><br/>server_all_len=${#server_all_list[*]}<br/>i=0<br/>while &nbsp;[ $i -lt $server_all_len ]<br/>do<br/> &nbsp; &nbsp;server_ip=$(echo ${server_all_list[$i]} &#124; awk -F ':' '{print $1}')<br/> &nbsp; &nbsp;server_port=$(echo ${server_all_list[$i]} &#124; awk -F ':' '{print $2}')<br/> &nbsp; &nbsp;if nc -vv -z -w 3 $server_ip $server_port > /dev/null 2>&1<br/> &nbsp; &nbsp;then<br/> &nbsp; &nbsp; &nbsp; &nbsp;#status: &nbsp; &nbsp;0,http down &nbsp; &nbsp;1,http ok &nbsp; &nbsp;2,http down but ping ok <br/> &nbsp; &nbsp; &nbsp; &nbsp;status=1<br/> &nbsp; &nbsp; &nbsp; &nbsp;echo "服务器${server_ip}，端口${server_port}能够正常访问！"<br/> &nbsp; &nbsp;else<br/> &nbsp; &nbsp; &nbsp; &nbsp;if nc -vv -z -w 10 $server_ip $server_port > /dev/null 2>&1<br/> &nbsp; &nbsp; &nbsp; &nbsp;then<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;status=1<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;echo "服务器${server_ip}，端口${server_port}能够正常访问！"<br/> &nbsp; &nbsp; &nbsp; &nbsp;else<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if ping -c 1 $server_ip > /dev/null 2>&1<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;then<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;status=2<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;echo "服务器${server_ip}，端口${server_port}无法访问，但是能够Ping通！"<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;status=0<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;echo "服务器${server_ip}，端口${server_port}无法访问，并且无法Ping通！"<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;fi<br/> &nbsp; &nbsp; &nbsp; &nbsp;fi<br/> &nbsp; &nbsp;fi<br/> &nbsp; &nbsp;send_msg_to_interface<br/> &nbsp; &nbsp;let i++<br/>done</div></div><br/><hr/><br/>　　３、MySQL服务器监控<br/>　　①、MySQL是否能够连接<br/>　　②、MySQL是否发生表损坏等错误<br/>　　③、MySQL活动连接数是否过多<br/>　　④、MySQL从库是否同步正常<br/>　　⑤、MySQL从库同步延迟时间是否过大<br/>　　脚本：/data0/monitor/mysql.php<br/>[codes=php]<?php<br/>//$server_list[]="服务器地址:端口:帐号:密码";<br/>$server_list[]="192.168.1.11:3306:root:password";<br/>$server_list[]="192.168.1.12:3306:root:password";<br/>$server_list[]="192.168.1.13:3306:root:password";<br/><br/>$database="mysql";<br/><br/>$curl = new Curl_Class(); <br/><br/>foreach ($server_list as $server) {<br/> &nbsp; &nbsp;$status=1;//初始化，正常状态<br/> &nbsp;unset($data);<br/> &nbsp; &nbsp;$data["menu"] = "mysql";<br/> &nbsp;$data["info"] = "";<br/> &nbsp; &nbsp;list($data["ip"], $data["port"], $username, $password) = explode(":", $server);<br/><br/> &nbsp; &nbsp;$connect = @mysql_connect($data["ip"].":".$data["port"], $username, $password);<br/> &nbsp; &nbsp;if(! $connect)<br/> &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp;$status=0;<br/> &nbsp; &nbsp; &nbsp; &nbsp;$data["info"] = $data["info"] . "无法连接MySQL服务器&#92;r&#92;n";<br/> &nbsp; &nbsp;}<br/> &nbsp;<br/> &nbsp; &nbsp;$select = @mysql_select_db($database, $connect);<br/> &nbsp; &nbsp;$result = @mysql_query("show slave status");<br/> &nbsp; &nbsp;$rs_slave = @mysql_fetch_array($result);<br/> &nbsp; &nbsp;$result = @mysql_query("show global status like 'Threads_running'");<br/> &nbsp; &nbsp;$rs_threads = @mysql_fetch_array($result);<br/> &nbsp; &nbsp;if($rs_slave["Slave_SQL_Running"] == "No")<br/> &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp;$status=0;//故障状态<br/> &nbsp; &nbsp; &nbsp; &nbsp;$data["abstract"] = "从库不同步";<br/> &nbsp; &nbsp; &nbsp; &nbsp;$data["info"] = $data["info"] . "Slave_SQL_Running = No&#92;r&#92;n"; &nbsp;<br/> &nbsp; &nbsp;}<br/> &nbsp; &nbsp;if($rs_slave["Slave_IO_Running"] == "No")<br/> &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp;$status=0;<br/> &nbsp; &nbsp; &nbsp; &nbsp;$data["abstract"] = "从库不同步";<br/> &nbsp; &nbsp; &nbsp; &nbsp;$data["info"] = $data["info"] . "Slave_IO_Running = No&#92;r&#92;n"; &nbsp;<br/> &nbsp; &nbsp;}<br/> &nbsp; &nbsp;if($rs_slave["Last_Error"] != "")<br/> &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp;$status=0;<br/> &nbsp; &nbsp; &nbsp; &nbsp;$data["abstract"] = "从库同步出错";<br/> &nbsp; &nbsp; &nbsp; &nbsp;$data["info"] = $data["info"] . "Last_Error = ".substr($rs_slave["Last_Error"], 0, 40)."&#92;r&#92;n";<br/> &nbsp; &nbsp;}<br/> &nbsp; &nbsp;if($rs_slave["Seconds_Behind_Master"] > 180)<br/> &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp;$status=0;<br/> &nbsp; &nbsp; &nbsp; &nbsp;$data["abstract"] = "从库同步延迟时间高达".$rs_slave["Seconds_Behind_Master"]."秒";<br/> &nbsp; &nbsp; &nbsp; &nbsp;$data["info"] = $data["info"] . "Seconds_Behind_Master = ".$rs_slave["Seconds_Behind_Master"]."&#92;r&#92;n";<br/> &nbsp; &nbsp;}<br/> &nbsp; &nbsp;if($rs_threads["Value"] > 60)<br/> &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp;$status=0;<br/> &nbsp; &nbsp; &nbsp; &nbsp;$data["abstract"] = "活动连接数多达".$rs_threads["Value"];<br/> &nbsp; &nbsp; &nbsp; &nbsp;$data["info"] = $data["info"] . "Threads_running = ".$rs_threads["Value"]."&#92;r&#92;n";<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;$data["date"] = date("Y-m-d_H:i:s");<br/> &nbsp; &nbsp;if($status == 0)<br/> &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp;$post = @$curl->post("http://127.0.0.1:8888/interface.php", $data);<br/> &nbsp; &nbsp; &nbsp; &nbsp;echo "MySQL服务器“".$data["ip"].":".$data["port"]."”发生故障!&#92;n";<br/> &nbsp; &nbsp; &nbsp; &nbsp;print_r($post); &nbsp; &nbsp; &nbsp;<br/> &nbsp; &nbsp;}<br/> &nbsp; &nbsp;else<br/> &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp;$data["failback"] = "active";//服务器正常，发送通知信息<br/> &nbsp; &nbsp; &nbsp; &nbsp;$post = @$curl->post("http://127.0.0.1:8888/interface.php", $data);<br/> &nbsp; &nbsp; &nbsp; &nbsp;echo "MySQL服务器“".$data["ip"].":".$data["port"]."”运行正常!&#92;n";<br/> &nbsp; &nbsp; &nbsp; &nbsp;print_r($post);<br/> &nbsp; &nbsp;}<br/>}<br/><br/>/**<br/>*********************************************************************<br/>* Curl_Class :curl 类<br/>*********************************************************************/<br/>class Curl_Class<br/>{<br/> &nbsp; &nbsp;function Curl_Class()<br/> &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp;return true;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;function execute($method, $url, $fields = '', $userAgent = '', $httpHeaders = '',<br/> &nbsp; &nbsp; &nbsp; &nbsp;$username = '', $password = '')<br/> &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp;$ch = Curl_Class::create();<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (false === $ch)<br/> &nbsp; &nbsp; &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return false;<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;if (is_string($url) && strlen($url))<br/> &nbsp; &nbsp; &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$ret = curl_setopt($ch, CURLOPT_URL, $url);<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;else<br/> &nbsp; &nbsp; &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return false;<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;//是否显示头部信息<br/> &nbsp; &nbsp; &nbsp; &nbsp;curl_setopt($ch, CURLOPT_HEADER, false);<br/> &nbsp; &nbsp; &nbsp; &nbsp;//<br/> &nbsp; &nbsp; &nbsp; &nbsp;curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;if ($username != '')<br/> &nbsp; &nbsp; &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;curl_setopt($ch, CURLOPT_USERPWD, $username . ':' . $password);<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;$method = strtolower($method);<br/> &nbsp; &nbsp; &nbsp; &nbsp;if ('post' == $method)<br/> &nbsp; &nbsp; &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;curl_setopt($ch, CURLOPT_POST, true);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (is_array($fields))<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$sets = array();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;foreach ($fields as $key => $val)<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$sets[] = $key . '=' . urlencode($val);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$fields = implode('&', $sets);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;else<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if ('put' == $method)<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;curl_setopt($ch, CURLOPT_PUT, true);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;//curl_setopt($ch, CURLOPT_PROGRESS, true);<br/> &nbsp; &nbsp; &nbsp; &nbsp;//curl_setopt($ch, CURLOPT_VERBOSE, true);<br/> &nbsp; &nbsp; &nbsp; &nbsp;//curl_setopt($ch, CURLOPT_MUTE, false);<br/> &nbsp; &nbsp; &nbsp; &nbsp;curl_setopt($ch, CURLOPT_TIMEOUT, 600);<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;if (strlen($userAgent))<br/> &nbsp; &nbsp; &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;if (is_array($httpHeaders))<br/> &nbsp; &nbsp; &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeaders);<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;$ret = curl_exec($ch);<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;if (curl_errno($ch))<br/> &nbsp; &nbsp; &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;curl_close($ch);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return array(curl_error($ch), curl_errno($ch));<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;else<br/> &nbsp; &nbsp; &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;curl_close($ch);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (!is_string($ret) &#124;&#124; !strlen($ret))<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return false;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return $ret;<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;function post($url, $fields, $userAgent = '', $httpHeaders = '', $username = '',<br/> &nbsp; &nbsp; &nbsp; &nbsp;$password = '')<br/> &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp;$ret = Curl_Class::execute('POST', $url, $fields, $userAgent, $httpHeaders, $username,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$password);<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (false === $ret)<br/> &nbsp; &nbsp; &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return false;<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;if (is_array($ret))<br/> &nbsp; &nbsp; &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return false;<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;return $ret;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;function get($url, $userAgent = '', $httpHeaders = '', $username = '', $password =<br/> &nbsp; &nbsp; &nbsp; &nbsp;'')<br/> &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp;$ret = Curl_Class::execute('GET', $url, '', $userAgent, $httpHeaders, $username,<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$password);<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (false === $ret)<br/> &nbsp; &nbsp; &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return false;<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;if (is_array($ret))<br/> &nbsp; &nbsp; &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return false;<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;return $ret;<br/> &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp;function create()<br/> &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp;$ch = null;<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (!function_exists('curl_init'))<br/> &nbsp; &nbsp; &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return false;<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;$ch = curl_init();<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (!is_resource($ch))<br/> &nbsp; &nbsp; &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return false;<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;return $ch;<br/> &nbsp; &nbsp;}<br/><br/>}<br/>?>[/codes]<hr/><br/>　　4、主动监控守护进程<br/>　　脚本：/data0/monitor/monitor.sh<br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content">#!/bin/sh<br/>while true<br/>do<br/> &nbsp; &nbsp;/bin/sh /data0/monitor/http.sh > /dev/null 2>&1<br/> &nbsp; &nbsp;/bin/sh /data0/monitor/tcp.sh > /dev/null 2>&1<br/> &nbsp; &nbsp;/usr/local/php/bin/php /data0/monitor/mysql.php > /dev/null 2>&1<br/> &nbsp; &nbsp;sleep 10<br/>done</div></div><br/><br/>　　启动主动监控守护进程：<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">/usr/bin/nohup /bin/sh /data0/monitor/monitor.sh 2>&1 > /dev/null &</div><br/><hr/><br/>　　三、被动报告监控（“被监控机”采集数据发送给“监控机”）<br/>　　１、磁盘空间使用量监控<br/>　　２、磁盘Inode使用量监控<br/>　　３、Swap交换空间使用量监控<br/>　　４、系统负载监控<br/>　　５、Apache进程数监控<br/><br/>　　被动监控这部分，在我的文章《<a href="read.php/291.htm" target="_blank">写完“Linux服务器监控系统 ServMon V1.1”</a> 》中已经实现，就不再详细写出。<br/><br/><br/>Tags - <a href="tag.php?tag=linux" rel="tag">linux</a> , <a href="tag.php?tag=tcp" rel="tag">tcp</a> , <a href="tag.php?tag=http" rel="tag">http</a> , <a href="tag.php?tag=shell" rel="tag">shell</a> , <a href="tag.php?tag=php" rel="tag">php</a>
]]>
</description>
</item><item>
<link>http://blog.s135.com/read.php?353</link>
<title><![CDATA[2008开源在中国]]></title> 
<author>张宴 &lt;net@s135.com&gt;</author>
<category><![CDATA[电脑杂谈]]></category>
<pubDate>Tue, 24 Jun 2008 00:29:22 +0000</pubDate> 
<guid>http://blog.s135.com/read.php?353</guid> 
<description>
<![CDATA[ 
	　　虽然没有订阅过全年的《程序员》杂志，但是，买到的这本以“2008开源在中国”为主题的2008年06期《程序员》，还是值得一看的。<br/><br/>　　<a href="http://blog.s135.com/attachment/200806/cxy.gif" target="_blank"><img src="http://blog.s135.com/attachment/200806/cxy.gif" class="insertimage" alt="点击在新窗口中浏览此图片" title="点击在新窗口中浏览此图片" border="0" align="right"/></a>专题布局：<br/>　　（1）2008开源在中国<br/>　　（2）说不尽的开源——记“开源在中国2008”研讨会<br/>　　（3）摸着石头过河——记开源社区huihu.org<br/>　　（4）莫等闲，抬望云和月<br/>　　（5）从一封信说起——记姜太文博士和他的<a href="http://xoops.org.cn/" target="_blank">XOOPS项目</a><br/>　　（6）比开源更自由的存在——<a href="http://www.zeuux.org/community/zeuux-salon.cn.html" target="_blank">哲思自由软件社区</a>专访<br/>　　（7）<a href="http://tech.sina.com.cn/s/s/2008-06-18/0751697637.shtml" target="_blank">解密淘宝网的开源架构</a><br/>　　（8）自由软件和新浪网<br/>　　（9）项庄舞剑，意在沛公？——评国际软件巨头的开源策略<br/>　　（10）大企业如何助力开源<br/>　　（11）让漫天繁星在指尖随心闪耀——专访开源专家马越<br/>　　（12）开源商业模式介绍<br/>　　（13）与开源共成长<br/>　　（14）ZK创始人叶明宪的开源进行时<br/>　　（15）开源者说——一个开源项目贡献者的自白<br/>　　（16）开源离我们有多远——中国开源现状调查<br/>　　（17）开源授权协议（License）初探<br/>　　（18）一个程序员谈开源 &nbsp; <br/><br/>　　架构专栏：<br/>　　（1）Web架构师的能力 <br/>　　Web架构师要在技术和业务之间找到平衡，选择最低成本的技术来实现业务需求，还要适当地为业务发展保留适当的平台空间。 &nbsp; <br/> <br/>　　（2）炫目的敏捷架构师<br/>　　随着敏捷软件开发的理念和方法论逐渐被越来越多的人接受，敏捷架构师在团队中的地位也越来越重要，本文讲述一个敏捷架构师应该具备的一些基本素质。 &nbsp; <br/> <br/>　　（3）写给Web2.0站长，不仅仅是泼冷水<br/>　　看到国外Web2.0站点的火热发展，国内众多Web创业者两眼发红，抄得兴起。然而没有扎实的技术积累和人才储备，要想持续发展几乎是不可能的事情。 &nbsp; <br/> <br/>　　（4）豆瓣的架构 &nbsp; <br/>　　经常有人说web2.0融资困难，商业模式不清楚，可能这是真的。但从技术上看，互联网技术不可能一成不变,本期选登的这两篇文章，可以让我们看到这方面的发展。 &nbsp; 
]]>
</description>
</item><item>
<link>http://blog.s135.com/read.php?352</link>
<title><![CDATA[使用Nginx作为Web服务器的国内网站[原创]]]></title> 
<author>张宴 &lt;net@s135.com&gt;</author>
<category><![CDATA[纯粹技术]]></category>
<pubDate>Thu, 19 Jun 2008 00:30:15 +0000</pubDate> 
<guid>http://blog.s135.com/read.php?352</guid> 
<description>
<![CDATA[ 
	　　[文章作者：张宴 本文版本：v1.1 最后修改：2008.06.19 转载请注明原文链接：<a href="http://blog.s135.com/read.php/352.htm" target="_blank">http://blog.s135.com/read.php/352.htm</a>]<br/><br/>　　Nginx <a href="read.php/351.htm" target="_blank">超越Apache的高性能和稳定性</a>，使得国内使用 Nginx 作为 Web 服务器的网站也越来越多，其中有新浪、网易、腾讯等门户网站，六间房、酷6等视频分享网站，Discuz!、水木社区等知名论坛，豆瓣、YUPOO等新兴Web 2.0网站。<br/><br/>　　Nginx 在国内的应用正在不断发展壮大！<br/><br/>　　<strong>一、使用 Nginx 运行 PHP(FastCGI) 程序的网站：</strong><br/> <br/>　　1、六间房视频（<a href="http://www.6.cn/" target="_blank">http://www.6.cn/</a>）：nginx/0.6.14 + PHP<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">[root@new-host ~]# curl --head <a href="http://6.cn/reg.php" target="_blank">http://6.cn/reg.php</a><br/>HTTP/1.0 200 OK<br/>Server: nginx/0.6.14<br/>Date: Wed, 18 Jun 2008 00:58:20 GMT<br/>Content-Type: text/html<br/>Vary: Accept-Encoding<br/>X-Cache: MISS from YZ-W-146<br/>X-Cache-Lookup: MISS from YZ-W-146:80<br/>Via: 1.0 YZ-W-146 (squid/3.0.STABLE1.dev)<br/>Connection: close</div><br/><br/>　　2、Discuz!官方论坛（<a href="http://www.discuz.net/" target="_blank">http://www.discuz.net/</a>）：nginx/0.7.2 + PHP/5.2.6<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">[root@new-host ~]# curl --head <a href="http://www.discuz.net/index.php" target="_blank">http://www.discuz.net/index.php</a><br/>HTTP/1.1 200 OK<br/>Server: nginx/0.7.2<br/>Date: Wed, 18 Jun 2008 00:57:16 GMT<br/>Content-Type: text/html<br/>Transfer-Encoding: chunked<br/>Connection: keep-alive<br/>X-Powered-By: PHP/5.2.6<br/>Set-Cookie: dznet_sid=Ek9XYc; expires=Wed, 25-Jun-2008 00:57:16 GMT; path=/; domain=.discuz.net</div><br/><br/>　　3、互联星空播客[新浪服务器]（<a href="http://you.video.vnet.cn/" target="_blank">http://you.video.vnet.cn/</a>）：nginx/0.5.33 + PHP/5.2.5<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">[root@new-host ~]# curl --head <a href="http://you.video.vnet.cn/pg/user/userHead.js.php" target="_blank">http://you.video.vnet.cn/pg/user/userHead.js.php</a><br/>HTTP/1.1 200 OK<br/>Server: nginx/0.5.33<br/>Content-Type: text/html; charset=gb2312<br/>X-Powered-By: PHP/5.2.5<br/>Expires: Sun, 13 Jul 2008 05:43:16 GMT<br/>Last-Modified: Fri, 13 Jun 2008 05:43:16GMT<br/>Content-Encoding: gzip<br/>Content-Length: 22403<br/>Date: Wed, 18 Jun 2008 01:09:33 GMT<br/>X-Varnish: 1426517043 1413292132<br/>Age: 415577<br/>Via: 1.1 varnish<br/>Connection: keep-alive</div><br/><br/>　　4、水木社区（<a href="http://www.newsmth.net/" target="_blank">http://www.newsmth.net/</a>）：nginx/0.5.35 + PHP<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">[root@new-host ~]# curl --head <a href="http://www.newsmth.net/img_rand/img_rand.php" target="_blank">http://www.newsmth.net/img_rand/img_rand.php</a><br/>HTTP/1.1 200 OK<br/>Server: nginx/0.5.35<br/>Date: Wed, 18 Jun 2008 00:59:01 GMT<br/>Content-Type: image/png<br/>Transfer-Encoding: chunked<br/>Connection: keep-alive<br/>Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0<br/>Expires: Thu, 19 Nov 1981 08:52:00 GMT<br/>Set-Cookie: PHPSESSID=fbb54a90ff0d42f92f49978512902a20; expires=Wednesday, 18-Jun-08 01:59:01 GMT; path=/<br/>Pragma: no-cache<br/>X-Cache: MISS from <a href="http://www.newsmth.net" target="_blank">www.newsmth.net</a></div><br/><br/>　　5、落伍者站长论坛（<a href="http://www.im286.com/" target="_blank">http://www.im286.com/</a>）：nginx/0.6.29 + PHP/5.1.6<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">[root@new-host ~]# curl --head <a href="http://www.im286.com/" target="_blank">http://www.im286.com/</a><br/>HTTP/1.1 200 OK<br/>Server: nginx/0.6.29<br/>Date: Wed, 18 Jun 2008 02:20:48 GMT<br/>Content-Type: text/html<br/>Transfer-Encoding: chunked<br/>Connection: keep-alive<br/>X-Powered-By: PHP/5.1.6<br/>Set-Cookie: cdb_sid=eO31Jb; expires=Wed, 25-Jun-2008 02:20:48 GMT; path=/</div><br/><br/><hr/><br/>　　<strong>二、使用 Nginx 作反向代理、规则过滤的网站：</strong><br/><br/>　　1、新浪博客（<a href="http://blog.sina.com.cn/" target="_blank">http://blog.sina.com.cn/</a>）：nginx/0.5.35<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">[root@new-host ~]# curl --head <a href="http://blog.sina.com.cn/" target="_blank">http://blog.sina.com.cn/</a><br/>HTTP/1.1 200 OK<br/>Server: nginx/0.5.35<br/>Date: Wed, 18 Jun 2008 01:18:50 GMT<br/>Content-Type: text/html<br/>Content-Length: 491279<br/>Last-Modified: Wed, 18 Jun 2008 01:14:16 GMT<br/>Connection: keep-alive<br/>Expires: Wed, 18 Jun 2008 01:19:20 GMT<br/>Cache-Control: max-age=30<br/>Accept-Ranges: bytes</div><br/><br/>　　2、YUPOO相册（<a href="http://www.yupoo.com/" target="_blank">http://www.yupoo.com/</a>）：nginx/0.5.35<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">[root@new-host ~]# curl --head <a href="http://www.yupoo.com/" target="_blank">http://www.yupoo.com/</a> <br/>HTTP/1.1 200 OK<br/>Server: nginx/0.5.35<br/>Date: Wed, 18 Jun 2008 01:58:04 GMT<br/>Content-Type: text/html;charset=UTF-8<br/>Transfer-Encoding: chunked<br/>Connection: keep-alive<br/>Set-Cookie: JSESSIONID=EC1A7935-4C66-B834-8B5B-495E958A6B53; Domain=.yupoo.com; Path=/<br/>Content-Language: zh-CN</div><br/><hr/><br/>　　<strong>三、使用 Nginx 运行静态HTML页、图片、FLV视频的网站：</strong><br/><br/>　　1、网易新闻（<a href="http://news.163.com/" target="_blank">http://news.163.com/</a>）：nginx/0.6.31<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">[root@new-host ~]# curl --head <a href="http://news.163.com/" target="_blank">http://news.163.com/</a><br/>HTTP/1.0 200 OK<br/>Server: nginx/0.6.31<br/>Date: Wed, 18 Jun 2008 01:17:04 GMT<br/>Content-Type: text/html; charset=GBK<br/>Expires: Wed, 18 Jun 2008 01:20:04 GMT<br/>Cache-Control: max-age=180<br/>X-Cache: MISS from cgi-gzip.163.com<br/>Content-Length: 259923<br/>Vary: Accept-Encoding<br/>Age: 74<br/>X-Cache: HIT from news.163.com<br/>Connection: close</div><br/><br/>　　2、酷6网（<a href="http://www.ku6.com/" target="_blank">http://www.ku6.com/</a>）视频服务器：nginx/0.5.36<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">[root@new-host ~]# curl --head <a href="http://video.ku6.com/" target="_blank">http://video.ku6.com/</a><br/>HTTP/1.1 404 Not Found<br/>Server: nginx/0.5.36<br/>Date: Wed, 18 Jun 2008 01:50:06 GMT<br/>Content-Type: text/html; charset=utf-8<br/>Connection: keep-alive<br/>Last-Modified: Sun, 05 Aug 2007 09:49:48 GMT<br/>Accept-Ranges: bytes<br/>Content-Length: 18782<br/>Vary: Accept-Encoding<br/>X-Cache: MISS from CDN-TJ-249</div><br/><br/>　　3、豆瓣网（<a href="http://www.douban.com/" target="_blank">http://www.douban.com/</a>）：nginx<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">[root@new-host ~]# curl --head <a href="http://www.douban.com/" target="_blank">http://www.douban.com/</a> &nbsp; &nbsp;<br/>HTTP/1.1 200 OK<br/>Server: nginx<br/>Date: Wed, 18 Jun 2008 01:56:58 GMT<br/>Content-Type: text/html; charset=utf-8<br/>Status: 200 OK<br/>Content-Length: 30106<br/>Expires: Sun, 1 Jan 2006 01:00:00 GMT<br/>Pragma: no-cache<br/>Cache-Control: must-revalidate, no-cache, private<br/>Set-Cookie: bid="rAlrIPo2jl4"; path=/; domain=.douban.com; expires=Thu, 01-Jan-2009 00:00:00 GMT</div><br/><br/>　　4、新华网RSS订阅频道（<a href="http://rss.xinhuanet.com/" target="_blank">http://rss.xinhuanet.com/</a>）：nginx<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">[root@new-host ~]# curl --head <a href="http://rss.xinhuanet.com/" target="_blank">http://rss.xinhuanet.com/</a><br/>HTTP/1.1 200 OK<br/>Server: nginx<br/>Date: Wed, 18 Jun 2008 01:18:00 GMT<br/>Content-Type: text/xml<br/>Content-Length: 4592<br/>Last-Modified: Mon, 26 Jun 2006 09:33:54 GMT<br/>Connection: keep-alive<br/>Expires: Wed, 18 Jun 2008 01:24:00 GMT<br/>Cache-Control: max-age=360<br/>Accept-Ranges: bytes</div><br/><br/>　　5、迅雷安全中心（<a href="http://safe.xunlei.com/" target="_blank">http://safe.xunlei.com/</a>）：nginx/0.6.31<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">[root@new-host ~]# curl --head <a href="http://safe.xunlei.com/" target="_blank">http://safe.xunlei.com/</a><br/>HTTP/1.1 200 OK<br/>Server: nginx/0.6.31<br/>Date: Wed, 18 Jun 2008 02:05:54 GMT<br/>Content-Type: text/html; charset=gb2312<br/>Content-Length: 13060<br/>Last-Modified: Thu, 12 Jun 2008 12:13:03 GMT<br/>Connection: keep-alive<br/>Keep-Alive: timeout=30<br/>Expires: Wed, 25 Jun 2008 02:05:54 GMT<br/>Cache-Control: max-age=604800<br/>Accept-Ranges: bytes</div><br/><br/>　　6、腾讯3G下载（<a href="http://down.3g.qq.com/" target="_blank">http://down.3g.qq.com/</a>）：nginx/0.5.33<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">[root@new-host ~]# curl --head <a href="http://down.3g.qq.com/" target="_blank">http://down.3g.qq.com/</a><br/>HTTP/1.1 403 Forbidden<br/>Server: nginx/0.5.33<br/>Date: Thu, 19 Jun 2008 05:50:44 GMT<br/>Content-Type: text/html<br/>Content-Length: 169<br/>Connection: keep-alive</div><br/><br/><br/>Tags - <a href="tag.php?tag=linux" rel="tag">linux</a> , <a href="tag.php?tag=php" rel="tag">php</a> , <a href="tag.php?tag=nginx" rel="tag">nginx</a>
]]>
</description>
</item><item>
<link>http://blog.s135.com/read.php?351</link>
<title><![CDATA[Nginx 0.6.31 + PHP 5.2.6（FastCGI）搭建胜过Apache十倍的Web服务器（第3版）[原创]]]></title> 
<author>张宴 &lt;net@s135.com&gt;</author>
<category><![CDATA[纯粹技术]]></category>
<pubDate>Mon, 09 Jun 2008 15:08:02 +0000</pubDate> 
<guid>http://blog.s135.com/read.php?351</guid> 
<description>
<![CDATA[ 
	　　[文章作者：张宴 本文版本：v3.1 最后修改：<span style="color: #FF0000;">2008.06.13</span> 转载请注明原文链接：<a href="http://blog.s135.com/read.php/351.htm" target="_blank">http://blog.s135.com/read.php/351.htm</a>]<br/><br/>　　前言：本文是我撰写的关于搭建“Nginx + PHP（FastCGI）”Web服务器的第3篇文章，也是Nginx 0.6系列版本成为稳定版后的第一篇文章，安装、配置方式与以往略有不同，并增加了一些在生产环境运行中不断修改、调整，总结出的配置上的优化。<br/><br/>　　链接：《<a href="read.php/297.htm" target="_blank">2007年9月的第1版</a>》、《<a href="read.php/314.htm" target="_blank">2007年12月的第2版</a>》<br/><br/>　　<a href="http://blog.s135.com/attachment/200806/nginx.png" target="_blank"><img src="http://blog.s135.com/attachment/200806/nginx.png" class="insertimage" alt="点击在新窗口中浏览此图片" title="点击在新窗口中浏览此图片" border="0"/></a><br/><br/>　　<a href="http://www.nginx.net/" target="_blank">Nginx</a> ("engine x") 是一个高性能的 HTTP 和反向代理服务器，也是一个 IMAP/POP3/SMTP 代理服务器。 Nginx 是由 Igor Sysoev 为俄罗斯访问量第二的 Rambler.ru 站点开发的，它已经在该站点运行超过两年半了。Igor 将源代码以类BSD许可证的形式发布。<br/><br/>　　Nginx 的中文维基：<a href="http://wiki.codemongers.com/NginxChs" target="_blank">http://wiki.codemongers.com/NginxChs</a><br/><br/><hr/><br/>　　在高并发连接的情况下，Nginx是Apache服务器不错的替代品。Nginx同时也可以作为7层负载均衡服务器来使用。根据我的测试结果，<strong>Nginx 0.6.31 + PHP 5.2.6 (FastCGI) 可以承受3万以上的并发连接数，相当于同等环境下Apache的10倍</strong>。<br/><br/>　　根据我的经验，4GB内存的服务器+Apache（prefork模式）一般只能处理3000个并发连接，因为它们将占用3GB以上的内存，还得为系统预留1GB的内存。我曾经就有两台Apache服务器，因为在配置文件中设置的MaxClients为4000，当Apache并发连接数达到3800时，导致服务器内存和Swap空间用满而崩溃。<br/><br/>　　而这台 Nginx 0.6.31 + PHP 5.2.6 (FastCGI) 服务器在3万并发连接下，开启的10个Nginx进程消耗150M内存（15M*10=150M），开启的64个php-cgi进程消耗1280M内存（20M*64=1280M），加上系统自身消耗的内存，总共消耗不到2GB内存。如果服务器内存较小，完全可以只开启25个php-cgi进程，这样php-cgi消耗的总内存数才500M。<br/><br/>　　在3万并发连接下，访问Nginx 0.6.31 + PHP 5.2.6 (FastCGI) 服务器的PHP程序，仍然速度飞快。下图为Nginx的状态监控页面，显示的活动连接数为28457（关于Nginx的监控页配置，会在本文接下来所给出的Nginx配置文件中写明）：<br/><br/>　　<a href="http://blog.s135.com/attachment/200712/nginx_status.png" target="_blank"><img src="http://blog.s135.com/attachment/200712/nginx_status.png" class="insertimage" alt="点击在新窗口中浏览此图片" title="点击在新窗口中浏览此图片" border="0"/></a><br/><br/>　　我生产环境下的两台Nginx + PHP5（FastCGI）服务器，跑多个一般复杂的纯PHP动态程序，单台Nginx + PHP5（FastCGI）服务器跑PHP动态程序的处理能力已经超过“<span style="color: #FF0000;">700次请求/秒</span>”，相当于每天可以承受6000万（700*60*60*24=60480000）的访问量（<a href="read.php/334.htm" target="_blank">更多信息见此</a>），而服务器的系统负载也不算高：<br/><br/>　　<a href="http://blog.s135.com/attachment/200803/nginx_php_la.gif" target="_blank"><img src="http://blog.s135.com/attachment/200803/nginx_php_la.gif" class="insertimage" alt="点击在新窗口中浏览此图片" title="点击在新窗口中浏览此图片" border="0"/></a><br/><br/><hr/><br/>　　安装步骤：<br/>　　（系统要求：Linux 2.6+ 内核，本文中的Linux操作系统为CentOS 5.1，另在RedHat AS4上也安装成功）<br/><br/>　　一、获取相关开源程序：<br/>　　1、利用CentOS Linux系统自带的yum命令安装、升级所需的程序库（RedHat等其他Linux发行版可从安装光盘中找到这些程序库的RPM包，进行安装）：<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">sudo -s<br/>LANG=C<br/>yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libpng libpng-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel</div><br/><br/>　　2、下载程序源码包：<br/>　　本文中提到的所有开源软件为截止到2008年6月5日的最新稳定版。<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">mkdir -p /data0/software<br/>cd /data0/software<br/>wget <a href="http://sysoev.ru/nginx/nginx-0.6.31.tar.gz" target="_blank">http://sysoev.ru/nginx/nginx-0.6.31.tar.gz</a><br/>wget <a href="http://www.php.net/get/php-5.2.6.tar.gz/from/this/mirror" target="_blank">http://www.php.net/get/php-5.2.6.tar.gz/from/this/mirror</a><br/>wget <a href="http://php-fpm.anight.org/downloads/head/php-5.2.6-fpm-0.5.8.diff.gz" target="_blank">http://php-fpm.anight.org/downloads/head/php-5.2.6-fpm-0.5.8.diff.gz</a><br/>wget <a href="http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.24-rc.tar.gz/from/http://mysql.ntu.edu.tw/" target="_blank">http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.24-rc.tar.gz/from/http://mysql.ntu.edu.tw/</a><br/>wget <a href="http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.12.tar.gz" target="_blank">http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.12.tar.gz</a><br/>wget "http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz?modtime=1171868460&big_mirror=0"<br/>wget "http://downloads.sourceforge.net/mcrypt/mcrypt-2.6.7.tar.gz?modtime=1194463373&big_mirror=0"<br/>wget <a href="http://pecl.php.net/get/memcache-2.2.3.tgz" target="_blank">http://pecl.php.net/get/memcache-2.2.3.tgz</a><br/>wget "http://downloads.sourceforge.net/mhash/mhash-0.9.9.tar.gz?modtime=1175740843&big_mirror=0"<br/>wget <a href="ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-7.7.tar.gz" target="_blank">ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-7.7.tar.gz</a><br/>wget <a href="http://xcache.lighttpd.net/pub/Releases/1.2.2/xcache-1.2.2.tar.gz" target="_blank">http://xcache.lighttpd.net/pub/Releases/1.2.2/xcache-1.2.2.tar.gz</a></div><br/><hr/><br/>　　二、安装PHP 5.2.6（FastCGI模式）<br/>　　1、编译安装PHP 5.2.6所需的支持库：<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">tar zxvf libiconv-1.12.tar.gz<br/>cd libiconv-1.12/<br/>./configure --prefix=/usr/local<br/>make<br/>make install<br/>cd ../<br/><br/>tar zxvf libmcrypt-2.5.8.tar.gz <br/>cd libmcrypt-2.5.8/<br/>./configure<br/>make<br/>make install<br/>/sbin/ldconfig<br/>cd libltdl/<br/>./configure --enable-ltdl-install<br/>make<br/>make install<br/>cd ../../<br/><br/>tar zxvf mhash-0.9.9.tar.gz<br/>cd mhash-0.9.9/<br/>./configure<br/>make<br/>make install<br/>cd ../<br/><br/>cp /usr/local/lib/libmcrypt.* /usr/lib <br/>ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2<br/><br/>tar zxvf mcrypt-2.6.7.tar.gz<br/>cd mcrypt-2.6.7/<br/>./configure<br/>make<br/>make install<br/>cd ../</div><br/><hr/><br/>　　2、编译安装MySQL 5.1.24-rc<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">/usr/sbin/groupadd mysql<br/>/usr/sbin/useradd -g mysql mysql<br/>tar zxvf mysql-5.1.24-rc.tar.gz<br/>cd mysql-5.1.24-rc/<br/>./configure --prefix=/usr/local/webserver/mysql/ --without-debug --with-unix-socket-path=/usr/local/webserver/mysql/mysql.sock --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static --enable-assembler --with-extra-charsets=gbk,gb2312,utf8 --with-pthread --enable-thread-safe-client<br/>make && make install<br/>chmod +w /usr/local/webserver/mysql<br/>chown -R mysql:mysql /usr/local/webserver/mysql<br/>cp support-files/my-medium.cnf /usr/local/webserver/mysql/my.cnf<br/>cd ../</div><br/><hr/><br/>　　附：以下为附加步骤，如果你想在这台服务器上运行MySQL数据库，则执行以下两步。如果你只是希望让PHP支持MySQL扩展库，能够连接其他服务器上的MySQL数据库，那么，以下两步无需执行。<br/>　　①、以mysql用户帐号的身份建立数据表：<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">/usr/local/webserver/mysql/bin/mysql_install_db --defaults-file=/usr/local/webserver/mysql/my.cnf --basedir=/usr/local/webserver/mysql --datadir=/usr/local/webserver/mysql/data --user=mysql --pid-file=/usr/local/webserver/mysql/mysql.pid --skip-locking --port=3306 --socket=/tmp/mysql.sock</div><br/><br/>　　②、启动MySQL（最后的&表示在后台运行）<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">/bin/sh /usr/local/webserver/mysql/bin/mysqld_safe --defaults-file=/usr/local/webserver/mysql/my.cnf &</div><br/><hr/><br/>　　3、编译安装PHP（FastCGI模式）<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">tar zxvf php-5.2.6.tar.gz<br/>gzip -cd php-5.2.6-fpm-0.5.8.diff.gz &#124; patch -d php-5.2.6 -p1<br/>cd php-5.2.6/<br/>./configure --prefix=/usr/local/webserver/php --with-config-file-path=/usr/local/webserver/php/etc --with-mysql=/usr/local/webserver/mysql --with-mysqli=/usr/local/webserver/mysql/bin/mysql_config --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-debug --disable-rpath --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl<br/>sed -i 's#-lz -lm -lxml2 -lz -lm -lxml2 -lz -lm -lcrypt#& -liconv#' Makefile<br/>make<br/>make install<br/>cp php.ini-dist /usr/local/webserver/php/etc/php.ini<br/>cd ../</div><br/><hr/><br/>　　4、编译安装PHP5扩展模块<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">tar zxvf memcache-2.2.3.tgz<br/>cd memcache-2.2.3/<br/>/usr/local/webserver/php/bin/phpize<br/>./configure --with-php-config=/usr/local/webserver/php/bin/php-config<br/>make<br/>make install<br/>cd ../<br/><br/>tar zxvf xcache-1.2.2.tar.gz<br/>cd xcache-1.2.2/<br/>/usr/local/webserver/php/bin/phpize<br/>./configure --with-php-config=/usr/local/webserver/php/bin/php-config --enable-xcache<br/>make<br/>make install<br/>cd ../</div><br/><br/>　　5、修改php.ini文件<br/>　　<strong>手工修改：</strong>查找/usr/local/webserver/php/etc/php.ini中的extension_dir = "./"<br/>　　修改为extension_dir = "/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/"<br/>　　并在此行后增加以下几行，然后保存：<br/>　　extension = "memcache.so"<br/><br/>　　再查找display_errors = On<br/>　　修改为display_errors = Off<br/><br/>　　<strong>自动修改：</strong>若嫌手工修改麻烦，可执行以下shell命令，自动完成对php.ini文件的修改：<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">sed -i 's#extension_dir = "./"#extension_dir = "/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/"&#92;nextension = "memcache.so"&#92;n#' /usr/local/webserver/php/etc/php.ini<br/>sed -i 's#display_errors = On#display_errors = Off#' /usr/local/webserver/php/etc/php.ini</div><br/><br/>　　6、配置XCache加速PHP：<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">vi /usr/local/webserver/php/etc/php.ini</div><br/>　　按shift+g键跳到配置文件的最末尾，加上以下配置信息：<br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content">[xcache-common]<br/>zend_extension = /usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/xcache.so<br/><br/>[xcache.admin]<br/>xcache.admin.user = "xcache"<br/>; xcache.admin.pass = md5($yourpasswd)<br/>xcache.admin.pass = "8e6867a5d05144cf4761d6481fc674a8"<br/><br/>[xcache]<br/>xcache.cacher = On<br/>xcache.shm_scheme = "mmap"<br/>xcache.size = 32M<br/>; cpu number (cat /proc/cpuinfo &#124;grep -c processor)<br/>xcache.count = 2<br/>xcache.slots = 8k<br/>xcache.ttl = 0<br/>xcache.gc_interval = 0<br/>xcache.var_size = 2M<br/>; cpu number (cat /proc/cpuinfo &#124;grep -c processor)<br/>xcache.var_count = 2<br/>xcache.var_slots = 8K<br/>xcache.var_ttl = 0<br/>xcache.var_maxttl = 0<br/>xcache.var_gc_interval = 300<br/>xcache.readonly_protection = Off<br/>xcache.mmap_path = "/dev/zero"</div></div><br/><hr/><br/>　　7、创建www用户和组，以及供blog.s135.com和<a href="http://www.s135.com" target="_blank">www.s135.com</a>两个虚拟主机使用的目录：<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">/usr/sbin/groupadd www -g 48<br/>/usr/sbin/useradd -u 48 -g www www<br/>mkdir -p /data0/htdocs/blog<br/>chmod +w /data0/htdocs/blog<br/>chown -R www:www /data0/htdocs/blog<br/>mkdir -p /data0/htdocs/www<br/>chmod +w /data0/htdocs/www<br/>chown -R www:www /data0/htdocs/www</div><br/><br/>　　8、创建php-fpm配置文件（php-fpm是为PHP打的一个FastCGI管理补丁，可以平滑变更php.ini配置而无需重启php-cgi）：<br/>　　在/usr/local/webserver/php/etc/目录中创建php-fpm.conf文件：<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">rm -f /usr/local/webserver/php/etc/php-fpm.conf<br/>vi /usr/local/webserver/php/etc/php-fpm.conf</div><br/>　　输入以下内容：[codes=xml]<?xml version="1.0" ?><br/><configuration><br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;All relative paths in this config are relative to php's install prefix<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;<section name="global_options"><br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Pid file<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<value name="pid_file">/usr/local/webserver/php/logs/php-fpm.pid</value><br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Error log file<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<value name="error_log">/usr/local/webserver/php/logs/php-fpm.log</value><br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Log level<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<value name="log_level">notice</value><br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;When this amount of php processes exited with SIGSEGV or SIGBUS ...<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<value name="emergency_restart_threshold">10</value><br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;... in a less than this interval of time, a graceful restart will be initiated.<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Useful to work around accidental curruptions in accelerator's shared memory.<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<value name="emergency_restart_interval">1m</value><br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Time limit on waiting child's reaction on signals from master<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<value name="process_control_timeout">5s</value><br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Set to 'no' to debug fpm<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<value name="daemonize">yes</value><br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;</section><br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;<workers><br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<section name="pool"><br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Name of pool. Used in logs and stats.<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<value name="name">default</value><br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Address to accept fastcgi requests on.<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Valid syntax is 'ip.ad.re.ss:port' or just 'port' or '/path/to/unix/socket'<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<value name="listen_address">127.0.0.1:9000</value><br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<value name="listen_options"><br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Set listen(2) backlog<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<value name="backlog">-1</value><br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Set permissions for unix socket, if one used.<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;In Linux read/write permissions must be set in order to allow connections from web server.<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Many BSD-derrived systems allow connections regardless of permissions.<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<value name="owner"></value><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<value name="group"></value><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<value name="mode">0666</value><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</value><br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Additional php.ini defines, specific to this pool of workers.<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<value name="php_defines"><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<value name="sendmail_path">/usr/sbin/sendmail -t -i</value><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<value name="display_errors">0</value><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</value><br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Unix user of processes<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<value name="user">www</value><br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Unix group of processes<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<value name="group">www</value><br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Process manager settings<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<value name="pm"><br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Sets style of controling worker process count.<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Valid values are 'static' and 'apache-like'<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<value name="style">static</value><br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Sets the limit on the number of simultaneous requests that will be served.<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Equivalent to Apache MaxClients directive.<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Equivalent to PHP_FCGI_CHILDREN environment in original php.fcgi<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Used with any pm_style.<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<value name="max_children">128</value><br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Settings group for 'apache-like' pm style<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<value name="apache_like"><br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Sets the number of server processes created on startup.<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Used only when 'apache-like' pm_style is selected<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<value name="StartServers">20</value><br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Sets the desired minimum number of idle server processes.<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Used only when 'apache-like' pm_style is selected<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<value name="MinSpareServers">5</value><br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Sets the desired maximum number of idle server processes.<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Used only when 'apache-like' pm_style is selected<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<value name="MaxSpareServers">250</value><br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</value><br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</value><br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Time limit on waiting execution of single request<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Should be used when 'max_execution_time' ini option does not terminate execution for some reason<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<value name="request_execution_timeout">31s</value><br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Set open file desc rlimit<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<value name="rlimit_files">51200</value><br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Set max core size rlimit<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<value name="rlimit_core">0</value><br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Chroot to this directory at the start<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<value name="chroot"></value><br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Chdir to this directory at the start<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<value name="chdir"></value><br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Redirect workers' stdout and stderr into main error log.<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;If not set, they will be redirected to /dev/null, according to FastCGI specs<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<value name="catch_workers_output">yes</value><br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;How much requests each process should execute before respawn.<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Useful to work around memory leaks in 3rd party libraries.<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;For endless request processing please specify 0<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Equivalent to PHP_FCGI_MAX_REQUESTS<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<value name="max_requests">51200</value><br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Comma separated list of ipv4 addresses of FastCGI clients that allowed to connect.<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Equivalent to FCGI_WEB_SERVER_ADDRS environment in original php.fcgi (5.2.2+)<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Makes sense only with AF_INET listening socket.<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<value name="allowed_clients">127.0.0.1</value><br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Pass environment variables like LD_LIBRARY_PATH<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;All $VARIABLEs are taken from current environment<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<value name="environment"><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<value name="HOSTNAME">$HOSTNAME</value><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<value name="PATH">/usr/local/bin:/usr/bin:/bin</value><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<value name="TMP">/tmp</value><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<value name="TMPDIR">/tmp</value><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<value name="TEMP">/tmp</value><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<value name="OSTYPE">$OSTYPE</value><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<value name="MACHTYPE">$MACHTYPE</value><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<value name="MALLOC_CHECK_">2</value><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</value><br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</section><br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;</workers><br/><br/></configuration>[/codes]　　9、启动php-cgi进程，监听127.0.0.1的9000端口，进程数为128（如果服务器内存小于3GB，可以只开启25个进程），用户为www：<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">ulimit -SHn 51200<br/>/usr/local/webserver/php/sbin/php-fpm start</div><br/>　　注：/usr/local/webserver/php/sbin/php-fpm还有其他参数，包括：start&#124;stop&#124;quit&#124;restart&#124;reload&#124;logrotate，修改php.ini后不重启php-cgi，重新加载配置文件使用reload。<br/><br/><hr/><br/>　　三、安装Nginx 0.6.31<br/>　　1、安装Nginx所需的pcre库：<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">tar zxvf pcre-7.7.tar.gz<br/>cd pcre-7.7/<br/>./configure<br/>make && make install<br/>cd ../</div><br/><br/>　　2、安装Nginx<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">tar zxvf nginx-0.6.31.tar.gz<br/>cd nginx-0.6.31/<br/>./configure --user=www --group=www --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module<br/>make && make install<br/>cd ../</div><br/><br/>　　3、创建Nginx日志目录<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">mkdir -p /data1/logs<br/>chmod +w /data1/logs<br/>chown -R www:www /data1/logs</div><br/><br/>　　4、创建Nginx配置文件<br/>　　①、在/usr/local/webserver/nginx/conf/目录中创建nginx.conf文件：<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">rm -f /usr/local/webserver/nginx/conf/nginx.conf<br/>vi /usr/local/webserver/nginx/conf/nginx.conf</div><br/>　　输入以下内容：<br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content">user &nbsp;www www;<br/><br/>worker_processes 8;<br/><br/>error_log &nbsp;/data1/logs/nginx_error.log &nbsp;crit;<br/><br/>pid &nbsp; &nbsp; &nbsp; &nbsp;/usr/local/webserver/nginx/nginx.pid;<br/><br/>#Specifies the value for maximum file descriptors that can be opened by this process. <br/>worker_rlimit_nofile 51200;<br/><br/>events <br/>{<br/> &nbsp; &nbsp; &nbsp;use epoll;<br/><br/> &nbsp; &nbsp; &nbsp;worker_connections 51200;<br/>}<br/><br/>http <br/>{<br/> &nbsp; &nbsp; &nbsp;include &nbsp; &nbsp; &nbsp; mime.types;<br/> &nbsp; &nbsp; &nbsp;default_type &nbsp;application/octet-stream;<br/><br/> &nbsp; &nbsp; &nbsp;charset &nbsp;utf-8;<br/> &nbsp; &nbsp; &nbsp;<br/> &nbsp; &nbsp; &nbsp;server_names_hash_bucket_size 128;<br/> &nbsp; &nbsp; &nbsp;<br/> &nbsp; &nbsp; &nbsp;sendfile on;<br/> &nbsp; &nbsp; &nbsp;tcp_nopush &nbsp; &nbsp; on;<br/><br/> &nbsp; &nbsp; &nbsp;keepalive_timeout 60;<br/><br/> &nbsp; &nbsp; &nbsp;tcp_nodelay on;<br/><br/> &nbsp; &nbsp; &nbsp;fastcgi_connect_timeout 60;<br/> &nbsp; &nbsp; &nbsp;fastcgi_send_timeout 180;<br/> &nbsp; &nbsp; &nbsp;fastcgi_read_timeout 180;<br/> &nbsp; &nbsp; &nbsp;fastcgi_buffer_size 128k;<br/> &nbsp; &nbsp; &nbsp;fastcgi_buffers 4 128k;<br/> &nbsp; &nbsp; &nbsp;fastcgi_busy_buffers_size 128k;<br/> &nbsp; &nbsp; &nbsp;fastcgi_temp_file_write_size 128k;<br/> &nbsp; &nbsp; &nbsp;fastcgi_temp_path /dev/shm;<br/><br/> &nbsp; &nbsp; &nbsp;gzip on;<br/> &nbsp; &nbsp; &nbsp;gzip_min_length &nbsp;1k;<br/> &nbsp; &nbsp; &nbsp;gzip_buffers &nbsp; &nbsp; 4 8k;<br/> &nbsp; &nbsp; &nbsp;gzip_http_version 1.1; <br/> &nbsp; &nbsp; &nbsp;gzip_types &nbsp; &nbsp; &nbsp; text/plain application/x-javascript text/css text/html application/xml;<br/><br/> &nbsp; &nbsp; &nbsp;server<br/> &nbsp; &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;listen &nbsp; &nbsp; &nbsp; 80;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;server_name &nbsp;blog.s135.com;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;index index.html index.htm index.php;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;root &nbsp;/data0/htdocs/blog;<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (-d $request_filename)<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rewrite ^/(.*)([^/])$ <a href="http://$host/$1$2/" target="_blank">http://$host/$1$2/</a> permanent;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;location ~ .*&#92;.php?$<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; include fcgi.conf; &nbsp; &nbsp; &nbsp;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #fastcgi_pass &nbsp;unix:/tmp/php-cgi.sock;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fastcgi_pass &nbsp;127.0.0.1:9000;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fastcgi_index index.php;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;log_format &nbsp;access &nbsp;'$remote_addr - $remote_user [$time_local] "$request" '<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'$status $body_bytes_sent "$http_referer" '<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'"$http_user_agent" $http_x_forwarded_for';<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;access_log &nbsp;/data1/logs/access.log &nbsp;access;<br/> &nbsp; &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp; &nbsp;server<br/> &nbsp; &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;listen &nbsp; &nbsp; &nbsp; 80;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;server_name &nbsp;<a href="http://www.s135.com;" target="_blank">www.s135.com;</a><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;index index.html index.htm index.php;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;root &nbsp;/data0/htdocs/www;<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (-d $request_filename)<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rewrite ^/(.*)([^/])$ <a href="http://$host/$1$2/" target="_blank">http://$host/$1$2/</a> permanent;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;location ~ .*&#92;.php?$<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; include fcgi.conf;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #fastcgi_pass &nbsp;unix:/tmp/php-cgi.sock;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fastcgi_pass &nbsp;127.0.0.1:9000;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fastcgi_index index.php;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;log_format &nbsp;wwwlogs &nbsp;'$remote_addr - $remote_user [$time_local] "$request" '<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'$status $body_bytes_sent "$http_referer" '<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'"$http_user_agent" $http_x_forwarded_for';<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;access_log &nbsp;/data1/logs/wwwlogs.log &nbsp;wwwlogs;<br/> &nbsp; &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp; &nbsp;server<br/> &nbsp; &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;listen &nbsp;80;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;server_name &nbsp;status.blog.s135.com;<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;location / {<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stub_status on;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; access_log &nbsp; off;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp;}<br/>}</div></div><br/><br/>　　②、在/usr/local/webserver/nginx/conf/目录中创建fcgi.conf文件：<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">vi /usr/local/webserver/nginx/conf/fcgi.conf</div><br/>　　输入以下内容：<br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content">fastcgi_param &nbsp;GATEWAY_INTERFACE &nbsp;CGI/1.1;<br/>fastcgi_param &nbsp;SERVER_SOFTWARE &nbsp; &nbsp;nginx;<br/><br/>fastcgi_param &nbsp;QUERY_STRING &nbsp; &nbsp; &nbsp; $query_string;<br/>fastcgi_param &nbsp;REQUEST_METHOD &nbsp; &nbsp; $request_method;<br/>fastcgi_param &nbsp;CONTENT_TYPE &nbsp; &nbsp; &nbsp; $content_type;<br/>fastcgi_param &nbsp;CONTENT_LENGTH &nbsp; &nbsp; $content_length;<br/><br/>fastcgi_param &nbsp;SCRIPT_FILENAME &nbsp; &nbsp;$document_root$fastcgi_script_name;<br/>fastcgi_param &nbsp;SCRIPT_NAME &nbsp; &nbsp; &nbsp; &nbsp;$fastcgi_script_name;<br/>fastcgi_param &nbsp;REQUEST_URI &nbsp; &nbsp; &nbsp; &nbsp;$request_uri;<br/>fastcgi_param &nbsp;DOCUMENT_URI &nbsp; &nbsp; &nbsp; $document_uri;<br/>fastcgi_param &nbsp;DOCUMENT_ROOT &nbsp; &nbsp; &nbsp;$document_root;<br/>fastcgi_param &nbsp;SERVER_PROTOCOL &nbsp; &nbsp;$server_protocol;<br/><br/>fastcgi_param &nbsp;REMOTE_ADDR &nbsp; &nbsp; &nbsp; &nbsp;$remote_addr;<br/>fastcgi_param &nbsp;REMOTE_PORT &nbsp; &nbsp; &nbsp; &nbsp;$remote_port;<br/>fastcgi_param &nbsp;SERVER_ADDR &nbsp; &nbsp; &nbsp; &nbsp;$server_addr;<br/>fastcgi_param &nbsp;SERVER_PORT &nbsp; &nbsp; &nbsp; &nbsp;$server_port;<br/>fastcgi_param &nbsp;SERVER_NAME &nbsp; &nbsp; &nbsp; &nbsp;$server_name;<br/><br/># PHP only, required if PHP was built with --enable-force-cgi-redirect<br/>#fastcgi_param &nbsp;REDIRECT_STATUS &nbsp; &nbsp;200;</div></div><br/><br/>　　5、启动Nginx<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">ulimit -SHn 51200<br/>/usr/local/webserver/nginx/sbin/nginx</div><br/><hr/><br/>　　四、配置开机自动启动Nginx + PHP<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">vi /etc/rc.local</div><br/>　　在末尾增加以下内容：<br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content">ulimit -SHn 51200<br/>/usr/local/webserver/php/sbin/php-fpm start<br/>/usr/local/webserver/nginx/sbin/nginx</div></div><br/><hr/><br/>　　五、优化Linux内核参数<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">vi /etc/sysctl.conf</div><br/>　　在末尾增加以下内容：<br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content">net.ipv4.tcp_fin_timeout = 30<br/>net.ipv4.tcp_keepalive_time = 300<br/>net.ipv4.tcp_syncookies = 1<br/>net.ipv4.tcp_tw_reuse = 1<br/>net.ipv4.tcp_tw_recycle = 1<br/>net.ipv4.ip_local_port_range = 5000 &nbsp; &nbsp;65000</div></div><br/><br/>　　使配置立即生效：<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">/sbin/sysctl -p</div><br/><hr/><br/>　　六、在不停止Nginx服务的情况下平滑变更Nginx配置<br/>　　(1)、修改/usr/local/webserver/nginx/conf/nginx.conf配置文件后，请执行以下命令检查配置文件是否正确：<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">/usr/local/webserver/nginx/sbin/nginx -t</div><br/>　　如果屏幕显示以下两行信息，说明配置文件正确：<br/>　　<span style="color: #008000;">the configuration file /usr/local/webserver/nginx/conf/nginx.conf syntax is ok<br/>　　the configuration file /usr/local/webserver/nginx/conf/nginx.conf was tested successfully</span><br/><br/>　　(2)、这时，输入以下命令查看Nginx主进程号：<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">ps -ef &#124; grep "nginx: master process" &#124; grep -v "grep" &#124; awk -F ' ' '{print $2}'</div><br/>　　屏幕显示的即为Nginx主进程号，例如：<br/>　　<span style="color: #008000;">6302</span><br/>　　这时，执行以下命令即可使修改过的Nginx配置文件生效：<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">kill -HUP 6302</div><br/>　　或者无需这么麻烦，找到Nginx的Pid文件：<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">kill -HUP `cat /usr/local/webserver/nginx/nginx.pid`</div><br/><hr/><br/>　　本文若有小的修改，会第一时间在以下网址发布：<br/>　　<a href="http://blog.s135.com/read.php/351.htm" target="_blank">http://blog.s135.com/read.php/351.htm</a><br/><br/>　　（全文完）<br/>Tags - <a href="tag.php?tag=linux" rel="tag">linux</a> , <a href="tag.php?tag=php" rel="tag">php</a> , <a href="tag.php?tag=mysql" rel="tag">mysql</a> , <a href="tag.php?tag=nginx" rel="tag">nginx</a> , <a href="tag.php?tag=apache" rel="tag">apache</a> , <a href="tag.php?tag=centos" rel="tag">centos</a> , <a href="tag.php?tag=epoll" rel="tag">epoll</a> , <a href="tag.php?tag=fastcgi" rel="tag">fastcgi</a> , <a href="tag.php?tag=xcache" rel="tag">xcache</a> , <a href="tag.php?tag=httpd" rel="tag">httpd</a>
]]>
</description>
</item><item>
<link>http://blog.s135.com/read.php?350</link>
<title><![CDATA[北京太阳村的爱心之旅]]></title> 
<author>张宴 &lt;net@s135.com&gt;</author>
<category><![CDATA[生活琐事]]></category>
<pubDate>Tue, 03 Jun 2008 15:52:21 +0000</pubDate> 
<guid>http://blog.s135.com/read.php?350</guid> 
<description>
<![CDATA[ 
	　　上个星期天（2008年6月1日），国际儿童节。我和老婆以及朋友，去北京顺义区赵全营镇板桥的<a href="http://www.sunvillage.com.cn/" target="_blank">太阳村</a>，看望了那里的孩子，为他们送去食物和衣物，并认领了<a href="http://cn.sunvillage.com.cn/chi/article_main.php?sec=1" target="_blank">爱心枣树</a>，贡献上自己的一份爱心。这个儿童节，你们不会孤单！<br/><br/>　　公交乘车路线：在“东直门外大街（东直门地铁站B出口以东）”乘<a href="http://map.sogou.com/map.html#s=m==bus!!appid==1421!!start==东直门!!end==牛栏山道口!!tactic==8!!mode==NORMAL&city=%u5317%u4EAC&c=12972375,4849250,10" target="_blank">916空调车（慢车）</a>至“牛栏山道口”下车，<a href="http://map.sogou.com/map.html#s=m==bus!!appid==1421!!start==牛栏山道口!!end==板桥!!tactic==8!!mode==NORMAL&city=%u5317%u4EAC&c=12977500.000000096,4868718.75,12" target="_blank">换乘947</a>在“板桥”站下车，往回走100米到十字路口（途中看到一个写有太阳村的门不是正门，走不通，请继续往回直到十字路口），沿着南北方向马路向北走50米。<br/><br/>　　<strong>太阳村背景：</strong><br/><br/>　　童年本来应该是快乐的，但并不是每个孩子都能拥有快乐的童年。太阳村里就住着这样一群特殊的孩子，他们的父母有的在服刑，有的已经伏法。由于父母犯罪，这些孩子得不到像烈士子女那样的尊重和照顾，也得不到一般孤儿的救助，成为社会上一个特殊的群体。这些孩子曾遭受过身边人百般的歧视和污辱，有的流浪街头，以行乞、偷窃为生；有的挣扎在生死边缘，无依无靠。<br/><br/>　　原陕西省监狱管理局一级警督张淑琴女士，在长期的监狱采访与犯罪人员接触过程中，让她发现并开始思索一个问题：假如是英雄或烈士留下的孩子，人们会把敬佩和感激之情转移到英烈子女身上；但对于罪犯的孩子有些人则会把痛恨及厌恶延伸到这些孩子身上，使他们沦为一个不幸的特殊群体。而这些孩子如果得不到妥善安置的话，很大程度上又会影响到父母在狱中的表现。为了让罪犯能安心服刑。张淑琴决定帮助那些因父母入狱而无人照看的孩子。<br/><br/>　　从1996年5月起，张淑琴在社会各界的大力支持下，自筹资金，相继在陕西省、河南省新乡市、北京市顺义区、陕西省陇县创建了4所专门救助服刑人员未成年子女的儿童村。在过去的十年中，太阳村救助了近800名特殊的孩子。<br/><br/>　　<strong>6.1拍下的照片：</strong><br/><br/>　　太阳村正门<br/>　　<a href="http://blog.s135.com/attachment/200806/sun01.jpg" target="_blank"><img src="http://blog.s135.com/attachment/200806/sun01.jpg" class="insertimage" alt="点击在新窗口中浏览此图片" title="点击在新窗口中浏览此图片" border="0"/></a><br/><br/>　　爱心小屋<br/>　　<a href="http://blog.s135.com/attachment/200806/sun02.jpg" target="_blank"><img src="http://blog.s135.com/attachment/200806/sun02.jpg" class="insertimage" alt="点击在新窗口中浏览此图片" title="点击在新窗口中浏览此图片" border="0"/></a><br/><br/>　　游乐园<br/>　　<a href="http://blog.s135.com/attachment/200806/sun03.jpg" target="_blank"><img src="http://blog.s135.com/attachment/200806/sun03.jpg" class="insertimage" alt="点击在新窗口中浏览此图片" title="点击在新窗口中浏览此图片" border="0"/></a><br/><br/>　　孩子们的创作之一：“每个人都有屁屁”<br/>　　<a href="http://blog.s135.com/attachment/200806/sun04.jpg" target="_blank"><img src="http://blog.s135.com/attachment/200806/sun04.jpg" class="insertimage" alt="点击在新窗口中浏览此图片" title="点击在新窗口中浏览此图片" border="0"/></a><br/><br/>　　孩子们的创作之二<br/>　　<a href="http://blog.s135.com/attachment/200806/sun05.jpg" target="_blank"><img src="http://blog.s135.com/attachment/200806/sun05.jpg" class="insertimage" alt="点击在新窗口中浏览此图片" title="点击在新窗口中浏览此图片" border="0"/></a><br/><br/>　　这个小宝宝，才两岁，孩子的母亲因贩毒入狱<br/>　　<a href="http://blog.s135.com/attachment/200806/sun06.jpg" target="_blank"><img src="http://blog.s135.com/attachment/200806/sun06.jpg" class="insertimage" alt="点击在新窗口中浏览此图片" title="点击在新窗口中浏览此图片" border="0"/></a><br/><br/>　　英语学习室<br/>　　<a href="http://blog.s135.com/attachment/200806/sun07.jpg" target="_blank"><img src="http://blog.s135.com/attachment/200806/sun07.jpg" class="insertimage" alt="点击在新窗口中浏览此图片" title="点击在新窗口中浏览此图片" border="0"/></a><br/><br/>　　为了一切孩子<br/>　　<a href="http://blog.s135.com/attachment/200806/sun08.jpg" target="_blank"><img src="http://blog.s135.com/attachment/200806/sun08.jpg" class="insertimage" alt="点击在新窗口中浏览此图片" title="点击在新窗口中浏览此图片" border="0"/></a><br/><br/>　　与孩子们的互动<br/>　　<a href="http://blog.s135.com/attachment/200806/sun09.jpg" target="_blank"><img src="http://blog.s135.com/attachment/200806/sun09.jpg" class="insertimage" alt="点击在新窗口中浏览此图片" title="点击在新窗口中浏览此图片" border="0"/></a><br/><br/>
]]>
</description>
</item><item>
<link>http://blog.s135.com/read.php?349</link>
<title><![CDATA[使用Google的开源TCMalloc库，提高MySQL在高并发情况下的性能[原创]]]></title> 
<author>张宴 &lt;net@s135.com&gt;</author>
<category><![CDATA[纯粹技术]]></category>
<pubDate>Sat, 31 May 2008 01:53:06 +0000</pubDate> 
<guid>http://blog.s135.com/read.php?349</guid> 
<description>
<![CDATA[ 
	　　[文章作者：张宴 本文版本：v1.1 最后修改：2008.06.02 转载请注明出自：<a href="http://blog.s135.com" target="_blank">http://blog.s135.com</a>]<br/><br/>　　TCMalloc（Thread-Caching Malloc）是google开发的开源工具──“<a href="http://code.google.com/p/google-perftools/" target="_blank">google-perftools</a>”中的成员。与标准的glibc库的malloc相比，TCMalloc在内存的分配上效率和速度要高得多，可以在很大程度上提高MySQL服务器在高并发情况下的性能，降低系统负载。<br/><br/>　　TCMalloc的实现原理和测试报告请见一篇文章：《<a href="http://shiningray.cn/tcmalloc-thread-caching-malloc.html" target="_blank">TCMalloc：线程缓存的Malloc</a>》<br/><br/>　　<strong>为MySQL添加TCMalloc库的安装步骤（Linux环境）：</strong><br/><br/>　　1、64位操作系统请先安装libunwind库，32位操作系统不要安装。libunwind库为基于64位CPU和操作系统的程序提供了基本的堆栈辗转开解功能，其中包括用于输出堆栈跟踪的API、用于以编程方式辗转开解堆栈的API以及支持C++异常处理机制的API。<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">wget <a href="http://download.savannah.gnu.org/releases/libunwind/libunwind-0.99-alpha.tar.gz" target="_blank">http://download.savannah.gnu.org/releases/libunwind/libunwind-0.99-alpha.tar.gz</a><br/>tar zxvf libunwind-0.99-alpha.tar.gz<br/>cd libunwind-0.99-alpha/<br/>CFLAGS=-fPIC ./configure<br/>make CFLAGS=-fPIC<br/>make CFLAGS=-fPIC install</div><br/><br/>　　2、安装google-perftools：<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">wget <a href="http://google-perftools.googlecode.com/files/google-perftools-0.97.tar.gz" target="_blank">http://google-perftools.googlecode.com/files/google-perftools-0.97.tar.gz</a><br/>tar zxvf google-perftools-0.97.tar.gz<br/>cd google-perftools-0.97/<br/>./configure<br/>make && make install<br/><br/>echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf<br/>/sbin/ldconfig</div><br/><br/>　　3、修改MySQL启动脚本（根据你的MySQL安装位置而定）：<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">vi /usr/local/mysql/bin/mysqld_safe</div><br/>　　在# executing mysqld_safe的下一行，加上：<div class="quote"><div class="quote-title">引用</div><div class="quote-content">export LD_PRELOAD=/usr/local/lib/libtcmalloc.so</div></div><br/>　　保存后退出，然后重启MySQL服务器。<br/><br/><br/>　　4、使用lsof命令查看tcmalloc是否起效：<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">/usr/sbin/lsof -n &#124; grep tcmalloc</div><br/>　　如果发现以下信息，说明tcmalloc已经起效：<br/>　　<span style="color: #008000;">mysqld &nbsp; &nbsp;10847 &nbsp; mysql &nbsp;mem &nbsp; &nbsp; &nbsp; REG &nbsp; &nbsp; &nbsp; &nbsp;8,5 &nbsp;1203756 &nbsp; 20484960 /usr/local/lib/libtcmalloc.so.0.0.0 &nbsp; </span><br/><br/><hr/><br/>　　注：2008年6月2日，修正了libunwind在x86_64位操作系统下的编译错误，TCMalloc无法加载等问题。<br/><br/>　　涉及修改内容：<br/>　　1、libunwind的编译参数改为：<br/>　　CFLAGS=-fPIC ./configure<br/>　　make CFLAGS=-fPIC<br/>　　make CFLAGS=-fPIC install<br/><br/>　　2、增加：<br/>　　echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf<br/>　　/sbin/ldconfig<br/><br/>　　3、修改MySQL加载TCMalloc的语句：<br/>　　export LD_PRELOAD=/usr/local/lib/libtcmalloc.so<br/><br/>　　感谢网友router。<br/><br/><br/>Tags - <a href="tag.php?tag=linux" rel="tag">linux</a> , <a href="tag.php?tag=mysql" rel="tag">mysql</a> , <a href="tag.php?tag=google" rel="tag">google</a> , <a href="tag.php?tag=tcmalloc" rel="tag">tcmalloc</a>
]]>
</description>
</item><item>
<link>http://blog.s135.com/read.php?348</link>
<title><![CDATA[利用NetScaler和自行编写的健康检查脚本，完美解决多台MySQL Slave数据库的负载均衡[原创]]]></title> 
<author>张宴 &lt;net@s135.com&gt;</author>
<category><![CDATA[纯粹技术]]></category>
<pubDate>Thu, 29 May 2008 15:21:04 +0000</pubDate> 
<guid>http://blog.s135.com/read.php?348</guid> 
<description>
<![CDATA[ 
	　　[文章作者：张宴 本文版本：v1.0 最后修改：2008.05.29 转载请注明出自：<a href="http://blog.s135.com" target="_blank">http://blog.s135.com</a>]<br/><br/>　　Citrix NetScaler是一款不错的4-7层硬件负载均衡交换机，市场占有率仅次于F5 BIG-IP，位居第二。NetScaler 8.0是<a href="http://www.citrix.com.cn/" target="_blank">美国思杰系统有限公司</a>（Citrix Systems, Inc）正式推出的最新版本NetScaler产品系列。<br/><br/>　　从我的实际测试来看，NetScaler 8.0在七层负载均衡方面，性能和功能都要比F5 BIG-IP强。<br/><br/>　　NetScaler 8.0的负载均衡监控中，可以对MySQL数据库进行健康检查，而F5 BIG-IP目前只支持对Oracle和Microsoft SQL Server数据库的健康检查。<br/><br/>　　<a href="http://blog.s135.com/attachment/200805/nsmysql-slave.png" target="_blank"><img src="http://blog.s135.com/attachment/200805/nsmysql-slave.png" class="insertimage" alt="点击在新窗口中浏览此图片" title="点击在新窗口中浏览此图片" border="0"/></a><br/><br/>　　但是，NetScaler 8.0自带的MySQL健康检查脚本（nsmysql.pl）并不完善，它只能检查一条SQL语句执行是否出错，并不能检查MySQL主从结构中的MySQL Slave数据库同步是否正常、表有无损坏、同步延迟是否过大、是否出现错误、非sleeping状态的连程数是否过高等情况。于是，我根据自己的需要，为NetScaler 8.0写了一个MySQL Slave数据库负载均衡健康检查脚本（nsmysql-slave.pl），实现了上述需求。<br/><br/>　　有了“nsmysql-slave.pl”做健康检查，利用NetScaler的VIP（虚拟IP），就可以完美实现多台MySQL Slave数据库的负载均衡了。当一台MySQL Slave数据库出现不同步、表损坏、同步延迟过大（本脚本中默认设置的落后MySQL主库180秒视为延迟，可根据具体应用修改）、连程数太高（本脚本中默认设置的是大于100视为连程数太高，可根据具体应用修改）等情况，“nsmysql-slave.pl”就会自动将其检查出来，并告知NetScaler，NetScaler会将该数据库标识为宕机，从而不将用户的查询请求传送到这台发生故障的数据库上。故障一旦修复，“nsmysql-slave.pl”会自动告知NetScaler，该数据库已经可以使用。<br/><br/>　　“nsmysql-slave.pl”源代码如下：　　[codes=ruby]#!/usr/bin/perl -w<br/>################################################################<br/>##<br/>## MySQL Slave Server Monitoring Script for NetScaler 8.x<br/>## Written by Zhang Yan (blog.s135.com) on May 28, 2008<br/>##<br/>################################################################<br/>## This is a netscaler supplied script. <br/><br/>## This script is used to do MySQL slave server monitoring<br/>## using KAS feature.<br/>## The mandatory arguments are:<br/>## &nbsp; &nbsp; &nbsp;1. Database to which the user is going to connect<br/>## &nbsp; &nbsp; &nbsp;2. User name<br/>## The optional arguments are:<br/>## &nbsp; &nbsp; &nbsp;1. password: &nbsp;This is the password that will be used to<br/>## &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;login into the server. If no password is<br/>## &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;given a blank password is used.<br/>## &nbsp; &nbsp; &nbsp;2. SQL query<br/>## Example:<br/>## &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;set monitor ... &nbsp;-scriptArgs "database=test;user=user1;password=password;<br/>## &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;query=show slave status"<br/><br/><br/>use strict;<br/>use DBI;<br/>use Netscaler::KAS;<br/><br/>## This function is a handler for performing MYSQL probe in KAS mode<br/>sub mysql_probe<br/>{<br/> &nbsp; &nbsp; &nbsp; &nbsp;## There must be at least 3 arguments to this function.<br/> &nbsp; &nbsp; &nbsp; &nbsp;## &nbsp; &nbsp; &nbsp;1. First argument is the IP that has to be probed.<br/> &nbsp; &nbsp; &nbsp; &nbsp;## &nbsp; &nbsp; &nbsp;2. Second argument is the port to connect to.<br/> &nbsp; &nbsp; &nbsp; &nbsp;## &nbsp; &nbsp; &nbsp;3. Arguments to be used during probing.<br/> &nbsp; &nbsp; &nbsp; &nbsp;if(scalar(@_) < 3)<br/> &nbsp; &nbsp; &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return (1,"Arguments not given");<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;## Parse the argument given, to get database,user name,password,SQL query.<br/> &nbsp; &nbsp; &nbsp; &nbsp;## If parsing fails, it is monitoring probe failure.<br/> &nbsp; &nbsp; &nbsp; &nbsp;$_[2]=~/database=([^;]+);user=([^;]+)(;password=([^;]+))?(;query=([^;]+))?/ <br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;or return (1,"Invalid argument format");<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;(my $database,my $username,my $password,my $sql_query)=($1,$2,$4,$6);<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;## If no password is given, try blank password<br/> &nbsp; &nbsp; &nbsp; &nbsp;if(!defined($password))<br/> &nbsp; &nbsp; &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$password="";<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;## Try to connect to the server<br/> &nbsp; &nbsp; &nbsp; &nbsp;my $db_handle = DBI->connect("dbi:mysql:database=$database:host=$_[0]:$_[1]",$username,$password)<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;or return (1,"Connection to database failed - $!");<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;## Check MySQL Slave Server<br/> &nbsp; &nbsp; &nbsp; &nbsp;my $slave_info = $db_handle->prepare("show slave status");<br/> &nbsp; &nbsp; &nbsp; &nbsp;$slave_info->execute()<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;or return (1,"Execution of SQL query failed");<br/> &nbsp; &nbsp; &nbsp; &nbsp;my $slave_ref = $slave_info->fetchrow_hashref()<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;or return (1,"Fetchrow of SQL query failed");<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;my $threads_info = $db_handle->prepare("show global status like 'Threads_connected'");<br/> &nbsp; &nbsp; &nbsp; &nbsp;$threads_info->execute()<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;or return (1,"Execution of SQL query failed");<br/> &nbsp; &nbsp; &nbsp; &nbsp;my $threads_ref = $threads_info->fetchrow_hashref()<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;or return (1,"Fetchrow of SQL query failed");<br/><br/> &nbsp; &nbsp; &nbsp; &nbsp;if (exists $slave_ref->{Slave_SQL_Running} and $slave_ref->{Slave_SQL_Running} eq 'No')<br/> &nbsp; &nbsp; &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return (1,"Slave IO thread has stopped");<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;elsif (exists $slave_ref->{Slave_IO_Running} and $slave_ref->{Slave_IO_Running} eq 'No')<br/> &nbsp; &nbsp; &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return (1,"Slave IO thread has stopped");<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;elsif (exists $slave_ref->{Last_Error} and $slave_ref->{Last_Error} ne '')<br/> &nbsp; &nbsp; &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return (1,"Has some error information");<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;elsif (exists $slave_ref->{Seconds_Behind_Master} and $slave_ref->{Seconds_Behind_Master} > 180)<br/> &nbsp; &nbsp; &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return (1,"The seconds behind master more than 180");<br/> &nbsp; &nbsp; &nbsp; &nbsp;} &nbsp; &nbsp;<br/> &nbsp; &nbsp; &nbsp; &nbsp;elsif (exists $threads_ref->{Value} and $threads_ref->{Value} > 100)<br/> &nbsp; &nbsp; &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return (1,"The number of threads that are not sleeping more than 100");<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;else<br/> &nbsp; &nbsp; &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nb