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%";
参考资料:
[1].http://blog.youkuaiyun.com/ligaofeng/article/details/47173557
[2].https://my.oschina.net/kcw/blog/362430
[3].https://mariadb.com/kb/en/mariadb/Build_Environment_Setup_for_Linux/
[4].https://mariadb.com/kb/en/mariadb/generic-build-instructions/
[5].https://mariadb.com/kb/en/mariadb/starting-and-stopping-mariadb-automatically/
[6].https://mariadb.com/kb/en/mariadb/mysqld-configuration-files-and-groups/
[7].http://www.biaodianfu.com/centos-7-2-mariadb.html
[8].http://www.linuxeye.com/Linux/1917.html