服务器
分析Mysql慢日志log_slow_queries
1 打开log_slow_queries
$sudo vi /etc/mysql/my.cnf log_slow_queries = /var/log/mysql/mysql-slow.log long_query_time = 5 log-queries-not-using-indexes
2使用工具分析mysql slow日志
myprofi.php
3 mysql调优工具
tuning-primer.sh
解决ubuntu12.04更换源后gpg错误
更换了一个更快的源,使用sudo apt-get update抱了一个gig错误
W: GPG error: http://extras.ubuntu.com precise Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 16126D3A3E5C1192
使用google查询到解决办法
$gpg --keyserver keyserver.ubuntu.com --recv 3E5C1192 $gpg --export --armor 3E5C1192 | sudo apt-key add - $sudo apt-get update
问题解决
使用Xdebug和KCachegrind分析php的discuz!x2.5运行CPU效率
论坛升级到discuz !x2.5,cpu随时都80-90%,load值居高不下,遂寻找一种检查php代码执行效率的方法
找到的方法php5-xdebug扩展或者xhprof扩展,因为服务器是ubuntu的,所以为了方便快捷,直接使用php5-xdebug来调试和分析了
1 xdebug配置
zend_extension=/usr/lib/php5/20090626/xdebug.so xdebug.profiler_enable=on xdebug.trace_output_dir="/tmp/xdebug" xdebug.profiler_output_dir="/tmp/xdebug" xdebug.profiler_output_name = cachegrind.out.%s #cachegrind.out._home_httpd_xxxxx
/tmp/xdebug目录需要手工建立,并且给www用户的读写权限
2 分析xdebug日志
windows环境可以使用WinCacheGrind
下载地址:http://sourceforge.net/projects/wincachegrind/
linux环境使KCachegrind
隐藏Nginx版本号
服务器需要隐藏nginx版本号
1 修改/etc/nginx/nginx.conf
http { ... server_tokens off; ... }
2 修改/etc/nginx/fastcgi_params
fastcgi_param SERVER_SOFTWARE nginx;
Ubuntu解决不能远程访问snmp协议的
需要远程使用snmp,发现ubuntu9.04上不支持远程访问,google了一下解决办法如下
编辑 /etc/default/snmpd
$sudo vi /etc/default/snmpd # This file controls the activity of snmpd and snmptrapd # MIB directories. /usr/share/snmp/mibs is the default, but # including it here avoids some strange problems. export MIBDIRS=/usr/share/snmp/mibs # snmpd control (yes means start daemon). SNMPDRUN=yes # snmpd options (use syslog, close stdin/out/err). #SNMPDOPTS='-Lsd -Lf /dev/null -u snmp -g snmp -I -smux -p /var/run/snmpd.pid 127.0.0.1' SNMPDOPTS='-Lsd -Lf /dev/null -u snmp -g snmp -I -smux -p /var/run/snmpd.pid'
去掉snmpdopts中的127.0.0.1绑定
ubuntu的dns服务器设置resolv.conf
一起一直修改/etc/resolv.conf中加入
nameserver 8.8.8.8
现在更新却不行了,自定义的/etc/resolv.conf被系统覆盖了,出现了
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8) # DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
搜索了一下解决办法,在/etc/resolvconf/resolv.conf.d/base里添加
$sudo vi /etc/resolvconf/resolv.conf.d/base nameserver 8.8.8.8
之后,每次重启之后/etc/resolv.conf中就回自动生成自定义的dns服务器信息了
使用persona for cacti插件监控mysql
需要mysql调优,安装了一个cacti监控插件 Percona Monitoring Plugins ,
官方地址:http://www.percona.com/software/percona-monitoring-plugins/
1 下载 percona-monitoring-plugins-1.0.0.tar.gz
2 上传 ss_get_mysql_stats.php 到cacti的scripts目录/usr/share/cacti/site/scripts
3 进入cacti的web页面import 数据模版cacti_host_template_percona_mysql_server_ht_0.8.6i-sver1.0.0.xml
4 设置ss_get_mysql_stats.php里的mysql账号链接
5 Percona Monitoring Plugins参考文档:http://form.percona.com/rs/percona/images/Percona_Monitoring_Plugins_100_Operations_Manual.pdf
在ubuntu上设置discuz远程附件
1 安装sftpd
sudo apt-get install vsftpd
2 设置ftp
/etc/vsftpd.conf # Uncomment this to enable any form of FTP write command. write_enable=YES # # Default umask for local users is 077. You may wish to change this to 022, # if your users expect that (022 is used by most other ftpd's) local_umask=022
3 增加用户
useradd -m ftp-user
4 将用户HOME目录链接到网站附件域名下
sudo ln -s /home/ftp-user /var/www/njava-att
合理计算mysql最大连接数max_connections
mysql经常出现MySQL: ERROR 1040: Too many connections,需要重新设置max_connections怎么才算合理呢?
1 查看当前mysql最大连接数
show global status like ‘Max_used_connections’;
2 设置max_connections值:Max_used_connections/max_connections=80%