CentOS 7.2编译安装MariaDB-10.0.xx

系统: CentOS 7.2 x64
数据库:MariaDB-10.0.30

使用jemalloc对MySQL内存进行优化。

附件可以到安科网资源站下载:

------------------------------------------分割线------------------------------------------

具体下载目录在 /2017年资料/10月/8日/CentOS 7.2编译安装MariaDB-10.0.xx/

------------------------------------------分割线------------------------------------------


安装jemalloc

[root@mysql src]# tar xf jemalloc-4.2.0.tar.bz2
[root@mysql src]# cd jemalloc-4.2.0
[root@mysql jemalloc-4.2.0]# ./configure --prefix=/usr/local/jemalloc
[root@mysql jemalloc-4.2.0]# make && make install
[root@mysql jemalloc-4.2.0]# echo '/usr/local/jemalloc/lib/' > /etc/ld.so.conf.d/local.conf
[root@mysql jemalloc-4.2.0]# ldconfig
[root@mysql jemalloc-4.2.0]# ln -vs /usr/local/jemalloc/lib/libjemalloc.so.2 /usr/local/lib/libjemalloc.so

安装mariadb

[root@mysql src]# tar xf mariadb-10.0.30.tar.gz
[root@mysql src]# cd mariadb-10.0.30
[root@mysql mariadb-10.0.30]# yum install cmake openssl-devel zlib-devel ncurses-devel -y
[root@mysql mariadb-10.0.30]# mkdir -pv /data/mysql/{data,bin_log,run,log,tmp}
[root@mysql mariadb-10.0.30]# groupadd -g 3306 mysql
[root@mysql mariadb-10.0.30]# useradd -u 3306 -g 3306 -s /sbin/nologin -M mysql
[root@mysql mariadb-10.0.30]# cmake . -LH
[root@mysql mariadb-10.0.30]# 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=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1  \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1  \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1  \
-DWITH_TOKUDB_STORAGE_ENGINE=1 \
-DWITH_XTRADB_STORAGE_ENGINE=1  \
-DWITH_ARIA_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_SPHINX_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1  \
-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=0 \
-DENABLE_PROFILING=1 \
-DWITH_SSL=system \
-DWITH_ZLIB=system \
-DWITH_LIBWRAP=0

[root@linuxidc mariadb-10.0.30]# 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@linuxidc mariadb-10.0.30]# cd /usr/local/mysql/
[root@linuxidc mysql]# rpm -qf /etc/my.cnf
[root@linuxidc mysql]# rpm -e --nodeps mariadb-libs

[root@linuxidc mysql]# grep -v ^# /etc/my.cnf | grep -v ^$
[client]
port        = 3306
socket        = /data/mysql/run/mysqld.sock
[mysqld]
port        = 3306
socket        = /data/mysql/run/mysqld.sock
datadir        = /data/mysql/data/    # 新增数据存储目录
back_log = 50
max_connections = 100
max_connect_errors = 10
table_open_cache = 2048
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 = 8
thread_concurrency = 8
query_cache_size = 64M
query_cache_limit = 2M
ft_min_word_len = 4
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 = 2
server-id = 1
key_buffer_size = 32M
bulk_insert_buffer_size = 64M
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
myisam_recover
innodb_additional_mem_pool_size = 16M
innodb_buffer_pool_size = 2G
innodb_data_file_path = ibdata1:10M:autoextend
innodb_write_io_threads = 8
innodb_read_io_threads = 8
innodb_thread_concurrency = 16
innodb_flush_log_at_trx_commit = 1
innodb_log_buffer_size = 8M
innodb_log_file_size = 256M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
[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 = 8192
log-error = /data/mysql/log/mariadb.log    # 指定log-file目录
pid-file = /data/mysql/run/mysqld.pid    # 指定pid目录

其他参数请自行调整。

[root@linuxidc mysql]# cp -a support-files/mysql.server /etc/init.d/mysqld
[root@linuxidc mysql]# chmod +x /etc/init.d/mysqld
[root@linuxidc mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql/data/
[root@linuxidc mysql]# service mysqld start
Starting MySQL.170401 09:59:20 mysqld_safe Logging to '/data/mysql/log/mariadb.log'.
170401 09:59:20 mysqld_safe Starting mysqld daemon with databases from /data/mysql/data/
 SUCCESS!

[root@linuxidc mysql]# ss -ntlp | grep mysqld
LISTEN    0      50          *:3306                    *:*                  users:(("mysqld",pid=46517,fd=24))

OK, 启动成功。

[root@linuxidc mysql]# cd bin/
[root@linuxidc bin]# pwd
/usr/local/mysql/bin
[root@linuxidc bin]# echo 'export PATH=$PATH:/usr/local/mysql/bin' > /etc/profile.d/mysql.sh
[root@linuxidc bin]# source /etc/profile.d/mysql.sh
[root@linuxidc bin]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 10.0.30-MariaDB Source distribution

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

查看jemalloc是否生效:

[root@linuxidc bin]# yum install lsof -y
[root@linuxidc bin]# lsof -n | grep jemalloc
mysqld    46517        mysql  mem      REG              253,0  2528895  102127721 /usr/local/jemalloc/lib/libjemalloc.so.2
mysqld    46517 46519  mysql  mem      REG              253,0  2528895  102127721 /usr/local/jemalloc/lib/libjemalloc.so.2
...

 

相关推荐