亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

MySQL數(shù)據(jù)讀寫分離MaxScale相關(guān)配置

瀏覽:9日期:2023-06-28 19:41:17
目錄一、概念:二、實(shí)現(xiàn)讀寫分離的拓?fù)鋱D:三、MaxScale相關(guān)配置:四、讀寫分離的配置流程:五、實(shí)操:第一步:配置Mysql服務(wù)器一主一從第二步:配置代理服務(wù)器(讀寫分離服務(wù)器)第三步:?jiǎn)?dòng)讀寫分離服務(wù)第四步:測(cè)試配置讀寫分離服務(wù)的配置第五步:驗(yàn)證補(bǔ)充說明一、概念:MySQL數(shù)據(jù)讀寫分離是存儲(chǔ)數(shù)據(jù)的一種服務(wù)架構(gòu)執(zhí)行select命令必須連接 slave角色服務(wù)器執(zhí)行insert命令必須連接 maste角色服務(wù)器提供數(shù)據(jù)讀寫分離功能的中間件軟件有: mysql-proxy maxscale mycat拓?fù)浼軜?gòu)只支持一主一從或者一主多從架構(gòu)二、實(shí)現(xiàn)讀寫分離的拓?fù)鋱D:

三、MaxScale相關(guān)配置:指令/路徑/...說明maxscale-2.1.2-1.rhel.7.x86_64.rpm軟件包/etc/maxscale.cnf主配置文件maxscale /etc/maxscale.cnf啟動(dòng)服務(wù)/var/log/maxscale/maxscale.log日志路徑(可查看報(bào)錯(cuò)信息)4006讀寫分離服務(wù)使用端口號(hào)4016管理服務(wù)使用端口號(hào)四、讀寫分離的配置流程:配置Mysql服務(wù)器一主一從配置代理服務(wù)器(讀寫分離服務(wù)器)啟動(dòng)讀寫分離服務(wù)客戶機(jī)50測(cè)試配置讀寫分離服務(wù)的配置五、實(shí)操:第一步:配置Mysql服務(wù)器一主一從把host61配置為master數(shù)據(jù)庫(kù)服務(wù)器[root@host61 ~]# vim /etc/my.cnf[mysqld]Server_id = 61log_bin=master61:wq[root@host61 ~]# systemctl restart mysqld[root@host61 ~]# mysql -uroot –p123qqq...AMysql> grant replication slave on *.* to repluser@'%' identified by '123qqq...A';Mysql> show master status ;+-----------------+----------+--------------+------------------+-------------------+| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |+-----------------+----------+--------------+------------------+-------------------+| master61.000001 | 441 | | | |+-----------------+----------+--------------+------------------+-------------------+1 row in set (0.00 sec)把host62 配置為slave數(shù)據(jù)庫(kù)服務(wù)器[root@host62 ~]# vim /etc/my.cnf[mysqld]Server_id = 62:wq[root@host62 ~]# systemctl restart mysqld[root@host62 ~]# mysql -uroot -p密碼Mysql> change master to master_host='192.168.88.61' ,Master_user='repluser' , Master_password='123qqq...A' ,Master_log_file='master61.000001' ,Master_log_pos=441 ;Mysql> start slave;Mysql> show slave status \G Slave_IO_Running: Yes Slave_SQL_Running: Yes第二步:配置代理服務(wù)器(讀寫分離服務(wù)器)安裝軟件[root@host60 ~]# yum -y install maxscale-2.1.2-1.rhel.7.x86_64.rpm 修改主配置文件[root@host60 ~]# cp /etc/maxscale.cnf /root/ 備份主配置文件[root@host60 ~]# vim /etc/maxscale.cnf[maxscale]threads=auto # 服務(wù)啟動(dòng)后線程的數(shù)量,根據(jù)CPU 核數(shù)創(chuàng)建[server1] type=serveraddress=192.168.88.61 # 指定第1臺(tái)數(shù)據(jù)庫(kù)服務(wù)器的ip地址port=3306protocol=MySQLBackend[server2] type=serveraddress=192.168.88.62 # 指定第2臺(tái)數(shù)據(jù)庫(kù)服務(wù)器的ip地址port=3306protocol=MySQLBackend[MySQL Monitor] # 定義監(jiān)視的數(shù)據(jù)庫(kù)服務(wù)器type=monitormodule=mysqlmonservers=server1,server2 # 監(jiān)視server1和server2user=mysqla # 監(jiān)控用戶賬號(hào)passwd=123qqq...A # 監(jiān)控用戶連接密碼monitor_interval=10000#禁止只讀服務(wù)(注釋)#[Read-Only Service]#type=service#router=readconnroute#servers=server1#user=myuser#passwd=mypwd#router_options=slave[Read-Write Service] # 啟用讀寫分離服務(wù)type=servicerouter=readwritesplitservers=server1,server2 # 讀寫分離在server1和server2服務(wù)器之間進(jìn)行user=mysqlb # 路由用戶passwd=123qqq...A # 連接密碼max_slave_connections=100%[MaxAdmin Service] # 管理服務(wù)(通過訪問管理服務(wù)可以查看監(jiān)控信息)type=servicerouter=cli# 因?yàn)橹蛔x服務(wù)沒有啟用 ,不需要定義服務(wù)使用的端口號(hào)(注釋)#[Read-Only Listener]#type=listener#service=Read-Only Service#protocol=MySQLClient#port=4008[Read-Write Listener] # 定義讀寫分離服務(wù)使用端口號(hào)type=listenerservice=Read-Write Serviceprotocol=MySQLClientport=4006 # 端口號(hào)[MaxAdmin Listener] # 定義管理服務(wù)使用端口號(hào)type=listenerservice=MaxAdmin Serviceprotocol=maxscaledsocket=defaultport=4016 # 端口號(hào):wq配置數(shù)據(jù)庫(kù)服務(wù)器(在數(shù)據(jù)庫(kù)服務(wù)器上添加監(jiān)控用戶和路由用戶)注意:因?yàn)槭侵鲝慕Y(jié)構(gòu) ,所以只需要在主服務(wù)器添加,從服務(wù)器會(huì)自動(dòng)同步[root@host61 ~]# mysql -uroot -p123qqq...A # 添加監(jiān)控用戶 mysqla 用戶mysql> grant replication slave , replication client on *.* to mysqla@'%' identified by '123qqq...A';# 權(quán)限說明:# replication client 監(jiān)視數(shù)據(jù)庫(kù)服務(wù)的運(yùn)行狀態(tài) # replication slave 數(shù)據(jù)庫(kù)服務(wù)器的主從角色 # 添加路由用戶 mysqlb 用戶mysql> grant select on mysql.* to mysqlb@'%' identified by '123qqq...A'; # 對(duì)授權(quán)庫(kù)下的表有查詢權(quán)限# 在從服務(wù)器查看用戶是否同步[root@host62 ~]# mysql -uroot -p123qqq...A select user from mysql.user where user='mysqla';select user from mysql.user where user='mysqlb';第三步:?jiǎn)?dòng)讀寫分離服務(wù)驗(yàn)證數(shù)據(jù)庫(kù)服務(wù)器的授權(quán)用戶 mysqla 和 mysqlb# 安裝提供mysql命令的軟件[root@host60 ~]# which mysql || yum -y install mariadb [root@host60 ~]# mysql -h192.168.88.61 -umysqla -p123qqq...A[root@host60 ~]# mysql -h192.168.88.62 -umysqla -p123qqq...A[root@host60 ~]# mysql -h192.168.88.61 -umysqlb -p123qqq...A[root@host60 ~]# mysql -h192.168.88.62 -umysqlb -p123qqq...A# 說明:能連接成功才是對(duì)的,如果連接失敗:執(zhí)行如下操作# 在主數(shù)據(jù)庫(kù)服務(wù)器host61 把添加 mysqla用戶 和 mysqlb 用戶的命令再執(zhí)行一遍# 啟動(dòng)服務(wù) [root@host60 ~]# maxscale /etc/maxscale.cnf # 查看日志文件[root@host60 ~]# ls /var/log/maxscale/ maxscale.log # 查看讀寫分離服務(wù)端口號(hào)[root@host60 ~]# netstat -utnlp | grep 4006 tcp6 0 0 :::4006 :::* LISTEN 1580/maxscale # 查看讀寫分離服務(wù)端口號(hào)[root@host60 ~]# netstat -utnlp | grep 4016 tcp6 0 0 :::4016 :::*LISTEN 1580/maxscale #把服務(wù)殺死 再啟動(dòng) 相當(dāng)于重啟服務(wù) (修改了配置文件后要重啟服務(wù)使其配置生效)# 通過殺進(jìn)程的方式停止服務(wù) [root@host60 ~]# killall -9 maxscale # 啟動(dòng)服務(wù)[root@host60 ~]# maxscale /etc/maxscale.cnf # 在host60本機(jī)訪問管理服務(wù)查看數(shù)據(jù)庫(kù)服務(wù)的監(jiān)控信息[root@host60 ~]# maxadmin -uadmin -pmariadb -P4016MaxScale> list serversServers.-------------------+-----------------+-------+-------------+--------------------Server | Address | Port | Connections | Status -------------------+-----------------+-------+-------------+--------------------server1 | 192.168.88.61 | 3306 | 0 | Master, Runningserver2 | 192.168.88.62 | 3306 | 0 | Slave, Running-------------------+-----------------+-------+-------------+--------------------MaxScale> exit 排錯(cuò)方法 : 查看日志里的報(bào)錯(cuò)信息 vim /var/log/maxscale/maxscale.log第四步:測(cè)試配置讀寫分離服務(wù)的配置客戶端能夠連接讀寫分離服務(wù)器訪問數(shù)據(jù)庫(kù)服務(wù)# 首先在主數(shù)據(jù)庫(kù)服務(wù)器host61 添加客戶端連接使用的用戶[root@host61 ~]# mysql -uroot -p密碼 create database bbsdb;create table bbsdb.a(id int);grant select,insert on bbsdb.* to yaya@'%' identified by '123qqq...A';# 在從服務(wù)器host62查看存儲(chǔ)數(shù)據(jù)庫(kù)表和添加用戶[root@host62 ~]# mysql -uroot -p密碼desc bbsdb.a;select user from mysql.user where user='yaya';# 客戶端host50連接讀寫分離服務(wù)器host60訪問數(shù)據(jù)庫(kù)服務(wù)mysql -h讀寫分離服務(wù)器的ip -P讀寫分離服務(wù)的端口號(hào) -u數(shù)據(jù)庫(kù)授權(quán)用戶名 -p密碼 [root@host50 ~]# mysql -h192.168.88.60 -P4006 -uyaya -p123qqq...A 連接讀寫分離服務(wù)后,可以對(duì)數(shù)據(jù)做查詢和存儲(chǔ)操作mysql> select * from bbsdb.a;Empty set (0.00 sec)mysql> insert into bbsdb.a values(8888);Query OK, 1 row affected (0.06 sec)mysql> select * from bbsdb.a;+------+| id |+------+| 8888 |+------+1 row in set (0.00 sec)第五步:驗(yàn)證怎么驗(yàn)證查詢select 訪問就在host62從服務(wù)器獲取的數(shù)據(jù)呢?在從服務(wù)本機(jī)向表里添加1條記錄(在從服務(wù)添加的新數(shù)據(jù)主服務(wù)器不會(huì)同步)# 從服務(wù)器插入1條數(shù)據(jù)[root@host62 ~]# mysql -uroot -p123qqq...A -e 'insert into bbsdb.a values(6262)'[root@host62 ~]# mysql -uroot -p123qqq...A -e 'select * from bbsdb.a'mysql: [Warning] Using a password on the command line interface can be insecure.+------+| id |+------+| 8888 || 6262 |+------+# 主服務(wù)器查詢[root@host11 ~]# mysql -uroot -p123qqq...a -e 'select * from bbsdb.a'mysql: [Warning] Using a password on the command line interface can be insecure.+------+| id |+------+| 8888 |+------+# 客戶端訪問讀寫分離服務(wù)器查詢數(shù)據(jù)(查詢結(jié)果為從服務(wù)器數(shù)據(jù)源)[root@host50 ~]# mysql -h192.168.88.60 -P4006 -uyaya -p123qqq...A -e 'select * from bbsdb.a'mysql: [Warning] Using a password on the command line interface can be insecure.+------+| id |+------+| 8888 || 6262 |+------+怎么驗(yàn)證存儲(chǔ)數(shù)據(jù)insert 訪問 就是存儲(chǔ)在了主機(jī)服務(wù)器host61上?# 客戶端機(jī)插入數(shù)據(jù)[root@host50 ~]# mysql -h192.168.88.60 -P4006 -uyaya -p123qqq...A -e 'insert into bbsdb.a values(666)' # 在主服務(wù)器本機(jī)查看數(shù)據(jù)[root@host61 ~]# mysql -uroot -p123qqq...a -e 'select * from bbsdb.a'mysql: [Warning] Using a password on the command line interface can be insecure.+------+| id |+------+| 8888 || 666 |+------+[root@host50 ~]# mysql -h192.168.88.60 -P4006 -uyaya -p123qqq...A -e 'select * from bbsdb.a'mysql: [Warning] Using a password on the command line interface can be insecure.+------+| id |+------+| 8888 || 6262 || 666 |+------+還可以通過查看主服務(wù)器的position是否在客戶端服務(wù)器插入數(shù)據(jù)后改動(dòng)來(lái)確定是不是在主服務(wù)器中進(jìn)行操作過數(shù)據(jù)補(bǔ)充說明如果主從結(jié)構(gòu)中的從服務(wù)器宕機(jī)了,就實(shí)現(xiàn)不了讀寫分離了,會(huì)把讀寫請(qǐng)求都給主服務(wù)器處理。如果主從結(jié)構(gòu)中的主服務(wù)器宕機(jī)了,讀寫分離服務(wù)無(wú)法訪問

以上就是MySQL數(shù)據(jù)讀寫分離MaxScale相關(guān)配置的詳細(xì)內(nèi)容,更多關(guān)于MySQL數(shù)據(jù)讀寫分離MaxScale的資料請(qǐng)關(guān)注好吧啦網(wǎng)其它相關(guān)文章!

標(biāo)簽: MySQL 數(shù)據(jù)庫(kù)
主站蜘蛛池模板: 欧洲性大片xxxxx久久久 | 欧美亚洲欧美日韩中文二区 | 久久国产在线视频 | 亚洲国产一二三 | 久久免费视频在线观看30 | 婷婷欧美 | 黄色影院免费观看 | 亚洲国产成人精品青青草原100 | 99re热视频这里只有精品5 | 日韩一区二区三区免费 | 四虎东方va私人影库在线观看 | 国产成人在线网站 | 国产一级特黄毛片 | 最新欧美一级视频 | 久久国产三级 | 俺来也俺来也天天夜夜视频 | 黄色欧美大片 | 国产精品久久久久久久久久久不卡 | 成年男女免费视频观看性 | 亚洲精品一区二三区在线观看 | 成人三级在线播放 | 午夜精品aaa国产福利 | 免费视频爱爱太爽了 | 一级做α爱毛毛片 | 亚洲在线第一页 | 国产精品久久久久一区二区三区 | 国产免费一级高清淫日本片 | 日韩亚洲成a人片在线观看 日韩亚洲欧美一区二区三区 | 国产呦精品系列在线 | 欧美啪啪毛片一区二区 | 国产在线欧美精品 | 小明看看免费 | 干综合网 | 久久在线综合 | a级精品九九九大片免费看 a级情欲片在线观看免费女中文 | 国产2021中文天码字幕 | 国产成人欧美一区二区三区的 | 国产丝袜制服在线 | 亚洲欧美日本欧美在线播放污 | 91在线在线啪永久地址 | 黄色免费在线观看视频 |