| CODE: | [Copy to clipboard] | |
| ||
升级OpenSSH(依照最新的OpenSSL)
| CODE: | [Copy to clipboard] | |
| ||
OK,现在ssh -V看一下版本吧
|
|
用户名:clay111 笔名:clay111 地区: 行业:其他 |
| 日 | 一 | 二 | 三 | 四 | 五 | 六 |
所有文章大部分从网络上面收集,少部分为原创文章。收集的文章都是一些在工作当中对我帮助很大的文章,在这里首先对原创作者表示感谢,由于很多文章不知道具体的作者是谁,所以我一般在题目加上ZT字样,如果你是文章的原创作者,可以和我留言,我把文章的署名改成您自己。
源码升级-(OpenSSL + OpenSSH) ZT
| CODE: | [Copy to clipboard] | |
| ||
| CODE: | [Copy to clipboard] | |
| ||
apache配置虚拟机
(总是忘,记下来)
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin webmaster@5zuiai.com
DocumentRoot /usr/local/apache2/htdocs/lhjweb
ServerName www.5zuiai.com
<Directory "/usr/local/apache2/htdocs/lhjweb">
Options -Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
ErrorLog logs/5zuiai-error_log
TransferLog logs/5zuiai-access_log
</VirtualHost>
DL360服务器的SCSI安装gentoo(Z)
让卡巴挂掉的代码
gentoo 安装NTPf服务
restrict 0.asia.pool.ntp.org
restrict 1.asia.pool.ntp.org
restrict 2.asia.pool.ntp.org
restrict 3.asia.pool.ntp.org
restrict 127.0.0.1 mask 255.0.0.0
restrict 192.168.1.0 mask 255.255.255.0 nomodify
server 0.asia.pool.ntp.org
server 1.asia.pool.ntp.org
server 2.asia.pool.ntp.org
server 3.asia.pool.ntp.org
broadcastdelay 0.008
logfile /var/log/ntp.log
3、查看ntp有没有工作
ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
+arteq.com.tw 220.130.158.51 3 u 29 64 377 93.116 38.782 7.695
211.22.55.116 .INIT. 16 u - 64 0 0.000 0.000 0.000
*203.116.5.254 130.207.244.240 2 u 33 64 377 82.320 31.845 11.375
+q037240.ppp.asa 200.23.51.205 2 u 221 64 150 405.989 -117.80 40.170
ntptrace xxx.xxx.xxx.xxx
xxx.xxx.xxx.xxx: stratum 3, offset -0.029005, synch distance 0.365843
203.116.5.254: timed out, nothing received
***Request timed out
4、查看log文件
tail -f /var/log/ntp.log
12 Jul 15:35:35 ntpd[2089]: synchronized to 59.124.71.8, stratum 3
12 Jul 15:35:35 ntpd[2089]: kernel time sync status change 0001
5、启动服务
/etc/init.d/ntpd start|stop|restart
6、注意事项
服务启动之后,大约5分钟左右才能进行时间服务。看到日志文件出现同步信息,基本服务就好了, 如果过了很长时间没有同步信息或者不能提供时间服务,请检查配置文件。
参考文档:
http://linux.vbird.org/linux_server/0440ntp.php#server_ntp.conf
Local time zone must be set--see zic
cp /usr/share/zoneinfo/Europe/Chongqing /etc/localtime
是因为没有设置localtime,也就是没有自己的时区,拷贝一个就好了。
shell date日期应用(ZT)
无光驱安装gentoo
无光驱安装gentoo
原理:服务器启动,通过网络从DHCP服务器获取TFTP服务器地址,服务器从TFTP服务器下载pxelinux并且执行,pxelinux读取配置文件,从网络下载gentoo内核和引导文件,从而引导gentoo系统,系统引导成功以后,可以正常安装gentoo。
1、环境介绍
一台gentoo服务器(IP:192.168.1.251),一个交换机,一个需要安装系统的无光驱服务器
2、安装DHCP服务器
首先配置gentoo服务器,gentoo服务器需要安装配置DHCP、TFTP服务。
Emerge dhcp
安装完成之后,修改DHCP配置文件
Nano –w /etc/dhcp/dhcpd.conf
文件内容如下所示:
ddns-update-style interim;
ignore client-updates;
option space PXE;
option PXE.mtftp-ip code 1 = ip-address;
option PXE.mtftp-cport code 2 = unsigned integer 16;
option PXE.mtftp-sport code 3 = unsigned integer 16;
option PXE.mtftp-tmout code 4 = unsigned integer 8;
option PXE.mtftp-delay code 5 = unsigned integer 8;
option PXE.discovery-control code 6 = unsigned integer 8;
option PXE.discovery-mcast-addr code 7 = ip-address;
class "pxeclients" {
match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";
option vendor-class-identifier "PXEClient";
vendor-option-space PXE;
option PXE.mtftp-ip 0.0.0.0;
filename "pxelinux.0";
next-server 192.168.1.251;
}
subnet 192.168.1.0 netmask 255.255.255.0 {
option routers 192.168.1.1;
option subnet-mask 255.255.255.0;
range 192.168.1.80 192.168.1.100;
}
启动DHCP服务
/etc/init.d/dhcpd start
3、配置TFTP服务器
首先建立TFTP工作目录
Mkdir /diskless
安装TFTP软件
Emerge tftp-hpa
配置TFTP
Nano –w /etc/conf.d/in.tftpd
配置文件内容如下所示:
# /etc/init.d/in.tftpd
INTFTPD_PATH="/diskless"
INTFTPD_USER="nobody"
#INTFTPD_OPTS="-u ${INTFTPD_USER} -l -vvvvvv -p -c -s ${INTFTPD_PATH}"
INTFTPD_OPTS="-l -v -s ${INTFTPD_PATH}"
启动TFTP
/etc/init.d/in.tftpd start
4、制作gentoo网络启动文件(关键步骤)
首先下载
LiveCD+PXE-0.0.1.tar.bz2 和 install-x86-universal-2004.2.iso
Cp install-x86-universal-2004.2.iso /tmp
解压文件 LiveCD+PXE
Tar zxjpf LiveCD+PXE-0.0.1.tar.bz2
Cd LiveCD+PXE-0.0.1
修改LiveCD+PXE.sh
Vi LiveCD+PXE.sh
查找PXE_HOST和PXE_DIR 修改成自己的服务器地址
PXE_HOST="192.168.1.251"
PXE_DIR="/diskless"
. /LiveCD+PXE.sh smp init
./ LiveCD+PXE.sh smp finish
此步骤为制作gentoo网络启动文件的关键步骤(生成:smp和smp.igz文件),如果制作不成功,则无法通过网络启动gentoo
5、安装pxelinux
Emerge syslinux
cp /usr/lib/syslinux/pxelinux.0 /diskless
mkdir /diskless/pxelinux.cfg
touch /diskless/pxelinux.cfg/default
vi /diskless/pxelinux.cfg/default
内容如下:
prompt 1
timeout 10
default livecd
label livecd
kernel smp
append init=/linuxrc initrd=smp.igz ramdisk_size=80000 ip=dhcp root=/dev/ram0 looptype=squashfs loop=/livecd.squashfs cdroot PXE keymap=us
6、启动需要安装系统的服务器
启动服务器,选择通过PXE启动,尽情享受gentoo网络启动带来的乐趣吧。
注意事项:
1、启动文件为gentoo 2004版 ,linux内核是2.4,如果安装gentoo 2007 LiveCD,安装时会提示linux 内核版本太低,不能安装。只能用install-x86-universal-2004.2.iso进行安装,然后升级系统软件。
2、LiveCD+PXE-0.0.1.tar.bz2 和 install-x86-universal-2004.2.iso 安装包在192.168.1.251上面都有,有需要安装测试的可以从这上面拷贝安装。
另类安装gentoo
通过正常步骤安装gentoo
此处省略2000字安装步骤。注意事项:一定要用genkernel -all来生成系统内核,因为genkernel 生成的内核和liveCD比较类似,系统兼容性比较好。如果不用genkernel生成内核,
挂上需要安装系统的硬盘,用LiveCD启动系统
Fdisk /dev/hda
系统分区
livecd ~ # fdisk -l /dev/hda
Disk /dev/hda: 78 GB,
255 heads, 63 sectors/track, 72943 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/hda1 1 12 96358+ 83 Linux
/dev/hda2 13 110 787185 82 Linux swap / Solaris
/dev/hda3 111 72943 585031072+ 83 Linux
/hda1目录为grub 和系统启动文件
/hda3为linux系统文件
我们知道linux一切都是文件,所以我们只要把所有的文件都拷贝过来就好了。
Fdisk –l /dev/hdb (这个是需要安装系统的硬盘)
/dev/hdb1 1 12 96358+ 83 Linux
/dev/hdb2 13 110 787185 82 Linux swap / Solaris
/dev/hdb3 111 72943 585031072+ 83 Linux
Mkdir /mnt/sroot linux系统文件目录
Mkidr /mnt/sboot 启动文件目录
Mkdir /mnt/groot
Mkidr /mnt/gboot
Mount /dev/hda3 /mnt/sroot mount 原目录
Mount /dev/hda1 /mnt/sboot mount 原目录
Mount /dev/hdb3 /mnt/groot mount 目标目录
Mount /dev/hdb1 /mnt/gboot mount 目标目录
Cp –a /mnt/sroot /mnt/groot 拷贝需要安装的文件到目标目录
Cp –a /mnt/sboot /mnt/gboot 拷贝系统启动文件到目标目录
拷贝完成以后,linux系统基本安装完成。只要在目标盘重新安装grub启动就好了。
3、摘下原盘,用liveCD启动。
重新安装grub就好了。
此方法与克隆安装互有优缺点:
克隆安装,只能在两个同等大小的硬盘之间克隆,如果原盘比目标盘大,则不能用克隆方法。
克隆安装比较方便,克隆完成之后,克隆盘可直接启动。
硬盘对拷方法适用于硬盘大小不统一之间的安装linux。
vmstat 说明(ZT )
gentoo 没有加载网卡怎么办?
错误提示:
ERROR: problem starting needed services
“netmount” was not started
查看网卡型号:
lspci
察看编译了哪些模块:
ls /lib/modules/`uname -r`/kernel/drivers/net
动态加载模块:
modprobe e100
加入自动加载模块组:
nano -w /etc/modules.autoload.d/kernel-2.4
在文件里面直接写模块名字,例如:
e100 #(我这里是网卡的型号)
修改/etc/conf.modeles,没有效果。开始在google乱搜,最后仔细阅读gentoo文档,发现:
原始碼 10: 搜尋提供的模組
# ls /lib/modules/`uname -r`/kernel/drivers/net
如果您找到您的網路卡所用的驅動程式,使用 modprobe 載入這個核心模組:
原始碼 11: 使用 modprobe 載入核心模組
(舉例來說,我們將載入 pcnet32 模組)
# modprobe pcnet32
尝试modprobe不同文件,包括ne2k,8139cp。最后modprobe 8139too。安装成功!
但现在还是无法使用文档中说的net-setup,难道是目录不对,我find / 没有发现net-setup的文件名。
注册7年,首次发现一点和别人遇到的情况不同的,首次发帖。但最后解决方法还是在手册中,呵呵!还是那个道理多看手册,问题几乎都能解决。(不知道发在安装版还是gentoo,由斑竹定夺吧!)
gentoo syslog-ng的设置(ZT)
原文摘自:http://blog.sina.com.cn/u/4707c9270100075v
log对于一个系统的重要性是显而易见的,然而不幸的是我发现我的系统并没有很好地记录应该记录的东西,至少昨天半夜它自动重启了,我却找不到为什么。
安装的时候安装的syslog-ng,查了一下它的配置文件,似乎记录的东西很少,对于系统安全来说是很不够的,于是自己man了很多东西,修改了一下设置,过程如下:
1、man其实没什么用,大概我基础不好,里面说的东西我看不懂。
2、syslog-ng的配置文件在/etc/syslog-ng/syslog-ng.conf,里面似乎只记录了messeges,没有其他东西,不确信的话可以自己打开看看。
3、安全起见,先将文件备份。
4、查看syslog-ng的配置说明,参考这个例子:/usr/share/doc/syslog-ng-1.6.9/syslog-ng.conf.sample.gz,然后修改/etc/syslog-ng/syslog-ng.conf,按格式按自己的需要修改。我的修改后的文件如下:
# $Header: /var/cvsroot/gentoo-x86/app-admin/syslog-ng/files/syslog-ng.conf.gentoo,v 1.5 2005/05/12 05:46:10 mr_bones_ Exp $#
# Syslog-ng default configuration file for Gentoo Linux
# contributed by Michael Sterrett
options {
chain_hostnames(off);
sync(0);
# The default action of syslog-ng 1.6.0 is to log a STATS line
# to the file every 10 minutes. That's pretty ugly after a while.
# Change it to every 12 hours so you get a nice daily update of
# how many messages syslog-ng missed (0).
stats(43200);
};
source src { unix-stream("/dev/log"); internal(); pipe("/proc/kmsg"); };
destination authlog { file("/var/log/auth.log"); };
destination syslog { file("/var/log/syslog"); };
destination user { file("/var/log/user.log"); };
destination messages { file("/var/log/messages"); };
# By default messages are logged to tty12...
destination console_all { file("/dev/tty12"); };
# ...if you intend to use /dev/console for programs like xconsole
# you can comment out the destination line above that references /dev/tty12
# and uncomment the line below.
#destination console_all { file("/dev/console"); };
log { source(src); destination(authlog); };
log { source(src); destination(syslog); };
log { source(src); destination(user); };
log { source(src); destination(messages); };
log { source(src); destination(console_all); };
要注意的是sample文件里面有filter的内容,如果你不知道这个是干什么的,man一下syslog-ng。需要的话照sample里面的样子,先添加filter段,再在log段里面添加相应内容。如果你不需要,就象我这样,把需要log的内容直接cp进来,把filter段去掉。
修改:今天查了一下,似乎有几个log里面的内容是差不多的,syslog和auth记录了重复的东西,想必是filter没定义的缘故,于是修改如下(增加了filter段):
# $Header: /var/cvsroot/gentoo-x86/app-admin/syslog-ng/files/syslog-ng.conf.gentoo,v 1.5 2005/05/12 05:46:10 mr_bones_ Exp $#
# Syslog-ng default configuration file for Gentoo Linux
# contributed by Michael Sterrett
options {
chain_hostnames(off);
sync(0);
# The default action of syslog-ng 1.6.0 is to log a STATS line
# to the file every 10 minutes. That's pretty ugly after a while.
# Change it to every 12 hours so you get a nice daily update of
# how many messages syslog-ng missed (0).
stats(43200);
};
source src { unix-stream("/dev/log"); internal(); pipe("/proc/kmsg"); };
destination authlog { file("/var/log/auth.log"); };
destination syslog { file("/var/log/syslog"); };
destination user { file("/var/log/user.log"); };
destination messages { file("/var/log/messages"); };
# By default messages are logged to tty12...
destination console_all { file("/dev/tty12"); };
# ...if you intend to use /dev/console for programs like xconsole
# you can comment out the destination line above that references /dev/tty12
# and uncomment the line below.
#destination console_all { file("/dev/console"); };
filter f_auth { facility(auth); };
filter f_authpriv { facility(auth, authpriv); };
filter f_syslog { not facility(authpriv, mail); };
filter f_user { facility(user); };
log { source(src); filter(f_authpriv); destination(authlog); };
log { source(src); filter(f_syslog); destination(syslog); };
log { source(src); filter(f_user); destination(user); };
log { source(src); destination(messages); };
log { source(src); destination(console_all); };
设置iptables log 如下所示:
vi /etc/syslog-ng/syslog-ng.conf
destination kern { file("/var/log/iptables.log"); };
filter f_kern { facility(kern); };
log { source(src); filter(f_kern); destination(kern); };
保存退出
shell下面运行:
/etc/init.d/syslog-ng reload
iptables -A INPUT -p icmp -j LOG --log-level debug --log-prefix "This is a test!"
查看:
tail -f /var/log/iptables.log
输出类似如下:
Jun 8 19:42:02 localhost szkingrose test---------IN=eth0 OUT= MAC=00:15:58:10:6f:70:00:18:39:84:7a:bc:08:00 SRC=59.151.18.182 DST=192.168.1.251 LEN=84 TOS=0x00 PREC=0x00 TTL=51 ID=20409 PROTO=ICMP TYPE=0 CODE=0 ID=2371 SEQ=5
Jun 8 19:42:02 localhost szkingrose test---------IN=eth0 OUT= MAC=00:15:58:10:6f:70:00:1b:fc:1a:09:c7:08:00 SRC=192.168.1.122 DST=192.168.1.251 LEN=60 TOS=0x00 PREC=0x00 TTL=128 ID=59970 PROTO=ICMP TYPE=8 CODE=0 ID=512 SEQ=19727
Jun 8 19:42:03 localhost szkingrose test---------IN=eth0 OUT= MAC=00:15:58:10:6f:70:00:1b:fc:1a:09:c7:08:00 SRC=192.168.1.122 DST=192.168.1.251 LEN=60 TOS=0x00 PREC=0x00 TTL=128 ID=59973 PROTO=ICMP TYPE=8 CODE=0 ID=512 SEQ=19983
Jun 8 19:42:04 localhost szkingrose test---------IN=eth0 OUT= MAC=00:15:58:10:6f:70:00:1b:fc:1a:09:c7:08:00 SRC=192.168.1.122 DST=192.168.1.251 LEN=60 TOS=0x00 PREC=0x00 TTL=128 ID=59976 PROTO=ICMP TYPE=8 CODE=0 ID=512 SEQ=20239
博客中国实在是太滥了
用了这么长时间,也懒得搬家了,但是实在是不爽,我要骂两句。
你们的文章总数准么? 你们的文章年度文件夹文章数对么?
你们怎么测试的产品,就拿着东西出来唬人了?
博客中国实在是太滥了,什么时候新浪推出博客中国的搬家工具,我搬到新浪去。
c与mysql连接和一个简单查询的例子(ZT)
今天给新来的同事做mysql培训,用到的一个例子:
连接数据库test 用户名root密码abc
在里面有一个username的表,describe username结果如下
mysql> describe username;
+----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| id | int(10) | YES | | NULL | |
| username | varchar(32) | | PRI | | |
+----------+-------------+------+-----+---------+-------+
mysql> select * from username;
+------+----------+
| id | username |
+------+----------+
| 1 | sfs |
+------+----------+
1 row in set (0.00 sec)
[b:f09d522785]本文目的查找执行select id from username这个语句并打印结果[/b:f09d522785]
[code:1:f09d522785]
#include <unistd.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <mysql/mysql.h>
#include <signal.h>
#include <errno.h>
#include <syslog.h>
MYSQL mysql;
main()
{
char host[32]="localhost";
char user[32]="root";
char passwd[32]="abc";
char dbname[32]="test";
if( mysql_init(&mysql) == NULL )
{
syslog(LOG_USER|LOG_INFO,"inital mysql handle error\n");
return 1;
}
if (mysql_real_connect(&mysql,host,user,passwd,dbname,0,NULL,0) == NULL)
{
syslog(LOG_USER|LOG_INFO, "Failed to connect to database: Error: %s\n",mysql_error(&mysql));
return 1;
}
else syslog(LOG_USER|LOG_INFO, "connect to database: \n");
find_ps();
db_close();
return 0;
}
int db_close()
{
mysql_close(&mysql);
return 0;
}
int find_ps ()
{
MYSQL_ROW m_row;
MYSQL_RES *m_res;
char sql[1024],username[32];
int res=1;
int *id;
sprintf(sql,"select id from username");
if(mysql_query(&mysql,sql) != 0)
{
syslog(LOG_USER|LOG_INFO, "select ps_info Error: %s\n",mysql_error(&mysql));
return res;
}
m_res = mysql_store_result(&mysql);
if(m_res==NULL)
{
syslog(LOG_USER|LOG_INFO, "select username Error: %s\n",mysql_error(&mysql));
res = 3;
return res;
}
if(m_row = mysql_fetch_row(m_res))
{
printf("m_row=%d\n",atoi(m_row[0]));
res = 0;
}
mysql_free_result(m_res);
return res;
}
[/code:1:f09d522785]
编译命令
gcc -g connect_db.c -L/usr/lib/mysql -lmysqlclient -lz
注意:
如果/tmp/ccTGmMS21.o: In function `main':
/tmp/ccTGmMS21.o(.text+0x11): undefined reference to `mysql_init'
那么参数增加-L/usr/lib/mysql -lmysqlclient
如果
usr/lib/mysql/libmysqlclient.a(my_compress.o): In function `my_uncompress':
my_compress.o(.text+0xaa): undefined reference to `uncompress'
那么增加-lz参数
我自己是这么编译的 呵呵
gcc -o ttmysql ttmysql.c -L /usr/lib/mysql/lib -lmysqlclient -lz
C语言中关于时间的函数
本文从介绍基础概念入手,探讨了在C/C++中对日期和时间操作所用到的数据结构和函数,并对计时、时间的获取、时间的计算和显示格式等方面进行了阐述。本文还通过大量的实例向你展示了time.h头文件中声明的各种函数和数据结构的详细使用方法。
关键字:UTC(世界标准时间),Calendar Time(日历时间),epoch(时间点),clock tick(时钟计时单元)
1.概念
在C/C++中,对字符串的操作有很多值得注意的问题,同样,C/C++对时间的操作也有许多值得大家注意的地方。最近,在技术群中有很多网友也多次问到过C++语言中对时间的操作、获取和显示等等的问题。下面,在这篇文章中,笔者将主要介绍在C/C++中时间和日期的使用方法.
通过学习许多C/C++库,你可以有很多操作、使用时间的方法。但在这之前你需要了解一些“时间”和“日期”的概念,主要有以下几个:
Coordinated Universal Time(UTC):协调世界时,又称为世界标准时间,也就是大家所熟知的格林威治标准时间(Greenwich Mean Time,GMT)。比如,中国内地的时间与UTC的时差为+8,也就是UTC+8。美国是UTC-5。
Calendar Time:日历时间,是用“从一个标准时间点到此时的时间经过的秒数”来表示的时间。这个标准时间点对不同的编译器来说会有所不同,但对一个编译系统来说,这个标准时间点是不变的,该编译系统中的时间对应的日历时间都通过该标准时间点来衡量,所以可以说日历时间是“相对时间”,但是无论你在哪一个时区,在同一时刻对同一个标准时间点来说,日历时间都是一样的。
epoch:时间点。时间点在标准C/C++中是一个整数,它用此时的时间和标准时间点相差的秒数(即日历时间)来表示。
clock tick:时钟计时单元(而不把它叫做时钟滴答次数),一个时钟计时单元的时间长短是由CPU控制的。一个clock tick不是CPU的一个时钟周期,而是C/C++的一个基本计时单位。
我们可以使用ANSI标准库中的time.h头文件。这个头文件中定义的时间和日期所使用的方法,无论是在结构定义,还是命名,都具有明显的C语言风格。下面,我将说明在C/C++中怎样使用日期的时间功能。
2. 计时
C/C++中的计时函数是clock(),而与其相关的数据类型是clock_t。在MSDN中,查得对clock函数定义如下:
clock_t clock( void );
这个函数返回从“开启这个程序进程”到“程序中调用clock()函数”时之间的CPU时钟计时单元(clock tick)数,在MSDN中称之为挂钟时间(wal-clock)。其中clock_t是用来保存时间的数据类型,在time.h文件中,我们可以找到对它的定义:
#ifndef _CLOCK_T_DEFINED
typedef long clock_t;
#define _CLOCK_T_DEFINED
#endif
很明显,clock_t是一个长整形数。在time.h文件中,还定义了一个常量CLOCKS_PER_SEC,它用来表示一秒钟会有多少个时钟计时单元,其定义如下:
#define CLOCKS_PER_SEC ((clock_t)1000)
可以看到每过千分之一秒(1毫秒),调用clock()函数返回的值就加1。下面举个例子,你可以使用公式clock()/CLOCKS_PER_SEC来计算一个进程自身的运行时间:
void elapsed_time()
{
printf("Elapsed time:%u secs.\n",clock()/CLOCKS_PER_SEC);
}
当然,你也可以用clock函数来计算你的机器运行一个循环或者处理其它事件到底花了多少时间:
#i nclude “stdio.h”
#i nclude “stdlib.h”
#i nclude “time.h”
int main( void )
{
long i = 10000000L;
clock_t start, finish;
double duration;
/* 测量一个事件持续的时间*/
printf( "Time to do %ld empty loops is ", i );
start = clock();
while( i-- ) ;
finish = clock();
duration = (double)(finish - start) / CLOCKS_PER_SEC;
printf( "%f seconds\n", duration );
system("pause");
}
在笔者的机器上,运行结果如下:
Time to do 10000000 empty loops is 0.03000 seconds
上面我们看到时钟计时单元的长度为1毫秒,那么计时的精度也为1毫秒,那么我们可不可以通过改变CLOCKS_PER_SEC的定义,通过把它定义的大一些,从而使计时精度更高呢?通过尝试,你会发现这样是不行的。在标准C/C++中,最小的计时单位是一毫秒。
3.与日期和时间相关的数据结构
在标准C/C++中,我们可通过tm结构来获得日期和时间,tm结构在time.h中的定义如下:
#ifndef _TM_DEFINED
struct tm {
int tm_sec; /* 秒 – 取值区间为[0,59] */
int tm_min; /* 分 - 取值区间为[0,59] */
int tm_hour; /* 时 - 取值区间为[0,23] */
int tm_mday; /* 一个月中的日期 - 取值区间为[1,31] */
int tm_mon; /* 月份(从一月开始,0代表一月) - 取值区间为[0,11] */
int tm_year; /* 年份,其值等于实际年份减去1900 */
int tm_wday; /* 星期 – 取值区间为[0,6],其中0代表星期天,1代表星期一,以此类推 */
int tm_yday; /* 从每年的1月1日开始的天数 – 取值区间为[0,365],其中0代表1月1日,1代表1月2日,以此类推 */
int tm_isdst; /* 夏令时标识符,实行夏令时的时候,tm_isdst为正。不实行夏令时的进候,tm_isdst为0;不了解情况时,tm_isdst()为负。*/
};
#define _TM_DEFINED
#endif
ANSI C标准称使用tm结构的这种时间表示为分解时间(broken-down time)。
而日历时间(Calendar Time)是通过time_t数据类型来表示的,用time_t表示的时间(日历时间)是从一个时间点(例如:1970年1月1日0时0分0秒)到此时的秒数。在time.h中,我们也可以看到time_t是一个长整型数:
#ifndef _TIME_T_DEFINED
typedef long time_t; /* 时间值 */
#define _TIME_T_DEFINED /* 避免重复定义 time_t */
#endif
大家可能会产生疑问:既然time_t实际上是长整型,到未来的某一天,从一个时间点(一般是1970年1月1日0时0分0秒)到那时的秒数(即日历时间)超出了长整形所能表示的数的范围怎么办?对time_t数据类型的值来说,它所表示的时间不能晚于2038年1月18日19时14分07秒。为了能够表示更久远的时间,一些编译器厂商引入了64位甚至更长的整形数来保存日历时间。比如微软在Visual C++中采用了__time64_t数据类型来保存日历时间,并通过_time64()函数来获得日历时间(而不是通过使用32位字的time()函数),这样就可以通过该数据类型保存3001年1月1日0时0分0秒(不包括该时间点)之前的时间。
在time.h头文件中,我们还可以看到一些函数,它们都是以time_t为参数类型或返回值类型的函数:
double difftime(time_t time1, time_t time0);
time_t mktime(struct tm * timeptr);
time_t time(time_t * timer);
char * asctime(const struct tm * timeptr);
char * ctime(const time_t *timer);
此外,time.h还提供了两种不同的函数将日历时间(一个用time_t表示的整数)转换为我们平时看到的把年月日时分秒分开显示的时间格式tm:
struct tm * gmtime(const time_t *timer);
struct tm * localtime(const time_t * timer);
通过查阅MSDN,我们可以知道Microsoft C/C++ 7.0中时间点的值(time_t对象的值)是从1899年12月31日0时0分0秒到该时间点所经过的秒数,而其它各种版本的Microsoft C/C++和所有不同版本的Visual C++都是计算的从1970年1月1日0时0分0秒到该时间点所经过的秒数。
4.与日期和时间相关的函数及应用
在本节,我将向大家展示怎样利用time.h中声明的函数对时间进行操作。这些操作包括取当前时间、计算时间间隔、以不同的形式显示时间等内容。
4.1 获得日历时间
我们可以通过time()函数来获得日历时间(Calendar Time),其原型为:
time_t time(time_t * timer);
如果你已经声明了参数timer,你可以从参数timer返回现在的日历时间,同时也可以通过返回值返回现在的日历时间,即从一个时间点(例如:1970年1月1日0时0分0秒)到现在此时的秒数。如果参数为空(NUL),函数将只通过返回值返回现在的日历时间,比如下面这个例子用来显示当前的日历时间:
#i nclude "time.h"
#i nclude "stdio.h"
int main(void)
{
struct tm *ptr;
time_t lt;
lt =time(NUL);
printf("The Calendar Time now is %d\n",lt);
return 0;
}
运行的结果与当时的时间有关,我当时运行的结果是:
The Calendar Time now is 1122707619
其中1122707619就是我运行程序时的日历时间。即从1970年1月1日0时0分0秒到此时的秒数。
4.2 获得日期和时间
这里说的日期和时间就是我们平时所说的年、月、日、时、分、秒等信息。从第2节我们已经知道这些信息都保存在一个名为tm的结构体中,那么如何将一个日历时间保存为一个tm结构的对象呢?
其中可以使用的函数是gmtime()和localtime(),这两个函数的原型为:
struct tm * gmtime(const time_t *timer);
struct tm * localtime(const time_t * timer);
其中gmtime()函数是将日历时间转化为世界标准时间(即格林尼治时间),并返回一个tm结构体来保存这个时间,而localtime()函数是将日历时间转化为本地时间。比如现在用gmtime()函数获得的世界标准时间是2005年7月30日7点18分20秒,那么我用localtime()函数在中国地区获得的本地时间会比世界标准时间晚8个小时,即2005年7月30日15点18分20秒。下面是个例子:
#i nclude "time.h"
#i nclude "stdio.h"
int main(void)
{
struct tm *local;
time_t t;
t=time(NUL);
local=localtime(&t);
printf("Local hour is: %d\n",local->tm_hour);
local=gmtime(&t);
printf("UTC hour is: %d\n",local->tm_hour);
return 0;
}
运行结果是:
Local hour is: 15
UTC hour is: 7
4.3 固定的时间格式
我们可以通过asctime()函数和ctime()函数将时间以固定的格式显示出来,两者的返回值都是char*型的字符串。返回的时间格式为:
星期几 月份 日期 时:分:秒 年\n\0
例如:Wed Jan 02 02:03:55 1980\n\0
其中\n是一个换行符,\0是一个空字符,表示字符串结束。下面是两个函数的原型:
char * asctime(const struct tm * timeptr);
char * ctime(const time_t *timer);
其中asctime()函数是通过tm结构来生成具有固定格式的保存时间信息的字符串,而ctime()是通过日历时间来生成时间字符串。这样的话,asctime()函数只是把tm结构对象中的各个域填到时间字符串的相应位置就行了,而ctime()函数需要先参照本地的时间设置,把日历时间转化为本地时间,然后再生成格式化后的字符串。在下面,如果t是一个非空的time_t变量的话,那么:
printf(ctime(&t));
等价于:
struct tm *ptr;
ptr=localtime(&t);
printf(asctime(ptr));
那么,下面这个程序的两条printf语句输出的结果就是不同的了(除非你将本地时区设为世界标准时间所在的时区):
#i nclude "time.h"
#i nclude "stdio.h"
int main(void)
{
struct tm *ptr;
time_t lt;
lt =time(NUL);
ptr=gmtime(<);
printf(asctime(ptr));
printf(ctime(<));
return 0;
}
运行结果:
Sat Jul 30 08:43:03 2005
Sat Jul 30 16:43:03 2005
4.4 自定义时间格式
我们可以使用strftime()函数将时间格式化为我们想要的格式。它的原型如下:
size_t strftime(
char *strDest,
size_t maxsize,
const char *format,
const struct tm *timeptr
);
我们可以根据format指向字符串中格式命令把timeptr中保存的时间信息放在strDest指向的字符串中,最多向strDest中存放maxsize个字符。该函数返回向strDest指向的字符串中放置的字符数。
函数strftime()的操作有些类似于sprintf():识别以百分号(%)开始的格式命令集合,格式化输出结果放在一个字符串中。格式化命令说明串strDest中各种日期和时间信息的确切表示方法。格式串中的其他字符原样放进串中。格式命令列在下面,它们是区分大小写的。
%a 星期几的简写
%A 星期几的全称
%b 月分的简写
%B 月份的全称
%c 标准的日期的时间串
%C 年份的后两位数字
%d 十进制表示的每月的第几天
%D 月/天/年
%e 在两字符域中,十进制表示的每月的第几天
%F 年-月-日
%g 年份的后两位数字,使用基于周的年
%G 年分,使用基于周的年
%h 简写的月份名
%H 24小时制的小时
%I 12小时制的小时
%j 十进制表示的每年的第几天
%m 十进制表示的月份
%M 十时制表示的分钟数
%n 新行符
%p 本地的AM或PM的等价显示
%r 12小时的时间
%R 显示小时和分钟:hh:mm
%S 十进制的秒数
%t 水平制表符
%T 显示时分秒:hh:mm:ss
%u 每周的第几天,星期一为第一天 (值从0到6,星期一为0)
%U 第年的第几周,把星期日做为第一天(值从0到53)
%V 每年的第几周,使用基于周的年
%w 十进制表示的星期几(值从0到6,星期天为0)
%W 每年的第几周,把星期一做为第一天(值从0到53)
%x 标准的日期串
%X 标准的时间串
%y 不带世纪的十进制年份(值从0到99)
%Y 带世纪部分的十进制年份
%z,%Z 时区名称,如果不能得到时区名称则返回空字符。
%% 百分号
如果想显示现在是几点了,并以12小时制显示,就象下面这段程序:
#i nclude “time.h”
#i nclude “stdio.h”
int main(void)
{
struct tm *ptr;
time_t lt;
char str[80];
lt=time(NUL);
ptr=localtime(<);
strftime(str,100,"It is now %I %p",ptr);
printf(str);
return 0;
}
其运行结果为:
It is now 4PM
而下面的程序则显示当前的完整日期:
#i nclude <stdio.h>
#i nclude <time.h>
void main( void )
{
struct tm *newtime;
char tmpbuf[128];
time_t lt1;
time( <1 );
newtime=localtime(<1);
strftime( tmpbuf, 128, "Today is %A, day %d of %B in the year %Y.\n", newtime);
printf(tmpbuf);
}
运行结果:
Today is Saturday, day 30 of July in the year 2005.
4.5 计算持续时间的长度
有时候在实际应用中要计算一个事件持续的时间长度,比如计算打字速度。在第1节计时部分中,我已经用clock函数举了一个例子。Clock()函数可以精确到毫秒级。同时,我们也可以使用difftime()函数,但它只能精确到秒。该函数的定义如下:
double difftime(time_t time1, time_t time0);
虽然该函数返回的以秒计算的时间间隔是double类型的,但这并不说明该时间具有同double一样的精确度,这是由它的参数觉得的(time_t是以秒为单位计算的)。比如下面一段程序:
#i nclude "time.h"
#i nclude "stdio.h"
#i nclude "stdlib.h"
int main(void)
{
time_t start,end;
start = time(NUL);
system("pause");
end = time(NUL);
printf("The pause used %f seconds.\n",difftime(end,start));//<-
system("pause");
return 0;
}
运行结果为:
请按任意键继续. . .
The pause used 2.000000 seconds.
请按任意键继续. . .
可以想像,暂停的时间并不那么巧是整整2秒钟。其实,你将上面程序的带有“//<-”注释的一行用下面的一行代码替换:
printf("The pause used %f seconds.\n",end-start);
其运行结果是一样的。
4.6 分解时间转化为日历时间
这里说的分解时间就是以年、月、日、时、分、秒等分量保存的时间结构,在C/C++中是tm结构。我们可以使用mktime()函数将用tm结构表示的时间转化为日历时间。其函数原型如下:
time_t mktime(struct tm * timeptr);
其返回值就是转化后的日历时间。这样我们就可以先制定一个分解时间,然后对这个时间进行操作了,下面的例子可以计算出1997年7月1日是星期几:
#i nclude "time.h"
#i nclude "stdio.h"
#i nclude "stdlib.h"
int main(void)
{
struct tm t;
time_t t_of_day;
t.tm_year=1997-1900;
t.tm_mon=6;
t.tm_mday=1;
t.tm_hour=0;
t.tm_min=0;
t.tm_sec=1;
t.tm_isdst=0;
t_of_day=mktime(&t);
printf(ctime(&t_of_day));
return 0;
}
运行结果:
Tue Jul 01 00:00:01 1997
现在注意了,有了mktime()函数,是不是我们可以操作现在之前的任何时间呢?你可以通过这种办法算出1945年8月15号是星期几吗?答案是否定的。因为这个时间在1970年1月1日之前,所以在大多数编译器中,这样的程序虽然可以编译通过,但运行时会异常终止。
freebsd安装及安全设置
| ||||
vsftp配置大全
LAMP优化(ZT)
I started to write this post many weeks ago and finally publish it even if it’s not totally finish. It is just a little feedback about tuning a full LAMP server with some user traffic and services load. Important thing to notice is that all stuff in this post is NOT THE SOLUTION. You will probably have to tune little more for adapt all this to your personal server usage, server load, development & architecture. So, use those tips as a kind of inspiration instead of an “how to”. Don’t forget that when you do such tuning, take care to keep a backup of your previous configuration files.
We will try to tune the following server :
The best way for tuning a server is to have dedicated services on one
server and so, having multiple server especially for MySQL and Apache.
We were runing a heavy website with DotClear and the heavy PhpADS with all its stuff (geoip, all counters, etc.)
The server up to a load of 114 in some peak with a swap totally used !
And so.. a big freeze of services… 70k mails/day , 110k pv/day, 12k
v/day, 47 sql queries/sec
In fact, services weren’t so loaded but the box was crashing a lot and swapping often without using too much CPU.
First
things that I do was to change the Linux Kernel from a 2.4.32 to a
2.6.18. Lot of things were improves in 2.6. I convey you to take a look
at this post on IBM :
http://www-128.ibm.com/developerworks/linux/library/l-web26/
After
this update, I take the time to update all version software for using a
MySQL 5.0.27, PHP 5.2 etc. Without looking at the changelogs, bugfixes
will still help us :-)
After this, we will tune our software configuration that still use
default values (this is really bad ! :) then we will tune a little the
kernel without recompile a new one.
Our HTTPD
is using some modules as url rewriting, server info, php5, GeoIP and
other basic modules. We could optimize much more by using an Apache
2.2.3 Worker and only useful modules or even more delivering static
pages and using proxy for dynamic pages. All this depend on your
developments and your server usage. Here we will only focus on the
Apache Prefork.
Nowadays, it’s important to keep active the KEEPALIVE
functionality. This will increase the speed of delivring pages for lot
of modern browsers (it’s supported by ie, firefox, safari, opera,
etc.). The only thing is to touch a little to the default value. In
fact, if your keepalive time out is too big, you will keep an entire
apache slot open for a user that is probably gone ! A 4 seconds timeout
is enough for delivering a full web page and take care of any network
congestion. MaxKeepAliveRequests is used to define the maximum number
of request manage by an apache slot during a keepalive session. Except
if you have lot of pictures to load on your web pages you don’t really
need to have a big value at this state.
KeepAlive On
KeepAliveTimeout 4
MaxKeepAliveRequests 500
As I don’t have lot of memory available on the server I ‘m constraint to decrease drastically the number of running servers from 150 to 60. As I have an apache using approximatly 13Mo of memory (withdraw 3Mo of shared memory), I need approximately 600 Mo of available memory when all the apache child process are running. We have to consider, for our further tuning, that this memory is used. It’s really important in our case to dedicate memory for avoid to swap too much and lost the box in a freeze. you can follow your memory usage by using TOP and looking for your apache/httpd process. (Do a quick “man top” for know more). If you have little more free memory you can take a look to the apache documentation for further tuning.
ServerLimit 60
MaxClients 60
Our server is often overload, with lot of traffic. When I need to restart the apache, or in case of any crashes the apache server start with only 5 Child server process and will add new one 1 second later, 2 new child 2 second later, 4 new at the third second, etc. It’s really too long when you are in a peak ! So, I configured StartServers for let us start directly with 30 child Server process. That will help us to deliver quickly the clients and minimize the impact of the server restart.
MinSpareServers and MaxSpareServers is used in same way as StartServer. When your apache server isn’t load, there is idle child waiting for connection. It’s not usefull to have all your child still open but, In case of a new peak the best way to minimize its impact on your server is to deliver web pages as quick as possible. So keeping some idle Child Process still waiting for client isn’t so stupid. Furthermore in case of our touchy server we consider to be able to allocate 600Mo of RAM. So, We can use it even if it’s for idle Child Process as we dedicate this RAM for apache. For avoid any module Memory Leak, and having fully available Child I set the MaxRequestPerChild to 1000, that mean that each 1000 request, the child will be kill and Apache Server will spare a new one. You’ll probably have to set this value to a higher number. It’s depend of the structure of your web page. You will have to monitor a little your server after those change for being sure to don’t have too much child kill/spare instead of delivering web pages.
StartServers 30
MinSpareServers 30
MaxSpareServers 30
MaxRequestsPerChild 1000
Follow some security issue, we don’t display too much information about our server. As we don’t need the reverse lookup on the client ip, we keep the default value of HostnameLookups to Off and by this way we save some network traffic and server load.
ServerTokens Prod
ServerSignature Off
HostnameLookups Off
For perform our page generation and save some cpu we use the php extension eaccelerator. Take a look at the documentation for install it.
We dedicate 32Mo of our RAM for eaccelerator (shm_size) and will use it with shared memory and file cache (”shm_and_disk”
value for keys, sessions and content variable). (Memory is really
useful in our case, because of all the mails, apache log and MySQL disk
access that generate too much i/o and slow down considerably all the
server). As we don’t change often the php script on the server we don’t
need to use the check_mtime functionality. When set
to “1″, that will do a stat on the php script for checking of last
modification date We don’t need this because we want to save disk
access and we don’t have so many updates on the running scripts. We
just have to clean the cache directory after an update.
eaccelerator.shm_size=”32″
eaccelerator.cache_dir=”/www/tmp/eaccelerator”
eaccelerator.enable=”1″
eaccelerator.optimizer=”1″
eaccelerator.check_mtime=”0″
eaccelerator.debug=”0″
eaccelerator.filter=”"
eaccelerator.shm_max=”0″
eaccelerator.shm_ttl=”3600″
eaccelerator.shm_prune_period=”1″
eaccelerator.shm_only=”0″
eaccelerator.compress=”1″
eaccelerator.compress_level=”9″
eaccelerator.keys = “shm_and_disk”
eaccelerator.sessions = “shm_and_disk”
eaccelerator.content = “shm_and_disk”
As I don’t manage how has been coding many of running script, I decrease all the timeout MySQL connection for avoid congestion. Then I increase the number off simultaneous MySQL connection as we had lot of “Too many connection” error message.
wait_timeout=6
connect_timeout=5
interactive_timeout=120
max_connections = 500
max_user_connections = 500
Now we change the touchiest part of the MySQL configuration : The RAM usage. It’s touchy because a bad value can really decrease your server performance and result in a big server swap. After some test I decrease the table cache and the key buffer cache to 256Mo. In fact we don’t have so many available ram as we had 600Mo for our HTTPD and we have lot of other services running. I tried to set it up little higher, hopping that the swap won’t be to big, but in fact, due to our i/o load the swap were totaly not a good thing for MySQL :-)
If you are using MYISAM tables I suggest you to use the “concurrent_insert=2” that will really increase your server performance in many case. MYISAM use table lock, with concurrent insert, the engine will sometime bypass the lock and allow INSERT and SELECT to run concurrently. We also disable all engine that is not used (innodb, bdb). Take a look at the MySQL documentation for better tuning.
join_buffer_size=1M
sort_buffer_size=1M
read_buffer_size=1M
read_rnd_buffer_size=1M
table_cache=256M
max_allowed_packet=4Mkey_buffer=256M
key_buffer_size=256M
thread_cache=256M
thread_concurrency=2
thread_cache_size=40
thread_stack=128Kconcurrent_insert=2
query_cache_limit=1M
query_cache_size=256M
query_cache_type=1
skip-bdb
skip-innodb
Here is a touchy part of our tuning, we will try to perform the Linux Kernel behavior with our server load for save some memory and avoid too much swap. Furthermore, has we done a great stuff above this part, we have to manage more TCP connection and support correctly the peak. We will use the command “sysctl” for doing our update on values.
# display value of a variable or group of variable
sysctl [-n] [-e] variable …
# set a new value toe the specified variable
sysctl [-n] [-e] [-q] -w variable=value …
# display all the variable
sysctl [-n] [-e] -a
# load a sysctl config file
sysctl [-n] [-e] [-q] -p (default /etc/sysctl.conf)
For our test we will create a test config file “/etc/sysctl.conf.testing” and we will load it by using the following command line :
sysctl -p /etc/sysctl.conf.testing
When
you will be glad of your change you could rename the file for
“/etc/sysctl.conf”. All the sysctl variable are documented with the
Kernel Sources. I suggest you to download the documentation corresponding to your kernel version and read it carefully if you decide to change some values.
A really good article on Security Focus give us some key for minimize the impact of a SYN ATTACK / SYN SPOOFING. In this goal we activate the syncookies and the route validation
net.ipv4.conf.default.rp_filter=1
net.ipv4.tcp_syncookies=1
net.ipv4.tcp_synack_retries=3
net.ipv4.tcp_syn_retries=3
As we had some swap troubles, important thing to do is to change the value of vm.swappiness where the default value is 60. This variable control how much the kernel should favor swapping out applications, its value can be 0 to 100. I set it to 10 for minimize the swap.
vm.swappiness=10
We upgrade the max backlog for support more TCP traffic and we change the congestion control algorithm to BIC. The Linux Kernel support lot of congestion algorithm like Reno (default one), htcp, vegas, westwood, etc.
net.core.netdev_max_backlog=2500 # Interface buffering
net.ipv4.tcp_max_syn_backlog=4096
net.core.somaxconn=1024 # Limit of socket listen() backlog. Default is 128.
net.ipv4.tcp_congestion_control=bic
For avoid to have a big TCP queue and so memory usage for not really active connection I decrease some TCP timeout and force the kernel to recycle quickly tcp connection. We don’t cache the value of ssthresh (Slow Start Threshold) for avoid to impact a given host to have a reduced ssthresh for all is next connections.
net.ipv4.tcp_keepalive_time=900
net.ipv4.tcp_fin_timeout=30
net.ipv4.tcp_max_orphans=16384
net.ipv4.tcp_tw_reuse=1
net.ipv4.tcp_tw_recycle=1
net.ipv4.tcp_rfc1337=1
net.ipv4.tcp_no_metrics_save=1
It’s critical to use the optimal SEND and RECEIVE socket buffer size for the link you are using. In our case we have a 100Mbits link connection. So for a better TCP connection and congestion control we had to increase the TCP Buffer. You can read more about this here.
net.core.rmem_max=16777216
net.core.wmem_max=16777216
net.ipv4.tcp_rmem=4096 87380 16777216
net.ipv4.tcp_wmem=4096 65536 16777216
Now, this server support twice more traffic load. Technical aspect was our traffic growth bottleneck. Lot of other tuning could be done for better performance (on i/o and disk access, other kernel options, compile a new kernel, using apache worker, etc.). This post was just some clues about how to tune your servers. One important thing to don’t forget is whatever you tune on your server, that will never be enough if you have a bloody developed programs running on it !
gentoo安装手册
step by step amd64 installation :
http://www.gentoo.org/doc/en/handbook/handbook-amd64.xml
attached our installation notes for w1 & w2.
a few more important notes for you :
- we don't install X-window, only terminal based
- take special care to the "CFLAGS" setting in make.conf , this discussion
suggested use "-march=nocona -O2 -pipe" http://forums.gentoo.org/viewtopic.php?t=225828
- we should use the "sys-kernel/hardened-sources" instead of general sys-kernel/gentoo-sources
- for file system , i think we should use reiser4 instead of ext3
- at /usr/src/linux, when you select kernal configuration,
in "Processor type and features" -> High Memory Support ->
you should choose the value higher than 4GB
========================================================
Gentoo setup
1. boot from CD-ROM
2. Testing the network
3. using the DHCP "dhcpcd eth0"
4. fdisk "fdisk /dev/sda"
3 paritions (32M sda1, 8G sda2, remaining sda3)
5. Making filesystem
# mke2fs /dev/hda1
# mke2fs -j /dev/hda3
# mkswap /dev/hda2
# swapon /dev/hda2
6. Mount the system
# mount /dev/hda3 /mnt/gentoo
# mkdir /mnt/gentoo/boot
# mount /dev/hda1 /mnt/gentoo/boot
7. Deploy stageTar
#links2 http://www.gentoo.org/main/en/mirrors.xml 选择下载一个stage3包
cd /mnt/gentoo
# tar xvjpf /mnt/cdrom/stages/stage3-
8. Deploy portage
# tar xvjpf /mnt/gentoo/portage-
9. vi /mnt/gentoo/etc/make.conf
add CFLAGS="-march=k8 -pipe -O2"
add MAKEOPTS="-j3"
10. chroot
# mirrorselect -i -o >> /mnt/gentoo/etc/make.conf
# mirrorselect -i -r -o >> /mnt/gentoo/etc/make.conf
11. Copy DNS
# cp -L /etc/resolv.conf /mnt/gentoo/etc/resolv.conf
# mount -t proc none /mnt/gentoo/proc
# mount -o bind /dev /mnt/gentoo/dev
12. chroot
chroot /mnt/gentoo /bin/bash
# env-update
# source /etc/profile
# export PS1="(chroot) $PS1"
13. emerge --sync or emerge --sync --quiet 后面选项可以加速
14. vi /etc/make.conf
add USE="-X" #remove X
15. get Hardened Kernel/Gentoo Kernel
USE="-doc symlink" emerge hardened-sources/gentoo-sources
16. Compile kernel
cd /usr/src/linux
make menuconfig
make && make modules_install
cp arch/x86_64/boot/bzImage /boot/kernel-2.6.17-gentoo-r5
17. update filesystem
nano -w /etc/fstab
----------------------------------------------------------------
/dev/sda1 /boot ext2 defaults,noatime 1 2
/dev/sda2 none swap sw 0 0
/dev/sda3 / ext3 noatime 0 1
none /proc proc defaults 0 0
none /dev/shm tmpfs nodev,nosuid,noexec 0 0
/dev/cdroms/cdrom0 /mnt/cdrom auto noauto,user 0 0
----------------------------------------------------------------
18. update hostname
nano -w /etc/conf.d/hostname
nano -w /etc/conf.d/domainname
rc-update add domainname default
nano -w /etc/conf.d/net
add >> config_eth0=( "dhcp" )
add >> config_eth1=( "dhcp" )
# rc-update add net.eth0 default
# cd /etc/init.d
# ln -s net.eth0 net.eth1
# rc-update add net.eth1 default
19. System tools
emerge app-admin/mcelog
# emerge syslog-ng
# rc-update add syslog-ng default
rc-update add sshd default
emerge sys-apps/slocate
emerge dhcpcd
emerge app-admin/sudo
emerge vim
emerge grub
# grub
grub> root (hd0,0) (指出你的/boot分区的位置)
grub> setup (hd0) (安装GRUB到MBR)
grub> quit (退出GRUB shell
20.
nano -w /boot/grub/grub.conf
--------------------------------------------
# Which listing to boot as default. 0 is the first, 1 the second etc.
default 0
# How many seconds to wait before the default listing is booted.
timeout 30
# Nice, fat splash-image to spice things up :)
# Comment out if you don't have a graphics card installed
splashimage=(hd0,0)/boot/grub/splash.xpm.gz
title=Gentoo Linux 2.6.17-r5
# Partition where the kernel image (or operating system) is located
root (hd0,0)
kernel /boot/kernel-2.6.17-gentoo-r5 root=/dev/hda3
title=Gentoo Linux 2.6.17-r5 (rescue)
# Partition where the kernel image (or operating system) is located
root (hd0,0)
kernel /boot/kernel-2.6.17-gentoo-r5 root=/dev/hda3 init=/bin/bb
--------------------------------------------
21.
grub
grub> root (hd0,0) (指出你的/boot分区的位置)
grub> setup (hd0) (安装GRUB到MBR)
grub> quit (退出GRUB shell)
22. passwd for root
23. exit
cd
umount /mnt/gentoo/boot /mnt/gentoo/dev /mnt/gentoo/proc /mnt/gentoo
reboot
24. add user
# useradd -m -G users,wheel,audio -s /bin/bash john
# passwd john
Change default editor
vi /etc/rc.conf
25. vi /etc/make.conf
add USE="-X -alsa -avi -cups -fortran -gnome -gtk -gtk2 -ipv6 -kde -mp3 -mpeg -opengl -quicktime -xv apache2"
26. emerge apache
27. enable usertrack and rewrite modules
vi /etc/conf.d/apache2
add "-D REWRITE -D USERTRACK"
28.
USE="sockets mysql cjk ctype curl apache2 berkdb cli crypt gdbm iconv ipv6 ncurses nls pcre readline reflection session spl ssl unicode zlib exif xml json snmp gd" emerge -av dev-lang/php
ACCEPT_KEYWORDS="~x86" emerge -av dev-php5/pecl-memcache
emerge -v dev-lang/php
29. install apachetop
emerge app-admin/apachetop
30. install qmail
emerge --unmerge mail-mta/ssmtp
emerge mail-mta/qmail
* To start qmail at boot you have to add svscan to your startup
* and create the following links:
* ln -s /var/qmail/supervise/qmail-send /service/qmail-send
* ln -s /var/qmail/supervise/qmail-smtpd /service/qmail-smtpd
rc-update add svscan default
31. compile ado extension
-remember to add "-march=k8" at the compilation
32. install ADO library code
emerge dev-php/adodb
33. install imagemagick
emerge media-gfx/imagemagick
所有碰到的问题,基本都是编译内核的问题.编译内核需要非常小心.
gentoo安装iptables注意事项
用rsync实现网站镜像和备份(ZT)
#/usr/local/rsync/bin/rsync -vzrtopg –progress –delete rsync_user@192.168.0.2::rsync_module_name1 /tmp/
Password:
或者你也可以制定password文件
由于需要系统crontab执行,所以这里采用读入密码文件的方式,
这个时候就成功了。
mysql的open file limit(ZT)
| 原文出处:http://haka.sharera.com/blog/BlogTopic/23115.htm |
|
| 在某几个月黑风高的晚上某个项目的MYSQL服务器在无数疯狂爬虫的折磨下,无奈的拒绝了他们,报出了这样的错误。 060907 2:45:26 [ERROR] /usr/××××/mysql5/bin/mysqld: Can't open file: './datab/abc.frm' (errno: 24) 一般来说,出现这种错误的MYSQL意味着他再也没有权限打开更多的文件了。意味着超出了运行这个程序的用户 即MYSQL这个用户的最大文件句柄数。可以查看如下 #ulimit -a 一般的LINUX安装缺省是1024个句柄。那么一个MYSQL服务器需要用到多少文件句柄呢? 和文件句柄数相关的MYSQL变量有table_cache, 每个表的打开需要两个文件描述符,一个数据文件一个索引文件。一个表在同一或者多个线程中多次被访问的话那么将多次 被打开。每次打开还将在缓冲中请求一个表目。 假如我们的table_cache=128,max_connections=1000,那么如果每个最大的情况下我们有12万的表缓冲。当然实际情况不 一定那么糟糕,我们还是计算实际情况好一点。 假设有1000个并发链接,每个连接平均打开5个表,那么共需要10个文件描述符。总共需要1万个文件描述符。如果某个操作 过多,那么肯定超出1万个。 解决方案就是修改ULIMIT. #vi /etc/secrity/limits.conf 增加 * soft nofile 100000 LINUX 系统的文件限制是 # cat /proc/sys/fs/file-max 也可以用ulimit -n 来设置一下,不过不能超过上面的软限制100000。 设置好这些后,重起MYSQL。MYSQL的文档里边自己说的系统变量open_files_limit 好像是不能设置的。只能通过命令行的方式来。 | |
apache安全模块 mod_security (ZT)
原文出处:http://www.modsecurity.or/download/index.htmlIntroducing mod_securityModSecurity is an Apache module that adds intrusion detection and prevention features to the Web server. In principle it is similar to an IDS you would use to analyse your network traffic, except that it works on the HTTP level and understands it really well. Because of this it allows you to do things that are normal from the HTTP point of view but are difficult to do from an classical IDS. This difference will become clearer later when we examine several examples of what mod_security can do.In addition to detection, mod_security also supports attack prevention. Because it stands between the client and the server, if it finds that the request contains a malicious payload it can reject the request, performing any of a number of built-in actions. As it is a module like any other, you can use mod_security as part of any Apache installation. The overhead that comes from additional processing can be negligible when it is configured properly. However, if you take into account that an incident is much more costly and that mod_security can also protect you from attacks the overhead becomes insignificant. So, how is mod_security helpful? We can't go into exhaustive detail on all the capabilities, but here is a short overview of what is happening on every request (for more details go to the mod_security Website and download the reference manual):
The request is then allowed to reach the handler where it executes. After the request:
Installation and configurationInstallation is surprisingly simple. We will assume that the server you want to protect is using the private address 192.168.254.10, and that you have configured the public domain name (www.modsecurity.org) to point to the reverse proxy server.On the reverse proxy you need to install the Apache 2 Web server, making sure you compile in mod_proxy, mod_proxy_http, and mod_security. We will not spend time on this step assuming you are already familiar with it. If not, have a look at the related links section where you will find links to a couple of very good articles covering the Apache installation process. It would also be a good idea to add mod_rewrite to the module mix since it can work in tandem in mod_proxy significantly increasing what you can do. Although any Web server can become a reverse proxy simply by adding the modules I mentioned above it is not recommended to mix the two roles together. The reverse proxy will be the only server exposed to the public and you will want to minimize the amount of code it contains, to minimize the risk of exploitable vulnerabilities. Apache 2.x is a better choice for a reverse proxy because it contains the new filtering API, allowing modules to see and interact with the request body as it comes in and with the response as it comes out. This is important for an application gateway since it must check the information that passes through before it reaches the recipient. Once you have the proxy installed here is how you will configure a virtual host:
Practical examplesIn this section I will demonstrate what the typical mod_security rule set looks like. You should always start with rules that have a broad scope, leading to more specific issues. All mod_security rules (and configuration options) can be applied on the per-virtual host or per-directory basis so you can have areas with completely different security configurations.Detecting common attacksThese rules will target the common Web application attacks:
Protecting a vulnerable scriptSome PHP applications are vulnerable when a register_globals configuration option is turned on, allowing attackers to set an internal variable to a value of their choice. This usually leads to attacker executing some code on the server. Here is an example from the real world (Cafelog b2, http://www.securityfocus.com/bid/7786):
Protecting from XSS attacks through the PHP session cookiePHP versions prior to 4.3.2 are vulnerable to XSS attacks carried out through the session identifier (http://www.securityfocus.com/bid/7761). If you can't upgrade your PHP version to the latest version you can still protect yourself:
Stop FormMail from being used to send spamSome versions of FormMail can be used to send email to arbitrary email addresses. The following rule demonstrates how you can have a filter applied only to certain locations, in this case just the FormMail script. The request will be rejected if the email is intended to any address except the one ending in "@modsecurity.org":
Restrict administrative login to an IP addressHere is a nice one. I have this application where the administrator logs in through the same log in panel as other users, but I still wanted to restrict administration login to certain IP addresses. So I used two chained rules. The second rule will apply only if the first rule matches; in this case - if the incoming username is "admin".
Preventing information leakIn all versions of PHP, if a fatal error occurs the script will be terminated immediately (standard error handling routine will not be invoked). Information leak through these problems can be prevented by scanning the output and preventing it from reaching the user if it contains error messages.
Detecting intrusionsOutput filtering can also be used to detect successful intrusions. These rules will monitor output and detect typical keywords resulting from a command execution on the server.
OtherWhat other rules you may find useful depends on the types of applications and Web servers you have behind the reverse proxy. On the mod_security Website you can find a large number of rules automatically converted from Snort rules. Download the list and simply remove the rules that do not apply.ConclusionThis article has just scratched the surface of a complex issue. I suggest that you browse through the related links section, as it contains a list of Websites, tools, and papers that you can use to familiarize yourself with other aspects we did not cover here, such as reverse proxy load balancing and clustering or transparent reverse proxy configuration. Going the other way, download the mod_security reference manual and get to know its features. It also contains other features not mentioned here. Finally, contact me to request new mod_security features if you have a need that is not covered by what already exists. | ||||||||
Relevant Links Apache Software Foundation, "Apache Web server" Apache Software Foundation, "Apache module mod_proxy" Ivan Ristic, "Apache Module mod_security" Apache Software Foundation, "Apache module mod_rewrite" Artur Maj, "Securing Apache: Step-by-Step" Lynda L. Morrison, "Perimeter Defense-in-Depth: Using Reverse Proxies and other tools to protect our internal assets" (PDF) Peter Sommerlad, "Reverse Proxy Patterns" |
MySQL 自带的 slow log 分析工具 mysqldumpslow(ZT)
Adodb 官方介绍
当你需要确保你程序的可移植性的时候,一个叫做 ADODB 的数据库封包链接库已经出现了。它提供了共通的应用程序接口来跟所有支持的数据库沟通,因此你无须放弃!
ADODB是Active Data Object DataBase的缩写(很抱歉!玩计算机的有时候不是很有原创性)。ADODB目前支持MySQL、PostgreSQL、Oracle、Interbase、Microsoft SQL Server、Access、FoxPro、Sybase、ODBC及ADO,你可以从 http://php.weblogs.com/adodb下载 ADODB。
MySQL的例子
PHP中最通用的数据库是MySQL,所以我想你会喜欢下面的程序代码,它连结到 localhost
的 MySQL 服务器,数据库名称是 mydab,并且执行一个 SQL 的 select 指令查询,查询结果会一列列地印出来。
$db = mysql_connect("localhost", "root",
"password");
mysql_select_db("mydb",$db);
$result = mysql_query("SELECT * FROM employees",$db);
if
($result === false) die("failed");
while ($fields
= mysql_fetch_row($result)) {
for ($i=0, $max=sizeof($fields); $i < $max;
$i++) {
print $fields[$i].' ';
}
print
"<br>n";
}
上列的程序代码用颜色标出分段,第一段是连结的部分,第二段是执行SQL指令,最后一段则是显示字段,while循环扫描结果的每一列,而for循环扫描到每列的字段。
接下来是以ADODB的程序代码得到同样的结果:
include("adodb.inc.php");
$db =
NewADOConnection('mysql');
$db->Connect("localhost", "root", "password",
"mydb");
$result = $db->Execute("SELECT * FROM
employees");
if ($result === false) die("failed");
while (!$result->EOF) {
for ($i=0,
$max=$result->FieldCount(); $i < $max; $i++)
print
$result->fields[$i].' ';
$result->MoveNext();
print
"<br>n";
}
现在改成指向Oracle数据库,程序代码只要修改第二行成为 NewADOConnection('oracle'),让我们看一下完整的程序代码...
与数据库连结
include("adodb.inc.php");
$db =
NewADOConnection('mysql');
$db->Connect("localhost", "root", "password",
"mydb");
连结的程序代码比起原来MySQL的程序代码有老练一些,因为我们正是需要更老练些。在ADODB我们使用对象导向的方法来管理多样数据库的复杂性,我们用不同类(class)来控制不同数据库。假如你不熟悉对象导向程序设计,别担心!所有的复杂事情都隐藏在 NewADOConnection() 函数之后。
为了节省内存,我们只加载与你所连结数据库相关的PHP程序代码,我们通过调用NewADOConnection(databasedriver)来完成这件事,合法的数据库驱动程序包含 mysql,mssql,oracle,oci8,postgres,sybase,vfp,access,ibase 以及许多其它的驱动程序。
接着我们通过调用 NewADOConnection() 来从连结类别产生一个新的对象实体,最后我们使用 $db->Connect() 来连结数据库。
执行SQL指令
$result = $db->Execute("SELECT * FROM employees");
if
($result === false) die("failed");
直接传送SQL指令到服务器,当成功执行之后,Execute()将传回一个recordset对象,你可以如同上面所列来检查$result。
一个初学者容易混淆的议题是,在ADODB有两种类型的对象,连结对象以及recordset对象,我们何时用这些对象呢?
连结对象($db)是负责连结数据库,格式化你的SQL查询。而recordset对象($result)则是负责撷取结果并将响应数据规格化成文字或数组。
唯一我需要增加的事情是,ADODB提供许多有用的函数来让INSERT及UPDATE指令更容易些,这点我们在进阶的章节会提到。
撷取资料
while (!$result->EOF) {
for ($i=0,
$max=$result->FieldCount(); $i < $max; $i++)
print
$result->fields[$i].' ';
$result->MoveNext();
print
"<br>n";
}
前面取得数据的范例很像从档案读数据,在每一行我们首先检查是否到了档案的结尾(EOF),若还没到结尾,循环扫过每列中的字段,然后移到下一行(MoveNext)接着重复同样的事情。
$result->fields[]数组是由PHP数据库延伸系统所产生的,有些数据库延伸系统并不会以字段名称建立该数组的索引,要强迫以名称排序索引该数组,使用$ADODB_FETCH_MODE的通用变量。
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
$rs1 =
$db->Execute('select * from table');
$ADODB_FETCH_MODE =
ADODB_FETCH_ASSOC;
$rs2 = $db->Execute('select * from
table');
print_r($rs1->fields); // shows array([0]=>'v0',[1]
=>'v1')
print_r($rs2->fields); // shows
array(['col1']=>'v0',['col2'] =>'v1')
如同你所见的上面例子,两个recordset储存并使用不同的取用模式,当recordset由Execute()产生后再设定$ADODB_FETCH_MODE。
ADOConnection
连结到数据库的对象,执行SQL指令并且有一组工具函数来标准格式化SQL指令,比如关联与日期格式等指令。
其它有用的函数
$recordset->Move($pos)卷动目前的数据列,ADODB支持整个数据库往前卷动,有一些数据库并不支持往后的卷动,这倒不会是个问题,因为你能够用暂存纪录到快取来仿真往后卷动。
$recordset->RecordCount()传回SQL指令存取到的纪录笔数,有些数据库会因为不支持而传回-1。
$recordset->GetArray()以数组的方式传回结果。
rs2html($recordset)函数将传进的recordset转为HTML的表格格式。下例中以粗体字显示相关用法:
include('adodb.inc.php');
include('tohtml.inc.php'); /* includes the rs2html function
*/
$conn = &ADONewConnection('mysql');
$conn->PConnect('localhost','userid','password','database');
$rs =
$conn->Execute('select * from table');
rs2html($rs); /*
recordset to html table */
还有许多其它有用的函数列示在文件之中,可从下列网址查得 http://php.weblogs.com/adodb_manual
进阶题材
新增及更新
假设你要新增下列数据到数据库中。
ID = 3
TheDate=mktime(0,0,0,8,31,2001)
/* 31st August 2001 */
Note= sugar why don't we call it off
当你改用别的数据库,可能就没办法新增数据。
第一个问题是,每一个数据库各自有不同的内定日期格式,MySQL使用 YYYY-MM-DD 格式,而其它数据库则有不同的内定格式,ADODB提供DBDate()函数来转换不同数据库之间的日期内定格式。
次一个问题是单引号(don't)的表示法,在MySQL可以直接使用单引号(don't),但在其它数据库如Sybase、Access、 Microsoft SQL Server,则用两个单引号表示(don''t),qstr()函数可以解决此问题。
我们如何使用这些函数?就像这样:
$sql = "INSERT INTO table (id, thedate,note) values ("
.
$ID . ','
. $db->DBDate($TheDate)
.','
.
$db->qstr($Note).")";
$db->Execute($sql);
ADODB还有$connection->Affected_Rows()函数,传回受最后update或delete指令影响的数据列数,及$recordset->Insert_ID()函数,传回最后因insert指令而自动产生的数据列编号,预先提醒大家,没有任何数据库有提供这两个函数。
MetaTypes
你可以得到关于字段的更多信息,透过recordset的方法FetchField($fieldoffset)传回对象的3个属性:name,type,max_length。
举例说明:
$recordset = $conn->Execute("select adate from table");
$f0 =
$recordset->FetchField(0);
结果$f0->name的内容是'adata',$f0->type将是'date',假如max_length不知道,其内容将会是-1。
处理不同数据库的一个问题是,每一个数据库对于相同的数据型态会有不同的称呼,比如timestamp型态在某数据库中称为datetime,而另一个数据库则称为time,所以ADODB提供MetaType($type,$max_length)函数来标准化下列的数据型态:
C: character and varchar types
X: text or long character (eg. more than
255 bytes wide).
B: blob or binary image
D: date
T: timestamp
L:
logical (boolean)
I: integer
N: numeric (float, double, money)
在前面的例子中,
$recordset = $conn->Execute("select adate from table");
$f0 =
$recordset->FetchField(0);
$type = $recordset->MetaType($f0->type,
$f0->max_length);
print $type; /* should print 'D' */
Select指令的Limit及Top支持
ADODB有个$connection->SelectLimit($sql,$nrows,$offset)函数让你撷取recordset的部分集合,这是采用Microsoft产品中的SELECT TOP用法,及PostgreSQL与MySQL中的SELECT...LIMIT用法的优点,即使原来的数据库并没有提供此用法,本函数也仿真提供该使用方式。
快取支援
ADODB允许你在你的档案系统中暂存recordset的数据,并且在$connection->CacheExecute($secs2cache,$sql)及 $connection->CacheSelectLimit($secs2cache,$sql,$nrows,$offset)等设定的时间间隔到达之后,才真正去做数据库的查询以节省时间。
PHP4 Session支持
ADODB也支持PHP4 session handler,你可以存放你的session变量在数据库中,相关功能请参考 http://php.weblogs.com/adodb-sessions
鼓励商业使用
假如你计划写商用的PHP应用软件来销售,你也可以使用ADODB,我们依据GPL来出版ADODB,也就是说你可以合法地在商用应用软件中引用,并保有你程序代码的所有权。强烈地鼓励ADODB的商业应用,我们自己内部也正以这个理由如此使用中。
结论
为了感谢你看完这篇文章,下面就是 let's call the whole thing off 的完整歌词。
Refrain
You say eether and I say eyether,
You say neether and I say nyther;
Eether, eyether, neether, nyther -
Let's call the whole thing off !You like potato and I like po-tah-to,
You like tomato and I like to-mah-to;
Potato, po-tah-to, tomato, to-mah-to -
Let's call the whole thing off !
But oh, if we call the whole thing off, then we must part.
And oh, if we ever part, then that might break my heart.
So, if you like pajamas and I like pa-jah-mas,
I'll wear pajamas and give up pa-jah-mas.
For we know we
Need each other, so we
Better call the calling off off.
Let's call the whole thing off !
Second Refrain
You say laughter and I say lawfter,
You say after and I say awfter;
Laughter, lawfter, after, awfter -
Let's call the whole thing off !You like vanilla and I like vanella,
You, sa's'parilla and I sa's'parella;
Vanilla, vanella, choc'late, strawb'ry -
Let's call the whole thing off !
But oh, if we call the whole thing off, then we must part.
And oh, if we ever part, then that might break my heart.
So, if you go for oysters and I go for ersters,
I'll order oysters and cancel the ersters.
For we know we
Need each other, so we
Better call the calling off off.
Let's call the whole thing off !
Song and lyrics by George and Ira Gershwin, introduced by Fred Astaire and Ginger Rogers in the film "Shall We Dance?"
freebsd 的 mysqld got signal 10 错误
freebsd: v6.0
mysql: v5.0.18
错误提示:
Version: '5.0.18-log' socket: '/tmp/mysql.sock' port: 3306 FreeBSD port: mysql-server-5.0.18_1
mysqld got signal 10;
This could be because you hit a bug. It is also possible that this binary
or one of the libraries it was linked against is corrupt, improperly built,
or misconfigured. This error can also be caused by malfunctioning hardware.
We will try our best to scrape up some info that will hopefully help diagnose
the problem, but since we have already crashed, something is definitely wrong
and this may fail.
key_buffer_size=16384
read_buffer_size=126976
max_used_connections=64
max_connections=1024
threads_connected=17
It is possible that mysqld could use up to
key_buffer_size + (read_buffer_size + sort_buffer_size)*max_connections = 192520 K
bytes of memory
Hope that's ok; if not, decrease some variables in the equation.
解决方法:
1、增加系统内核可用内存
vi /boot/loader.conf
增加如下内容:
kern.maxdsiz="1773741824"
kern.dfldsiz="1773741824"
kern.maxssiz="134217728"
我的系统为2G内存,mysql 可以用到大概1.5G左右。
2、替换lib
vi /etc/libmap.conf
增加如下内容
[mysqld]
libpthread.so.2 libthr.so.2
libpthread.so libthr.so
确保以上动态库在系统中都存在
利用Snooper下载流媒体和mp3
这时我们打开 Project URL Snooper ,要注意的是如果你是第一次运行这个软件的话请先到 [General Options] 选单那里选择驱动模块(请务必确认你已经正确的安装了 WINPCAP 这个数据嗅探驱动软件)如下图:
选择完毕后(不管是拨号上网或者是 ADSL 上网,只要你正确安装了 WINPCAP ,那么都能出现和上图基本相似的选项,ADSL 拨号的话驱动那里选那个由相应拨号软件建立的选项,简单电说一般就是拨号软件的名字啦。) 回到 [Search] 选单,按下 [Sniff Network] 按钮启动嗅探,然后返回浏览器窗口在地址栏输入 rtsp://140.247.24.29:554/chem17/Lecture04/4-01.smil?cloakport=8080,554,7070 。很快 RealPlayer 自动运行并经过一番连接后开始播放节目。这个时候 Project URL Snooper 正在后台监视着数据包的一举一动,从它的结果窗口我们可以明显的看见,我们想要的东西出现了。如下图:
如箭头所指,Project URL Snooper 已经从杂乱的数据包里面帮我们把真实的地址找出来了,在这个地址上按鼠标右键可以把这个地址复制到剪帖版或者直接调用 StreamBox vcr 进行下载,如下图:
如果你想调用另外的外部程序来对这个连接地址处理可以在 [ External Links] 选单里面选择,如下图:
得到真实地址后再调用 StreamBox vcr 就可以正常下载流节目了
关于java.lang.OutofMemory Exception 的错误!(ZT)
| ||||||||||||
Applications need memory. The processor provides access to memory through memory pages; applications request memory using virtual addresses, and the processor translates that to physical addresses on-the-fly. The mapping between the physical and virtual addresses is maintained in the page table; speeding access to that large table is a cache, called the Translation Lookaside Buffer. By default, the pages are small, only 4KB in size; on AMD's Opteron and Athlon 64 processors, the TLB caches the translations to 512 of these 4K pages. Thus, the TLB can only provide high-speed access to the mappings for a tiny fraction of the memory used in a modern server or workstation. However, as we explained in Part 1, you can configure AMD64-based systems to use large memory pages, which are 2MB in size, and thereby provide a more efficient TLB caching system and, in many cases, faster application performance. In Part 2, we'll talk about how to use those large memory pages under 32-bit and 64-bit Windows and Linux, and configure three advanced Java Virtual Machines to take advantage of them. Setting Up Linux and Windows Therefore, it's best to set up the JVM when your PC or server has just been rebooted; that way, big blocks of contiguous memory are available to be reserved. If you wait until the machine has been running for some time, memory will become fragmented, and the operating system may not be able to find as many 2MB contiguous blocks are you require—thereby giving your JVM less memory, and somewhat reducing the effectiveness of the techniques. The procedures for setting up Linux and Windows are quite different. Linux: To set Linux for large pages, there are two steps: first, make sure your kernel supports large pages, and then, allocate those pages. log in as root. To check to make sure that your kernel support large pages, go to the shell and issue the command: If the output has lines that say "HugePage_Total," "HugePages_Free" and "Hugepagesize," then you're in business. Also, the /proc/filesystems should show a file system of type "hugetlbfs," which means "huge translation lookaside buffer file system." (Remember, Linux uses the word "huge" instead of "large.") Once you've determined that your system supports large pages, you'll have to allocate them. Think about how much memory your JVM will need, because once you've allocated those pages, they're not available for any other purpose until you reboot, unless you deallocate them using: Remember, each page is 2MB in size, so if your application will require 2GB of memory, you will need to allocate 1000 large pages. From the shell, issue the command:
Now, you may not get all those pages. To see how many large pages were actually allocated, use: Windows: What about Windows XP or Windows Server 2003? The process is, as you'd expect, entirely different. The first step is to authorize a specific user to be able to lock pages in memory. This is a one-time configuration change. Make sure you're logged in with administrative privileges, and run Start > Control Pages > Administrative Tools > Local Security Policy > Local Policies > User Rights Assignment, and then select Lock pages in memory (see Figure 1). From that page, click on "Add User or Group" (see Figure 2), and put in your appropriate authorized user or admin account (see Figure 3). Then close all this out and logout/login or reboot to free up memory. Now, applications running as this user can access large pages merely by reserving the number of pages that they need. Wasn't that easy? Remember, this is different than with Linux, where you'll need to reallocate those pages each time you reboot. With Windows, this is a one-time change Note that on Windows, you can't reserve pages the way you can with Linux. So, for this reason, the best policy is to start your JVM as soon as you can after rebooting.
Setting Up Java Virtual Machines Before we dive in, here's an important note: a JVM can't mix large pages and small pages. Even if you provide the appropriate "large page" option, if the JVM can't allocate the whole thing using large 2MB pages, it will revert to using small 4KB pages. Thus, you should explicitly allocate the maximum heap size using the -Xmx option—and make sure it's a multiple of 2MB—rather than leave it unbounded. (The -Xmx flag specifies the maximum heap size. The flag -Xms sets the minimum. If you want to lock in a specific heap size, you can set -Xms and -Xmx to be the same size. So, for example, for the 2GB heap size used above, the command would be -Xmx2G on the JVM command line.) BEA JRockit: You set up the BEA Java Virtual Machine by using the switch --XXlargepages. You can learn more about this in BEA's documentation. If you're running Windows, this is the only step you have to do (assuming that you made the "Lock pages in memory" policy change earlier). If you're running Linux, your root account will also need to create a mount point for mapping the large pages, and assign permissions to that mount point. This is also a one-time change:
IBM's SDK and JRE: The IBM solution for Linux has a different mechanism for doing large pages: the -Xlp switch. Before you start the JVM, however, you'll need to log in as root and change the SHMMAX value; that value defines the maximum size (in bytes) for a shared memory segment. You should set it to be the number of bytes (less one) you'll want in your shared memory. Using our example earlier, we wanted 1000 2MB shared pages to provide 2GB of memory. The size for the SHHMAX should thus be: To set that value: Before you run the process to allocate pages described earlier: Then use the -Xlp switch to launch the JVM. If you're using the IBM SDK and JRE for Windows using Eclipse, just use the -Xlp parameter on JVM startup. Sun's HotSpot JRE for Linux and Windows: The process for using the Sun JVM is similar to the IBM one, except that you use the flag XX:+UseLargePages. Use this flag for both Linux and Windows. With Linux, as with the IBM process above, you'll need to set the SHMMAX capacity. Follow the procedure describe above. YMMV However, it doesn't take a full enterprise app to begin experimenting with the technique. To that end, Listing 1 contains a sample app, LinkedListTest, that runs through a large linked list three times, and then prints out the elapsed time for the operation. Each element in the linked list spans 4K of memory. Because the linked lists span a lot of memory, the code exercises the translation lookahead buffer. To compile the code, use BEA's JRocket 5.0 or later, IBM's JRE 1.4.2 or later, or Sun's 5.0 Update 5 or later. Be sure the jdk bin directory is in your path, since you'll need javac and java. Compile with javac -source 1.4 linklisttest.java. You can then use different command-line arguments to launch JVMs.
For this test, we'll take advantage of the fact that the test application looks at the heap size and uses three-quarters of it to create the linked-list elements. To see the benefit of large pages, let's use a heap of 64MB. To run the application with small pages, start the JVM and launch the application with: Now, run it again using large pages. Here's the startup code for our three JVMs: Try running the code with small and large pages, and with different heap sizes. The results should be strikingly different! (If you get the exact same results, or close enough, then something didn't configure properly; the application may still be using small pages, even if you want otherwise. In that case, please consult the JVM maker's support section or documentation; unfortunately, I don't have the bandwidth or resources to help troubleshoot.) Let's conclude with an exercise for the reader: When you're running the tests, either with the sample program or with your own applications, use AMD's CodeAnalyst performance analyzer to watch for specific processor events. The event to watch for would be 0x46, "L1 and L2 DTLB Miss" (see Figure 4). This event fires whenever the processor requests a page that's not cached in the TLB. The fewer of those cache misses, the better! Page 1 of 1 | ||||||||||||
A former mainframe software developer and systems analyst, Alan Zeichick is principal analyst at Camden Associates, an independent technology research firm focusing on networking, storage, and software development. Read his blog at http://ztrek.blogspot.com. |
windows 的awstats安装
AWStats是sourceforge.net上很有名的Web/Mail/FTP服务器日志文件分析工具。
安装配置步骤(适用于分析IIS日志文件)
1、下载AWStats, 下载地址:http://sourceforge.net/projects/awstats/
2、由于AWStats是Pertl写的,所以要下载Perl 解释器, 下载地址: http://activestate.com/Products/ActivePerl/
3、安装Perl 解释器ActivePerl
4、安装AWStats(这里假设安装在C:\Program Files), 出现命令提示时,第一次输入none, 第二次输入你的主机的域名
5、配置IIS日志
5.1 活动日志格式选用默认的“W3C扩充扩展日志文件格式”
5.2 点击“属性”,再选择“扩展属性”,选中下列项目:
date
time
c-ip
cs-username
cs-method
cs-uri-stem
cs-uri-query
sc-status
sc-bytes
cs-version
cs(User-Agent)
cs(Referer)
其他都不要选中。
6、建立虚拟目录cgi-bin,映射到C:\Program Files\AWStats\wwwroot\cgi-bin。
建立虚拟目录ico, 映射到C:\Program Files\AWStats\wwwroot\icon
7、修改C:\Program Files\AWStats\wwwroot\cgi-bin中的相应的配置文件:awstats.myvirtualhostname.conf(myvirtualhostname为你第4步中输入的域名, 比如www.cnblogs.com)。修改下列项目:
8、重启IIS, 删除C:\WINDOWS\System32\LogFiles\W3SVC1下的所有日志文件
9、使配置生效: awstats.pl -config=myvirtualhostname -update
10、配置完成,通过Web访问日志http://www.myserver.mydomain/cgi-bin/awstats.pl?config=myvirtualhostname,点击“立即更新”。
页面截图:
11、通过任务计划自动更新:
创建批处理文件AwstatsUpate.bat,内容为 :
在任务计划调度运行该批处理文件。
更详细的步骤,请查看帮助文件C:\Program Files\AWStats\docs\awstats_setup.html
参考文章:
1、http://briandesmond.com/blog/archive/2003/09/08/176.aspx
2、http://www.cnblogs.com/Files/dudu/InstallingAWStatsOnIIS6.rar(pdf文件)
关于不能往yahoo,sina等地址发邮件的问题(ZT)
退信代码 | 说 明 |
554 HL:IHU | 该IP的发送行为触犯了网易的服务条款,被临时挂起。请检查是否有用户不正当的发送行为。 |
554 HL:IPB | 该IP不在网易允许的发送地址列表里。 |
450 HL:MEP | 该IP发送行为异常,被临时禁止连接。 |
450 HL:REP | 该IP发送行为异常,被临时禁止连接。 |
554 HL:ICC | 该IP短期内发送了大量信件,超过了网易的限制,被临时禁止连接。请检查是否有用户发送病毒或者垃圾邮件。 |
554 HL:IFQ | 该IP短期内发送了大量信件,超过了网易的限制,被临时禁止连接。请检查是否有用户发送病毒或者垃圾邮件。 |
554 HL:ITC | 该IP短期内发送了大量信件,超过了网易的限制,被临时禁止连接。请检查是否有用户发送病毒或者垃圾邮件。 |
554 MI:SPB | 此用户不在网易允许的发信用户列表里。 |
550 MI:NHD | HELO命令不允许为空。 |
550 MI:IMF | 发信人电子邮件地址不合规范。请参考http://www.rfc-editor.org/关于电子邮件规范的定义。 |
550 MI:SPF | 发信IP未被发送域的SPF许可。请参考http://www.openspf.org/关于SPF规范的定义。 |
450 MI:CEL | 发送行为异常,该发件人被临时禁止发信。 |
450 MI:DMC | 发送行为异常,该发件人被临时禁止发信。 |
450 MI:CCL | 发送行为异常,该发件人被临时禁止发信。 |
554 MI:SFQ | 短期内发送了大量信件,超过了网易的限制,该发件人被临时禁止发信。 |
550 MI:STC | 短期内发送了大量信件,超过了网易的限制,该发件人被临时禁止发信。 |
550 RP:FRL | 禁止发信到非网易用户。 |
550 RP:RCL | 群发收件人数量超过了限额。 |
550 RP:CEL | 发件人发送行为异常。 |
450 RP:DRC | 群发收件人数量超过了限额。 |
450 RP:CCL | 发件人发送行为异常。 |
550 RP:QRC | 该用户短期内发送了大量信件,超过了网易的限制,被临时禁止发信。 |
550 RP:TRC | 该用户短期内发送了大量信件,超过了网易的限制,被临时禁止发信。 |
450 DT:SPM | 发送的邮件内容包含了未被网易许可的信息,或违背了网易的反垃圾服务条款。 |
550 DT:SPM | 发送的邮件内容包含了未被网易许可的信息,或违背了网易的反垃圾服务条款。 |
450 DT:RBL | 发信IP位于一个或多个RBL里。请参考http://www.rbls.org/关于RBL的相关信息。 |
554 IP in blacklist | 该IP不在网易允许的发送地址列表里。 |
552 Requested mail action aborted: exceeded mailsize limit | 发送的信件大小超过了网易邮箱允许接收的最大限制。 |
500 Error: bad syntaxU | 发送的smtp命令语法有误。 |
550 Invalid User | 请求的用户不存在。 |
550 User in blacklist | 该用户不被允许给网易用户发信。 |
550 User suspended | 请求的用户处于禁用或者冻结状态。 |
451 Requested action aborted: local error in processing | 系统暂时出现故障,请稍后再次尝试发送。 |
AWStats Installation Configuration(ZT备用)
![]() | AWStats logfile analyzer 6.6 Documentation |
| perl awstats_configure.pl |
| date time c-ip cs-username cs-method cs-uri-stem cs-uri-query sc-status sc-bytes cs-version cs(User-Agent) cs(Referer) |
| 2000-07-19 14:14:14 62.161.78.73 - GET / 200 1234 HTTP/1.1 Mozilla/4.0+(compatible;+MSIE+5.01;+Windows+NT+5.0) http://www.from.com/from.htm |
| perl awstats.pl -config=mysite -update |
| Update for config "/etc/awstats/awstats.mysite.conf" With data in log file "/pathtoyourlog/yourlog.log"... Phase 1 : First bypass old records, searching new record... Searching new records from beginning of log file... Phase 2 : Now process new records (Flush history on disk after 20000 hosts)... Jumped lines in file: 0 Parsed lines in file: 225730 Found 122 dropped records, Found 87 corrupted records, Found 0 old records, Found 225521 new qualified records. |
| perl awstats.pl -config=mysite -output -staticlinks > awstats.mysite.html |
| perl awstats.pl -config=mysite -output=alldomains -staticlinks > awstats.mysite.alldomains.html perl awstats.pl -config=mysite -output=allhosts -staticlinks > awstats.mysite.allhosts.html perl awstats.pl -config=mysite -output=lasthosts -staticlinks > awstats.mysite.lasthosts.html perl awstats.pl -config=mysite -output=unknownip -staticlinks > awstats.mysite.unknownip.html perl awstats.pl -config=mysite -output=alllogins -staticlinks > awstats.mysite.alllogins.html perl awstats.pl -config=mysite -output=lastlogins -staticlinks > awstats.mysite.lastlogins.html perl awstats.pl -config=mysite -output=allrobots -staticlinks > awstats.mysite.allrobots.html perl awstats.pl -config=mysite -output=lastrobots -staticlinks > awstats.mysite.lastrobots.html perl awstats.pl -config=mysite -output=urldetail -staticlinks > awstats.mysite.urldetail.html perl awstats.pl -config=mysite -output=urlentry -staticlinks > awstats.mysite.urlentry.html perl awstats.pl -config=mysite -output=urlexit -staticlinks > awstats.mysite.urlexit.html perl awstats.pl -config=mysite -output=browserdetail -staticlinks > awstats.mysite.browserdetail.html perl awstats.pl -config=mysite -output=osdetail -staticlinks > awstats.mysite.osdetail.html perl awstats.pl -config=mysite -output=unknownbrowser -staticlinks > awstats.mysite.unknownbrowser.html perl awstats.pl -config=mysite -output=unknownos -staticlinks > awstats.mysite.unknownos.html perl awstats.pl -config=mysite -output=refererse -staticlinks > awstats.mysite.refererse.html perl awstats.pl -config=mysite -output=refererpages -staticlinks > awstats.mysite.refererpages.html perl awstats.pl -config=mysite -output=keyphrases -staticlinks > awstats.mysite.keyphrases.html perl awstats.pl -config=mysite -output=keywords -staticlinks > awstats.mysite.keywords.html perl awstats.pl -config=mysite -output=errors404 -staticlinks > awstats.mysite.errors404.html |
| perl awstats.pl -config=mysite -output=urldetail:/news -staticlinks > awstats.mysite.urldetailwithfilter.html |
| http://www.myserver.mydomain/awstats/awstats.pl?config=mysite |