Chinaunix

标题: 恳请高手指点,1G内存VPS的MYSQL数据库配置文件MY.CNF的优化方案 [打印本页]

作者: 腐败网    时间: 2011-12-21 14:06
标题: 恳请高手指点,1G内存VPS的MYSQL数据库配置文件MY.CNF的优化方案
本帖最后由 腐败网 于 2012-01-24 21:28 编辑

LINUX系统的VPS
内存 1G
硬盘 40G,闲置空间 18G
一颗CPU,Intel(R) Xeon(R) CPU E5506 @ 2.13GHz,限制多少不知道

现在CPU占用很高,经查,是MYSQL数据库占用资源较多
见下图

mysql日志.part05.rar (286.95 KB, 下载次数: 24) mysql日志.part04.rar (1.39 MB, 下载次数: 15) mysql日志.part03.rar (1.39 MB, 下载次数: 28) mysql日志.part02.rar (1.39 MB, 下载次数: 15) mysql日志.part01.rar (1.39 MB, 下载次数: 18) slow_log.rar (1.38 MB, 下载次数: 27)

所以现在想优化一下数据库的配置文件
数据库状态见下图



下面是现有配置文件内容:

# Example MySQL config file for very large systems.
#
# This is for a large system with memory of 1G-2G where the system runs mainly
# MySQL.
#
# MySQL programs look for option files in a set of
# locations which depend on the deployment platform.
# You can copy this option file to one of those
# locations. For information about these locations, see:
# http://dev.mysql.com/doc/mysql/en/option-files.html
#
# In this file, you can use all long options that a program supports.
# If you want to know which options a program supports, run the program
# with the "--help" option.

# The following options will be passed to all MySQL clients
[client]
#password        = your_password
port                = 3306
socket                = /tmp/mysql.sock

# Here follows entries for some specific programs

# The MySQL server
[mysqld]
port                = 3306
socket                = /tmp/mysql.sock
skip-locking
key_buffer_size = 128M
max_allowed_packet = 16M
table_open_cache = 65535
sort_buffer_size = 4M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size = 32M
# Try number of CPU's*2 for thread_concurrency
thread_concurrency = 8

# Don't listen on a TCP/IP port at all. This can be a security enhancement,
# if all processes that need to connect to mysqld run on the same host.
# All interaction with mysqld must be made via Unix sockets or named pipes.
# Note that using this option without enabling named pipes on Windows
# (via the "enable-named-pipe" option) will render mysqld useless!
#
#skip-networking

# Replication Master Server (default)
# binary logging is required for replication
log-bin=mysql-bin

# required unique id between 1 and 2^32 - 1
# defaults to 1 if master-host is not set
# but will not function as a master if omitted
server-id        = 1

# Replication Slave (comment out master section to use this)
#
# To configure this host as a replication slave, you can choose between
# two methods :
#
# 1) Use the CHANGE MASTER TO command (fully described in our manual) -
#    the syntax is:
#
#    CHANGE MASTER TO MASTER_HOST=<host>, MASTER_PORT=<port>,
#    MASTER_USER=<user>, MASTER_PASSWORD=<password> ;
#
#    where you replace <host>, <user>, <password> by quoted strings and
#    <port> by the master's port number (3306 by default).
#
#    Example:
#
#    CHANGE MASTER TO MASTER_HOST='125.564.12.1', MASTER_PORT=3306,
#    MASTER_USER='joe', MASTER_PASSWORD='secret';
#
# OR
#
# 2) Set the variables below. However, in case you choose this method, then
#    start replication for the first time (even unsuccessfully, for example
#    if you mistyped the password in master-password and the slave fails to
#    connect), the slave will create a master.info file, and any later
#    change in this file to the variables' values below will be ignored and
#    overridden by the content of the master.info file, unless you shutdown
#    the slave server, delete master.info and restart the slaver server.
#    For that reason, you may want to leave the lines below untouched
#    (commented) and instead use CHANGE MASTER TO (see above)
#
# required unique id between 2 and 2^32 - 1
# (and different from the master)
# defaults to 2 if master-host is set
# but will not function as a slave if omitted
#server-id       = 2
#
# The replication master for this slave - required
#master-host     =   <hostname>
#
# The username the slave will use for authentication when connecting
# to the master - required
#master-user     =   <username>
#
# The password the slave will authenticate with when connecting to
# the master - required
#master-password =   <password>
#
# The port the master is listening on.
# optional - defaults to 3306
#master-port     =  <port>
#
# binary logging - not required for slaves, but recommended
#log-bin=mysql-bin
#
# binary logging format - mixed recommended
#binlog_format=mixed

# Uncomment the following if you are using InnoDB tables
#innodb_data_home_dir = /usr/local/mysql/var
#innodb_data_file_path = ibdata1:2000M;ibdata2:10M:autoextend
#innodb_log_group_home_dir = /usr/local/mysql/var
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high

# Set .._log_file_size to 25 % of buffer pool size

innodb_buffer_pool_size = 512M
innodb_additional_mem_pool_size = 8M
innodb_log_file_size = 5M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
innodb_max_dirty_pages_pct=90
innodb_open_files=65535

innodb_file_per_table=1

# innodb_flush_method=O_DIRECT

query_cache_size=128M

log_slow_queries=1
slow_launch_time=1
long_query_time=0.5
log_output=table




[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates

[myisamchk]
key_buffer_size = 256M
sort_buffer_size = 256M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]


想请高手们指点一下,我现在要如何优化MY.CNF
作者: 腐败网    时间: 2011-12-21 14:10
顶一下
作者: 小版主杀手    时间: 2011-12-21 14:27
本帖最后由 小版主杀手 于 2011-12-21 14:31 编辑

开启慢查询 看看哪些语句要优化的,如加索引或者其他的优化
# Try number of CPU's*2 for thread_concurrency
thread_concurrency = 8

这个取消掉 或者改为2看
作者: 腐败网    时间: 2011-12-25 23:44
谢谢!
我试试看
作者: kerlion    时间: 2011-12-27 18:01
提示: 作者被禁止或删除 内容自动屏蔽
作者: 腐败网    时间: 2011-12-28 13:58
回复 5# kerlion

是远程SSH连接上后,输入top

   
作者: 小版主杀手    时间: 2011-12-28 14:53
腐败网 发表于 2011-12-28 13:58
回复 5# kerlion

是远程SSH连接上后,输入top


现在CPU占用如何了?
作者: longxibendi    时间: 2011-12-29 21:15
cgi也挺多
作者: 腐败网    时间: 2012-01-05 02:39
回复 7# 小版主杀手


    我换了几个服务器,现在这个似乎好点了,但是不是也会占用过高
慢查询我不会搞
所以一时还不知道怎么处理
谢谢你的关注
如果可能可否指点一下
作者: 小版主杀手    时间: 2012-01-05 09:39
腐败网 发表于 2012-01-05 02:39
回复 7# 小版主杀手

my.cnf里加上
log_slow_queries = ON
log_slow_queries=slow-log
long_query_time=2---查询超过2秒的语句记录下来

看手册 和网上搜索含义
作者: 腐败网    时间: 2012-01-05 12:56
回复 10# 小版主杀手
我按照你的建议做了
请问怎么去查询记录呢?

   
作者: 小版主杀手    时间: 2012-01-05 13:48
腐败网 发表于 2012-01-05 12:56
回复 10# 小版主杀手
我按照你的建议做了
请问怎么去查询记录呢?


等应用跑段时间 看这个慢查询日志里有没有sql语句,有的话,优化下这些语句explain 下看,
作者: 腐败网    时间: 2012-01-07 11:12
本帖最后由 腐败网 于 2012-01-07 13:38 编辑

回复 12# 小版主杀手


    应该已经跑了好几天了
这个慢查询日志目录地址是什么啊
我迫不急待的想看看
作者: 小版主杀手    时间: 2012-01-09 09:15
腐败网 发表于 2012-01-07 11:12
回复 12# 小版主杀手


在你二进制目录下 或者数据存放目录下有个slow-log
,看看
作者: 腐败网    时间: 2012-01-09 23:18
本帖最后由 腐败网 于 2012-01-09 23:26 编辑

回复 14# 小版主杀手

找不到文件
真是要命了

QQ截图20120109231542.png (2.97 KB, 下载次数: 19)

QQ截图20120109231542.png

作者: 小版主杀手    时间: 2012-01-10 09:21
腐败网 发表于 2012-01-09 23:18
回复 14# 小版主杀手

找不到文件


在系统下搜索整个目录 ,不可能没有slow-log

作者: 腐败网    时间: 2012-01-10 10:57
回复 16# 小版主杀手

搞了半天,慢查询还是没打开
好像要重启服务器一次
要命
   
作者: 小版主杀手    时间: 2012-01-10 11:00
腐败网 发表于 2012-01-10 10:57
回复 16# 小版主杀手

搞了半天,慢查询还是没打开

改了my.cn 肯定要重启服务,整了半天,你没重启啊
作者: 腐败网    时间: 2012-01-10 11:13
回复 18# 小版主杀手

我重启了,在PHPMYADMIN里输入SHOW GLOBAL VARIABLES LIKE  '%slow%'
查询发现慢查询还是没开启

   



不知道哪里出错了
作者: 小版主杀手    时间: 2012-01-10 11:26
本帖最后由 小版主杀手 于 2012-01-10 11:27 编辑
腐败网 发表于 2012-01-10 11:13
回复 18# 小版主杀手

我重启了,在PHPMYADMIN里输入SHOW GLOBAL VARIABLES LIKE  '%slow%'


注:log-slow-queries参数为慢查询日志存放的位置,一般这个目录要有mysql的运行帐号的可写权限,一般都将这个目录设置为mysql的数据存放目录;

用命令开启set global slow_query_log = ON;
作者: 腐败网    时间: 2012-01-10 11:43
本帖最后由 腐败网 于 2012-01-10 11:44 编辑

回复 20# 小版主杀手

现在是打开慢查询了

    但是日志地址我没改,还是log_slow_queries=/home/ftp/1520/finerbuy_com-20120102-OwQ/finerbuy.com/log-slow.log
结果确找不到这个文件

如果那个目录MYSQL没有权限写,慢查询应该也打不开吧

MY.CNF里的目录地址和数据库查询的地址不一样

信谁啊


作者: 小版主杀手    时间: 2012-01-10 11:58
腐败网 发表于 2012-01-10 11:43
回复 20# 小版主杀手

现在是打开慢查询了


按理是my.cnf中配置中的地址
作者: 腐败网    时间: 2012-01-10 20:05
回复 22# 小版主杀手


成功了
看起来是要按照数据库显示的那个地址去找
再运行一段时间看看结果吧


   
作者: 腐败网    时间: 2012-01-11 13:55
回复 22# 小版主杀手


又来麻烦你了
这个是慢查询日志
http://bbs.chinaunix.net/forum.p ... DR8MzY2MTU4Mw%3D%3D

能否帮忙分析下啊

   
作者: 小版主杀手    时间: 2012-01-11 14:19
腐败网 发表于 2012-01-11 13:55
回复 22# 小版主杀手


# Query_time: 18.385875  Lock_time: 0.000162 Rows_sent: 20  Rows_examined: 10650
use finerbuy_com;
SET timestamp=1326166655;
SELECT bn,name,cat_id,price,store,marketable,brand_id,weight,d_order,uptime,type_id,supplier_id,goods_id,image_default,thumbnail_pic,brief,pdt_desc,mktprice,big_pic FROM ex_goods WHERE brand_id = 16 AND ex_goods.disabled = 'false' AND ex_goods.marketable='true' AND ex_goods.goods_type='normal' ORDER BY d_order  DESC ,p_order  DESC LIMIT 0, 20;

explain 这条语句,你用的phpmyadmin吧,会显示一些信息的,然后对照着优化,索引啊、联合啊什么的,你是DBA吗?可以把这些东西给你们开发应用的看看

作者: 腐败网    时间: 2012-01-11 15:25
回复 25# 小版主杀手

谢谢你
但是我不懂MYSQL,
能否直接写出explain那条语句的具体命令啊
真不好意思,还要麻烦你
   
作者: 小版主杀手    时间: 2012-01-11 15:33
腐败网 发表于 2012-01-11 15:25
回复 25# 小版主杀手

谢谢你


就是这条ya

explain SELECT bn,name,cat_id,price,store,marketable,brand_id,weight,d_order,uptime,type_id,supplier_id,goods_id,image_default,thumbnail_pic,brief,pdt_desc,mktprice,big_pic FROM ex_goods WHERE brand_id = 16 AND ex_goods.disabled = 'false' AND ex_goods.marketable='true' AND ex_goods.goods_type='normal' ORDER BY d_order  DESC ,p_order  DESC LIMIT 0, 20;


作者: 腐败网    时间: 2012-01-11 15:55
回复 27# 小版主杀手


   


结果就是这样

说明什么呢
作者: 小版主杀手    时间: 2012-01-11 16:12
腐败网 发表于 2012-01-11 15:55
回复 27# 小版主杀手

show create table ex_goods;
order by--后面这个 d_order是索引吗
作者: 腐败网    时间: 2012-01-11 23:24
本帖最后由 腐败网 于 2012-01-11 23:30 编辑

回复 29# 小版主杀手


不知道是不是索引
我搜索了一下数据库
发现有这个东西
但是进去一看,竟然是我网站后台管理员的用户名和密码



作者: 小版主杀手    时间: 2012-01-12 09:58
腐败网 发表于 2012-01-11 23:24
回复 29# 小版主杀手


你这个太乱了 你的应用和数据库是在同一台机器上,用的带宽是共享的还是独立的?把所有情况描叙出来,才好分析
作者: 腐败网    时间: 2012-01-12 10:55
回复 31# 小版主杀手

我的是VPS,都放在一起的啊
你需要什么信息,我都告诉你

   
作者: 小版主杀手    时间: 2012-01-12 11:11
腐败网 发表于 2012-01-12 10:55
回复 31# 小版主杀手

我的是VPS,都放在一起的啊


vps上面的应用和配置是服务商安装的还是你自己整上去的?如果是服务商的话,打电话让他们帮你查吧。我觉得 你这个1G内存太小了,系统、应用、数据库都要占资源,问题原因不是sql语句,sql语句在差 ,数据量不多的情况下 也不可能直接当机。
作者: 腐败网    时间: 2012-01-12 12:22
小版主杀手 发表于 2012-01-12 11:11
vps上面的应用和配置是服务商安装的还是你自己整上去的?如果是服务商的话,打电话让他们帮你查吧。我觉 ...



LINUX CENTOS 5.7是服务商装的,剩下的都是我自己装的

你说内存小,但是我查我的内存,很多都没用上




看A部分,内存很空闲,而B部分的等待进程就很多
C部分CPU忙得不行,没有空闲



再看TOP里,MYSQL刚重启不久RES就那么大了。

运行iostat -x 1
结果是这样的:
[root@localhost ~]# iostat -x 1
Linux 2.6.18-274.el5 (localhost.localdomain)    01/12/2012

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
          72.72    0.04   16.41    5.74    0.00    5.09

Device:         rrqm/s   wrqm/s   r/s   w/s   rsec/s   wsec/s avgrq-sz avgqu-sz   await  svctm  %util
sda              10.38    66.51 27.60 14.62  1037.04   649.11    39.93     1.83   43.31  10.02  42.30
sda1              1.31     0.00  0.08  0.00     2.80     0.01    33.53     0.00    9.75   9.47   0.08
sda2              1.92     0.00  0.05  0.00     2.23     0.00    43.21     0.00    8.91   7.53   0.04
sda3              7.10    66.51 27.44 14.62  1031.36   649.11    39.96     1.83   43.45  10.03  42.20

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           0.00    0.00    0.00  100.00    0.00    0.00

Device:         rrqm/s   wrqm/s   r/s   w/s   rsec/s   wsec/s avgrq-sz avgqu-sz   await  svctm  %util
sda               0.00     0.00 133.33  0.00  1066.67     0.00     8.00    43.03  323.25 322.75 4303.33
sda1              0.00     0.00  0.00  0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00
sda2              0.00     0.00  0.00  0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00
sda3              0.00     0.00 133.33  0.00  1066.67     0.00     8.00    43.03  323.25 322.75 4303.33

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
          89.47    0.00   10.53    0.00    0.00    0.00

Device:         rrqm/s   wrqm/s   r/s   w/s   rsec/s   wsec/s avgrq-sz avgqu-sz   await  svctm  %util
sda               0.00     0.00  5.26  0.00    42.11     0.00     8.00     0.00    0.00   0.00   0.00
sda1              0.00     0.00  0.00  0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00
sda2              0.00     0.00  0.00  0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00
sda3              0.00     0.00  5.26  0.00    42.11     0.00     8.00     0.00    0.00   0.00   0.00

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
          91.21    0.00    8.79    0.00    0.00    0.00

Device:         rrqm/s   wrqm/s   r/s   w/s   rsec/s   wsec/s avgrq-sz avgqu-sz   await  svctm  %util
sda               0.00     0.00  2.20  0.00   263.74     0.00   120.00     0.05   22.00  22.00   4.84
sda1              0.00     0.00  0.00  0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00
sda2              0.00     0.00  0.00  0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00
sda3              0.00     0.00  2.20  0.00   263.74     0.00   120.00     0.05   22.00  22.00   4.84

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
          91.43    0.00    8.57    0.00    0.00    0.00

Device:         rrqm/s   wrqm/s   r/s   w/s   rsec/s   wsec/s avgrq-sz avgqu-sz   await  svctm  %util
sda               0.00     0.00  0.00  0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00
sda1              0.00     0.00  0.00  0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00
sda2              0.00     0.00  0.00  0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00
sda3              0.00     0.00  0.00  0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
          84.85    0.00   15.15    0.00    0.00    0.00

Device:         rrqm/s   wrqm/s   r/s   w/s   rsec/s   wsec/s avgrq-sz avgqu-sz   await  svctm  %util
sda               0.00   327.27  0.00 54.55     0.00  3054.55    56.00     0.47    8.56   0.61   3.33
sda1              0.00     0.00  0.00  0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00
sda2              0.00     0.00  0.00  0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00
sda3              0.00   327.27  0.00 54.55     0.00  3054.55    56.00     0.47    8.56   0.61   3.33

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
          90.00    0.00   10.00    0.00    0.00    0.00

Device:         rrqm/s   wrqm/s   r/s   w/s   rsec/s   wsec/s avgrq-sz avgqu-sz   await  svctm  %util
sda               0.00     0.00  0.00  0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00
sda1              0.00     0.00  0.00  0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00
sda2              0.00     0.00  0.00  0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00
sda3              0.00     0.00  0.00  0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
          93.88    0.00    6.12    0.00    0.00    0.00

Device:         rrqm/s   wrqm/s   r/s   w/s   rsec/s   wsec/s avgrq-sz avgqu-sz   await  svctm  %util
sda               0.00     0.00 57.14  0.00   783.67     0.00    13.71     1.39   24.32  22.50 128.57
sda1              0.00     0.00  0.00  0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00
sda2              0.00     0.00  0.00  0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00
sda3              0.00     0.00 57.14  0.00   783.67     0.00    13.71     1.39   24.32  22.50 128.57

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
          52.63    0.00   10.53   36.84    0.00    0.00

Device:         rrqm/s   wrqm/s   r/s   w/s   rsec/s   wsec/s avgrq-sz avgqu-sz   await  svctm  %util
sda               0.00     0.00 300.00 10.53  2652.63    84.21     8.81     4.92   15.85  15.81 491.05
sda1              0.00     0.00  0.00  0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00
sda2              0.00     0.00  0.00  0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00
sda3              0.00     0.00 300.00 10.53  2652.63    84.21     8.81     4.92   15.85  15.81 491.05

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
          62.07    0.00   37.93    0.00    0.00    0.00

Device:         rrqm/s   wrqm/s   r/s   w/s   rsec/s   wsec/s avgrq-sz avgqu-sz   await  svctm  %util
sda               0.00     0.00  3.45  0.00   156.32     0.00    45.33     0.01    3.00   3.00   1.03
sda1              0.00     0.00  0.00  0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00
sda2              0.00     0.00  0.00  0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00
sda3              0.00     0.00  3.45  0.00   156.32     0.00    45.33     0.01    3.00   3.00   1.03

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
          89.39    0.00   10.61    0.00    0.00    0.00

Device:         rrqm/s   wrqm/s   r/s   w/s   rsec/s   wsec/s avgrq-sz avgqu-sz   await  svctm  %util
sda               1.52   378.79 12.12 57.58  1854.55  3490.91    76.70     0.23    3.37   2.33  16.21
sda1              0.00     0.00  0.00  0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00
sda2              0.00     0.00  0.00  0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00
sda3              1.52   378.79 12.12 57.58  1854.55  3490.91    76.70     0.23    3.37   2.33  16.21

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
          92.86    0.00    7.14    0.00    0.00    0.00

Device:         rrqm/s   wrqm/s   r/s   w/s   rsec/s   wsec/s avgrq-sz avgqu-sz   await  svctm  %util
sda               0.00     0.00  1.79  0.00    14.29     0.00     8.00     0.10   56.00  56.00  10.00
sda1              0.00     0.00  0.00  0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00
sda2              0.00     0.00  0.00  0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00
sda3              0.00     0.00  1.79  0.00    14.29     0.00     8.00     0.10   56.00  56.00  10.00

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
          79.66    0.00    8.47   11.86    0.00    0.00

Device:         rrqm/s   wrqm/s   r/s   w/s   rsec/s   wsec/s avgrq-sz avgqu-sz   await  svctm  %util
sda               0.00     0.00 25.42  0.00   203.39     0.00     8.00     0.25    9.73   9.73  24.75
sda1              0.00     0.00  0.00  0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00
sda2              0.00     0.00  0.00  0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00
sda3              0.00     0.00 25.42  0.00   203.39     0.00     8.00     0.25    9.73   9.73  24.75

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
          88.73    0.00    9.86    1.41    0.00    0.00

Device:         rrqm/s   wrqm/s   r/s   w/s   rsec/s   wsec/s avgrq-sz avgqu-sz   await  svctm  %util
sda               0.00     0.00  8.45  0.00   236.62     0.00    28.00     0.78    3.67  92.17  77.89
sda1              0.00     0.00  0.00  0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00
sda2              0.00     0.00  0.00  0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00
sda3              0.00     0.00  8.45  0.00   236.62     0.00    28.00     0.78    3.67  92.17  77.89

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
          86.36    0.00   13.64    0.00    0.00    0.00

Device:         rrqm/s   wrqm/s   r/s   w/s   rsec/s   wsec/s avgrq-sz avgqu-sz   await  svctm  %util
sda               0.00     0.00  0.00  0.00     0.00     0.00     0.00     4.55    0.00   0.00 455.00
sda1              0.00     0.00  0.00  0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00
sda2              0.00     0.00  0.00  0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00
sda3              0.00     0.00  0.00  0.00     0.00     0.00     0.00     4.55    0.00   0.00 455.00

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
          92.59    0.00    7.41    0.00    0.00    0.00

Device:         rrqm/s   wrqm/s   r/s   w/s   rsec/s   wsec/s avgrq-sz avgqu-sz   await  svctm  %util
sda               0.00   337.04  5.56 53.70   444.44  3125.93    60.25     0.64   58.59   8.38  49.63
sda1              0.00     0.00  0.00  0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00
sda2              0.00     0.00  0.00  0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00
sda3              0.00   337.04  5.56 53.70   444.44  3125.93    60.25     0.64   58.59   8.38  49.63

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
          91.43    0.00    8.57    0.00    0.00    0.00

Device:         rrqm/s   wrqm/s   r/s   w/s   rsec/s   wsec/s avgrq-sz avgqu-sz   await  svctm  %util
sda               0.00     0.00  0.00  0.00     0.00     0.00     0.00     0.69    0.00   0.00  69.29
sda1              0.00     0.00  0.00  0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00
sda2              0.00     0.00  0.00  0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00
sda3              0.00     0.00  0.00  0.00     0.00     0.00     0.00     0.69    0.00   0.00  69.29


唉,我也说不清楚了
要不,我给您权限,您帮我看看?
作者: 小版主杀手    时间: 2012-01-12 14:22
腐败网 发表于 2012-01-12 10:55
回复 31# 小版主杀手

我的是VPS,都放在一起的啊

my.cnf里这样配置下
tmp_table_size =64M
max_connections=120
sort_buffer_size = 4M
read_buffer_size = 4M

另外Table_locks_waited--这个值有448,说明查询语句有不小的问题,要优化
数据流也不小啊 一下就那么多G

你把应用先暂停,就启动mysql,用几条日志里的慢查询语句 运行下看看负载 什么的
show full processlist;
作者: fenanr    时间: 2012-01-12 16:06
# Time: 120110 12:19:49
# User@Host: finerbuy_com[finerbuy_com] @ localhost []
# Query_time: 11.583040  Lock_time: 0.000130 Rows_sent: 1  Rows_examined: 33328
SET timestamp=1326169189;
select * from ex_gimages where goods_id=1101;

大哥, 你的表没做索引吧?  数据是多大?
作者: fenanr    时间: 2012-01-12 16:08
# Time: 120110 12:31:05
# User@Host: finerbuy_com[finerbuy_com] @ localhost []
# Query_time: 13.534684  Lock_time: 0.000175 Rows_sent: 715  Rows_examined: 11345
SET timestamp=1326169865;
SELECT *,goods_id,image_default,thumbnail_pic,brief,pdt_desc,mktprice,big_pic FROM ex_goods WHERE cat_id IN (50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,705,154,155,171,207,210,212,227,233,267,268,274,276,280,281,289,293,297,299,301,305,400,456,453,635,636) AND brand_id IN(35) AND ex_goods.disabled = 'false' AND ex_goods.marketable='true' AND ex_goods.goods_type='normal' ORDER BY d_order  DESC ,p_order  DESC LIMIT 0, 18446744073709551615;

还有这种查询, 优化应当从程序开始.
再到phpmyadmin.
再到mysql配置
再到硬件.
这些dba工程师要熟悉.
作者: renxiao2003    时间: 2012-01-15 22:13
有什么大问题啊。

作者: 腐败网    时间: 2012-01-16 10:09
回复 38# renxiao2003


就是没事就宕机的问题啊

   
作者: renxiao2003    时间: 2012-01-16 10:39
回复 39# 腐败网


    是不是有大量的访问导致你的服务器不能提供服务。
作者: 腐败网    时间: 2012-01-16 11:08
回复 40# renxiao2003


访问量也不算大啊,最高也就1400,现在在线几个人都可能死机

   
作者: 腐败网    时间: 2012-01-16 23:10
renxiao2003 发表于 2012-01-16 10:39
回复 39# 腐败网


看起来不像是访问问题
每天就300~400IP,最高峰1300IP
作者: renxiao2003    时间: 2012-01-16 23:12
回复 42# 腐败网


    那把日志贴出来吧。
作者: 腐败网    时间: 2012-01-22 03:22
renxiao2003 发表于 2012-01-16 23:12
回复 42# 腐败网
nginx_vhost_log.rar (1.02 MB, 下载次数: 6)
作者: renxiao2003    时间: 2012-01-22 13:29
回复 44# 腐败网


    应该贴出来。方便大家看。我下载看看。
作者: renxiao2003    时间: 2012-01-22 13:54
回复 44# 腐败网


    这个根本不是MySQL的配置啊。
作者: 腐败网    时间: 2012-01-22 15:09
renxiao2003 发表于 2012-01-22 13:54
回复 44# 腐败网


你说要日志啊
下面是MY.CNF的配置:

# Example MySQL config file for very large systems.
#
# This is for a large system with memory of 1G-2G where the system runs mainly
# MySQL.
#
# MySQL programs look for option files in a set of
# locations which depend on the deployment platform.
# You can copy this option file to one of those
# locations. For information about these locations, see:
# http://dev.mysql.com/doc/mysql/en/option-files.html
#
# In this file, you can use all long options that a program supports.
# If you want to know which options a program supports, run the program
# with the "--help" option.

# The following options will be passed to all MySQL clients
[client]
#password        = your_password
port                = 3306
socket                = /tmp/mysql.sock

# Here follows entries for some specific programs

# The MySQL server
[mysqld]
port                = 3306
socket                = /tmp/mysql.sock
skip-locking
key_buffer_size = 128M
max_allowed_packet = 16M
table_open_cache = 65535
sort_buffer_size = 4M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size = 32M
# Try number of CPU's*2 for thread_concurrency
thread_concurrency = 8

# Don't listen on a TCP/IP port at all. This can be a security enhancement,
# if all processes that need to connect to mysqld run on the same host.
# All interaction with mysqld must be made via Unix sockets or named pipes.
# Note that using this option without enabling named pipes on Windows
# (via the "enable-named-pipe" option) will render mysqld useless!
#
#skip-networking

# Replication Master Server (default)
# binary logging is required for replication
log-bin=mysql-bin

# required unique id between 1 and 2^32 - 1
# defaults to 1 if master-host is not set
# but will not function as a master if omitted
server-id        = 1

# Replication Slave (comment out master section to use this)
#
# To configure this host as a replication slave, you can choose between
# two methods :
#
# 1) Use the CHANGE MASTER TO command (fully described in our manual) -
#    the syntax is:
#
#    CHANGE MASTER TO MASTER_HOST=<host>, MASTER_PORT=<port>,
#    MASTER_USER=<user>, MASTER_PASSWORD=<password> ;
#
#    where you replace <host>, <user>, <password> by quoted strings and
#    <port> by the master's port number (3306 by default).
#
#    Example:
#
#    CHANGE MASTER TO MASTER_HOST='125.564.12.1', MASTER_PORT=3306,
#    MASTER_USER='joe', MASTER_PASSWORD='secret';
#
# OR
#
# 2) Set the variables below. However, in case you choose this method, then
#    start replication for the first time (even unsuccessfully, for example
#    if you mistyped the password in master-password and the slave fails to
#    connect), the slave will create a master.info file, and any later
#    change in this file to the variables' values below will be ignored and
#    overridden by the content of the master.info file, unless you shutdown
#    the slave server, delete master.info and restart the slaver server.
#    For that reason, you may want to leave the lines below untouched
#    (commented) and instead use CHANGE MASTER TO (see above)
#
# required unique id between 2 and 2^32 - 1
# (and different from the master)
# defaults to 2 if master-host is set
# but will not function as a slave if omitted
#server-id       = 2
#
# The replication master for this slave - required
#master-host     =   <hostname>
#
# The username the slave will use for authentication when connecting
# to the master - required
#master-user     =   <username>
#
# The password the slave will authenticate with when connecting to
# the master - required
#master-password =   <password>
#
# The port the master is listening on.
# optional - defaults to 3306
#master-port     =  <port>
#
# binary logging - not required for slaves, but recommended
#log-bin=mysql-bin
#
# binary logging format - mixed recommended
#binlog_format=mixed

# Uncomment the following if you are using InnoDB tables
#innodb_data_home_dir = /usr/local/mysql/var
#innodb_data_file_path = ibdata1:2000M;ibdata2:10M:autoextend
#innodb_log_group_home_dir = /usr/local/mysql/var
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high

# Set .._log_file_size to 25 % of buffer pool size

innodb_buffer_pool_size = 512M
innodb_additional_mem_pool_size = 8M
innodb_log_file_size = 5M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
innodb_max_dirty_pages_pct=90
innodb_open_files=65535

innodb_file_per_table=1

# innodb_flush_method=O_DIRECT

query_cache_size=128M

log_slow_queries=1
slow_launch_time=1
long_query_time=0.5
log_output=table




[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates

[myisamchk]
key_buffer_size = 256M
sort_buffer_size = 256M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout

作者: renxiao2003    时间: 2012-01-22 15:59
很正常的配置啊。数据库的日志呢。
作者: 腐败网    时间: 2012-01-24 00:19
renxiao2003 发表于 2012-01-22 15:59
很正常的配置啊。数据库的日志呢。


首先祝愿大家龙年进步,事事顺利!


你说的MYSQL日志,我看了一下,好多个,从1~32
我不知道哪个是最新的
我估计是32是最新的吧
但是体积很大啊,68M

怎么给你啊
作者: 腐败网    时间: 2012-01-24 00:37
回复 48# renxiao2003


mysql日志.part01.rar (1.39 MB, 下载次数: 1) mysql日志.part02.rar (1.39 MB, 下载次数: 1) mysql日志.part03.rar (1.39 MB, 下载次数: 1) mysql日志.part04.rar (1.39 MB, 下载次数: 1) mysql日志.part05.rar (286.95 KB, 下载次数: 1)
   

分卷压缩了一下,麻烦你了
作者: 腐败网    时间: 2012-01-24 01:33
回复 48# renxiao2003

顺便把慢查询的记录也传上来吧



    slow_log.rar (1.38 MB, 下载次数: 54)
作者: renxiao2003    时间: 2012-01-24 14:39
腐败网 发表于 2012-01-24 01:33
回复 48# renxiao2003

顺便把慢查询的记录也传上来吧


你应该把这些东西帖子第一楼。这样方便大家看。
作者: renxiao2003    时间: 2012-01-24 14:40
不知道哪个最新就查看日期啊。
作者: 小版主杀手    时间: 2012-01-28 14:01
还是优化程序靠谱
作者: 腐败网    时间: 2012-02-01 11:17
小版主杀手 发表于 2012-01-28 14:01
还是优化程序靠谱



这个程序是SHOPEX
是著名的电子商务系统
对他做优化基本不可能,因为不开源
另外,别人用的好好的,为什么我不行?
如果是程序问题,那应该大家都不行啊
所以我觉得,程序可能有问题,但不是主要问题
会不会是其他方面的因素影响呢?
作者: WSLEICHAO    时间: 2012-02-01 18:12
   本人也是新手,我的VPS突发事512M,用RPM方式安装MySQL5.6后内存占用很大,后来看网上把引擎从InnoDB改为MyISAM,内存立马飞似地下降,不知道对你有用不
作者: kuhanzhu    时间: 2012-02-07 14:50
本帖最后由 kuhanzhu 于 2012-02-07 14:51 编辑

我的服务器是4G的内存。MySQL参数设置比楼主的小很多。
每天访问PV是 8W(51.la统计,不包含扫描、后台、蜘蛛等不需要统计的数据。如果从nginx上看则大概有20W。IP并不是很多,但就楼主的问题而言,我拿PV来说事更合理)
但是CPU则占用不到1%,基本看不到PHP和MySQL进程。
所以,我认为楼主的问题,应该是VPS的问题,CPU分配太小了。别看空间商说是志强XX,要是一台服务器放20个 VPS,每个VPS分配的CPU必然小的很。至于内存,16G的服务器分到VPS上,给你1G很正常啦。当然我没做过VPS,所以不知道一台服务器能搞几个VPS。但我可以肯定楼主是CPU处理不过来的缘故。
另外参数方面,也并不是越大越好。
作者: 腐败网    时间: 2012-02-10 02:06
WSLEICHAO 发表于 2012-02-01 18:12
引擎从InnoDB改为MyISAM ...


我正好和你相反,我把MYISAM改成了INNODB,数据库对CPU方面的占用变小很多,相反,PHP-CGI进程对CPU占用的压力就体现出来了
作者: 腐败网    时间: 2012-02-10 02:10
回复 57# kuhanzhu


恩,也有可能是PV问题
浏览量一大就崩溃
只是有个现象我不懂,之前也是同一台机器,好好的,用过一段时间之后就不行了,大概2个月左右是正常的,随说速度不是飞快,但也不至于宕机
后来突然不行了,怎么搞都不行,浏览量也没以前的多
然后还升级内存从512到1G,还是不行
难道是机房把资源给调低了?
这些配置问题IDC都是不对外公布的,他们就靠这个赚钱了
所以分析来分析去,我都找不出问题原因



   
作者: epstar    时间: 2012-09-29 17:04
谢谢楼主啊,受益匪浅啊!
作者: chinafenghao    时间: 2012-09-29 21:31
有人挖坟咯。
作者: lq2003    时间: 2012-10-17 17:09

发现两个问题:

1,log日志设置太小;
innodb_log_file_size = 5M  建议调整到100M;

2,操作系统的swap分区,1g内存才512M的swap,建议2g的swap。




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2