溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

mysql如何通過遷移某個(gè)庫的目錄來擴(kuò)容

發(fā)布時(shí)間:2021-11-16 14:31:58 來源:億速云 閱讀:160 作者:柒染 欄目:MySQL數(shù)據(jù)庫

mysql如何通過遷移某個(gè)庫的目錄來擴(kuò)容,相信很多沒有經(jīng)驗(yàn)的人對(duì)此束手無策,為此本文總結(jié)了問題出現(xiàn)的原因和解決方法,通過這篇文章希望你能解決這個(gè)問題。

問題描述:現(xiàn)在有一套主主復(fù)制的mysql數(shù)據(jù)庫,數(shù)據(jù)文件目錄超過97%,嚴(yán)重不足,需要馬上進(jìn)行處理,我們知道m(xù)ysql數(shù)據(jù)庫數(shù)據(jù)文件目錄不能動(dòng)態(tài)的去改變,不像oracle那樣可以直接更改數(shù)據(jù)文件的目錄,下面展示一種比較好的擴(kuò)大mysql數(shù)據(jù)文件目錄的方法:

這套庫是利用keepalived ,來提供一個(gè)vip,然后業(yè)務(wù)連接這個(gè)vip(這里的vip為192.***118),如下查看vip的位置,它現(xiàn)在在S244上,說i明目前的S244,

[root@S244 ~]# ip  a

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN

link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

inet 127.0.0.1/8 scope host lo

inet6 ::1/128 scope host

valid_lft forever preferred_lft forever

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000

link/ether 00:26:2d:0d:50:42 brd ff:ff:ff:ff:ff:ff

inet 192.168.0.244/24 brd 192.168.0.255 scope global eth0

inet 192.168.0.118/24 brd 192.168.0.255 scope global secondary eth0:1

inet6 fe80::226:2dff:fe0d:5042/64 scope link

valid_lft forever preferred_lft forever

3: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000

link/ether 00:26:2d:0d:50:43 brd ff:ff:ff:ff:ff:ff

inet6 fe80::226:2dff:fe0d:5043/64 scope link

valid_lft forever preferred_lft forever

4: eth3: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000

link/ether 00:26:2d:0d:50:41 brd ff:ff:ff:ff:ff:ff

inet 192.168.8.244/24 brd 192.168.8.255 scope global eth3

[root@S243 keepalived]# ip a

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN

link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

inet 127.0.0.1/8 scope host lo

inet6 ::1/128 scope host

valid_lft forever preferred_lft forever

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000

link/ether 00:26:2d:0d:50:42 brd ff:ff:ff:ff:ff:ff

inet 192.168.0.244/24 brd 192.168.0.255 scope global eth0

inet6 fe80::226:2dff:fe0d:5042/64 scope link

valid_lft forever preferred_lft forever

3: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000

link/ether 00:26:2d:0d:50:43 brd ff:ff:ff:ff:ff:ff

inet6 fe80::226:2dff:fe0d:5043/64 scope link

valid_lft forever preferred_lft forever

4: eth3: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000

link/ether 00:26:2d:0d:50:41 brd ff:ff:ff:ff:ff:ff

inet 192.168.8.244/24 brd 192.168.8.255 scope global eth3

[root@S244 keepalived]#

那么好,下面展示具體操作流程:

我打算移動(dòng)一個(gè)庫的目錄到另一個(gè)空間充足的路徑下。

在操作數(shù)據(jù)庫之前,應(yīng)該先和系統(tǒng)工程溝通好,先停掉相關(guān)的服務(wù)。

一)首先操作從庫;

1,關(guān)閉主從復(fù)制

mysql> stop slave;

2,關(guān)閉mysql服務(wù),注意有的時(shí)候是:service mysqld stop

[root@S243 ~]# service mysql stop

3,我們知道一個(gè)庫對(duì)應(yīng)一個(gè)子目錄,經(jīng)過對(duì)比,我決定把mailer 庫移動(dòng)到另一個(gè)目錄  /mysql2

1)[root@S243 ~]#cd   /mysql/datadir

2)[root@S243 datadir]#    cp -r  mailer    /mysql2/mailer              ----把整個(gè)目錄  mailer 復(fù)制到/mysql2,并且起名字也為mailer.

3)確定復(fù)制成功后,刪除原來在/mysql的mailer目錄

[root@S243 datadir]#  rm  -rf  mailer

4)修改 /mysql2/下的mailer的屬組,

[root@S243 mysql2]#  chown -R mysql:mysql  mailer

5)建立軟連接,到/mysql/datadir目錄

[root@S243 mysql2]# ln -s  /mysql2/mailer   /mysql/datadir/mailer

4,啟動(dòng)數(shù)據(jù)庫.

[root@S243 ~]# service mysql  start

5,開啟主從復(fù)制,并檢查相關(guān)進(jìn)程的狀態(tài),均為yes為正常。

mysql> start slave;

mysql> show slave status\G;

*************************** 1. row ***************************

Slave_IO_State: Waiting for master to send event

Master_Host: 192.168.0.244

Master_User: info_syncer

Master_Port: 3306

Connect_Retry: 60

Master_Log_File: mysql-bin.001358

Read_Master_Log_Pos: 643287297

Relay_Log_File: S243-relay-bin.001134

Relay_Log_Pos: 350

Relay_Master_Log_File: mysql-bin.001358

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

。。。。。。

到此從庫的操作結(jié)束。。。。

針對(duì)主庫的操作和從庫的操作一樣,需要注意的我們這臺(tái)主主復(fù)制的mysql.通過keepalived設(shè)置出了一個(gè)vip 118 ,寫的業(yè)務(wù)是通過連接vip登錄數(shù)據(jù)庫的,我們可以保證寫的業(yè)務(wù)不受影響,因?yàn)関ip所在的那臺(tái)服務(wù)器就是主mysql,當(dāng)這臺(tái)mysql死掉后,vip就自動(dòng)轉(zhuǎn)移到另一臺(tái)服務(wù)器上了,依舊保持正常的寫入的業(yè)務(wù),

然后我關(guān)注的是vip轉(zhuǎn)移的觸發(fā)條件:我們都知道keepalived 監(jiān)控著的服務(wù)死掉,會(huì)觸發(fā)vip遷移,還有就是keepalived 的服務(wù)停掉也會(huì)觸發(fā)vip漂移,

1).關(guān)閉keepalived 會(huì)觸發(fā)vip飄到另一臺(tái)服務(wù)器,

[root@S244 ~]# ip a

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN

link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

inet 127.0.0.1/8 scope host lo

inet6 ::1/128 scope host

valid_lft forever preferred_lft forever

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000

link/ether 00:26:2d:0d:50:42 brd ff:ff:ff:ff:ff:ff

inet 192.168.0.244/24 brd 192.168.0.255 scope global eth0

inet 192.168.0.118/24 brd 192.168.0.255 scope global secondary eth0:1

inet6 fe80::226:2dff:fe0d:5042/64 scope link

valid_lft forever preferred_lft forever

[root@S244 ~]# service keepalived stop

再次查看果然沒有了 118那個(gè)vip

[root@S244 ~]# ip  a

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN

link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

inet 127.0.0.1/8 scope host lo

inet6 ::1/128 scope host

valid_lft forever preferred_lft forever

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000

link/ether 00:26:2d:0d:50:42 brd ff:ff:ff:ff:ff:ff

inet 192.168.0.244/24 brd 192.168.0.255 scope global eth0

inet6 fe80::226:2dff:fe0d:5042/64 scope link

valid_lft forever preferred_lft forever

可是當(dāng)再次[root@S244 ~]# service keepalived start之后,vip118又再次飄回到這里了。原來keepalived 配置文件里有個(gè)參數(shù)   priority 是優(yōu)先級(jí),如下發(fā)現(xiàn)是s244這臺(tái)機(jī)器的優(yōu)先級(jí)更高 priority 100高于 priority 50,并且還有個(gè)參數(shù)nopreempt代表優(yōu)先級(jí)別高的不要搶占vip, 默認(rèn)是preempt搶占vip。

[root@S243 keepalived]# cat keepalived.conf

global_defs {

notification_email {

}

}

vrrp_instance VI_1 {

#  state MASTER

state BACKUP

interface eth0

virtual_router_id 51

#   priority 100

priority 50

mcast_src_ip 192.168.0.243

advert_int 1

authentication {

auth_type PASS

auth_pass 1111

}

virtual_ipaddress {

#    202.85.218.197 dev eth2 label eth2:1

192.168.0.118/24 broadcast 192.168.0.255   dev eth0 label eth0:1

}

virtual_server 192.168.0.118 3306 {

delay_loop 2   #每個(gè)2秒檢查一次real_server狀態(tài)

lb_algo wrr   #LVS算法

lb_kind DR    #LVS模式

persistence_timeout 60   #會(huì)話保持時(shí)間

protocol TCP

real_server 192.168.0.243 3306 {

weight 3

notify_down /var/lib/mysql/mysql_kpa.sh  #檢測(cè)到服務(wù)down后執(zhí)行的腳本

TCP_CHECK {

connect_timeout 10    #連接超時(shí)時(shí)間

nb_get_retry 3       #重連次數(shù)

delay_before_retry 3   #重連間隔時(shí)間

connect_port 3306   #健康檢查端口

}

}

[root@S244 ~]# cat  /etc/keepalived/keepalived.conf

global_defs {

notification_email {

}

}

vrrp_instance VI_1 {

#   state BACKUP

state MASTER

interface eth0

virtual_router_id 51

#    priority 50

priority 100

mcast_src_ip 192.168.0.244

advert_int 1

authentication {

auth_type PASS

auth_pass 1111

}

virtual_ipaddress {

#   202.85.218.197 dev eth2 label eth2:1

192.168.0.118/24 broadcast 192.168.0.255  dev eth0 label eth0:1

}

virtual_server 192.168.0.118 3306 {

delay_loop 2   #每個(gè)2秒檢查一次real_server狀態(tài)

lb_algo wrr   #LVS算法

lb_kind DR    #LVS模式

persistence_timeout 60   #會(huì)話保持時(shí)間

protocol TCP

real_server 192.168.0.244 3306 {

weight 3

notify_down /var/lib/mysql/mysql_kpa.sh  #檢測(cè)到服務(wù)down后執(zhí)行的腳本

TCP_CHECK {

connect_timeout 10    #連接超時(shí)時(shí)間

nb_get_retry 3       #重連次數(shù)

delay_before_retry 3   #重連間隔時(shí)間

connect_port 3306   #健康檢查端口

}

}

mysql數(shù)據(jù)庫的空間空間可擴(kuò)展性還是比oracle要差點(diǎn),所以針對(duì)mysql數(shù)據(jù)庫前期的準(zhǔn)備和預(yù)估工作很重要,你需要更準(zhǔn)確的預(yù)估出未來一段時(shí)間的空間增幅,以便于預(yù)留出更加準(zhǔn)確的空間,因?yàn)閙ysql空間擴(kuò)展是需要停服務(wù)的,并且存在一定的風(fēng)險(xiǎn),

看完上述內(nèi)容,你們掌握mysql如何通過遷移某個(gè)庫的目錄來擴(kuò)容的方法了嗎?如果還想學(xué)到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注億速云行業(yè)資訊頻道,感謝各位的閱讀!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI