全球主机交流论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

CeraNetworks网络延迟测速工具IP归属甄别会员请立即修改密码
查看: 8371|回复: 43
打印 上一主题 下一主题

请教10W ip 的wp站如何优化mysql

[复制链接]
跳转到指定楼层
#
发表于 2014-12-9 18:38:36 | 只看该作者 回帖奖励 |正序浏览 |阅读模式
本帖最后由 wdfsinap 于 2014-12-9 18:39 编辑

现在用的16G linode vps。wp站。5W多文章。负载有些大。请教该如何优化mysql。
vps装的是军哥的lnmp。已安装memcached和wp super cache。
top.png (36.93 KB, 下载次数: 0)

# Example MySQL config file for medium systems.
#
# This is for a system with little memory (32M - 64M) where MySQL plays
# an important part, or systems up to 128M where MySQL is used together with
# other programs (such as a web server)
#
# 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
datadir = /usr/local/mysql/var
skip-external-locking

query_cache_limit = 4M
query_cache_min_res_unit = 4k
key_buffer_size = 2048M
max_allowed_packet = 16M
table_open_cache = 4096
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M

# 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

# binary logging format - mixed recommended
binlog_format=mixed

# 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
# Uncomment the following if you are using InnoDB tables
innodb_data_home_dir = /usr/local/mysql/var
innodb_data_file_path = ibdata1: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
init_connect='SET autocommit=0'
innodb_buffer_pool_size = 2048M
innodb_additional_mem_pool_size = 16M
# Set .._log_file_size to 25 % of buffer pool size
innodb_log_file_size = 8M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 0
innodb_lock_wait_timeout = 50

[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 = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout

推荐
发表于 2014-12-9 21:43:42 | 只看该作者
16G内存用medium ,你还真够省的……
直接上HHVM
推荐
发表于 2014-12-9 19:42:22 | 只看该作者
本帖最后由 cst4you 于 2014-12-9 19:45 编辑

内存真多, 其实用不完, 这个量级2G内存就够了.

友情送你个卖站之前的配置吧, 主要还是WP还是得靠缓存, 什么都拿内存顶, mysql差不多就行了.

  1. [mysqld]
  2. port            = 3306
  3. socket          = /tmp/mysql.sock

  4. interactive_timeout = 30
  5. wait_timeout = 60
  6. connect_timeout = 60

  7. ft_min_word_len=2

  8. default-storage-engine=MyISAM
  9. skip-innodb
  10. ;skip-locking
  11. skip-name-resolve
  12. low-priority-updates
  13. key_buffer_size = 192M
  14. sort_buffer_size = 6M
  15. read_buffer_size = 4M
  16. read_rnd_buffer_size = 4M
  17. join_buffer_size = 3M
  18. table_cache = 2560
  19. table_definition_cache = 512
  20. max_connections = 500
  21. max_join_size = 4294967295
  22. myisam_sort_buffer_size = 4M
  23. thread_cache = 32
  24. thread_cache_size = 256
  25. query_cache_limit= 8M
  26. query_cache_size = 128M
  27. query_cache_type = 1


  28. max_connect_errors= 50
  29. max_allowed_packet= 16M

  30. tmp_table_size = 384M
  31. net_buffer_length = 32768

  32. slow_query_log = 1
  33. log-queries-not-using-indexes = 0
  34. slow_query_log_file = /tmp/slowquery.log

  35. general_log = 0
  36. general_log_file = /tmp/mysql.log


  37. # Try number of CPU's*2 for thread_concurrency
  38. thread_concurrency = 12
复制代码


不要问我为什么这么配. 当然这个参数也是针对当时2G内存的机器配的, 你16G的话, 参数意思自己研究修改下吧.

点评

流量比较厉害,这站能卖到 6位数么?  发表于 2014-12-10 09:51
推荐
发表于 2014-12-9 18:54:28 | 只看该作者
wdfsinap 发表于 2014-12-9 18:51
已经用了wp super cache了。还是不行。文章有图片的


wp super cache 假静态没意义!用cos-html-cache!图片静态不了-反正都只是调用-不浪费资源-
42#
发表于 2014-12-11 12:18:19 | 只看该作者
才5w文章 你搞那么大内存  不用缓存 你做死
41#
发表于 2014-12-11 11:03:03 | 只看该作者
wdfsinap 发表于 2014-12-11 07:29
奇怪我的memcached 命中率这么低,只有82%。

不错了, 时间长了命中率会上去的
40#
 楼主| 发表于 2014-12-11 07:29:21 | 只看该作者
cst4you 发表于 2014-12-10 10:31
参考
http://blog.wpjam.com/m/wordpress-memcached/
http://blog.wpjam.com/m/batcache/

奇怪我的memcached 命中率这么低,只有82%。
39#
发表于 2014-12-11 00:31:29 | 只看该作者
haoyu.me ? 不科学呀
38#
发表于 2014-12-10 23:34:07 | 只看该作者
提示: 作者被禁止或删除 内容自动屏蔽
37#
发表于 2014-12-10 22:25:29 | 只看该作者
再重复一次 看看varnish cache
36#
 楼主| 发表于 2014-12-10 22:01:58 | 只看该作者
已经使用了memcached和wordpress插件。但是CPU还是高。mysql负载大。我用nginx缓存再试试
35#
 楼主| 发表于 2014-12-10 20:26:55 | 只看该作者
cst4you 发表于 2014-12-10 10:31
参考
http://blog.wpjam.com/m/wordpress-memcached/
http://blog.wpjam.com/m/batcache/

我准备尝试这两个插件,奇怪memcached总是提示错误。
后面我准备用nginx反代试试。多谢
34#
发表于 2014-12-10 10:31:59 | 只看该作者
本帖最后由 cst4you 于 2014-12-10 10:34 编辑
wdfsinap 发表于 2014-12-9 19:50
你没用innodb做存储引擎。我用了。不知道MyISAM跟innodb哪个好些。


参考
http://blog.wpjam.com/m/wordpress-memcached/
http://blog.wpjam.com/m/batcache/

我之前的项目就用了这俩方案. 不用其他任何的什么鸟 super-cache, 那么多钩子用了反而更慢.
对于 wp 这样读比写多的多的场景, innodb 简直是浪费效率又浪费内存.

这样下来, 只要CPU够强, 就能顶更多流量.
网络瓶颈不在我们讨论范畴里.

当然, 如果你的站互动不多的话(关闭自带评论功能), 你完全可以在本机nginx反代个, 或者用squid之类的也可以.
33#
发表于 2014-12-10 07:58:23 | 只看该作者
zhiyong 发表于 2014-12-9 21:32
当然用过!你本地生成再上传?不是在主机里自动生成?你想表达什么呢?-我说的那个就是直接在主机或者VPS ...

我pc里都可以直接生成静态的,VPS里不行?

路径地址:***.com/wp-content/cache/supercache/www.****.com/index.html

还有什么地方需要科普?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|全球主机交流论坛

GMT+8, 2025-12-21 20:10 , Processed in 0.073860 second(s), 14 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表