percona-5.6.sh 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. #!/bin/bash
  2. # Author: yeho <lj2007331 AT gmail.com>
  3. # BLOG: https://blog.linuxeye.com
  4. #
  5. # Notes: OneinStack for CentOS/RadHat 5+ Debian 6+ and Ubuntu 12+
  6. #
  7. # Project home page:
  8. # http://oneinstack.com
  9. # https://github.com/lj2007331/oneinstack
  10. Install_Percona-5-6()
  11. {
  12. cd $oneinstack_dir/src
  13. src_url=http://www.percona.com/redir/downloads/Percona-Server-5.6/LATEST/source/tarball/percona-server-$percona_6_version.tar.gz && Download_src
  14. id -u mysql >/dev/null 2>&1
  15. [ $? -ne 0 ] && useradd -M -s /sbin/nologin mysql
  16. mkdir -p $percona_data_dir;chown mysql.mysql -R $percona_data_dir
  17. tar zxf percona-server-$percona_6_version.tar.gz
  18. cd percona-server-$percona_6_version
  19. if [ "$je_tc_malloc" == '1' ];then
  20. EXE_LINKER="-DCMAKE_EXE_LINKER_FLAGS='-ljemalloc'"
  21. elif [ "$je_tc_malloc" == '2' ];then
  22. EXE_LINKER="-DCMAKE_EXE_LINKER_FLAGS='-ltcmalloc'"
  23. fi
  24. make clean
  25. [ ! -d "$percona_install_dir" ] && mkdir -p $percona_install_dir
  26. cmake . -DCMAKE_INSTALL_PREFIX=$percona_install_dir \
  27. -DMYSQL_DATADIR=$percona_data_dir \
  28. -DSYSCONFDIR=/etc \
  29. -DWITH_INNOBASE_STORAGE_ENGINE=1 \
  30. -DWITH_PARTITION_STORAGE_ENGINE=1 \
  31. -DWITH_FEDERATED_STORAGE_ENGINE=1 \
  32. -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
  33. -DWITH_MYISAM_STORAGE_ENGINE=1 \
  34. -DWITH_ARCHIVE_STORAGE_ENGINE=1 \
  35. -DENABLED_LOCAL_INFILE=1 \
  36. -DENABLE_DTRACE=0 \
  37. -DDEFAULT_CHARSET=utf8mb4 \
  38. -DDEFAULT_COLLATION=utf8mb4_general_ci \
  39. $EXE_LINKER
  40. make -j `grep processor /proc/cpuinfo | wc -l`
  41. make install
  42. if [ -d "$percona_install_dir/support-files" ];then
  43. echo "${CSUCCESS}Percona install successfully! ${CEND}"
  44. cd ..
  45. rm -rf percona-server-$percona_6_version
  46. else
  47. rm -rf $percona_install_dir
  48. echo "${CFAILURE}Percona install failed, Please contact the author! ${CEND}"
  49. kill -9 $$
  50. fi
  51. /bin/cp $percona_install_dir/support-files/mysql.server /etc/init.d/mysqld
  52. chmod +x /etc/init.d/mysqld
  53. OS_CentOS='chkconfig --add mysqld \n
  54. chkconfig mysqld on'
  55. OS_Debian_Ubuntu='update-rc.d mysqld defaults'
  56. OS_command
  57. cd ..
  58. # my.cf
  59. cat > /etc/my.cnf << EOF
  60. [client]
  61. port = 3306
  62. socket = /tmp/mysql.sock
  63. default-character-set = utf8mb4
  64. [mysqld]
  65. port = 3306
  66. socket = /tmp/mysql.sock
  67. basedir = $percona_install_dir
  68. datadir = $percona_data_dir
  69. pid-file = $percona_data_dir/mysql.pid
  70. user = mysql
  71. bind-address = 0.0.0.0
  72. server-id = 1
  73. init-connect = 'SET NAMES utf8mb4'
  74. character-set-server = utf8mb4
  75. skip-name-resolve
  76. #skip-networking
  77. back_log = 300
  78. max_connections = 1000
  79. max_connect_errors = 6000
  80. open_files_limit = 65535
  81. table_open_cache = 128
  82. max_allowed_packet = 4M
  83. binlog_cache_size = 1M
  84. max_heap_table_size = 8M
  85. tmp_table_size = 16M
  86. read_buffer_size = 2M
  87. read_rnd_buffer_size = 8M
  88. sort_buffer_size = 8M
  89. join_buffer_size = 8M
  90. key_buffer_size = 4M
  91. thread_cache_size = 8
  92. query_cache_type = 1
  93. query_cache_size = 8M
  94. query_cache_limit = 2M
  95. ft_min_word_len = 4
  96. log_bin = mysql-bin
  97. binlog_format = mixed
  98. expire_logs_days = 30
  99. log_error = $percona_data_dir/mysql-error.log
  100. slow_query_log = 1
  101. long_query_time = 1
  102. slow_query_log_file = $percona_data_dir/mysql-slow.log
  103. performance_schema = 0
  104. explicit_defaults_for_timestamp
  105. #lower_case_table_names = 1
  106. skip-external-locking
  107. default_storage_engine = InnoDB
  108. #default-storage-engine = MyISAM
  109. innodb_file_per_table = 1
  110. innodb_open_files = 500
  111. innodb_buffer_pool_size = 64M
  112. innodb_write_io_threads = 4
  113. innodb_read_io_threads = 4
  114. innodb_thread_concurrency = 0
  115. innodb_purge_threads = 1
  116. innodb_flush_log_at_trx_commit = 2
  117. innodb_log_buffer_size = 2M
  118. innodb_log_file_size = 32M
  119. innodb_log_files_in_group = 3
  120. innodb_max_dirty_pages_pct = 90
  121. innodb_lock_wait_timeout = 120
  122. bulk_insert_buffer_size = 8M
  123. myisam_sort_buffer_size = 8M
  124. myisam_max_sort_file_size = 10G
  125. myisam_repair_threads = 1
  126. interactive_timeout = 28800
  127. wait_timeout = 28800
  128. [mysqldump]
  129. quick
  130. max_allowed_packet = 16M
  131. [myisamchk]
  132. key_buffer_size = 8M
  133. sort_buffer_size = 8M
  134. read_buffer = 4M
  135. write_buffer = 4M
  136. EOF
  137. if [ $Mem -gt 1500 -a $Mem -le 2500 ];then
  138. sed -i 's@^thread_cache_size.*@thread_cache_size = 16@' /etc/my.cnf
  139. sed -i 's@^query_cache_size.*@query_cache_size = 16M@' /etc/my.cnf
  140. sed -i 's@^myisam_sort_buffer_size.*@myisam_sort_buffer_size = 16M@' /etc/my.cnf
  141. sed -i 's@^key_buffer_size.*@key_buffer_size = 16M@' /etc/my.cnf
  142. sed -i 's@^innodb_buffer_pool_size.*@innodb_buffer_pool_size = 128M@' /etc/my.cnf
  143. sed -i 's@^tmp_table_size.*@tmp_table_size = 32M@' /etc/my.cnf
  144. sed -i 's@^table_open_cache.*@table_open_cache = 256@' /etc/my.cnf
  145. elif [ $Mem -gt 2500 -a $Mem -le 3500 ];then
  146. sed -i 's@^thread_cache_size.*@thread_cache_size = 32@' /etc/my.cnf
  147. sed -i 's@^query_cache_size.*@query_cache_size = 32M@' /etc/my.cnf
  148. sed -i 's@^myisam_sort_buffer_size.*@myisam_sort_buffer_size = 32M@' /etc/my.cnf
  149. sed -i 's@^key_buffer_size.*@key_buffer_size = 64M@' /etc/my.cnf
  150. sed -i 's@^innodb_buffer_pool_size.*@innodb_buffer_pool_size = 512M@' /etc/my.cnf
  151. sed -i 's@^tmp_table_size.*@tmp_table_size = 64M@' /etc/my.cnf
  152. sed -i 's@^table_open_cache.*@table_open_cache = 512@' /etc/my.cnf
  153. elif [ $Mem -gt 3500 ];then
  154. sed -i 's@^thread_cache_size.*@thread_cache_size = 64@' /etc/my.cnf
  155. sed -i 's@^query_cache_size.*@query_cache_size = 64M@' /etc/my.cnf
  156. sed -i 's@^myisam_sort_buffer_size.*@myisam_sort_buffer_size = 64M@' /etc/my.cnf
  157. sed -i 's@^key_buffer_size.*@key_buffer_size = 256M@' /etc/my.cnf
  158. sed -i 's@^innodb_buffer_pool_size.*@innodb_buffer_pool_size = 1024M@' /etc/my.cnf
  159. sed -i 's@^tmp_table_size.*@tmp_table_size = 128M@' /etc/my.cnf
  160. sed -i 's@^table_open_cache.*@table_open_cache = 1024@' /etc/my.cnf
  161. fi
  162. $percona_install_dir/scripts/mysql_install_db --user=mysql --basedir=$percona_install_dir --datadir=$percona_data_dir
  163. chown mysql.mysql -R $percona_data_dir
  164. service mysqld start
  165. [ -z "`grep ^'export PATH=' /etc/profile`" ] && echo "export PATH=$percona_install_dir/bin:\$PATH" >> /etc/profile
  166. [ -n "`grep ^'export PATH=' /etc/profile`" -a -z "`grep $percona_install_dir /etc/profile`" ] && sed -i "s@^export PATH=\(.*\)@export PATH=$percona_install_dir/bin:\1@" /etc/profile
  167. . /etc/profile
  168. $percona_install_dir/bin/mysql -e "grant all privileges on *.* to root@'127.0.0.1' identified by \"$dbrootpwd\" with grant option;"
  169. $percona_install_dir/bin/mysql -e "grant all privileges on *.* to root@'localhost' identified by \"$dbrootpwd\" with grant option;"
  170. $percona_install_dir/bin/mysql -uroot -p$dbrootpwd -e "delete from mysql.user where Password='';"
  171. $percona_install_dir/bin/mysql -uroot -p$dbrootpwd -e "delete from mysql.db where User='';"
  172. $percona_install_dir/bin/mysql -uroot -p$dbrootpwd -e "delete from mysql.proxies_priv where Host!='localhost';"
  173. $percona_install_dir/bin/mysql -uroot -p$dbrootpwd -e "drop database test;"
  174. $percona_install_dir/bin/mysql -uroot -p$dbrootpwd -e "reset master;"
  175. sed -i "s@^db_install_dir.*@db_install_dir=$percona_install_dir@" options.conf
  176. sed -i "s@^db_data_dir.*@db_data_dir=$percona_data_dir@" options.conf
  177. service mysqld stop
  178. }