服务器和网站类

监测Apache运行状态,如果崩溃就重启Apache

0

首先我一直没有搞清楚为什么我的Apache会经常崩溃。这可不是什么值得炫耀的事情。所以有人能帮我分析吗?我会非常感谢。
因为Apache经常崩溃,我又查不出原因,之后写一个脚本监测Apache是死是活,如果事情不对劲,就重启Apache。
分享脚本如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/bin/bash
Apache_Thread_Num=$(ps -e | grep -c 'httpd')
Min_Normal_Thread=$(grep 'MinSpareServers' /etc/apache2/server-tuning.conf | egrep "[0-9]{1,}" -o)
if [ $Apache_Thread_Num -lt $Min_Normal_Thread ];
then
    echo time point =`date "+%Y-%m-%d-%H-%M-%S"`
    echo Apache dead, alive thread less than MinSpareServers
    echo Apache_Thread_Num=$Apache_Thread_Num
    echo Min_Normal_Thread=$Min_Normal_Thread
   # service apache2 restart
/etc/init.d/apache2 restart
#else
#       echo time point =`date "+%Y-%m-%d-%H-%M-%S"`
#       echo apache alive
#       echo Apache_Thread_Num=$Apache_Thread_Num
#       echo Min_Normal_Thread=$Min_Normal_Thread
fi

然后把它加到crontab里每分钟运行,世界似乎清静一些了。

代码高亮插件的用法和语言列表

0

本篇日志纯粹个人备忘,大部分读者可以直接忽略。
我使用WP-CodeBox做本站带代码可视化工具。 provides clean syntax highlighting and AJAX advanced features for embedding source code within pages or posts.Wrap code blocks with

Download download.txt
1
 

. The LANG is supported by wide range of popular languages syntax. The FILE will create code downloading attribute. line=”n”is the starting line number, colla=”+/-” will expand/collapse the codebox.
应该也是基于GeSHi来做的。支持语言的列表见:

http://gehrcke.de/files/perm/wp-geshi-highlight/wp-geshi-highlight_languages_1_0_5.txt

(更多…)

download.zhuwenhao.com redirected to d.zhu.im

0

偶然发现一个很简短的域名zhu.im被某人掉下来了。赶紧注册。
于是把原来的下载站download.zhuwenhao.com使用htaccess转成了d.zhu.im
大家可以使用d.zhu.im去访问我同步的Android和其他很多的源代码了。是不是方便记忆很多了?
顺便说下htaccess写法。

1
2
3
RewriteEngine On
rewritecond %{http_host} !^d\.zhu\.im [NC]
rewriterule ^(.*)$ http://d.zhu.im/$1 [R=301,NC]

优化Apache, 消除Page Speed中expiration not specified

0
本文是专题:建站日记中的第12篇,共12篇

前情提要:

Google Lab 里有一个很好的工具 Page Speed,能够分析网站是不是够快,以及如何改进。提供非常详细的改进指导。

我测试了网站http://zhuwenhao.com 其中有一个严重问题,名字叫 expiration not specified 就是说很多静态资源没有指定过期时间,所以不能被浏览器很好的做缓存,严重影响性能。这里是谷歌提供的文档 LeverageBrowserCaching

我是这样搞定的:

1:在/etc/sysconfig/apache2中开启Apache模块 mod_headers  mod_expires

2:在/ect/apache2/conf.d/中新建一个mycache.conf(其实我早就建好了:)

3:使用如下的代码

View Code APACHE
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<IfModule mod_expires.c>
  ExpiresActive on
 
# Perhaps better to whitelist expires rules? Perhaps.
  ExpiresDefault                          "access plus 1 day"
 
# cache.appcache needs re-requests in FF 3.6 (thx Remy ~Introducing HTML5)
#  ExpiresByType text/cache-manifest       "access plus 0 seconds"
 
# your document html
  #ExpiresByType text/html                 "access plus 0 seconds"
 
# data
 # ExpiresByType text/xml                  "access plus 0 seconds"
 # ExpiresByType application/xml           "access plus 0 seconds"
 # ExpiresByType application/json          "access plus 0 seconds"
 
# rss feed
#  ExpiresByType application/rss+xml       "access plus 1 hour"
 
# favicon (cannot be renamed)
  ExpiresByType image/x-icon              "access plus 2 months"
 
# media: images, video, audio
  ExpiresByType image/gif                 "access plus 1 month"
  ExpiresByType image/png                 "access plus 1 month"
  ExpiresByType image/jpg                 "access plus 1 month"
  ExpiresByType image/jpeg                "access plus 1 month"
  ExpiresByType video/ogg                 "access plus 1 month"
  ExpiresByType audio/ogg                 "access plus 1 month"
  ExpiresByType video/mp4                 "access plus 1 month"
  ExpiresByType video/webm                "access plus 1 month"
 
# htc files  (css3pie)
  ExpiresByType text/x-component          "access plus 1 month"
 
# webfonts
  ExpiresByType font/truetype             "access plus 1 month"
  ExpiresByType font/opentype             "access plus 1 month"
  ExpiresByType application/x-font-woff   "access plus 1 month"
  ExpiresByType image/svg+xml             "access plus 1 month"
  ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
 
# css and javascript
  ExpiresByType text/css                  "access plus 2 months"
  ExpiresByType application/javascript    "access plus 2 months"
  ExpiresByType text/javascript           "access plus 2 months"
  ExpiresByType text/x-js                 "access plus 2 months"
 
  <IfModule mod_headers.c>
    Header append Cache-Control "public"
  </IfModule>
 
</IfModule>

我的解决方法参考了帖子: specifing-expiration-date-for-static-files-caches 但代码是不一样的,请注意根据需要修改

重申我用的是 openSUSE, 所以配置文件的路径可能不同.

服务器升级至openSUSE 11.4 Apache改为Worker+PHP+fastcgi

0
本文是专题:建站日记中的第11篇,共12篇

利用假期,我把本站的服务器和配置都做了下升级.

openSUSE从11.2升级至11.4,非常成功,没有遇到大问题.

主要步骤:

1, 更新Software Repositories指向11.4版本的库.

2, zypper update , 解决依赖性. 升级一些包,降级一些包. 以前用开发分支的Apache, PHP, mysql要先降级.幸好这个危险的过程没有出任何问题.

3, zypper dup, 将会做完全的版本升级.

然后是Apache配置由perfork改为Worker的MPM.

1, 删除mod_php, 确认PHP支持CLI

2, 安装 mod_fcgid mod_fastcgi

3, 修改 /etc/sysconfig/apache2 中的APACHE_MODULES字段, 删除php, 增加actions, facgid, fastcgi

4, 修改路径 /etc/apache2/conf.d/ 中的 mod_fcgid.conf 去掉<FilesMatch “\.php$”>这一块内容的注释.

最后 service apache2 restart 就搞定了.

完成后,可以看出Apache本事基本不消耗多少内存,但是PHP占用内存仍然很多. 所以Apache头上占用内存的坏名声可以洗脱了.一切都是PHP惹的祸.

在这种配置下, 使用 ab 工具测试, 在Apache过载之后,网页会出现500错误,但随着DDOS的结束, server能够自行恢复. 不像以前用perfork的时候,Apache就死了. 读Apache错误日志, 会发现Apache给失去响应的PHP发了一堆的signal 11. Good Job!

 

Go to Top