2008年12月 归档

开机时跳过键盘检查

| 暂无评论 | 暂无引用通告

    有两台PC,安装了Linux系统,通过ssh进行控制,没连显示器和键盘,每次重启,系统自检,检查键盘的时就会停止,提示按F1继续。解决方法:

      自检时按DEL进入CMOS,进入Standard CMOS Features后选Halt On,然后选择"All,But Keyboard",缺省的是"All Errors",以下是几个选项:

No Errors

不管任何错误,均开机

All Errors

有任何错误均暂停,等候处理

All,But Keyboard

有任何错误均暂停,等候处理,除了键盘以外

All,But Diskette

有任何错误均暂停,等候处理,除了软驱以外

All,But Disk/Key

有任何错误均暂停,等候处理,除了软驱和键盘以外

利用Tie::File可以将文件的内容看着是一个数组来操作,具体示例如下:

[supersun@supersun.biz perl]$ cat tie.pl

#!/usr/bin/perl -w

use strict;

 

use Tie::File;

 

my $file=shift;

my @arrary;

tie @arrary,'Tie::File',$file;

 

push @arrary,"hello";

在文件的结尾增加一行:hello

[supersun@supersun.biz perl]$ cat test

aaaaa

[supersun@supersun.biz perl]$ perl tie.pl  test

[supersun@supersun.biz perl]$ cat test

aaaaa

hello

[supersun@supersun.biz perl]$

 

    我使用这个模块的目的主要是用于处理inotify脚本生成的日志文件,因为之前一直使用logrotate及cron来实现文件的上传,cron的最小时间间隔是1分钟,间隔稍长了一点。

一个与awstats相关的小报表

| 暂无评论 | 暂无引用通告

几台服务器的apache日志使用awstat进行统计,现在需要将每台主机的每日访问文件数按日期排序,打印成一张表:

awstat生成的数据文件的文件名格式为:awstats102008.hostname.txt

20081017 2826794 2826794 340568061 59

20081018 2736667 2736667 336467614 58

20081019 3314638 3314638 352853200 56

需要获取的数据为上面的第一二列,即日期和文件数

 

#!/usr/bin/perl -w

use strict;

my $data_dir="/opt/awstats/dirdata";

chdir $data_dir;

my %data;

my $month=shift;

my $year="2008";

my $mod=shift;

my @hosts;

@hosts=(21..28) if $mod eq "m";

@hosts=(31..38) if $mod eq "t";

print "<html>

<head>

<title>access log statistic</title>

</head>

<body>

<h1>access log statistic on $month $year</h1>

<h3><a href='/'>return to index</a></h3>

<table border=1>

";

foreach my $host (@hosts){

my $file="awstats".$month.$year.".".$host.".txt";

 

next unless -f $file;

open FD,$file;

while(<FD>){

        my $arrary=$_;

        if ($arrary =~ /^$year$month/){

                my @tmp=split /\s+/,$arrary;

                my $date=shift @tmp;

                my $num=shift @tmp;

                $data{"d".$date}{"h".$host}=$num;

        }

}

close FD;

}

 

print "<tr>\n";

print "<th>date</th>\n";

foreach my $host (@hosts){

        print "<th>$host</th>\n";

}

print "</tr>\n";

foreach my $date (sort keys %data){

        print "<tr>\n";

        print "<td>$date</td>\n";

        foreach my $host (@hosts){

        print "<td align='right'> ",$data{$date}{'h'.$host}?$data{$date}{'h'.$host}:0," </td>\n";

        }

        print "</tr>\n";

}

print "</table>

<h3><a href='/'>return to index</a></h3>

</body>

</html>";


运行perl awstat_html.pl 12 m

第一个参数是月份,第二个参数是服务器分组,我在脚本里定义了两个分组

生成的结果如下:

 access statistic on 12 2008

return to index

date 21 22 23 24 25 26 27 28
d20081201 3889363 3510197 3822591 3705947 3648502 3507673 3575994 3595313
d20081202 3460608 3584238 3793175 3847570 3541112 4261298 3440269 3479714
d20081203 3543943 3480454 3747391 3865192 3400915 3621912 3579295 3459238
d20081204 3426827 3319026 3290832 3301444 3290683 3437950 3378622 3384148
d20081205 3029773 3124348 3057467 3026183 3367647 3028501 3196543 3221404
d20081206 2816795 2872855 2990546 3240831 2965240 2813721 2821424 3318829


将就着看,呵呵。

 

jdk快速安装脚本

| 暂无评论 | 暂无引用通告

如果你有多台服务器需要安装JDK,不妨使用以下的脚本,在安装前定制一下脚本中的变量:JKD_ARCHIVE(jdk压缩包文件名) JDK_VERSION(解压后的目录名) INSTALL_DIR(目标目录)

 

#!/bin/sh

#auther:supersun

#email:supersun06@gmail.com

#homepage:http://supersun.biz

 

JKD_ARCHIVE="jdk1.5.tgz"

JDK_VERSION="jdk1.5.0_017"

INSTALL_DIR="/usr/local/"

 

HOSTLISTS="$*"

 

for HOST in $HOSTLISTS

do

 

ssh $HOST " if [ -d ${INSTALL_DIR}${JDK_VERSION} ]

then

 echo $JDK_VERSION has been installed

else

 echo  $JDK_VERSION hasnot been installed

 cd $INSTALL_DIR

 tar zxf -

 test -L java && rm java

 ln -s $JDK_VERSION java

 cat >/etc/profile.d/java.sh <<'EOF'

#!/bin/sh

JAVA_HOME=/usr/local/java

PATH=\$JAVA_HOME/bin:\$PATH

 

export JAVA_HOME PATH

EOF

 

fi" <$JKD_ARCHIVE

done

 

用法如下

[supersun@supersun.biz java]$ sudo sh ins_jdk.sh host1

Password:

jdk1.5.0_017 hasnot been installed

[supersun@supersun.biz java java]$ s ssh mss1

Last login: Thu Dec 11 15:47:12 2008 from supersun.biz

[root@host1 ~]# which java

/usr/local/java/bin/java

 

此页面重定向不正确

| 暂无评论 | 暂无引用通告

    登陆GOOGLE日历,Firefox提示"此页面重定向不正确",Firefox菜单"工具"->选项->隐私->"显示Cookie" 然后关google日历的Cookie删除,重新登陆Google日历,不再报错。

如何获取进程的启动时间

| 暂无评论 | 暂无引用通告

作者: PuGuangH 原文链接: http://blog.sina.com.cn/s/blog_4d6f6219010009n7.html

PID=$1

JIFFIES=`cat /proc/$PID/stat | cut -d" " -f22`

UPTIME=`grep btime /proc/stat | cut -d" " -f2`

START_SEC=$(( $UPTIME + $JIFFIES / 100 ))

START_TIME=`date -d "1970-1-1 UTC $START_SEC seconds"`

echo $START_TIME

 

其中PID中要传入对应的进程ID

 

其中/proc/stat中的btime指的是系统的启动时间也就是boot time

对于一个具体的进程  /proc/$pid/stat中对应的第22项指的是该进程相对于系统启动以来的执行时间。

    inotify是Linux内核的新功能,用于监控文件系统的事件,此功能对于海量小文件的备份很有帮助。

    我手头管理着一组服务器,每台服务器上存放大量小文件,一天之中,更新的文件数量达到30万左右(这个数据是从rsync的日志中得到的,每天我们会运行一组rsync脚本,用于备份数据。完成同步需要6个小时左右,每天的同一文件的多次变动还未计算在内),为了将在发生意外时,数据的损失减少到尽可能的小,我们通过linux的inotify功能,监控数据文件的目录,对创建,更改操作进行监控,并将文件的路径记入到日志文件中,每一分钟备份一次更新的文件。

整个脚本的部署分为以下几个步骤:

1、升级Linux内核,使其支持inotify功能

2、安装脚本所需的Perl模块。

3、生成监控数据,运行脚本

4、定制并运行日志外理命令。

5、管理inotify脚本。


Perl中检测文件编码

| 暂无评论 | 暂无引用通告

一个脚本用于分析应用程序的日志,但是在这些日志文件中,有的编码是utf-8的,有的编码是gbk的.对于utf-8的日志文件,需要将内容转换成gbk的编码,这样看到的中文才不至于乱码:

因此,在perl脚本中加入以下行判断日志内容,如是不是gbk的编码,就对其转码:

$line=encode ("gbk",decode("utf-8",$line)) unless (detect($line) =~ /gb/);

这里用到的模块有:

use Encode;

use Encode::CN;

use Encode::Detect::Detector;

apache的基本认证的密码是通过命令htpasswd来生成的,方法如下:

[supersun@supersun.biz conf]$../bin/htpasswd -bc password supersun hello

[supersun@supersun.biz conf]$cat password

supersun:Pajgyd5fZISUs

有时手头没有htpasswd这个命令,或者给别人建个账号而不想知道别人的密码,这时我们只需要将别人发过来的密码加密串添到加password文件中就行。这里有一个perl的加密脚本crypt.pl,内容如下:

#!/usr/bin/perl

use strict;

my $passWord=$ARGV[0];

print crypt($passWord,$passWord)."\n";

运行perl crypt.pl hello

[supersun@supersun.biz ~]$ perl crypt.pl hello

heFw0NKyvGSTg

然后将加密串和账号添加到password中。

httpd.conf中的配置为如下格式

<Location />

        AuthType Basic

        AuthName "hello"

        AuthUserFile /home/apache/conf/password

        Require valid-user

</Location>

原文见http://bash.cyberciti.biz/web-server/htpasswd-replacement-perl-script/

 

tomcat http connector 参数

| 暂无评论 | 暂无引用通告
  • acceptCount - defines the maximum queue length for incoming connection requests when all possible request processing threads are in use. Any requests received when the queue is full are refused. The default value is 10.

  • bufferSize - defines the size (in bytes) of the buffer to be provided for input streams created by this connector. By default, buffers of 2048 bytes are provided.

  • maxKeepAliveRequests - the maximum number of HTTP requests that can be held in the pipeline until the connection is closed by the server. Setting this attribute to 1 disables HTTP/1.0 keep-alive, as well as HTTP/1.1 keep-alive and pipelining. Setting this to -1 allows an unlimited number of pipelined or keep-alive HTTP requests. If not specified, this attribute is set to 100.

  • maxSpareThreads - the maximum number of unused request processing threads that are allowed to exist until the thread pool starts stopping the unnecessary threads. The default value is 50.

  • maxThreads - the maximum number of request processing threads to be created by this Connector, which therefore determines the maximum number of simultaneous requests that can be handled. If not specified, this attribute is set to 200.

  • minSpareThreads - the number of request processing threads that are created when this Connector is first started. The connector will also make sure it has the specified number of idle processing threads available. This attribute should be set to a value smaller than that set for maxThreads. The default value is 4.

关于此归档

这里是2008年12月的所有日记,它们按照时间从新到老排序。

上一篇日记2008年11月

下一篇日记2009年1月

首页归档页可以看到最新的日记和所有日记。