基本策略:
成都創(chuàng)新互聯(lián)成立與2013年,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項(xiàng)目成都網(wǎng)站建設(shè)、做網(wǎng)站網(wǎng)站策劃,項(xiàng)目實(shí)施與項(xiàng)目整合能力。我們以讓每一個(gè)夢(mèng)想脫穎而出為使命,1280元山亭做網(wǎng)站,已為上家服務(wù),為山亭各地企業(yè)和個(gè)人服務(wù),聯(lián)系電話:18980820575此時(shí)需要在主服務(wù)器上先完全備份,還原到從服務(wù)器;接著開啟主從復(fù)制; 如果直接使用主從復(fù)制,那么主從服務(wù)器的壓力很大;主服務(wù)器數(shù)據(jù)全備份操作:
[root@master ~]$mysqldump -A -F --single-transaction --master-data=1 > all.sql主服務(wù)器模擬修改操作:
MariaDB [(none)]> create database wangdb1; Query OK, 1 row affected (0.01 sec) MariaDB [(none)]> show master logs; +--------------------+-----------+ | Log_name | File_size | +--------------------+-----------+ | mariadb-bin.000001 | 8217 | | mariadb-bin.000002 | 555 | | mariadb-bin.000003 | 334 | +--------------------+-----------+ 3 rows in set (0.00 sec) [root@master ~]$less all.sql CHANGE MASTER TO MASTER_LOG_FILE='mariadb-bin.000003', MASTER_LOG_POS=245;主服務(wù)器配置:
[root@slave ~]$vim /etc/my.cnf [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # Settings user and group are ignored when systemd is used. innodb_file_per_table server_id=2從服務(wù)器數(shù)據(jù)還原:
[root@master ~]$scp all.sql 192.168.27.17:~ [root@slave ~]$mysql < all.sql從服務(wù)器開啟主從復(fù)制:
MariaDB [(none)]> CHANGE MASTER TO -> MASTER_HOST='192.168.27.7', -> MASTER_USER='repluser', -> MASTER_PASSWORD='centos', -> MASTER_LOG_FILE='mariadb-bin.000003', -> MASTER_LOG_POS=245; Query OK, 0 rows affected (0.01 sec) MariaDB [(none)]> start slave; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> show slave status\G *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 192.168.27.7 Master_User: repluser Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mariadb-bin.000003 Read_Master_Log_Pos: 334 Relay_Log_File: mariadb-relay-bin.000002 Relay_Log_Pos: 620 Relay_Master_Log_File: mariadb-bin.000003 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0 Last_Error: Skip_Counter: 0 Exec_Master_Log_Pos: 334 Relay_Log_Space: 916 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 Master_SSL_Verify_Server_Cert: No Last_IO_Errno: 0 Last_IO_Error: Last_SQL_Errno: 0 Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 1 1 row in set (0.00 sec)從服務(wù)器數(shù)據(jù)一致性保證:
由于從服務(wù)器上的數(shù)據(jù)也是可以被刪除的,所以為了保證數(shù)據(jù)的一致性,可以將只讀屬性打開; 這種情況下,MySQL的root用戶依然是可以修改刪除的,只是對(duì)于普通用戶生效; MariaDB [(none)]> show variables like 'read_only'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | read_only | OFF | +---------------+-------+ 1 row in set (0.00 sec) [root@slave ~]$vim /etc/my.cnf [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # Settings user and group are ignored when systemd is used. innodb_file_per_table server_id=2 read_only MariaDB [(none)]> grant select,update,delete on *.* to test@'192.168.27.%' identified by 'centos'; Query OK, 0 rows affected (0.00 sec) [root@master ~]$mysql -utest -pcentos -h292.168.27.17 MariaDB [hellodb]> select * from students where age='22'; +-------+---------------+-----+--------+---------+-----------+ | StuID | Name | Age | Gender | ClassID | TeacherID | +-------+---------------+-----+--------+---------+-----------+ | 1 | Shi Zhongyu | 22 | M | 2 | 3 | | 2 | Shi Potian | 22 | M | 1 | 7 | | 21 | Huang Yueying | 22 | F | 6 | NULL | +-------+---------------+-----+--------+---------+-----------+ 3 rows in set (0.00 sec) MariaDB [hellodb]> delete from students; ERROR 1290 (HY000): The MariaDB server is running with the --read-only option so it cannot execute this statement另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。