İyinet'e Hoşgeldiniz!

Türkiye'nin En Eski Webmaster Forum'una Hemen Kayıt Olun!

Kayıt Ol!

Mysql'da replication

CaNeRiuM

0
İyinet Üyesi
Onaylı Üye
Katılım
10 Mart 2008
Mesajlar
210
Reaction score
2
Mysql replication master olarak seçilen databaseda bellirli bir
objeyi - database, tablo, vs - slave olarak seçilen databaselere
senkronize etmek için kullanilir.

örnek setup:


Kod:
Kod:
master : aaa.aaa.aaa.aaa 
slave1 : bbb.bbb.bbb.bbb 
slave2 : ccc.ccc.ccc.ccc"master"de my.cnf dosyasina:


Kod:
Kod:
server-id = 1
log-binsatırları eklenir. Değişikliklerin aktif olabilmesi için mysql restart edilir.




Kod:
Kod:
mysql> GRANT REPLICATION SLAVE ON *.* to slave_user@'bbb.bbb.bbb.bbb' identified by 'slave_password' 
mysql> GRANT RELOAD ON *.* to slave_user@'bbb.bbb.bbb.bbb' identified by 'slave_password'; 
mysql> GRANT SUPER,REPLICATION CLIENT ON *.* to slave_user@'bbb.bbb.bbb.bbb' identified by 'slave_password'; 

mysql> GRANT REPLICATION SLAVE ON *.* to slave_user@'ccc.ccc.ccc.ccc' identified by 'slave_password' 
mysql> GRANT RELOAD ON *.* to slave_user@'ccc.ccc.ccc.ccc' identified by 'slave_password'; 
mysql> GRANT SUPER,REPLICATION CLIENT ON *.* to slave_user@'ccc.ccc.ccc.ccc' identified by 'slave_password';"slave1"de my.cnf dosyasinda, (replicate-do-table ile replicate yapilacak tablolar belirleniyor)


Kod:
Kod:
server-id = 2 
master-host =aaa.aaa.aaa.aaa 
master-user = slave_user 
master-password=slave_password 
master-port = 3306 
replicate-do-table=db.TABLE1 
replicate-do-table=db.TABLE2 
replicate-do-table=db.TABLE3 
replicate-do-table=db.TABLE4 

"slave2"de my.cnf dosyasinda 

server-id = 3 
master-host =aaa.aaa.aaa.aaa 
master-user = slave_user 
master-password=slave_password 
master-port = 3306 
replicate-do-table=db.TABLE1 
replicate-do-table=db.TABLE2 
replicate-do-table=db.TABLE3 
replicate-do-table=db.TABLE4eklentileri yapilir ve herbir slave makinada mysqller tekrar başlatılır.

slave1 veya slave2 de


Kod:
Kod:
mysql> load data from master 
mysql> slave startedilir.

slavelerde,


Kod:
Kod:
mysql> show slave status\G; ile 

************************** 1. row ************************** 
Slave_IO_State: Waiting for master to send event 
Master_Host: aaa.aaa.aaa.aaa 
Master_User: slave_user 
Master_Port: 3306 
Connect_Retry: 60 
Master_Log_File: bin-log.000001 
Read_Master_Log_Pos: 160158 
Relay_Log_File: smlcpurgw1-relay-bin.000001 
Relay_Log_Pos: 59186 
Relay_Master_Log_File: bin-log.000001 
Slave_IO_Running: Yes 
Slave_SQL_Running: Yes 
Replicate_Do_DB: 
Replicate_Ignore_DB: 
Replicate_Do_Table: db.TABLE1,db.TABLE2,db.TABLE3,db.TABLE4 
Replicate_Ignore_Table: 
Replicate_Wild_Do_Table: 
Replicate_Wild_Ignore_Table: 
Last_Errno: 0 
Last_Error: 
Skip_Counter: 0 
Exec_Master_Log_Pos: 160158 
Relay_Log_Space: 59186 
Until_Condition: None 
Until_Log_File: 
Until_Log_Pos: 0 
Master_SSL_Allowed: No 
Master_SSL_CA_File: 
Master_SSL_CA_Path: 
Master_SSL_Cert: 
Master_SSL_Cipher: 
Master_SSL_Key: 
Seconds_Behind_Master: 0 
1 row in set (0.00 sec)ERROR: 
No query specified

elde edilir.

buradaki Read_Master_Log_Pos: 160158 ile

master makinadaki


Kod:
Kod:
mysql> show master status; 
+-----------------------------------+------------------+ 
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | 
+-----------------------------------+------------------+ 
| bin-log.000001 | 160158 | | | 
+-----------------------------------+------------------+ 
1 row in set (0.00 sec)daki position: 160158 degerinin aynı olduğu görülür.

masterin bin-log position ile slave lerdeki positionlar eşit olduğu sürece
master-slave sistemi senkronize demektir.
 

Türkiye’nin ilk webmaster forum sitesi iyinet.com'da forum üyeleri tarafından yapılan tüm paylaşımlardan; Türk Ceza Kanunu’nun 20. Maddesinin, 5651 Sayılı Kanununun 4. maddesinin 2. fıkrasına göre, paylaşım yapan üyeler sorumludur.

Üst