2009年11月9日星期一

Howto configure sendmail in HP-UX

Howto configure sendmail in HP-UX


* Purpose

Configure sendmail to let mailx deliver outside

* Operation Steps

o 1 sendmail.cf

vi /etc/mail/sendmail.cf

#Dj $w.Foo.COM

>> Dj $w.ebis.com


o 2 nsswitch

vi /etc/nsswitch.conf

hosts:files

o 3 hosts

vi /etc/hosts

192.168.0.33 hwccl.com

o 4 testing

/sbin/init.d/sendmail stop

/sbin/init.d/sendmail start

mailx meansonw@hwccl.com

test

server

.

EOT

2009年8月13日星期四

用JAD反编译并正确显示中文

用JAD反编译并正确显示中文
2008年05月09日 星期五 13:12

http://www.kpdus.com/jad.html   官方最新版本,支持jdk1.6

一、基本用法
Usage:jad [option(s)]
直接输入类文件名,且支持通配符,如下所示。
c:\Java\>jad example1.class
c:\Java\>jad *.class
结果是将example1.class反编译为example1.jad。将example1.jad改为example1.Java即得源文件。

二、Option -o
不提示,覆盖源文件

三、Option -s
c:\Java\>jad -sJava example1.class
反编译结果以.Java为扩展名。

四、Option -p
将反编译结果输出到屏幕
c:\Java\>jad -p example1.class
将反编译结果重定向到文件
c:\Java\>jad -p example1.class>example1.Java

五、Option -d
指定反编译的输出文件目录
c:\Java\>jad -o -dtest -sJava *.class

如:jad -sjava d.class 就是把当前目录的d.class编译成d.java

再用:native2ascii -reverse d.java d2.java   把d.java中的汉字转换成能直接看懂的汉字(d2.java)

2009年7月17日星期五

LINUX:ARCHLINUX How to downgrade wicd

    Today after I upgrade my wicd to 1.6.2 ,everything is ok but wifi just can scan wireless router around me and cann't connect it.

    Keep working on it for hours ,I give up the upgrading , Here are the way howto downgrade it to 1.5.9 .

    1. Get wicd-1.5.9-1-i686.pkg.tar.gz  from here

       http://archlinux.alouche.net/?pkgName=wicd&submit=Search+Packages

       $cd /var/cache/pacman/pkg/
       $sudo wget http://archlinux.alouche.net/repo/extra/os/i686/wicd-1.5.9-1-i686.pkg.tar.gz

    2.Remove wicd

    sudo pacman -R wicd
    sudo mv /etc/wicd /etc/wicd.bak
    sudo mv /var/log/wicd /var/log/wicd.bak

    3.Reinstall wicd
   
    sudo pacman -U wicd-1.5.9-1-i686.pkg.tar.gz

    4.Restart service

    sudo /etc/rc.d/dbus restart
    sudo /etc/rc.d/wicd restart
   
    5. Not try to open wicd-client and connect your wireless router

    wicd-client

2009年7月16日星期四

UNIX:HP-UX 压缩备份与解压

压缩:
tar cvf - /u02/datafile/  |gzip > /u03/test.tar.gz


解压缩:
gzip -dc /u03/test.tar.gz | tar �xvf -

2009年7月10日星期五

LINUX:X How to Connect HP-UX CDE with archlinux

Purpose :
In Archlinux 's PC,use X to connect HP-UX 's CDE windows.
Machine :
HP server :
ip:192.168.0.17
hostname:rp5470
os: hp-ux 11.23
Archlinux : 191.268.0.16


1. Log in on the HP-UX machine with root.

2. Copy /usr/dt/config/Xsetup to /etc/dt/config (if it doesn't already exist

3. Edit /etc/dt/config/Xsetup and add the following line at the end of
the file:
$XDIR/xset fp+ tcp/192.168.0.17:7000

4. Edit /etc/rc.config.d/xfs and set RUN_X_FONT_SERVER to 1.

5. Restart the font server
# /sbin/init.d/xfs stop
# /sbin/init.d/xfs start

6. Check with the following command that xfs is running:
# ps -ef | grep xfs

7. Login Archlinux
KDE -> Leave -> Switch User -> New Session
Menu -> Remote Login
Choose rp5470

Source Link:
http://forums11.itrc.hp.com/service/forums/questionanswer.do?admit=109447626+1247205414403+28353475&threadId=74012

2009年7月6日星期一

HP-UX:FIND 查找包含指定字符串的文件名

find ./ -type f -print |xargs grep -l "erp001"


2009年7月2日星期四

游记:交通 韶关 清远

出差到韶关两天,再直奔清远,虽是短途,却也颇多曲折.

广州去韶关很方便,10:28分的火车,不到中午1点就到韶关了,据说汽车要三个小时,
还贵许多.

而去清远的火车最后一班在13:30,火车站离清远有三,四十公里.

而韶关城小,汽车站倒有两个,东站在火车站旁,到广州深圳等地方,而城际列车在西
站,去清远在西站,65大元,车子不错,最晚一班车在18:00,车程2 小时45分,到清远
新车站.

由于当地同事的误导,最终我悠悠闲闲打的到了汽车东站,再急急忙忙打摩的汽车西
站,最终晃晃悠悠到了清远.还好一切顺利.

2009年5月26日星期二

UNIX:HP-UX fuser 的用法

查看占用目录的用户和进程

fuser -cu /home

终止占用目录的用户和进程

fuser -ku /home

2009年5月25日星期一

LINUX:ARCHLINUX 时间同步

sudo pacman -S ntp

nptdate stdtime.gov.hk

此时时间已经是最准的了。如果要自动定时

sudo crontab -e root
把这行加到最后。

0 13 * * 1-5 ntpdate stdtime.gov.hk

LINUX:ARCHLINUX Virtualbox 如何用 host interface


从VirtualBox 2.1.0 开始支持直接从客户机来实现Host interface功能。只需要在rc.conf中 的MODULES中加入 vboxnetflt 之后在你虚拟机设置中选择Host Interface Networking

测试方法:

modprobe vboxnetflt

设置->网络-》连接方式 : Host Interface

启动虚拟机


如果OK,在/etc/rc.conf 中加入 vboxnetflt 模块,重启计算机即可。

2009年5月18日星期一

LINUX:ARCHLINUX How to access mysql remotely

如何开启mysql 的侦听允许远程访问?



1.请在/etc/hosts.allow 添加以下行:

mysqld : ALL : ALLOW mysqld-max : ALL : ALLOW   2.需要编辑/etc/my.cnfskip-networking注释掉:  #skip-networking     You can get the "error no. 2013: Lost Connection to mysql server during query" message instantly whenever you try to connect to the MySQL daemon by TCP/IP. This is the TCP wrappers system (tcpd), which uses the hosts_access(5) system to allow or disallow connections.   # Don't listen on a TCP/IP port at all. This can be a security enhancement, # if all processes that need to connect to mysqld run on the same host.     # All interaction with mysqld must be made via Unix sockets or named pipes. # Note that using this option without enabling named pipes on Windows       # (via the "enable-named-pipe" option) will render mysqld useless!     

2009年4月12日星期日

LINUX:ARCHLINUX java 界面乱码

Java:

java -version
java version "1.6.0_0"
OpenJDK Runtime Environment (IcedTea6 1.5pre) (ArchLinux-1.5-0.1-i686)
OpenJDK Server VM (build 14.0-b10, mixed mode)


solution:


cd /usr/lib/jvm/java-1.6.0-openjdk/jre/lib/fonts
sudo mkdir fallback
cd fallback
sudo cp /usr/share/fonts/truetype/arphic/uming.ttc
/usr/lib/jvm/java-6-sun-1.6.0.10/jre/lib/fonts/fallback
sudo mkfontdir
sudo mkfontscale

2009年4月5日星期日

ISSUE:HP-UX vgdisplay error: Couldn't query volume group "vg00"

Issue:

# vgdisplay -v /dev/vg00
vgdisplay: Couldn't query volume group "/dev/vg00".
Possible error in the Volume Group minor number; Please check and make
sure the group minor number is unique.
vgdisplay: Cannot display volume group "/dev/vg00".

Debug:


# ll /dev/*/group
crw-r----- 1 root sys 64 0x000000 Sep 27 2006 /dev/vg00/group
cr--r--r-- 1 root sys 64 0x010000 Oct 11 2006 /dev/vg01/group
crw-r--r-- 1 root sys 64 0x020000 Mar 4 11:00 /dev/vg02/group
# ll /dev/slvmg
/dev/slvmg not found
# cd /dev
# find . -exec ll {} \; | grep 0x000000 | grep 64
crw-r----- 1 root sys 64 0x000000 Sep 27 2006 group
crw-r----- 1 root sys 64 0x000000 Sep 27 2006 ./vg00/group

Fixed:
# mv /etc/lvmtab /etc/lvmtab.save
# vgscan -v
# vgchange -a y vg00
# vgdisplay vg00

Relink Doc:
http://forums11.itrc.hp.com/service/forums/questionanswer.do?threadId=248847
key words:ULVMKBRC00008020

2009年4月4日星期六

电信商务领航定制终端 大亚 DB120-B1 配置方法

公司装宽带,电信送了个无线路由加猫的东东,叫电信商务领航定制终端,型号是大亚 DB120-B1 。
公司的技术员说无法自动拨号上网,所以没用。那好,我就看看,电信这会是黄鼠狼还是喜羊羊。

回家,接上自己家的ADSL,开始操作。

按说明书,一步一步的做

1.设置自己PC的IP为  192.168.1.2

2.用配的交叉线连路由的LAN1

3.输入   http://192.168.1.1  
(如果不行,试试https://192.168.1.1)
username :   telecomadmin
password:     nE7jA%5m

4.网络-宽带设置

连接名称: 新建一个连接
连接模式:Route
             选       pppoE
NAT : YES
VPI:8
VCI:35
服务类别:UBR WITHOUT PCR
启用VLAN: NO
VLAN ID:
封装:LLC/SNAP-BRIDGING
用户名:电信账户
密码:电信密码
服务名称:CHINATELLECOM
启用802.1优先级:YES
端口绑定:仅INTERNET
                端口全选


然后设置WLAN和DHCP,这些不详说,

设置后,一定要到  管理-设备管理-保存/重启  ,设置才会生效。


重启后,看看 状态-网络侧信息

如果出现 

8/35 Off PPPoE Up 219.137.210.254
这行,恭喜,成功了!

没有出现?也不用灰心,因为你和笔者不在同一个城市,GOOGLE一下你城市的VPI和VCI吧。我的技术员也就是填错了这里。


2009年4月2日星期四

LINUX:CENTOS How to modify Ip address

[oracle@server-centos01 ~]$ cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=server-centos01
GATEWAY=192.168.0.3

[oracle@server-centos01 ~]$ cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=dhcp
HWADDR=00:22:19:B0:9D:E6
ONBOOT=no
TYPE=Ethernet
DHCP_HOSTNAME=server-centos01
[oracle@server-centos01 ~]$ cat /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
BOOTPROTO=static
BROADCAST=192.168.0.255
HWADDR=00:22:19:B0:9D:E8
IPADDR=192.168.0.22
NETMASK=255.255.255.0
NETWORK=192.168.0.0
ONBOOT=yes
TYPE=Ethernet

LINUX:CENTOS How to setup openvnc

It is very simple to config openvnc to work.

Step 1:

login with your account like myname
run vncserver
input your password

Step 2:

vi ~/.vnc/xstartup

remove with # mark

#xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
#twm &

add this line to enable use gnome to show x window in vnc client
gnome-session &


Step3:

vi /etc/sysconfig/vncservers

add these lines,notice that [youname] is your account name


VNCSERVERARGS[1]="-geometry 1024x768"
VNCSERVERS="1:youname"


Step 4:start service

sudo /sbin/service vncserver restart

Step 5:login with browser

in client PC,open your brower with

http://vnc-server-ip:5801/

2009年3月25日星期三

Linux:Centos 如何释放内存


     当在Linux下频繁存取文件后,物理内存会很快被用光,当程序结束后,内存不会被正常释放,而是一直作为caching。因此,在系统备份(tar) 后,用top看的时候内存使用会吓你一大跳,用光了?

    先用 free -m 看看系统内存情况:

[oracle@server-centos01 ~]$ free -m
             total       used       free     shared    buffers     cached
Mem:          4047       4012         35          0         68       2509
-/+ buffers/cache:       1434       2613                                
Swap:         1906          0       1906


    其他的先别管,留意  

-/+ buffers/cache:       1434       2613        

    2613才是真正可用的内存,而不是total - used =free。

    那么,有没有办法释放这些内存呢,答案是有的。先看看以下的介绍:

/proc/sys/vm/drop_caches (since Linux 2.6.16)
Writing to this file causes the kernel to drop clean caches,
dentries and inodes from memory, causing that memory to become
free.

To free pagecache, use echo 1 > /proc/sys/vm/drop_caches; to
free dentries and inodes, use echo 2 > /proc/sys/vm/drop_caches;
to free pagecache, dentries and inodes, use echo 3 >
/proc/sys/vm/drop_caches.

Because this is a non-destructive operation and dirty objects
are not freeable, the user should run sync first.


    释放的方法:
   
    1.    sync
    2.    echo 3 >/proc/sys/vm/drop_caches


    再用 free -m 去看:

[root@server-centos01 ~]# free -m                     
             total       used       free     shared    buffers     cached
Mem:          4047       1652       2394          0          0        234
-/+ buffers/cache:       1417       2629                                
Swap:         1906          0       1906


    其实,如果不是用于调试,这类手工释放的方法建议还是不要去用。
   

2009年3月6日星期五

xorg.conf for Archlinux KDE 4.2.1 in HP Compaq nx7400

xorg.conf for Archlinux KDE 4.2.1 in HP Compaq nx7400

# /.../
# SaX generated X11 config file
# Created on: 2008-08-19T16:21:40+0800.
#
# Version: 8.1
# Contact: Marcus Schaefer <sax@suse.de>, 2005
# Contact: SaX-User list
<https://lists.berlios.de/mailman/listinfo/sax-users>
#
# Automatically generated by [ISaX] (8.1)
# PLEASE DO NOT EDIT THIS FILE!
#

Section "Files"
# FontPath "/usr/share/fonts/misc:unscaled"
FontPath "/usr/share/fonts/local"
FontPath "/usr/share/fonts/75dpi:unscaled"
FontPath "/usr/share/fonts/100dpi:unscaled"
FontPath "/usr/share/fonts/URW"
FontPath "/usr/share/fonts/Speedo"
FontPath "/usr/share/fonts/PEX"
FontPath "/usr/share/fonts/cyrillic"
FontPath "/usr/share/fonts/latin2/misc:unscaled"
FontPath "/usr/share/fonts/latin2/75dpi:unscaled"
FontPath "/usr/share/fonts/latin2/100dpi:unscaled"
FontPath "/usr/share/fonts/latin2/Type1"
FontPath "/usr/share/fonts/latin7/75dpi:unscaled"
FontPath "/usr/share/fonts/baekmuk:unscaled"
FontPath "/usr/share/fonts/japanese:unscaled"
FontPath "/usr/share/fonts/kwintv"
FontPath "/usr/share/fonts/truetype"
FontPath "/usr/share/fonts/uni:unscaled"
FontPath "/usr/share/fonts/CID"
FontPath "/usr/share/fonts/ucs/misc:unscaled"
FontPath "/usr/share/fonts/ucs/75dpi:unscaled"
FontPath "/usr/share/fonts/ucs/100dpi:unscaled"
FontPath "/usr/share/fonts/hellas/misc:unscaled"
FontPath "/usr/share/fonts/hellas/75dpi:unscaled"
FontPath "/usr/share/fonts/hellas/100dpi:unscaled"
FontPath "/usr/share/fonts/hellas/Type1"
FontPath "/usr/share/fonts/misc/sgi:unscaled"
FontPath "/usr/share/fonts/xtest"
FontPath "/opt/kde3/share/fonts"
InputDevices "/dev/gpmdata"
InputDevices "/dev/input/mice"
EndSection

Section "ServerFlags"
Option "AIGLX" "on"
Option "AllowMouseOpenFail" "on"
Option "ZapWarning" "on"
EndSection

Section "Module"
Load "glx"
#Load "type1"
Load "extmod"
Load "dbe"
Load "freetype"
Load "dri"
Load "synaptics"
EndSection

Section "InputDevice"
Driver "kbd"
Identifier "Keyboard[0]"
#Option "Protocol" "Standard"
Option "XkbLayout" "us"
#Option "XkbModel" "microsoftpro"
Option "XkbModel" "pc104"
#Option "XkbRules" "xfree86"
EndSection


Section "InputDevice"
Driver "mouse"
Identifier "Mouse[1]"
Option "Buttons" "5"
Option "Device" "/dev/input/mice"
Option "Name" "Pixart Imaging USB OPTICAL MOUSE"
Option "Protocol" "explorerps/2"
Option "Vendor" "Sysp"
Option "ZAxisMapping" "4 5"
EndSection

Section "InputDevice"
Driver "synaptics"
Identifier "Mouse[3]"
Option "Buttons" "5"
Option "Device" "/dev/input/mice"
Option "Emulate3Buttons" "on"
Option "HorizScrollDelta" "0"
Option "InputFashion" "Mouse"
Option "Name" "Synaptics;Touchpad"
Option "Protocol" "explorerps/2"
Option "SHMConfig" "on"
Option "Vendor" "Sysp"
Option "ZAxisMapping" "4 5"
EndSection


Section "Monitor"
DisplaySize 305 230
HorizSync 30-82
Identifier "Monitor[0]"
ModelName "1280X1024@60HZ"
Option "DPMS"
#Option "PreferredMode" "1280x1024"
VendorName "--> LCD"
VertRefresh 50-60
UseModes "Modes[0]"
EndSection


Section "Modes"
Identifier "Modes[0]"
# 640x480 @ 60Hz (Industry standard) hsync: 31.5kHz
ModeLine "640x480" 25.2 640 656 752 800 480 490 492 525 -hsync -vsync
# # 640x480 @ 72Hz (VESA) hsync: 37.9kHz
ModeLine "640x480" 31.5 640 664 704 832 480 489 491 520 -hsync -vsync
# # 800x600 @ 56Hz (VESA) hsync: 35.2kHz
ModeLine "800x600" 36.0 800 824 896 1024 600 601 603 625 +hsync +vsync
# # 800x600 @ 60Hz (VESA) hsync: 37.9kHz
ModeLine "800x600" 40.0 800 840 968 1056 600 601 605 628 +hsync +vsync
# # 800x600 @ 72Hz (VESA) hsync: 48.1kHz
ModeLine "800x600" 50.0 800 856 976 1040 600 637 643 666 +hsync +vsync
# # 800x600 @ 75Hz (VESA) hsync: 46.9kHz
ModeLine "800x600" 49.5 800 816 896 1056 600 601 604 625 +hsync +vsync
# # 1024x768 @ 60Hz (VESA) hsync: 48.4kHz
ModeLine "1024x768" 65.0 1024 1048 1184 1344 768 771 777 806 -hsync -vsync
# # 1024x768 @ 70Hz (VESA) hsync: 56.5kHz
ModeLine "1024x768" 75.0 1024 1048 1184 1328 768 771 777 806 -hsync -vsync
# # 1024x768 @ 75Hz (VESA) hsync: 60.0kHz
ModeLine "1024x768" 78.8 1024 1040 1136 1312 768 769 772 800 +hsync +vsync
# # 1280x960 @ 60Hz (VESA) hsync: 60.0kHz
ModeLine "1280x960" 148.5 1280 1344 1504 1728 960 961 964 1011 +hsync
+vsync
# # 1280x1024 @ 60Hz (VESA) hsync: 64.0kHz
ModeLine "1280x1024" 108.0 1280 1328 1440 1688 1024 1025 1028 1066
+hsync +vsync
# # 1280x1024 @ 75Hz (VESA) hsync: 80.0kHz
ModeLine "1280x1024" 135.0 1280 1296 1440 1688 1024 1025 1028 1066
+hsync +vsync
# # 1600x1200 @ 60Hz (VESA) hsync: 75.0kHz
ModeLine "1600x1200" 162.0 1600 1664 1856 2160 1200 1201 1204 1250
+hsync +vsync
# # 1600x1200 @ 65Hz (VESA) hsync: 81.3kHz
ModeLine "1600x1200" 175.5 1600 1664 1856 2160 1200 1201 1204 1250
+hsync +vsync
# # 1600x1200 @ 70Hz (VESA) hsync: 87.5kHz
ModeLine "1600x1200" 189.0 1600 1664 1856 2160 1200 1201 1204 1250
+hsync +vsync
# # 1600x1200 @ 75Hz (VESA) hsync: 93.8kHz
ModeLine "1600x1200" 202.5 1600 1664 1856 2160 1200 1201 1204 1250
+hsync +vsync
EndSection


Section "Screen"
DefaultDepth 16
SubSection "Display"
Depth 15
Modes "1280x1024" "1280x960" "1280x800" "1152x864" "1280x768" "1280x720"
"1024x768" "1280x600" "1024x600" "800x600" "768x576" "640x480"
EndSubSection
SubSection "Display"
Depth 16
Modes "1280x1024" "1280x960" "1280x800" "1152x864" "1280x768" "1280x720"
"1024x768" "1280x600" "1024x600" "800x600" "768x576" "640x480"
EndSubSection
SubSection "Display"
Depth 24
Modes "1280x1024" "1280x960" "1280x800" "1152x864" "1280x768" "1280x720"
"1024x768" "1280x600" "1024x600" "800x600" "768x576" "640x480"
EndSubSection
SubSection "Display"
Depth 8
Modes "1280x1024" "1280x960" "1280x800" "1152x864" "1280x768" "1280x720"
"1024x768" "1280x600" "1024x600" "800x600" "768x576" "640x480"
EndSubSection
Device "Device[0]"
Identifier "Screen[0]"
Monitor "Monitor[0]"
EndSection


Section "Device"
BoardName "945 GM"
BusID "0:2:0"
Driver "intel"
Identifier "Device[0]"
Option "monitor-LVDS" "Monitor[0]"
Screen 0
VendorName "Intel"
#Option "AddARGBGLXVisuals" "True"
EndSection

Section "ServerLayout"
Identifier "Layout[all]"
InputDevice "Keyboard[0]" "CoreKeyboard"
InputDevice "Mouse[1]" "CorePointer"
InputDevice "Mouse[3]" "SendCoreEvents"
Option "Clone" "off"
Option "Xinerama" "off"
Screen "Screen[0]"
EndSection


Section "DRI"
Group "video"
Mode 0660
EndSection

Section "Extensions"
Option "Composite" "Enable"
EndSection

2009年2月11日星期三

LINUX:CENTOS:HOWTO 安装MRTG

主要资料来源:
http://www.sofee.cn/blog/2006/10/21/49/


OS:centos 4.7

1、安装SNMPD服务
# yum install net-snmp-utils
# vi /etc/snmp/snmpd.conf
把以下的内容注释掉:

# First, map the community name "public" into a "security name"  #       sec.name  source          community ##com2sec notConfigUser  default       public  #### # Second, map the security name into a group name:  #       groupName      securityModel securityName ##group   notConfigGroup v1           notConfigUser ##group   notConfigGroup v2c           notConfigUser  #### # Third, create a view for us to let the group have rights to:  # Make at least  snmpwalk -v 1 localhost -c public system fast again. #       name           incl/excl     subtree         mask(optional) ##view    systemview    included   .1.3.6.1.2.1.1 ##view    systemview    included   .1.3.6.1.2.1.25.1.1  #### # Finally, grant the group read-only access to the systemview view.  #       group          context sec.model sec.level prefix read   write  notif ##access  notConfigGroup ""      any       noauth    exact  systemview none none


然后增加以下内容:

############################################################## ## sec.name source community com2sec local   localhost       public com2sec lan     192.168.1.0/24  public  ## group.name sec.model sec.name group   MyRWGroup       v1      local group   MyRWGroup       v2c     local group   MyRWGroup       usm     local group   MyROGroup       v1      lan group   MyROGroup       v2c     lan group   MyROGroup       usm     lan  view all    included  .1                               80 #view mib2   included  .iso.org.dod.internet.mgmt.mib-2 fc  ## context sec.model sec.level prefix read write notif access MyROGroup ""      any       noauth    exact      all    none   none access MyRWGroup ""      any       noauth    exact      all    all    all rocommunity  public disk / 100000 disk /mnt/share 500000 ##############################################################

其中的disk配置是为了监控磁盘的使用量,用户可自行修改要监控的目录,这里监控的是系统目录/和数据目录/mnt/share。

完了之后就开启snmpd服务。
# chkconfig snmpd on
# /etc/init.d/snmpd start


2、安装MRTG
# yum install mrtg
默认安装下,已在/etc/cron.d/下生成一个mrtg任务,cron进程会根据据/etc/cron.d/mrtg 中指定的参数每5分钟执行一次,对统计数据的结果页面进行更新,所以要注意MRTG配置文件的保存位置。一般情况下,MRTG的流量统计页面是放在 /var/www/mrtg/下,配置文件保存在/etc/mrtg/mrtg.cfg。如果用户自行修改了保存位置,那么也请同时修改/etc /cron.d/mrtg文件中的路径。

2.1 测试生成MRTG配置文件
#/usr/bin/cfgmaker �global 'WorkDir: /var/www/mrtg' �output /etc/mrtg/mrtg.cfg public@127.0.0.1
如果出现一些错误,一般都是/etc/snmp/snmpd.conf文件配置错误引起,执行后会在/etc/mrtg/下生成一个mrtg.cfg配置 文件。
MRTG除了统计流量之外,还可以统计CPU、UPTIME、内存、磁盘使用量等等,而用cfgmaker生成的配置文件只包含网卡的流量统计,所以用户 可� �据自己的需求对/etc/mrtg/mrtg.cfg进行修改。可参考本文最后我的mrtg.cfg配置文件内容。

由于MRTG根据SNMP获取的UPTIME信息不符合规则,所以需要写个脚本来进行转换。
# vi /var/www/mrtg/mrtg-uptime.pl

sub convertUptime {         my $data = shift;         my $days = 0;         # 1 day, 1:42:50         if ( $data =~ /^(d+)sday/ ) {                 $days = $1;         }         return ("$days"); }


注:如果直接使用cfgmaker生成的配置文件的话,那么还需要执行indexmaker来生成统计页面。
/usr/bin/indexmaker -output=/var/www/mrtg/index.html -title="sofee.cn MRTG Graph" /etc/mrtg/mrtg.cfg

2.2 配置Apache

安装 apache
#yum install httpd

在CentOS中,Apache的配置部分是除了本机之外拒绝所有人访问的,所以还需要对Apache进行相应的配置,以使外网也能够对MRTG统 计页面进行访问。
# vi /etc/httpd/conf.d/mrtg.conf

Alias /mrtg /var/www/mrtg <Location /mrtg>     Order deny, allow     Allow from all #   Deny from all #   Allow from 127.0.0.1 #   Allow from ::1 #   Allow from .example.com </Location>

这里设置的是所有人都可以通过WEB访问/mrtg,用户可自行设置相应权限。
# /etc/init.d/httpd graceful

2.3 生成统计页面
# env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg
第1、2次执行一般都会有错误信息,执行第3次就好了。

至此,MRTG已基本设置完毕,可通过浏览器访问http://www.yourhost.com/mrtg来查看统计页面。

3、我的MRTG配置文件
/etc/mrtg/mrtg.cfg

######################################################################
# Multi Router Traffic Grapher -- Example Configuration File         
######################################################################
# This file is for use with mrtg-2.0                                 
#                                                                    
# Note:                                                              
#                                                                    
# * Keywords must start at the begin of a line.                      
#                                                                    
# * Lines which follow a keyword line which do start                 
#   with a blank are appended to the keyword line                    
#                                                                    
# * Empty Lines are ignored                                          
#                                                                    
# * Lines starting with a # sign are comments.                       

# Where should the logfiles, and webpages be created?

# Minimal mrtg.cfg
#--------------------

HtmlDir: /var/www/mrtg
ImageDir: /var/www/mrtg
LogDir: /var/lib/mrtg 
ThreshDir: /var/lib/mrtg
Target[r1]: 2:public@myrouter.somplace.edu
MaxBytes[r1]: 1250000                    
Title[r1]: Traffic Analysis              
PageTop[r1]: <h1>Stats for our Ethernet</h1>

#Language: GB2312
                
Interval:5      
                
Options[_]: nopercent,growright,noinfo,gauge
                                           
MaxBytes[_]: 125000000                     
                                           
Xsize[_]: 600                              
Ysize[_]: 200                              
Ytics[_]: 10                               
                                           
LoadMIBs: /usr/share/snmp/mibs/UCD-SNMP-MIB.txt,/usr/share/snmp/mibs/TCP-MIB.txt,/usr/share/snmp/mibs/HOST-RESOURCES-MIB.txt                                                                                 
ConversionCode: /var/www/mrtg/mrtg-uptime.pl                                                          
                                                                                                      
###############################################################################                       
#                                                                                                     
# HTML formatting stuff                                                                               
#                                                                                                     
###############################################################################                       
PageTop[^]: <table cellspacing="0" cellpadding="10" border="0" width="100%" align="center"><tr><td width="185" valign="top" class="small"><table cellspacing="0" cellpadding="5" border="0" width="100%"><tr><td class="tableh">Network</td></tr><tr><td class="tablesh"><a href="index.html">- Traffic</a><br><a href="newtcp.html">- New Connections</a><br><a href="estabtcp.html">- Established Connections</a></td></tr><tr><td>&nbsp;</td></tr><tr><td class="tableh">System Stats</td></tr><tr><td class="tablesh"><a href="load.html">- Load Averages</a><br><a href="swap.html">- Swap Memory</a><br><a href="processes.html">- Processes</a><br><a href="uptime.html">- Uptime</a><br><a href="cpu.html">- CPU</a><br><a href="memory.html">- Free Memory</a><br><a href="disk.html">- Disk Usage</a></td></tr><tr><td>&nbsp;</td></tr></table></td><td>                                                                                            
                                                                                                      
PageFoot[^]: </td></tr></table>                                                                       
                                                                                                      
AddHead[^]: <meta http-equiv='Expires' content='-1'><style><!-- body { text-align: center; background-color: #CCCCCC; font-size: 10pt; font-family: arial, verdana; } th, td { font-size: 10pt; font-family: arial, verdana; } h3 { font-size: 12pt; font-family: arial, verdana; font-weight: bold; } .small { font-size: 8pt; font-family: arial, verdana; } .tableh { font-size: 10pt; font-family: arial, verdana; color: white; background-color: black; font-weight: bold; } .tablesh { font-size: 10pt; font-family: arial, verdana; color: black; background-color: #999999; font-weight: normal; } a:visited, a:active, a:link { text-decoration: none; font-weight: normal; font-family: arial, verdana; color: black; } a:hover { font-weight: normal; font-family: arial, verdana; background-color: #999999; color: white; } --></style>  
                                                                                                      
######################################################################                                
# System: www.sofee.cn                                                                                
# Description: Linux www.sofee.cn 2.6.9-42.ELsmp #1 SMP Tue Aug 15 10:35:26 BST 2006 x86_64           
# Contact: Root <root@localhost> (configure /etc/snmp/snmp.local.conf)                                
# Location: Unknown (edit /etc/snmp/snmpd.conf)                                                       
######################################################################                                
#                                                                                                     
# Traffic Monitoring                                                                                  
#                                                                                                     
Target[index]: 2:public@127.0.0.1:                                                                    
SetEnv[index]: MRTG_INT_IP="192.168.0.22" MRTG_INT_DESCR="eth0"                                       
Options[index]: nopercent,growright, noinfo, bits                                                     
Title[index]: Traffic Analysis for eth0                                                               
PageTop[index]: <h1>Traffic Analysis for eth0</h1>                                                    
PNGTitle[index]: Traffic Analysis for eth0                                                            
kilo[index]: 1024                                                                                     
                                                                                                      
#                                                                                                     
# CPU Monitoring                                                                                      
#                                                                                                     
Target[cpu]:ssCpuRawUser.0&ssCpuRawUser.0:public@localhost + ssCpuRawSystem.0&ssCpuRawSystem.0:public@localhost + ssCpuRawNice.0&ssCpuRawNice.0:public@localhost                                             
Title[cpu]: CPU Load                                                                                  
PageTop[cpu]: <h1>Active CPU Load %</h1>                                                              
PNGTitle[cpu]: CPU Load - System, User and Nice Processes                                             
RouterUptime[cpu]: public@localhost                                                                   
MaxBytes[cpu]: 100                                                                                    
Unscaled[cpu]: ymwd                                                                                   
ShortLegend[cpu]: %                                                                                   
YLegend[cpu]: CPU Utilization                                                                         
Legend1[cpu]: Active CPU in % (Load)                                                                  
Legend2[cpu]:                                                                                         
Legend3[cpu]:                                                                                         
Legend4[cpu]:                                                                                         
LegendI[cpu]:  Active                                                                                 
LegendO[cpu]:                                                                                         
Options[cpu]: growright,nopercent                                                                     
                                                                                                      
#                                                                                                     
# Memory Monitoring                                                                                   
#                                                                                                     
Target[memory]: memAvailReal.0&memTotalReal.0:public@localhost                                        
Title[memory]: Free Memory                                                                            
PageTop[memory]: <h1>Free Memory</h1>                                                                 
PNGTitle[memory]: Free Memory                                                                         
MaxBytes[memory]: 100000000000                                                                        
ShortLegend[memory]: B                                                                                
YLegend[memory]: Bytes                                                                                
LegendI[memory]: Free                                                                                 
LegendO[memory]: Total                                                                                
Legend1[memory]: Free memory, not including swap, in bytes                                            
Legend2[memory]: Total memory                                                                         
Options[memory]: gauge,growright,nopercent,noinfo                                                     
kMG[memory]: k,M,G,T,P,X                                                                              
                                                                                                      
#                                                                                                     
# Swap Monitoring                                                                                     
#                                                                                                     
Target[swap]: memAvailSwap.0&memAvailSwap.0:public@localhost                                          
Title[swap]: Swap Memory                                                                              
PageTop[swap]: <h1>Swap Memory</h1>                                                                   
PNGTitle[swap]: Available Swap                                                                        
Options[swap]: nopercent,growright,gauge,noinfo                                                       
MaxBytes[swap]: 1000000                                                                               
kMG[swap]: k,M,G,T,P,X                                                                                
YLegend[swap]: bytes                                                                                  
ShortLegend[swap]: bytes                                                                              
LegendI[swap]:  Free Memory:                                                                          
LegendO[swap]:                                                                                        
Legend1[swap]: Swap memory avail, in bytes                                                            
                                                                                                      
#                                                                                                     
# New TCP Connection Monitoring (per minute)                                                          
#                                                                                                     
Target[newtcp]: tcpPassiveOpens.0&tcpActiveOpens.0:public@localhost                                   
Title[newtcp]: Newly Created TCP Connections                                                          
PageTop[newtcp]: <h1>New TCP Connections</h1>                                                         
PNGTitle[newtcp]: Newly Created Inbound&Outbound TCP Connections                                      
MaxBytes[newtcp]: 10000000000                                                                         
ShortLegend[newtcp]: c/s                                                                              
YLegend[newtcp]: Conns / Min                                                                          
LegendI[newtcp]: In                                                                                   
LegendO[newtcp]: Out                                                                                  
Legend1[newtcp]: New inbound connections                                                              
Legend2[newtcp]: New outbound connections                                                             
Options[newtcp]: growright,nopercent,perminute                                                        
                                                                                                      
#                                                                                                     
# Established TCP Connections                                                                         
#                                                                                                     
Target[estabtcp]: tcpCurrEstab.0&tcpCurrEstab.0:public@localhost                                      
Title[estabtcp]: Currently Established TCP Connections                                                
PageTop[estabtcp]: <h1>Established TCP Connections</h1>                                               
PNGTitle[estabtcp]: Established TCP Connections                                                       
MaxBytes[estabtcp]: 10000000000                                                                       
ShortLegend[estabtcp]:                                                                                
YLegend[estabtcp]: Connections                                                                        
LegendI[estabtcp]: No. of Connections                                                                 
LegendO[estabtcp]:                                                                                    
Legend1[estabtcp]: Established connections                                                            
Legend2[estabtcp]:                                                                                    
Options[estabtcp]: growright,nopercent,gauge                                                          
                                                                                                      
#                                                                                                     
# Disk Usage Monitoring                                                                               
#                                                                                                     
# add disk entry to snmpd.conf                                                                        
# disk / 100000                                                                                       
# disk /mnt/data 500000                                                                               
Target[disk]: dskPercent.1&dskPercent.2:public@localhost                                              
Title[disk]: Disk Partition Usage                                                                     
PageTop[disk]: <h1>Disk Partition Usage / and /uappl</h1>                                             
PNGTitle[disk]: Disk Usage on / and /uappl                                                            
MaxBytes[disk]: 100                                                                                   
ShortLegend[disk]: %                                                                                  
YLegend[disk]: Utilization                                                                            
LegendI[disk]: /                                                                                      
LegendO[disk]: /uappl                                                                                 
Options[disk]: gauge,growright,nopercent                                                              
Unscaled[disk]: ymwd                                                                                  
                                                                                                      
#                                                                                                     
# Load Averages Monitoring                                                                            
#                                                                                                     
Target[load]: laLoadInt.1&laLoadInt.3:public@localhost                                                
Title[load]: Load Averages                                                                            
PageTop[load]: <h1>Load Averages</h1>                                                                 
PNGTitle[load]: Load Averages                                                                         
Options[load]: growright, gauge, nopercent, noinfo                                                    
MaxBytes[load]: 3000                                                                                  
YLegend[load]: Load (10E-2)                                                                           
ShortLegend[load]: (10E-2)                                                                            
LegendI[load]: 1-minute stagger                                                                       
LegendO[load]: 15-mintute stagger                                                                     
Legend1[load]: Load Average over last 1 minutes                                                       
Legend2[load]: Load Average over last 15 minutes                                                      
Legend3[load]: Average over last 1 minutes                                                            
Legend4[load]: Average over last 15 minutes                                                           
                                                                                                      
#                                                                                                     
# Processes Monitoring                                                                                
#                                                                                                     
Target[processes]: hrSystemProcesses.0&hrSystemProcesses.0:public@localhost                           
Title[processes]: Processes                                                                           
PageTop[processes]: <h1>Processes</h1>                                                                
PNGTitle[processes]: Processes                                                                        
Options[processes]: gauge,nopercent,growright
MaxBytes[processes]: 1000
YLegend[processes]: Processes
ShortLegend[processes]:
LegendI[processes]: Total
LegendO[processes]: Running

#
# Uptime Monitoring
#
Target[uptime]: hrSystemUptime.0&hrSystemUptime.0:public@localhost|convertUptime
Title[uptime]: System Uptime In Days
PageTop[uptime]: <h1>System Uptime Report</h1>
PNGTitle[uptime]: System Uptime
MaxBytes[uptime]: 100
ShortLegend[uptime]: Days
YLegend[uptime]: No. of Days
LegendI[uptime]: Uptime:
LegendO[uptime]:
Legend1[uptime]: Uptime in Days
Options[uptime]: gauge,growright,nopercent,noo