环境 CentOS 6.3 64bit

安装libunwind库(32位系统可省略次步)

wget http://download.savannah.gnu.org/releases/libunwind/libunwind-0.99-alpha.tar.gz

tar zxvf libunwind-0.99-alpha.tar.gz

cd libunwind-0.99-alpha/

CFLAGS=-fPIC ./configure

make CFLAGS=-fPIC

make CFLAGS=-fPIC install

安装Tcmalloc

wget http://gperftools.googlecode.com/files/gperftools-2.0.tar.gz

tar zxvf  gperftools-2.0.tar.gz

cd gperftools-2.0/

./configure

make && make install

echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf

/sbin/ldconfig

编译完成后,我们编辑mysqld_safe文件,加入Tcmalloc部分。

vi /usr/bin/mysqld_safe

# 找到# executing mysqld_safe,在下面加入:
export LD_PRELOAD=/usr/local/lib/libtcmalloc.so

# 保存,退出,重启MySQL。
service mysqld restart

检查是否加载成功,运行:lsof -n | grep tcmalloc
显示如下类似内容即Ok

mysqld 32573 mysql mem REG 9,3 13771446
/usr/local/lib/libtcmalloc.so.4.1.0 (path dev=0,53)

修改配置文件

运行:

vi /etc/my.cnf

全选替换为:

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

# 12/17/2013 Add
local-infile=0
skip-locking
query_cache_limit=1M
query_cache_size=32M
query_cache_type=1
max_connections=500
interactive_timeout=100
wait_timeout=100
connect_timeout=10
thread_cache_size=128
key_buffer=16M
join_buffer=1M
max_allowed_packet=16M
table_cache=1024
record_buffer=1M
sort_buffer_size=2M
read_buffer_size=2M
max_connect_errors=10
# Try number of CPU's*2 for thread_concurrency
thread_concurrency=2
myisam_sort_buffer_size=64M
server-id=1

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
open_files_limit=8192

[mysqldump]
quick
max_allowed_packet=16M

[mysql]
no-auto-rehash
#safe-updates

[isamchk]
key_buffer=64M
sort_buffer=64M
read_buffer=16M
write_buffer=16M

[myisamchk]
key_buffer=64M
sort_buffer=64M
read_buffer=16M
write_buffer=16M

[mysqlhotcopy]
interactive-timeout

以上配置可根据自己服务器情况修改参数!
最后保存退出,运行 service mysqld restart 重启MySQL,完成。

标签: Linux管理维护

添加新评论