[跟我學中小企業架構部署]之三:數據庫多實例部署

DB1  DB2 部署
所需軟件:
mysql-5.0.56.tar.gz

安裝mysql

  1. cd /root/tools 

創建mysql帳號:

  1. groupadd mysql 
  2. useradd -g mysql -M -s /sbin/nologin mysql 
  3. tar zxvf mysql-5.0.56.tar.gz 
  4. cd mysql-5.0.56 
  5. ./configure \ 
  6. --prefix=/usr/local/mysql \ 
  7. --enable-assembler \ 
  8. --with-extra-charsets=complex \ 
  9. --enable-thread-safe-client \ 
  10. --with-big-tables \ 
  11. --with-readline \ 
  12. --with-ssl \ 
  13. --with-embedded-server \ 
  14. --enable-local-infile \ 
  15. --with-plugins=partition,innobase \ 
  16. --with-plugin-PLUGIN \ 
  17. --with-mysqld-ldflags=-all-static \ 
  18. --with-client-ldflags=-all-static 
  19. make && make install 
  20. cd .. 

創建數據目錄

  1. mkdir -p /data/3306/data 
  2. mkdir -p /data/3307/data 
  3. chown -R mysql:mysql /data/3306 
  4. chown -R mysql:mysql /data/3307 
建立3306,3307 my.cnf配置文件

  1. vi /data/3306/my.cnf 
  2. vi /data/3307/my.cnf 

my.cnf內容:(3307 my.cnf就是3306 批量替換3307就好)

  1. #/data/3306/my.cnf 
  2. [client] 
  3. port            = 3306 
  4. socket          = /data/3306/mysql.sock 
  5. [mysql] 
  6. no-auto-rehash 
  7.  
  8. [mysqld] 
  9. user    = mysql 
  10. port    = 3306 
  11. socket  = /data/3306/mysql.sock 
  12. basedir = /usr/local/mysql 
  13. datadir = /data/3306/data 
  14. open_files_limit    = 1024 
  15. back_log = 600 
  16. max_connections = 800 
  17. max_connect_errors = 3000 
  18. table_cache = 614 
  19. external-locking = FALSE 
  20. max_allowed_packet =8M 
  21. sort_buffer_size = 1M 
  22. join_buffer_size = 1M 
  23. thread_cache_size = 100 
  24. thread_concurrency = 2 
  25. query_cache_size = 2M 
  26. query_cache_limit = 1M 
  27. query_cache_min_res_unit = 2k 
  28. default_table_type = InnoDB 
  29. thread_stack = 192K 
  30. transaction_isolation = READ-COMMITTED 
  31. tmp_table_size = 2M 
  32. max_heap_table_size = 2M 
  33. long_query_time = 1 
  34. log_long_format 
  35. log-bin=mysql3306-bin 
  36. binlog_cache_size = 1M 
  37. max_binlog_cache_size = 1M 
  38. max_binlog_size = 2M 
  39. expire_logs_days = 7 
  40. key_buffer_size = 16M 
  41. read_buffer_size = 1M 
  42. read_rnd_buffer_size = 1M 
  43. bulk_insert_buffer_size = 1M 
  44. myisam_sort_buffer_size = 1M 
  45. myisam_max_sort_file_size = 10G 
  46. myisam_max_extra_sort_file_size = 10G 
  47. myisam_repair_threads = 1 
  48. myisam_recover 
  49. lower_case_table_names = 1 
  50. interactive_timeout = 60 
  51. wait_timeout = 60 
  52. server-id = 1 
  53.  
  54. innodb_additional_mem_pool_size = 4M 
  55. innodb_buffer_pool_size = 32M 
  56. innodb_data_file_path = ibdata1:128M:autoextend 
  57. innodb_file_io_threads = 4 
  58. innodb_thread_concurrency = 8 
  59. innodb_flush_log_at_trx_commit = 2 
  60. innodb_log_buffer_size = 2M 
  61. innodb_log_file_size = 4M 
  62. innodb_log_files_in_group = 3 
  63. innodb_max_dirty_pages_pct = 90 
  64. innodb_lock_wait_timeout = 120 
  65. innodb_file_per_table = 0 
  66. [mysqldump] 
  67. quick 
  68. max_allowed_packet = 2M 
  69.  
  70. [mysqld_safe] 
  71. log-error=/data/3306/mysql_err.log 
  72. pid-file=/data/3306/mysqld.pid 

批量替換方法:

  1. sed -i "s/3306/3307/g"  /data/3306/my.cnf  >/data/3307/my.cnf 

改變my.cnf配置文件的所有權

  1. chown -R mysql:mysql /data/3306/my.cnf 
  2. chown -R mysql:mysql /data/3307/my.cnf 

建立mysql啓動腳本

  1. vi /data/3306/mysql 
  2. vi /data/3307/mysql 

mysql 內容: (3307的mysql需把port改爲3307)

啓動數據庫

  1. /data/3306/mysql start 
  2. /data/3307/mysql start 

添加爲系統自啓動

  1. echo "/data/3306/mysql start" >>/etc/rc.local 
  2. echo "/data/3307/mysql start" >>/etc/rc.local 

用 netstat –ant 命令查看mysql端口,若看到下圖標記的端口,即MYSQL安裝成功!

訪問方法(安裝完初始無密碼):

 
  1. mysql -uroot -p -S /data/3306/mysql.sock 
  2. mysql -uroot -p -S /data/3307/mysql.sock 

更改root密碼

  1. /usr/local/mysql/bin/mysqladmin -u root password 'elain' -S /data/3306/mysql.sock 
  2. /usr/local/mysql/bin/mysqladmin -u root password 'elain' -S /data/3307/mysql.sock 

登錄MYSQL

  1. mysql -uroot -p -S /data/3306/mysql.sock 
  2. mysql -uroot -p -S /data/3307/mysql.sock 

清理掉系統默認(標記的)的多餘的mysql用戶 3306,3307

  1. select user,host from mysql.user; 

 刪除無用帳號

  1. drop user ''@'db1'; 
  2. drop user ''@'localhost'; 
  3. drop user 'root'@'db1'; 

3307同理
處理後結果:
 

到此,MYSQL 安裝完成,DB1 DB2上安裝完全相同!!

轉載請註明: 轉載自http://www.elain.org

本文鏈接地址:[跟我學中小企業架構部署]之三:數據庫多實例部署

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章