存档

‘系统管理’ 分类的存档

Debian下配置mrtg

2010年6月4日 没有评论

目标:配置mrtg并每5分钟更新一次mrtg到/var/www/mrtg

1、安装snmpd, mrtg

apt-get install snmpd mrtg

mrtg是基于snmp通信,snmpd必不可少

2、配置snmpd
修改 /etc/snmp/snmpd.conf

com2sec paranoid   default         public
#com2sec readonly  default         public
#com2sec readwrite default         private

#       sec.name  source          community
#com2sec paranoid  default         public
com2sec readonly  127.0.0.1         public
#com2sec readwrite default         private

创建一个source为本机,名为public的只读通信

重启snmpd
/etc/init.d/snmpd restart

3、检测snmpd是否工作并显示当前网络的interface

snmpwalk -v 1 -c public localhost 1.3.6.1.2.1.2.2.1.2

后面一串1.3.6.1.2.1.2.2.1.2为snmp通信的oid,意为ifDescr

如我的interface描述输出

IF-MIB::ifDescr.1 = STRING: lo
IF-MIB::ifDescr.3 = STRING: venet0

有2个可监控的interface,1为localhost,3为virtual net

4、编写mrtg.cfg
虽说可以mrtg.cfg由cfgmaker生成,但手写mrtg.cfg可以更好的理解mrtg
理论上mrtg.cfg可以在任何位置,这里为/etc/mrtg.cfg,因为debian在/etc/cron.d/mrtg已为mrtg添加了周期为5分钟的cron

#工作目录,也就是mrtg生成的图表等在的目录
WorkDir: /var/www/mrtg

#通用配置
#Title前缀
Title[^]: Traffic Analysis for
#以bit为单位,图表内的数据居右显示
Options[_]: bits, growright

#标题
Title[wan]: wan
#最大字节,比如10Mbps,那么MaxBytes为 10/8=1.25M=1250000
MaxBytes[wan]: 1250000
#监控目标 interface 3
Target[wan]: 3:public@127.0.0.1

5、更新mrtg数据
env LANG=C mrtg /etc/mrtg.cfg
生成的网页在/var/www/mrtg。通过对http访问该目录即可。

6、添加至crontab
若/etc/cron.d 中无mrtg那么可通过crontab -e添加一个cron
*/5 * * * env LANG=C /usr/bin/mrtg /etc/mrtg.cfg 2>&1 | tee -a /var/log/mrtg/mrtg.log

7、相关链接
mrtg配置文档
snmp oid描述

分类: ubuntu/debian, 系统管理 标签:

linux命令行下的ctrl+r

2010年4月16日 6 条评论

linux命令行的history是一个熟知但不常用的命令,原因是要查某个命令的编号需要输入 history|grep xxx ,又因为!?xxx,!xxx 属于运行即执行也不方便,ctrl+r则方便多了。

ctrl+r
用途:反向搜索执行过的命令。(reverse-i-search)

若对于现有history
611 ruby foo.rb
612 ruby bar.rb
613 ruby fo.rb
614 ruby ba.rb
615 …

700 …

在不知道序号的情况下,若要运行ruby foo.rb。
1、ctrl+r
2、foo

1、ctrl+r
2、fo
3、ctrl+r (继续反向搜索)
只需要寥寥几键。当然若仅是上几个命令还是[上]键更有效率。

分类: ubuntu/debian, 系统管理 标签:

使用256色的debian终端

2009年4月8日 没有评论

  putty ssh连debian,都只有8色,看到putty有xterm 256色选项,告诉我debian因该有可以支持256的方法。

#tput colors

1、安装ncurse-term
apt-get install ncurses-term

2、更改环境TERM
export TERM=xterm-256color

# tput colors
256

修改putty window->colours->Allow terminal to use 256-color mode.
 成功!

分类: 系统管理 标签:

有惊无险,linux ext3文件夹误删恢复

2009年2月13日 2 条评论

就在1小时前,不小心删除了linux的一个文件夹,里面有5个php文件。网上google下。

Q: How can I recover (undelete) deleted files from my ext3 partition?

Actually, you can’t! This is what one of the developers, Andreas Dilger, said about it:In order to ensure that ext3 can safely resume an unlink after a crash, it actually zeros out the block pointers in the inode, whereas
ext2 just marks these blocks as unused in the block bitmaps and marks the inode as “deleted” and leaves the block pointers alone.

Your only hope is to “grep” for parts of your files that have been deleted and hope for the best. (出自 http://batleth.sapienti-sat.org/projects/FAQs/ext3-faq.html )

开发人员都这么说了,一时找不到北。突然灵感一现,若我直接从硬盘中搜索再复制,文件不多只有5个,且都是文本文件,可能有用。我立刻从网上下了个winhex,winhex是我用到现在最好的hex文件编辑器,看了看那个硬盘文件debian.vdi,不大只有3.9G。

我想,这几个文件都是这两天新建的,那么逆向搜索应该更有效。于是回忆每个文件中的几个函数名function xxx( 逆向搜,发现了不少残本。也不管新旧,都复制过来。就这么不一会,5个文件都原原本本的找了回来。

真是有惊无险。

分类: 系统管理 标签:

经测试VirtualBox比VMware慢20%

2009年1月29日 5 条评论

一模一样的Debian环境与配置Rails production hello world controller测试结果为
VMware: 169 reqs /s
VirtualBox: 140 reqs /s
VirtualBox比VMware慢20%
VirtualBox开启VT-x/AMD-V后,性能提升为 163 reqs /s,但不清楚会不会对稳定性有影响,先不开用一段时间,确认非常稳定后再尝试开启吧。
但VirtualBox比我的VMware冒似稳定很多,至少没有VMware的时间不稳定问题。
测试用,这速度足够了,稳定大于一切嘛。

—2009-02-10 补充—
VirtualBox非常稳定 ,到目前为止没出现过一次问题。
但尝试开启VT-x/AMD-V系统进不去,不过现在的状态足矣。

分类: 系统管理 标签:

开始用VirtualBox了

2009年1月29日 2 条评论

最近VMWARE变得不稳定,莫名的失去响应,拌随的症状是时钟走得飞快。不得其解,于是打算试试其它的虚拟机。

在wikipedia上面对琳琅满目的虚拟机,最后计划的替代产品为Virtual PC与Virtual Box,一个是Microsoft出的,一个是Sun出的,都是小母牛到北极的公司(牛X到极点)

先试了Virtual PC,不清楚咋搞的,连debian的mini.iso的安装画面都进不去。于是又下了Virtual Box,Sun果然牛,Virtual Box设计也很人性化,功能看似也很强大。现在正在通过网络安装debian,没有任何问题。希望在未来的使用过程中也能让用户满意,让群众放心。

分类: 系统管理 标签:

web服务器由apache2转向nginx

2008年12月24日 没有评论

打算抛弃一起走过数年的apache2,选择更快的服务器,在lighttpd和nginx中犹豫了满久,两者速度不分伯仲,最终还是选择了单词比较短的nginx,- -很离谱的选择方式。

nginx静态文件比apache2快很多,但fastcgi比不上apache2内置模块快。因为多了个反向代理过程,现在可能看不出优势,但日后一定会感觉到,因为很容易实现负载均衡。 :)

分类: 系统管理 标签:

使用Rsync备份数据

2008年12月14日 没有评论
  经历了硬盘数据全没了的痛苦,痛定思痛,作好每日或更短时间的备份功作犹为重要,真正做到有备无患。

  1. 准备:
    • 系统环境:Debian 4.0 (其它linux大同小异)
    • 需要权限:root
  2. 安装:
    apt-get install rsync
  3. 配置服务端:
    • 建立配置文件:/etc/rsyncd.conf
      Debian4下rsyncd.conf不直接提供,那就新建一个

      vi /etc/rsyncd.conf

      输入

      uid = nobody
      gid = nogroup
      use chroot = no
      max connections = 4
      pid file = /var/run/rsync.pid
      lock file = /var/run/rsync.lock
      log file=/var/log/rsync.log
      
      #备份的模块名
      [website]
      path = /var/www
      comment = backup
      ignore errors
      read only = true
      list = false
      #备份用户名
      auth users = test
      #帐号密码文件
      secrets file = /etc/rsyncd.secrets
    • 建立帐号文件/etc/rsyncd.secrets
      vi /etc/rsyncd.secrets

      输入

      #用户名:密码
      test:test
    • 更改rsyncd.secrets的权限为只读
      chmod 0400 /etc/rsyncd.secrets
    • 配置inetd
      vi /etc/inetd.conf

      添加

      rsync stream tcp nowait root /usr/bin/rsync rsync --daemon
    • 重启inetd
      /etc/init.d/openbsd-inetd restart
  4. 配置客户端
    • 建立密码文件password
      echo 'test'>password
    • 同步数据
      rsync -vzrtopg --progress --password-file=password test@服务器IP::website /var/www

      同步服务器IP的website到目录/var/www
      -v –verbose #输出调试信息
      -z –compress #压缩数据
      -r –recursive #递归目录,通俗讲就是包括所有子目录
      -t –times #保持时间
      -o –owner #保持所有者
      -p –permission #保持permission
      -g –group #保持组

分类: 系统管理 标签: ,