1
0

alisql-5.6.sh 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. #!/bin/bash
  2. # Author: yeho <lj2007331 AT gmail.com>
  3. # BLOG: https://linuxeye.com
  4. #
  5. # Notes: OneinStack for CentOS/RedHat 6+ Debian 8+ and Ubuntu 14+
  6. #
  7. # Project home page:
  8. # https://oneinstack.com
  9. # https://github.com/oneinstack/oneinstack
  10. Install_AliSQL56() {
  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 "${alisql_install_dir}" ] && mkdir -p ${alisql_install_dir}
  15. mkdir -p ${alisql_data_dir};chown mysql.mysql -R ${alisql_data_dir}
  16. tar xzf alisql-${alisql_ver}.tar.gz
  17. pushd alisql-${alisql_ver}
  18. cmake . -DCMAKE_INSTALL_PREFIX=${alisql_install_dir} \
  19. -DCMAKE_BUILD_TYPE="Release" \
  20. -DWITH_EMBEDDED_SERVER=0 \
  21. -DWITH_EXTRA_CHARSETS=all \
  22. -DWITH_MYISAM_STORAGE_ENGINE=1 \
  23. -DWITH_INNOBASE_STORAGE_ENGINE=1 \
  24. -DWITH_PARTITION_STORAGE_ENGINE=1 \
  25. -DWITH_CSV_STORAGE_ENGINE=1 \
  26. -DWITH_ARCHIVE_STORAGE_ENGINE=1 \
  27. -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
  28. -DWITH_FEDERATED_STORAGE_ENGINE=1 \
  29. -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
  30. -DWITH_TOKUDB_STORAGE_ENGINE=0
  31. make -j ${THREAD}
  32. make install
  33. popd
  34. if [ -d "${alisql_install_dir}/support-files" ]; then
  35. echo never > /sys/kernel/mm/transparent_hugepage/enabled
  36. sed -i "s+^dbrootpwd.*+dbrootpwd='${dbrootpwd}'+" ../options.conf
  37. echo "${CSUCCESS}AliSQL installed successfully! ${CEND}"
  38. rm -rf alisql-${alisql_ver}
  39. else
  40. rm -rf ${alisql_install_dir}
  41. rm -rf alisql-${alisql_ver}
  42. echo "${CFAILURE}AliSQL install failed, Please contact the author! ${CEND}" && lsb_release -a
  43. kill -9 $$
  44. fi
  45. /bin/cp ${alisql_install_dir}/support-files/mysql.server /etc/init.d/mysqld
  46. [ -z "`grep transparent_hugepage /etc/init.d/mysqld`" ] && sed -i "s@^basedir=.*@echo never > /sys/kernel/mm/transparent_hugepage/enabled\n&@" /etc/init.d/mysqld
  47. sed -i "s@^basedir=.*@basedir=${alisql_install_dir}@" /etc/init.d/mysqld
  48. sed -i "s@^datadir=.*@datadir=${alisql_data_dir}@" /etc/init.d/mysqld
  49. chmod +x /etc/init.d/mysqld
  50. [ "${PM}" == 'yum' ] && { chkconfig --add mysqld; chkconfig mysqld on; }
  51. [ "${PM}" == 'apt-get' ] && update-rc.d mysqld defaults
  52. popd
  53. # my.cnf
  54. [ -d "/etc/mysql" ] && /bin/mv /etc/mysql{,_bk}
  55. cat > /etc/my.cnf << EOF
  56. [client]
  57. port = 3306
  58. socket = /tmp/mysql.sock
  59. default-character-set = utf8mb4
  60. [mysql]
  61. prompt="AliSQL [\\d]> "
  62. no-auto-rehash
  63. [mysqld]
  64. port = 3306
  65. socket = /tmp/mysql.sock
  66. basedir = ${alisql_install_dir}
  67. datadir = ${alisql_data_dir}
  68. pid-file = ${alisql_data_dir}/mysql.pid
  69. user = mysql
  70. bind-address = 0.0.0.0
  71. server-id = 1
  72. init-connect = 'SET NAMES utf8mb4'
  73. character-set-server = utf8mb4
  74. skip-name-resolve
  75. #skip-networking
  76. back_log = 300
  77. max_connections = 1000
  78. max_connect_errors = 6000
  79. open_files_limit = 65535
  80. table_open_cache = 128
  81. max_allowed_packet = 500M
  82. binlog_cache_size = 1M
  83. max_heap_table_size = 8M
  84. tmp_table_size = 16M
  85. read_buffer_size = 2M
  86. read_rnd_buffer_size = 8M
  87. sort_buffer_size = 8M
  88. join_buffer_size = 8M
  89. key_buffer_size = 4M
  90. thread_cache_size = 8
  91. query_cache_type = 1
  92. query_cache_size = 8M
  93. query_cache_limit = 2M
  94. ft_min_word_len = 4
  95. log_bin = mysql-bin
  96. binlog_format = mixed
  97. expire_logs_days = 7
  98. log_error = ${alisql_data_dir}/mysql-error.log
  99. slow_query_log = 1
  100. long_query_time = 1
  101. slow_query_log_file = ${alisql_data_dir}/mysql-slow.log
  102. performance_schema = 0
  103. explicit_defaults_for_timestamp
  104. #lower_case_table_names = 1
  105. skip-external-locking
  106. default_storage_engine = InnoDB
  107. innodb_file_per_table = 1
  108. innodb_open_files = 500
  109. innodb_buffer_pool_size = 64M
  110. innodb_write_io_threads = 4
  111. innodb_read_io_threads = 4
  112. innodb_thread_concurrency = 0
  113. innodb_purge_threads = 1
  114. innodb_flush_log_at_trx_commit = 2
  115. innodb_log_buffer_size = 2M
  116. innodb_log_file_size = 32M
  117. innodb_log_files_in_group = 3
  118. innodb_max_dirty_pages_pct = 90
  119. innodb_lock_wait_timeout = 120
  120. bulk_insert_buffer_size = 8M
  121. myisam_sort_buffer_size = 8M
  122. myisam_max_sort_file_size = 10G
  123. myisam_repair_threads = 1
  124. interactive_timeout = 28800
  125. wait_timeout = 28800
  126. [mysqldump]
  127. quick
  128. max_allowed_packet = 500M
  129. [myisamchk]
  130. key_buffer_size = 8M
  131. sort_buffer_size = 8M
  132. read_buffer = 4M
  133. write_buffer = 4M
  134. EOF
  135. sed -i "s@max_connections.*@max_connections = $((${Mem}/3))@" /etc/my.cnf
  136. if [ ${Mem} -gt 1500 -a ${Mem} -le 2500 ]; then
  137. sed -i 's@^thread_cache_size.*@thread_cache_size = 16@' /etc/my.cnf
  138. sed -i 's@^query_cache_size.*@query_cache_size = 16M@' /etc/my.cnf
  139. sed -i 's@^myisam_sort_buffer_size.*@myisam_sort_buffer_size = 16M@' /etc/my.cnf
  140. sed -i 's@^key_buffer_size.*@key_buffer_size = 16M@' /etc/my.cnf
  141. sed -i 's@^innodb_buffer_pool_size.*@innodb_buffer_pool_size = 128M@' /etc/my.cnf
  142. sed -i 's@^tmp_table_size.*@tmp_table_size = 32M@' /etc/my.cnf
  143. sed -i 's@^table_open_cache.*@table_open_cache = 256@' /etc/my.cnf
  144. elif [ ${Mem} -gt 2500 -a ${Mem} -le 3500 ]; then
  145. sed -i 's@^thread_cache_size.*@thread_cache_size = 32@' /etc/my.cnf
  146. sed -i 's@^query_cache_size.*@query_cache_size = 32M@' /etc/my.cnf
  147. sed -i 's@^myisam_sort_buffer_size.*@myisam_sort_buffer_size = 32M@' /etc/my.cnf
  148. sed -i 's@^key_buffer_size.*@key_buffer_size = 64M@' /etc/my.cnf
  149. sed -i 's@^innodb_buffer_pool_size.*@innodb_buffer_pool_size = 512M@' /etc/my.cnf
  150. sed -i 's@^tmp_table_size.*@tmp_table_size = 64M@' /etc/my.cnf
  151. sed -i 's@^table_open_cache.*@table_open_cache = 512@' /etc/my.cnf
  152. elif [ ${Mem} -gt 3500 ]; then
  153. sed -i 's@^thread_cache_size.*@thread_cache_size = 64@' /etc/my.cnf
  154. sed -i 's@^query_cache_size.*@query_cache_size = 64M@' /etc/my.cnf
  155. sed -i 's@^myisam_sort_buffer_size.*@myisam_sort_buffer_size = 64M@' /etc/my.cnf
  156. sed -i 's@^key_buffer_size.*@key_buffer_size = 256M@' /etc/my.cnf
  157. sed -i 's@^innodb_buffer_pool_size.*@innodb_buffer_pool_size = 1024M@' /etc/my.cnf
  158. sed -i 's@^tmp_table_size.*@tmp_table_size = 128M@' /etc/my.cnf
  159. sed -i 's@^table_open_cache.*@table_open_cache = 1024@' /etc/my.cnf
  160. fi
  161. ${alisql_install_dir}/scripts/mysql_install_db --user=mysql --basedir=${alisql_install_dir} --datadir=${alisql_data_dir}
  162. [ "${Wsl}" == true ] && chmod 600 /etc/my.cnf
  163. chown mysql.mysql -R ${alisql_data_dir}
  164. [ -d "/etc/mysql" ] && mv /etc/mysql{,_bk}
  165. service mysqld start
  166. [ -z "$(grep ^'export PATH=' /etc/profile)" ] && echo "export PATH=${alisql_install_dir}/bin:\$PATH" >> /etc/profile
  167. [ -n "$(grep ^'export PATH=' /etc/profile)" -a -z "$(grep ${alisql_install_dir} /etc/profile)" ] && sed -i "s@^export PATH=\(.*\)@export PATH=${alisql_install_dir}/bin:\1@" /etc/profile
  168. . /etc/profile
  169. ${alisql_install_dir}/bin/mysql -e "grant all privileges on *.* to root@'127.0.0.1' identified by \"${dbrootpwd}\" with grant option;"
  170. ${alisql_install_dir}/bin/mysql -e "grant all privileges on *.* to root@'localhost' identified by \"${dbrootpwd}\" with grant option;"
  171. ${alisql_install_dir}/bin/mysql -uroot -p${dbrootpwd} -e "delete from mysql.user where Password='';"
  172. ${alisql_install_dir}/bin/mysql -uroot -p${dbrootpwd} -e "delete from mysql.db where User='';"
  173. ${alisql_install_dir}/bin/mysql -uroot -p${dbrootpwd} -e "delete from mysql.proxies_priv where Host!='localhost';"
  174. ${alisql_install_dir}/bin/mysql -uroot -p${dbrootpwd} -e "drop database test;"
  175. ${alisql_install_dir}/bin/mysql -uroot -p${dbrootpwd} -e "reset master;"
  176. rm -rf /etc/ld.so.conf.d/{mysql,mariadb,percona,alisql}*.conf
  177. [ -e "${alisql_install_dir}/my.cnf" ] && rm -rf ${alisql_install_dir}/my.cnf
  178. echo "${alisql_install_dir}/lib" > /etc/ld.so.conf.d/z-alisql.conf
  179. ldconfig
  180. service mysqld stop
  181. }