mariadb-10.0.sh 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. [mysqld]
  53. port = 3306
  54. socket = /tmp/mysql.sock
  55. basedir = $mariadb_install_dir
  56. datadir = $mariadb_data_dir
  57. pid-file = $mariadb_data_dir/mysql.pid
  58. user = mysql
  59. bind-address = 0.0.0.0
  60. server-id = 1
  61. skip-name-resolve
  62. #skip-networking
  63. back_log = 300
  64. max_connections = 1000
  65. max_connect_errors = 6000
  66. open_files_limit = 65535
  67. table_open_cache = 128
  68. max_allowed_packet = 4M
  69. binlog_cache_size = 1M
  70. max_heap_table_size = 8M
  71. tmp_table_size = 16M
  72. read_buffer_size = 2M
  73. read_rnd_buffer_size = 8M
  74. sort_buffer_size = 8M
  75. join_buffer_size = 8M
  76. key_buffer_size = 4M
  77. thread_cache_size = 8
  78. query_cache_type = 1
  79. query_cache_size = 8M
  80. query_cache_limit = 2M
  81. ft_min_word_len = 4
  82. log_bin = mysql-bin
  83. binlog_format = mixed
  84. expire_logs_days = 30
  85. log_error = $mariadb_data_dir/mysql-error.log
  86. slow_query_log = 1
  87. long_query_time = 1
  88. slow_query_log_file = $mariadb_data_dir/mysql-slow.log
  89. performance_schema = 0
  90. #lower_case_table_names = 1
  91. skip-external-locking
  92. default_storage_engine = InnoDB
  93. #default-storage-engine = MyISAM
  94. innodb_file_per_table = 1
  95. innodb_open_files = 500
  96. innodb_buffer_pool_size = 64M
  97. innodb_write_io_threads = 4
  98. innodb_read_io_threads = 4
  99. innodb_thread_concurrency = 0
  100. innodb_purge_threads = 1
  101. innodb_flush_log_at_trx_commit = 2
  102. innodb_log_buffer_size = 2M
  103. innodb_log_file_size = 32M
  104. innodb_log_files_in_group = 3
  105. innodb_max_dirty_pages_pct = 90
  106. innodb_lock_wait_timeout = 120
  107. bulk_insert_buffer_size = 8M
  108. myisam_sort_buffer_size = 8M
  109. myisam_max_sort_file_size = 10G
  110. myisam_repair_threads = 1
  111. interactive_timeout = 28800
  112. wait_timeout = 28800
  113. [mysqldump]
  114. quick
  115. max_allowed_packet = 16M
  116. [myisamchk]
  117. key_buffer_size = 8M
  118. sort_buffer_size = 8M
  119. read_buffer = 4M
  120. write_buffer = 4M
  121. EOF
  122. Memtatol=`free -m | grep 'Mem:' | awk '{print $2}'`
  123. if [ $Memtatol -gt 1500 -a $Memtatol -le 2500 ];then
  124. sed -i 's@^thread_cache_size.*@thread_cache_size = 16@' /etc/my.cnf
  125. sed -i 's@^query_cache_size.*@query_cache_size = 16M@' /etc/my.cnf
  126. sed -i 's@^myisam_sort_buffer_size.*@myisam_sort_buffer_size = 16M@' /etc/my.cnf
  127. sed -i 's@^key_buffer_size.*@key_buffer_size = 16M@' /etc/my.cnf
  128. sed -i 's@^innodb_buffer_pool_size.*@innodb_buffer_pool_size = 128M@' /etc/my.cnf
  129. sed -i 's@^tmp_table_size.*@tmp_table_size = 32M@' /etc/my.cnf
  130. sed -i 's@^table_open_cache.*@table_open_cache = 256@' /etc/my.cnf
  131. elif [ $Memtatol -gt 2500 -a $Memtatol -le 3500 ];then
  132. sed -i 's@^thread_cache_size.*@thread_cache_size = 32@' /etc/my.cnf
  133. sed -i 's@^query_cache_size.*@query_cache_size = 32M@' /etc/my.cnf
  134. sed -i 's@^myisam_sort_buffer_size.*@myisam_sort_buffer_size = 32M@' /etc/my.cnf
  135. sed -i 's@^key_buffer_size.*@key_buffer_size = 64M@' /etc/my.cnf
  136. sed -i 's@^innodb_buffer_pool_size.*@innodb_buffer_pool_size = 512M@' /etc/my.cnf
  137. sed -i 's@^tmp_table_size.*@tmp_table_size = 64M@' /etc/my.cnf
  138. sed -i 's@^table_open_cache.*@table_open_cache = 512@' /etc/my.cnf
  139. elif [ $Memtatol -gt 3500 ];then
  140. sed -i 's@^thread_cache_size.*@thread_cache_size = 64@' /etc/my.cnf
  141. sed -i 's@^query_cache_size.*@query_cache_size = 64M@' /etc/my.cnf
  142. sed -i 's@^myisam_sort_buffer_size.*@myisam_sort_buffer_size = 64M@' /etc/my.cnf
  143. sed -i 's@^key_buffer_size.*@key_buffer_size = 256M@' /etc/my.cnf
  144. sed -i 's@^innodb_buffer_pool_size.*@innodb_buffer_pool_size = 1024M@' /etc/my.cnf
  145. sed -i 's@^tmp_table_size.*@tmp_table_size = 128M@' /etc/my.cnf
  146. sed -i 's@^table_open_cache.*@table_open_cache = 1024@' /etc/my.cnf
  147. fi
  148. $mariadb_install_dir/scripts/mysql_install_db --user=mysql --basedir=$mariadb_install_dir --datadir=$mariadb_data_dir
  149. chown mysql.mysql -R $mariadb_data_dir
  150. service mysqld start
  151. [ -z "`grep ^'export PATH=' /etc/profile`" ] && echo "export PATH=$mariadb_install_dir/bin:\$PATH" >> /etc/profile
  152. [ -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
  153. . /etc/profile
  154. $mariadb_install_dir/bin/mysql -e "grant all privileges on *.* to root@'127.0.0.1' identified by \"$dbrootpwd\" with grant option;"
  155. $mariadb_install_dir/bin/mysql -e "grant all privileges on *.* to root@'localhost' identified by \"$dbrootpwd\" with grant option;"
  156. $mariadb_install_dir/bin/mysql -uroot -p$dbrootpwd -e "delete from mysql.user where Password='';"
  157. $mariadb_install_dir/bin/mysql -uroot -p$dbrootpwd -e "delete from mysql.db where User='';"
  158. $mariadb_install_dir/bin/mysql -uroot -p$dbrootpwd -e "delete from mysql.proxies_priv where Host!='localhost';"
  159. $mariadb_install_dir/bin/mysql -uroot -p$dbrootpwd -e "drop database test;"
  160. $mariadb_install_dir/bin/mysql -uroot -p$dbrootpwd -e "reset master;"
  161. sed -i "s@^db_install_dir.*@db_install_dir=$mariadb_install_dir@" options.conf
  162. sed -i "s@^db_data_dir.*@db_data_dir=$mariadb_data_dir@" options.conf
  163. service mysqld stop
  164. }