tar -zxvf rrd-1.1.0.tgz cd rrd-1.1.0 /usr/local/php/bin/phpize ln -s /usr/local/rrdtool/lib/librrd.so.4 /lib64/librrd.so.4 #不知是否我的人品问题,如果不做软连接,则会提示: #error: rrd lib version seems older than 1.3.0, update to 1.3.0+ #configure会直接退出,检查config.log才发现conftest找不到librrd.so.4,故做软链接 ./configure --with-php-config=/usr/local/php/bin/php-config make cp modules/rrd.so /usr/lib
[root@localhost rrd-1.1.0]# /usr/local/php/bin/php -i | grep rrd rrd rrd tool module => enabled rrd tool module version => 1.1.0 rrdtool library version => 1.4.7 #看到这行则成功 RRDCACHED_ADDRESS => unix:/dev/shm/rrdcached.sock PWD => /root/rrd-1.1.0 _SERVER["RRDCACHED_ADDRESS"] => unix:/dev/shm/rrdcached.sock _SERVER["PWD"] => /root/rrd-1.1.0
/usr/local/rrdtool/bin/rrdcached -l unix:/dev/shm/rrdcached.sock -s web -F -w 3600 -z 3600 -f 86400 chown web.web /dev/shm/rrdcached.sock
echo 'export RRDCACHED_ADDRESS="unix:/dev/shm/rrdcached.sock"' >> /etc/profile
putenv("RRDCACHED_ADDRESS=unix:/dev/shm/rrdcached.sock");
顺便给出一小段测试代码,初学者随手写的……大牛们勿喷……
<?php #phpinfo(); putenv("RRDCACHED_ADDRESS=unix:/dev/shm/rrdcached.sock"); $opts_cpu = array( "--step", "1", "--start",time()-10, "DS:ds0:GAUGE:2:0:90000000000", "RRA:MAX:0.5:1:600" ); $fname = "/home/web/rrd/Liv.rrd"; $ret = rrd_create($fname, $opts_cpu); if($ret == 0) { $err = rrd_error(); error_log(time()."|Liv|-1|create|".$err); } else{ for($i = 0; $i < 10; $i++) { mt_srand((double)microtime()*1000000*getmypid()); $rrdtime = time(); $data = mt_rand(); echo $data."\r\n"; sleep(2); $uret = rrd_update($fname, array("$rrdtime:$data")); if($uret == 0) { $err = rrd_error(); error_log(time()."|Liv|-1|update|".$err); } } }
[root@localhost ~]# nc -U /dev/shm/rrdcached.sock stats 9 Statistics follow QueueLength: 0 UpdatesReceived: 18794128 FlushesReceived: 1 UpdatesWritten: 963771 DataSetsWritten: 17810163 TreeNodesNumber: 98816 TreeDepth: 20 JournalBytes: 0 JournalRotate: 0
PS : 有兴趣的可以google一下这篇论文:Application Buffer-Cache Management for Performance:Running the World’s Largest MRTG