2010年4月3号Google PR更新

2010年4月3号下午发现Google PR在更新,Njava的PR还是维持3,希望下3个月的周期里能有所上升。虽然说不重要了,但是受应试教育的影响,还是很期待这个分数的。同时今天Apple也正式发售IPAD了,希望有一天能弄一个来玩玩

Tags: , , ,

星期日, 四月 4th, 2010 网络 没有评论

使用find命令定期删除n天前的日志文件

日志和备份多了,硬盘不够了,所以删除之

bear@njava:/data/log$ find /data/log -mtime +3 -exec rm -rf {} \;

关于find参数-mtime,-ctime,-atime

bear@njava:~$ man find
       -mtime n
              File's data was last modified n*24 hours ago.  See the comments for -atime to understand how  rounding
              affects the interpretation of file modification times.
       -ctime n
              File's status was last changed n*24 hours ago.  See the comments for -atime to understand how rounding
              affects the interpretation of file status change times.
      -atime n
              File  was  last  accessed n*24 hours ago.  When find figures out how many 24-hour periods ago the file
              was last accessed, any fractional part is ignored, so to match -atime +1, a  file  has  to  have  been
              accessed at least two days ago.

Tags: , ,

星期六, 四月 3rd, 2010 服务器 没有评论

linux的内存使用查看和实际可用内存计算

使用free,top等工具都可以查看linux的内存使用量,如
使用top命令

bear@njava:/etc/nginx/conf# top
Tasks:  36 total,   2 running,  32 sleeping,   2 stopped,   0 zombie
Cpu(s):  0.3%us,  0.3%sy,  0.0%ni, 99.3%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:    524800k total,   478320k used,    46480k free,        0k buffers
Swap:        0k total,        0k used,        0k free,        0k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND            
15658 www-data  23   0 49188 7280 4104 S  0.0  1.4   0:00.03 php5-cgi           
15663 www-data  16   0 57888  28m  16m S  0.0  5.5   0:12.62 php5-cgi           
15664 www-data  16   0 60704  32m  18m S  0.0  6.4   0:11.99 php5-cgi           
15665 www-data  16   0 59488  29m  16m S  0.0  5.8   0:11.00 php5-cgi           
15667 www-data  18   0 58388  30m  17m S  0.0  5.9   0:11.62 php5-cgi           
15668 www-data  16   0 58628  28m  16m S  0.0  5.6   0:12.05 php5-cgi           
15669 www-data  16   0 58660  29m  16m S  0.0  5.7   0:09.81 php5-cgi           
15670 www-data  16   0 56220  26m  16m S  0.0  5.2   0:11.24 php5-cgi           
15671 www-data  16   0 59432  29m  16m S  0.0  5.8   0:11.04 php5-cgi           
15673 www-data  16   0 54596  25m  16m S  0.0  4.9   0:12.43 php5-cgi           
15674 www-data  16   0 58036  27m  15m S  0.0  5.4   0:11.66 php5-cgi           
19790 www-data  15   0 10856 2644 1008 S  0.0  0.5   0:02.18 nginx              
19791 www-data  18   0 10856 2676 1060 S  0.0  0.5   0:01.55 nginx              
19939 www-data  17   0  6936 3136  744 S  0.0  0.6   0:00.11 nginx-fcgi 

使用free命令

bear@njava:/etc/nginx/conf# free
             total       used       free     shared    buffers     cached
Mem:        524800     476756      48044          0          0          0
-/+ buffers/cache:     476756      48044
Swap:            0          0          0
bear@njava:/etc/nginx/conf# 

又那么多的内存参数字段:used,free,shared,buffers,cached
怎么计算实际剩余可用内存呢?
公式如下:

空闲内存=free+buffers+cached

看上去巴士的vps不适合做这个例子,呵呵,当作留存吧

Tags: ,

星期五, 四月 2nd, 2010 服务器 没有评论

ubuntu修改时区

查看时区

bear@njava:#  date -R

修改为+8时区的上海

bear@njava:#  cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

Tags: ,

星期五, 四月 2nd, 2010 服务器 没有评论

nginx的stub_status状态信息解释

打开nginx的stub_status可以通过页面链接看到如下信息

Active connections: 353
server accepts handled requests
 532423 532423 3283276
Reading: 1 Writing: 1 Waiting: 351

他们是啥意思呢,解释如下
active connections:353 #nginx 正处理的活动连接数 353个。
server accepts handled requests
nginx启动到现在共处理了 532423个连接 ,
nginx启动到现在共成功创建 532423 次握手 ,
请求丢失数=(握手-连接),可以看出,我们没丢请求
总共处理了3283276 次请求。
Reading :nginx 读取到客户端的 Header 信息数。
Writing : nginx 返回给客户端的 Header 信息数。
Waiting : Nginx 已经处理完正在等候下一次请求指令的驻留连接。开启 keep-alive 的情况下,这个值等于 active – (reading + writing)。

Tags: ,

星期五, 四月 2nd, 2010 服务器 没有评论

cacti的rrdtool画不出图来的问题

1 习惯性的把rrd的文件rm -rf *掉了,发现cron过了好多次都没画出图来
2 检查权限,权限ok的,cron的执行用户和/var/www/cacti/rra目录的拥有者是同一个用户

bear@njava:/var/www/cacti/rra$ sudo vi /etc/crontab
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m h dom mon dow user  command
17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly
25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6    * * 7   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6    1 * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
*/5 * * * * www-data php /var/www/cacti/poller.php > /dev/null 2>&1

3 把Poller Type由spine改成cmd.php,奇迹发生了,图被画出来了,之后再改回spine,运转正常

Tags: ,

星期四, 四月 1st, 2010 服务器 没有评论

cacti通过snmp监控ubuntu9.10网卡流量遇到的问题

折腾无线,snmp总是链接不上,debug报如下错误;

+ Running data query [1].
+ Found type = '3' [snmp query].
+ Found data query XML file at '/var/www/cacti/resource/snmp_queries/interface.xml'
+ XML file parsed ok.
+ Executing SNMP walk for list of indexes @ '.1.3.6.1.2.1.2.2.1.1'
+ No SNMP data returned
+ Found data query XML file at '/var/www/cacti/resource/snmp_queries/interface.xml'
+ Found data query XML file at '/var/www/cacti/resource/snmp_queries/interface.xml'
+ Found data query XML file at '/var/www/cacti/resource/snmp_queries/interface.xml'

谷歌百度,终于找到解决办法,记录之。。。

bear@njava:/var/www/njava$ sudo vi /etc/snmp/snmpd.conf 
# First, map the community name (COMMUNITY) into a security name
# (local and mynetwork, depending on where the request is coming
# from):
# sec.name  source          community
#com2sec paranoid  default         public
#com2sec paranoid  default         njava
com2sec readonly  default         public
bear@njava:/var/www/njava$ sudo /etc/init.d/snmpd restart

获取到后的数据源

+ Running data query [1].
+ Found type = '3' [snmp query].
+ Found data query XML file at '/var/www/cacti/resource/snmp_queries/interface.xml'
+ XML file parsed ok.
+ Executing SNMP walk for list of indexes @ '.1.3.6.1.2.1.2.2.1.1'
+ Index found at OID: '1.3.6.1.2.1.2.2.1.1.1' value: '1'
+ Index found at OID: '1.3.6.1.2.1.2.2.1.1.2' value: '2'
+ Index found at OID: '1.3.6.1.2.1.2.2.1.1.3' value: '3'
+ Located input field 'ifIndex' [walk]
+ Executing SNMP walk for data @ '.1.3.6.1.2.1.2.2.1.1'
+ Found item [ifIndex='1'] index: 1 [from value]
+ Found item [ifIndex='2'] index: 2 [from value]
+ Found item [ifIndex='3'] index: 3 [from value]
+ Located input field 'ifOperStatus' [walk]
+ Executing SNMP walk for data @ '.1.3.6.1.2.1.2.2.1.8'
+ Found item [ifOperStatus='Up'] index: 1 [from value]
+ Found item [ifOperStatus='Up'] index: 2 [from value]
+ Found item [ifOperStatus='Down'] index: 3 [from value]
+ Located input field 'ifDescr' [walk]
+ Executing SNMP walk for data @ '.1.3.6.1.2.1.2.2.1.2'
+ Found item [ifDescr='lo'] index: 1 [from value]
+ Found item [ifDescr='eth0'] index: 2 [from value]
+ Found item [ifDescr='eth1'] index: 3 [from value]
+ Located input field 'ifName' [walk]
+ Executing SNMP walk for data @ '.1.3.6.1.2.1.31.1.1.1.1'
+ Found item [ifName='lo'] index: 1 [from value]
+ Found item [ifName='eth0'] index: 2 [from value]
+ Found item [ifName='eth1'] index: 3 [from value]
+ Located input field 'ifAlias' [walk]
+ Executing SNMP walk for data @ '.1.3.6.1.2.1.31.1.1.1.18'
+ Found item [ifAlias=''] index: 1 [from value]
+ Found item [ifAlias=''] index: 2 [from value]
+ Found item [ifAlias=''] index: 3 [from value]
+ Located input field 'ifType' [walk]
+ Executing SNMP walk for data @ '.1.3.6.1.2.1.2.2.1.3'
+ Found item [ifType='softwareLoopback(24)'] index: 1 [from value]
+ Found item [ifType='ethernetCsmacd(6)'] index: 2 [from value]
+ Found item [ifType='ethernetCsmacd(6)'] index: 3 [from value]
+ Located input field 'ifSpeed' [walk]
+ Executing SNMP walk for data @ '.1.3.6.1.2.1.2.2.1.5'
+ Found item [ifSpeed='10000000'] index: 1 [from value]
+ Found item [ifSpeed='100000000'] index: 2 [from value]
+ Found item [ifSpeed='0'] index: 3 [from value]
+ Located input field 'ifHwAddr' [walk]
+ Executing SNMP walk for data @ '.1.3.6.1.2.1.2.2.1.6'
+ Found item [ifHwAddr=''] index: 1 [from value]
+ Found item [ifHwAddr='00:0D:60:D4:BC:04'] index: 2 [from value]
+ Found item [ifHwAddr='00:0D:60:D4:BC:05'] index: 3 [from value]
+ Located input field 'ifIP' [walk]
+ Executing SNMP walk for data @ '.1.3.6.1.2.1.4.20.1.2'
+ Found item [ifIP='127.0.0.1'] index: 1 [from regexp oid parse]
+ Found item [ifIP='8.8.8.8'] index: 2 [from regexp oid parse]
+ Found data query XML file at '/var/www/cacti/resource/snmp_queries/interface.xml'
+ Found data query XML file at '/var/www/cacti/resource/snmp_queries/interface.xml'
+ Found data query XML file at '/var/www/cacti/resource/snmp_queries/interface.xml'
+ Found data query XML file at '/var/www/cacti/resource/snmp_queries/interface.xml'
+ Found data query XML file at '/var/www/cacti/resource/snmp_queries/interface.xml'
+ Found data query XML file at '/var/www/cacti/resource/snmp_queries/interface.xml'

参考:http://www.linuxquestions.org/questions/linux-networking-3/cacti-traffic-stats-snmp-config-prob-378983/

Tags: , ,

星期四, 四月 1st, 2010 服务器 没有评论

ubuntu网卡流量实时查看

1  工具iftop


bear@njava:~# sudo apt-get install iftop

bear@njava:~# sudo iftop

2 工具nload


bear@njava:~# sudo apt-get install nload

bear@njava:~# nload

Tags: ,

星期三, 三月 31st, 2010 服务器 没有评论

Nginx的防盗链模块NginxHttpAccessKeyModule

1 下载

bear@njava:/$wget http://wiki.nginx.org/images/5/51/Nginx-accesskey-2.0.3.tar.gz

2 配置

bear@njava:/$tar -xzvf Nginx-accesskey-2.0.3.tar.gz
bear@njava:/$vi ../nginx-accesskey-2.0.3/config
USE_MD5=YES
USE_SHA1=YES
ngx_addon_name=ngx_http_accesskey_module
#HTTP_MODULES="$HTTP_MODULES $HTTP_ACCESSKEY_MODULE"
HTTP_MODULES="$HTTP_MODULES ngx_http_accesskey_module"
NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_accesskey_module.c"

3 重编译nginx

bear@njava:~/nginx-0.8.34# ./configure --conf-path=/etc/nginx/nginx.conf \--error-log-path=/var/log/nginx/error.log --pid-path=/var/run/nginx.pid --lock-path=/var/lock/nginx.lock --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/body --http-proxy-temp-path=/var/lib/nginx/proxy --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --with-debug --with-http_stub_status_module --with-http_flv_module --with-http_ssl_module --with-http_dav_module --with-http_gzip_static_module --with-mail --with-mail_ssl_module --with-ipv6 --with-http_realip_module --with-http_geoip_module --with-http_xslt_module --with-http_image_filter_module --with-sha1=/usr/include/openssl --with-md5=/usr/include/openssl --add-module=../gnosek-nginx-upstream-fair-2131c73 --add-module=../nginx-accesskey-2.0.3

4 配置NginxHttpAccessKeyModule

bear@njava:~/nginx-0.8.34$ vi /etc/nginx/sites-available/njava
       location /test {
         accesskey             on;
         accesskey_hashmethod  md5;
         accesskey_arg         "abc";
         accesskey_signature   "njavakey$remote_addr";
         }

5 重启nginx

6 使用
使用的时候参考代码如下:

function get_acc_url($url){
  return $url."?abc=" . md5('njavakey' . $_SERVER['REMOTE_ADDR']);
}

7 代码测试
http://www.njava.com/a.php

Tags: , ,

星期二, 三月 30th, 2010 服务器 没有评论

隐藏php版本号

很不爽http头部信息给别人看njava的Php版本信息,修改对应的php.ini属性expose_php

bear@njava:~/nginx-0.8.34# sudo vi /etc/php5/cgi/php.i
#expose_php = On
expose_php = Off

Tags: ,

星期二, 三月 30th, 2010 服务器 没有评论
Pages: Prev 1 2 3 4 5 6 7 8 9 10 ... 13 14 15 Next
1LMooBmUE153Wnd3zDryWvDyXxQudbFxDr