Browse Source

Add MariaDB-10.2

lj2007331@gmail.com 7 years ago
parent
commit
a366534306
4 changed files with 286 additions and 24 deletions
  1. 45 6
      include/check_download.sh
  2. 214 0
      include/mariadb-10.2.sh
  3. 25 16
      install.sh
  4. 2 2
      versions.txt

+ 45 - 6
include/check_download.sh

@@ -248,6 +248,45 @@ checkDownload() {
         ;;
 
       4)
+        # MariaDB 10.2
+        if [ "${dbInstallMethods}" == '1' ]; then
+          echo "Download MariaDB 10.2 binary package..."
+          FILE_NAME=mariadb-${mariadb102_version}-${GLIBC_FLAG}-${SYS_BIT_b}.tar.gz
+          if [ "${IPADDR_COUNTRY}"x == "CN"x ]; then
+            DOWN_ADDR_MARIADB=https://mirrors.tuna.tsinghua.edu.cn/mariadb/mariadb-${mariadb102_version}/bintar-${GLIBC_FLAG}-${SYS_BIT_a}
+            MARAIDB_TAR_MD5=$(curl -Lk ${DOWN_ADDR_MARIADB}/md5sums.txt | grep ${FILE_NAME} | awk '{print $1}')
+            [ -z "${MARAIDB_TAR_MD5}" ] && { DOWN_ADDR_MARIADB=https://mirrors.ustc.edu.cn/mariadb/mariadb-${mariadb102_version}/bintar-${GLIBC_FLAG}-${SYS_BIT_a}; MARAIDB_TAR_MD5=$(curl -Lk ${DOWN_ADDR_MARIADB}/md5sums.txt | grep ${FILE_NAME} | awk '{print $1}'); }
+          else
+            DOWN_ADDR_MARIADB=https://downloads.mariadb.org/interstitial/mariadb-${mariadb102_version}/bintar-${GLIBC_FLAG}-${SYS_BIT_a}
+            MARAIDB_TAR_MD5=$(curl -Lk http://archive.mariadb.org/mariadb-${mariadb102_version}/bintar-${GLIBC_FLAG}-${SYS_BIT_a}/md5sums.txt |  grep ${FILE_NAME} | awk '{print $1}')
+          fi
+        elif [ "${dbInstallMethods}" == '2' ]; then
+          echo "Download MariaDB 10.2 source package..."
+          FILE_NAME=mariadb-${mariadb102_version}.tar.gz
+          if [ "${IPADDR_COUNTRY}"x == "CN"x ]; then
+            DOWN_ADDR_MARIADB=https://mirrors.tuna.tsinghua.edu.cn/mariadb/mariadb-${mariadb102_version}/source
+            MARAIDB_TAR_MD5=$(curl -Lk ${DOWN_ADDR_MARIADB}/md5sums.txt | grep ${FILE_NAME} | awk '{print $1}')
+            [ -z "${MARAIDB_TAR_MD5}" ] && { DOWN_ADDR_MARIADB=https://mirrors.ustc.edu.cn/mariadb/mariadb-${mariadb102_version}/source; MARAIDB_TAR_MD5=$(curl -Lk ${DOWN_ADDR_MARIADB}/md5sums.txt | grep ${FILE_NAME} | awk '{print $1}'); }
+          else
+            DOWN_ADDR_MARIADB=https://downloads.mariadb.org/interstitial/mariadb-${mariadb102_version}/source
+            MARAIDB_TAR_MD5=$(curl -Lk http://archive.mariadb.org/mariadb-${mariadb102_version}/source/md5sums.txt |  grep ${FILE_NAME} | awk '{print $1}')
+          fi
+        fi
+        tryDlCount=0
+        while [ "$(md5sum ${FILE_NAME} | awk '{print $1}')" != "${MARAIDB_TAR_MD5}" ]; do
+          wget -c --no-check-certificate ${DOWN_ADDR_MARIADB}/${FILE_NAME};sleep 1
+          let "tryDlCount++"
+          [ "$(md5sum ${FILE_NAME} | awk '{print $1}')" == "${MARAIDB_TAR_MD5}" -o "${tryDlCount}" == '6' ] && break || continue
+        done
+        if [ "${tryDlCount}" == '6' ]; then
+          echo "${CFAILURE}${FILE_NAME} download failed, Please contact the author! ${CEND}"
+          kill -9 $$
+        else
+          echo "[${CMSG}${FILE_NAME}${CEND}] found."
+        fi
+        ;;
+
+      5)
         # MariaDB 10.1
         if [ "${dbInstallMethods}" == '1' ]; then
           echo "Download MariaDB 10.1 binary package..."
@@ -286,7 +325,7 @@ checkDownload() {
         fi
         ;;
 
-      5)
+      6)
         # MariaDB 10.0
         if [ "${dbInstallMethods}" == '1' ]; then
           echo "Download MariaDB 10.0 binary package..."
@@ -325,7 +364,7 @@ checkDownload() {
         fi
         ;;
 
-      6)
+      7)
         # MariaDB 5.5
         if [ "${dbInstallMethods}" == '1' ]; then
           echo "Download MariaDB 5.5 binary package..."
@@ -364,7 +403,7 @@ checkDownload() {
         fi
         ;;
 
-      7)
+      8)
         # Precona 5.7
         if [ "${dbInstallMethods}" == '1' ]; then
           echo "Download Percona 5.7 binary package..."
@@ -398,7 +437,7 @@ checkDownload() {
         fi
         ;;
 
-      8)
+      9)
         # Precona 5.6
         if [ "${dbInstallMethods}" == '1' ]; then
           echo "Download Percona 5.6 binary package..."
@@ -433,7 +472,7 @@ checkDownload() {
         fi
         ;;
 
-      9)
+      10)
         # Percona 5.5
         if [ "${dbInstallMethods}" == '1' ]; then
           echo "Download Percona 5.5 binary package..."
@@ -468,7 +507,7 @@ checkDownload() {
         fi
         ;;
 
-      10)
+      11)
         # AliSQL 5.6
         DOWN_ADDR_ALISQL=$mirrorLink
         echo "Download AliSQL 5.6 source package..."

+ 214 - 0
include/mariadb-10.2.sh

@@ -0,0 +1,214 @@
+#!/bin/bash
+# Author:  yeho <lj2007331 AT gmail.com>
+# BLOG:  https://blog.linuxeye.com
+#
+# Notes: OneinStack for CentOS/RadHat 5+ Debian 6+ and Ubuntu 12+
+#
+# Project home page:
+#       https://oneinstack.com
+#       https://github.com/lj2007331/oneinstack
+
+Install_MariaDB102() {
+  pushd ${oneinstack_dir}/src
+
+  id -u mysql >/dev/null 2>&1
+  [ $? -ne 0 ] && useradd -M -s /sbin/nologin mysql
+
+  [ ! -d "${mariadb_install_dir}" ] && mkdir -p ${mariadb_install_dir}
+  mkdir -p ${mariadb_data_dir};chown mysql.mysql -R ${mariadb_data_dir}
+
+  if [ "${dbInstallMethods}" == "1" ]; then
+    tar zxf mariadb-${mariadb102_version}-${GLIBC_FLAG}-${SYS_BIT_b}.tar.gz
+    mv mariadb-${mariadb102_version}-*-${SYS_BIT_b}/* ${mariadb_install_dir}
+    sed -i 's@executing mysqld_safe@executing mysqld_safe\nexport LD_PRELOAD=/usr/local/lib/libjemalloc.so@' ${mariadb_install_dir}/bin/mysqld_safe
+    sed -i "s@/usr/local/mysql@${mariadb_install_dir}@g" ${mariadb_install_dir}/bin/mysqld_safe
+  elif [ "${dbInstallMethods}" == "2" ]; then
+    tar xvf mariadb-${mariadb102_version}.tar.gz
+    pushd mariadb-${mariadb102_version}
+    cmake . -DCMAKE_INSTALL_PREFIX=${mariadb_install_dir} \
+    -DMYSQL_DATADIR=${mariadb_data_dir} \
+    -DSYSCONFDIR=/etc \
+    -DWITH_INNOBASE_STORAGE_ENGINE=1 \
+    -DWITH_PARTITION_STORAGE_ENGINE=1 \
+    -DWITH_FEDERATED_STORAGE_ENGINE=1 \
+    -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
+    -DWITH_MYISAM_STORAGE_ENGINE=1 \
+    -DWITH_EMBEDDED_SERVER=1 \
+    -DENABLE_DTRACE=0 \
+    -DENABLED_LOCAL_INFILE=1 \
+    -DDEFAULT_CHARSET=utf8mb4 \
+    -DDEFAULT_COLLATION=utf8mb4_general_ci \
+    -DEXTRA_CHARSETS=all \
+    -DCMAKE_EXE_LINKER_FLAGS='-ljemalloc'
+    make -j ${THREAD}
+    make install
+    popd
+  fi
+
+  if [ -d "${mariadb_install_dir}/support-files" ]; then
+    echo "${CSUCCESS}MariaDB installed successfully! ${CEND}"
+    if [ "${dbInstallMethods}" == "1" ]; then
+      rm -rf mariadb-${mariadb102_version}-*-${SYS_BIT_b}
+    elif [ "${dbInstallMethods}" == "2" ]; then
+      rm -rf mariadb-${mariadb102_version}
+    fi
+  else
+    rm -rf ${mariadb_install_dir}
+    rm -rf mariadb-${mariadb102_version}
+    echo "${CFAILURE}MariaDB install failed, Please contact the author! ${CEND}"
+    kill -9 $$
+  fi
+
+  /bin/cp ${mariadb_install_dir}/support-files/mysql.server /etc/init.d/mysqld
+  sed -i "s@^basedir=.*@basedir=${mariadb_install_dir}@" /etc/init.d/mysqld
+  sed -i "s@^datadir=.*@datadir=${mariadb_data_dir}@" /etc/init.d/mysqld
+  chmod +x /etc/init.d/mysqld
+  [ "${OS}" == "CentOS" ] && { chkconfig --add mysqld; chkconfig mysqld on; }
+  [[ "${OS}" =~ ^Ubuntu$|^Debian$ ]] && update-rc.d mysqld defaults
+  popd
+
+  # my.cnf
+  cat > /etc/my.cnf << EOF
+[client]
+port = 3306
+socket = /tmp/mysql.sock
+default-character-set = utf8mb4
+
+[mysqld]
+port = 3306
+socket = /tmp/mysql.sock
+
+basedir = ${mariadb_install_dir}
+datadir = ${mariadb_data_dir}
+pid-file = ${mariadb_data_dir}/mysql.pid
+user = mysql
+bind-address = 0.0.0.0
+server-id = 1
+
+init-connect = 'SET NAMES utf8mb4'
+character-set-server = utf8mb4
+
+skip-name-resolve
+#skip-networking
+back_log = 300
+
+max_connections = 1000
+max_connect_errors = 6000
+open_files_limit = 65535
+table_open_cache = 128
+max_allowed_packet = 500M
+binlog_cache_size = 1M
+max_heap_table_size = 8M
+tmp_table_size = 16M
+
+read_buffer_size = 2M
+read_rnd_buffer_size = 8M
+sort_buffer_size = 8M
+join_buffer_size = 8M
+key_buffer_size = 4M
+
+thread_cache_size = 8
+
+query_cache_type = 1
+query_cache_size = 8M
+query_cache_limit = 2M
+
+ft_min_word_len = 4
+
+log_bin = mysql-bin
+binlog_format = mixed
+expire_logs_days = 7
+
+log_error = ${mariadb_data_dir}/mysql-error.log
+slow_query_log = 1
+long_query_time = 1
+slow_query_log_file = ${mariadb_data_dir}/mysql-slow.log
+
+performance_schema = 0
+
+#lower_case_table_names = 1
+
+skip-external-locking
+
+default_storage_engine = InnoDB
+innodb_file_per_table = 1
+innodb_open_files = 500
+innodb_buffer_pool_size = 64M
+innodb_write_io_threads = 4
+innodb_read_io_threads = 4
+innodb_thread_concurrency = 0
+innodb_purge_threads = 1
+innodb_flush_log_at_trx_commit = 2
+innodb_log_buffer_size = 2M
+innodb_log_file_size = 32M
+innodb_log_files_in_group = 3
+innodb_max_dirty_pages_pct = 90
+innodb_lock_wait_timeout = 120
+
+bulk_insert_buffer_size = 8M
+myisam_sort_buffer_size = 8M
+myisam_max_sort_file_size = 10G
+myisam_repair_threads = 1
+
+interactive_timeout = 28800
+wait_timeout = 28800
+
+[mysqldump]
+quick
+max_allowed_packet = 500M
+
+[myisamchk]
+key_buffer_size = 8M
+sort_buffer_size = 8M
+read_buffer = 4M
+write_buffer = 4M
+EOF
+
+  sed -i "s@max_connections.*@max_connections = $((${Mem}/3))@" /etc/my.cnf
+  if [ ${Mem} -gt 1500 -a ${Mem} -le 2500 ]; then
+    sed -i 's@^thread_cache_size.*@thread_cache_size = 16@' /etc/my.cnf
+    sed -i 's@^query_cache_size.*@query_cache_size = 16M@' /etc/my.cnf
+    sed -i 's@^myisam_sort_buffer_size.*@myisam_sort_buffer_size = 16M@' /etc/my.cnf
+    sed -i 's@^key_buffer_size.*@key_buffer_size = 16M@' /etc/my.cnf
+    sed -i 's@^innodb_buffer_pool_size.*@innodb_buffer_pool_size = 128M@' /etc/my.cnf
+    sed -i 's@^tmp_table_size.*@tmp_table_size = 32M@' /etc/my.cnf
+    sed -i 's@^table_open_cache.*@table_open_cache = 256@' /etc/my.cnf
+  elif [ ${Mem} -gt 2500 -a ${Mem} -le 3500 ]; then
+    sed -i 's@^thread_cache_size.*@thread_cache_size = 32@' /etc/my.cnf
+    sed -i 's@^query_cache_size.*@query_cache_size = 32M@' /etc/my.cnf
+    sed -i 's@^myisam_sort_buffer_size.*@myisam_sort_buffer_size = 32M@' /etc/my.cnf
+    sed -i 's@^key_buffer_size.*@key_buffer_size = 64M@' /etc/my.cnf
+    sed -i 's@^innodb_buffer_pool_size.*@innodb_buffer_pool_size = 512M@' /etc/my.cnf
+    sed -i 's@^tmp_table_size.*@tmp_table_size = 64M@' /etc/my.cnf
+    sed -i 's@^table_open_cache.*@table_open_cache = 512@' /etc/my.cnf
+  elif [ ${Mem} -gt 3500 ]; then
+    sed -i 's@^thread_cache_size.*@thread_cache_size = 64@' /etc/my.cnf
+    sed -i 's@^query_cache_size.*@query_cache_size = 64M@' /etc/my.cnf
+    sed -i 's@^myisam_sort_buffer_size.*@myisam_sort_buffer_size = 64M@' /etc/my.cnf
+    sed -i 's@^key_buffer_size.*@key_buffer_size = 256M@' /etc/my.cnf
+    sed -i 's@^innodb_buffer_pool_size.*@innodb_buffer_pool_size = 1024M@' /etc/my.cnf
+    sed -i 's@^tmp_table_size.*@tmp_table_size = 128M@' /etc/my.cnf
+    sed -i 's@^table_open_cache.*@table_open_cache = 1024@' /etc/my.cnf
+  fi
+
+  ${mariadb_install_dir}/scripts/mysql_install_db --user=mysql --basedir=${mariadb_install_dir} --datadir=${mariadb_data_dir}
+
+  chown mysql.mysql -R ${mariadb_data_dir}
+  [ -d "/etc/mysql" ] && /bin/mv /etc/mysql{,_bk}
+  service mysqld start
+  [ -z "$(grep ^'export PATH=' /etc/profile)" ] && echo "export PATH=${mariadb_install_dir}/bin:\$PATH" >> /etc/profile
+  [ -n "$(grep ^'export PATH=' /etc/profile)" -a -z "$(grep ${mariadb_install_dir} /etc/profile)" ] && sed -i "s@^export PATH=\(.*\)@export PATH=${mariadb_install_dir}/bin:\1@" /etc/profile
+  . /etc/profile
+
+  ${mariadb_install_dir}/bin/mysql -e "grant all privileges on *.* to root@'127.0.0.1' identified by \"${dbrootpwd}\" with grant option;"
+  ${mariadb_install_dir}/bin/mysql -e "grant all privileges on *.* to root@'localhost' identified by \"${dbrootpwd}\" with grant option;"
+  ${mariadb_install_dir}/bin/mysql -uroot -p${dbrootpwd} -e "delete from mysql.user where Password='';"
+  ${mariadb_install_dir}/bin/mysql -uroot -p${dbrootpwd} -e "delete from mysql.db where User='';"
+  ${mariadb_install_dir}/bin/mysql -uroot -p${dbrootpwd} -e "delete from mysql.proxies_priv where Host!='localhost';"
+  ${mariadb_install_dir}/bin/mysql -uroot -p${dbrootpwd} -e "drop database test;"
+  ${mariadb_install_dir}/bin/mysql -uroot -p${dbrootpwd} -e "reset master;"
+  rm -rf /etc/ld.so.conf.d/{mysql,mariadb,percona,alisql}*.conf
+  echo "${mariadb_install_dir}/lib" > /etc/ld.so.conf.d/mariadb.conf
+  ldconfig
+  service mysqld stop
+}

+ 25 - 16
install.sh

@@ -169,23 +169,24 @@ while :; do echo
         echo -e "\t${CMSG} 1${CEND}. Install MySQL-5.7"
         echo -e "\t${CMSG} 2${CEND}. Install MySQL-5.6"
         echo -e "\t${CMSG} 3${CEND}. Install MySQL-5.5"
-        echo -e "\t${CMSG} 4${CEND}. Install MariaDB-10.1"
-        echo -e "\t${CMSG} 5${CEND}. Install MariaDB-10.0"
-        echo -e "\t${CMSG} 6${CEND}. Install MariaDB-5.5"
-        echo -e "\t${CMSG} 7${CEND}. Install Percona-5.7"
-        echo -e "\t${CMSG} 8${CEND}. Install Percona-5.6"
-        echo -e "\t${CMSG} 9${CEND}. Install Percona-5.5"
-        echo -e "\t${CMSG}10${CEND}. Install AliSQL-5.6"
+        echo -e "\t${CMSG} 4${CEND}. Install MariaDB-10.2"
+        echo -e "\t${CMSG} 5${CEND}. Install MariaDB-10.1"
+        echo -e "\t${CMSG} 6${CEND}. Install MariaDB-10.0"
+        echo -e "\t${CMSG} 7${CEND}. Install MariaDB-5.5"
+        echo -e "\t${CMSG} 8${CEND}. Install Percona-5.7"
+        echo -e "\t${CMSG} 9${CEND}. Install Percona-5.6"
+        echo -e "\t${CMSG}10${CEND}. Install Percona-5.5"
+        echo -e "\t${CMSG}11${CEND}. Install AliSQL-5.6"
         read -p "Please input a number:(Default 2 press Enter) " DB_version
         [ -z "$DB_version" ] && DB_version=2
-        if [ ${DB_version} -ge 1 >/dev/null 2>&1 -a ${DB_version} -le 10 >/dev/null 2>&1 ]; then
+        if [ ${DB_version} -ge 1 >/dev/null 2>&1 -a ${DB_version} -le 11 >/dev/null 2>&1 ]; then
           while :; do
             read -p "Please input the root password of database: " dbrootpwd
             [ -n "`echo $dbrootpwd | grep '[+|&]'`" ] && { echo "${CWARNING}input error,not contain a plus sign (+) and & ${CEND}"; continue; }
             (( ${#dbrootpwd} >= 5 )) && sed -i "s+^dbrootpwd.*+dbrootpwd='$dbrootpwd'+" ./options.conf && break || echo "${CWARNING}database root password least 5 characters! ${CEND}"
           done
           # choose install methods
-          if [[ $DB_version =~ ^[1-9]$ ]]; then
+          if [ ${DB_version} -ge 1 >/dev/null 2>&1 -a ${DB_version} -le 10 >/dev/null 2>&1 ]; then
             while :; do echo
               echo "Please choose installation of the database:"
               echo -e "\t${CMSG}1${CEND}. Install database from binary package."
@@ -201,7 +202,7 @@ while :; do echo
           fi
           break
         else
-          echo "${CWARNING}input error! Please only input number 1,2,3,4,5,6,7,8,9,10${CEND}"
+          echo "${CWARNING}input error! Please only input number 1~11${CEND}"
         fi
       done
     fi
@@ -526,6 +527,14 @@ case "${DB_version}" in
     Install_MySQL55 2>&1 | tee -a ${oneinstack_dir}/install.log
     ;;
   4)
+    if [ "${dbInstallMethods}" == "2" ]; then
+      . include/boost.sh
+      installBoost 2>&1 | tee -a ${oneinstack_dir}/install.log
+    fi
+    . include/mariadb-10.2.sh
+    Install_MariaDB102 2>&1 | tee -a ${oneinstack_dir}/install.log
+    ;;
+  5)
     if [ "${dbInstallMethods}" == "2" ]; then
       . include/boost.sh
       installBoost 2>&1 | tee -a ${oneinstack_dir}/install.log
@@ -533,15 +542,15 @@ case "${DB_version}" in
     . include/mariadb-10.1.sh
     Install_MariaDB101 2>&1 | tee -a ${oneinstack_dir}/install.log
     ;;
-  5)
+  6)
     . include/mariadb-10.0.sh
     Install_MariaDB100 2>&1 | tee -a ${oneinstack_dir}/install.log
     ;;
-  6)
+  7)
     . include/mariadb-5.5.sh
     Install_MariaDB55 2>&1 | tee -a ${oneinstack_dir}/install.log
     ;;
-  7)
+  8)
     if [ "${dbInstallMethods}" == "2" ]; then
       . include/boost.sh
       installBoost 2>&1 | tee -a ${oneinstack_dir}/install.log
@@ -549,15 +558,15 @@ case "${DB_version}" in
     . include/percona-5.7.sh
     Install_Percona57 2>&1 | tee -a ${oneinstack_dir}/install.log
     ;;
-  8)
+  9)
     . include/percona-5.6.sh
     Install_Percona56 2>&1 | tee -a ${oneinstack_dir}/install.log
     ;;
-  9)
+  10)
     . include/percona-5.5.sh
     Install_Percona55 2>&1 | tee -a ${oneinstack_dir}/install.log
     ;;
-  10)
+  11)
     . include/alisql-5.6.sh
     Install_AliSQL56 2>&1 | tee -a $oneinstack_dir/install.log
     ;;

+ 2 - 2
versions.txt

@@ -28,7 +28,7 @@ mariadb55_version=5.5.56
 
 percona57_version=5.7.18-15
 percona56_version=5.6.36-82.0
-percona55_version=5.5.58-38.8
+percona55_version=5.5.55-38.8
 
 alisql56_version=5.6.32-5
 
@@ -88,7 +88,7 @@ boost_version=1.59.0
 
 # Others
 libevent_version=2.0.22-stable
-tmux_version=2.3
+tmux_version=2.5
 htop_version=2.0.2
 bison_version=2.7.1
 python_version=2.7.13