Skip to content


wordpress open_basedir restriction in effect问题

nginx-0.8.46
php-5.2.14
mysql-5.1.37
eaccelerator-0.9.6.1
wordpress 为官方3.0英文版

安装后在页面出现错误信息

  1. Warning: require() [function.require]: open_basedir restriction in effect. File() is not within the allowed path(s): (/opt/htdocs:/opt/lampp/htdocs:/opt/php/lib/php:/tmp/session:/tmp/upload) in /opt/lampp/htdocs/wordpress/wp-settings.php on line 132

php.ini 中的配置也没错

  1. open_basedir = "/opt/htdocs:/opt/lampp/htdocs:/opt/php/lib/php:/tmp/session:/tmp/upload"

关闭open_basedir或去掉[eaccelerator]之后不会报错,安全起见open_basedir一定要开,eaccelerator换成0.9.5.3后没问题了。

  1. tar jxvf eaccelerator-0.9.5.3.tar.bz2
  2. cd eaccelerator-0.9.5.3/
  3. /opt/php/bin/phpize
  4. ./configure  --enable-eaccelerator=shared --with-php-config=/opt/php/bin/php-config
  5. make
  6. make install

参考:
http://linux.chinaunix.net/bbs/redirect.php?tid=1162653&goto=lastpost

收藏与分享

Posted in PHP, 技术.

Tagged with , , .


Linux下硬盘检测工具smartmontools(smartctl)使用方法

安装:
yum install smartmontools

help:
#smartctl --help
smartctl version 5.38 [i686-redhat-linux-gnu] Copyright (C) 2002-8 Bruce Allen
Home page is http://smartmontools.sourceforge.net/

Usage: smartctl [options] device

============================================ SHOW INFORMATION OPTIONS =====

-h, --help, --usage
Display this help and exit

-V, --version, --copyright, --license
Print license, copyright, and version information and exit

-i, --info
Show identity information for device

-a, --all
Show all SMART information for device

================================== SMARTCTL RUN-TIME BEHAVIOR OPTIONS =====

-q TYPE, --quietmode=TYPE (ATA)
Set smartctl quiet mode to one of: errorsonly, silent, noserial

-d TYPE, --device=TYPE
Specify device type to one of: ata, scsi, marvell, sat, 3ware,N

-T TYPE, --tolerance=TYPE (ATA)
Tolerance: normal, conservative, permissive, verypermissive

-b TYPE, --badsum=TYPE (ATA)
Set action on bad checksum to one of: warn, exit, ignore

-r TYPE, --report=TYPE
Report transactions (see man page)

-n MODE, --nocheck=MODE (ATA)
No check if: never, sleep, standby, idle (see man page)

============================== DEVICE FEATURE ENABLE/DISABLE COMMANDS =====

-s VALUE, --smart=VALUE
Enable/disable SMART on device (on/off)

-o VALUE, --offlineauto=VALUE (ATA)
Enable/disable automatic offline testing on device (on/off)

-S VALUE, --saveauto=VALUE (ATA)
Enable/disable Attribute autosave on device (on/off)

======================================= READ AND DISPLAY DATA OPTIONS =====

-H, --health
Show device SMART health status

-c, --capabilities (ATA)
Show device SMART capabilities

-A, --attributes
Show device SMART vendor-specific Attributes and values

-l TYPE, --log=TYPE
Show device log. TYPE: error, selftest, selective, directory,
background, scttemp[sts,hist]

-v N,OPTION , --vendorattribute=N,OPTION (ATA)
Set display OPTION for vendor Attribute N (see man page)

-F TYPE, --firmwarebug=TYPE (ATA)
Use firmware bug workaround: none, samsung, samsung2,
samsung3, swapid

-P TYPE, --presets=TYPE (ATA)
Drive-specific presets: use, ignore, show, showall

============================================ DEVICE SELF-TEST OPTIONS =====

-t TEST, --test=TEST
Run test. TEST: offline short long conveyance select,M-N
pending,N afterselect,[on|off] scttempint,N[,p]

-C, --captive
Do test in captive mode (along with -t)

-X, --abort
Abort any non-captive test on device

=================================================== SMARTCTL EXAMPLES =====

smartctl --all /dev/hda (Prints all SMART information)

smartctl --smart=on --offlineauto=on --saveauto=on /dev/hda
(Enables SMART on first disk)

smartctl --test=long /dev/hda (Executes extended disk self-test)

smartctl --attributes --log=selftest --quietmode=errorsonly /dev/hda
(Prints Self-Test & Attribute errors)
smartctl --all --device=3ware,2 /dev/sda
smartctl --all --device=3ware,2 /dev/twe0
smartctl --all --device=3ware,2 /dev/twa0
(Prints all SMART info for 3rd ATA disk on 3ware RAID controller)
smartctl --all --device=hpt,1/1/3 /dev/sda
(Prints all SMART info for the SATA disk attached to the 3rd PMPort
of the 1st channel on the 1st HighPoint RAID controller)

简单用法:
1、smartctl -a 检查该设备是否已经打开SMART技术。
2、smartctl -s on 如果没有打开SMART技术,使用该命令打开SMART技术。
3、smartctl -t short 后台检测硬盘,消耗时间短;
smartctl -t long 后台检测硬盘,消耗时间长;
smartctl -C -t short 前台检测硬盘,消耗时间短;
smartctl -C -t long 前台检测硬盘,消耗时间长。其实就是利用硬盘SMART的自检程序。
4、smartctl -X 中断后台检测硬盘。
5、smartctl -l selftest 显示硬盘检测日志。
6、smartctl -l error 显示硬盘错误汇总。

收藏与分享

Posted in Linux 命令, 技术.

Tagged with , .


Connection closed by remote server

#ssh -p 6022 c1g@192.168.0.18

  1. Connection closed by 192.168.0.18

再ping一下,也没问题
#ping 192.168.0.18

  1. PING 192.168.0.18 (192.168.0.18) 56(84) bytes of data.
  2. 64 bytes from 192.168.0.18: icmp_seq=1 ttl=64 time=1.09 ms
  3. 64 bytes from 192.168.0.18: icmp_seq=2 ttl=64 time=0.215 ms
  4. 64 bytes from 192.168.0.18: icmp_seq=3 ttl=64 time=0.138 ms
  5.  
  6. --- 192.168.0.18 ping statistics ---
  7. 3 packets transmitted, 3 received, 0% packet loss, time 1999ms
  8. rtt min/avg/max/mdev = 0.138/0.481/1.090/0.431 ms

看了下web也可以访问,再看一下ssh的详细信息
#ssh -vv -p 6022 192.168.0.18

  1. OpenSSH_4.3p2, OpenSSL 0.9.8e-fips-rhel5 01 Jul 2008
  2. debug1: Reading configuration data /etc/ssh/ssh_config
  3. debug1: Applying options for *
  4. debug2: ssh_connect: needpriv 0
  5. debug1: Connecting to 192.168.0.18 [192.168.0.18] port 6022.
  6. debug1: Connection established.
  7. debug1: identity file /home/c1g/.ssh/identity type -1
  8. debug1: identity file /home/c1g/.ssh/id_rsa type -1
  9. debug1: identity file /home/c1g/.ssh/id_dsa type -1
  10. debug1: loaded 3 keys
  11. debug1: Remote protocol version 2.0, remote software version OpenSSH_4.3
  12. debug1: match: OpenSSH_4.3 pat OpenSSH*
  13. debug1: Enabling compatibility mode for protocol 2.0
  14. debug1: Local version string SSH-2.0-OpenSSH_4.3
  15. debug2: fd 3 setting O_NONBLOCK
  16. debug1: SSH2_MSG_KEXINIT sent
  17. debug1: SSH2_MSG_KEXINIT received
  18. debug2: kex_parse_kexinit: diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
  19. debug2: kex_parse_kexinit: ssh-rsa,ssh-dss
  20. debug2: kex_parse_kexinit: aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour128,arcfour256,arcfour,aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se,aes128-ctr,aes192-ctr,aes256-ctr
  21. debug2: kex_parse_kexinit: aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour128,arcfour256,arcfour,aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se,aes128-ctr,aes192-ctr,aes256-ctr
  22. debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
  23. debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
  24. debug2: kex_parse_kexinit: none,zlib@openssh.com,zlib
  25. debug2: kex_parse_kexinit: none,zlib@openssh.com,zlib
  26. debug2: kex_parse_kexinit:
  27. debug2: kex_parse_kexinit:
  28. debug2: kex_parse_kexinit: first_kex_follows 0
  29. debug2: kex_parse_kexinit: reserved 0
  30. debug2: kex_parse_kexinit: diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
  31. debug2: kex_parse_kexinit: ssh-rsa,ssh-dss
  32. debug2: kex_parse_kexinit: aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour128,arcfour256,arcfour,aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se,aes128-ctr,aes192-ctr,aes256-ctr
  33. debug2: kex_parse_kexinit: aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour128,arcfour256,arcfour,aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se,aes128-ctr,aes192-ctr,aes256-ctr
  34. debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
  35. debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
  36. debug2: kex_parse_kexinit: none,zlib@openssh.com
  37. debug2: kex_parse_kexinit: none,zlib@openssh.com
  38. debug2: kex_parse_kexinit:
  39. debug2: kex_parse_kexinit:
  40. debug2: kex_parse_kexinit: first_kex_follows 0
  41. debug2: kex_parse_kexinit: reserved 0
  42. debug2: mac_init: found hmac-md5
  43. debug1: kex: server->client aes128-cbc hmac-md5 none
  44. debug2: mac_init: found hmac-md5
  45. debug1: kex: client->server aes128-cbc hmac-md5 none
  46. debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
  47. debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
  48. debug2: dh_gen_key: priv key bits set: 136/256
  49. debug2: bits set: 532/1024
  50. debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
  51. debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
  52. debug1: Host '192.168.0.18' is known and matches the RSA host key.
  53. debug1: Found key in /home/c1g/.ssh/known_hosts:4
  54. debug2: bits set: 513/1024
  55. debug1: ssh_rsa_verify: signature correct
  56. debug2: kex_derive_keys
  57. debug2: set_newkeys: mode 1
  58. debug1: SSH2_MSG_NEWKEYS sent
  59. debug1: expecting SSH2_MSG_NEWKEYS
  60. debug2: set_newkeys: mode 0
  61. debug1: SSH2_MSG_NEWKEYS received
  62. debug1: SSH2_MSG_SERVICE_REQUEST sent
  63. debug2: service_accept: ssh-userauth
  64. debug1: SSH2_MSG_SERVICE_ACCEPT received
  65. debug2: key: /home/c1g/.ssh/identity ((nil))
  66. debug2: key: /home/c1g/.ssh/id_rsa ((nil))
  67. debug2: key: /home/c1g/.ssh/id_dsa ((nil))
  68. debug1: Authentications that can continue: publickey,gssapi-with-mic,password
  69. debug1: Next authentication method: gssapi-with-mic
  70. debug1: Unspecified GSS failure.  Minor code may provide more information
  71. Unknown code krb5 195
  72.  
  73. debug1: Unspecified GSS failure.  Minor code may provide more information
  74. Unknown code krb5 195
  75.  
  76. debug1: Unspecified GSS failure.  Minor code may provide more information
  77. Unknown code krb5 195
  78.  
  79. debug2: we did not send a packet, disable method
  80. debug1: Next authentication method: publickey
  81. debug1: Trying private key: /home/c1g/.ssh/identity
  82. debug1: Trying private key: /home/c1g/.ssh/id_rsa
  83. debug1: Trying private key: /home/c1g/.ssh/id_dsa
  84. debug2: we did not send a packet, disable method
  85. debug1: Next authentication method: password
  86. c1g@192.168.0.18's password:
  87. debug2: we sent a password packet, wait for reply
  88. Connection closed by 192.168.0.18

在输入密码后就断掉了,把机器重启下后,可以登录了。

查看/var/log/messages 和 /var/log/cron
发现从凌晨3点起就没有记录了,估计是磁盘出错变成不可写适成不能登录。

收藏与分享

Posted in LINUX, 技术.

Tagged with .


RRDtool 1.4.4 安装

RRDtool介绍

rrdtool-3dlogo
RRDTool是由Tobias Oetiker开发的自由软件,它使用RRD(Round Robin Database)作为存储格式,Round robin是一种处理定量数据、以及当前元素指针的技术。RRDTool主要用来跟踪对象的变化情况,生成这些变化的走势图。

stream-pop

07/09/10释放的cacti-0.8.7g已支持rrdtool-1.4X
我选择05-Jul-2010 最新释放的rrdtool-1.4.4.tar.gz
系统为centos 5.2,已安装yum

安装支持包
yum install libxml2-devel libpng-devel pkg-config glib pixman pango pango-devel freetype freetype-devel fontconfig cairo cairo-devel libart_lgpl libart_lgpl-devel

安装rrdtool

  1. wget http://oss.oetiker.ch/rrdtool/pub/rrdtool-1.4.4.tar.gz
  2. tar zxvf rrdtool-1.4.4.tar.gz
  3. cd rrdtool-1.4.4
  4. ./configure --prefix=/usr/local/rrdtool-1.4.4 --disable-tcl --disable-python
  1. ordering CD from http://tobi.oetiker.ch/wish .... just kidding ;-)
  2.  
  3. ----------------------------------------------------------------
  4. Config is DONE!
  5.  
  6.           With MMAP IO: yes
  7.       Build rrd_getopt: no
  8.        Static programs: no
  9.           Perl Modules: perl_piped perl_shared
  10.            Perl Binary: /usr/bin/perl
  11.           Perl Version: 5.8.8
  12.           Perl Options: PREFIX=/usr/local/rrdtool-1.4.4 LIB=/usr/local/rrdtool-1.4.4/lib/perl/5.8.8
  13.           Ruby Modules:
  14.            Ruby Binary: no
  15.           Ruby Options: sitedir=/usr/local/rrdtool-1.4.4/lib/ruby
  16.     Build Lua Bindings: no
  17.     Build Tcl Bindings: no
  18.  Build Python Bindings: no
  19.           Build rrdcgi: yes
  20.        Build librrd MT: yes
  21.            Use gettext: yes
  22.            With libDBI: no
  23.  
  24.              Libraries: -lxml2 -lcairo -lcairo -lcairo -lm  -lcairo -lpng12   -lglib-2.0   -lpangocairo-1.0 -lpango-1.0 -lcairo -lgobject-2.0 -lgmodule-2.0 -ldl -lglib-2.0 
  25.  
  26. Type 'make' to compile the software and use 'make install' to
  27. install everything to: /usr/local/rrdtool-1.4.4.

出现下面信息可能缺少支持包

  1. configure: error: Please fix the library issues listed above and try again.
  1. make
  2. make install
  3.  
  4. ln -s /usr/local/rrdtool-1.4.4 /usr/local/rrdtool
  5. /usr/local/rrdtool/bin/rrdtool -v
  1. RRDtool 1.4.4  Copyright 1997-2010 by Tobias Oetiker <tobi@oetiker.ch>
  2.                Compiled Jul 22 2010 11:18:48
  3.  
  4. Usage: rrdtool [options] command command_options
  5. Valid commands: create, update, updatev, graph, graphv,  dump, restore,
  6.                 last, lastupdate, first, info, fetch, tune,
  7.                 resize, xport, flushcached
  8.  
  9. RRDtool is distributed under the Terms of the GNU General
  10. Public License Version 2. (www.gnu.org/copyleft/gpl.html)
  11.  
  12. For more information read the RRD manpages

参考:
rrdtool 1.3.7安装
http://blog.c1gstudio.com/archives/459

收藏与分享

Posted in RRDtool.

Tagged with .


cacti 监控远程主机

环境介绍
安装cacti的监控机A,ip为 192.168.0.16
安装snmp的被监控机B,ip为 192.168.0.17
系统为centos 4/5

被监控B机安装snmp
net-snmp 安装参考

修改B机snmp配置,充许外部访问
自带的snmp配置文件在/etc/snmp/snmpd.conf;
编译安装的snmp配置文件在/usr/local/etc/snmp/snmpd.conf;
vi /etc/snmp/snmpd.conf

  1. com2sec local     localhost       privatepass #安装教程中配置的本机访问要权限
  2. com2sec mynetwork     192.168.0.16       privatepass #新增的外部访问权限,192.168.0.16为监控机ip,privatepass 为安全码可以和local不同
  3.  
  4. group MyROGroup v1 local
  5. group MyROGroup v2c local
  6. group MyROGroupnet v1         mynetwork #新增
  7. group MyROGroupnet v2c        mynetwork #新增
  8.  
  9.  
  10. view mib2   included  .iso.org.dod.internet.mgmt.mib-2 fc
  11. view all    included  .1                               80 #新增
  12.  
  13.  
  14. access MyROGroup "" any noauth exact mib2 none none
  15. access MyROGroupnet ""      any       noauth    exact  all    none   none #新增
  16.  
  17.  
  18. #以下为访问项目,如果想监控磁盘空间,load等需把注释去掉
  19. #编译安装默认已去掉,自带安装的需手动把注释去掉
  20.  
  21. #  Make sure mountd is running
  22. proc mountd #去掉前面的"#"
  23.  
  24. #  Make sure there are no more than 4 ntalkds running, but 0 is ok too.
  25. proc ntalkd 4
  26.  
  27. #  Make sure at least one sendmail, but less than or equal to 10 are running.
  28. proc sendmail 10 1
  29.  
  30. # Check the / partition and make sure it contains at least 10 megs.
  31.  
  32. disk / 10000
  33.  
  34. # Check for loads:
  35. load 12 14 14

重启snmpd服务
#/etc/init.d/snmpd restart

#killall -9 snmpd
#/usr/local/sbin/snmpd

iptables规则
假如B机开启了iptables并且INPUT默认策略为DROP
在第一条插入充许192.168.0.16(监控机)以udp协议访问snmpd默认161端口的规则

  1. /sbin/iptables -I INPUT -p udp -m udp -s 192.168.0.16 --dport 161 -j ACCEPT

保存一下,防止重启服务后失效

  1. /etc/init.d/iptables save

测试snmp
在A机上先看下系统信息
#snmpwalk -v 2c -c privatepass 192.168.0.17 system

  1. SNMPv2-MIB::sysDescr.0 = STRING: Linux touareg 2.6.18-128.el5 #1 SMP Wed Jan 21 10:41:14 EST 2009 x86_64
  2. SNMPv2-MIB::sysObjectID.0 = OID: NET-SNMP-MIB::netSnmpAgentOIDs.10
  3. DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (59664) 0:09:56.64
  4. SNMPv2-MIB::sysContact.0 = STRING: Root <root@localhost> (configure /etc/snmp/snmp.local.conf)
  5. SNMPv2-MIB::sysName.0 = STRING: touareg
  6. SNMPv2-MIB::sysLocation.0 = STRING: Unknown (edit /etc/snmp/snmpd.conf)
  7. SNMPv2-MIB::sysORLastChange.0 = Timeticks: (7) 0:00:00.07
  8. SNMPv2-MIB::sysORID.1 = OID: SNMPv2-MIB::snmpMIB
  9. SNMPv2-MIB::sysORID.2 = OID: TCP-MIB::tcpMIB
  10. SNMPv2-MIB::sysORID.3 = OID: IP-MIB::ip
  11. SNMPv2-MIB::sysORID.4 = OID: UDP-MIB::udpMIB
  12. SNMPv2-MIB::sysORID.5 = OID: SNMP-VIEW-BASED-ACM-MIB::vacmBasicGroup
  13. SNMPv2-MIB::sysORID.6 = OID: SNMP-FRAMEWORK-MIB::snmpFrameworkMIBCompliance
  14. SNMPv2-MIB::sysORID.7 = OID: SNMP-MPD-MIB::snmpMPDCompliance
  15. SNMPv2-MIB::sysORID.8 = OID: SNMP-USER-BASED-SM-MIB::usmMIBCompliance
  16. SNMPv2-MIB::sysORDescr.1 = STRING: The MIB module for SNMPv2 entities
  17. SNMPv2-MIB::sysORDescr.2 = STRING: The MIB module for managing TCP implementations
  18. SNMPv2-MIB::sysORDescr.3 = STRING: The MIB module for managing IP and ICMP implementations
  19. SNMPv2-MIB::sysORDescr.4 = STRING: The MIB module for managing UDP implementations
  20. SNMPv2-MIB::sysORDescr.5 = STRING: View-based Access Control Model for SNMP.
  21. SNMPv2-MIB::sysORDescr.6 = STRING: The SNMP Management Architecture MIB.
  22. SNMPv2-MIB::sysORDescr.7 = STRING: The MIB for Message Processing and Dispatching.
  23. SNMPv2-MIB::sysORDescr.8 = STRING: The management information definitions for the SNMP User-based Security Model.
  24. SNMPv2-MIB::sysORUpTime.1 = Timeticks: (6) 0:00:00.06
  25. SNMPv2-MIB::sysORUpTime.2 = Timeticks: (6) 0:00:00.06
  26. SNMPv2-MIB::sysORUpTime.3 = Timeticks: (6) 0:00:00.06
  27. SNMPv2-MIB::sysORUpTime.4 = Timeticks: (6) 0:00:00.06
  28. SNMPv2-MIB::sysORUpTime.5 = Timeticks: (6) 0:00:00.06
  29. SNMPv2-MIB::sysORUpTime.6 = Timeticks: (7) 0:00:00.07
  30. SNMPv2-MIB::sysORUpTime.7 = Timeticks: (7) 0:00:00.07
  31. SNMPv2-MIB::sysORUpTime.8 = Timeticks: (7) 0:00:00.07

没有问题,再看下磁盘信息
#snmpwalk -v 2c -c privatepass 192.168.0.17 .1.3.6.1.4.1.2021.9

  1. UCD-SNMP-MIB::dskIndex.1 = INTEGER: 1
  2. UCD-SNMP-MIB::dskPath.1 = STRING: /
  3. UCD-SNMP-MIB::dskDevice.1 = STRING: /dev/mapper/VolGroup00-LogVol01
  4. UCD-SNMP-MIB::dskMinimum.1 = INTEGER: 10000
  5. UCD-SNMP-MIB::dskMinPercent.1 = INTEGER: -1
  6. UCD-SNMP-MIB::dskTotal.1 = INTEGER: 44628400
  7. UCD-SNMP-MIB::dskAvail.1 = INTEGER: 22383404
  8. UCD-SNMP-MIB::dskUsed.1 = INTEGER: 19941408
  9. UCD-SNMP-MIB::dskPercent.1 = INTEGER: 47
  10. UCD-SNMP-MIB::dskPercentNode.1 = INTEGER: 1
  11. UCD-SNMP-MIB::dskErrorFlag.1 = INTEGER: noError(0)
  12. UCD-SNMP-MIB::dskErrorMsg.1 = STRING:

出现下面这个信息,你需要检查下A机snmpd.conf中“disk / 10000”前的注释有无去掉。

  1. UCD-SNMP-MIB::dskTable = No Such Object available on this agent at this OID

".1.3.6.1.4.1.2021.9"代表磁盘
".1.3.6.1.4.1.2021.10"代表load,可以参考snmpd.conf中的注释

监控机cacti增加监控设备
Console -> Devices->add
cacti add device
在设置页面配置

Description:touareg
Hostname:192.168.0.17
Host Template:ucd/net SNMP Host

Downed Device Detection:Ping and SNMP

SNMP Version:预定义的设置

保存后在页面左上角可以看到调试信息

touareg (192.168.0.17)
SNMP Information
System:Linux touareg 2.6.18-128.el5 #1 SMP Wed Jan 21 10:41:14 EST 2009
x86_64
Uptime: 38790 (0 days, 0 hours, 6 minutes)
Hostname: touareg
Location: Unknown (edit /etc/snmp/snmpd.conf)
Contact: Root root@localhost (configure /etc/snmp/snmp.local.conf)

cacti graphs

1) ucd/net - CPU Usage Not Being Graphed (cpu负载,system,user,nice)
2) ucd/net - Load Average Not Being Graphed (系统平均负载,1分钟,5分钟,15分钟)
3) ucd/net - Memory Usage Not Being Graphed (内存使用,free,buffers,cache)

1) SNMP - Interface Statistics (网卡流量,in,out)
2) ucd/net - Get Monitored Partitions (根分区,free,used)

Not Being Graphed 表示还末生成图像,创建图像后会变成Is Being Graphed
我们可以再添加一些更详细的监控
Host MIB - Processes 监控进程数量
Host MIB - Logged in Users 监控登录用户

SNMP - Get Mounted Partitions 更多分区大小,Memory Buffer,Real Memory,Swap Space
SNMP - Get Processor Information 每个cpu的负载

临控对像增加图表
左则New Graphs
在host中选择touareg
cacti graphs2
勾选右则后选择create,就完成了图表创建,真是很方便。

添加到Graph Trees
图表创建后在Graph Management里可以看到图表,但点击导航上方的"graphs"是看不到的,需要添加到graph trees中。
Console -> Graph Trees -> (Edit) -> Graph Tree Items

Tree Item Type:host
Host:touareg

创建后就可以在graph中看到了
cacti graph tree

参考:http://docs.cacti.net/manual:087:2_basics.0_principles_of_operation#principles_of_operation

收藏与分享

Posted in Cacti, 技术.

Tagged with , .


在 Android 手机上运行 PHP

PHP可不仅仅只能在互联网站上发展,一个PHP for Android (PFA)网站表示他们将可以发布编程模型、工具盒文档让PHP在Android上实现应用。该项目的主要赞助商是开源公司IronTec,PFA使用Scripting Layer for Android (SL4A),也就是Androd Scripting Environment (ASE)来实现这一点,您可以参看他们的网站来了解更多技术内幕。

1.下载并安装ASE
扫描下面的二维码,可在你的手机上安装个条码扫描器(BarcodeScanner)

或用浏览器下载并安装
http://phpforandroid.net/files/ASEr26unofficial.apk

2.安装PhpForAndroid.apk

或用浏览器下载并安装
http://phpforandroid.net/files/PhpForAndroid_r1.apk

3.运行
安装好PhpForAndroid_r1.apk后再运行ASE就可以看到5个php demo
hello_world.php

  1. <?php
  2. require_once("Android.php");
  3. $droid = new Android();
  4. $name = $droid->getInput("Hi!", "What is your name?");
  5. $droid->makeToast('Hello, ' . $name['result']);

list_items.php

  1. <?php
  2. require_once("Android.php");
  3. $droid = new Android();
  4. $droid->dialogCreateAlert();
  5. $droid->dialogSetItems(range(0, 9));
  6. $droid->dialogShow();

phpinfo.php

  1. <?php
  2. require_once("Android.php");
  3. ... phpinfo();#这里是我编辑器问题改成了全角

testnow.php

  1. <?php
  2. require_once("Android.php");
  3. $droid = new Android();
  4. //include("http://YOURHOST/yourfile.php.txt");

vibrate.php

  1. <?php
  2. require_once("Android.php");
  3. $droid = new Android();
  4. $droid->vibrate();

点击phpinfo.php文件开始运行;
程序会输出php的相关信息,当前使用的php版本为5.3.3rc2

  1. $ export TEMP="/sdcard/ase/extras/php/tmp"
  2. $ export AP_PORT="37356"
  3. $ export PHPHOME="/data/data/com.irontec.phpforandroid/php"
  4. $ export PHPPATH="/sdcard/ase/extras/php"
  5. $ /data/data/com.irontec.phpforandroid/php/bin/php -c $PHPPATH /sdcard/ase/scripts/phpinfo.php
  6. FIX ME! implement getprotobyname() bionic/libc/bionic/stubs.c:402
  7. FIX ME! implement getprotobyname() bionic/libc/bionic/stubs.c:402
  8. phpinfo()
  9. PHP Version => 5.3.3RC2
  10. System => Linux localhost 2.6.29.6-xdan #20 PREEMPT Sat Mar 27 03:36:57 EDT 2010 armv6l
  11. Build Date => Jul  4 2010 19:40:10
  12. Configure Command =>  './configure'  '--disable-all' '--target=arm-linux' '--enable-cli' '--enable-json' '--enable-sockets'
  13. Server API => Command Line Interface
  14. Virtual Directory Support => disabled
  15. Configuration File (php.ini) Path => /usr/local/lib
  16. Loaded Configuration File => /sdcard/ase/extras/php/php.ini
  17. Scan this dir for additional .ini files => (none)
  18. Additional .ini files parsed => (none)
  19. PHP API => 20090626
  20. PHP Extension => 20090626
  21. Zend Extension => 220090626
  22. Zend Extension Build => API220090626,NTS
  23. PHP Extension Build => API20090626,NTS
  24. Debug Build => no
  25. Thread Safety => disabled
  26. Zend Memory Manager => enabled
  27. Zend Multibyte Support => disabled
  28. IPv6 Support => disabled
  29. Registered PHP Streams => php, file, data, http, ftp
  30. Registered Stream Socket Transports => tcp, udp, unix, udg
  31. Registered Stream Filters => string.rot13, string.toupper, string.tolower, string.strip_tags, convert.*, consumed, dechunk
  32. This program makes use of the Zend Scripting Language Engine:
  33. Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
  34. _______________________________________________________________________
  35. Configuration
  36. Core
  37. PHP Version => 5.3.3RC2
  38. Directive => Local Value => Master Value
  39. allow_call_time_pass_reference => On => On
  40. allow_url_fopen => On => On
  41. allow_url_include => On => On
  42. always_populate_raw_post_data => Off => Off
  43. arg_separator.input => & => &
  44. arg_separator.output => & => &
  45. asp_tags => Off => Off
  46. auto_append_file => no value => no value
  47. auto_globals_jit => On => On
  48. auto_prepend_file => no value => no value
  49. browscap => no value => no value
  50. default_charset => no value => no value
  51. default_mimetype => text/html => text/html
  52. define_syslog_variables => Off => Off
  53. disable_classes => no value => no value
  54. disable_functions => no value => no value
  55. display_errors => STDOUT => STDOUT
  56. display_startup_errors => On => On
  57. doc_root => no value => no value
  58. docref_ext => no value => no value
  59. docref_root => no value => no value
  60. enable_dl => Off => Off
  61. error_append_string => no value => no value
  62. error_log => no value => no value
  63. error_prepend_string => no value => no value
  64. error_reporting => 22527 => 22527
  65. exit_on_timeout => Off => Off
  66. expose_php => On => On
  67. extension_dir => /usr/local/lib/php/extensions/no-debug-non-zts-20090626 => /usr/local/lib/php/extensions/no-debug-non-zts-20090626
  68. file_uploads => On => On
  69. highlight.bg => <font style="color: #FFFFFF">#FFFFFF</font> => <font style="color: #FFFFFF">#FFFFFF</font>
  70. highlight.comment => <font style="color: #FF8000">#FF8000</font> => <font style="color: #FF8000">#FF8000</font>
  71. highlight.default => <font style="color: #0000BB">#0000BB</font> => <font style="color: #0000BB">#0000BB</font>
  72. highlight.html => <font style="color: #000000">#000000</font> => <font style="color: #000000">#000000</font>
  73. highlight.keyword => <font style="color: #007700">#007700</font> => <font style="color: #007700">#007700</font>
  74. highlight.string => <font style="color: #DD0000">#DD0000</font> => <font style="color: #DD0000">#DD0000</font>
  75. html_errors => Off => Off
  76. ignore_repeated_errors => Off => Off
  77. ignore_repeated_source => Off => Off
  78. ignore_user_abort => Off => Off
  79. implicit_flush => On => On
  80. include_path => .:/sdcard/ase/extras/php => .:/sdcard/ase/extras/php
  81. log_errors => Off => Off
  82. log_errors_max_len => 1024 => 1024
  83. magic_quotes_gpc => Off => Off
  84. magic_quotes_runtime => Off => Off
  85. magic_quotes_sybase => Off => Off
  86. mail.add_x_header => Off => Off
  87. mail.force_extra_parameters => no value => no value
  88. mail.log => no value => no value
  89. max_execution_time => 0 => 0
  90. max_file_uploads => 20 => 20
  91. max_input_nesting_level => 64 => 64
  92. max_input_time => -1 => -1
  93. memory_limit => 128M => 128M
  94. open_basedir => no value => no value
  95. output_buffering => 0 => 0
  96. output_handler => no value => no value
  97. post_max_size => 8M => 8M
  98. precision => 14 => 14
  99. realpath_cache_size => 16K => 16K
  100. realpath_cache_ttl => 120 => 120
  101. register_argc_argv => On => On
  102. register_globals => Off => Off
  103. register_long_arrays => Off => Off
  104. report_memleaks => On => On
  105. report_zend_debug => Off => Off
  106. request_order => GP => GP
  107. safe_mode => Off => Off
  108. safe_mode_exec_dir => no value => no value
  109. safe_mode_gid => Off => Off
  110. safe_mode_include_dir => no value => no value
  111. sendmail_from => no value => no value
  112. sendmail_path => /usr/sbin/sendmail -t -i  => /usr/sbin/sendmail -t -i
  113. serialize_precision => 100 => 100
  114. short_open_tag => On => On
  115. SMTP => localhost => localhost
  116. smtp_port => 25 => 25
  117. sql.safe_mode => Off => Off
  118. track_errors => Off => Off
  119. unserialize_callback_func => no value => no value
  120. upload_max_filesize => 2M => 2M
  121. upload_tmp_dir => no value => no value
  122. user_dir => no value => no value
  123. user_ini.cache_ttl => 300 => 300
  124. user_ini.filename => .user.ini => .user.ini
  125. variables_order => GPCS => GPCS
  126. xmlrpc_error_number => 0 => 0
  127. xmlrpc_errors => Off => Off
  128. y2k_compliance => On => On
  129. zend.enable_gc => On => On
  130. date
  131. date/time support => enabled
  132. "Olson" Timezone Database Version => 2010.9
  133. Timezone Database => internal
  134. Warning: phpinfo(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/Chicago' for 'CST/-CST/no DST' instead in /sdcard/ase/scripts/phpinfo.php on line 4
  135. Default timezone => America/Chicago
  136. Directive => Local Value => Master Value
  137. date.default_latitude => 31.7667 => 31.7667
  138. date.default_longitude => 35.2333 => 35.2333
  139. date.sunrise_zenith => 90.583333 => 90.583333
  140. date.sunset_zenith => 90.583333 => 90.583333
  141. date.timezone => no value => no value
  142. ereg
  143. Regex Library => Bundled library enabled
  144. json
  145. json support => enabled
  146. json version => 1.2.1
  147. pcre
  148. PCRE (Perl Compatible Regular Expressions) Support => enabled
  149. PCRE Library Version => 8.02 2010-03-19
  150. Directive => Local Value => Master Value
  151. pcre.backtrack_limit => 100000 => 100000
  152. pcre.recursion_limit => 100000 => 100000
  153. Reflection
  154. Reflection => enabled
  155. Version => $Revision: 300393 $
  156. sockets
  157. Sockets Support => enabled
  158. SPL
  159. SPL support => enabled
  160. Interfaces => Countable, OuterIterator, RecursiveIterator, SeekableIterator, SplObserver, SplSubject
  161. Classes => AppendIterator, ArrayIterator, ArrayObject, BadFunctionCallException, BadMethodCallException, CachingIterator, DirectoryIterator, DomainException, EmptyIterator, FilesystemIterator, FilterIterator, InfiniteIterator, InvalidArgumentException, IteratorIterator, LengthException, LimitIterator, LogicException, MultipleIterator, NoRewindIterator, OutOfBoundsException, OutOfRangeException, OverflowException, ParentIterator, RangeException, RecursiveArrayIterator, RecursiveCachingIterator, RecursiveDirectoryIterator, RecursiveFilterIterator, RecursiveIteratorIterator, RecursiveRegexIterator, RecursiveTreeIterator, RegexIterator, RuntimeException, SplDoublyLinkedList, SplFileInfo, SplFileObject, SplFixedArray, SplHeap, SplMinHeap, SplMaxHeap, SplObjectStorage, SplPriorityQueue, SplQueue, SplStack, SplTempFileObject, UnderflowException, UnexpectedValueException
  162. standard
  163. Dynamic Library Support => enabled
  164. Path to sendmail => /usr/sbin/sendmail -t -i
  165. Directive => Local Value => Master Value
  166. assert.active => 1 => 1
  167. assert.bail => 0 => 0
  168. assert.callback => no value => no value
  169. assert.quiet_eval => 0 => 0
  170. assert.warning => 1 => 1
  171. auto_detect_line_endings => 0 => 0
  172. default_socket_timeout => 60 => 60
  173. safe_mode_allowed_env_vars => PHP_ => PHP_
  174. safe_mode_protected_env_vars => LD_LIBRARY_PATH => LD_LIBRARY_PATH
  175. url_rewriter.tags => a=href,area=href,frame=src,form=,fieldset= => a=href,area=href,frame=src,form=,fieldset=
  176. user_agent => no value => no value
  177. Additional Modules
  178. Module Name
  179. Environment
  180. Variable => Value
  181. ANDROID_ROOT => /system
  182. PHPPATH => /sdcard/ase/extras/php
  183. LD_LIBRARY_PATH => /system/lib
  184. PATH => /usr/bin:/usr/sbin:/bin:/sbin:/system/sbin:/system/bin:/system/xbin:/system/xbin/bb:/data/local/bin
  185. AP_PORT => 37356
  186. ANDROID_SOCKET_zygote => 11
  187. TEMP => /sdcard/ase/extras/php/tmp
  188. BOOTCLASSPATH => /system/framework/core.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/android.policy.jar:/system/framework/services.jar
  189. ANDROID_BOOTLOGO => 1
  190. ANDROID_ASSETS => /system/app
  191. EXTERNAL_STORAGE => /sdcard
  192. ANDROID_DATA => /data
  193. TERMINFO => /system/etc/terminfo
  194. ANDROID_PROPERTY_WORKSPACE => 10,32768
  195. PHPHOME => /data/data/com.irontec.phpforandroid/php
  196. PHP Variables
  197. Variable => Value
  198. _SERVER["ANDROID_ROOT"] => /system
  199. _SERVER["PHPPATH"] => /sdcard/ase/extras/php
  200. _SERVER["LD_LIBRARY_PATH"] => /system/lib
  201. _SERVER["PATH"] => /usr/bin:/usr/sbin:/bin:/sbin:/system/sbin:/system/bin:/system/xbin:/system/xbin/bb:/data/local/bin
  202. _SERVER["AP_PORT"] => 37356
  203. _SERVER["ANDROID_SOCKET_zygote"] => 11
  204. _SERVER["TEMP"] => /sdcard/ase/extras/php/tmp
  205. _SERVER["BOOTCLASSPATH"] => /system/framework/core.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/android.policy.jar:/system/framework/services.jar
  206. _SERVER["ANDROID_BOOTLOGO"] => 1
  207. _SERVER["ANDROID_ASSETS"] => /system/app
  208. _SERVER["EXTERNAL_STORAGE"] => /sdcard
  209. _SERVER["ANDROID_DATA"] => /data
  210. _SERVER["TERMINFO"] => /system/etc/terminfo
  211. _SERVER["ANDROID_PROPERTY_WORKSPACE"] => 10,32768
  212. _SERVER["PHPHOME"] => /data/data/com.irontec.phpforandroid/php
  213. _SERVER["PHP_SELF"] => /sdcard/ase/scripts/phpinfo.php
  214. _SERVER["SCRIPT_NAME"] => /sdcard/ase/scripts/phpinfo.php
  215. _SERVER["SCRIPT_FILENAME"] => /sdcard/ase/scripts/phpinfo.php
  216. _SERVER["PATH_TRANSLATED"] => /sdcard/ase/scripts/phpinfo.php
  217. _SERVER["DOCUMENT_ROOT"] =>
  218. _SERVER["REQUEST_TIME"] => 1279269078
  219. _SERVER["argv"] => Array
  220. (
  221.     [0] => /sdcard/ase/scripts/phpinfo.php
  222. )
  223. _SERVER["argc"] => 1
  224. PHP License
  225. This program is free software; you can redistribute it and/or modify
  226. it under the terms of the PHP License as published by the PHP Group
  227. and included in the distribution in the file:  LICENSE
  228. This program is distributed in the hope that it will be useful,
  229. but WITHOUT ANY WARRANTY; without even the implied warranty of
  230. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  231. If you did not receive a copy of the PHP license, or have any
  232. questions about PHP licensing, please contact license@php.net.

运行结束后就是控制台界面,按menu键会出来Exit&Edit可以进入编辑模式;
编辑模式下有API Browser可供调用,save & Run就可以调试程序了。
在我的g1,1.6固件上运行正常。

安装教程
http://www.phpforandroid.net/screencast

收藏与分享

Posted in Android, 其它.

Tagged with , , .


google JavaScript Style Guide

Google JavaScript Style Guide
另有C++ Style Guide, Objective-C Style Guide, and Python Style Guide

http://code.google.com/p/google-styleguide/

收藏与分享

Posted in JavaScript/DOM/XML, 技术.

Tagged with , .


cacti 安装npc 整合 nagios

Cacti是一套PHP程序,它使用snmpget命令采集数据、RRDTool绘图。Cacti界面简洁直观,让你根本无需明白RRDTool的众多参数即可轻松绘制出漂亮的图形。另外,它还提供了强大的数据管理和用户管理功能。在图像管理上,Cacti采用了树状结构的查看界面,在用户管理上,能对用户的权限进行细致划分,甚至支持使用LDAP进行用户验证。Cacti主要功能包括:数据定时采集、图像绘制与显示、树状的主机和图像管理、RRDTool信息管理、用户和权限管理以及模板导入导出等。

cactilogo

1.Cacti系统组成

  Cacti系统由4个部分组成:

  Cacti页面(PHP)——用户控制的平台,用户在此进行所有的设置;

  SNMP采集工具——Unix下使用 Net-SNMP软件包自带的“snmpget”和“snmpwalk”等程序,Windows下使用PHP的SNMP功能;

  RRDTool绘图引擎——性能数据的存储和绘画图像;

  MySQL数据库——储存RRDTool绘图所需的信息,如模板、rra、主机对应的信息等,要注意的是MySQL数据库并不保存性能数据,性能数据保存在RRDTool自己的数据库格式rrd文件中。利用Cacti可以对校园网络进行很好的实时监控,从而做到运筹帷幄。
2.菜单功能介绍

  Console菜单包括了New Graphs(创建新图像)、Graph Management(图像管理)、Graph Trees(图像树)、Data Sources(管理rrd文件)、Devices(设备管理)、 Data Queries 和Data Input Methods(采集数据方式)、Graph Templates(图像模板)、Host Templates(主机类型模板)、Data Templates(数据模板)、Import Templates(模板导入)、Export Templates(模板导出)Settings(Cacti的主要配置菜单)、System Utilities(显示Cacti系统的一些cache和log信息)、User Management(用户管理)、Logout User (用户退出登录)等菜单选项。

  Grapes菜单包括三种查看图像的形式,分别为setting、树形显示、列表型显示和预览型显示。
cacti_promo_main

在线demo:
http://status.pulpfree.org/cacti/graph_view.php?action=tree&tree_id=3&leaf_id=28&select_first=true
http://www.querx.com/cacti/graph_view.php?action=tree&tree_id=1&leaf_id=9
http://www.kende.com/cacti/graph_view.php?action=tree&tree_id=1&leaf_id=7&select_first=true
更多demo:
http://www.cacti.net/sites_that_use_cacti.php

最新版本:
The latest stable version is 0.8.7g, released 07/09/10.
http://www.cacti.net/download_cacti.php
0.8.7g版本和某些插件有兼容型问题,如npc,thold,我安装下来在顶部不能正常显示导航菜单。
cacti的版本要和插件架构匹配,我装0.8.7e+cacti-plugin-0.8.7f-PA可以使用,但顶部导航显示不正确。
这里选用0.8.7e+cacti-plugin-0.8.7e-PA

依赖关系:
安装之前需lamp环境 安装参考
net-snmp 安装参考
RRDTool 安装参考
php扩展 安装参考
php_json
pdo_mysql
sockets
nagios 安装参考
ndoutils 安装参考

下载cacti:
cd /opt/htdocs/www
wget wget http://www.cacti.net/downloads/cacti-0.8.7e.tar.gz
wget http://mirror.cactiusers.org/downloads/plugins/cacti-plugin-0.8.7e-PA-v2.6.zip
wget http://www.constructaegis.com/downloads/npc-2.0.4.tar.gz

constructaegis.com域名已过期
可以使用svn checkout
http://svn2.assembla.com/svn/npc/trunk

安装cacti:
我的nginx运行用户为www组为website
安装路径为/opt/htdocs/www

  1. tar zxvf cacti-0.8.7e.tar.gz
  2. mv cacti-0.8.7e cacti
  3. chown -R www:website cacti
  4. chmod -R 0775 cacti

安装cacti数据库:
创建cacti库,并创建cacti用户给予它cacti库权限,也可以使用phpmyadmin来完成.
导入cacti.sql到cacti库

  1. mysql –u root –p
  2. mysql>create database cacti;
  3. mysql>use cacti;
  4. Mysql>source /opt/htdocs/www/cacti/cacti.sql
  5. Mysql>grant all privileges on cacti.* to cacti@localhost identified by ‘cactipass’;
  6. #添加一个数据库账号cacti 密码为cactipass 用以访问cacti库
  7. Mysql>flush privileges;    #刷新权限信息

配置cacti数据库信息
#cd cacti
#vi include/config.php

  1. $database_type = "mysql";
  2. $database_default = "cacti";
  3. $database_hostname = "localhost";
  4. $database_username = "cactiuser";
  5. $database_password = "cacti";

配置cacti自动运行:
#crontab -e

  1. */5 * * * *  /opt/php/bin/php /opt/htdocs/www/cacti/poller.php > /dev/null 2>&1

Spine更有效率可以选择性安装

配置cacti:
访问cacti的web地址,就会显示安装界面
http://nagios.c1gstudio.com/cacti/

1.选择"新的安装"

2.配置路径(以系统中实际安装路径为准)
/usr/local/rrdtool/bin/rrdtool
/opt/php/bin/php
/usr/local/bin/snmpwalk
/usr/local/bin/snmpget
/usr/local/bin/snmpbulkwalk
/usr/local/bin/snmpgetnext

3.默认用户名及密码
admin/admin
接着输入新的密码

4.进入cacti后台
设置相应版本及验证码
settings->General
RRDTool Utility Version = RRDTool1.3.X
SNMP Version = 2
SNMP Community = 你的验证码(privatepass )
save

5.查看报表
点graphs选项5分钟后应该可以看到4个报表.
memory usage
load average
logged in users
processers

6.创建磁盘监控
在首页点击Create graphs然后在Data Query栏目中勾上需要监控的分区保存.

以上完成了cacti安装,下面安装插件
在安装插件前需先安装"插件框架"

安装插件框架:
1.解压

  1. cd /opt/htdocs/www
  2. unzip cacti-plugin-0.8.7e-PA-v2.6.zip
  3. chown -R www:website cacti-plugin-arch/
  4. chmod -R 0775 cacti-plugin-arch

2.导入数据库结构

  1. mysql -u cacti -p cacti<cacti-plugin-arch/pa.sql

3.覆盖文件
方法一:覆盖

  1. cp –rf cacti-plugin-arch/files-0.8.7e/* /opt/htdocs/www/cacti

方法二:打补丁

  1. cp cacti-plugin-arch/cacti-plugin-0.8.7e-PA-v2.6.diff /opt/htdocs/www/cacti/
  2.  cd /opt/htdocs/www/cacti/
  3.  patch -p1 -N <cacti-plugin-0.8.7e-PA-v2.6.diff

我用方法一

4.配置插件的数据库信息
#cd /opt/htdocs/www/cacti/
#vi include/global.php
#插件数据库需再配置一下

  1. $database_type = "mysql";
  2. $database_default = "cacti";
  3. $database_hostname = "localhost";
  4. $database_username = "cactiuser";
  5. $database_password = "cacti";

5.配制插件

  1. #我的cacti安装在域下的cacti目录,这里也需修改
  2. $config['url_path'] = '/cacti/';
  3.  
  4. #为后面安装npc增加变量
  5. $plugins[] = 'npc';

注:0.8.7g开始上面两变量改放在includes/config.php中,如果参照以前的教程会找不到了囧
参见Change Log
http://forums.cacti.net/viewtopic.php?t=38492

安装NPC插件:
1.解压后移到plugins目录下

  1. cd /opt/htdocs/www
  2. unzip npc.zip
  3. chown -R www:website npc
  4. chmod -R 0775 npc
  5. mv npc cacti/plugins/

2.启用cacti的插件功能,
以admin用户登陆cacti,在console中的user management里对admin的用户权限进行编辑,
勾选上Plugin Management、NPC、NPC Global Commands
然后到Plugin Management
安装并启用NPC即可。
在Settings->npc中
勾上Remote Commands
Nagios Command File Path=/usr/local/nagios/var/rw/nagios.cmd
Nagios URL=你的地址(http://nagios.c1gstudio.com/nagios/)

3.配置ndoutils
参见

如果一切正常点击导航菜单npc后就可以看到信息了。
没有显示可能有以下原因:

  1. cacti和npc版本不兼容
  2. cacti和plugin框架版本不一致
  3. npc没有正确安装(数据库结构不对)
  4. ndoutils没有正确配置(数据库中无信息)
  5. php-json,pdo_mysql,sockets没有安装(php -m 检查一下)

留意cacti/log/cacti.log文件

==============================
2010-07-23
spine安装
#wget http://www.cacti.net/downloads/spine/cacti-spine-0.8.7e.tar.gz
#tar zxvf cacti-spine-0.8.7e.tar.gz
#cd cacti-spine-0.8.7e
#./configure
#make
#make install
#vi /usr/local/spine/etc/spine.conf

  1. DB_Host         localhost
  2. DB_Database     cacti
  3. DB_User         cactiuser
  4. DB_Pass         cacti
  5. DB_Port         3306

#mv /usr/local/spine/etc/spine.conf /etc/
#/usr/local/spine/bin/spine

  1. SPINE: Using spine config file [/etc/spine.conf]
  2. SPINE: Version 0.8.7e starting
  3. SPINE: Time: 7.3153 s, Threads: 1, Hosts: 11

配置spine
(1)登陆console--Configuration--Settings--poller--Poller Type改为spine
(2)登陆console--Configuration--Settings--paths--Spine Poller File Path添加/usr/local/spine/bin/spine

#tail /opt/htdocs/www/cacti/log/cacti.log
07/23/2010 03:20:02 PM - POLLER: Poller[0] ERROR: The path: /usr/local/spine/bin/spine is invalid. Can not continue #如果你的php有open_basedir限制,需加上/usr/local/spine/bin/目录
07/23/2010 03:25:04 PM - SYSTEM STATS: Time:3.2262 Method:spine Processes:1 Threads:1 Hosts:11 HostsPerProcess:11 DataSources:190 RRDsProcessed:147 #相比php方式快很多

参考:
http://liuyu.blog.51cto.com/183345/259995
http://www.cacti.net/downloads/docs/html/install_unix.html

收藏与分享

Posted in Cacti.

Tagged with , , , .


强大的Excel 文档生成类库PHPExcel

PHPExcel是强大的 MS Office Excel 文档生成类库,基于Microsoft's OpenXML ,支持普通xls,Excel2007,pdf,csv,html等
官方网站http://phpexcel.codeplex.com/
最新版本为2010-05-31 Release 1.7.3c ,7.1M左右

注意插入的值是以'='开头,默认会用作公式,而不是字符串导致出错。

当前支持的一些功能:

    Set spreadsheet meta data (author, title, description, ...)
    支持文档属性设置
    Add worksheets to spreadsheet
    增加工作表
    Add data and formulas to individual cells
    填充单元格值
    Merge cells
    合并单元格
    Protect ranges of cells with a password
    密码保护单元格
    Supports setting cell width and height
    设定例宽和例高
    Supports different fonts and font styles
    设定字体及样式
    Supports formatting, styles, cell borders, fills, gradients, ...
    设定格式,样式,边框
    Supports hyperlinks
    超链接格式
    Supports different data types for individual cells
    独立的单元格类型
    Supports cell text wrapping
    单元格折行
    Supports conditional formatting
    条件格式
    Supports column auto-sizing
    自适应列宽
    Supports rich-text strings
    富文本格式
    Supports autofilter
    自动筛选
    Supports "freezing" cell panes
    锁定单元格
    Supports cell-level security
    单元格级安全
    Supports workbook-level security
    工作簿级安全
    Supports worksheet-level protection
    工作表保护
    Group rows/columns
    分组
    Cell data validation
    数据验证
    Insert/remove rows/columns
    插入/移除行或列
    Named ranges
    指定范围
    Worksheet references
    工作表引用
    Calculate formula values
    公式计算
    Add comments to a cell
    单元格注释
    Add images to your spreadsheet
    添加图片
    Set image styles
    图片样式
    Positioning
    图片位置
    Rotation
    图片角度
    Shadow
    图片阴影
    Set printing options
    打印选项
    Header
    页头
    Footer
    页脚
    Page margins
    页边距
    Paper size
    打印页大小
    Orientation
    打印方向
    Row and column breaks
    行或列换行
    Repeat rows at header / columns at left
    重复行或列
    Print area
    区域打印
    Output your spreadsheet object to different file formats
    多种输出格式
    Excel 2007 (spreadsheetML)
    BIFF8 (Excel 97 and higher)
    PHPExcel Serialized Spreadsheet
    CSV (Comma Separated Values)
    HTML
    PDF
    Read different file formats into your spreadsheet object
    读取多种格式
    Excel 2007 (spreadsheetML)
    BIFF5 (Excel 5.0 / Excel 95), BIFF8 (Excel 97 and higher)
    PHPExcel Serialized Spreadsheet
    Excel 2003 XML format
    Symbolic Link (SYLK)
    CSV (Comma Separated Values)图片详例:

phpexcel生成效果图:
phpexcel_features

 
其它详例:

php代码详例:

  1. <?php
  2. /** Error reporting */
  3. error_reporting(E_ALL);
  4.  
  5. /** PHPExcel */
  6. require_once '../Classes/PHPExcel.php';
  7.  
  8.  
  9. $objPHPExcel = new PHPExcel();
  10.  
  11. // 设置文件属性
  12. $objPHPExcel->getProperties()->setCreator("C1G")
  13.                              ->setLastModifiedBy("C1G")
  14.                              ->setTitle("phpexcel Test Document")
  15.                              ->setSubject("phpexcel Test Document")
  16.                              ->setDescription("Test document for phpexcel, generated using PHP classes.")
  17.                              ->setKeywords("office 2007 openxml php c1gstudio")
  18.                              ->setCategory("Test");
  19.  
  20. //设置当前活动的sheet
  21. $objPHPExcel->setActiveSheetIndex(0);
  22.  
  23. //设置sheet名字
  24. $objPHPExcel->getActiveSheet()->setTitle('phpexcel demo');
  25.  
  26. //设置默认行高
  27. $objPHPExcel->getActiveSheet()->getDefaultRowDimension()->setRowHeight(15);
  28.  
  29. //由PHPExcel根据传入内容自动判断单元格内容类型
  30. $objPHPExcel->getActiveSheet()->setCellValue('A1', "Firstname");
  31. $objPHPExcel->getActiveSheet()->setCellValue('B1', "Lastname");
  32. $objPHPExcel->getActiveSheet()->setCellValue('C1', "Phone");
  33. $objPHPExcel->getActiveSheet()->setCellValue('D1', "Fax");
  34. $objPHPExcel->getActiveSheet()->setCellValue('E1', "Address");
  35. $objPHPExcel->getActiveSheet()->setCellValue('F1', "ZIP");
  36. $objPHPExcel->getActiveSheet()->setCellValue('G1', "DATE");
  37.  
  38.  
  39. $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(0, 8, 'firstname');
  40. $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(1, 8, 'lastname');
  41.  
  42.  
  43. // utf8格式字符
  44. $objPHPExcel->setActiveSheetIndex(0)
  45.             ->setCellValue('A15', 'Miscellaneous glyphs')
  46.             ->setCellValue('A16', 'éàèùâêîôûëïüÿäöüç')
  47.             ->setCellValue('A17', 'phpexcel演示');
  48.  
  49. $objPHPExcel->getActiveSheet()->setCellValue('A9', "502");
  50. $objPHPExcel->getActiveSheet()->setCellValue('B9', "99");
  51. $objPHPExcel->getActiveSheet()->setCellValue('C9', "=SUM(A9:B9)");
  52.  
  53. //设置列宽
  54. $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth('20');
  55.  
  56.  
  57. // 设置行高
  58. $objPHPExcel->getActiveSheet()->getRowDimension('9')->setRowHeight(20);
  59.  
  60. // 加粗
  61. $objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
  62.  
  63. // 中文
  64. $objPHPExcel->getActiveSheet()->setCellValue('A2', "小风");
  65. $objPHPExcel->getActiveSheet()->setCellValue('B2', "wang");
  66.  
  67. // 设置单元格格式
  68. $objPHPExcel->getActiveSheet()->getCell('C2')->setValueExplicit('861391327543258', PHPExcel_Cell_DataType::TYPE_NUMERIC);
  69.  
  70. // 日期
  71. $objPHPExcel->getActiveSheet()->setCellValue('G2', '2008-12-31');
  72. $objPHPExcel->getActiveSheet()->getStyle('G2')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDDSLASH);
  73.  
  74. // 时间戳
  75. $time = gmmktime(0,0,0,12,31,2008); // int(1230681600)
  76. $objPHPExcel->getActiveSheet()->setCellValue('G3', PHPExcel_Shared_Date::PHPToExcel($time));
  77. $objPHPExcel->getActiveSheet()->getStyle('G3')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDDSLASH);
  78.  
  79. // url
  80. $objPHPExcel->getActiveSheet()->setCellValue('G11', 'blog.c1gstudio.com');
  81. $objPHPExcel->getActiveSheet()->getCell('G11')->getHyperlink()->setUrl('http://blog.c1gstudio.com');
  82.  
  83. // 另一个sheet
  84. $objPHPExcel->getActiveSheet()->setCellValue('G12', 'sheetb');
  85. $objPHPExcel->getActiveSheet()->getCell('G12')->getHyperlink()->setUrl("sheet://'sheetb'!A1");
  86.  
  87. // 水平居上
  88. $objPHPExcel->getActiveSheet()->getStyle('A9:B9')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_TOP);
  89.  
  90. // 单元格换行
  91. $objPHPExcel->getActiveSheet()->getStyle('G2:G3')->getAlignment()->setWrapText(true);
  92.  
  93. // 合并
  94. $objPHPExcel->getActiveSheet()->mergeCells('A18:E22');
  95.  
  96.  
  97. // 隐藏D列
  98. $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setVisible(false);
  99.  
  100. //
  101. $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setOutlineLevel(1);
  102. $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setVisible(false);
  103. $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setOutlineLevel(1);
  104. $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setVisible(false);
  105. $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setCollapsed(true);
  106.  
  107. // 固定第一行
  108. $objPHPExcel->getActiveSheet()->freezePane('A2');
  109.  
  110. // 保护工作表
  111. $objPHPExcel->getActiveSheet()->getProtection()->setPassword('PHPExcel');
  112. $objPHPExcel->getActiveSheet()->getProtection()->setSheet(true);
  113. $objPHPExcel->getActiveSheet()->getProtection()->setSort(true);
  114. $objPHPExcel->getActiveSheet()->getProtection()->setInsertRows(true);
  115. $objPHPExcel->getActiveSheet()->getProtection()->setFormatCells(true);
  116.  
  117. //设置边框
  118. $sharedStyle1 = new PHPExcel_Style();
  119. $sharedStyle1->applyFromArray(
  120.     array('borders' => array(
  121.                                 'left'        => array('style' => PHPExcel_Style_Border::BORDER_MEDIUM)
  122.                             )
  123.          ));
  124. $objPHPExcel->getActiveSheet()->setSharedStyle($sharedStyle1, "B1:B10");
  125.  
  126. // 创建一个新的工作表
  127. $objWorksheet1 = $objPHPExcel->createSheet();
  128. $objWorksheet1->setTitle('sheetb');
  129.  
  130.  
  131. $objPHPExcel->setActiveSheetIndex(1);
  132.  
  133.  
  134. // 创建一个图片
  135. $gdImage = @imagecreatetruecolor(200, 20) or die('Cannot Initialize new GD image stream');
  136. $textColor = imagecolorallocate($gdImage, 255, 255, 255);
  137. imagestring($gdImage, 1, 5, 5'Created with PHPExcel (c1gstudio.com)', $textColor);
  138.  
  139. // 把创建的图片添加到工作表
  140. $objDrawing = new PHPExcel_Worksheet_MemoryDrawing();
  141. $objDrawing->setName('Sample image');
  142. $objDrawing->setDescription('Sample image');
  143. $objDrawing->setImageResource($gdImage);
  144. $objDrawing->setRenderingFunction(PHPExcel_Worksheet_MemoryDrawing::RENDERING_JPEG);
  145. $objDrawing->setMimeType(PHPExcel_Worksheet_MemoryDrawing::MIMETYPE_DEFAULT);
  146. $objDrawing->setHeight(36);
  147. $objDrawing->setWorksheet($objPHPExcel->getActiveSheet());
  148.  
  149. $objPHPExcel->setActiveSheetIndex(0);
  150.  
  151. // 保存
  152. $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  153. $objWriter->save('testexcel'.time().'.xls');
  154.  
  155. /*
  156. //在浏览器导出
  157. header('Content-Type: application/vnd.ms-excel');
  158. header('Content-Disposition: attachment;filename="testexcel.xls"');
  159. header('Cache-Control: max-age=0');
  160.  
  161. $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  162. $objWriter->save('php://output');
  163.  
  164. */
  165. /**
  166. * $Log$
  167. */
  168. ?>

上面代码生成的excel文件.
testexcel1278403711.xls

收藏与分享

Posted in PHP, 技术.

Tagged with , , .


lvm在线增加磁盘空间

一。查看当前空间
#df -h

  1. Filesystem            Size  Used Avail Use% Mounted on
  2. /dev/mapper/VolGroup00-LogVol00
  3.                        97G  1.9G   91G   3% /
  4. /dev/mapper/VolGroup00-LogVol01
  5.                       194G  140G   44G  77% /home
  6. /dev/mapper/VolGroup00-LogVol04
  7.                        97G   17G   75G  19% /var
  8. /dev/mapper/VolGroup00-LogVol03
  9.                        97G   52G   41G  56% /opt
  10. /dev/mapper/VolGroup00-LogVol02
  11.                       9.7G  158M  9.1G   2% /tmp
  12. /dev/sda1              99M   12M   82M  13% /boot
  13. tmpfs                1010M  4.0K 1010M   1% /dev/shm

/home 增加200G
/opt 增加100G

fdisk 查看下磁盘为1T大小,并全部分给lvm
#fdisk -l

  1. Disk /dev/sda: 1000.2 GB, 1000203804160 bytes
  2. 255 heads, 63 sectors/track, 121601 cylinders
  3. Units = cylinders of 16065 * 512 = 8225280 bytes
  4.  
  5.    Device Boot      Start         End      Blocks   Id  System
  6. /dev/sda1   *           1          13      104391   83  Linux
  7. /dev/sda2              14         535     4192965   82  Linux swap / Solaris
  8. /dev/sda3             536      121601   972462645   8e  Linux LVM

vgdisplay查看卷组空间,还有400G空闲空间
#vgdisplay

  1. --- Volume group ---
  2.   VG Name               VolGroup00
  3.   System ID             
  4.   Format                lvm2
  5.   Metadata Areas        1
  6.   Metadata Sequence No  6
  7.   VG Access             read/write
  8.   VG Status             resizable
  9.   MAX LV                0
  10.   Cur LV                5
  11.   Open LV               5
  12.   Max PV                0
  13.   Cur PV                1
  14.   Act PV                1
  15.   VG Size               927.41 GB
  16.   PE Size               32.00 MB
  17.   Total PE              29677
  18.   Alloc PE / Size       16320 / 510.00 GB
  19.   Free  PE / Size       13357 / 417.41 GB
  20.   VG UUID               4Wzdqp-f3RH-1lEP-YfXN-01Vp-3K5c-EmtcBE

二.开始增加空间
(错误的方式)
#lvextend -L +100G /dev/mapper/VolGroup00-LogVol03

  1. Volume group "mapper" not found
  2.   Volume group mapper doesn't exist

这里的设备名写错了(另注意一定要加"+"),正确的是
#lvextend -L +100G /dev/VolGroup00/LogVol03

  1. Extending logical volume LogVol03 to 200.00 GB
  2.   Logical volume LogVol03 successfully resized

三.lvextend修改了lvm的大小,下面还需修改文件系统大小。
可以用umount+resize2fs 或ext2online
umount通常会碰到device is busy,这里用ext2online

下载ext2online
http://www.mirrorservice.org/sites/download.sourceforge.net/pub/sourceforge/e/project/ex/ext2resize/ext2resize/ext2resize-1.1.19/

1.下载i386的rpm
#wget http://www.mirrorservice.org/sites/download.sourceforge.net/pub/sourceforge/e/project/ex/ext2resize/ext2resize/ext2resize-1.1.19/ext2resize-1.1.19-1.i386.rpm

2.创建sct用户
#useradd sct
#rpm -ivh ext2resize-1.1.19-1.i386.rpm
-----------------
安装完成后会有三个命令:
ext2online ext2prepare ext2resize
-----------------
注意:安装此工具,必须有sct用户(当前用户不用是sct)

3.运行
#ext2online /dev/VolGroup00/LogVol03
ext2online v1.1.18 - 2001/03/18 for EXT2FS 0.5b

四.最后检查
#df -h

  1. Filesystem            Size  Used Avail Use% Mounted on
  2. /dev/mapper/VolGroup00-LogVol00
  3.                        97G  1.9G   91G   3% /
  4. /dev/mapper/VolGroup00-LogVol01
  5.                       194G  140G   44G  77% /home
  6. /dev/mapper/VolGroup00-LogVol04
  7.                        97G   17G   75G  19% /var
  8. /dev/mapper/VolGroup00-LogVol03
  9.                       194G   52G  133G  28% /opt
  10. /dev/mapper/VolGroup00-LogVol02
  11.                       9.7G  158M  9.1G   2% /tmp
  12. /dev/sda1              99M   12M   82M  13% /boot
  13. tmpfs                1010M     0 1010M   0% /dev/shm

/opt 已增加到200G.同样的方式再增加/home就可以了。

收藏与分享

Posted in linux 维护优化, 技术.

Tagged with , , .