Centos7.2编译安装mariadb-10.1.19
0- 卸载系统自带mariadb-libs
rpm -qa|grep mariadb-libs
卸载
rpm -e –nodeps mariadb-libs
1- 安装相关包
安装开发工具组和一些其他包
yum groupinstall "Development Tools"
yum install libaio libaio-devel bison bison-devel zlib-devel cmake openssl openssl-devel ncurses ncurses-devel libcurl-devel libarchive-devel boost boost-devel lsof wget
2-下载和编译jemalloc
下载并编译
cd /usr/local/src
wget https://github.com/jemalloc/jemalloc/releases/download/4.3.1/jemalloc-4.3.1.tar.bz2
tar jxvf jemalloc-4.3.1.tar.bz2
cd jemalloc-4.3.1
./configure &&make && make install
安装后设置库
echo '/usr/local/lib' > /etc/ld.so.conf.d/local.conf
/sbin/ldconfig #更新ld
/sbin/ldconfig -v #查询更新后的ld
3- 安装JDK
下载和安装jdk8
wget --no-check-certificate --no-cookies \
--header "Cookie: oraclelicense=accept-securebackup-cookie" \
http://download.oracle.com/otn-pub/java/jdk/8u111-b14/jdk-8u111-linux-x64.tar.gz
mkdir /usr/local/java
tar zxvf jdk-8u111-linux-x64.tar.gz -C /usr/local/java
ln -s /usr/local/java/jdk1.8.0_111 /usr/local/java/latest
添加java环境变量
vi /etc/profile.d/java.sh
export JAVA_HOME=/usr/local/java/latest
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$JAVA_HOME/bin:$PATH
执行 source 更新环境变量。
. /etc/profile.d/java.sh
4- 使用cmake编译mariadb。
cd /usr/local/src
tar zxvf mariadb-10.1.19.tar.gz
cd mariadb-10.1.19
执行 cmake . -LH ,可以看到没有报错信息出现。
cmake . -LH
此时开始编译mariadb-10.1.19,编译需要较长时间。
cmake . -DBUILD_CONFIG=MysqL_release
make && make install
5- 设置环境变量和MysqL库
vi /etc/profile.d/MysqL.sh
export PATH=$PATH:/usr/local/MysqL/bin/
生效环境变量
. /etc/profile.d/MysqL.sh
设置MysqL库
echo '/usr/local/MysqL/lib' > /etc/ld.so.conf.d/mariadb.conf
/sbin/ldconfig
/sbin/ldconfig -v
6- 建立用户,目录,设置权限
useradd -M -s /sbin/nologin -r MysqL
chown -R MysqL /usr/local/MysqL/
mkdir -p /data/MysqL #数据目录
mkdir /var/log/mariadb #日志和pid目录
chown -R MysqL /data/ /data/MysqL
chown -R MysqL /var/log/mariadb
7- 设置自动启动脚本
cd /usr/local/MysqL
cp support-files/MysqL.server /etc/init.d/MysqLd
chmod +x /etc/init.d/MysqLd
chkconfig --add MysqLd
chkconfig MysqLd on
8- 使用jemalloc优化mariadb
运行命令:
sed -i ‘s@executing MysqLd_safe@executing MysqLd_safe\nexport LD_PRELOAD=/usr/local/lib/libjemalloc.so@’ /usr/local/MysqL/bin/MysqLd_safe
9- 设置默认配置
cd /usr/local/MysqL
cp support-files/my-large.cnf /etc/my.cnf
vi /etc/my.cnf
添加如下配置:
[client]
default-character-set = utf8
[MysqLd]
log-error = /var/log/mariadb/mariadb.log
pid-file = /var/log/mariadb/mariadb.pid
datadir = /data/MysqL
character-set-server = utf8
10- 初始化mariadb
cd /usr/local/MysqL
scripts/MysqL_install_db --user=MysqL
11- 启动mariadb
systemctl start MysqLd
12- 初始安全设置
MysqL_secure_installation
13- 检查默认配置和运行情况
MysqLd --print-defaults
ss -tlnp|grep :3306
lsof |grep jemalloc
14- 连接mariadb使用
MysqL -u root -p
show engines;
show VARIABLES like "character_set%";
参考资料: @H_254_403@ [1].http://www.jb51.cc/article/p-qhnnfonm-mo.html @H_254_403@ [2].https://my.oschina.net/kcw/blog/362430 @H_254_403@ [3].https://mariadb.com/kb/en/mariadb/Build_Environment_Setup_for_Linux/ @H_254_403@ [4].https://mariadb.com/kb/en/mariadb/generic-build-instructions/ @H_254_403@ [5].https://mariadb.com/kb/en/mariadb/starting-and-stopping-mariadb-automatically/ @H_254_403@ [6].https://mariadb.com/kb/en/mariadb/mysqld-configuration-files-and-groups/ @H_254_403@ [7].http://www.biaodianfu.com/centos-7-2-mariadb.html @H_254_403@ [8].http://www.linuxeye.com/Linux/1917.html