IT log

moral & concision is my dream.

hmailserver error and mysql study log

这些天只要是工作时间 hmailserver 总会出现只能接收外部邮件但无法收发邮件的情况,  错误日志的描述是:
“ERROR”    1800    “2009-05-05 07:13:50.390″    “Severity: 2 (High), Code: HM4208, Source: Thread::ThreadFunc, Description: An error occurred while running thread.  Returning thread to pool. Error number: 10060, Description: 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。”

我一直在 hmailserver  上查找原因, 升级啊, 优化啊, 做了好多遍也没起作用. 因为其他服务mysql 和 apache 在我看了网站访问没问题, 他们也应该没问题才对.

我突然意识到一个问题,也许是由于垃圾邮件的缘故导致 mysql 并发连接数超限, 使得 hmailserver 认为 mysql 服务断开了.

仿照我 centos 中的设置, 在另一个子公司的此邮件和网站服务器 windows 2003 上设置 apache 的分页日志参数为:
ErrorLog   “|d:/xampp/apache/bin/rotatelogs.exe d:/logs/zuolo_Error_%Y%m%d.log 2M”
CustomLog   “|d:/xampp/apache/bin/rotatelogs.exe d:/logs/zuolo_access_%Y%m%d.log 864000″   common

并且发现之前服务器上的 mysql 没有输错误日志, 故在 my.cnf 中添加参数:
log_error=”d:/mysql_error.log”

这样以后 hmailserver错误出现时, 我就可以对照看看 mysql 当时是不是也出现问题了.

在服务器上使用 mysql administrator 查看 Heal 功能中的 Status Variables 和 System Variables 情况, 发现现在都深夜了, 视图连接到 mysql 的次数是 513, 而系统默认最大的连接数只有100, 不过已用的连接只有8, 就是不知道高峰期会达到多少. 如果没有安装软件可以登录 mysql 控制台后, 用命令 SHOW VARIABLES LIKE ‘%conn%’; 和 SHOW STATUS LIKE ‘%conn%’; 来查看系统和当前参数情况, 使用命令 show full processlist 则可以查看当前进程/有哪些mysql连接/有哪些数据库在使用.

一般情况下100个最大连接应该足够了, 但我发现代码操作超时参数的 wait_timeout 和 interactive_timeout  都值为 28800 , 也就是8个小时, 时间太长了, 这样如果有很多坏的连接就会导致mysql 超过连接上限了.

还有一个参数 max_connect_errors 是用来统计某个主机的错误链接的, 一旦超过将阻止它, 我想这个参数才是真正导致 hmailserver 无法访问 mysql 的原因吧.  如果是这个原因的话, 可以通过 运行 flush hosts; 来清空被 mysql 阻止的主机缓存.

又看到一个重要的参数 back_log 设置突发连接, 如果邮件服务器突然收到大量垃圾邮件, 则会导致突发连接过多, 也可能是这个参数, 默认值为 50 , 建议更改为500.

下面我对 my.cnf 优化后的参数:

back_log=512
interactive_timeout=512
max_connect_errors=1024
max_connections=1024
wait_timeout=512
key_buffer_size=256M
query_cache_size=128M
myisam_sort_buffer_size=128M
read_buffer_size=16M
read_rnd_buffer_size=16M
sort_buffer_size=32M
table_cache=512
thread_cache_size=80
join_buffer_size=8M

参考资料如下:

5.1.3. Server System Variables

http://dev.mysql.com/doc/refman/6.0/en/server-system-variables.html#sysvar_myisam_max_sort_file_size

MySQL配置文件my.cnf 例子最详细翻译,可以保存做笔

http://blog.sina.com.cn/s/blog_45a590db0100c0c8.html

优化mysql性能的十个参数的详细介绍

http://www.sqlserver.com.cn/c2l0ZS9zaG93Lmh0bWw_bXlpZD0xMzI3url.html

MySQL优化经验

http://kb.discuz.net/index.php?title=MySQL%E4%BC%98%E5%8C%96%E7%BB%8F%E9%AA%8C

MySQL优化经验 key_buffer_size,query_cache_size,table_cache

http://www.01hr.com/wenzhang/1715759.htm

posted by Leon Tsang in Live - Work and Struggle and have No Comments

Place your comment

Please fill your data and comment below.
Name
Email
Website
Your comment