linux下mysqlソースパッケージインストール-方法3


手順:TCMallocをインストールし、mysqlをインストールする
 
一、MySQLにTCMallocライブラリを追加してシステム負荷を下げる
TCMalloc(Thread-CachingMalloc)は、googleが開発したオープンソースツール「google-perftools」のメンバーです.TCMallocは、標準的なglibcライブラリのmallocと比較して、メモリの割り当ての効率と速度が非常に高く、MySQLサーバの高同時性のパフォーマンスを大幅に向上させ、システム負荷を低減することができます.
1、64ビットオペレーティングシステムはlibunwindライブラリをインストールしてください.32ビットオペレーティングシステムはインストールしません.Libunwindライブラリは、64ビットCPUおよびオペレーティングシステムに基づくプログラムに対して、スタックトラッキングを出力するためのAPI、プログラム的にスタックを転送するためのAPI、およびC++異常処理機構をサポートするAPIを含む基本的なスタック転送機能を提供する.

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


tar zxvf libunwind-0.99.tar.gz


cd libunwind-0.99/


CFLAGS=-fPIC ./configure


make CFLAGS=-fPIC


make CFLAGS=-fPIC install

 


2、google-perftoolsをインストールする:

wget http://google-perftools.googlecode.com/files/google-perftools-1.6.tar.gz

tar zxvf google-perftools-1.6.tar.gz

cd google-perftools-1.6/

./configure

make && make install

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

/sbin/ldconfig

 

、 MYSQL


[root@mg04 opt]# tar zxvf libevent-1.4.13-stable.tar.gz 
[root@mg04 opt]# cd libevent-1.4.13-stable
[root@mg04 libevent-1.4.13-stable]# ./configure --prefix=/usr/local/libevent
[root@mg04 libevent-1.4.13-stable]# make && make install
[root@mg04 libevent-1.4.13-stable]# ln -s/usr/local/libevent/lib/libevent-1.4.so.2/usr/lib
[root@mg04 opt]# tar zxvf mysql-5.1.49.tar.gz
[root@mg04 opt]# cd mysql-5.1.49
[root@mg04 mysql-5.1.49]# groupadd mysql
[root@mg04 mysql-5.1.49]# useradd -g mysql -s/sbin/nologin  mysql
[root@mg04 mysql-5.1.49]# ./configure --prefix=/usr/local/mysql --with-unix-socket-path=/usr/local/mysql/tmp/mysql.sock --localstatedir=/usr/database/mysql_data --enable-assembler --enable-thread-safe-client --enable-local-infile --with-big-tables --with-extra-charsets=utf8,gbk --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static --with-mysqld-ldflags=-ltcmalloc --with-mysqld-user=mysql --with-pthread --without-ndb-debug --with-plugins=partition,innobase,myisammrg
[root@mg04 mysql-5.1.49]# make && make install
[root@mg04 mysql-5.1.49]# cp support-files/my-huge.cnf/etc/my.cnf
[root@mg04 mysql-5.1.49]# mkdir -p/usr/database/mysql_data
[root@mg04 mysql-5.1.49]#/usr/local/mysql/bin/mysql_install_db --user=mysql
[root@mg04 mysql-5.1.49]# chown -R root/usr/local/mysql/
[root@mg04 mysql-5.1.49]# chown -R mysql/usr/database/mysql_data/
[root@mg04 mysql-5.1.49]# chgrp -R mysql/usr/local/mysql/
[root@mg04 mysql-5.1.49]#/usr/local/mysql/bin/mysqld_safe &
[root@mg04 mysql-5.1.49]# cp support-files/mysql.server/etc/init.d/mysqld
[root@mg04 mysql-5.1.49]# chmod 755/etc/init.d/mysqld 
[root@mg04 mysql-5.1.49]#/etc/init.d/mysqld stop
Shutting down MySQL.....100712 23:19:20 mysqld_safe mysqld from pid file/mnt/database/mysql_data/mg04.jieshi.org.pid ended
                                                           [  OK  ]
[2]-  Done                    /mnt/software/mysql/bin/mysqld_safe
[root@mg04 mysql-5.1.49]#/etc/init.d/mysqld start
Starting MySQL.                                            [  OK  ]
[root@mg04 mysql-5.1.49]#/etc/init.d/mysqld restart
Shutting down MySQL....                                    [  OK  ]
Starting MySQL.                                            [  OK  ]
[root@mg04 mysql-5.1.49]# vim/etc/profile
export PATH=$PATH:/usr/local/mysql/bin
[root@data03 mysql-5.1.49]# source/etc/profile
[root@mg04 mysql-5.1.49]# mysql
Welcome to the MySQL monitor.  Commands end with ; or\g.
Your MySQL connection id is 1
Server version: 5.1.49-log Source distribution
 
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license
 
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 
mysql> 
[root@mg04 mysql-5.1.49]# chkconfig mysqld on
[root@data03 opt]# chkconfig --level 24 mysqld off
[root@data03 opt]# chkconfig --list mysqld
mysqld 0:閉じる1:閉じる2:閉じる3:有効4:閉じる5:有効6:閉じる
 
[root@mg04 ~]# mysqladmin -uroot password dian588
[root@mg04 ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or\g.
Your MySQL connection id is 3
Server version: 5.1.49-log Source distribution
 
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license
 
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 
mysql> 
MySQL起動スクリプトの変更(MySQLのインストール場所によって異なります):
vi /usr/local/mysql/bin/mysqld_safe

#executingmysqld_safeの次の行に、以下を加えます.
export LD_PRELOAD=/usr/local/lib/libtcmalloc.so

保存して終了し、MySQLサービスを再起動します.
lsofコマンドを使用して、tcmallocが有効かどうかを確認します.
lsof -n | grep tcmalloc

次の情報が表示された場合、tcmallocが有効になったことを示します.
mysqld 10847 mysql mem REG 8,5 1203756 20484960/usr/local/lib/libtcmalloc.so.0.0.0 

参考文献:http://www.iteye.com/topic/485354
http://coralzd.blog.51cto.com/90341/729847