mycat基礎(chǔ)架構(gòu)搭建

1. 基礎(chǔ)架構(gòu)介紹


mycat基礎(chǔ)環(huán)境圖


2. 準(zhǔn)備環(huán)境

2.1 環(huán)境準(zhǔn)備:

兩臺虛擬機(jī) db01 db02

每臺創(chuàng)建四個mysql實(shí)例:3307 3308 3309 3310

2.2 刪除歷史環(huán)境:

===================================================================================
執(zhí)行過程中要看好標(biāo)記,看好#號后標(biāo)記得主機(jī)名稱蛹锰;這里的我的主機(jī)環(huán)境:db01(eth0:10.0.0.51 eth1: 172.16.1.51) db02(eth0:10.0.0.52 eth1:172.16.1.52)?

===================================================================================

pkill mysqld

rm -rf /data/330*

mv /etc/my.cnf /etc/my.cnf.bak

2.3 創(chuàng)建相關(guān)目錄初始化數(shù)據(jù)

mkdir /data/33{07..10}/data -p

mysqld --initialize-insecure? --user=mysql --datadir=/data/3307/data --basedir=/data/app/mysql

mysqld --initialize-insecure? --user=mysql --datadir=/data/3308/data --basedir=/data/app/mysql

mysqld --initialize-insecure? --user=mysql --datadir=/data/3309/data --basedir=/data/app/mysql

mysqld --initialize-insecure? --user=mysql --datadir=/data/3310/data --basedir=/data/app/mysql

2.4 準(zhǔn)備配置文件和啟動腳本

========db01==============

cat >/data/3307/my.cnf<<EOF

[mysqld]

basedir=/data/app/mysql

datadir=/data/3307/data

socket=/data/3307/mysql.sock

port=3307

log-error=/data/3307/mysql.log

log_bin=/data/3307/mysql-bin

binlog_format=row

skip-name-resolve

server-id=7

gtid-mode=on

enforce-gtid-consistency=true

log-slave-updates=1

EOF

cat >/data/3308/my.cnf<<EOF

[mysqld]

basedir=/data/app/mysql

datadir=/data/3308/data

port=3308

socket=/data/3308/mysql.sock

log-error=/data/3308/mysql.log

log_bin=/data/3308/mysql-bin

binlog_format=row

skip-name-resolve

server-id=8

gtid-mode=on

enforce-gtid-consistency=true

log-slave-updates=1

EOF

cat >/data/3309/my.cnf<<EOF

[mysqld]

basedir=/data/app/mysql

datadir=/data/3309/data

socket=/data/3309/mysql.sock

port=3309

log-error=/data/3309/mysql.log

log_bin=/data/3309/mysql-bin

binlog_format=row

skip-name-resolve

server-id=9

gtid-mode=on

enforce-gtid-consistency=true

log-slave-updates=1

EOF

cat >/data/3310/my.cnf<<EOF

[mysqld]

basedir=/data/app/mysql

datadir=/data/3310/data

socket=/data/3310/mysql.sock

port=3310

log-error=/data/3310/mysql.log

log_bin=/data/3310/mysql-bin

binlog_format=row

skip-name-resolve

server-id=10

gtid-mode=on

enforce-gtid-consistency=true

log-slave-updates=1

EOF

cat >/etc/systemd/system/mysqld3307.service<<EOF

[Unit]

Description=MySQL Server

Documentation=man:mysqld(8)

Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html

After=network.target

After=syslog.target

[Install]

WantedBy=multi-user.target

[Service]

User=mysql

Group=mysql

ExecStart=/data/app/mysql/bin/mysqld --defaults-file=/data/3307/my.cnf

LimitNOFILE = 5000

EOF

cat >/etc/systemd/system/mysqld3308.service<<EOF

[Unit]

Description=MySQL Server

Documentation=man:mysqld(8)

Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html

After=network.target

After=syslog.target

[Install]

WantedBy=multi-user.target

[Service]

User=mysql

Group=mysql

ExecStart=/data/app/mysql/bin/mysqld --defaults-file=/data/3308/my.cnf

LimitNOFILE = 5000

EOF

cat >/etc/systemd/system/mysqld3309.service<<EOF

[Unit]

Description=MySQL Server

Documentation=man:mysqld(8)

Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html

After=network.target

After=syslog.target

[Install]

WantedBy=multi-user.target

[Service]

User=mysql

Group=mysql

ExecStart=/data/app/mysql/bin/mysqld --defaults-file=/data/3309/my.cnf

LimitNOFILE = 5000

EOF

cat >/etc/systemd/system/mysqld3310.service<<EOF

[Unit]

Description=MySQL Server

Documentation=man:mysqld(8)

Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html

After=network.target

After=syslog.target

[Install]

WantedBy=multi-user.target

[Service]

User=mysql

Group=mysql

ExecStart=/data/app/mysql/bin/mysqld --defaults-file=/data/3310/my.cnf

LimitNOFILE = 5000

EOF

========db02===============

cat >/data/3307/my.cnf<<EOF

[mysqld]

basedir=/data/app/mysql

datadir=/data/3307/data

socket=/data/3307/mysql.sock

port=3307

log-error=/data/3307/mysql.log

log_bin=/data/3307/mysql-bin

binlog_format=row

skip-name-resolve

server-id=17

gtid-mode=on

enforce-gtid-consistency=true

log-slave-updates=1

EOF

cat >/data/3308/my.cnf<<EOF

[mysqld]

basedir=/data/app/mysql

datadir=/data/3308/data

port=3308

socket=/data/3308/mysql.sock

log-error=/data/3308/mysql.log

log_bin=/data/3308/mysql-bin

binlog_format=row

skip-name-resolve

server-id=18

gtid-mode=on

enforce-gtid-consistency=true

log-slave-updates=1

EOF

cat >/data/3309/my.cnf<<EOF

[mysqld]

basedir=/data/app/mysql

datadir=/data/3309/data

socket=/data/3309/mysql.sock

port=3309

log-error=/data/3309/mysql.log

log_bin=/data/3309/mysql-bin

binlog_format=row

skip-name-resolve

server-id=19

gtid-mode=on

enforce-gtid-consistency=true

log-slave-updates=1

EOF

cat >/data/3310/my.cnf<<EOF

[mysqld]

basedir=/data/app/mysql

datadir=/data/3310/data

socket=/data/3310/mysql.sock

port=3310

log-error=/data/3310/mysql.log

log_bin=/data/3310/mysql-bin

binlog_format=row

skip-name-resolve

server-id=20

gtid-mode=on

enforce-gtid-consistency=true

log-slave-updates=1

EOF

cat >/etc/systemd/system/mysqld3307.service<<EOF

[Unit]

Description=MySQL Server

Documentation=man:mysqld(8)

Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html

After=network.target

After=syslog.target

[Install]

WantedBy=multi-user.target

[Service]

User=mysql

Group=mysql

ExecStart=/data/app/mysql/bin/mysqld --defaults-file=/data/3307/my.cnf

LimitNOFILE = 5000

EOF

cat >/etc/systemd/system/mysqld3308.service<<EOF

[Unit]

Description=MySQL Server

Documentation=man:mysqld(8)

Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html

After=network.target

After=syslog.target

[Install]

WantedBy=multi-user.target

[Service]

User=mysql

Group=mysql

ExecStart=/data/app/mysql/bin/mysqld --defaults-file=/data/3308/my.cnf

LimitNOFILE = 5000

EOF

cat >/etc/systemd/system/mysqld3309.service<<EOF

[Unit]

Description=MySQL Server

Documentation=man:mysqld(8)

Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html

After=network.target

After=syslog.target

[Install]

WantedBy=multi-user.target

[Service]

User=mysql

Group=mysql

ExecStart=/data/app/mysql/bin/mysqld --defaults-file=/data/3309/my.cnf

LimitNOFILE = 5000

EOF

cat >/etc/systemd/system/mysqld3310.service<<EOF

[Unit]

Description=MySQL Server

Documentation=man:mysqld(8)

Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html

After=network.target

After=syslog.target

[Install]

WantedBy=multi-user.target

[Service]

User=mysql

Group=mysql

ExecStart=/data/app/mysql/bin/mysqld --defaults-file=/data/3310/my.cnf

LimitNOFILE = 5000

EOF

2.5 修改權(quán)限曲梗,啟動多實(shí)例

chown -R mysql.mysql /data/*

systemctl start mysqld3307

systemctl start mysqld3308

systemctl start mysqld3309

systemctl start mysqld3310

mysql -S /data/3307/mysql.sock -e "show variables like 'server_id'"

mysql -S /data/3308/mysql.sock -e "show variables like 'server_id'"

mysql -S /data/3309/mysql.sock -e "show variables like 'server_id'"

mysql -S /data/3310/mysql.sock -e "show variables like 'server_id'"

2.7 分片規(guī)劃(不用執(zhí)行茂卦,結(jié)構(gòu)介文字說明)

shard1:(節(jié)點(diǎn)①)

? ? Master:10.0.0.51:3307

? ? slave1:10.0.0.51:3309

? ? Standby Master:10.0.0.52:3307

? ? slave2:10.0.0.52:3309

shard2:(節(jié)點(diǎn)②)

? ? Master:10.0.0.52:3308

? ? slave1:10.0.0.52:3310

? ? Standby Master:10.0.0.51:3308

? ? slave2:10.0.0.51:3310

2.8 開始配置主從環(huán)境

# shard1

##? 10.0.0.51:3307 <-----> 10.0.0.52:3307

# db02

mysql? -S /data/3307/mysql.sock -e "grant replication slave on *.* to repl@'10.0.0.%' identified by '123';"

mysql? -S /data/3307/mysql.sock -e "grant all? on *.* to root@'10.0.0.%' identified by '123'? with grant option;"

# db01

mysql? -S /data/3307/mysql.sock -e "CHANGE MASTER TO MASTER_HOST='10.0.0.52', MASTER_PORT=3307, MASTER_AUTO_POSITION=1, MASTER_USER='repl', MASTER_PASSWORD='123';"

mysql? -S /data/3307/mysql.sock -e "start slave;"

mysql? -S /data/3307/mysql.sock -e "show slave status\G"

# db02

mysql? -S /data/3307/mysql.sock -e "CHANGE MASTER TO MASTER_HOST='10.0.0.51', MASTER_PORT=3307, MASTER_AUTO_POSITION=1, MASTER_USER='repl', MASTER_PASSWORD='123';"

mysql? -S /data/3307/mysql.sock -e "start slave;"

mysql? -S /data/3307/mysql.sock -e "show slave status\G"

## 10.0.0.51:3309 ------> 10.0.0.51:3307

# db01

mysql? -S /data/3309/mysql.sock? -e "CHANGE MASTER TO MASTER_HOST='10.0.0.51', MASTER_PORT=3307, MASTER_AUTO_POSITION=1, MASTER_USER='repl', MASTER_PASSWORD='123';"

mysql? -S /data/3309/mysql.sock? -e "start slave;"

mysql? -S /data/3309/mysql.sock? -e "show slave status\G"

## 10.0.0.52:3309 ------> 10.0.0.52:3307

# db02

mysql? -S /data/3309/mysql.sock -e "CHANGE MASTER TO MASTER_HOST='10.0.0.52', MASTER_PORT=3307, MASTER_AUTO_POSITION=1, MASTER_USER='repl', MASTER_PASSWORD='123';"

mysql? -S /data/3309/mysql.sock -e "start slave;"

mysql? -S /data/3309/mysql.sock -e "show slave status\G"

====================================================================

# shard2

## 10.0.0.52:3308 <-----> 10.0.0.51:3308

# db01

mysql? -S /data/3308/mysql.sock -e "grant replication slave on *.* to repl@'10.0.0.%' identified by '123';"

mysql? -S /data/3308/mysql.sock -e "grant all? on *.* to root@'10.0.0.%' identified by '123'? with grant option;"

# db02

mysql? -S /data/3308/mysql.sock -e "CHANGE MASTER TO MASTER_HOST='10.0.0.51', MASTER_PORT=3308, MASTER_AUTO_POSITION=1, MASTER_USER='repl', MASTER_PASSWORD='123';"

mysql? -S /data/3308/mysql.sock -e "start slave;"

mysql? -S /data/3308/mysql.sock -e "show slave status\G"

# db01

mysql? -S /data/3308/mysql.sock -e "CHANGE MASTER TO MASTER_HOST='10.0.0.52', MASTER_PORT=3308, MASTER_AUTO_POSITION=1, MASTER_USER='repl', MASTER_PASSWORD='123';"

mysql? -S /data/3308/mysql.sock -e "start slave;"

mysql? -S /data/3308/mysql.sock -e "show slave status\G"

## 10.0.0.52:3310 -----> 10.0.0.52:3308

# db02

mysql? -S /data/3310/mysql.sock -e "CHANGE MASTER TO MASTER_HOST='10.0.0.52', MASTER_PORT=3308, MASTER_AUTO_POSITION=1, MASTER_USER='repl', MASTER_PASSWORD='123';"

mysql? -S /data/3310/mysql.sock -e "start slave;"

mysql? -S /data/3310/mysql.sock -e "show slave status\G"

##10.0.0.51:3310 -----> 10.0.0.51:3308

# db01

mysql? -S /data/3310/mysql.sock -e "CHANGE MASTER TO MASTER_HOST='10.0.0.51', MASTER_PORT=3308, MASTER_AUTO_POSITION=1, MASTER_USER='repl', MASTER_PASSWORD='123';"

mysql? -S /data/3310/mysql.sock -e "start slave;"

mysql? -S /data/3310/mysql.sock -e "show slave status\G"

2.9 檢測主從狀態(tài)

mysql -S /data/3307/mysql.sock -e "show slave status\G"|grep Running

mysql -S /data/3308/mysql.sock -e "show slave status\G"|grep Running

mysql -S /data/3309/mysql.sock -e "show slave status\G"|grep Running

mysql -S /data/3310/mysql.sock -e "show slave status\G"|grep Running

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

注:如果中間出現(xiàn)錯誤保礼,在每個節(jié)點(diǎn)進(jìn)行執(zhí)行以下命令亿柑,從2.8從頭執(zhí)行

mysql -S /data/3307/mysql.sock -e "stop slave; reset slave all;"

mysql -S /data/3308/mysql.sock -e "stop slave; reset slave all;"

mysql -S /data/3309/mysql.sock -e "stop slave; reset slave all;"

mysql -S /data/3310/mysql.sock -e "stop slave; reset slave all;"

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

最后結(jié)果是:下圖樣子:


maycat db01 成功結(jié)果圖
maycat db02 成功結(jié)果圖
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末匠襟,一起剝皮案震驚了整個濱河市祟敛,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌佣蓉,老刑警劉巖披摄,帶你破解...
    沈念sama閱讀 206,214評論 6 481
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件亲雪,死亡現(xiàn)場離奇詭異,居然都是意外死亡疚膊,警方通過查閱死者的電腦和手機(jī)义辕,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,307評論 2 382
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來寓盗,“玉大人终息,你說我怎么就攤上這事≌耆茫” “怎么了?”我有些...
    開封第一講書人閱讀 152,543評論 0 341
  • 文/不壞的土叔 我叫張陵柳譬,是天一觀的道長喳张。 經(jīng)常有香客問我,道長美澳,這世上最難降的妖魔是什么销部? 我笑而不...
    開封第一講書人閱讀 55,221評論 1 279
  • 正文 為了忘掉前任,我火速辦了婚禮制跟,結(jié)果婚禮上舅桩,老公的妹妹穿的比我還像新娘。我一直安慰自己雨膨,他們只是感情好擂涛,可當(dāng)我...
    茶點(diǎn)故事閱讀 64,224評論 5 371
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著聊记,像睡著了一般撒妈。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上排监,一...
    開封第一講書人閱讀 49,007評論 1 284
  • 那天狰右,我揣著相機(jī)與錄音,去河邊找鬼舆床。 笑死棋蚌,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的挨队。 我是一名探鬼主播谷暮,決...
    沈念sama閱讀 38,313評論 3 399
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼瞒瘸!你這毒婦竟也來了坷备?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 36,956評論 0 259
  • 序言:老撾萬榮一對情侶失蹤情臭,失蹤者是張志新(化名)和其女友劉穎省撑,沒想到半個月后赌蔑,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 43,441評論 1 300
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡竟秫,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 35,925評論 2 323
  • 正文 我和宋清朗相戀三年娃惯,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片肥败。...
    茶點(diǎn)故事閱讀 38,018評論 1 333
  • 序言:一個原本活蹦亂跳的男人離奇死亡趾浅,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出馒稍,到底是詐尸還是另有隱情皿哨,我是刑警寧澤,帶...
    沈念sama閱讀 33,685評論 4 322
  • 正文 年R本政府宣布纽谒,位于F島的核電站证膨,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏鼓黔。R本人自食惡果不足惜央勒,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,234評論 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望澳化。 院中可真熱鬧崔步,春花似錦、人聲如沸缎谷。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,240評論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽列林。三九已至眼虱,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間席纽,已是汗流浹背捏悬。 一陣腳步聲響...
    開封第一講書人閱讀 31,464評論 1 261
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留润梯,地道東北人过牙。 一個月前我還...
    沈念sama閱讀 45,467評論 2 352
  • 正文 我出身青樓,卻偏偏與公主長得像纺铭,于是被迫代替她去往敵國和親寇钉。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 42,762評論 2 345

推薦閱讀更多精彩內(nèi)容