percona-8.0.sh 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. #!/bin/bash
  2. # Author: yeho <lj2007331 AT gmail.com>
  3. # BLOG: https://linuxeye.com
  4. #
  5. # Notes: OneinStack for CentOS/RedHat 7+ Debian 9+ and Ubuntu 16+
  6. #
  7. # Project home page:
  8. # https://oneinstack.com
  9. # https://github.com/oneinstack/oneinstack
  10. Install_Percona80() {
  11. pushd ${oneinstack_dir}/src > /dev/null
  12. id -u mysql >/dev/null 2>&1
  13. [ $? -ne 0 ] && useradd -M -s /sbin/nologin mysql
  14. [ ! -d "${percona_install_dir}" ] && mkdir -p ${percona_install_dir}
  15. mkdir -p ${percona_data_dir};chown mysql:mysql -R ${percona_data_dir}
  16. if [ "${dbinstallmethod}" == "1" ]; then
  17. tar xzf ./Percona-Server-${percona80_ver}-Linux.x86_64.glibc2.28.tar.gz
  18. mv Percona-Server-${percona80_ver}-Linux.x86_64.glibc2.28/* ${percona_install_dir}
  19. #sed -i 's@executing mysqld_safe@executing mysqld_safe\nexport LD_PRELOAD=/usr/local/lib/libjemalloc.so@' ${percona_install_dir}/bin/mysqld_safe
  20. sed -i "s@/usr/local/Percona-Server-${percona80_ver}-Linux.x86_64.glibc2.28@${percona_install_dir}@g" ${percona_install_dir}/bin/mysqld_safe
  21. elif [ "${dbinstallmethod}" == "2" ]; then
  22. boostVersion2=$(echo ${boost_percona_ver} | awk -F. '{print $1"_"$2"_"$3}')
  23. tar xzf boost_${boostVersion2}.tar.gz
  24. tar xzf percona-server-${percona80_ver}.tar.gz
  25. pushd percona-server-${percona80_ver}
  26. cmake . -DCMAKE_INSTALL_PREFIX=${percona_install_dir} \
  27. -DMYSQL_DATADIR=${percona_data_dir} \
  28. -DDOWNLOAD_BOOST=1 \
  29. -DWITH_BOOST=../boost_${boostVersion2} \
  30. -DFORCE_INSOURCE_BUILD=1 \
  31. -DSYSCONFDIR=/etc \
  32. -DWITH_INNOBASE_STORAGE_ENGINE=1 \
  33. -DWITH_PARTITION_STORAGE_ENGINE=1 \
  34. -DWITH_FEDERATED_STORAGE_ENGINE=1 \
  35. -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
  36. -DWITH_MYISAM_STORAGE_ENGINE=1 \
  37. -DWITH_EMBEDDED_SERVER=1 \
  38. -DENABLE_DTRACE=0 \
  39. -DENABLED_LOCAL_INFILE=1 \
  40. -DDEFAULT_CHARSET=utf8mb4 \
  41. -DEXTRA_CHARSETS=all
  42. make -j ${THREAD}
  43. make install
  44. sed -i 's@^load_jemalloc=1@load_jemalloc=0@' ${percona_install_dir}/bin/mysqld_safe
  45. popd
  46. fi
  47. # backup openssl so
  48. #[ ! -e "${percona_install_dir}/lib/lib_bk" ] && mkdir ${percona_install_dir}/lib/lib_bk
  49. #/bin/mv ${percona_install_dir}/lib/{libssl,libcrypto}.so* ${percona_install_dir}/lib/lib_bk/
  50. if [ -d "${percona_install_dir}/support-files" ]; then
  51. sed -i "s+^dbrootpwd.*+dbrootpwd='${dbrootpwd}'+" ../options.conf
  52. echo "${CSUCCESS}Percona installed successfully! ${CEND}"
  53. if [ "${dbinstallmethod}" == "1" ]; then
  54. rm -rf Percona-Server-${percona80_ver}-Linux.x86_64.glibc2.28
  55. elif [ "${dbinstallmethod}" == "2" ]; then
  56. rm -rf percona-server-${percona80_ver} boost_${boostVersion2}
  57. fi
  58. else
  59. rm -rf ${percona_install_dir}
  60. echo "${CFAILURE}Percona install failed, Please contact the author! ${CEND}" && grep -Ew 'NAME|ID|ID_LIKE|VERSION_ID|PRETTY_NAME' /etc/os-release
  61. kill -9 $$; exit 1;
  62. fi
  63. /bin/cp ${percona_install_dir}/support-files/mysql.server /etc/init.d/mysqld
  64. sed -i "s@^basedir=.*@basedir=${percona_install_dir}@" /etc/init.d/mysqld
  65. sed -i "s@^datadir=.*@datadir=${percona_data_dir}@" /etc/init.d/mysqld
  66. chmod +x /etc/init.d/mysqld
  67. [ "${PM}" == 'yum' ] && { chkconfig --add mysqld; chkconfig mysqld on; }
  68. [ "${PM}" == 'apt-get' ] && update-rc.d mysqld defaults
  69. popd
  70. # my.cnf
  71. cat > /etc/my.cnf << EOF
  72. [client]
  73. port = 3306
  74. socket = /tmp/mysql.sock
  75. default-character-set = utf8mb4
  76. [mysql]
  77. prompt="Percona [\\d]> "
  78. no-auto-rehash
  79. [mysqld]
  80. port = 3306
  81. socket = /tmp/mysql.sock
  82. default_authentication_plugin = mysql_native_password
  83. basedir = ${percona_install_dir}
  84. datadir = ${percona_data_dir}
  85. pid-file = ${percona_data_dir}/mysql.pid
  86. user = mysql
  87. bind-address = 0.0.0.0
  88. server-id = 1
  89. init-connect = 'SET NAMES utf8mb4'
  90. character-set-server = utf8mb4
  91. collation-server = utf8mb4_0900_ai_ci
  92. skip-name-resolve
  93. #skip-networking
  94. back_log = 300
  95. max_connections = 1000
  96. max_connect_errors = 6000
  97. open_files_limit = 65535
  98. table_open_cache = 128
  99. max_allowed_packet = 500M
  100. binlog_cache_size = 1M
  101. max_heap_table_size = 8M
  102. tmp_table_size = 16M
  103. read_buffer_size = 2M
  104. read_rnd_buffer_size = 8M
  105. sort_buffer_size = 8M
  106. join_buffer_size = 8M
  107. key_buffer_size = 4M
  108. thread_cache_size = 8
  109. ft_min_word_len = 4
  110. log_bin = mysql-bin
  111. binlog_format = mixed
  112. binlog_expire_logs_seconds = 604800
  113. log_error = ${percona_data_dir}/mysql-error.log
  114. slow_query_log = 1
  115. long_query_time = 1
  116. slow_query_log_file = ${percona_data_dir}/mysql-slow.log
  117. performance_schema = 0
  118. explicit_defaults_for_timestamp
  119. #lower_case_table_names = 1
  120. skip-external-locking
  121. default_storage_engine = InnoDB
  122. #default-storage-engine = MyISAM
  123. innodb_file_per_table = 1
  124. innodb_open_files = 500
  125. innodb_buffer_pool_size = 64M
  126. innodb_write_io_threads = 4
  127. innodb_read_io_threads = 4
  128. innodb_thread_concurrency = 0
  129. innodb_purge_threads = 1
  130. innodb_flush_log_at_trx_commit = 2
  131. innodb_log_buffer_size = 2M
  132. innodb_log_file_size = 32M
  133. innodb_log_files_in_group = 3
  134. innodb_max_dirty_pages_pct = 90
  135. innodb_lock_wait_timeout = 120
  136. bulk_insert_buffer_size = 8M
  137. myisam_sort_buffer_size = 8M
  138. myisam_max_sort_file_size = 10G
  139. interactive_timeout = 28800
  140. wait_timeout = 28800
  141. [mysqldump]
  142. quick
  143. max_allowed_packet = 500M
  144. [myisamchk]
  145. key_buffer_size = 8M
  146. sort_buffer_size = 8M
  147. read_buffer = 4M
  148. write_buffer = 4M
  149. EOF
  150. sed -i "s@max_connections.*@max_connections = $((${Mem}/3))@" /etc/my.cnf
  151. if [ ${Mem} -gt 1500 -a ${Mem} -le 2500 ]; then
  152. sed -i 's@^thread_cache_size.*@thread_cache_size = 16@' /etc/my.cnf
  153. sed -i 's@^myisam_sort_buffer_size.*@myisam_sort_buffer_size = 16M@' /etc/my.cnf
  154. sed -i 's@^key_buffer_size.*@key_buffer_size = 16M@' /etc/my.cnf
  155. sed -i 's@^innodb_buffer_pool_size.*@innodb_buffer_pool_size = 128M@' /etc/my.cnf
  156. sed -i 's@^tmp_table_size.*@tmp_table_size = 32M@' /etc/my.cnf
  157. sed -i 's@^table_open_cache.*@table_open_cache = 256@' /etc/my.cnf
  158. elif [ ${Mem} -gt 2500 -a ${Mem} -le 3500 ]; then
  159. sed -i 's@^thread_cache_size.*@thread_cache_size = 32@' /etc/my.cnf
  160. sed -i 's@^myisam_sort_buffer_size.*@myisam_sort_buffer_size = 32M@' /etc/my.cnf
  161. sed -i 's@^key_buffer_size.*@key_buffer_size = 64M@' /etc/my.cnf
  162. sed -i 's@^innodb_buffer_pool_size.*@innodb_buffer_pool_size = 512M@' /etc/my.cnf
  163. sed -i 's@^tmp_table_size.*@tmp_table_size = 64M@' /etc/my.cnf
  164. sed -i 's@^table_open_cache.*@table_open_cache = 512@' /etc/my.cnf
  165. elif [ ${Mem} -gt 3500 ]; then
  166. sed -i 's@^thread_cache_size.*@thread_cache_size = 64@' /etc/my.cnf
  167. sed -i 's@^myisam_sort_buffer_size.*@myisam_sort_buffer_size = 64M@' /etc/my.cnf
  168. sed -i 's@^key_buffer_size.*@key_buffer_size = 256M@' /etc/my.cnf
  169. sed -i 's@^innodb_buffer_pool_size.*@innodb_buffer_pool_size = 1024M@' /etc/my.cnf
  170. sed -i 's@^tmp_table_size.*@tmp_table_size = 128M@' /etc/my.cnf
  171. sed -i 's@^table_open_cache.*@table_open_cache = 1024@' /etc/my.cnf
  172. fi
  173. ${percona_install_dir}/bin/mysqld --initialize-insecure --user=mysql --basedir=${percona_install_dir} --datadir=${percona_data_dir}
  174. [ "${Wsl}" == true ] && chmod 600 /etc/my.cnf
  175. chown mysql:mysql -R ${percona_data_dir}
  176. [ -d "/etc/mysql" ] && /bin/mv /etc/mysql{,_bk}
  177. service mysqld start
  178. [ -z "$(grep ^'export PATH=' /etc/profile)" ] && echo "export PATH=${percona_install_dir}/bin:\$PATH" >> /etc/profile
  179. [ -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
  180. . /etc/profile
  181. ${percona_install_dir}/bin/mysql -uroot -hlocalhost -e "create user root@'127.0.0.1' identified by \"${dbrootpwd}\";"
  182. ${percona_install_dir}/bin/mysql -uroot -hlocalhost -e "grant all privileges on *.* to root@'127.0.0.1' with grant option;"
  183. ${percona_install_dir}/bin/mysql -uroot -hlocalhost -e "grant all privileges on *.* to root@'localhost' with grant option;"
  184. ${percona_install_dir}/bin/mysql -uroot -hlocalhost -e "alter user root@'localhost' identified by \"${dbrootpwd}\";"
  185. ${percona_install_dir}/bin/mysql -uroot -p${dbrootpwd} -e "reset master;"
  186. rm -rf /etc/ld.so.conf.d/{mysql,mariadb,percona}*.conf
  187. [ -e "${percona_install_dir}/my.cnf" ] && rm -f ${percona_install_dir}/my.cnf
  188. echo "${percona_install_dir}/lib" > /etc/ld.so.conf.d/z-percona.conf
  189. ldconfig
  190. service mysqld stop
  191. }