??xml version="1.0" encoding="utf-8" standalone="yes"?> 让我们用一个简单的例子看一下这些东西, 下面q两个例子行来自我们?inittab文g: 在Red Hatpȝ中这很典型。一旦init被启?Q读?etc/inittab ?从第一行,我们知道 init
在pȝ启动后从q行q行U?。一旦我们到了那个运行 Q第二行告诉 init 去运行脚?/etc/rc.d/rc 3 q且在执行前{待l止?/p> ?etc/rc.d目录的rc 脚本收到 3作ؓ一个参数?q个 3 相当于运行3。结?rc
脚本执行/etc/rc.d/rc3.d目录中的所有脚本。它首先用参数``stop''执行所有K(代表
``kill''杀掉进E或者服?打头的脚本,接下来,它运行所有以 字母 S 打头的脚本,带有参数``start'' 启动q程或者服务?
最后要指明QK和S脚本的执行顺序是Z排序? 名ؓ S90mysql的脚本将?S95httpd之前执行?/p> /etc/rc.d/rc3.d
中的脚本实际是对/etc/rc.d/init.d中文件的W号q接。UNIX理员可以在rc3.d中放制文Ӟ 实际情况下Red
Hat的init.d目录是所有脚本的W一位置Q然后生成逻辑q接?rc*.d 目录。手工作q些文g的管理很烦h、琐?
chkconfig现在接手qg事情! Red Hat 的这个chkconfig工具是专ؓ理
/etc/rc.d/rc[0-6].d中的W号q接而设计?/p>
语法为: 输出的部分内容大致如? 调整chkconfig?几乎和列出现在的设|一样容易。格? chkconfig [--level <q行U?gt;] <名字> 例如Q如果我们决定在q行U?2止crondQ?/p> (root执行) 会在q行U?xcrond. q行 chkconfig --list会确信crond的配|已l被调整?更进一步,下面的find 命ocommand 昄一?kill脚本已经在目录rc2.d中代替了 start脚本: chkconfig --levels 2345 crond on 有的时候,
删掉一个服务也很恰当。例如,针对sendmailQ在客户Z导入本地账号的邮件没有必要。运行sendmail最为守护进E就不是必要的了。这U情
况,我发现禁止sendmail服务很有必要Q减了潜在的安全问题,从chkconfig中删掉sendmailQ输? 在下面,我们?find命o昄该处没有W号q接?Q不qsendmail的init脚本仍然? d一个chkconfig ?/strong> 到目前ؓ止,一切顺利。我们已l知道用chkconfig如何查看、调整、删掉服务。现在添加一个新的服务。看下面的脚?oracle (see Listing 1). 使用q个脚本Q?Oracle 8可以以参?``start''启动Q以 ``stop'' 参数停止。它W合init脚本的最要求可以和 /etc/rc.d/rc脚本联合使用?/p> 把脚本放?/etc/rc.d/init.d中ƈq行 (?root) : 使你的脚本可执行 。如果你担心普通用户察看这个脚本,你可以设定更严格的文件权?。只要这个脚本可以被root作ؓ单独的脚本运行就可以?/p> 注意脚本中的两行注释: chkconfig需要这些行来决定如何实现初始运行d服务Q如何设定启动和停止序的优先 ?q些行指明脚本将行2Q?Q?Q?启动 Oracle 8 服务。另外, 启动优先权将被设定ؓ 80而停止优先权讑֮?05?/p> 现在脚本在合适的位置Qƈ且有合适的执行权限Q以及恰当的chkconfig注释Q?我们可以dinit脚本Q作?rootQ
?chkconfig的查询,我们能核实我们所作的d: 而且Q我们可以用标准?find 命o察看chkconfig如何讑֮W号q接: 大家可能都知道了Qinetd?Red Hat 7中已l被xinetd 所取代。而且Qchkconfig 的功能已l被扩展Q可以管理一些xinetd的Internet服务。例子如? 很简捷啊Q呵c可是,q里有个问题。当配置已经改变Q命?etc/init.d/xinetd reload指明xinetd
自动重蝲入新的配|,?chkconfig执行。这个脚本运行一个带有SIGUSR2信号的kill 指示 xinetd q行一个“硬“重配置?/p> 那意味着什?哦,当我试的时候,通过xinetd 提供的活动服?i.e., Telnet, FTP,
etc.)立刻被中止。如果你能计划在最合适的旉启动/止你的pȝ上的服务Q可能不是个问题。作ZU替代方式,你可以调整你?
/etc/init.d/xinetd脚本 Q这?reload 选项发送一?SIGUSR1 信号?
q是个“Y“重配置。这重启动你的服务而不中断你现存的q接 ?/p> chkconfig 理下,dxinetd服务只要单的dxinetd服务文g?/etc/xinetd.d目录中。chkconfig会自动的“捡起“它q其可用,通过chkconfig 工具q行理。简z阿! l论 现在你已l应该认识到U帽子的chkconfig工具理init脚本的好处了Q虽然它的功能似乎简单了些,但是它节省时_q其成Z个系l管理员适用的命令,值得记牢?/p> 学习操作pȝ时我们都了解到文件系l是操作pȝ的重要组成部分之一。文件系l有很多U类型,比windows的fat、fat32QLinux的ext、ext2或ext3QFreeBSD的ufs{等。在使用Linux的过E,也常常Linux操作pȝ使用虚拟文gpȝVFSQ通过VFS可以直接存取其它已被内核支持的各U文件系l,用v来就像是在普通的 Linux的extpd文gpȝ一栗早期的Linux内置支持的文件系l不多,?kernel 2.0.x 起ƈ支持?VFAT Q以后?渐增加,到目前可以说 军_多数的文件系l都有了支持。只是有一些如NTFS需要重新编译内核才能支持?/p>
Linux在启动过E中Q会按照/etc/fstab中的讄Q把各个分区上的文gpȝ加挂到对应到加蝲点上厅RLinux臛_需要两个分区才能启动:一个是根分?Q另一个是交换分区Q如果在启动时根分区加蝲p|QLinux׃能完成启动。如果交换分区加载失败,Linux׃能仍能启动,在内存不够的情况下速度׃受很大的影响。根分区的文件系l类型通常是ext、ext2或ext3Q但也可以是其它的一些文件系l?/p>
除了加蝲了Linux所必需的文件系l外QLinux的用戯l常需要用其它的各种文gpȝQ特别是在一台机器上同时安装多个操作pȝ的时候。比如笔者的机器上同时安装了Linux和Windows2000Q其中Windows的C盘采用了NTFS文gpȝ、D盘采用了FAT32文gpȝ。而当我在Linux上工作的时候,常常需要访问Windows的C盘和D盘的内容Q甚x|络上的׃n目录QLinux下加挂一个文件系l用的是mount命oQ用man mount命o可以得到命o参数的详l解释。下面就来介l一下在几种情况下以命o行方式加挂文件系l的具体ҎQ?/p>
1.加挂FAT32文gpȝ 最单的用法 /dev/hda6是笔者Windows的D盘,/mnt/d是目录加挂点。Linux会识别到/dev/hda6分区的文件系l类型是什么,然后加挂的。当然也可以指定分区的文件系l类型,命o如下Q?/p>
mount -t vfat /dev/hda6 /mnt/d 在实际中操作中,直接加挂一个windows的分区,中文的文件名和目录名会出Cؕ码,Z避免q种情况可以指定字符集,命o如下Q?/p>
mount /dev/hda6 /mnt/d -o codepage=936,iocharset=cp936 注意Qcp936是指体中文,cp950是指J体中文?/p>
2.加挂NTFS文gpȝ 在目前多数的Linux版本上,需要重~译Linux核心才能Q加挂NTFS分区(~译Ҏ请参阅其它文?。核心支持NTFS后,可以用以下命令加挂: mount -t ntfs /dev/hda2 /mnt/c 同样对于中文的文件名和目录名会出Cؕ码的问题可以指定字符集,不过和加挂vfat分区不同Q实际中用以下命令是可行的: mount -t ntfs -o iocharset=cp936 /dev/hda2 /mnt/c -r 3.加挂U盘上的文件系l?/p>
现在使用U盘的来越多了Q其实在Linux下用U盘也非常单,Linux对USB讑֤有很好的支持Q在你插入U盘后QU盘被识别Z个SCSI盘,通常您用以下命op加挂U盘上的文件系l?br />mount /dev/sda1 /usb 同样对于中文的文件名和目录名会出Cؕ码的问题可以指定字符集,命ocM于上面对FAT32介绍的: 4.加挂Linuxpȝ通过samba׃n出来的目?/p>
利用samba׃n出来的目录其实很难说其原来是哪种文gpȝQ不q这一点不重要Q只要它对用h透明的就好啦。加挂时Q我们指定类型ؓsmbfsQ在加挂samba׃n的分区时Q也会出C文的文g名和目录名ؕ码情况,可以用以下命令加挂: mount -t smbfs -o 注意Q你可以不直接写password=terryq个参数Q系l界时会要你输入密码Q这样就可以防止有h直接看到你的密码。视具体情况而定Q?o后面的参数可以对应增减?/p>
5.加挂Windowpȝ׃n出来的目?/p>
在局域网中,常常需要去讉K其它Windowspȝ׃n出来的目录,在Linux下,安装了samba后就可以使用samba中带的命令来讉KWindows机器的共享资源?/p>
用smbclient来列出Windows机器的共享资源 ? Ҏ上面所列出Windows的共享资源后Q可以选择需要加挂到本地Linux中去的Windows的共享资源,然后使用smbmount或mount来加挂,请参照下面几条命令: smbmount //192.168.100.111/public /public/ 以上介绍的都是命令行的方式,每次使用旉要输入一ơ,如果你常常要加挂一些文件系l,惛_启动时自动加挂应该怎样做呢Q下面介l两U方法: Ҏ1. Ҏ2. h意最后三行: 倒数W四行,加挂我的C盘,NTFS格式?br /> 倒数W三行,加挂我的D盘,FAT32格式?br /> 倒数W二行,加挂的是我的局域网中另一台安装samba的Linux文g服务器上的一个目录?/p>
本文ȝ了一下在Linux上不同情况下几种常见加挂文gpȝ的方法,包括如何加挂FAT/NTFS/smbfs/U盘,以及解决加挂中关于中文显C?用户密码{的问题?br />
Linux 可以有多U运行。常见的是多用L2(单用P没有NFS),3(完整的多用户),4(用户自定?,5(X)Q很多h知道 5 是运?X-Windows
的别,?0 是x了。运行的改变可以通过 init 命o来切换。例如,假设你要l护pȝq入单用L态,那么Q可以?init 1
来切换。在Linux 的运行的切换过E中Q系l会自动L对应q行U的目录/etc/rc[0-6].d下的K ?S
开头的文gQ按后面的数字顺序,执行q些脚本?br /> 每一个运行?/etc/rc.d下都有个相应的目录。如q行U?Q目录就?etc/rc.d/rc5.d
。包含启动这个运行的时候运行的相关d的相x件。在 Red Hat? q些文g一般都?shell
脚本的符可接,可以?etc/rc.d/init.d中找到?
以下是引用片D:
id:3:initdefault:
l3:3:wait:/etc/rc.d/rc 3
chkconfig --list [name]
chkconfig --add name
chkconfig --del name
chkconfig [--level levels] name <on|off|reset>
chkconfig [--level levels] name
chkconfig 有五功能:d服务Q删除服务,列表服务Q改变启动信息以及检查特定服务的启动状态?br />
chkconfig 没有参数q行Ӟ昄用法。如果加上服务名Q那么就查这个服务是否在当前q行U启动。如果是Q返?trueQ否则返?false?
--level 选项可以指定要查看的q行U而不一定是当前q行U?br />
如果在服务名后面指定了onQoff 或?resetQ那?chkconfig 会改变指定服务的启动信息。on ?off 分别指服务在改变q行U时的启动和停止。reset 指初始化服务信息Q无论有问题的初始化脚本指定了什么?br />
对于 on ?off 开养Ipȝ默认只对q行U?3Q?Q?5有效Q但?reset 可以Ҏ有运行有效。指?--level 选项Ӟ可以选择特定的运行?br />
需要说明的是,对于每个q行U,只能有一个启动脚本或者停止脚本。当切换q行U时Qinit 不会重新启动已经启动的服务,也不会再ơ去停止已经停止的服务?br />
选项介绍Q?br />
--level levels 指定q行U,由数?0 ?7 构成的字W串Q如Q?br />
--level 35 表示指定q行U? ??br />
--add name
q个选项增加一Ҏ的服务,chkconfig 保每个q行U有一?启动(S) 或?杀?K) 入口。如有缺,则会从缺省的init 脚本自动建立?br />
--del name
用来删除服务Qƈ把相关符可接从 /etc/rc[0-6].d 删除?br />
--list name
列表Q如果指定了name 那么只是昄指定的服务名Q否则,列出全部服务在不同运行的状态?br />
q行U文?br />
每个被chkconfig 理的服务需要在对应的init.d 下的脚本加上两行或者更多行的注释?br />
W一行告?chkconfig ~省启动的运行以及启动和停止的优先U。如果某服务~省不在Mq行U启动,那么使用 - 代替q行U?br />
W二行对服务q行描述Q可以用\ 跨行注释?br />
例如Qrandom.init 包含三行Q?br />
# chkconfig: 2345 20 80
# description: Saves and restores system entropy pool for \
# higher quality random number generation.
表明 random 脚本应该在运行 2, 3, 4, 5 启动Q启动优先权?0Q停止优先权?80?br />具体详细参见/etc/rc.d/init.d 下的脚本.
启动基础知识
chkconfig的二q制软g?/sbin下,默认权限允许M用户执行 。不q没有root权限的用户只能察看当前的 chkconfig配置。输?
[root]# chkconfig --list | grep on
在输出的每一行,最开始的D代表在 /etc/rc.d/init.d中的init脚本名?
其余的区D表C本进入各个运行时的各运行0-6的状态?例如Qcrond应当在进入运行2Q?Q?4Q? 的时候启动,当进?0, 1
and 6的时候停止。我们可以通过find命o查找?etc/rc.d中所有crondl尾的文件确信我们设|的正确?
amd 0:off 1:off 2:off 3:off 4:on 5:on 6:off
apmd 0:off 1:off 2:on 3:off 4:on 5:off 6:off
arpwatch 0:off 1:off 2:off 3:off 4:off 5:off 6:off
atd 0:off 1:off 2:off 3:on 4:on 5:on 6:off
autofs 0:off 1:off 2:off 3:off 4:off 5:off 6:off
named 0:off 1:off 2:off 3:off 4:off 5:off 6:off
bootparamd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
keytable 0:off 1:off 2:on 3:on 4:on 5:on 6:off
crond 0:off 1:off 2:on 3:on 4:on 5:on 6:off
syslog 0:off 1:off 2:on 3:on 4:on 5:on 6:off
netfs 0:off 1:off 2:off 3:on 4:on 5:on 6:off
network 0:off 1:off 2:on 3:on 4:on 5:on 6:off
注意chkconfig报告的每?``off'' ?(0, 1, 6)Q?一?kill脚本存在 script is in place
每一个``on'' ?(2, 3, 4, 5)Q有一?start脚本?接下来,执行一个不同的 find 命o以确信每个发现的文g的类?
以下是引用片D:
[root]# find /etc/rc.d -name ?crond’?print
/etc/rc.d/init.d/crond
/etc/rc.d/rc0.d/K60crond
/etc/rc.d/rc1.d/K60crond
/etc/rc.d/rc2.d/S40crond
/etc/rc.d/rc3.d/S40crond
/etc/rc.d/rc4.d/S40crond
/etc/rc.d/rc5.d/S40crond
/etc/rc.d/rc6.d/K60crond
q表明在init.d中找到的crond是一个shell脚本Q找到的所有其他的文g都是?crond 脚本的符可接?br />以下是引用片D:
[root]# find /etc/rc.d -name ?crond’?exec file {} ;
/etc/rc.d/init.d/crond: Bourne shell script text
/etc/rc.d/rc0.d/K60crond: symbolic link to
../init.d/crond
/etc/rc.d/rc1.d/K60crond: symbolic link to
../init.d/crond
/etc/rc.d/rc2.d/S40crond: symbolic link to
../init.d/crond
/etc/rc.d/rc3.d/S40crond: symbolic link to
../init.d/crond
/etc/rc.d/rc4.d/S40crond: symbolic link to
../init.d/crond
/etc/rc.d/rc5.d/S40crond: symbolic link to
../init.d/crond
/etc/rc.d/rc6.d/K60crond: symbolic link to
../init.d/crond
调整chkconfig?/strong> # chkconfig --level 2 crond off
紧记 chkconfig不是立即自动止或激zM个服务的Q它只是单的改变了符可接,用户可以用这个命?
/etc/rc.d/init.d/crond stop立刻止crond服务。最后,你可以用一个命令行Ȁz?止多个q行U的某个命o ?
例如输入:
[root]# find /etc/rc.d -name ?crond’?print
/etc/rc.d/init.d/crond
/etc/rc.d/rc0.d/K60crond
/etc/rc.d/rc1.d/K60crond
/etc/rc.d/rc2.d/K60crond
/etc/rc.d/rc3.d/S40crond
/etc/rc.d/rc4.d/S40crond
/etc/rc.d/rc5.d/S40crond
/etc/rc.d/rc6.d/K60crond
会设?crond 在运行2Q?3Q?4 ?5启动?/p> 删掉一?/strong> chkconfig --del sendmail
在我看来q很完美。脚本保留了Q万一 sendmail
需要作Z个服务实现呢?不过所有的W号q接L了。我们能在每一个运行止sendmail
服务Q这在每一个rc*.d子目录中攄一个kill脚本Q虽然sendmail从不在初始化阶段启动Q是个不必要的Q?
Q可是,我曾看到一些系l管理员需要在特定的场合手工启动服?。把kill脚本留在那里保可以q净的杀掉服务?
[root]# find /etc/rc.d -name ?sendmail’?print
/etc/rc.d/init.d/sendmail #!/bin/sh<\n>
#chkconfig: 2345 80 05
#description: Oracle 8 Server
ORA_HOME=/usr/home/oracle/product/8.0.5
ORA_OWNER=oracle
if [ ! -f $ORA_HOME/bin/dbstart ]
then
echo "Oracle startup: cannot start"
exit
fi
case "$1" in
"start")
su-$ORA_OWNER -c $ORA_HOME/bin/dbstart
su-$ORA_OWNER -c "$ORA_HOME/bin/lsnrctl start"
;;
"stop")
su-$ORA_OWNER -c $ORA_HOME/bin/dbshut
su-$ORA_OWNER -c "$ORA_HOME/bin/lsnrctl stop"
;;
esac chmod +x /etc/rc.d/init.d/oracle #chkconfig: 2345 80 05
#description: Oracle 8 Server# chkconfig --add oracle. [root]# chkconfig --list | grep oracle
oracle 0:off 1:off 2:on 3:on 4:on 5:on 6:off
正如需要的那样Qkillq接的名字包含优先权05而startq接包含80。如果你需要调整优先权Q?(e.g.我们停止的优先权需要设?
03)Q简单的调整oracle init脚本的chkconfig 注释行ƈq行 reset命o commandQ如下所C。符可接会被改?
[root]# chkconfig oracle reset [root]# find /etc/rc.d -name ?oracle’?print
/etc/rc.d/init.d/oracle
/etc/rc.d/rc0.d/K05oracle
/etc/rc.d/rc1.d/K05oracle
/etc/rc.d/rc2.d/S80oracle
/etc/rc.d/rc3.d/S80oracle
/etc/rc.d/rc4.d/S80oracle
/etc/rc.d/rc5.d/S80oracle
/etc/rc.d/rc6.d/K05oracle
[root]# find /etc/rc.d -name ?oracle’?print
/etc/rc.d/init.d/oracle
/etc/rc.d/rc0.d/K03oracle
/etc/rc.d/rc1.d/K03oracle
/etc/rc.d/rc2.d/S80oracle
/etc/rc.d/rc3.d/S80oracle
/etc/rc.d/rc4.d/S80oracle
/etc/rc.d/rc5.d/S80oracle
/etc/rc.d/rc6.d/K03oracle
Red Hat 7中的改进
掉一?xinetd 服务Q可能是 fingerQ你应该输入:
[root]# chkconfig --list
...
xinetd based services:
finger: on
linuxconf-web: off
rexec: off
rlogin: off
rsh: off
ntalk: off
talk: off
telnet: on
tftp: off
wu-ftpd: on [root]# chkconfig finger off.
L信如果照着q个来做,你的MRTG很快׃搞定.^_^.
主要功能:
用一个网|监视pȝ的CPU,NIC,MEM,SWAP,DISK usage, DISK I/O.情况.
里面的script有部分是自已写的,也有部分是下载的.像磁盘空间那个script是下载的,但是觉得功能不是很好?׃有现成的也就没有再写,如果哪位有更好的script望请׃n.
1. 安装.
(1)需要的RPM
RHEL 3.0/4.0的安装CD带有MRTG的RPM安装? Z使用MRTG的一些脚?需要安装其他的一些安装包.
Sysstat.rpm pȝ状况监视安装?(cpu.sh)
Procps.rpm 内存,Swap 使用情况工具{?cpu.sh,mem.sh,swap.sh)
Coreutils.rpm (df.pl,disk.sh)
gd-1.8.4-4
gd-devel-1.8.4-4
perl-5.6.0-17
perl-CGI
mod_perl-1.24_01-3
libpng-1.0.12-2
libpng-devel-1.0.12-2
gcc-2.96-98
gcc-g77-2.96-98
gcc-c++-2.96-98
zlib-1.1.3-24
zlib-devel-1.1.3-24
httpd(apache)
net-snmp
mrtg
查装有没有上面rpm?
(2)安装MRTG
Rpm –ivh mrtg -2.9.29-4.ent.i386.rpm
2. 配置SNMP 让他可以配合MRTG工作
~辑/etc/snmp/snmpd.conf
把下面的#号去掉?
#view mib2 included .iso.org.dod.internet.mgmt.mib-2 fc #?9行?
把下面的语句#?2行?
access notConfigGroup "" any noauth exact systemview none none
改ؓQ?
access notConfigGroup "" any noauth exact mib2 none none
改完重启一下snmp
Service snmpd restat
3. 配置MRTG
(1) mkdir /var/www/html/mrtg
(2) mkdir /opt/mrtg
(3) 从下面的贴子复制以下几个script ?opt/mrtg
Cpu.sh , mem.sh , swap.sh, diskperf.sh, disk.pl
(4) cp /var/www/mrtg/* /var/www/html/mrtg
(5) /usr/bin/cfgmaker –output=/var/www/html/mrtg/mrtg.cfg public@10.102.17.100 用来配置一个mrtg配置文g.
(./cfgmaker --global 'WorkDir: /opt/jakarta-tomcat-5.0.16/webapps/ROOT/mrtg' --global 'Options[_]: growright,bits' --ifref=ip --output /etc/mrtg.cfg public@x.x.x.x)
(6) ~辑MRTG的配|文件 vi /var/www/html/mrtg/mrtg.cfg
(1)把WorkDir: /var/www/html/mrtg 加入到配|文件的前面.
(2)把Options[_]: growright, bits 前面?删掉.
(3)把要监测的几个ITEM加入到配|文仉面去.
1) CPU
################CPU######################
Target[cpu]: `/opt/mrtg/cpu.sh`
MaxBytes[cpu]: 12500000
Title[cpu]: CPU -- XMNLINUXTEST02
Options[cpu]: gauge,nopercent,growright
YLegend[cpu]: CPU loading (%)
ShortLegend[cpu]:%
LegendO[cpu]: & CPU USER;
LegendI[cpu]: & CPU SYSTEM;
PageTop[cpu]: <H1>;CPU -- XMNLINUXTEST02</H1>;
2)NIC 用配|文件自动配好的.
3)MEM q个图最大设?G,如果服务器有更大的内?可以修改Maxbytes.
############### MEM 2G #################
Target[managemem]:`/opt/mrtg/mem.sh`
Unscaled[managemem]: dwym
MaxBytes[managemem]: 2048000
Title[managemem]:Memory
ShortLegend[managemem]: &
kmg[managemem]:kB,MB
kilo[managemem]:1024
YLegend[managemem]: Memory Usage
Legend1[managemem]: Total Memory
Legend2[managemem]: Used Memory
LegendI[managemem]: Total Memory
LegendO[managemem]: Used Memory
Options[managemem]: growright,gauge,nopercent
PageTop[managemem]:<H1>;Memory -------XMNLINUXTEST2</H1>;
4)Swap 也是设ؓ2G,Ҏ实际情况改MaxBytes.
################### Swap 2G#######################
Target[swap]:`/opt/mrtg/swap.sh`
Unscaled[swap]: dwym
MaxBytes[swap]: 2048000
Title[swap]:Memory State of Server
ShortLegend[swap]: &
kmg[swap]:kB,MB
kilo[swap]:1024
YLegend[swap]: Swap Usage
Legend1[swap]: Total Swap
Legend2[swap]: Used Swap
LegendI[swap]: Total Swap
LegendO[swap]: Used Swap
Options[swap]: growright,gauge,nopercent
PageTop[swap]:<H1>;Swap-------XMNLINUXTEST02</H1>;
5)讄盘使用量 最大ؓ480G,可以Ҏ实际情况修改MaxBytes
################## Disk Space 480G #########################
Target[disk]: `/opt/mrtg/df.pl`
Title[disk]: Disk Space ----XMNLINUXTEST02
Unscaled[disk]: dwym
MaxBytes[disk]: 465247550
kmg[disk]: KB,MB,GB
LegendI[disk]: Total Disk Space
LegendO[disk]: Used Disk Space
Legend1[disk]: Total Disk Space
Legend2[disk]: Used Disk Space
YLegend[disk]: Megabytes
ShortLegend[disk]: &
Options[disk]: growright,gauge,nopercent
PageTop[disk]: <H1>;Disk Space --------XMNLINUXTEST02</H1>;
6)盘I/O的检?如果需要的,更多的分?修改q复制这个部?q修改diskperf.sh
################## Disk I/O 100K/sec /DEV/SDA ##########
# If you want monitor more disk, please copy below create
# now monitor job, and copy & modify the diskperf.sh to setting disk.
Target[diskIO]: `/opt/mrtg/diskperf.sh`
Title[diskIO]: Disk HDA I/O Utilization Report
Unscaled[diskIO]: dwym
MaxBytes[diskIO]: 100
PageTop[diskIO]: <H1>;Disk I/O Utilization Report</H1>;
kmg[diskIO]: KB,MB,GB
LegendI[diskIO]: Disk I/O KBread/sec
LegendO[diskIO]: Disk I/O KBwrite/sec
Legend1[diskIO]: Disk I/O KBread/sec
Legend2[diskIO]: Disk I/O KBwrite/sec
YLegend[diskIO]: Megabytes
ShortLegend[diskIO]: &
Options[diskIO]: growright,gauge,nopercent
4. ~译配置文g
先在/etc/profile 加入两个参数
LC_ALL=C
LANGUAGE=on
# env LANG=C /usr/bin/mrtg /var/www/html/mrtg/mrtg.cfg
前面两次会出?多运行几ơ就没有问题.
5. 生成html文g.
/usr/bin/indexmaker –output=/var/www/html/mrtg/index.html –title=L名?var/www/html/mrtg/mrtg.cfg
6. 配置apache 的设|?
#vi /etc/httpd/conf.d/mrtg.cfg
把Alias /mrtg /var/www/mrtg 改ؓAlias /mrtg /var/www/html/mrtg
把Allow from localhost 改ؓAllow from all
#service httpd restart ,重启apache.
7. 配置,自运行脚?每五分钟自动q行一?
在root 下启动 crontab –e d计划
*/5 * * * * env LANG=C /usr/bin/mrtg /var/www/html/mrtg/mrtg.cfg
8. 认service http&crontab的运q?
可以用下面两个命令查看这个服务的q行状况,
#chkconfig –list |grep httpd
#chkconfig –list |grep crontab
或用讑֮q行U别
chkconfig --level 35 httpd on
chkconfig --level 35 crontab on5. 常见问题
(1)?实际内存或硬盘跟的图里面的值相差太?要吗U超出图?要吗,在图表的下面. 如何更改图表的比? 如内存实际上只有512M,但表里面内存昄最大ؓ2G.
{?修改/var/www/html/mrtg/mrtg.cfg 扑ֈ相关的部? 修改MaxBytes[managemem]: 2048000 中的2048000?12000
(2)?我有几个盘,如果要监其他的盘IO?
{?首先复制一份diskperf.sh 成diskperf2.sh ,再修改diskperf2.sh里面把hd=xxx改ؓ你要监测的硬?再修?var/www/html/mrtg/mrtg.cfg 复制sda的那一部门,q修改相关的部分.
如Target[diskIO]:`/opt/mrtg/diskperf.sh` ҎTarget[diskIO]: `/opt/mrtg/diskperf2.sh`
q一部䆾的[diskIO]改ؓdisk2IO
(3)?修改了配|文?var/www/html/mrtg/mrtg.cfg ?|页没有生效
{?修改完配|文件应该要重新用下面命令生成新的网?
/usr/bin/indexmaker –output=/var/www/html/mrtg/index.html –title=L名?var/www/html/mrtg/mrtg.cfg
(4)?如何看我的MRTG?
{?用http://你的IP/mrtg/ 可以看C.
?1: mrtg.cfg 里面几个参数的意?
TargetQ是要执行的脚本
XsizeQ生成图表的横向宽度Q最?00Q?
YsizeQ生成图表的U向高度Q最?00Q?
TitleQ标题?
kMG: Change the default multiplier prefixes
YticsQ纵向划分ؓ几个块(格子Q?
MaxBytesQ图表纵向数值的最大上限?
PageTopQ页面上面的提示
kiloQ一般是?024Q如果需要的话,?000在计机里的单位
LegendIQ从SHELLq回的数据中的第一个?
LegendOQ从SHELLq回的数据中的第二个
OptionsQ growrightQ表C图表向叛_g?
?:各个script
(1)
cat /opt/mrtg/cpu.sh
#!/bin/bash
cpuusr=`/usr/bin/sar -u 1 3 |grep Average |awk '{print $3}'`
cpusys=`/usr/bin/sar -u 1 3 |grep Average |awk '{print $5}'`
UPtime=`/usr/bin/uptime |awk '{print $3""$4""$5}'`
echo $cpuusr
echo $cpusys
echo $UPtime
hostname
(2)
Disk usage
cat /opt/mrtg/df.pl
#!/usr/bin/perl
# output(df -kl) looks like this:
# Filesystem 1k-blocks Used Available Use% Mounted on
# /dev/md0 95645100 30401312 64272080 33% /
# /dev/hde1 14119 1159 12231 9% /boot
#
# In which case, this script returns :
# 95659219
# 30402503
# when run.
foreach $filesystem (`df -kl | grep -v "Filesystem"`)
{
@df = split(/\s+/,$filesystem);
$total += $df[1];
$usage += $df[2];
}
print "$total\n";
print "$usage\n";
hostname
(3) DISK IO # cat /opt/mrtg/diskperf.sh
#!/bin/bash
# This script will monitor the KBread/sec &KBwriten/sec of Disk.
# Creater: CCC IT loren ext:2288 2005/8/3
# As sda ,sdb,sdc,sdd,hda.
# disk=sda
hd=sda
disk=/dev/$hd
KBread_sec=`iostat -x $disk|grep $hd |awk '{print $8}'`
KBwrite_sec=`iostat -x $disk|grep $hd |awk '{print $9}'`
echo "$KBread_sec"
echo "$KBwrite_sec"
hostname
(4)MEMORY
cat /opt/mrtg/mem.sh
#!/bin/bash
# This script to monitor the mem usage.
totalmem=`/usr/bin/free |grep Mem |awk '{print $2}'`
usedmem=`/usr/bin/free |grep Mem |awk '{print $3}'`
echo "$totalmem"
echo "$usedmem"
(5)SWAP
cat /opt/mrtg/swap.sh
#!/bin/bash
# This script to monitor the swap usage.
totalswap=`/usr/bin/free |grep Swap |awk '{print $2}'`
usedswap=`/usr/bin/free |grep Swap |awk '{print $3}'`
echo "$totalswap"
echo "$usedswap"
]]>
mount /dev/hda6 /mnt/d
mount -t vfat /dev/hda6 /mnt/d -o codepage=936,iocharset=cp936
mount -t ntfs -o iocharset=cp936,rw /dev/hda2 /mnt/c
mount /dev/sda1 /usb -o pagecode=936,iocharset=cp936
username=terry,password=terry,codepage=936,iocharset=cp936
//terry-linux/terry /mp3/
mount -t smbfs -o
username=terry,password=terry,codepage=936,iocharset=cp936
//192.168.100.228/terry /mp3/
smbclient -L 192.168.100.111
mount //192.168.100.111/d /mnt/cdrom -o username=terry (q样要在命o行输入密码的)
mount //192.168.100.111/d /mnt/cdrom -o username=terry$1234 (q样则不必在命o行输入密?
注:除了上面介绍的命令行Ҏ之外Q这时最好的Ҏ是使用其它的客LQ如LinNeighborhood、networkneighbours、ksmbshare{,请参考其它文章?/p>
把加挂的命o攑֜/etc/rc.d/rc.local中?/p>
修改分区配置文g/etc/fstabQ在启动时加挂文件系l,下面是我?etc/fstab文gQ?br /> LABEL=/ / ext3 defaults
1 1
none /dev/pts devpts gid=5,mode=620
0 0
LABEL=/home /home ext3 defaults
1 2
none /proc proc defaults
0 0
none /dev/shm tmpfs defaults
0 0
/dev/hda4 swap swap defaults
0 0
/dev/cdrom /mnt/cdrom iso9660
noauto,owner,kudzu,ro 0 0
/dev/hda2 /ntfs ntfs defaults,iocharset=cp936 0 0
/dev/hda6 /win vfat defaults,codepage=936,iocharset= cp936 0 0
//192.168.100.228/terry /mp3 smbfs username=terry,password=terry,codepage=cp936,iocharset=cp936 0 0
]]>
cd /usr/local
wget http://awstats.sourceforge.net/files/awstats-6.5.tar.gz
tar xzvf awstats-6.5.tar.gz
cd /usr/local/awstats/tools/
2.
perl awstats_configure.pl
----- AWStats awstats_configure 1.0 (build 1.6) (c) Laurent Destailleur -----
This tool will help you to configure AWStats to analyze statistics for
one web server. You can try to use it to let it do all that is possible
in AWStats setup, however following the step by step manual setup
documentation (docs/index.html) is often a better idea. Above all if:
- You are not an administrator user,
- You want to analyze downloaded log files without web server,
- You want to analyze mail or ftp log files instead of web log files,
- You need to analyze load balanced servers log files,
- You want to 'understand' all possible ways to use AWStats...
Read the AWStats documentation (docs/index.html).
-----> Running OS detected: Linux, BSD or Unix
-----> Check for web server install
Found Web server Apache config file '/usr/local/apache2/conf/httpd.conf'
-----> Check and complete web server config file '/usr/local/apache2/conf/httpd.conf'
Warning: You Apache config file contains directives to write 'common' log files
This means that some features can't work (os, browsers and keywords detection).
Do you want me to setup Apache to write 'combined' log files [y/N] ? y
Add 'Alias /awstatsclasses "/usr/local/awstats/wwwroot/classes/"'
Add 'Alias /awstatscss "/usr/local/awstats/wwwroot/css/"'
Add 'Alias /awstatsicons "/usr/local/awstats/wwwroot/icon/"'
Add 'ScriptAlias /awstats/ "/usr/local/awstats/wwwroot/cgi-bin/"'
Add '<Directory>' directive
AWStats directives added to Apache config file.
-----> Update model config file '/usr/local/awstats/wwwroot/cgi-bin/awstats.model.conf'
File awstats.model.conf updated.
-----> Need to create a new config file ?
Do you want me to build a new AWStats config/profile
file (required if first install) [y/N] ? y
-----> Define config file name to create
What is the name of your web site or profile analysis ?
Example: www.mysite.com
Example: demo
Your web site, virtual server or profile name:
> mms.xxxxx.com
-----> Define config file path
In which directory do you plan to store your config file(s) ?
Default: /etc/awstats
Directory path to store config file(s) (Enter for default):
>
-----> Create config file '/etc/awstats/awstats.mms.xxxxx.com.conf'
Config file /etc/awstats/awstats.mms.xxxxx.com.conf created.
-----> Restart Web server with '/sbin/service httpd restart'
httpd: unrecognized service
-----> Add update process inside a scheduler
Sorry, configure.pl does not support automatic add to cron yet.
You can do it manually by adding the following command to your cron:
/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=mms.xxxxx.com
Or if you have several config files and prefer having only one command:
/usr/local/awstats/tools/awstats_updateall.pl now
Press ENTER to continue...
A SIMPLE config file has been created: /etc/awstats/awstats.mms.xxxxx.com.conf
You should have a look inside to check and change manually main parameters.
You can then manually update your statistics for 'mms.xxxxx.com' with command:
> perl awstats.pl -update -config=mms.xxxxxcom
You can also read your statistics for 'mms.xxxxx.com' with URL:
> http://localhost/awstats/awstats.pl?config=mms.xxxxx.com
Press ENTER to finish...
up to this procedure, the httpd.conf have these codes
#
# Directives to allow use of AWStats as a CGI
#
Alias /awstatsclasses "/usr/local/awstats/wwwroot/classes/"
Alias /awstatscss "/usr/local/awstats/wwwroot/css/"
Alias /awstatsicons "/usr/local/awstats/wwwroot/icon/"
ScriptAlias /awstats/ "/usr/local/awstats/wwwroot/cgi-bin/"
#
# This is to permit URL access to scripts/files in AWStats directory.
#
<Directory "/usr/local/awstats/wwwroot">
Options None
AllowOverride None
Order allow,deny
Allow from all
</Directory>
3.vi /etc/awstat/awstats.mms.xxxxx.com.conf
LogFile="/usr/local/apache2/logs/access_log"
4.according to DirData="/var/lib/awstats" in /etc/awstat/awstats.mms.xxxxx.com.conf
create dir /var/lib/awstats and chown -R nobody /var/lib/awstats
restart server
5. perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=mms.xxxxx.com
6.chmod 755 /usr/local/awstats
http://mms.xxxxx.com/awstats/awstats.pl?config=mms.xxxxx.com
7.crontab -e
1 3 * * * ()
Apache配置文g(httpd.conf)中文说明 |
# Z NCSA 服务的配|文件?# ServerRoot "/usr/loacl/apache2"
# #ScoreBoardFile:用来保存内部服务q程信息的文件?br />#如果未指明(默认Q,记分板(scoreboardQ将被保存在一个匿名的׃n内存D中Q?br />#q且它不能被W三方Y件所使用?br />#如果指定了,要确保不能用两个Apache使用同一个记分板文gQ?br />#q个记分板文件必M存在本地盘上?/font> <IfModule !mpm_netware.c>
#
#
#
#
#
##
# worker MPM
# perchild MPM
# WinNT MPM
# BeOS MPM
# NetWare MPM
# OS/2 MPM
#
#
#
#
#
#
# # q将止讉K文gpȝ所在的目录Qƈd你希望允许访问的目录块?br /># 如下所C?/font> <Directory />
#
# <Directory "/home/redhat/public_html">
# Options FollowSymLinks
#
# UserDir public_html
# 为防止在UserDir指o上的漏洞Q对root用户讄 UserDir disabled root
#
# DirectoryIndex index.php index.html index.html.var
# AccessFileName .htaccess
# <Files ~ "^.ht">
# TypeConfig conf/mime.types
# DefaultType text/plain
# <IfModule mod_mime_magic.c>
# HostnameLookups Off
#
#
# ErrorLog logs/error_log
# LogLevel warn
# LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined # 你需要安装了mod_logio.c模块才能使用%I?O?br /># LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
# CustomLog logs/access_log common
#
#
# ServerTokens Full
# ServerSignature On
#
# <Directory "/usr/local/apache2/icons">
#
#
# q里是添加php 4支持的指?/font>
# <Directory "/usr/local/apache2/cgi-bin">
#
#
# IndexOptions FancyIndexing VersionSort
# AddIconByEncoding (CMP,/icons/compressed.gif) x-compress x-gzip AddIconByType (TXT,/icons/text.gif) text ServerRoot "/usr/loacl/apache2"
# <IfModule !mpm_winnt.c> #ScoreBoardFile:用来保存内部服务q程信息的文件?br />#如果未指明(默认Q,记分板(scoreboardQ将被保存在一个匿名的׃n内存D中Q?br />#q且它不能被W三方Y件所使用?br />#如果指定了,要确保不能用两个Apache使用同一个记分板文gQ?br />#q个记分板文件必M存在本地盘上?br /># <IfModule !mpm_netware.c>
# <IfModule !mpm_neware.c>
# Timeout 300
# KeepAlive On
# MaxKeepAliveRequests 100
# KeepAliveTimeout 15
##
# prefork MPM <IfModule prefork.c>
# worker MPM <IfModule worker.c>
# perchild MPM <IfModule perchild.c>
# WinNT MPM <IfModule mpm_winnt.c>
# BeOS MPM <IfModule beos.c>
# NetWare MPM <IfModule mpm_netware.c>
# OS/2 MPM
# Listen 80
#
#
### W二区:“主”服务配|?br /># <IfModule !mpm_winnt.c> User nobody
# ServerAdmin [email]kreny@sina.com[/email]
# ServerName <a href="http://www.dalouis.com:80" target="_blank">www.dalouis.com:80</a>
# UseCanonicalName Off
# DocumentRoot "/home/redhat/public_html"
# # q将止讉K文gpȝ所在的目录Qƈd你希望允许访问的目录块?br /># 如下所C?/font> <Directory />
#
# <Directory "/home/redhat/public_html">
# UserDir public_html
# 为防止在UserDir指o上的漏洞Q对root用户讄 UserDir disabled root
#
# DirectoryIndex index.php index.html index.html.var
# AccessFileName .htaccess
#
# TypeConfig conf/mime.types
# DefaultType text/plain
#
# HostnameLookups Off
#
#
# ErrorLog logs/error_log
#
# # 你需要安装了mod_logio.c模块才能使用%I?O?br /># LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
# CustomLog logs/access_log common
#
#
# ServerTokens Full
# ServerSignature On
#
# <Directory "/usr/local/apache2/icons">
#
#
# q里是添加php 4支持的指?/font>
<IfModule mod_cgid.c>
#
#
#
|