<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title>百里挑一</title> 
<link>http://www.admin99.net/index.php</link> 
<description>linux命令 &#124; seo优化技术 &#124; linux系统管理员指南 --我的学习园地</description> 
<language>zh-cn</language> 
<copyright>Powered by Bo-blog 2.0.2 sp2</copyright>
<item>
<link>http://www.admin99.net/read.php?482</link>
<title>为php安装imagick</title> 
<author>real &lt;real@admin99.net&gt;</author>
<category>php</category>
<pubDate>Thu, 08 Jul 2010 08:47:01 +0000</pubDate> 
<guid>http://www.admin99.net/read.php?482</guid> 
<description>
<![CDATA[ 
	首先必须安装imagemagick<br/>cd /usr/src<br/>wget ftp://ftp.imagemagick.org/pub/ImageMagick/ImageMagick.tar.gz<br/>tar xzf ImageMagick.tar.gz<br/>cd ImageMagick-6.6.3-0/<br/>./configure<br/>make<br/>make install<br/><br/>然后安装imagick<br/>cd /usr/src<br/>wget http://pecl.php.net/get/imagick<br/>tar xzf imagick-3.0.0RC1.tgz<br/>cd imagick-3.0.0RC1<br/>./configure --with-php-config=/usr/local/php/bin/php-config<br/>make<br/>make install<br/>然后修改php.ini，添加extension=imagick.so<br/>Tags - <a href="http://www.admin99.net/tag.php?tag=php" rel="tag">php</a>
  ]]> 
</description>
</item><item>
<link>http://www.admin99.net/read.php?480</link>
<title>php使用geoip方法三</title> 
<author>real &lt;real@admin99.net&gt;</author>
<category>php</category>
<pubDate>Thu, 17 Jun 2010 17:58:09 +0000</pubDate> 
<guid>http://www.admin99.net/read.php?480</guid> 
<description>
<![CDATA[ 
	适用于centos<br/>yum install GeoIP.i386 GeoIP-data.i386 GeoIP-devel.i386<br/><br/>cd /usr/src<br/>wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz<br/>gzip -d GeoLiteCity.dat.gz<br/>mv GeoLiteCity.dat /var/lib/GeoIP/GeoIPCity.dat<br/><br/>cd /usr/src<br/>wget http://pecl.php.net/get/geoip-1.0.7.tgz<br/>tar xvf geoip-1.0.7.tgz<br/>cd geoip-1.0.7<br/>/usr/local/php5/bin/phpize<br/>./configure --with-php-config=/usr/local/php5/bin/php-config --with-geoip<br/>make<br/>make install<br/><br/>php的geoip编译完成以后，会在php的extensions目录下生成一个geoip.so，现在需要在php.ini中加载这个so。可以在php.ini的末尾加上如下一行：<br/>extension=geoip.so<br/><br/>然后就可以使用了<br/><br/>当前没有测试成功，估计还不能支持php5.3.2 ，就版本的没测试。仅做备用<br/>Tags - <a href="http://www.admin99.net/tag.php?tag=php" rel="tag">php</a>
  ]]> 
</description>
</item><item>
<link>http://www.admin99.net/read.php?479</link>
<title>php使用geoip方法二</title> 
<author>real &lt;real@admin99.net&gt;</author>
<category>php</category>
<pubDate>Thu, 17 Jun 2010 17:54:45 +0000</pubDate> 
<guid>http://www.admin99.net/read.php?479</guid> 
<description>
<![CDATA[ 
	安装php的时候要开启pear<br/>比如编译的时候加上--with-pear<br/>装好php之后<br/>用 /usr/local/php/bin/pear install Net_GeoIP 来安装<br/>如果提示说版本更新之类的<br/>比如 <br/>就按提示的从新地点下载<br/>安装好之后。<br/>下载ip数据资源<br/>http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz，并解压<br/>把解压得来的GeoIP.dat放到网站根目录下或者其它能被正确引用到的目录<br/>Net_GeoIP类文件在 /usr/local/php/lib/php/Net/下<br/>写一个文件测试一下<br/><br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content"><?php<br/>// include class<br/>include("Net/GeoIP.php");<br/><br/>// initialize object<br/>// open database<br/>$geo = Net_GeoIP::getInstance("GeoIP.dat");<br/><br/>// look up IP address<br/>$country = $geo->lookupCountryName("216.239.115.148");<br/>echo "IP mapped to: " . $country;<br/><br/>// close database<br/>$geo->close();<br/><br/>// acknowledgement, required by MaxMind<br/>echo "This product includes GeoLite data created by MaxMind, available from http://www.maxmind.com/."<br/>?></div></div><br/>Tags - <a href="http://www.admin99.net/tag.php?tag=php" rel="tag">php</a>
  ]]> 
</description>
</item><item>
<link>http://www.admin99.net/read.php?478</link>
<title>php 配置使用 geoip 方法一</title> 
<author>real &lt;real@admin99.net&gt;</author>
<category>php</category>
<pubDate>Thu, 17 Jun 2010 17:18:36 +0000</pubDate> 
<guid>http://www.admin99.net/read.php?478</guid> 
<description>
<![CDATA[ 
	到这里下载几个资源<br/>http://geolite.maxmind.com/download/geoip/<br/>1.比如我们用php来使用geoip，那么首先要下载一个php的api<br/>http://geolite.maxmind.com/download/geoip/api/php/geoip.inc<br/>这个是最基础的，里面还有更多的资源，比如geoipcity.inc<br/>2.然后去下载ip数据<br/>http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz<br/>下载下来后解压得到GeoIP.dat<br/>这个也是最基础的，如果要用更详细的就看看这个目录里其它的，比如有http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz这个是到具体城市的<br/>3.将第一步的geoip.ini和第二部解压得到的GeoIP.dat 放到同一个目录<br/>然后编辑一个简单的测试文件，将其中的1.1.1.1改成随便一个ip<br/><br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content"><?php<br/><br/>// include functions<br/>include("geoip.inc");<br/><br/>// read GeoIP database<br/>$handle = geoip_open("GeoIP.dat", GEOIP_STANDARD);<br/><br/>// map IP to country<br/>echo "IP address 1.1.1.1 located in " . geoip_country_name_by_addr($handle, "1.1.1.1") . " (country code " . geoip_country_code_by_addr($handle, "1.1.1.1") . ")";<br/><br/>// close database handler<br/>geoip_close($handle);<br/><br/>// print compulsory license notice<br/>echo "<p> -- This product includes GeoIP data created by MaxMind, available from http://maxmind.com/ --";<br/><br/>?></div></div><br/>然后在浏览器中访问。<br/>Tags - <a href="http://www.admin99.net/tag.php?tag=php" rel="tag">php</a>
  ]]> 
</description>
</item><item>
<link>http://www.admin99.net/read.php?466</link>
<title>安装magickwand</title> 
<author>real &lt;real@admin99.net&gt;</author>
<category>php</category>
<pubDate>Mon, 01 Mar 2010 08:52:45 +0000</pubDate> 
<guid>http://www.admin99.net/read.php?466</guid> 
<description>
<![CDATA[ 
	如果服务器上没安装imagemagick，需要先安装<br/><br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content"><br/>cd /usr/src<br/>wget http://image_magick.veidrodis.com/image_magick/ImageMagick-6.5.9-0.tar.gz<br/>tar xzf ImageMagick-6.5.9-0.tar.gz <br/>cd ImageMagick-6.5.9-0<br/>./configure -enable-shared -enable-lzw -without-perl -with-modules<br/>make<br/>make install</div></div><br/>安装magickwand<br/><br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content"><br/>cd /usr/src<br/>wget http://www.magickwand.org/download/php/MagickWandForPHP-1.0.7.tar.gz<br/>tar xzf MagickWandForPHP-1.0.7.tar.gz <br/>cd MagickWandForPHP-1.0.7<br/>/usr/local/php-fpm/bin/phpize <br/>./configure -with-php-config=/usr/local/php/bin/php-config -enable-shared -with-magickwand=/usr/local<br/>make<br/>make install<br/></div></div><br/>编辑php.ini<br/>vi /usr/local/php/lib/php.ini<br/>添加<br/>extension="magickwand.so"<br/>Tags - <a href="http://www.admin99.net/tag.php?tag=php" rel="tag">php</a>
  ]]> 
</description>
</item><item>
<link>http://www.admin99.net/read.php?431</link>
<title>php的memcache模块的优化</title> 
<author>real &lt;real@admin99.net&gt;</author>
<category>php</category>
<pubDate>Sat, 02 May 2009 08:58:33 +0000</pubDate> 
<guid>http://www.admin99.net/read.php?431</guid> 
<description>
<![CDATA[ 
	参数不多<br/><br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content">memcache.allow_failover = 1 <br/>memcache.max_failover_attempts=20 <br/>memcache.chunk_size =8192 <br/>memcache.default_port = 11211 </div></div><br/>其中比较重要的是 <br/>memcache.chunk_size<br/> &nbsp; &nbsp;一个整型值，用于控制数据传输的大小。默认值为 8192 字节 (8 KB)，但是如果设置为 32768 (32 KB)，则可以获得更好的性能。<br/>memcache.allow_failover<br/> &nbsp; &nbsp;一个布尔值，用于控制当连接出错时 Memcache 扩展是否故障转移到其他服务器上。默认值为 1 (true)。<br/>memcache.max_failover_attempts<br/> &nbsp; &nbsp;一个整型值，用于限制连接到持久性数据或检索数据的服务器数目。如果 memcache.allow_failover 为 false，则将忽略此参数。默认值为 20。<br/>memcache.default_port<br/> &nbsp; &nbsp;另一个整型值，用于设置连接到 Memcache 所使用的 TCP 端口。除非您修改它，否则默认值为无特权的高端口 11211。 <br/><br/> &nbsp; &nbsp;对于访问量非常大的服务器，最好是通过socket来连接memcached，这样能减少打开和关闭tcp/ip链接的开销。<br/> &nbsp; &nbsp;如果memcached和php在两台不同的服务器上，通过udp来连接应该比tcp连接能消耗小一些，并且能获得更好的速度(尚未测试)<br/> &nbsp; &nbsp;在memcached中启用压缩，对于通过tcp/ip 或者udp连接的memcache，能减少传输数据的大小，也能相应的降低一些负载<br/>Tags - <a href="http://www.admin99.net/tag.php?tag=php" rel="tag">php</a> , <a href="http://www.admin99.net/tag.php?tag=cache" rel="tag">cache</a>
  ]]> 
</description>
</item><item>
<link>http://www.admin99.net/read.php?396</link>
<title>关于php-cgi 的 SIGSEGV 错误的一些想法</title> 
<author>real &lt;real@admin99.net&gt;</author>
<category>php</category>
<pubDate>Tue, 11 Nov 2008 07:31:19 +0000</pubDate> 
<guid>http://www.admin99.net/read.php?396</guid> 
<description>
<![CDATA[ 
	几台使用了 nginx+php-fpm 的机器上，偶尔能看到php-fpm.log中有这样的内容<br/><br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content">Oct 28 23:13:53.849419 [NOTICE] fpm_got_signal(), line 73: received SIGCHLD<br/>Oct 28 23:13:53.849490 [WARNING] fpm_children_bury(), line 229: child 15044 (pool default) exited on signal 11 SIGSEGV after 1.332818 seconds<br/>Oct 28 23:13:53.850341 [NOTICE] fpm_children_make(), line 305: child 15122 (pool default) started</div></div><br/>如果得到SIGSEGV信号的进程比较多的话，还能看到如下的日志<br/><br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content">Oct 28 09:03:15.812009 [WARNING] fpm_children_bury(), line 256: failed processes threshold (10 in 60 sec) is reached, initiating reload<br/>Oct 28 09:03:15.812030 [NOTICE] fpm_pctl(), line 208: switching to 'reloading' state</div></div><br/>然后php-fpm就会重启。其中的<br/>failed processes threshold (10 in 60 sec) is reached<br/>是在php-fpm.conf中设置的，表示在60秒内出现SIGSEGV或者SIGBUS错误的php-cgi进程数如果超过10个，php-fpm就会重启。可以通过把php-fpm.conf中的 emergency_restart_threshold的值设置的大一些来增加这个重启的阀值，比如增加到60个，在有些时候，这能够避免php-fpm重启，但这并不是解决问题的根本办法<br/><br/>SIGSEGV信号一般表示<br/><br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content">SIGSEGV --- Segment Fault. The possible cases of your encountering this error are: <br/>1.buffer overflow --- usually caused by a pointer reference out of range. <br/>2.stack overflow --- please keep in mind that the default stack size is 8192K. <br/>3.illegal file access --- file operations are forbidden on our judge system</div></div><br/>其中的第三条，跟本问题的关系比较大。也就是php-cgi访问了一个不存在的或者没有权限访问的文件<br/>我用的php-fpm补丁是0.5.8版的，按照一些说法，只要设置了<br/><br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content">fastcgi_param &nbsp;SCRIPT_NAME &nbsp; &nbsp; &nbsp; &nbsp;$fastcgi_script_name;</div></div><br/>之后，php-cgi如果找不到文件或者没有权限访问的话 会提示No input file specified. 或者Access denied.<br/>问题到这里似乎又陷入了僵局<br/>后来又在php.ini中找到了php-cgi的一个参数 cgi.fix_pathinfo<br/><br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content">cgi.fix_pathinfo &nbsp;boolean<br/>对 CGI 提供了真正的 PATH_INFO/PATH_TRANSLATED 支持。以前 PHP 的行为是将 PATH_TRANSLATED 设为 SCRIPT_FILENAME，而不管 PATH_INFO 是什么。有关 PATH_INFO 的更多信息见 cgi 规格。将此值设为 1 将使 PHP CGI 修正其路径以遵守规格。设为 0 将使 PHP 的行为和从前一样。默认为零。用户应该修正其脚本使用 SCRIPT_FILENAME 而不是 PATH_TRANSLATED。</div></div><br/>把这个参数的值设置为1 ，cgi会多做一些检查，来判断请求的路径中，那部分是文件名，哪部分是路径名<br/>下面是google groups上的一段话<br/><br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content">when cgi.fix_pathinfo was set to "1" it caused a lot of checks in order to find which part of SCRIPT_FILENAME is a file name and which is PATH_INFO. In case of missing file it caused NULL<br/>in path_translated, which caused the crash.</div></div><br/>此问题已经耗费了我太多的精力，已经不愿意多花时间去查问题了。比如，可以使用gbd来查看php-cgi 出错以后产生的dump文件。但这个问题只是偶尔发生，很难捕捉到。如果有兄弟也遇到这个问题，或者你有更好的解决办法，不妨大家交流一下<br/>修改此参数后，观察了一段时间，SIGSEGV错误在一些服务器上确实消失了。<br/>补充一下 11月10日早上6点半左右到9点26分，三台服务器(给校内网做的app)同时出现了大量的SIGSEGV错误，校内的服务器出的故障，在我这几台服务器上产生了大量的不正确的 post / ，后来问校内的工程师，他们只说服务down掉了，却不肯略微详细的说一下情况。后来我模拟这些post，确没出问题？？奇怪了<br/>Tags - <a href="http://www.admin99.net/tag.php?tag=php" rel="tag">php</a>
  ]]> 
</description>
</item><item>
<link>http://www.admin99.net/read.php?388</link>
<title>php大量session存储到内存中、散列及过期回收</title> 
<author>real &lt;real@admin99.net&gt;</author>
<category>php</category>
<pubDate>Sun, 19 Oct 2008 13:07:18 +0000</pubDate> 
<guid>http://www.admin99.net/read.php?388</guid> 
<description>
<![CDATA[ 
	一台服务器流量比较大，因为程序的需要，session的过期时间设置的是3小时，导致/tmp下堆积了近20万的session文件。进而导致内核占用的cpu急剧上升。因为session的读写涉及到大量小文件的随机读写，并且是集中在一个目录下，iowait也急剧升高。<br/><br/>首先考虑将session放入内存中，最简单的办法莫过于将/tmp挂载为 tmpfs文件系统，也就是内存中<br/>具体见 <a href="http://www.admin99.net/read.php/379.htm" target="_blank">使用内存作linux下的临时文件夹</a><br/><br/>第二步，将session存储到不通的目录中<br/>php本身支持session的多级散列<br/>在php.ini中，将 ;session.save_path = /tmp 改为<br/><br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content">session.save_path = "2;/tmp/session"</div></div><br/>表示将session存储到 /tmp/session这个文件夹中，并且是用2及散列。<br/>保存退出，等第三步结束后重启php<br/><br/>第三步，创建session存储文件夹<br/>php并不会自动去创建这些文件夹，不过在源文件中提供了一些创建文件夹的脚本。下面这个脚本也好用<br/><br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content">I="0 1 2 3 4 5 6 7 8 9 a b c d e f"<br/>for acm in $I;<br/>do<br/>for x in $I;<br/>do<br/>mkdir -p /tmp/session/$acm/$x;<br/>done;<br/>done<br/>chown -R nobody:nobody /tmp/session<br/>chmod -R 1777 /tmp/session</div></div><br/>因为/tmp是用的内存，服务器重启后，里面的所有文件都会丢失，所以，需要把上面的脚本加入到 /etc/rc.local中，并且要放在启动php之前<br/><br/>第四步，session的回收<br/>session在经过session.gc_maxlifetime后会过期，但并不会马上被删除，时间长了以后会造成/tmp空间占用很大。具体的删除算法懒得去研究。下面这个命令可以删除过期的session，我这里定义的过期时间是3小时<br/><br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content">find /tmp/session &nbsp;-amin +180 -exec rm -rf {} &#92;;</div></div><br/>放入cron中，10分钟执行一次，完事。<br/>Tags - <a href="http://www.admin99.net/tag.php?tag=cache" rel="tag">cache</a> , <a href="http://www.admin99.net/tag.php?tag=php" rel="tag">php</a> , <a href="http://www.admin99.net/tag.php?tag=shell" rel="tag">shell</a>
  ]]> 
</description>
</item><item>
<link>http://www.admin99.net/read.php?387</link>
<title>杀掉内存溢出的php-cgi进程的脚本</title> 
<author>real &lt;real@admin99.net&gt;</author>
<category>php</category>
<pubDate>Sun, 19 Oct 2008 08:15:29 +0000</pubDate> 
<guid>http://www.admin99.net/read.php?387</guid> 
<description>
<![CDATA[ 
	网站上的bug，某个页面访问的时候，会造成内存溢出，正常情况下一个php-cgi进程占用大概0.2% 约8M左右的内存，出问题的时候，某些php-cgi进程可能会占用掉几百兆。<br/>因为一时无法找出那个页面出得错误，只好用脚本来kill掉异常的进程<br/>只要一个php-cgi进程占用的内存超过 %1 就把它kill掉<br/><br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content">#!/bin/sh<br/><br/>PIDS=`ps aux&#124;grep php-cgi&#124;grep -v grep&#124;awk '{if($4>=1)print $2}'`<br/><br/>for PID in $PIDS<br/>do<br/>echo `date +%F....%T` >> /usr/bash/phpkill.log<br/>echo $PID >> /usr/bash/phpkill.log<br/>kill -9 &nbsp;$PID<br/>done</div></div><br/>放到cron里每分钟执行一次<br/>Tags - <a href="http://www.admin99.net/tag.php?tag=shell" rel="tag">shell</a> , <a href="http://www.admin99.net/tag.php?tag=php" rel="tag">php</a>
  ]]> 
</description>
</item><item>
<link>http://www.admin99.net/read.php?372</link>
<title>php-fpm的一个异常状态</title> 
<author>real &lt;real@admin99.net&gt;</author>
<category>php</category>
<pubDate>Tue, 30 Sep 2008 18:27:21 +0000</pubDate> 
<guid>http://www.admin99.net/read.php?372</guid> 
<description>
<![CDATA[ 
	一台服务器上运行着nginx php(fpm) xcache，访问量日均 300W pv左右<br/>最近经常会出现这样的情况： php页面打开很慢，cpu使用率突然降至很低，系统负载突然升至很高，查看网卡的流量，也会发现突然降到了很低。这种情况只持续数秒钟就恢复了<br/>检查php-fpm的日志文件发现了一些线索<br/>Sep 30 08:32:23.289973 [NOTICE] fpm_unix_init_main(), line 271: getrlimit(nofile): max:51200, cur:51200<br/>Sep 30 08:32:23.290212 [NOTICE] fpm_sockets_init_main(), line 371: using inherited socket fd=10, "127.0.0.1:9000"<br/>Sep 30 08:32:23.290342 [NOTICE] fpm_event_init_main(), line 109: libevent: using epoll<br/>Sep 30 08:32:23.296426 [NOTICE] fpm_init(), line 47: fpm is running, pid 30587<br/>在这几句的前面，是1000多行的关闭children和开启children的日志<br/>原来，php-fpm有一个参数 max_requests ，该参数指明了，每个children最多处理多少个请求后便会被关闭，默认的设置是500。因为php是把请求轮询给每个children，在大流量下，每个childre到达max_requests所用的时间都差不多，这样就造成所有的children基本上在同一时间被关闭。<br/>在这期间，nginx无法将php文件转交给php-fpm处理，所以cpu会降至很低(不用处理php，更不用执行sql)，而负载会升至很高(关闭和开启children、nginx等待php-fpm)，网卡流量也降至很低(nginx无法生成数据传输给客户端)<br/><br/>解决问题很简单，增加children的数量，并且将 max_requests 设置未 0 或者一个比较大的值，重启php-fpm<br/>Tags - <a href="http://www.admin99.net/tag.php?tag=fpm" rel="tag">fpm</a> , <a href="http://www.admin99.net/tag.php?tag=php" rel="tag">php</a>
  ]]> 
</description>
</item>
</channel>
</rss>