为Linux MySQL数据库设置磁盘限额

因为MySQL数据库本身没有磁盘限额的功能,我们可以限制Linux自带的quota工具为mysql进行磁盘限额。
1、首先需要为/home自动挂载一个分区,并且设置为quota磁盘格式。我们以用户foo为例,设置foo的磁盘限额。具体如何设置请参考Linux Quota基础教程
2、在foo主目录创建一个存放数据库的dbs目录,并设置此目录的所有权为mysql:foo,权限为3755。

  1. mkdir /home/foo/dbs
  2. chown mysql:foo /home/foo/dbs
  3. chmod 3755 /home/foo/dbs

3、现在把 /var/lib/mysql的所有foo的数据库文件移到/home/foo/dbs目录。

  1. mkdir /root/backup
  2. cp -avr /var/lib/mysql/* root/backup
  3. mv /var/lib/mysql/database-name /home/foo/dbs/
  4. chown -Rf mysql:foo /home/foo
  5. chmod -Rf 3755 /home/foo
  6. ln -s /var/lib/mysql/database-name /home/foo/dbs/database-name -v

之后重启mysql数据库服务器:

  1. /etc/init.d/mysqld restart

Linux Quota基础配置

Quota介绍

这篇文章将介绍Linux的一个重要工具-Quota,使用Quota能对某一分区下指定用户或用户组进行磁盘限额。这里要说明的是,限额不是针对用户主目录,而是针对这个分区下的用户或用户组。Quota通过限制用户的blocks或者inodes起到限额的作用。

Quota配置

1、首先我们需要设置分区的Quota档案格式,只要在 /etc/fstab 里头增加了 usrquota, grpquota 就可以。如下,对分区/和/home启用quota磁盘格式。

  1. /dev/VolGroup00/LogVol04 /
  2. ext3 defaults,usrquota,grpquota 1 1
  3. LABEL=/boot /boot ext3 defaults 1 2
  4. devpts /dev/pts devpts gid=5,mode=620 0 0
  5. tmpfs /dev/shm tmpfs defaults 0 0
  6. /dev/VolGroup00/LogVol00 /home
  7. ext3 defaults,usrquota,grpquota 1 2
  8. proc /proc proc defaults 0 0
  9. sysfs /sys sysfs defaults 0 0
  10. /dev/VolGroup00/LogVol02 /tmp ext3 defaults 1 2
  11. /dev/VolGroup00/LogVol03 /var ext3 defaults 1 2
  12. /dev/VolGroup00/LogVol01 swap swap defaults 0 0

2、重新挂载/和/home文件系统激活quota。

  1. mount -o remount /
  2. mount -o remount /home

3、初始化quota数据库,运行quotacheck -cug 命令之后,在每个挂载分区根目录下你会发现生成了aquota.user aquota.group两个文件,这两个文件记录了对分区限额的信息。
初始化quota数据库:

  1. quotacheck -cug /
  2. quotacheck -cug /home/

检测是否已经生成:

  1. ls -al /aquota*
  2. -rw——- 1 root root 6144 May 26 17:15 /aquota.group
  3. -rw——- 1 root root 6144 May 26 17:15 /aquota.user
  4. ls -al /home/aquota*
  5. -rw——- 1 root root 7168 May 26 17:16 /home/aquota.group
  6. -rw——- 1 root root 7168 May 26 17:16 /home/aquota.user

4、开启一个定时任务,用来定时扫描quota空间。最好设置在深夜执行,如下:

  1. #MIN (0-59) HOUR (0-23)
  2. DoM (1-31) MONTH (1-12) DoW (0-7) CMD
  3. 0 1 * * 0 quotacheck -vug /
  4. 20 1 * * * quotacheck -vug /home

5、启用文件系统的quota支持。最简单的方法是重启计算机,你也可以使用quotaon命令而不需要重启计算机。
使用quotaon激活:

  1. quotaon /home
  2. quotaon /

检查是否激活成功:

  1. quotaon -p /home
  2. group quota on /home (/dev/mapper/VolGroup00-LogVol00) is on
  3. user quota on /home (/dev/mapper/VolGroup00-LogVol00) is on
  4. quotaon -p /
  5. group quota on / (/dev/mapper/VolGroup00-LogVol04) is on
  6. user quota on / (/dev/mapper/VolGroup00-LogVol04) is on

设定用户或用户组磁盘限额

在为用户设置限额时,需要知道几个术语:
soft :这是最低限制容量的意思,使用者在宽限期间之内,他的容量可以超过 soft ,但必需要宽限时间之内将磁盘容量降低到 soft 的容量限制之下!
hard :这是『绝对不能超过』的容量!跟 soft 相比的意思为何呢?通常 hard limit 会比 soft limit 为高,例如网络磁盘空间为 30 MB ,那么 hard limit 就设定为 30MB ,但是为了让使用者有一定的警戒心,所以当使用空间超过 25 MB 时,例如使用者使用了 27 MB 的空间时,那么系统就会警告使用者,让使用者可以在『宽限时间内』将他的档案量降低至 25 MB ( 亦即是 soft limit )之内!也就是说, soft 到 hard 之间的容量其实就是宽限的容量啦!可以达到针对使用者的『警示』作用!
宽限时间:那么宽限时间就可以很清楚的知道含意是什么了!也就是当您的使用者使用的空间超过了 soft limit ,却还没有到达 hard limit 时,那么在这个『宽限时间』之内,就必需要请使用者将使用的磁盘容量降低到 soft limit 之下!而当使用者将磁盘容量使用情况超过 soft limit 时,『宽限时间』就会自动被启动,而在使用者将容量降低到 soft limit 之下,那么宽限时间就会自动的取消啰!
1、使用edquota编辑用户限额

  1. edquota thirt

2、设置如下:

  1. Disk quotas for user thirt (uid 500):
  2. Filesystem                 blocks soft hard inodes soft hard
  3. /dev/mapper/VolGroup00-LogVol04 0 0 0 0 0 0
  4. /dev/mapper/VolGroup00-LogVol00 88 92160 102400 13 0 0

解释:
filesystem:这个是那个 partition 的意思!
blocks:这个是目前使用者 thirt ( uid 500 )在 /dev/mapper/VolGroup00-LogVol00 这个 filesystem (参考上面一个信息),所耗掉的磁盘容量,也就是目前的使用掉的空间啦!单位是 Kbytes 喔!这个信息是 quota 程序自己计算出来的,所以请不要修改他!
soft 与 hard :这个是目前的 test 在这个 filesystem 之内的 quota 限制值!至于 soft 与 hard 的意思就如同上面提的那个意思!当 soft 与 hard 数值为 0 的时候,表示『没有限制』的意思!而数值的单位仍是 Kbytes 喔!
inodes :是目前使用掉 inode 的状态,也是 quota 自己计算出来而得到的,所以不要去变更他。一般而言, inode 不容易控制,所以您可以不必去限制 inode 呢!
3、设置过期时间
设置/ 文件系统的默认过期时间:

  1. edquota -f / -t
  1. Grace period before enforcing soft limits for users:
  2. Time units may be: days, hours, minutes, or seconds
  3. Filesystem Block grace period Inode grace period
  4. /dev/mapper/VolGroup00-LogVol04 7days 7days

设置/home文件系统过期时间:

  1. edquota -f /home -t
  1. Grace period before enforcing soft limits for users:
  2. Time units may be: days, hours, minutes, or seconds
  3. Filesystem Block grace period Inode grace period
  4. /dev/mapper/VolGroup00-LogVol00 7days 7days

4、验证设置
打印所有限额信息

  1. repquota -a

打印单个用户限额信息

  1. quota thirt

DDoS deflate – Linux下防御/减轻DDOS攻击

前言

互联网如同现实社会一样充满钩心斗角,网站被DDOS也成为站长最头疼的事。在没有硬防的情况下,寻找软件代替是最直接的方法,比如用iptables,但是iptables不能在自动屏蔽,只能手动屏蔽。今天要说的就是一款能够自动屏蔽DDOS攻击者IP的软件:DDoS deflate。

DDoS deflate介绍

DDoS deflate是一款免费的用来防御和减轻DDoS攻击的脚本。它通过netstat监测跟踪创建大量网络连接的IP地址,在检测到某个结点超过预设的限 制时,该程序会通过APF或IPTABLES禁止或阻挡这些IP.

DDoS deflate官方网站:http://deflate.medialayer.com/

如何确认是否受到DDOS攻击?

执行:

  1. netstat -ntu | awk ‘{print $5}’ | cut -d: -f1 | sort | uniq -c | sort -n

执行后,将会显示服务器上所有的每个IP多少个连接数。

以下是我自己用VPS测试的结果:

li88-99:~# netstat -ntu | awk ‘{print $5}’ | cut -d: -f1 | sort | uniq -c | sort -n
1 114.226.9.132
1 174.129.237.157
1 58.60.118.142
1 Address
1 servers)
2 118.26.131.78
3 123.125.1.202
3 220.248.43.119
4 117.36.231.253
4 119.162.46.124
6 219.140.232.128
8 220.181.61.31
2311 67.215.242.196
每个IP几个、十几个或几十个连接数都还算比较正常,如果像上面成百上千肯定就不正常了。
安装配置DDoS deflate

1、安装DDoS deflate

  1. wget http://www.inetbase.com/scripts/ddos/install.sh   //下载DDoS  deflate
  2. chmod 0700 install.sh    //添加权限
  3. ./install.sh             //执行

2、配置DDoS deflate

下面是DDoS deflate的默认配置位于/usr/local/ddos/ddos.conf ,内容如下:

  1. ##### Paths of the script and other files
  2. PROGDIR="/usr/local/ddos"
  3. PROG="/usr/local/ddos/ddos.sh"
  4. IGNORE_IP_LIST="/usr/local/ddos/ignore.ip.list"  //IP地址白名单
  5. CRON="/etc/cron.d/ddos.cron"    //定时执行程序
  6. APF="/etc/apf/apf"
  7. IPT="/sbin/iptables"
  8.  
  9. ##### frequency in minutes for running the script
  10. ##### Caution: Every time this setting is changed, run the script with –cron
  11. #####          option so that the new frequency takes effect
  12. FREQ=1   //检查时间间隔,默认1分钟
  13.  
  14. ##### How many connections define a bad IP? Indicate that below.
  15. NO_OF_CONNECTIONS=150     //最大连接数,超过这个数IP就会被屏蔽,一般默认即可
  16.  
  17. ##### APF_BAN=1 (Make sure your APF version is atleast 0.96)
  18. ##### APF_BAN=0 (Uses iptables for banning ips instead of APF)
  19. APF_BAN=1        //使用APF还是iptables。推荐使用iptables,将APF_BAN的值改为0即可。
  20.  
  21. ##### KILL=0 (Bad IPs are’nt banned, good for interactive execution of script)
  22. ##### KILL=1 (Recommended setting)
  23. KILL=1   //是否屏蔽IP,默认即可
  24.  
  25. ##### An email is sent to the following address when an IP is banned.
  26. ##### Blank would suppress sending of mails
  27. EMAIL_TO="root"   //当IP被屏蔽时给指定邮箱发送邮件,推荐使用,换成自己的邮箱即可
  28.  
  29. ##### Number of seconds the banned ip should remain in blacklist.
  30. BAN_PERIOD=600    //禁用IP时间,默认600秒,可根据情况调整

用户可根据给默认配置文件加上的注释提示内容,修改配置文件。

查看/usr/local/ddos/ddos.sh文件的第117行

  1. netstat -ntu | awk ‘{print $5}’ | cut -d: -f1 | sort | uniq -c | sort -nr > $BAD_IP_LIST

修改为以下代码即可!

  1. netstat -ntu | awk ‘{print $5}’ | cut -d: -f1 | sed -n ‘/[0-9]/p’ | sort | uniq -c | sort -nr > $BAD_IP_LIST

喜欢折腾的可以用Web压力测试软件测试一下效果,相信DDoS deflate还是能给你的VPS或服务器抵御一部分DDOS攻击,给你的网站更多的保护。
转自:http://www.vpser.net/security/ddos-deflate.html

Linux安装PHP加速器Xcache

XCache 是一个又快又稳定的 PHP opcoolcode 缓存器. 经过良好的测试并在大流量/高负载的生产机器上稳定运行. 经过(在 linux 上)测试并支持所有现行 PHP 分支的最新发布版本, 如 PHP_4_3 PHP_4_4 PHP_5_0 PHP_5_1 PHP_5_2 HEAD(6.x), 并支持线程安全/Windows. 与同类 opcoolcode 缓存器相比更胜一筹, 比如能够快速跟进 PHP 版本.下面介绍如何安装配置。
1、安装xcache

  1. wget http://xcache.lighttpd.net/pub/Releases/1.3.2/xcache-1.3.2.tar.gz
  2. tar -zxvf xcache-1.3.2.tar.gz
  3. cd xcache-1.3.2
  4. phpize
  5. ./configure –enable-xcache
  6. make
  7. make install

2、配置xcache
打开php.ini文件,增加如下代码:

  1. [xcache-common]
  2. ; change me – 64 bit php => /usr/lib64/php/modules/xcache.so
  3. ; 32 bit php => /usr/lib/php/modules/xcache.so
  4. zend_extension = /usr/lib64/php/modules/xcache.so
  5.  
  6. [xcache.admin]
  7. xcache.admin.auth = On
  8. xcache.admin.user = "mOo"
  9. ; xcache.admin.pass = md5($your_password)
  10. xcache.admin.pass = ""
  11.  
  12. [xcache]
  13. xcache.shm_scheme =        "mmap"
  14. xcache.size  =               32M
  15. xcache.count =                 1
  16. xcache.slots =                8K
  17. xcache.ttl   =              3600
  18. xcache.gc_interval =         300
  19.  
  20. ; Same as aboves but for variable cache
  21. ; If you don’t know for sure that you need this, you probably don’t
  22. xcache.var_size  =            0M
  23. xcache.var_count =             1
  24. xcache.var_slots =            8K
  25. xcache.var_ttl   =             0
  26. xcache.var_maxttl   =          0
  27. xcache.var_gc_interval =     300
  28.  
  29. ; N/A for /dev/zero
  30. xcache.readonly_protection = Off
  31.  
  32. xcache.mmap_path =    "/dev/zero"
  33.  
  34. xcache.cacher =               On
  35. xcache.stat   =               On

注意修改zend_extension = /usr/lib64/php/modules/xcache.so为正确的路径。
详情的配置说明:http://xcache.lighttpd.net/wiki/XcacheIni

Apache web服务器压力测试工具ab(apache benchmark)

以前安装好APACHE总是不知道该如何测试APACHE的性能,现在总算找到一个测试工具了。就是APACHE自带的测试工具AB(apache benchmark).在APACHE的bin目录下。
格式: ./ab [options] [http://]hostname[:port]/path
参数:
-n requests Number of requests to perform
//在测试会话中所执行的请求个数。默认时,仅执行一个请求
-c concurrency Number of multiple requests to make
//一次产生的请求个数。默认是一次一个。
-t timelimit Seconds to max. wait for responses
//测试所进行的最大秒数。其内部隐含值是-n 50000。它可以使对服务器的测试限制在一个固定的总时间以内。默认时,没有时间限制。
-p postfile File containing data to POST
//包含了需要POST的数据的文件.
-T content-type Content-type header for POSTing
//POST数据所使用的Content-type头信息。
-v verbosity How much troubleshooting info to print
//设置显示信息的详细程度 – 4或更大值会显示头信息, 3或更大值可以显示响应代码(404, 200等), 2或更大值可以显示警告和其他信息。 -V 显示版本号并退出。
-w Print out results in HTML tables
//以HTML表的格式输出结果。默认时,它是白色背景的两列宽度的一张表。
-i Use HEAD instead of GET
// 执行HEAD请求,而不是GET。
-x attributes String to insert as table attributes
//
-y attributes String to insert as tr attributes
//
-z attributes String to insert as td or th attributes
//
-C attribute Add cookie, eg. ‘Apache=1234. (repeatable)
//-C cookie-name=value 对请求附加一个Cookie:行。 其典型形式是name=value的一个参数对。此参数可以重复。
-H attribute Add Arbitrary header line, eg. ‘Accept-Encoding: gzip’
Inserted after all normal header lines. (repeatable)
-A attribute Add Basic WWW Authentication, the attributes
are a colon separated username and password.
-P attribute Add Basic Proxy Authentication, the attributes
are a colon separated username and password.
//-P proxy-auth-username:password 对一个中转代理提供BASIC认证信任。用户名和密码由一个:隔开,并以base64编码形式发送。无论服务器是否需要(即, 是否发送了401认证需求代码),此字符串都会被发送。
-X proxy:port Proxyserver and port number to use
-V Print version number and exit
-k Use HTTP KeepAlive feature
-d Do not show percentiles served table.
-S Do not show confidence estimators and warnings.
-g filename Output collected data to gnuplot format file.
-e filename Output CSV file with percentages served
-h Display usage information (this message)
//-attributes 设置 属性的字符串. 缺陷程序中有各种静态声明的固定长度的缓冲区。另外,对命令行参数、服务器的响应头和其他外部输入的解析也很简单,这可能会有不良后果。它没有完整地实现HTTP/1.x; 仅接受某些’预想’的响应格式。 strstr(3)的频繁使用可能会带来性能问题,即, 你可能是在测试ab而不是服务器的性能。
参数很多,一般我们用 -c 和 -n 参数就可以了. 例如:
./ab -c 1000 -n 1000 http://127.0.0.1/index.php
这个表示同时处理1000个请求并运行1000次index.php文件.
#/usr/local/xiaobai/apache2054/bin/ab -c 1000 -n 1000 http://127.0.0.1/index.html.zh-cn.gb2312
This is ApacheBench, Version 2.0.41-dev apache-2.0
Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright (c) 1998-2002 The Apache Software Foundation, http://www.apache.org/
Benchmarking 127.0.0.1 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Finished 1000 requests

Server Software: Apache/2.0.54
//平台apache 版本2.0.54
Server Hostname: 127.0.0.1
//服务器主机名
Server Port: 80
//服务器端口
Document Path: /index.html.zh-cn.gb2312
//测试的页面文档
Document Length: 1018 bytes
//文档大小
Concurrency Level: 1000
//并发数
Time taken for tests: 8.188731 seconds
//整个测试持续的时间
Complete requests: 1000
//完成的请求数量
Failed requests: 0
//失败的请求数量
Write errors: 0

Total transferred: 1361581 bytes
//整个场景中的网络传输量
HTML transferred: 1055666 bytes
//整个场景中的HTML内容传输量
Requests per second: 122.12 [#/sec] (mean)
//大家最关心的指标之一,相当于 LR 中的 每秒事务数 ,后面括号中的 mean 表示这是一个平均值
Time per request: 8188.731 [ms] (mean)
//大家最关心的指标之二,相当于 LR 中的 平均事务响应时间 ,后面括号中的 mean 表示这是一个平均值
Time per request: 8.189 [ms] (mean, across all concurrent requests)
//每个请求实际运行时间的平均值
Transfer rate: 162.30 [Kbytes/sec] received
//平均每秒网络上的流量,可以帮助排除是否存在网络流量过大导致响应时间延长的问题
Connection Times (ms)
min mean[+/-sd] median max
Connect: 4 646 1078.7 89 3291
Processing: 165 992 493.1 938 4712
Waiting: 118 934 480.6 882 4554
Total: 813 1638 1338.9 1093 7785
//网络上消耗的时间的分解,各项数据的具体算法还不是很清楚
Percentage of the requests served within a certain time (ms)
50% 1093
66% 1247
75% 1373
80% 1493
90% 4061
95% 4398
98% 5608
99% 7368
100% 7785 (longest request)
//整个场景中所有请求的响应情况。在场景中每个请求都有一个响应时间,其中50%的用户响应时间小于1093 毫秒,60% 的用户响应时间小于1247 毫秒,最大的响应时间小于7785 毫秒
由于对于并发请求,cpu实际上并不是同时处理的,而是按照每个请求获得的时间片逐个轮转处理的,所以基本上第一个Time per request时间约等于第二个Time per request时间乘以并发请求数
转自:http://blog.chinaunix.net/space.php?uid=12318776&do=blog&cuid=537944

Apache防DDOS模块mod_evasive

博客不时的有人拿来做压力测试,于是准备配置iptables限制每个IP的并发数。但配置iptables才发现,由于Linux内核版本比较低,iptables不支持connlimit模块,于是想到把conlimit模块编译到内核中,无奈openvz vps不支持编译内核。所以使用了Apache的防DDOS模块mod_evasive,具体安装配置如下:
一、下载模块

  1. wget http://www.zdziarski.com/blog/wp-content/uploads/2010/02/mod_evasive_1.10.1.tar.gz
  2. tar xzvf mod_evasive_1.10.1.tar.gz
  3. cd mod_evasive

二、安装模块
1、对于Apache 1.x 请用下面的编译方法;

  1. /usr/local/apache/bin/apxs -iac mod_evasive.c

2、对于Apache 2.x 可以用下面的办法;

  1. /usr/local/apache/bin/apxs -i -a -c mod_evasive20.c

三、配置模块
在配置文件httpd.conf加入如下代码:
在Apache v1.x 版本中,要加入;

  1. <IfModule mod_evasive.c>
  2.     DOSHashTableSize    3097
  3.     DOSPageCount        2
  4.     DOSSiteCount        50
  5.     DOSPageInterval     1
  6.     DOSSiteInterval     1
  7.     DOSBlockingPeriod   10
  8. </IfModule>

在Apache v2.x加入;

  1. <IfModule mod_evasive20.c>
  2.     DOSHashTableSize    3097
  3.     DOSPageCount        2
  4.     DOSSiteCount        50
  5.     DOSPageInterval     1
  6.     DOSSiteInterval     1
  7.     DOSBlockingPeriod   10
  8. </IfModule>

之后重启httpd。
相关参数说明:
DOSHashTableSize 3097:定义哈希表大小。
DOSPageCount 2:允许客户机访问同一页的间隔。
DOSSiteCount 50:允许客户机的最大并发连接。
DOSPageInterval 1:网页访问计数器间隔。
DOSSiteInterval 1:全站访问计数器间隔。
DOSBlockingPeriod 10:加入黑名单后拒绝访问时间。
四、对mod_evasive测试验证
可以使用apache的ab工具,也可以使用evasive解压目录中的test.pl脚本测试。
ab工具:ab -n 1000 -c 50 http://devops.webres.wang/
perl: perl test.pl
需要了解更多关于evasive模块的使用可以查看解压目录中的README文件。

eAccelerator 配置参数详解

  1. eaccelerator.shm_size="32"

eAccelerator 可以使用的共享内存的数量 (以兆为单位) . “0” 是指操作系统的默认值. 默认值是 “0”.可根据服务器的实际情况来调整,16,32,64,128都是可以的。

  1. eaccelerator.cache_dir="/home/php/tmp"

这个目录是给磁盘缓存使用. eAccelerator 在这里储存预先编译好的代码, 进程数据, 内容以及用户的自定义内容. 同样的数据也能被储存在共享内存中 (这样可以提高访问速度). 默认的设置是 “/tmp/eaccelerator”.

  1. eaccelerator.enable="1"

开启或关闭 eAccelerator。”1″ 为开启,”0″ 为关闭。默认值为 “1”。

  1. eaccelerator.optimizer="1"

启或关闭内部优化器,可以提升代码执行速度。”1″ 为开启,”0″ 为关闭。默认值为 “1”。
eaccelerator.check_mtime=”1″
打开或者关闭 PHP 的文件修改检查. “1” 是指打开, “0” 是指关闭. 如果您在修改以后重新编译 PHP 的文件,那么您应当设置为 “1”. 默认值是 “1”.

  1. eaccelerator.debug="0"

开启或关闭调试日志记录。”1″ 为开启,”0″ 为关闭。默认值为 “0”。会将缓存命中得记录写入日志。

  1. eaccelerator.filter=""

判断哪些 PHP 文件必须缓存。您可以指定缓存和不缓存的文件类型(如 “*.php *.phtml”等)
如果参数以 “!” 开头,则匹配这些参数的文件被忽略缓存。默认值为 “”,即,所有 PHP 文件都将被缓存。

  1. eaccelerator.shm_max="0"

当使用 ” eaccelerator_put() ” 函数时禁止其向共享内存中存储过大的文件。该参数指定允许存储的最大值,单位:字节 (10240, 10K, 1M)。”0″ 为不限制。默认值为 “0”。

  1. eaccelerator.shm_ttl="0"

当 eAccelerator 获取新脚本的共享内存大小失败时,它将从共享内存中删除所有在最后 “shm_ttl” 秒内没有存取的脚本缓存。默认值为 “0”,即:不从共享内春中删除任何缓存文件。

  1. eaccelerator.shm_prune_period="0"

当 eAccelerator 获取新脚本的共享内存大小失败时,他将试图从共享内存中删除早于”shm_prune_period” 秒的缓存脚本。默认值为 “0”,即:不从共享内春中删除任何缓存文件。

  1. eaccelerator.shm_only="0"

允许或禁止将已编译脚本缓存在磁盘上。该选项对 session 数据和内容缓存无效。默认值为 “0”,即:使用磁盘和共享内存进行缓存。

  1. eaccelerator.compress="1"

允许或禁止压缩内容缓存。默认值为 “1”,即:允许压缩。

  1. eaccelerator.compress_level="9"

指定内容缓存的压缩等级。默认值为 “9”,为最高等级。

  1. eaccelerator.keys = "disk_only"
  2. eaccelerator.session = "disk_only"
  3. eaccelerator.content = "disk_only"

设置内容缓存的存放的地方,可以设置为:
shm_and_disk 在共享缓存和硬盘(默认值)
shm 默认存在共享内存,如果共享内存已满或大小超过 “eaccelerator.shm_max” 的值,就存到硬盘
shm_only 只存放在共享内存
disk_only 只存放在硬盘
none 不缓存数据

  1. eaccelerator.allowed_admin_path = "/var/www/html/21andy.com/eaccelerator"

这是控制面板的地址
安装包里有个control.php,你把它复制到网站的任意目录,可以用它查看和管理,这个必须指定,否则查看缓存内容的时候会出错
最后,来看一下我的 eAccelerator 设置

  1. ; eaccelerator
  2. [eaccelerator]
  3. zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so"
  4. eaccelerator.shm_size="128"
  5. eaccelerator.cache_dir="/tmp/eaccelerator"
  6. eaccelerator.enable="1"
  7. eaccelerator.optimizer="1"
  8. eaccelerator.check_mtime="1"
  9. eaccelerator.debug="0"
  10. eaccelerator.filter=""
  11. eaccelerator.shm_max="0"
  12. eaccelerator.shm_ttl="3600"
  13. eaccelerator.shm_prune_period="3600"
  14. eaccelerator.shm_only="0"
  15. eaccelerator.compress="1"
  16. eaccelerator.compress_level="9"
  17. eaccelerator.keys = "disk_only"
  18. eaccelerator.sessions = "disk_only"
  19. eaccelerator.content = "disk_only"
  20. eaccelerator.allowed_admin_path = "/var/www/html/21andy.com/eaccelerator"

另外,再说下 eAccelerator 的安装

  1. # wget http://bart.eaccelerator.net/source/0.9.6/eaccelerator-0.9.6.tar.bz2
  2. # tar -jxvf eaccelerator-0.9.6.tar.bz2
  3. # cd eaccelerator-0.9.6
  4. # /usr/local/php/bin/phpize
  5. # ./configure –enable-eaccelerator=shared –with-php-config=/usr/local/php/bin/php-config
  6. # make && make install

文章来源:http://www.21andy.com/blog/20100207/1646.html

Linux vsftpd启动,停止,重启脚本

yum安装vsftpd后启动脚本也安装好了,管理vsftpd进程非常方便。但编译安装vsftpd的话,修改配置文件需要重启,就有点麻烦了,需要用kill杀掉进程,再键入/usr/local/sbin/vsftpd &启动。下面提供一个vsftpd启动脚本,让管理vsftpd也像yum安装管理vsftpd一样轻松。

  1. #!/bin/bash
  2.  
  3. #chkconfig: 345 60 50
  4. #description:vsftpd
  5. . /etc/rc.d/init.d/functions
  6. if [ -f /etc/init.d/functions ] ; then
  7. . /etc/init.d/functions
  8. elif [ -f /etc/rc.d/init.d/functions ] ; then
  9. . /etc/rc.d/init.d/functions
  10. else
  11. exit 0
  12. fi
  13. vsftpd=/usr/local/sbin/vsftpd      //vsftp启动脚本中配置vsftpd安装的路径
  14. prog=vsftpd
  15. RETVAL=0
  16. start() {
  17.         if [ -n "`/sbin/pidof $prog`" ]
  18.         then
  19.                 echo "$prog: already running"       
  20.                 echo
  21.                 return 1
  22.         fi
  23.         echo "Starting $prog:"
  24.         base=$prog
  25.         $vsftpd &
  26.         RETVAL=$?
  27.         usleep 5000000
  28.         if [ -z "`/sbin/pidof $prog`" ]
  29.         then
  30.                 RETVAL=1
  31.         fi
  32.         if [ $RETVAL -ne 0 ]       
  33.         then
  34.         echo "Startup failure"     //vsftp启动脚本启动失败提示
  35.         else
  36.         echo "Startup success"     //vsftp启动脚本启动成功提示
  37.         fi
  38.         echo
  39.         return $RETVAL
  40. }
  41.  
  42. stop() {
  43.         echo "Stopping $prog:"
  44.         killall $vsftpd
  45.         RETVAL=$?
  46.         if [ $RETVAL -ne 0 ]
  47.         then
  48.         echo "Shutdown failure"     //vsftp启动脚本停止失败提示
  49.         else
  50.         echo "Shutdown success"     //vsftp启动脚本停止成功提示
  51.         fi
  52.         echo
  53. }
  54.  
  55. case "$1" in
  56. start)
  57.         start     //vsftp启动脚本服务启动操作
  58.         ;;
  59. stop)
  60.         stop     //vsftp启动脚本服务停止操作
  61.         ;;
  62. status)
  63.         status $vsftpd
  64.         RETVAL=$?    //vsftp启动脚本服务状态
  65.         ;;
  66. restart)
  67.         stop
  68.         usleep 5000000    //vsftp启动脚本服务重启操作
  69.         start
  70.         ;;
  71. *)
  72.         echo "Usage: $prog {start|stop|restart|status}"
  73.         exit 1
  74. esac
  75. exit $RETVAL

使用Apache Mod_Layout模块向网页动态插入内容

什么是Mod_Layout

Mod_Layout能在文档的头部和底部(或者一个标签的之前或之后)放置信息。使用Layout指令你可以动态地向文档的任何地方插入代码。你可以利用它把标准的免责声明增加到服务器上的所有页面,或者在所有页面的顶部放置横幅广告。Mod_Layout能处理很多种类型的文档,如html,text, CGI, Java, PHP or Perl。更多的功能需要你去挖掘。

如何安装

Mod_Layout适用于Apache 1.3 Apache 2 Apache 2.2,对于这三个版本都有对应的Mod_Layout版本下载。
mod_layout-3.1适用Apache 1.3
mod_layout-4.1适用Apache 2
mod_layout-5.1适用Apache 2.2
这三个版本都可以在http://download.tangent.org/下载。
不同的版本安装方式有些许区别,下面以Apache 2.2为例。
1、下载适合的Mod_Layout版本

  1. wget http://download.tangent.org/mod_layout-5.1.tar.gz
  2. tar xvfz mod_layout-5.1.tar.gz
  3. cd mod_layout-5.1

2、编辑Makefile文件

  1. APXS=apxs
  2. APACHECTL=apachectl
  3. CC=`apxs -q CC`
  4. INC=-I`apxs -q INCLUDEDIR` `$(APXS) -q CFLAGS` #-DLAYOUT_FILEOWNER_NAME
  5. LD_SHLIB=`apxs -q LDFLAGS_SHLIB`

主要是保证APXS和APACHECTL的路径有效。
3、开始安装

  1. make
  2. make install

如何使用

在使用之前,请确认你想插入代码的网页是否启用gzip压缩,如果启用,Mod_layout将不能正常工作。
下面是启用mod_layout的一个例子

  1. <virtualHost *:80> 
  2.     AllowOverride None 
  3.     Order allow,deny 
  4.     Allow from all 
  5. <Directory /home/foo/public_html>
  6.        AllowOverride None
  7.        Options SymLinksIfOwnerMatch
  8.        AddOutputFilter LAYOUT html
  9.        LayoutFooter /menu.html
  10.        LayoutIgnoreURI /diary/*
  11.        LayoutIgnoreURI /linux/*
  12. </Directory>
  13. </VirtualHost>

说明:
AddOutputFilter LAYOUT html:启动mod_layout的网页类型为html,你也可以添加php,shtml等
LayoutFooter /menu.html:添加到文档尾的文件menu.html。
LayoutIgnoreURI /diary/*:排除diary目录下的文档。
更多指令:http://www.musc.edu/webserver/mod_layout.html#_1_9