Skip to content


解决nginx access日志中400 bad request 错误

在access.log中有大量400错误,并以每天几百M的速度增加,占用大量空间.
tail -f /opt/nginx/logs/access.log

116.236.228.180 – – [15/Dec/2010:11:00:15 +0800] “-” 400 0 “-” “-”
116.236.228.180 – – [15/Dec/2010:11:00:15 +0800] “-” 400 0 “-” “-”
116.236.228.180 – – [15/Dec/2010:11:00:15 +0800] “-” 400 0 “-” “-”
116.236.228.180 – – [15/Dec/2010:11:00:15 +0800] “-” 400 0 “-” “-”
116.236.228.180 – – [15/Dec/2010:11:00:15 +0800] “-” 400 0 “-” “-”
119.97.196.7 – – [15/Dec/2010:11:00:16 +0800] “-” 400 0 “-” “-”
119.97.196.7 – – [15/Dec/2010:11:00:16 +0800] “-” 400 0 “-” “-”
116.236.228.180 – – [15/Dec/2010:11:00:16 +0800] “-” 400 0 “-” “-”
116.236.228.180 – – [15/Dec/2010:11:00:16 +0800] “-” 400 0 “-” “-”
116.236.228.180 – – [15/Dec/2010:11:00:16 +0800] “-” 400 0 “-” “-”
116.236.228.180 – – [15/Dec/2010:11:00:16 +0800] “-” 400 0 “-” “-”
116.236.228.180 – – [15/Dec/2010:11:00:16 +0800] “-” 400 0 “-” “-”
116.236.228.180 – – [15/Dec/2010:11:00:16 +0800] “-” 400 0 “-” “-”
116.236.228.180 – – [15/Dec/2010:11:00:16 +0800] “-” 400 0 “-” “-”
116.236.228.180 – – [15/Dec/2010:11:00:16 +0800] “-” 400 0 “-” “-”
219.243.95.197 – – [15/Dec/2010:11:00:16 +0800] “-” 400 0 “-” “-”
116.236.228.180 – – [15/Dec/2010:11:00:16 +0800] “-” 400 0 “-” “-”
116.236.228.180 – – [15/Dec/2010:11:00:16 +0800] “-” 400 0 “-” “-”

网上大把的文章说是HTTP头/Cookie过大引起的,可以修改nginx.conf中两参数来修正.

client_header_buffer_size 16k;
large_client_header_buffers 4 32k;

修改后

client_header_buffer_size 64k;
large_client_header_buffers 4 64k;

没有效果,就算我把nginx0.7.62升到最新的0.8.54也没能解决.
官方论坛中nginx作者提到空主机头不会返回自定义的状态码,是返回400错误.
http://forum.nginx.org/read.php?2,9695,11560

最后修正如下
改为原先的值

client_header_buffer_size 16k;
large_client_header_buffers 4 32k;

关闭默认主机的日志记录就可以解决问题

server {
listen *:80 default;
server_name _;
return 444;
access_log off;
}

Posted in Nginx, 技术.

Tagged with , .


discuz 7.2 后台添加ip禁止时的bug

后台添加ip禁止时如果去除有效期保持为空,会造成服务器负载直线上升,数据库大量空连接,网站不能访问.
删险添加的记录并重新生成缓存后可解决问题.

Posted in Discuz/Uchome/Ucenter, 其它.

Tagged with .


mysqlreport 查看mysql状态

mysqlreport以非常友好的方式显示MySQL状态变量值。和SHOW STATUS不同,mysqlreport以一种非常格式化的方式输出状态值,具有非常好的可读性。

wget http://hackmysql.com/scripts/mysqlreport-3.5.tgz
tar zxvf mysqlreport-3.5.tgz
cd mysqlreport-3.5
chmod +x mysqlreport
./mysqlreport

Use of uninitialized value in subtraction (-) at ./mysqlreport line 648.
Use of uninitialized value in subtraction (-) at ./mysqlreport line 648.
Use of uninitialized value in multiplication (*) at ./mysqlreport line 648.
Use of uninitialized value in multiplication (*) at ./mysqlreport line 652.
Use of uninitialized value in multiplication (*) at ./mysqlreport line 652.
MySQL 5.1.26-rc uptime 0 2:57:2 Wed Nov 17 14:48:32 2010

__ Key _________________________________________________________________
Buffer used 366.25M of 3.02G %Used: 11.83
Current 944.89M %Usage: 30.52
Write hit 52.83%
Read hit 99.95%

__ Questions ___________________________________________________________
Total 6.76M 636.3/s
DMS 3.34M 314.0/s %Total: 49.35
Com_ 1.92M 180.5/s 28.36
COM_QUIT 823.41k 77.5/s 12.18
QC Hits 684.24k 64.4/s 10.12
-Unknown 978 0.1/s 0.01
Slow 10 s 83 0.0/s 0.00 %DMS: 0.00 Log: OFF
DMS 3.34M 314.0/s 49.35
SELECT 2.47M 232.2/s 36.49 73.94
UPDATE 360.06k 33.9/s 5.33 10.80
INSERT 238.60k 22.5/s 3.53 7.15
DELETE 172.46k 16.2/s 2.55 5.17
REPLACE 97.91k 9.2/s 1.45 2.94
Com_ 1.92M 180.5/s 28.36
set_option 1.12M 105.5/s 16.57
change_db 743.18k 70.0/s 11.00
show_variab 26.44k 2.5/s 0.39

__ SELECT and Sort _____________________________________________________
Scan 90.27k 8.5/s %SELECT: 3.66
Range 94.02k 8.9/s 3.81
Full join 35 0.0/s 0.00
Range check 0 0/s 0.00
Full rng join 0 0/s 0.00
Sort scan 59.49k 5.6/s
Sort range 136.07k 12.8/s
Sort mrg pass 0 0/s

__ Query Cache _________________________________________________________
Memory usage 50.50M of 128.00M %Used: 39.45
Block Fragmnt 24.56%
Hits 684.24k 64.4/s
Inserts 2.39M 224.6/s
Insrt:Prune 2.39M:1 224.6/s
Hit:Insert 0.29:1

__ Table Locks _________________________________________________________
Waited 156.42k 14.7/s %Total: 3.20
Immediate 4.73M 445.4/s

__ Tables ______________________________________________________________
Open 1238 of 3072 %Cache: 40.30
Opened 2.27k 0.2/s

__ Connections _________________________________________________________
Max used 111 of 350 %Max: 31.71
Total 824.31k 77.6/s

__ Created Temp ________________________________________________________
Disk table 29.99k 2.8/s
Table 100.82k 9.5/s Size: 1.0G
File 0 0/s

__ Threads _____________________________________________________________
Running 2 of 4
Cached 76 of 80 %Hit: 99.97
Created 208 0.0/s
Slow 0 0/s

__ Aborted _____________________________________________________________
Clients 1.78k 0.2/s
Connects 42 0.0/s

__ Bytes _______________________________________________________________
Sent 13.50G 1.3M/s
Received 1.08G 101.5k/s

mysql配置信息参照之前的优化
http://blog.c1gstudio.com/archives/1142

Posted in Mysql, 技术.

Tagged with , .


tuning-primer.sh 调优MySQL的性能

安装运行

wget http://www.day32.com/MySQL/tuning-primer.sh
chmod +x tuning-primer.sh

运行时你可以选择在用户目录下生成一个保存mysql密码的.my.cnf文件方便下次调用
~/.my.cnf文件内容应该是这样的
cat ~/.my.cnf

[client]
user=test
password=123qwe
socket=/opt/mysql/mysql.sock

./tuning-primer.sh

Using login values from ~/.my.cnf
– INITIAL LOGIN ATTEMPT FAILED –
Testing for stored webmin passwords:
None Found
Could not auto detect login info!
Found Sockets: /opt/mysql/mysql.sock
Using: /opt/mysql/mysql.sock
Would you like to provide a different socket?: [y/N] n
Do you have your login handy ? [y/N] : y
User: test
Password: 123qwe

Would you like me to create a ~/.my.cnf file for you? [y/N] : y

~/.my.cnf already exists!

Replace ? [y/N] : y
– FINAL LOGIN ATTEMPT FAILED –
Unable to log into socket: /opt/mysql/mysql.sock

因为我的mysql是编译安装在/opt/mysql/下,这里找不到执行文件,所以没有连接上.
编辑第219和220行,手动修改文件加上路径
vi tuning-primer.sh

215 if [ -f /etc/psa/.psa.shadow ] ; then
216 mysql=”mysql -S $socket -u admin -p$(cat /etc/psa/.psa.shadow)”
217 mysqladmin=”mysqladmin -S $socket -u admin -p$(cat /etc/psa/.psa.shadow)”
218 else
219 mysql=”/opt/mysql/bin/mysql”
220 mysqladmin=”/opt/mysql/bin/mysqladmin”
221 # mysql=”mysql -S $socket”
222 # mysqladmin=”mysqladmin -S $socket”
223 fi

顺带修复生成密码时的错误问题.
第313行”$pass\”后面需加个”n”

313 printf “[client]\nuser=$user\npassword=$pass\nsocket=$socket” > ~/.my.cnf

提示:vi中显示行号方法.在命令模式下输入”:set number”

保存后再次运行,在终端上按照问题重要程度分别用黄色/红色字符标记问题
./tuning-primer.sh

— MYSQL PERFORMANCE TUNING PRIMER —
– By: Matthew Montgomery –

MySQL Version 5.1.26-rc x86_64

Uptime = 0 days 7 hrs 17 min 18 sec
Avg. qps = 286
Total Questions = 7527430
Threads Connected = 6

Warning: Server has not been running for at least 48hrs.
It may not be safe to use these recommendations

To find out more information on how each of these
runtime variables effects performance visit:
http://dev.mysql.com/doc/refman/5.1/en/server-system-variables.html
Visit http://www.mysql.com/products/enterprise/advisors.html
for info about MySQL’s Enterprise Monitoring and Advisory Service

SLOW QUERIES
The slow query log is NOT enabled.
Current long_query_time = 10.000000 sec.
You have 29 out of 7527516 that take longer than 10.000000 sec. to complete
Your long_query_time seems to be fine

BINARY UPDATE LOG
The binary update log is NOT enabled.
You will not be able to do point in time recovery
See http://dev.mysql.com/doc/refman/5.1/en/point-in-time-recovery.html

WORKER THREADS
Current thread_cache_size = 80
Current threads_cached = 75
Current threads_per_sec = 0
Historic threads_per_sec = 0
Your thread_cache_size is fine

MAX CONNECTIONS
Current max_connections = 350
Current threads_connected = 7
Historic max_used_connections = 208
The number of used connections is 59% of the configured maximum.
Your max_connections variable seems to be fine.

No InnoDB Support Enabled!

MEMORY USAGE
Max Memory Ever Allocated : 68.78 G
Configured Max Per-thread Buffers : 112.17 G
Configured Max Global Buffers : 2.12 G
Configured Max Memory Limit : 114.29 G
Physical Memory : 15.66 G

nMax memory limit exceeds 90% of physical memory

KEY BUFFER
Current MyISAM index space = 3.00 G
Current key_buffer_size = 2.00 G
Key cache miss rate is 1 : 3262
Key buffer free ratio = 62 %
Your key_buffer_size seems to be fine

QUERY CACHE
Query cache is enabled
Current query_cache_size = 128 M
Current query_cache_used = 61 M
Current query_cache_limit = 2 M
Current Query cache Memory fill ratio = 47.81 %
Current query_cache_min_res_unit = 2 K
Query Cache is 21 % fragmented
Run “FLUSH QUERY CACHE” periodically to defragment the query cache memory
If you have many small queries lower ‘query_cache_min_res_unit’ to reduce fragmentation.
MySQL won’t cache query results that are larger than query_cache_limit in size

SORT OPERATIONS
Current sort_buffer_size = 256 M
Current read_rnd_buffer_size = 32 M
Sort buffer seems to be fine

JOINS
Current join_buffer_size = 32.00 M
You have had 15 queries where a join could not use an index properly
join_buffer_size >= 4 M
This is not advised
You should enable “log-queries-not-using-indexes”
Then look for non indexed joins in the slow query log.

OPEN FILES LIMIT
Current open_files_limit = 51200 files
The open_files_limit should typically be set to at least 2x-3x
that of table_cache if you have heavy MyISAM usage.
Your open_files_limit value seems to be fine

TABLE CACHE
Current table_open_cache = 3072 tables
Current table_definition_cache = 256 tables
You have a total of 658 tables
You have 1814 open tables.
The table_cache value seems to be fine
You should probably increase your table_definition_cache value.

TEMP TABLES
Current max_heap_table_size = 384 M
Current tmp_table_size = 1.00 G
Of 142450 temp tables, 18% were created on disk
Effective in-memory tmp_table_size is limited to max_heap_table_size.
Created disk tmp tables ratio seems fine

TABLE SCANS
Current read_buffer_size = 8 M
Current table scan ratio = 5065 : 1
read_buffer_size seems to be fine

TABLE LOCKING
Current Lock Wait ratio = 1 : 25
You may benefit from selective use of InnoDB.
If you have long running SELECT’s against MyISAM tables and perform
frequent updates consider setting ‘low_priority_updates=1’
If you have a high concurrency of inserts on Dynamic row-length tables
consider setting ‘concurrent_insert=2’.

我的my.cnf

[mysqld]
port = 3306
socket = /opt/mysql/mysql.sock
skip-locking
skip-name-resolve
back_log=100
key_buffer_size = 2048M
query_cache_size = 128M
query_cache_limit = 2M #default=1M
query_cache_min_res_unit = 2k #default=4K

max_allowed_packet = 16M
table_cache = 3072

tmp_table_size = 1024M #default=16M
max_heap_table_size = 384M #default=16M

read_buffer_size = 8M
read_rnd_buffer_size = 32M

sort_buffer_size = 256M
join_buffer_size = 32M
myisam_sort_buffer_size = 256M
thread_cache_size = 80 #default=0
thread_stack = 192K #default=192K

# Try number of CPU’s*2 for thread_concurrency
thread_concurrency = 16 #default=10
connect_timeout = 30
#interactive timeout = 600
max_connection = 350
max_connect_errors = 30
wait_timeout = 30

服务配置为5504(4核) *2,16G内存,centos 5.3 64位
大大小小十几个数据库,几十G数据,主要的应用是discuz论坛

根据提示对my.cnf做一些优化,效率更好了点.
关键还是需要优化sql来减少慢查询及锁定的问题.

key_buffer_size = 3096M
table_definition_cache = 800
join_buffer_size = 4M
low_priority_updates =1

参考:http://www.chedong.com/blog/archives/001451.html

Posted in Mysql, 技术.

Tagged with , , .


获取TinyMce编辑器的内容

由于TinyMce编辑器的内容不能用js直接获取,否则获取的永远是初始化时候的值,必须使用它们内部提供的函数。

函数如下:

来源:
http://www.ourys.com/?s=tinymce

Posted in TinyMce, 技术.

Tagged with .


foreach 使用”引用”遍历数组时的问题


$testarr = array(‘a’,’b’,’c’);

foreach( $testarr as $k=>&$v ) {
echo $k.”=>”.$v.”
“;
}
echo “——-
“;
foreach( $testarr as $k=>$v ) {
echo $k.”=>”.$v.”
“;
}

你可能以为结果为

0=>a
1=>b
2=>c
——-
0=>a
1=>b
2=>c

实际输出是

0=>a
1=>b
2=>c
——-
0=>a
1=>b
2=>b

这是什么道理?

Posted in PHP, 技术.

Tagged with , , .


curl_setopt(): CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an open_basedir is set in

当系统开启safe_mode和 open_basedir,在程序中使用以下语句
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
并且遇到301,302状态吗时会出现错误

[11-Oct-2010 14:17:41] PHP Warning: curl_setopt(): CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an open_basedir is set in msn.class.php on line 819

解决方法是在curl语句用不使用curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true),在php函数中自定义一个函数

curl_redir_exec函数
curl_redir_exec

curl_redir_exec($ch)替换curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true)语句

参考:

http://spoint.babyshoot.cn/archives/2009/11/curlopt-php.html
http://www.php.net/manual/en/function.curl-setopt.php

Posted in PHP, 技术.

Tagged with , .


FireFox 3.6与discuz7.2 兼容问题

当firefox升级到3.6时,论坛登录框的不能显示,发贴时不能勾选源码按钮. 

编辑include/js/common.js


BROWSER.firefox = document.getBoxObjectFor &&  USERAGENT.indexOf(‘firefox’) != -1 && USERAGENT.substr(USERAGENT.indexOf(‘firefox’) + 8, 3);

去掉
document.getBoxObjectFor && 

保存,然后到后台更新缓存.

参考:
http://www.discuz.net/thread-1553662-1-1.html
http://www.discuz.net/thread-1553664-1-1.html

Posted in Discuz/Uchome/Ucenter, 其它.

Tagged with , .


备份时内核出错Unable to handle kernel NULL pointer dereference at virtual address

备份十几万图片文件时碰到内核出错,reboot等命令也无法重启。

重启后再试还是出错。

<coolcode>

SELinux: initialized (dev rpc_pipefs, type rpc_pipefs), uses genfs_contexts
Losing some ticks… checking if CPU frequency changed.
Unable to handle kernel NULL pointer dereference at virtual address 000000f8
 printing eip:
c02c4ecb
*pde = 00004001
Oops: 0000 [#1]
SMP
Modules linked in: autofs4 sunrpc ipt_state iptable_filter iptable_nat ip_conntrack iptable_mangle ip_tables dm_mod button battery ac uhci_hcd ehci_hcd tg3 floppy ext3 jbd ata_piix libata aic79xx sd_mod scsi_mod
CPU:    1
EIP:    0060:[<c02c4ecb>]    Not tainted VLI
EFLAGS: 00010046   (2.6.9-5.ELsmp)
EIP is at _spin_lock_irqsave+0x7/0x45
eax: 000000f4   ebx: 00000246   ecx: c2024d60   edx: 00000200
esi: 000000f4   edi: 00000283   ebp: f7fecf68   esp: f7fecf50
ds: 007b   es: 007b   ss: 0068
Process khelper (pid: 14, threadinfo=f7fec000 task=f7f67230)
Stack: 000000f0 000000f4 c011cfa7 e191be40 e191be44 00000283 f7eb2000 c012e837
       e191be80 c012e498 ffffffff ffffffff 00000001 00000000 c011ce93 00010000
       00000000 c0400e20 c201cd60 00000000 00000000 f7f67230 c011ce93 00100100
Call Trace:
 [<c011cfa7>] complete+0x12/0x3d
 [<c012e837>] worker_thread+0x168/0x1d5
 [<c012e498>] __call_usermodehelper+0x0/0x41
 [<c011ce93>] default_wake_function+0x0/0xc
 [<c011ce93>] default_wake_function+0x0/0xc
 [<c012e6cf>] worker_thread+0x0/0x1d5
 [<c0131dcd>] kthread+0x73/0x9b
 [<c0131d5a>] kthread+0x0/0x9b
 [<c01041f1>] kernel_thread_helper+0x5/0xb
Code: 6c 00 6c 74 2d c0 0f b6 02 84 c0 7e 08 0f 0b 6d 00 6c 74 2d c0 86 0a c3 f0 81 00 00 00 00 01 c3 f0 ff 00 c3 56 89 c6 53 9c 5b fa <81> 78 04 ad 4e ad de 74 18 ff 74 24 08 68 5f 83 2d c0 e8 24 bd
</coolcode>

Posted in 备份, 技术.

Tagged with , , .


网站服务器所使用的各 Linux 发行版统计数据对比分析

网站服务器所使用的各 Linux 发行版统计数据对比分析:
CentOS 增长最快,Debain 平稳发展,Ubuntu 稍有提升
Red Hat和Fedora略有下降

 

Historical trends in the usage of Linux versions for websites

This report shows the historical trends in the usage of Linux versions since October 2009.

  2009
1 Oct
2009
1 Nov
2009
1 Dec
2010
1 Jan
2010
1 Feb
2010
1 Mar
2010
1 Apr
2010
1 May
2010
1 Jun
2010
1 Jul
2010
1 Aug
2010
1 Sep
2010
3 Sep
CentOS 23.4% 22.0% 21.6% 22.1% 22.8% 23.5% 24.9% 25.8% 27.5% 29.9% 31.8% 33.3% 33.4%
Debian 26.5% 28.0% 28.5% 28.6% 28.4% 28.3% 28.1% 28.1% 27.7% 27.0% 26.5% 26.0% 26.0%
Red Hat 21.0% 21.4% 21.7% 21.5% 21.1% 20.6% 19.7% 19.2% 18.4% 17.5% 16.7% 16.1% 16.1%
Ubuntu 8.8% 8.7% 8.8% 9.0% 9.2% 9.5% 9.8% 9.9% 10.0% 10.1% 10.1% 10.2% 10.2%
Fedora 11.3% 11.0% 10.7% 10.3% 10.0% 9.7% 9.2% 8.9% 8.6% 8.1% 7.8% 7.5% 7.4%
SuSE 6.2% 6.1% 6.0% 5.9% 5.6% 5.6% 5.3% 5.3% 5.1% 4.8% 4.6% 4.5% 4.5%
Gentoo 2.6% 2.5% 2.5% 2.5% 2.5% 2.5% 2.5% 2.4% 2.4% 2.3% 2.2% 2.2% 2.1%
Mandriva 0.2% 0.2% 0.2% 0.2% 0.2% 0.2% 0.2% 0.2% 0.2% 0.2% 0.2% 0.2% 0.2%
Turbolinux         0.1% 0.1% 0.2% 0.2% 0.2% 0.1% 0.1% 0.1% 0.1%

The diagram shows only Linux versions with more than 1% usage.

Historical trends in the usage of Linux versions

来源:

http://w3techs.com/technologies/history_details/os-linux

Posted in LINUX, 技术.

Tagged with , .