系统: centos7.2 x64
数据库:MariaDB-10.0.30
使用jemalloc对MySQL内存进行优化。
软件包下载地址:http://pan.baidu.com/s/1eS44OKU 密码:ghe3
安装jemalloc
[root@mysql src]# tar xf jemalloc-4.2..tar.bz2
[root@mysql src]# cd jemalloc-4.2.
[root@mysql jemalloc-4.2.]# ./configure --prefix=/usr/local/jemalloc
[root@mysql jemalloc-4.2.]# make && make install
[root@mysql jemalloc-4.2.]# echo '/usr/local/jemalloc/lib/' > /etc/ld.so.conf.d/local.conf
[root@mysql jemalloc-4.2.]# ldconfig
[root@mysql jemalloc-4.2.]# ln -vs /usr/local/jemalloc/lib/libjemalloc.so. /usr/local/lib/libjemalloc.so
安装mariadb
[root@mysql src]# tar xf mariadb-10.0..tar.gz
[root@mysql src]# cd mariadb-10.0.
[root@mysql mariadb-10.0.]# yum install cmake openssl-devel zlib-devel ncurses-devel -y
[root@mysql mariadb-10.0.]# mkdir -pv /data/mysql/{data,bin_log,run,log,tmp}
[root@mysql mariadb-10.0.]# groupadd -g mysql
[root@mysql mariadb-10.0.]# useradd -u -g -s /sbin/nologin -M mysql
[root@mysql mariadb-10.0.]# cmake . -LH
[root@mysql mariadb-10.0.]# cmake . \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/data/mysql/data \
-DTMPDIR=/usr/local/mysql/tmp \
-DMYSQL_UNIX_ADDR=/data/mysql/run/mysqld.sock \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE= \
-DWITH_INNOBASE_STORAGE_ENGINE= \
-DWITH_ARCHIVE_STORAGE_ENGINE= \
-DWITH_BLACKHOLE_STORAGE_ENGINE= \
-DWITH_PERFSCHEMA_STORAGE_ENGINE= \
-DWITH_FEDERATED_STORAGE_ENGINE= \
-DWITH_TOKUDB_STORAGE_ENGINE= \
-DWITH_XTRADB_STORAGE_ENGINE= \
-DWITH_ARIA_STORAGE_ENGINE= \
-DWITH_PARTITION_STORAGE_ENGINE= \
-DWITH_SPHINX_STORAGE_ENGINE= \
-DWITH_READLINE= \
-DMYSQL_TCP_PORT= \
-DENABLED_LOCAL_INFILE= \
-DWITH_EXTRA_CHARSETS=all \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DCMAKE_EXE_LINKER_FLAGS='-ljemalloc' \
-DWITH_SAFEMALLOC=OFF \
-DWITH_DEBUG= \
-DENABLE_PROFILING= \
-DWITH_SSL=system \
-DWITH_ZLIB=system \
-DWITH_LIBWRAP=
[root@bogon mariadb-10.0.]# make && make install
说明:
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ # 安装根目录
-DMYSQL_DATADIR=/data/mysql/data \ # 数据存储目录
-DTMPDIR=/data/mysql/tmp \ # 临时文件存放目录
-DMYSQL_UNIX_ADDR=/data/mysql/run/mysqld.sock \ # UNIX socket文件
-DSYSCONFDIR=/etc \ # 配置文件存放目录
-DWITH_MYISAM_STORAGE_ENGINE=1 \ # Myisam 引擎支持
-DWITH_INNOBASE_STORAGE_ENGINE=1 \ # innoDB 引擎支持
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \ # ARCHIVE 引擎支持
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ # BLACKHOLE 引擎支持
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \ # PERFSCHEMA 引擎支持
-DWITH_FEDERATED_STORAGE_ENGINE=1 \ # FEDERATEDX 引擎支持
-DWITH_TOKUDB_STORAGE_ENGINE=1 \ # TOKUDB 引擎支持
-DWITH_XTRADB_STORAGE_ENGINE=1 \ # XTRADB 引擎支持
-DWITH_ARIA_STORAGE_ENGINE=1 \ # ARIA 引擎支持
-DWITH_PARTITION_STORAGE_ENGINE=1 \ # PARTITION 引擎支持
-DWITH_SPHINX_STORAGE_ENGINE=1 \ # SPHINX 引擎支持
-DWITH_READLINE=1 \ # readline库
-DMYSQL_TCP_PORT=3306 \ # TCP/IP端口
-DENABLED_LOCAL_INFILE=1 \ # 启用加载本地数据
-DWITH_EXTRA_CHARSETS=all \ # 扩展支持编码 ( all | utf8,gbk,gb2312 | none )
-DEXTRA_CHARSETS=all \ # 扩展字符支持
-DDEFAULT_CHARSET=utf8 \ # 默认字符集
-DDEFAULT_COLLATION=utf8_general_ci \ # 默认字符校对
-DCMAKE_EXE_LINKER_FLAGS='-ljemalloc' \ # Jemalloc内存管理库
-DWITH_SAFEMALLOC=OFF \ # 关闭默认内存管理
-DWITH_DEBUG=0 \ # 关闭调试模式
-DENABLE_PROFILING=1 \ # 启用性能分析功能
-DWITH_SSL=system \ # 使用系统上的自带的SSL库
-DWITH_ZLIB=system \ # 使用系统上的自带的zlib库
-DWITH_LIBWRAP=0 # 禁用libwrap库
半个小时的等待。。。
[root@bogon mariadb-10.0.]# cd /usr/local/mysql/
[root@bogon mysql]# rpm -qf /etc/my.cnf
[root@bogon mysql]# rpm -e --nodeps mariadb-libs [root@bogon mysql]# grep -v ^# /etc/my.cnf | grep -v ^$
[client]
port =
socket = /data/mysql/run/mysqld.sock
[mysqld]
port =
socket = /data/mysql/run/mysqld.sock
datadir = /data/mysql/data/ # 新增数据存储目录
back_log =
max_connections =
max_connect_errors =
table_open_cache =
max_allowed_packet = 16M
binlog_cache_size = 1M
max_heap_table_size = 64M
read_buffer_size = 2M
read_rnd_buffer_size = 16M
sort_buffer_size = 8M
join_buffer_size = 8M
thread_cache_size =
thread_concurrency =
query_cache_size = 64M
query_cache_limit = 2M
ft_min_word_len =
default-storage-engine = INNODB # 修改存储引擎为INNODB
thread_stack = 240K
transaction_isolation = REPEATABLE-READ
tmp_table_size = 64M
log-bin=mysql-bin
binlog_format=mixed
slow_query_log
long_query_time =
server-id =
key_buffer_size = 32M
bulk_insert_buffer_size = 64M
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 10G
myisam_repair_threads =
myisam_recover
innodb_additional_mem_pool_size = 16M
innodb_buffer_pool_size = 2G
innodb_data_file_path = ibdata1:10M:autoextend
innodb_write_io_threads =
innodb_read_io_threads =
innodb_thread_concurrency =
innodb_flush_log_at_trx_commit =
innodb_log_buffer_size = 8M
innodb_log_file_size = 256M
innodb_log_files_in_group =
innodb_max_dirty_pages_pct =
innodb_lock_wait_timeout =
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 512M
sort_buffer_size = 512M
read_buffer = 8M
write_buffer = 8M
[mysqlhotcopy]
interactive-timeout
[mysqld_safe]
open-files-limit =
log-error = /data/mysql/log/mariadb.log # 指定log-file目录
pid-file = /data/mysql/run/mysqld.pid # 指定pid目录
其他参数请自行调整。
[root@bogon mysql]# cp -a support-files/mysql.server /etc/init.d/mysqld
[root@bogon mysql]# chmod +x /etc/init.d/mysqld
[root@bogon mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql/data/
[root@bogon mysql]# service mysqld start
Starting MySQL. :: mysqld_safe Logging to '/data/mysql/log/mariadb.log'.
:: mysqld_safe Starting mysqld daemon with databases from /data/mysql/data/
SUCCESS! [root@bogon mysql]# ss -ntlp | grep mysqld
LISTEN *: *:* users:(("mysqld",pid=,fd=))
OK, 启动成功。
[root@bogon mysql]# cd bin/
[root@bogon bin]# pwd
/usr/local/mysql/bin
[root@bogon bin]# echo 'export PATH=$PATH:/usr/local/mysql/bin' > /etc/profile.d/mysql.sh
[root@bogon bin]# source /etc/profile.d/mysql.sh
[root@bogon bin]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is
Server version: 10.0.-MariaDB Source distribution Copyright (c) , , Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]>
查看jemalloc是否生效:
[root@bogon bin]# yum install lsof -y
[root@bogon bin]# lsof -n | grep jemalloc
mysqld mysql mem REG , /usr/local/jemalloc/lib/libjemalloc.so.
mysqld mysql mem REG , /usr/local/jemalloc/lib/libjemalloc.so.
...