日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Linux下使用MaxScale實現(xiàn)數(shù)據(jù)庫讀寫分離

MaxScale是maridb開發(fā)的一個mysql數(shù)據(jù)中間件,其配置簡單,能夠?qū)崿F(xiàn)讀寫分離,并且可以根據(jù)主從狀態(tài)實現(xiàn)寫庫的自動切換,本篇文章重點為大家講解一下Linux下使用MaxScale實現(xiàn)數(shù)據(jù)庫讀寫分離。

創(chuàng)新互聯(lián)公司專注于潮州網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗。 熱誠為您提供潮州營銷型網(wǎng)站建設(shè),潮州網(wǎng)站制作、潮州網(wǎng)頁設(shè)計、潮州網(wǎng)站官網(wǎng)定制、微信小程序服務(wù),打造潮州網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供潮州網(wǎng)站排名全網(wǎng)營銷落地服務(wù)。

操作系統(tǒng):CentOS Linux release 7.3.1611 (Core)

數(shù)據(jù)庫:MariaDB-10.2.6-linux-glibc_214-x86_64

MaxScale服務(wù)器:10.200.10.55

主服務(wù)器:172.16.8.56

從服務(wù)器:172.16.8.57

從服務(wù)器:172.16.8.58

1.maxscale的安裝方式有很多,例如源碼安裝、rpm、二進(jìn)制構(gòu)建等,我選擇二進(jìn)制進(jìn)行安裝。

根據(jù)場景需要下載相對應(yīng)的版本,下載地址;https://mariadb.com/downloads/maxscale

   [root@localhost ~]# groupadd maxscale
   [root@localhost ~]# useradd -g maxscale maxscale
   [root@localhost ~]# cd /usr/local
   [root@localhost local]# wget https://downloads.mariadb.com/MaxScale/2.1.3/centos/7server/x86_64/maxscale-2.1.3.centos.7.tar.gz
   [root@localhost local]# tar zxvf maxscale-2.1.3.centos.7.tar.gz
   [root@localhost local]# ln -s maxscale-2.1.3.centos.7 maxscale
   [root@localhost local]# cd maxscale
   [root@zhu56 maxscale]# chown -R maxscale var

建議創(chuàng)建軟連接,這樣有助于以后的版本升級及后期維護(hù)。

2.首次安裝maxscale需要創(chuàng)建日志相關(guān)目錄

   [root@localhost ~]# mkdir /var/log/maxscale
   [root@localhost ~]# mkdir /var/lib/maxscale
   [root@localhost ~]# mkdir /var/run/maxscale
   [root@localhost ~]# mkdir /var/cache/maxscale

3.以下目錄必須具備maxscala用戶權(quán)限

   [root@localhost ~]# chown maxscale /var/log/maxscale
   [root@localhost ~]# chown maxscale /var/lib/maxscale
   [root@localhost ~]# chown maxscale /var/run/maxscale
   [root@localhost ~]# chown maxscale /var/cache/maxscale

4.為了能讓Maxscale能順利啟動,還需要創(chuàng)建配置文件,在Maxscale目錄下有配置文件模板拷貝到etc下即可。

    [root@localhost ~]# cp /usr/local/maxscale/etc/maxscale.cnf.template /etc/maxscale.cnf

5.在修改配置文件之前,需要在主服務(wù)器上創(chuàng)建一個用戶并給予授權(quán),而這個用戶用于MySQL監(jiān)控、路由功能

   MariaDB [(none)]> create user 'jiankongdb'@'%' identified by 'jiankong123';
   MariaDB [(none)]> grant SELECT on mysql.user to 'jiankongdb'@'%';
   MariaDB [(none)]> GRANT SELECT ON mysql.db TO 'jiankongdb'@'%';
   MariaDB [(none)]> GRANT SELECT ON mysql.tables_priv TO 'jiankongdb'@'%';
   MariaDB [(none)]> GRANT SHOW DATABASES ON *.* TO 'jiankongdb'@'%';
   MariaDB [(none)]> grant REPLICATION CLIENT on *.* to 'jiankongdb'@'%';

   MariaDB [(none)]> GRANT replication slave, replication client,SELECT ON *.* TO jiankongdb@'%';

6.查看授權(quán)情況

    MariaDB [(none)]> SHOW GRANTS FOR'jiankong'@'%';

7.接下來就開始修改maxscale.cnf配置文件,否則無法啟動。

   [root@localhost ~]# vim /etc/maxscale.cnf

   # MaxScale documentation on GitHub:
   # https://github.com/mariadb-corporation/MaxScale/blob/2.1/Documentation/Documentation-Contents.md

   # Global parameters
   #
   # Complete list of configuration options:
   # https://github.com/mariadb-corporation/MaxScale/blob/2.1/Documentation/Getting-Started/Configuration-Guide.md
   #全局配置
   [maxscale]
   threads=1

   # Server definitions
   #
   # Set the address of the server to the network
   # address of a MySQL server.
   #

   [server1]
   type=server
   address=172.16.8.56
   port=3306
   protocol=MySQLBackend
   serv_weight=1

   [server2]
   type=server
   address=172.16.8.57
   port=3306
   protocol=MySQLBackend
   serv_weight=3

   [server3]
   type=server
   address=172.16.8.58
   port=3306
   protocol=MySQLBackend
   serv_weight=3


   # Monitor for the servers
   #
   # This will keep MaxScale aware of the state of the servers.
   # MySQL Monitor documentation:
   # https://github.com/mariadb-corporation/MaxScale/blob/2.1/Documentation/Monitors/MySQL-Monitor.md
   #MariaDB狀態(tài)監(jiān)控
   [MySQL Monitor]
   type=monitor
   module=mysqlmon
   servers=server1,server2,server3
   user=jiankong
   passwd=jiankong123
   monitor_interval=10000
   detect_stale_master=true #即使從全掛掉,保證主擔(dān)任讀寫

   # Service definitions
   #
   # Service Definition for a read-only service and
   # a read/write splitting service.
   #

   # ReadConnRoute documentation:
   # https://github.com/mariadb-corporation/MaxScale/blob/2.1/Documentation/Routers/ReadConnRoute.md
   #讀
   [Read-Only Service]
   type=service
   router=readconnroute
   servers=server1,server2,server3
   user=jiankong
   passwd=jiankong123
   router_options=slave
   enable_root_user=1 #允許root用戶登錄執(zhí)行
   weightby=serv_weight #主從權(quán)重

   # ReadWriteSplit documentation:
   # https://github.com/mariadb-corporation/MaxScale/blob/2.1/Documentation/Routers/ReadWriteSplit.md
   #寫
   [Read-Write Service]
   type=service
   router=readwritesplit
   servers=server1,server2,server3
   user=jiankong
   passwd=jiankong123
   max_slave_connections=100%
   use_sql_variables_in=master #保證會話的一致性
   enable_root_user=1 #允許root登錄
   max_slave_replication_lag=3600 #允許從超出主的同步時間,超出則不路由

   # This service enables the use of the MaxAdmin interface
   # MaxScale administration guide:
   # https://github.com/mariadb-corporation/MaxScale/blob/2.1/Documentation/Reference/MaxAdmin.md

   [MaxAdmin Service]
   type=service
   router=cli

   # Listener definitions for the services
   #
   # These listeners represent the ports the
   # services will listen on.
   #

   [Read-Only Listener]
   type=listener
   service=Read-Only Service
   protocol=MySQLClient
   port=4008

   [Read-Write Listener]
   type=listener
   service=Read-Write Service
   protocol=MySQLClient
   port=4006

   [MaxAdmin Listener]
   type=listener
   service=MaxAdmin Service
   protocol=maxscaled
   socket=default

保存并退出。 8.下面創(chuàng)建啟動腳本

   [root@localhost ~]# cp /usr/local/maxscale-2.1.3.centos.7/share/maxscale.service /usr/lib/systemd/system/
   [root@localhost ~]# vim /usr/lib/systemd/system/maxscale.service

9.修改maxscale.service中的ExecStart=///bin/maxscale為ExecStart=/usr/local/maxscale/bin/maxscale

   [root@localhost ~]# chmod 755 /usr/lib/systemd/system/maxscale.service
   [root@localhost ~]# systemctl enable maxscale
   [root@localhost ~]# systemctl daemon-reload
   [root@localhost ~]# systemctl start maxscale

10.添加變量值

   [root@localhost ~]# vi /etc/profile //最后一行添加以下內(nèi)容保存退出!

   PATH=$PATH:/usr/local/maxscale/bin
   export PATH

   [root@localhost ~]# source /etc/profile //使其變量立即生效

11.接下來就可以使用MaxAdmin進(jìn)行管理。MaxAdmin是一個簡單的客戶端管理界面,可用于與MariaDB MaxScale服務(wù)器進(jìn)行交互,可以顯示MariaDB MaxScale內(nèi)部的統(tǒng)計信息狀態(tài)以及對MariaDB MaxScale操作的控制。詳情: https://mariadb.com/kb/en/mariadb-enterprise/maxadmin-admin-interface/

   [root@localhost ~]# maxadmin //回車
   MaxScale> list servers
   Servers.
   ---------------+--------------+-------+-------------+-----------------
   Server | Address | Port | Connections | Status
   ---------------+--------------+-------+-------------+-----------------
   server1 | 172.16.8.56 | 3306 | 0 | Master, Running
   server2 | 172.16.8.57 | 3306 | 0 | Slave, Running
   server2 | 172.16.8.58 | 3306 | 0 | Slave, Running
   ---------------+--------------+-------+-------------+-----------------

12.至此MaxScale已經(jīng)配置完成?,F(xiàn)在就可以使用客戶端連接Maxscale服務(wù)器端 端口為4006。


名稱欄目:Linux下使用MaxScale實現(xiàn)數(shù)據(jù)庫讀寫分離
文章源于:http://m.5511xx.com/article/cohpsce.html