成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

通過Atlas實現MySQL讀寫分離

數據庫 MySQL
最近公司項目要求MySQL高可用,加上以前公司聽過QiHoo360的Atlas,所以就嘗試搭建了一個MySQL讀寫分離,并且高可用的。

通過Atlas實現MySQL讀寫分離

前期準備

  1. 準備4臺機器,系統為CentOS release 6.6
  2. Ip分別為192.168.20.121、192.168.20.122、192.168.20.123、192.168.20.124
  3. 4臺機器分別作為Atlas代理服務,master MySQL,slave MySQL 1,slave MySQL 2
  4. 下載QiHoo360的Atlas 地址

安裝Atlas

  • 下載得到Atlas-XX.el6.x86_64.rpm安裝文件
  • sudo rpm –i Atlas-XX.el6.x86_64.rpm安裝
  • 安裝在/usr/local/mysql-proxy
  • 安裝目錄分析
    • bin
      • 可執行文件
      • encrypt用來加密密碼,后面會用到
      • mysql-proxy是MySQL自己的讀寫分離代理
      • mysql-proxyd操作Atlas
      • VERSION
    • conf
      • test.cnf配置文件
      • 一個文件為一個實例,實例名即文件名,啟動需要帶上這個實例名
    • lib依賴包
    • log記錄日志
  • 啟動命令:/usr/local/mysql-proxy/bin/mysql-proxyd [實例名] start
  • 停止命令:/usr/local/mysql-proxy/bin/mysql-proxyd [實例名] stop
  • 同理,restart為重啟,status為查看狀態
  • 配置文件解釋

請查看官方文檔

數據庫配置

1.1臺master2臺slave,都要配置相同的用戶名密碼,且都要可以遠程訪問

2.分別進入3臺服務器,創建相同的用戶名密碼,創建數據庫test,設置權限

  1. CREATE USER 'test'@'%' IDENTIFIED BY 'test123'
  2. CREATE USER 'test'@'localhost' IDENTIFIED BY 'test123'
  3. grant all privileges on test.* to 'test'@'%' identified by 'test123'
  4. grant all privileges on test.* to 'test'@'localhost' identified by 'test123'
  5. flush privileges 

3.主從數據庫配置

    1.配置master服務器

  • 找到MySQL配置文件my.cnf,一般在etc目錄下
  • 修改配置文件 
  1. [mysqld] 
  2.  # 一些其他配置 
  3.  ...  
  4.  
  5.  #主從復制配置   
  6.  innodb_flush_log_at_trx_commit=1   
  7.  sync_binlog=1   
  8.  #需要備份的數據庫 
  9.  binlog-do-db=test 
  10.  #不需要備份的數據庫 
  11.  binlog-ignore-db=mysql   
  12.  
  13.  #啟動二進制文件   
  14.  log-bin=mysql-bin   
  15.  
  16.  #服務器ID   
  17.  server-id=1   
  18.  
  19.  # Disabling symbolic-links is recommended to prevent assorted security risks   
  20.  symbolic-links=0  
  • 重啟數據庫service mysql restart
  • 進入數據庫,配置主從復制的權限
  1. mysql -uroot -p123456 
  2.  grant replication slave on *.* to 'test'@'127.0.0.1' identified by 'test123' 
  • 查看主數據庫信息,記住下面的File與Position的信息,它們是用來配置從數據庫的關鍵信息。 
  1. mysql> show master status; 
  2.   +------------------+----------+--------------+------------------+ 
  3.   | File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | 
  4.   +------------------+----------+--------------+------------------+ 
  5.   | mysql-bin.000002 | 17620976 | test         | mysql            | 
  6.   +------------------+----------+--------------+------------------+ 
  7.   1 row in set (0.00 sec)  

    2.配置兩臺salve服務器

  • 找到配置文件my.cnf
  • 修改配置文件如下
  1. [mysqld] 
  2.   # 一些其他配置 
  3.   ...  
  4.  
  5.   # 幾臺服務器不能一樣 
  6.   server-id=2 
  7.  
  8.   # Disabling symbolic-links is recommended to prevent assorted security risks 
  9.   symbolic-links=0  
  • 進入數據庫,配置從數據庫的信息,這里輸入剛才記錄下來的File與Position的信息,并且在從服務器上執行(執行的時候,#行不要復制進去):
  1. # master數據庫的ip 
  2.  mysql> change master to master_host='192.168.20.122'
  3.        # master的用戶名 
  4.             master_user='buck'
  5.            # 密碼 
  6.             master_password='hello'
  7.            # 端口 
  8.             master_port=3306, 
  9.            # master數據庫的`File ` 
  10.             master_log_file='mysql-bin.000002'
  11.            # master數據庫的`Position` 
  12.             master_log_pos=17620976, 
  13.             master_connect_retry=10;  
  • 啟動進程
  1. mysql> start slave; 
  2.  
  3. Query OK, 0 rows affected (0.00 sec)  
  • 檢查主從復制狀態,要看到下列Slave_IO_Running、Slave_SQL_Running的信息中,兩個都是Yes,才說明主從連接正確,如果有一個是No,需要重新確定剛才記錄的日志信息,停掉“stop slave”重新進行配置主從連接。
  1. mysql> show slave status \G; 
  2.   *************************** 1. row *************************** 
  3.                  Slave_IO_State: Waiting for master to send event 
  4.                     Master_Host: 192.168.246.134 
  5.                     Master_User: buck 
  6.                     Master_Port: 3306 
  7.                   Connect_Retry: 10 
  8.                 Master_Log_File: mysql-bin.000002 
  9.             Read_Master_Log_Pos: 17620976 
  10.                  Relay_Log_File: mysqld-relay-bin.000002 
  11.                   Relay_Log_Pos: 251 
  12.           Relay_Master_Log_File: mysql-bin.000002 
  13.                Slave_IO_Running: Yes 
  14.               Slave_SQL_Running: Yes 
  15.                 Replicate_Do_DB:  
  16.             Replicate_Ignore_DB:  
  17.              Replicate_Do_Table:  
  18.          Replicate_Ignore_Table:  
  19.         Replicate_Wild_Do_Table:  
  20.     Replicate_Wild_Ignore_Table:  
  21.                      Last_Errno: 0 
  22.                      Last_Error:  
  23.                    Skip_Counter: 0 
  24.             Exec_Master_Log_Pos: 17620976 
  25.                 Relay_Log_Space: 407 
  26.                 Until_Condition: None 
  27.                  Until_Log_File:  
  28.                   Until_Log_Pos: 0 
  29.              Master_SSL_Allowed: No 
  30.              Master_SSL_CA_File:  
  31.              Master_SSL_CA_Path:  
  32.                 Master_SSL_Cert:  
  33.               Master_SSL_Cipher:  
  34.                  Master_SSL_Key:  
  35.           Seconds_Behind_Master: 0 
  36.   Master_SSL_Verify_Server_Cert: No 
  37.                   Last_IO_Errno: 0 
  38.                   Last_IO_Error:  
  39.                  Last_SQL_Errno: 0 
  40.                  Last_SQL_Error:  
  41.   1 row in set (0.00 sec) 
  42.  
  43.   ERROR:  
  44.   No query specified  

Atlas配置

1.使用Atlas的加密工具對上面用戶的密碼進行加密

  1. /usr/local/mysql-proxy/bin/encrypt test123 
  2.  
  3. 29uENYYsKLo=  

2.配置atlas

  • 這是用來登錄到Atlas的管理員的賬號與密碼,與之對應的是Atlas監聽的管理接口IP和端口,也就是說需要設置管理員登錄的端口,才能進入管理員界面,默認端口是2345,也可以指定IP登錄,指定IP后,其他的IP無法訪問管理員的命令界面。方便測試,我這里沒有指定IP和端口登錄。
  • 配置主數據的地址與從數據庫的地址,這里配置的主數據庫是122,從數據庫是123、124
  1. #Atlas后端連接的MySQL主庫的IP和端口,可設置多項,用逗號分隔 
  2.   proxy-backend-addresses = 192.168.20.122:3306 
  3.   #Atlas后端連接的MySQL從庫的IP和端口,@后面的數字代表權重,用來作負載均衡,若省略則默認為1,可設置多項,用逗號分隔 
  4.   proxy-read-only-backend-addresses = 192.168.20.123:3306[@1](https://my.oschina.net/u/1198),192.168.20.124:3306@2 
  • 這個是用來配置MySQL的賬戶與密碼的,就是上面創建的用戶,用戶名是test,密碼是test123,剛剛使用Atlas提供的工具生成了對應的加密密碼
  1. pwds = buck:RePBqJ+5gI4= 

3.啟動Atlas

  1. [root[@localhost](https://my.oschina.net/u/570656) /usr/local/mysql-proxy/bin]# ./mysql-proxyd test start 
  2.  
  3. OK: MySQL-Proxy of test is started  

測試

1.進入atlas的管理界面

  1. [root[@localhost](https://my.oschina.net/u/570656) ~]#mysql -h127.0.0.1 -P2345 -uuser -ppwd 
  2.  Welcome to the MySQL monitor.  Commands end with ; or \g. 
  3.  Your MySQL connection id is 1 
  4.  Server version: 5.0.99-agent-admin 
  5.  
  6.  Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. 
  7.  
  8.  Oracle is a registered trademark of Oracle Corporation and/or its 
  9.  affiliates. Other names may be trademarks of their respective 
  10.  owners. 
  11.  
  12.  Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. 
  13.  
  14.  mysql> select * from help; 
  15.  +----------------------------+---------------------------------------------------------+ 
  16.  | command                    | description                                             | 
  17.  +----------------------------+---------------------------------------------------------+ 
  18.  | SELECT * FROM help         | shows this help                                         | 
  19.  | SELECT * FROM backends     | lists the backends and their state                      | 
  20.  | SET OFFLINE $backend_id    | offline backend server, $backend_id is backend_ndx's id | 
  21.  | SET ONLINE $backend_id     | online backend server, ...                              | 
  22.  | ADD MASTER $backend        | example: "add master 127.0.0.1:3306", ...               | 
  23.  | ADD SLAVE $backend         | example: "add slave 127.0.0.1:3306", ...                | 
  24.  | REMOVE BACKEND $backend_id | example: "remove backend 1", ...                        | 
  25.  | SELECT * FROM clients      | lists the clients                                       | 
  26.  | ADD CLIENT $client         | example: "add client 192.168.1.2", ...                  | 
  27.  | REMOVE CLIENT $client      | example: "remove client 192.168.1.2", ...               | 
  28.  | SELECT * FROM pwds         | lists the pwds                                          | 
  29.  | ADD PWD $pwd               | example: "add pwd user:raw_password", ...               | 
  30.  | ADD ENPWD $pwd             | example: "add enpwd user:encrypted_password", ...       | 
  31.  | REMOVE PWD $pwd            | example: "remove pwd user", ...                         | 
  32.  | SAVE CONFIG                | save the backends to config file                        | 
  33.  | SELECT VERSION             | display the version of Atlas                            | 
  34.  +----------------------------+---------------------------------------------------------+ 
  35.  16 rows in set (0.00 sec) 
  36.  
  37.  mysql>   

2.使用工作接口來訪問

  1. [root@localhost ~]#mysql -h127.0.0.1 -P1234 -utest -ptest123 
  2.  Welcome to the MySQL monitor.  Commands end with ; or \g. 
  3.  Your MySQL connection id is 34 
  4.  Server version: 5.0.81-log MySQL Community Server (GPL) 
  5.  
  6.  Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. 
  7.  
  8.  Oracle is a registered trademark of Oracle Corporation and/or its 
  9.  affiliates. Other names may be trademarks of their respective 
  10.  owners. 
  11.  
  12.  Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. 
  13.  
  14.  mysql> show databases; 
  15.  +--------------------+ 
  16.  | Database           | 
  17.  +--------------------+ 
  18.  | information_schema | 
  19.  | mysql              | 
  20.  | performance_schema | 
  21.  | test               | 
  22.  +--------------------+ 
  23.  4 rows in set (0.00 sec) 
  24.  
  25.  mysql>   

使用可視化管理工具Navicat登錄

使用用戶名test、密碼test123、端口1234、地址192.168.20.121正常登錄。注意,這里登錄的是atlas服務器,不再是任何一個MySQL服務器 

責任編輯:龐桂玉 來源: Crazy_Coder的博客
相關推薦

2017-05-25 10:22:13

NoSQL數據庫主主備份

2009-05-04 09:13:52

PHPMySQL讀寫分離

2021-06-25 10:05:58

SpringBootMySQL數據庫

2011-08-30 09:59:47

Mysql ProxyLUA

2021-09-08 10:23:08

讀寫分離Java數據庫

2020-04-23 15:08:41

SpringBootMyCatJava

2022-04-25 08:03:57

MySQL中間件MyCat

2020-03-24 14:16:18

ProxySQLMySQL數據庫

2010-05-17 11:19:44

MySQL proxy

2020-12-08 06:17:11

MycatMySQL分離

2011-08-30 12:49:59

Mysql ProxyLua分離

2020-11-24 09:56:12

數據源讀寫分離

2019-05-13 15:00:14

MySQLMyCat數據庫

2025-01-24 08:38:47

2019-09-30 09:19:54

Redis分離云數據庫

2017-11-24 17:20:37

數據庫數據倉庫讀寫分離

2018-10-16 16:45:05

數據庫讀寫分離

2011-08-30 13:08:55

Mysql ProxyLua分離

2021-03-08 08:16:42

MySQL分離架構

2018-04-08 15:20:15

數據庫MySQL主從復制
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 看av电影 | 91麻豆精品国产91久久久久久久久 | 国产高清精品一区二区三区 | 美女午夜影院 | 日韩欧美三级在线 | 精品一区国产 | 在线国产视频 | www.日日操| 亚洲高清免费 | 国产精品无码专区在线观看 | 黄色视频a级毛片 | 欧美一级淫片免费视频黄 | 成人免费日韩 | 欧美一区二区三区视频在线观看 | 奇米av| 成人精品毛片国产亚洲av十九禁 | 成年女人免费v片 | 日本精品视频 | 久久午夜剧场 | 色接久久 | 久久久久久久久久久久亚洲 | 精品国产欧美日韩不卡在线观看 | 一级高清免费毛片 | 国产精品国产自产拍高清 | 视频一区二区在线观看 | 精品一区二区免费视频 | 91麻豆精品国产91久久久久久久久 | 九九热视频这里只有精品 | 国产精品久久久久久久久久久久冷 | 91在线看| 欧美日韩中文在线观看 | 中文字幕国产精品 | 日韩 欧美 二区 | 成人黄色在线观看 | 国产成人精品一区二区三区四区 | 成人欧美一区二区三区在线播放 | 在线播放一区二区三区 | 国产欧美在线 | 日韩在线播放中文字幕 | 欧美黄在线观看 | 久久网亚洲 |