mariadb-10.0.sh 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. #!/bin/bash
  2. # Author: yeho <lj2007331 AT gmail.com>
  3. # Blog: http://blog.linuxeye.com
  4. Install_MariaDB-10-0()
  5. {
  6. cd $oneinstack_dir/src
  7. . ../functions/download.sh
  8. . ../functions/check_os.sh
  9. . ../options.conf
  10. public_IP=`../functions/get_public_ip.py`
  11. if [ "`../functions/get_ip_area.py $public_IP`" == '\u4e2d\u56fd' ];then
  12. FLAG_IP=CN
  13. fi
  14. echo $public_IP $FLAG_IP
  15. [ "$FLAG_IP"x == "CN"x ] && DOWN_ADDR=http://mirrors.aliyun.com/mariadb || DOWN_ADDR=https://downloads.mariadb.org/f
  16. [ -d "/lib64" ] && { SYS_BIT_a=x86_64;SYS_BIT_b=x86_64; } || { SYS_BIT_a=x86;SYS_BIT_b=i686; }
  17. LIBC_VERSION=`getconf -a | grep GNU_LIBC_VERSION | awk '{print $NF}'`
  18. LIBC_YN=`echo "$LIBC_VERSION < 2.14" | bc`
  19. [ $LIBC_YN == '1' ] && GLIBC_FLAG=linux || GLIBC_FLAG=linux-glibc_214
  20. src_url=$DOWN_ADDR/mariadb-${mariadb_10_version}/bintar-${GLIBC_FLAG}-$SYS_BIT_a/mariadb-${mariadb_10_version}-${GLIBC_FLAG}-${SYS_BIT_b}.tar.gz && Download_src
  21. useradd -M -s /sbin/nologin mysql
  22. mkdir -p $mariadb_data_dir;chown mysql.mysql -R $mariadb_data_dir
  23. tar zxf mariadb-${mariadb_10_version}-${GLIBC_FLAG}-${SYS_BIT_b}.tar.gz
  24. [ ! -d "$mariadb_install_dir" ] && mkdir -p $mariadb_install_dir
  25. mv mariadb-${mariadb_10_version}-linux-${SYS_BIT_b}/* $mariadb_install_dir
  26. if [ "$je_tc_malloc" == '1' ];then
  27. sed -i 's@executing mysqld_safe@executing mysqld_safe\nexport LD_PRELOAD=/usr/local/lib/libjemalloc.so@' $mariadb_install_dir/bin/mysqld_safe
  28. elif [ "$je_tc_malloc" == '2' ];then
  29. sed -i 's@executing mysqld_safe@executing mysqld_safe\nexport LD_PRELOAD=/usr/local/lib/libtcmalloc.so@' $mariadb_install_dir/bin/mysqld_safe
  30. fi
  31. if [ -d "$mariadb_install_dir/bin" ];then
  32. echo -e "\033[32mMariaDB install successfully! \033[0m"
  33. else
  34. rm -rf $mariadb_install_dir
  35. echo -e "\033[31mMariaDB install failed, Please contact the author! \033[0m"
  36. kill -9 $$
  37. fi
  38. /bin/cp $mariadb_install_dir/support-files/mysql.server /etc/init.d/mysqld
  39. sed -i "s@^basedir=.*@basedir=$mariadb_install_dir@" /etc/init.d/mysqld
  40. sed -i "s@^datadir=.*@datadir=$mariadb_data_dir@" /etc/init.d/mysqld
  41. chmod +x /etc/init.d/mysqld
  42. OS_CentOS='chkconfig --add mysqld \n
  43. chkconfig mysqld on'
  44. OS_Debian_Ubuntu='update-rc.d mysqld defaults'
  45. OS_command
  46. cd ..
  47. # my.cf
  48. cat > /etc/my.cnf << EOF
  49. [client]
  50. port = 3306
  51. socket = /tmp/mysql.sock
  52. default-character-set = utf8mb4
  53. [mysqld]
  54. port = 3306
  55. socket = /tmp/mysql.sock
  56. basedir = $mariadb_install_dir
  57. datadir = $mariadb_data_dir
  58. pid-file = $mariadb_data_dir/mysql.pid
  59. user = mysql
  60. bind-address = 0.0.0.0
  61. server-id = 1
  62. init-connect = 'SET NAMES utf8mb4'
  63. character-set-server = utf8mb4
  64. skip-name-resolve
  65. #skip-networking
  66. back_log = 300
  67. max_connections = 1000
  68. max_connect_errors = 6000
  69. open_files_limit = 65535
  70. table_open_cache = 128
  71. max_allowed_packet = 4M
  72. binlog_cache_size = 1M
  73. max_heap_table_size = 8M
  74. tmp_table_size = 16M
  75. read_buffer_size = 2M
  76. read_rnd_buffer_size = 8M
  77. sort_buffer_size = 8M
  78. join_buffer_size = 8M
  79. key_buffer_size = 4M
  80. thread_cache_size = 8
  81. query_cache_type = 1
  82. query_cache_size = 8M
  83. query_cache_limit = 2M
  84. ft_min_word_len = 4
  85. log_bin = mysql-bin
  86. binlog_format = mixed
  87. expire_logs_days = 30
  88. log_error = $mariadb_data_dir/mysql-error.log
  89. slow_query_log = 1
  90. long_query_time = 1
  91. slow_query_log_file = $mariadb_data_dir/mysql-slow.log
  92. performance_schema = 0
  93. #lower_case_table_names = 1
  94. skip-external-locking
  95. default_storage_engine = InnoDB
  96. #default-storage-engine = MyISAM
  97. innodb_file_per_table = 1
  98. innodb_open_files = 500
  99. innodb_buffer_pool_size = 64M
  100. innodb_write_io_threads = 4
  101. innodb_read_io_threads = 4
  102. innodb_thread_concurrency = 0
  103. innodb_purge_threads = 1
  104. innodb_flush_log_at_trx_commit = 2
  105. innodb_log_buffer_size = 2M
  106. innodb_log_file_size = 32M
  107. innodb_log_files_in_group = 3
  108. innodb_max_dirty_pages_pct = 90
  109. innodb_lock_wait_timeout = 120
  110. bulk_insert_buffer_size = 8M
  111. myisam_sort_buffer_size = 8M
  112. myisam_max_sort_file_size = 10G
  113. myisam_repair_threads = 1
  114. interactive_timeout = 28800
  115. wait_timeout = 28800
  116. [mysqldump]
  117. quick
  118. max_allowed_packet = 16M
  119. [myisamchk]
  120. key_buffer_size = 8M
  121. sort_buffer_size = 8M
  122. read_buffer = 4M
  123. write_buffer = 4M
  124. EOF
  125. Memtatol=`free -m | grep 'Mem:' | awk '{print $2}'`
  126. if [ $Memtatol -gt 1500 -a $Memtatol -le 2500 ];then
  127. sed -i 's@^thread_cache_size.*@thread_cache_size = 16@' /etc/my.cnf
  128. sed -i 's@^query_cache_size.*@query_cache_size = 16M@' /etc/my.cnf
  129. sed -i 's@^myisam_sort_buffer_size.*@myisam_sort_buffer_size = 16M@' /etc/my.cnf
  130. sed -i 's@^key_buffer_size.*@key_buffer_size = 16M@' /etc/my.cnf
  131. sed -i 's@^innodb_buffer_pool_size.*@innodb_buffer_pool_size = 128M@' /etc/my.cnf
  132. sed -i 's@^tmp_table_size.*@tmp_table_size = 32M@' /etc/my.cnf
  133. sed -i 's@^table_open_cache.*@table_open_cache = 256@' /etc/my.cnf
  134. elif [ $Memtatol -gt 2500 -a $Memtatol -le 3500 ];then
  135. sed -i 's@^thread_cache_size.*@thread_cache_size = 32@' /etc/my.cnf
  136. sed -i 's@^query_cache_size.*@query_cache_size = 32M@' /etc/my.cnf
  137. sed -i 's@^myisam_sort_buffer_size.*@myisam_sort_buffer_size = 32M@' /etc/my.cnf
  138. sed -i 's@^key_buffer_size.*@key_buffer_size = 64M@' /etc/my.cnf
  139. sed -i 's@^innodb_buffer_pool_size.*@innodb_buffer_pool_size = 512M@' /etc/my.cnf
  140. sed -i 's@^tmp_table_size.*@tmp_table_size = 64M@' /etc/my.cnf
  141. sed -i 's@^table_open_cache.*@table_open_cache = 512@' /etc/my.cnf
  142. elif [ $Memtatol -gt 3500 ];then
  143. sed -i 's@^thread_cache_size.*@thread_cache_size = 64@' /etc/my.cnf
  144. sed -i 's@^query_cache_size.*@query_cache_size = 64M@' /etc/my.cnf
  145. sed -i 's@^myisam_sort_buffer_size.*@myisam_sort_buffer_size = 64M@' /etc/my.cnf
  146. sed -i 's@^key_buffer_size.*@key_buffer_size = 256M@' /etc/my.cnf
  147. sed -i 's@^innodb_buffer_pool_size.*@innodb_buffer_pool_size = 1024M@' /etc/my.cnf
  148. sed -i 's@^tmp_table_size.*@tmp_table_size = 128M@' /etc/my.cnf
  149. sed -i 's@^table_open_cache.*@table_open_cache = 1024@' /etc/my.cnf
  150. fi
  151. $mariadb_install_dir/scripts/mysql_install_db --user=mysql --basedir=$mariadb_install_dir --datadir=$mariadb_data_dir
  152. chown mysql.mysql -R $mariadb_data_dir
  153. service mysqld start
  154. [ -z "`grep ^'export PATH=' /etc/profile`" ] && echo "export PATH=$mariadb_install_dir/bin:\$PATH" >> /etc/profile
  155. [ -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
  156. . /etc/profile
  157. $mariadb_install_dir/bin/mysql -e "grant all privileges on *.* to root@'127.0.0.1' identified by \"$dbrootpwd\" with grant option;"
  158. $mariadb_install_dir/bin/mysql -e "grant all privileges on *.* to root@'localhost' identified by \"$dbrootpwd\" with grant option;"
  159. $mariadb_install_dir/bin/mysql -uroot -p$dbrootpwd -e "delete from mysql.user where Password='';"
  160. $mariadb_install_dir/bin/mysql -uroot -p$dbrootpwd -e "delete from mysql.db where User='';"
  161. $mariadb_install_dir/bin/mysql -uroot -p$dbrootpwd -e "delete from mysql.proxies_priv where Host!='localhost';"
  162. $mariadb_install_dir/bin/mysql -uroot -p$dbrootpwd -e "drop database test;"
  163. $mariadb_install_dir/bin/mysql -uroot -p$dbrootpwd -e "reset master;"
  164. sed -i "s@^db_install_dir.*@db_install_dir=$mariadb_install_dir@" options.conf
  165. sed -i "s@^db_data_dir.*@db_data_dir=$mariadb_data_dir@" options.conf
  166. service mysqld stop
  167. }