正文
本文介绍percona-server-5.7.25-28源码安装,操作系统基于Centos7,其它版本的源码安装基本类似,可参考此文章
先决条件
yum依赖项
# yum -y install gcc gcc-c++ ncurses ncurses-devel wget bzip2 openssl openssl-devel cmake bison zlib-devel curl-devel
zlib安装:zlib是用于数据压缩的函数库
# cd /usr/local/src
# wget http://www.zlib.net/fossils/zlib-1.2.8.tar.gz
# tar -xf zlib-1.2.8.tar.gz
# cd zlib-1.2.8
# ./configure --prefix=/usr/local/zlib
# make && make install
jemalloc安装:jemalloc是用于内存优化管理
# cd /usr/local/src
# wget https://src.fedoraproject.org/lookaside/pkgs/jemalloc/jemalloc-4.2.1.tar.bz2/094b0a7b8c77c464d0dc8f0643fd3901/jemalloc-4.2.1.tar.bz2
# cd jemalloc-4.2.1
# ./configure && make && make install
# echo '/usr/local/lib' > /etc/ld.so.conf.d/local.conf
# ldconfig
boost安装:Boost库是为C++语言标准库提供扩展的一些C++程序库的总称
# cd /usr/local/src
# wget https://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz
# tar -xf boost_1_59_0.tar.gz
# mv boost_1_59_0 /usr/local/
编译安装
创建用户并授权
# useradd -u 8000 -s /sbin/nologin -M mysql
# mkdir -p /usr/local/mysql
# mkdir -p /data/mysql/3306
# mkdir -p /data1/binlog/3306
# chown -R mysql.mysql /usr/local/mysql/
# chown -R mysql.mysql /data/mysql/3306
# chown -R mysql.mysql /data1/binlog/3306
编译安装MySQL
# cd /usr/local/src
# wget https://www.percona.com/downloads/Percona-Server-5.7/Percona-Server-5.7.25-28/source/tarball/percona-server-5.7.25-28.tar.gz
# tar -xf percona-server-5.7.25-28.tar.gz
# cd percona-server-5.7.25-28
# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/data/mysql/3306/mysql.sock \
-DMYSQL_DATADIR=/data/mysql/3306 \
-DSYSCONFDIR=/etc \
-DMYSQL_TCP_PORT=3306 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_DEBUG=0 \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS=all \
-DMYSQL_MAINTAINER_MODE=0 \
-DWITH_EDITLINE=bundled \
-DWITH_SSL:STRING=bundled \
-DWITH_ZLIB:STRING=bundled \
-DZLIB_LIBRARY:FILEPATH=/usr/local/zlib/lib/ \
-DZLIB_INCLUDE_DIR:PATH=/usr/local/zlib/include/ \
-DCMAKE_EXE_LINKER_FLAGS="-ljemalloc" \
-DENABLE_DOWNLOADS=1 \
-DWITH_BOOST=/usr/local/boost_1_59_0
# make -j 8
# make install
主要编译选项含义:
- CMAKE_INSTALL_PREFIX:安装目录
- MYSQL_UNIX_ADDR:socket目录
- MYSQL_DATADIR:数据目录
- SYSCONFDIR:配置文件目录
- MYSQL_TCP_PORT:端口号
- WITH_INNOBASE_STORAGE_ENGINE:安装INNOBASE存储引擎
- ENABLED_LOCAL_INFILE :启动本地的LOCAL_INFILE
- EXTRA_CHARSETS:支持哪些额外的字符集
- DEFAULT_CHARSET=utf8:默认字符集
- MYSQL_MAINTAINER_MODE:是否启用MySQL维护者特定的开发环境
- WITH_DEBUG:禁用调试模式
- WITH_SSL:STRING:通讯时支持ssl协议
- WITH_ZLIB:STRING:允许使用zlib library
- WITH_BOOST:指定boost安装路径
- ZLIB_LIBRARY:FILEPATH:zlib路径
数据库初始化
# echo 'export PATH=$PATH:/usr/local/mysql/bin' >> /etc/profile
# source /etc/profile
# cd /usr/local/mysql/bin/
# sed -i 's@executing mysqld_safe@executing mysqld_safe\nexport LD_PRELOAD=/usr/local/lib/libjemalloc.so@' /usr/local/mysql/bin/mysqld_safe
# echo "/usr/local/mysql/lib" >> /etc/ld.so.conf
# ldconfig
# ./mysqld --defaults-file=/etc/my.cnf --user=mysql --initialize-insecure
/etc/my.cnf主要参数含义可查看 文档
服务配置
centos7下的MySQL服务路径为/lib/systemd/system/mysqld.service
mysqld.service内容
[Unit]
Description=mysql - high performance mysql server
Documentation=http://dev.mysql.net/en/docs/
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/usr/sbin/mysqld_start
ExecStop=/usr/local/mysql/bin/mysqladmin -S /data/mysql/3306/mysql3306.sock shutdown -uroot -pxxxxxxx
PrivateTmp=true
mysqld_start内容
#!/bin/bash
/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf &
启动服务、初始化常用用户
# systemctl start mysqld
# mysql -uroot -p --socket=/data/mysql/3306/mysql3306.sock --port=3306 -e " grant replication slave,replication client on *.* to 'rep'@'%' identified by 'rep_xxxx'"
# mysql -uroot -p --socket=/data/mysql/3306/mysql3306.sock --port=3306 -e " grant process, replication client on *.* to 'zabbix'@'%' identified by 'zabbix_xxxx'"
# mysql -uroot -p --socket=/data/mysql/3306/mysql3306.sock --port=3306 -e " create user 'dbaadmin'@'%' identified by 'dba_xxx'"
# mysql -uroot -p --socket=/data/mysql/3306/mysql3306.sock --port=3306 -e " grant select, insert, update, delete, create, drop, reload, process, references, index, alter, create temporary tables, lock tables, execute, replication slave, replication client, create view, show view, create routine, alter routine, create user, event, trigger on *.* to 'dbaadmin'@'%'"
# mysql -uroot -p --socket=/data/mysql/3306/mysql3306.sock --port=3306 -e "alter user root@'localhost' identified by 'xxxxxxx'"