step 1. 因为是64位的系统,所以先要安装libunwind,32位系统可以忽略此步
- wget http://download.savannah.gnu.org/releases/libunwind/libunwind-1.1.tar.gz
- tar zxvf libunwind-1.1.tar.gz
- cd libunwind-1.1/
- CFLAGS=-fPIC ./configure --enable-shared
- make CFLAGS=-fPIC
- make CFLAGS=-fPIC install
step 2.安装Google Performance Tools
- wget https://gperftools.googlecode.com/files/gperftools-2.1.tar.gz
- tar zxvf gperftools-2.1.tar.gz
- cd gperftools-2.1/
- ./configure
- make -j8
- make install
- echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf
- /sbin/ldconfig
step 3. 修改MySQL启动脚本(根据你的MySQL安装位置而定):
- vi /usr/local/mysql/bin/mysqld_safe
在# executing mysqld_safe的下一行,加上:
- export LD_PRELOAD=/usr/local/lib/libtcmalloc.so
保存后退出,然后重启MySQL服务器。
step 4. 使用lsof命令查看tcmalloc是否起效:
- lsof -n|grep tcmalloc
如果发现以下信息,就证明配置成功了。
- mysqld 12278 mysql mem REG 202,1 2241773 1186797 /usr/local/lib/libtcmalloc.so.4.1.2