概述

今天偷个懒,就分享下mariadb简介及一键部署的脚本,仅供参考。

文末跳转链接为一键部署脚本下载方式,不定期更新~

官网:https://downloads.mariadb.org/mariadb/10.5.3/

下载地址:http://mirror.kku.ac.th/mariadb//mariadb-10.4.13/yum/centos7-amd64/


一、简介

Michael Widenius的女儿的简称就是MY,Michael Widenius大概也是把MySQL当成自己的女儿吧。看着自己辛苦养大的MySQL被Oracle搞成这样,Michael Widenius非常失望,决定在MySQL走向闭源前,将MySQL进行分支化,依然是使用了自己女儿的名字MariaDB(玛莉亚DB)。

MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可 MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能轻松成为MySQL的代替品。在存储引擎方面,使用XtraDB来代替MySQL的InnoDB。 MariaDB由MySQL的创始人Michael Widenius主导,由开源社区的大神们进行开发。因此,大家都认为,MariaDB拥有比MySQL更纯正的MySQL血脉。

最初的版本更新与MySQL同步,相对MySQL5以后的版本,MariaDB也有相应的5.1~5.5的版本。后来MariaDB终于摆脱了MySQL,它的版本号直接从10.0开始,以自己的步伐进行开发,当然,还是可以对MySQL完全兼容。现在,MariaDB的数据特性、性能等都超越了MySQL。




mariadb版本如何选择 mariadb版本对应_centos



二、官网--yum安装

Here is your custom MariaDB YUM repository entry for CentOS. Copy and paste it into a file under /etc/yum.repos.d/ (we suggest naming the file MariaDB.repo or something similar).

# MariaDB 10.4 CentOS repository list - created 2020-05-28 07:09 UTC# http://downloads.mariadb.org/mariadb/repositories/[mariadb]name = MariaDBbaseurl = http://yum.mariadb.org/10.4/centos7-amd64gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDBgpgcheck=1

After the file is in place, install MariaDB with:

sudo yum install MariaDB-server MariaDB-client

三 、mariadb一键部署脚本

function install_mariadb10_el7() {echo ""  echo -e "033[33m***********************************************自动部署mariadb-10.4.13**********************************************033[0m"   #建用户及目录  groupadd -r mysql && useradd -r -g mysql mysql -d /home/mysql -m  mkdir -p $MYSQL_HOME/datafile &&  mkdir -p $MYSQL_HOME/log  chown -R mysql:mysql $MYSQL_HOME && chmod -R 755 $MYSQL_HOME  #关闭selinux  setenforce 0  sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config    #下载libzstd-1.3.4  if [ -f /opt/libzstd-1.3.4-1.el7.x86_64.rpm ];then      echo "*****存在libzstd-1.3.4安装包,无需下载*****"  else      ping -c 4 mirror.kku.ac.th >/dev/null 2>&1      if [ $? -eq 0 ];then      wget http://mirror.kku.ac.th/mariadb//mariadb-10.4.13/yum/centos7-amd64/rpms/libzstd-1.3.4-1.el7.x86_64.rpm  -P /opt      else        echo "please download libzstd-1.3.4 package manual !"    exit $?      fi   fi    #下载jemalloc  if [ -f /opt/jemalloc-3.6.0-1.el7.x86_64.rpm ] && [ -f /opt/jemalloc-devel-3.6.0-1.el7.x86_64.rpm ] ;then      echo "*****存在jemalloc安装包,无需下载*****"  else      ping -c 4 mirror.kku.ac.th >/dev/null 2>&1      if [ $? -eq 0 ];then      wget http://mirror.kku.ac.th/mariadb//mariadb-10.4.13/yum/centos7-amd64/rpms/jemalloc-3.6.0-1.el7.x86_64.rpm  -P /opt      wget http://mirror.kku.ac.th/mariadb//mariadb-10.4.13/yum/centos7-amd64/rpms/jemalloc-devel-3.6.0-1.el7.x86_64.rpm  -P /opt      else        echo "please download jemalloc package manual!"    exit $?      fi   fi    #下载libboost_program_options.so.1.53和 galera-4-26  if [ -f /opt/boost-program-options-1.53.0-28.el7.x86_64.rpm ] && [ -f /opt/galera-4-26.4.4-1.rhel7.el7.centos.x86_64.rpm ] ;then      echo "*****存在galera安装包,无需下载*****"  else      ping -c 4 mirror.kku.ac.th >/dev/null 2>&1      if [ $? -eq 0 ];then      wget  -P ftp://ftp.pbone.net/mirror/ftp.centos.org/7.8.2003/os/x86_64/Packages/boost-program-options-1.53.0-28.el7.x86_64.rpm /opt      wget  -P http://mirror.kku.ac.th/mariadb//mariadb-10.4.13/yum/centos7-amd64/rpms/galera-4-26.4.4-1.rhel7.el7.centos.x86_64.rpm /opt      else        echo "please download galera-4-26 package manual !"    exit $?      fi   fi    #http://mirror.centos.org/centos/7/os/x86_64/Packages/perl-DBI-1.627-4.el7.x86_64.rpm  #下载perl-DBI相关包#  perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64.rpm#  perl-Compress-Raw-Zlib-2.061-4.el7.x86_64.rpm#  perl-Data-Dumper-2.145-3.el7.x86_64.rpm#  perl-DBI-1.627-4.el7.x86_64.rpm#  perl-IO-Compress-2.061-2.el7.noarch.rpm#  perl-Net-Daemon-0.48-5.el7.noarch.rpm#  perl-PlRPC-0.2020-14.el7.noarch.rpm  if [ -f /opt/perl-DBI-1.627-4.el7.x86_64.rpm ] ;then      echo "*****存在perl-DBI安装包,无需下载*****"  else      ping -c 4 mirror.centos.org >/dev/null 2>&1      if [ $? -eq 0 ];then      wget  -P http://mirror.centos.org/centos/7/os/x86_64/Packages/perl-DBI-1.627-4.el7.x86_64.rpm /opt      else        echo "please download perl-DBI package manual !"    exit $?      fi   fi    #从MariaDB 10.1.20 版本开始,Galera Cluster就已经包含在MariaDB包里面了,不需要单独部署MariaDB-Galera-server 和galera包。    #下载mariadb包  if [ -f /opt/MariaDB-client-10.4.13-1.el7.centos.x86_64.rpm ] && [ -f /opt/MariaDB-common-10.4.13-1.el7.centos.x86_64.rpm ]  && [ -f /opt/MariaDB-compat-10.4.13-1.el7.centos.x86_64.rpm ] && [ -f /opt/MariaDB-devel-10.4.13-1.el7.centos.x86_64.rpm ] && [  -f /opt/MariaDB-server-10.4.13-1.el7.centos.x86_64.rpm ] ;then      echo "*****存在mariadb 10.4.13安装包,无需下载*****"  else      ping -c 4 www.percona.com >/dev/null 2>&1      if [ $? -eq 0 ];then      wget  -P http://mirror.kku.ac.th/mariadb//mariadb-10.4.13/yum/centos7-amd64/rpms/MariaDB-client-10.4.13-1.el7.centos.x86_64.rpm /opt      wget  -P http://mirror.kku.ac.th/mariadb//mariadb-10.4.13/yum/centos7-amd64/rpms/MariaDB-common-10.4.13-1.el7.centos.x86_64.rpm /opt      wget  -P http://mirror.kku.ac.th/mariadb//mariadb-10.4.13/yum/centos7-amd64/rpms/MariaDB-compat-10.4.13-1.el7.centos.x86_64.rpm /opt      wget  -P http://mirror.kku.ac.th/mariadb//mariadb-10.4.13/yum/centos7-amd64/rpms/MariaDB-server-10.4.13-1.el7.centos.x86_64.rpm /opt      wget  -P http://mirror.kku.ac.th/mariadb//mariadb-10.4.13/yum/centos7-amd64/rpms/MariaDB-devel-10.4.13-1.el7.centos.x86_64.rpm /opt      else        echo "please download mariadb 10.4.13 package manual !"    exit $?      fi   fi      #配yum安装mariadb 10.4.13依赖包  rpm -qa|grep perl-JSON  if [ $? -eq 1 ];then    install_yum    yum install -y gcc gcc-c++ openssl openssl-devel libaio libaio-devel  ncurses ncurses-devel net-tools perl  perl-JSON &>/dev/null     action "************安装mariadb 10.4.13依赖包完成************" /bin/true      else    action "************已安装mariadb 10.4.13依赖包************" /bin/true   fi  #安装Percona Server for MySQL 8.0  ps -ef|grep mysql |grep -v grep  if [ $? -eq 0 ] ;then     echo "*****************已存在mysql进程*****************"     exit $?  else   # 卸载 mysql     rpm -qa|grep mysql|xargs -i rpm -e --nodeps {}      # 卸载 mariadb-libs     rpm -qa|grep mariadb|xargs -i rpm -e --nodeps {}      rpm -qa|grep mariadb-libs|xargs -i rpm -e --nodeps {}      # 安装mysql     action "*************开始安装mariadb 10.4.13数据库**************" /bin/true     rpm -ivh /opt/libzstd-1.3.4-1.el7.x86_64.rpm      rpm -ivh /opt/jemalloc-3.6.0-1.el7.x86_64.rpm     rpm -ivh /opt/jemalloc-devel-3.6.0-1.el7.x86_64.rpm     #安装 boost-devel 依赖环境     rpm -ivh /opt/boost-program-options-1.53.0-28.el7.x86_64.rpm     #安装 galera 环境     rpm -ivh /opt/galera-4-26.4.4-1.rhel7.el7.centos.x86_64.rpm     rpm -ivh /opt/perl*.rpm     rpm -ivh /opt/MariaDB-*.rpm  fi    #初始化数据并启动数据库  systemctl start mariadb.service    sleep 3   #转移数据文件目录  systemctl stop mariadb  cp -raf /var/lib/mysql/*  ${MYSQL_HOME}/datafile    #配置my.cnf  cp /etc/my.cnf /etc/my.cnf_${DATE}bak &>/dev/null cat << EOF > /etc/my.cnf [mysqld]port=${MYSQL_PORT}datadir=${MYSQL_HOME}/datafilelog_error = ${MYSQL_HOME}/log/mariadb.log#mysql8默认禁用Symbolic links,无需再去标记禁用#symbolic-links=0bind-address=0.0.0.0lower_case_table_names=1character_set_server=utf8mb4max_allowed_packet=500M#SQL Mode的NO_AUTO_CREATE_USER取消sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION#InnoDB用于缓存数据、索引、锁、插入缓冲、数据字典等innodb_buffer_pool_size=4G#InnoDB的log bufferinnodb_log_buffer_size = 64M#InnoDB redo log大小innodb_log_file_size = 256M#InnoDB redo log文件组innodb_log_files_in_group = 2innodb_flush_log_at_trx_commit = 2#连接数max_connections=600max_connect_errors=1000max_user_connections=400#设置临时表最大值max_heap_table_size = 100Mtmp_table_size = 100M#每个连接都会分配的一些排序、连接等缓冲sort_buffer_size = 2Mjoin_buffer_size = 2Mread_buffer_size = 2Mread_rnd_buffer_size = 2Mbulk_insert_buffer_size = 32M                   #批量插入数据缓存大小#关闭query cache#query_cache_size = 0#如果是以InnoDB引擎为主的DB,专用于MyISAM引擎的 key_buffer_size 可以设置较小,8MB 已足够,如果是以MyISAM引擎为主,可设置较大,但不能超过4Gkey_buffer_size = 8M#设置慢查询阀值,单位为秒long_query_time = 60slow_query_log=1         log_output=table,File    #日志输出会写表,也会写日志文件,为了便于程序去统计,所以最好写表slow_query_log_file=${MYSQL_HOME}/log/slow.log#快速预热缓冲池innodb_buffer_pool_dump_at_shutdown=1innodb_buffer_pool_load_at_startup=1#打印deadlock日志innodb_print_all_deadlocks=1#二进制配置server-id = 1log-bin = ${MYSQL_HOME}/log/mysql-bin.loglog-bin-index =${MYSQL_HOME}/log/binlog.indexlog_bin_trust_function_creators=1expire-logs-days=7#scheduleevent_scheduler = on#unknown variable 'show_compatibility_56=on'#show_compatibility_56=on#处理TIMESTAMP with implicit DEFAULT value is deprecatedexplicit_defaults_for_timestamp=trueopen_files_limit = 65535 EOF  systemctl start mariadb  #安全设置mysql_secure_installation  #MYSQL_TEMP_PWD=$(grep "temporary password" ${MYSQL_HOME}/log/mysqld.log|cut -d "@" -f 2|awk '{print $2}')  #mysql -hlocalhost  -P${MYSQL_PORT}  -uroot -p"${MYSQL_TEMP_PWD}" -e "set global validate_password.policy=0" --connect-expired-password  #mysql -hlocalhost  -P${MYSQL_PORT}  -uroot -p"${MYSQL_TEMP_PWD}" -e "ALTER USER 'root'@'localhost' IDENTIFIED  BY '${MYSQL_PWD}';flush privileges"  --connect-expired-password    #mysql -hlocalhost  -P${MYSQL_PORT}  -uroot -p${MYSQL_PWD} -e "grant all privileges on *.* to root@'%' identified by '${MYSQL_PWD}'" --connect-expired-password  mysql -uroot -p"${MYSQL_PWD}" -e "CREATE USER 'root'@'%' IDENTIFIED BY '${MYSQL_PWD}'"  --connect-expired-password  mysql -uroot -p"${MYSQL_PWD}" -e "grant all privileges on *.* to root@'%'"  --connect-expired-password     #授权root远程登录需输入以下命令:  #create user root@'%' identified by 'fswl@1234';  #grant all privileges on *.* to root@'%';  echo -e "033[33m*******************************************完成mariadb-10.4.13数据库部署********************************************033[0m"cat > /tmp/mariadb-10.4.13.log << EOFmariadb安装目录:${MYSQL_HOME}mariadb版本:mariadb-10.4.13mariadb端口:${MYSQL_PORT}mariadb密码:${MYSQL_PWD}mariadb状态:`systemctl status mariadb`EOF  cat /tmp/mariadb-10.4.13.log  echo -e "e[1;31m 以上信息10秒后消失,保存在/tmp/mariadb-10.4.13.log文件下 e[0m"  echo -e "033[33m************************************************************************************************************************033[0m"  echo ""  sleep 10}

以下为脚本安装过程:


mariadb版本如何选择 mariadb版本对应_centos_02


mariadb版本如何选择 mariadb版本对应_centos_03


mariadb版本如何选择 mariadb版本对应_mysql_04



觉得有用的朋友多帮忙转发哦!后面会分享更多devops和DBA方面的内容,感兴趣的朋友可以关注下~


mariadb版本如何选择 mariadb版本对应_centos_05