mysql復制主從集群搭建

近期搭了個主從復制。中間出了點小問題,排查搞定,記錄下來


1
環境:
虛擬機:
OS:
centos6.5
Linux host2 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux


serverIP
192.168.18.66
192.168.18.67


DB:
mysql> select version();
+-----------+
| version() |
+-----------+
| 5.6.20 ? ?|
+-----------+


2
主機:192.168.18.66
從機:192.168.18.67


3
改動主server配置,加入例如以下內容:
? server-id=10
? log-bin=mysql-bin
? binlog-ignore-db=mysql
? binlog-ignore-db=information_schema
? binlog-ignore-db=performance_schema
? replicate-do-db=reptest


此時主server這個配置文件/etc/my.cnf內容例如以下:
[client]
#password = system
#port = 3306
default-character-set=utf8


[mysqld]


server-id=10
log-bin=mysql-bin
binlog-ignore-db=mysql
binlog-ignore-db=information_schema
binlog-ignore-db=performance_schema
replicate-do-db=reptest


sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES?


port=3306
character_set_server=utf8
character_set_client=utf8
collation-server=utf8_general_ci
lower_case_table_names=1
max_connections=500


[mysql]
default-character-set=utf8


4
改動從server配置
? ?server-id=20
? ?relay_log=mysql-relay-bin
? ?read_only


此時從server配置文件內容例如以下:
[client]
#password=system
#port=3306
default-character-set=utf8


[mysqld]


server-id=20
relay_log=mysql-relay-bin
#read_only
#log_slave_updates=1


#master-host=192.168.18.66
#master-user=repl
#master-password=123
#master-port=3306
#master-connect-retry=60
#replicate_do_db=reptest
#replicate_ignore_db=mysql,information_schema,performance_schema


sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
port=3306
character_set_server=utf8
character_set_client=utf8
collation-server=utf8_general_ci
lower_case_table_names=1
max_connections=500


[mysql]
default-character-set=utf8


mysql復制的相關參數可參考以下的網頁:
http://dev.mysql.com/doc/refman/5.5/en/replication-options-slave.html




5
在主上添加復制用戶
mysql> grant replication slave on *.* to 'repl'@'%' identified by '123456';
flush privileges;


192.168.18.67是從server,就通過repl用戶password為空來同步復制


mysql> select host,user,Repl_slave_priv from mysql.user where user='repl';
+---------------+------+-----------------+
| host ? ? ? ? ?| user | Repl_slave_priv |
+---------------+------+-----------------+
| 192.168.18.67 | repl | Y ? ? ? ? ? ? ? |
+---------------+------+-----------------+
1 row in set (0.00 sec)


6
重新啟動主從server:
停主。停從
mysqladmin -uroot shutdown -psystem
起從,起主
/etc/init.d/mysql start


[root@host3 ~]# /etc/init.d/mysql start
Starting MySQL.. SUCCESS!?


7
導出主數據庫數據。取快照
1)鎖主庫
?flush tables with read lock;


2)
這一步比較重要,要記住File和Position值,在起從server上的slave線程時備用
mysql> show master status \G
*************************** 1. row ***************************
? ? ? ? ? ? ?File: mysql-bin.000002
? ? ? ? ?Position: 401
? ? ?Binlog_Do_DB:?
?Binlog_Ignore_DB: mysql,information_schema,performance_schema
Executed_Gtid_Set:?
1 row in set (0.00 sec)


3)
[root@host3 ~]# mysqldump -uroot -p ?reptest --triggers --routines --events > /home/zxw/master_reptest.sql


順便看一下,mysqldump的內容例如以下:
[root@host3 ~]# ll /home/zxw/
total 4
-rw-r--r--. 1 root root 1910 Aug 25 13:50 master_reptest.sql
[root@host3 ~]# nl /home/zxw/master_reptest.sql?
? ? ?1 ?-- MySQL dump 10.13 ?Distrib 5.6.20, for Linux (x86_64)
? ? ?2 ?--
? ? ?3 ?-- Host: localhost ? ?Database: reptest
? ? ?4 ?-- ------------------------------------------------------
? ? ?5 ?-- Server version ? ? ? 5.6.20-log
? ? ? ?
? ? ?6 ?/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
? ? ?7 ?/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
? ? ?8 ?/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
? ? ?9 ?/*!40101 SET NAMES utf8 */;
? ? 10 ?/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
? ? 11 ?/*!40103 SET TIME_ZONE='+00:00' */;
? ? 12 ?/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
? ? 13 ?/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
? ? 14 ?/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
? ? 15 ?/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
? ? ? ?
? ? 16 ?--
? ? 17 ?-- Table structure for table `tbldata`
? ? 18 ?--
? ? ? ?
? ? 19 ?DROP TABLE IF EXISTS `tbldata`;
? ? 20 ?/*!40101 SET @saved_cs_client ? ? = @@character_set_client */;
? ? 21 ?/*!40101 SET character_set_client = utf8 */;
? ? 22 ?CREATE TABLE `tbldata` (
? ? 23 ? ?`id` int(11) DEFAULT NULL
? ? 24 ?) ENGINE=InnoDB DEFAULT CHARSET=utf8;
? ? 25 ?/*!40101 SET character_set_client = @saved_cs_client */;
? ? ? ?
? ? 26 ?--
? ? 27 ?-- Dumping data for table `tbldata`
? ? 28 ?--
? ? ? ?
? ? 29 ?LOCK TABLES `tbldata` WRITE;
? ? 30 ?/*!40000 ALTER TABLE `tbldata` DISABLE KEYS */;
? ? 31 ?INSERT INTO `tbldata` VALUES (1),(2),(3);
? ? 32 ?/*!40000 ALTER TABLE `tbldata` ENABLE KEYS */;
? ? 33 ?UNLOCK TABLES;
? ? ? ?
? ? 34 ?--
? ? 35 ?-- Dumping events for database 'reptest'
? ? 36 ?--
? ? ? ?
? ? 37 ?--
? ? 38 ?-- Dumping routines for database 'reptest'
? ? 39 ?--
? ? 40 ?/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
? ? ? ?
? ? 41 ?/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
? ? 42 ?/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
? ? 43 ?/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
? ? 44 ?/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
? ? 45 ?/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
? ? 46 ?/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
? ? 47 ?/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
? ? ? ?
? ? 48 ?-- Dump completed on 2014-08-25 13:50:48


4)
解鎖數據庫
mysql> unlock tables;
Query OK, 0 rows affected (0.00 sec)


############################
###拷貝數據文件文件夾方式#####
############################
#另外一種取主數據庫快照的方法
#mysqladmin -uroot shutdown
#打包數據庫數據文件夾,比如數據文件夾是/data/dbdata:
#cd /data
#tar zcvf dbdata.tar.gz dbdata
#備份后就能夠啟動主server了:
#mysqld_safe –user=mysql &


8
在從server上恢復主庫快照
1)
在從庫上創建數據庫
mysql> create database reptest;
Query OK, 1 row affected (0.00 sec)
2)
拷貝備份腳本到從server
[root@host2 ~]# scp root@192.168.18.66:/home/zxw/master_reptest.sql /home/zxw/
3)
主庫快照導入到從庫
[root@host2 ~]# mysql -uroot -psystem reptest < /home/zxw/master_reptest.sql?
Warning: Using a password on the command line interface can be insecure.
4)
驗證:
[root@host2 ~]# mysql -uroot -psystem
mysql> use reptest;
mysql>?
mysql> show tables
? ? -> ;
+-------------------+
| Tables_in_reptest |
+-------------------+
| tbldata ? ? ? ? ? |
+-------------------+
1 row in set (0.00 sec)


mysql> select * from tbldata;
+------+
| id ? |
+------+
| ? ?1 |
| ? ?2 |
| ? ?3 |
+------+
3 rows in set (0.00 sec)


mysql>?


############################
###拷貝數據文件文件夾方式#####
############################
#備份文件方式的導入
#因為須要置換成主server的數據文件夾,先關閉服務:
#mysqladmin -uroot shutdown
#備份數據文件夾
#mv dbdata dbdata.bak
#解包從主server拷貝來的數據文件夾
#tar zxvf dbdata.tar.gz
#要確保文件的權限屬主等設置沒問題。dbdata文件夾應該是mysql:mysql用戶全部。


9
1)
在從server上操作,連接主server開始同步數據:
mysql> Change master to Master_host = '192.168.18.66', Master_port = 3306, Master_user = 'repl', Master_password = '123456', Master_log_file = 'mysql-bin.000002', Master_log_pos = 401;
Query OK, 0 rows affected, 2 warnings (0.11 sec)
mysql>?
這里包括的信息有主機的地址和port、主機提供的復制帳號、主機的binlog位置信息。

Master_log_file和Master_log_pos是主server的快照信息(就是第7不第2小步看到的值),從server從該binlog的對應位置開始從主server同步數據。


2)
啟動從server線程就能夠開始同步了:
start slave;
一旦從server開始同步了,就能在數據文件文件夾下找到2個文件master.info和relay-log.info。從server利用這2個文件來跟蹤處理了多少master的binlog。
分別在主從servershow processlist查看連接,就能夠看到repl用戶的連接,可證明復制已經生效。


從:
mysql> show slave status \G
*************************** 1. row ***************************
? ? ? ? ? ? ? ?Slave_IO_State: Waiting for master to send event
? ? ? ? ? ? ? ? ? Master_Host: 192.168.18.66
? ? ? ? ? ? ? ? ? Master_User: usrep
? ? ? ? ? ? ? ? ? Master_Port: 3306
? ? ? ? ? ? ? ? Connect_Retry: 60
? ? ? ? ? ? ? Master_Log_File: mysql-bin.000004
? ? ? ? ? Read_Master_Log_Pos: 1264
? ? ? ? ? ? ? ?Relay_Log_File: mysql-relay-bin.000021
? ? ? ? ? ? ? ? Relay_Log_Pos: 283
? ? ? ? Relay_Master_Log_File: mysql-bin.000004
? ? ? ? ? ? ?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: 1264
? ? ? ? ? ? ? Relay_Log_Space: 1075
? ? ? ? ? ? ? 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: 10
? ? ? ? ? ? ? ? ? Master_UUID: c03d6252-2a2f-11e4-9b48-000c291888ce
? ? ? ? ? ? ?Master_Info_File: /var/lib/mysql/master.info
? ? ? ? ? ? ? ? ? ? SQL_Delay: 0
? ? ? ? ? SQL_Remaining_Delay: NULL
? ? ? Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
? ? ? ? ? ?Master_Retry_Count: 86400
? ? ? ? ? ? ? ? ? Master_Bind:?
? ? ? Last_IO_Error_Timestamp:?
? ? ?Last_SQL_Error_Timestamp:?
? ? ? ? ? ? ? ?Master_SSL_Crl:?
? ? ? ? ? ?Master_SSL_Crlpath:?
? ? ? ? ? ?Retrieved_Gtid_Set:?
? ? ? ? ? ? Executed_Gtid_Set:?
? ? ? ? ? ? ? ? Auto_Position: 0
1 row in set (0.00 sec)


主:能夠看到以下內容
mysql> show processlist \G
*************************** 2. row ***************************
? ? ?Id: 11
? ?User: usrep
? ?Host: 192.168.18.67:48746
? ? ?db: NULL
Command: Binlog Dump
? ?Time: 179
? State: Master has sent all binlog to slave; waiting for binlog to be updated
? ?Info: NULL
2 rows in set (0.00 sec)




從server:
數據文件里相關文件例如以下
[root@host2 ~]# ll /var/lib/mysql/
-rw-rw----. 1 mysql mysql ? ? ?128 Aug 28 11:32 master.info
-rw-rw----. 1 mysql mysql ? ? ? 59 Aug 28 11:32 relay-log.info


-rw-rw----. 1 mysql mysql ? ? ?792 Aug 28 11:32 mysql-relay-bin.000020
-rw-rw----. 1 mysql mysql ? ? ?283 Aug 28 11:32 mysql-relay-bin.000021
-rw-rw----. 1 mysql mysql ? ? ? 50 Aug 28 11:32 mysql-relay-bin.index


主server:
數據文件里相關文件例如以下
-rw-rw----. 1 mysql mysql ? ? 1036 Aug 28 09:32 mysql-bin.000003
-rw-rw----. 1 mysql mysql ? ? 1264 Aug 28 11:04 mysql-bin.000004
-rw-rw----. 1 mysql mysql ? ? ? 76 Aug 28 09:32 mysql-bin.index




到這兒就ok了


以下說一下在配置過程中遇到的問題:


問題1
1
剛搭完跑起來一看。有問題,Slave_IO_Running: Connecting,IO線程鏈接主服務進程沒有成功
mysql> show slave status \G;
*************************** 1. row ***************************
? ? ? ? ? ? ? ?Slave_IO_State: Connecting to master
? ? ? ? ? ? ? ? ? Master_Host: 192.168.18.66
? ? ? ? ? ? ? ? ? Master_User: repl
? ? ? ? ? ? ? ? ? Master_Port: 3306
? ? ? ? ? ? ? ? Connect_Retry: 60
? ? ? ? ? ? ? Master_Log_File: mysql-bin.000002
? ? ? ? ? Read_Master_Log_Pos: 401
? ? ? ? ? ? ? ?Relay_Log_File: host2-relay-bin.000001
? ? ? ? ? ? ? ? Relay_Log_Pos: 4
? ? ? ? Relay_Master_Log_File: mysql-bin.000002
? ? ? ? ? ? ?Slave_IO_Running: Connecting
? ? ? ? ? ? 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: 401
? ? ? ? ? ? ? Relay_Log_Space: 120
? ? ? ? ? ? ? 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: NULL
Master_SSL_Verify_Server_Cert: No
? ? ? ? ? ? ? ? Last_IO_Errno: 2003
? ? ? ? ? ? ? ? Last_IO_Error: error connecting to master 'repl@192.168.18.66:3306' - retry-time: 60 ?retries: 1
? ? ? ? ? ? ? ?Last_SQL_Errno: 0
? ? ? ? ? ? ? ?Last_SQL_Error:?
? Replicate_Ignore_Server_Ids:?
? ? ? ? ? ? ?Master_Server_Id: 0
? ? ? ? ? ? ? ? ? Master_UUID:?
? ? ? ? ? ? ?Master_Info_File: /var/lib/mysql/master.info
? ? ? ? ? ? ? ? ? ? SQL_Delay: 0
? ? ? ? ? SQL_Remaining_Delay: NULL
? ? ? Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
? ? ? ? ? ?Master_Retry_Count: 86400
? ? ? ? ? ? ? ? ? Master_Bind:?
? ? ? Last_IO_Error_Timestamp: 140825 14:29:05
? ? ?Last_SQL_Error_Timestamp:?
? ? ? ? ? ? ? ?Master_SSL_Crl:?
? ? ? ? ? ?Master_SSL_Crlpath:?
? ? ? ? ? ?Retrieved_Gtid_Set:?
? ? ? ? ? ? Executed_Gtid_Set:?
? ? ? ? ? ? ? ? Auto_Position: 0
1 row in set (0.00 sec)


問題1
2
查看日志有例如以下內容
[root@host2 ~]# tail -n 30 /var/lib/mysql/host2.err?
2014-08-27 17:04:37 2384 [ERROR] Slave I/O: error connecting to master 'repl@192.168.18.66:3306' - retry-time: 60 ?retries: 1, Error_code: 2003
2014-08-27 17:04:37 2384 [Warning] Slave SQL: If a crash happens this configuration does not guarantee that the relay log info will be consistent, Error_code: 0
2014-08-27 17:04:37 2384 [Note] Slave SQL thread initialized, starting replication in log 'mysql-bin.000003' at position 120, relay log './mysql-relay-bin.000001' position: 4
2014-08-27 17:05:12 2384 [Note] Error reading relay log event: slave SQL thread was killed
2014-08-27 17:05:12 2384 [Note] Slave I/O thread killed while connecting to master
2014-08-27 17:05:12 2384 [Note] Slave I/O thread exiting, read up to log 'mysql-bin.000003', position 120




問題1
3
在主上新建一個全權用戶。在從上用這個用戶做復制。結果一致
主:
mysql> grant all on *.* to 'usrep'@'%' identified by '123456';

mysql> Change master to Master_host = '192.168.18.66', Master_port = 3306, Master_user = 'repl', Master_password = '123456', Master_log_file = 'mysql-bin.000002', Master_log_pos = 401;
用usrep在從上起slave復制線程,問題依然


問題1
4
在主上mysql -uusrep -p直接登錄主數據庫,成功。
在從上mysql -h 192.168.18.67 -uusrep -p登錄主數據庫。失敗。
[root@host2 ~]# mysql -h 192.168.18.67 -uroot -psystem
Warning: Using a password on the command line interface can be insecure.
ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.18.66' (113)


問題1
5
查看主的iptable
[root@host3 ~]# iptables -L
Chain INPUT (policy ACCEPT)
target ? ? prot opt source ? ? ? ? ? ? ? destination ? ? ? ??
ACCEPT ? ? all ?-- ?anywhere ? ? ? ? ? ? anywhere ? ? ? ? ? ?state RELATED,ESTABLISHED?
ACCEPT ? ? icmp -- ?anywhere ? ? ? ? ? ? anywhere ? ? ? ? ? ?
ACCEPT ? ? all ?-- ?anywhere ? ? ? ? ? ? anywhere ? ? ? ? ? ?
ACCEPT ? ? tcp ?-- ?anywhere ? ? ? ? ? ? anywhere ? ? ? ? ? ?state NEW tcp dpt:ssh?
REJECT ? ? all ?-- ?anywhere ? ? ? ? ? ? anywhere ? ? ? ? ? ?reject-with icmp-host-prohibited?


Chain FORWARD (policy ACCEPT)
target ? ? prot opt source ? ? ? ? ? ? ? destination ? ? ? ??
REJECT ? ? all ?-- ?anywhere ? ? ? ? ? ? anywhere ? ? ? ? ? ?reject-with icmp-host-prohibited?


Chain OUTPUT (policy ACCEPT)
target ? ? prot opt source ? ? ? ? ? ? ? destination ? ? ? ??


問題1
6
打開文件 /etc/sysconfig/iptables(該文件路徑因操作系統而異),文件內容例如以下:
[root@host3 ~]# nl /etc/sysconfig/iptables
? ? ?1 ?# Firewall configuration written by system-config-firewall
? ? ?2 ?# Manual customization of this file is not recommended.
? ? ?3 ?*filter
? ? ?4 ?:INPUT ACCEPT [0:0]
? ? ?5 ?:FORWARD ACCEPT [0:0]
? ? ?6 ?:OUTPUT ACCEPT [0:0]
? ? ?7 ?-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
? ? ?8 ?-A INPUT -p icmp -j ACCEPT
? ? ?9 ?-A INPUT -i lo -j ACCEPT
? ? 10 ?-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
? ? 11 ?-A INPUT -j REJECT --reject-with icmp-host-prohibited
? ? 12 ?-A FORWARD -j REJECT --reject-with icmp-host-prohibited
? ? 13 ?COMMIT


編輯該文件添加一行,放開tcp的3306port
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
結果例如以下
[root@host3 ~]# nl /etc/sysconfig/iptables
? ? ?1 ?# Firewall configuration written by system-config-firewall
? ? ?2 ?# Manual customization of this file is not recommended.
? ? ?3 ?*filter
? ? ?4 ?:INPUT ACCEPT [0:0]
? ? ?5 ?:FORWARD ACCEPT [0:0]
? ? ?6 ?:OUTPUT ACCEPT [0:0]
? ? ?7 ?-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
? ? ?8 ?-A INPUT -p icmp -j ACCEPT
? ? ?9 ?-A INPUT -i lo -j ACCEPT
? ? 10 ?-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
? ? 11 ?-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
? ? 12 ?-A INPUT -j REJECT --reject-with icmp-host-prohibited
? ? 13 ?-A FORWARD -j REJECT --reject-with icmp-host-prohibited
? ? 14 ?COMMIT


重新啟動iptable服務
[root@host3 ~]# /etc/init.d/iptables restart


查看現有iptables規則:
[root@host3 ~]# iptables -L
Chain INPUT (policy ACCEPT)
target ? ? prot opt source ? ? ? ? ? ? ? destination ? ? ? ??
ACCEPT ? ? all ?-- ?anywhere ? ? ? ? ? ? anywhere ? ? ? ? ? ?state RELATED,ESTABLISHED?
ACCEPT ? ? icmp -- ?anywhere ? ? ? ? ? ? anywhere ? ? ? ? ? ?
ACCEPT ? ? all ?-- ?anywhere ? ? ? ? ? ? anywhere ? ? ? ? ? ?
ACCEPT ? ? tcp ?-- ?anywhere ? ? ? ? ? ? anywhere ? ? ? ? ? ?state NEW tcp dpt:ssh?
ACCEPT ? ? tcp ?-- ?anywhere ? ? ? ? ? ? anywhere ? ? ? ? ? ?state NEW tcp dpt:mysql?
REJECT ? ? all ?-- ?anywhere ? ? ? ? ? ? anywhere ? ? ? ? ? ?reject-with icmp-host-prohibited?


Chain FORWARD (policy ACCEPT)
target ? ? prot opt source ? ? ? ? ? ? ? destination ? ? ? ??
REJECT ? ? all ?-- ?anywhere ? ? ? ? ? ? anywhere ? ? ? ? ? ?reject-with icmp-host-prohibited?


Chain OUTPUT (policy ACCEPT)
target ? ? prot opt source ? ? ? ? ? ? ? destination ?


問題1
7
再在從上啟動slave復制線程。問題解決:
mysql> show slave status \G
*************************** 1. row ***************************
? ? ? ? ? ? ? ?Slave_IO_State: Waiting for master to send event
? ? ? ? ? ? ? ? ? Master_Host: 192.168.18.66
? ? ? ? ? ? ? ? ? Master_User: usrep
? ? ? ? ? ? ? ? ? Master_Port: 3306
? ? ? ? ? ? ? ? Connect_Retry: 60
? ? ? ? ? ? ? Master_Log_File: mysql-bin.000004
? ? ? ? ? Read_Master_Log_Pos: 1264
? ? ? ? ? ? ? ?Relay_Log_File: mysql-relay-bin.000021
? ? ? ? ? ? ? ? Relay_Log_Pos: 283
? ? ? ? Relay_Master_Log_File: mysql-bin.000004
? ? ? ? ? ? ?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: 1264
? ? ? ? ? ? ? Relay_Log_Space: 1075
? ? ? ? ? ? ? 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: 10
? ? ? ? ? ? ? ? ? Master_UUID: c03d6252-2a2f-11e4-9b48-000c291888ce
? ? ? ? ? ? ?Master_Info_File: /var/lib/mysql/master.info
? ? ? ? ? ? ? ? ? ? SQL_Delay: 0
? ? ? ? ? SQL_Remaining_Delay: NULL
? ? ? Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
? ? ? ? ? ?Master_Retry_Count: 86400
? ? ? ? ? ? ? ? ? Master_Bind:?
? ? ? Last_IO_Error_Timestamp:?
? ? ?Last_SQL_Error_Timestamp:?
? ? ? ? ? ? ? ?Master_SSL_Crl:?
? ? ? ? ? ?Master_SSL_Crlpath:?
? ? ? ? ? ?Retrieved_Gtid_Set:?
? ? ? ? ? ? Executed_Gtid_Set:?
? ? ? ? ? ? ? ? Auto_Position: 0
1 row in set (0.00 sec)




此時主從復制搭建完畢。測試了能夠正常執行。


問題2
想把從數據庫搞成僅僅讀的,在配置文件里加read_only參數及各種賦值和啟停從庫n次,沒有達到預期效果,依舊能夠直接連從庫進行增刪改。
此處特詭異,改日再試








災難恢復


主從不同步
假設主從同步出現了不一致。就須要又一次實施主從復制。步驟和上面同樣,僅僅是省略了改動配置文件和創建用戶的步驟。
又一次配置之前,須要在從server停止同步線程:stop slave;


從從server恢復
假設主機掛了,能夠把從server提升為主機,把原主server作為備機。


先在從server停止同步線程:
stop slave;
在從server上加入同步用戶:
grant replication slave on *.* to repl@'從serverip' identified by '123456';
flush privileges;
配置文件里my.cnf的server-id能夠不改動,僅僅要保證id不沖突即可了。

然后。依照主從復制的步驟來進行操作。



-----------------?

轉載請著明出處:
blog.csdn.net/beiigang

轉載于:https://www.cnblogs.com/jzdwajue/p/6999714.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/392479.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/392479.shtml
英文地址,請注明出處:http://en.pswp.cn/news/392479.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

java jolt tuxedo_java通過jolt調用tuxedo服務.xls

java通過jolt調用tuxedo服務.xls還剩20頁未讀&#xff0c;繼續閱讀下載文檔到電腦&#xff0c;馬上遠離加班熬夜&#xff01;親&#xff0c;喜歡就下載吧&#xff0c;價低環保&#xff01;內容要點&#xff1a;?private bea.jolt.pool.servlet.ServletSessionPoolManager bool…

你的周末時光是什么樣的?

周末是一個特殊的假日&#xff0c;隔三差五就會有&#xff0c;來的容易去得也容易&#xff0c;即便如此&#xff0c;我們還是應該好好珍惜&#xff0c;周末可以做的事太多了&#xff0c;既可以用來減壓&#xff0c;也可以為下一周的學習和工作充電&#xff0c;不管做什么&#…

leetcode 290. 單詞規律(hash)

給定一種規律 pattern 和一個字符串 str &#xff0c;判斷 str 是否遵循相同的規律。 這里的 遵循 指完全匹配&#xff0c;例如&#xff0c; pattern 里的每個字母和字符串 str 中的每個非空單詞之間存在著雙向連接的對應規律。 示例1: 輸入: pattern “abba”, str “dog…

2019年微博用戶畫像_2019年您需要了解的有關用戶的信息

2019年微博用戶畫像by Yisroel Yakovson通過伊斯洛爾雅科夫森 2019年您需要了解的有關用戶的信息 (What You Need to Know About Your Users in 2019) Users have changed a lot in the last few years. We programmers may have a culture gap to overcome in this area. If …

使用lt;jsp:includegt;,不想寫死URL,動態生成URL的解決的方法

JSP中文件包括有2種方式&#xff0c;靜態包括和動態包括。靜態包括使用<% include file"" %>。動態包括使用<jsp:include page"" />。本文不打算介紹這2種方式的差別和使用場景&#xff0c;主要關注page和file屬性的路徑問題。 假設事先知道被…

java udp ip端口 設置_UDP端口掃描Java只找到1個開放的UDP端口

我對端口掃描有一個分歧.我在Java中掃描一些IP地址的UDP端口.在我的程序中(假設一切正常)我只能找到一個開放的UDP端口.在另一方面端口掃描“nmap”我得到4個開放的UDP端口.有人可以告訴我為什么我不能通過Java代碼找到多個端口&#xff1f;順便說一句,我可以在我的代碼中找到真…

pandas之Seris和DataFrame

pandas是一個強大的python工具包&#xff0c;提供了大量處理數據的函數和方法&#xff0c;用于處理數據和分析數據。 使用pandas之前需要先安裝pandas包&#xff0c;并通過import pandas as pd導入。 一、系列Series Seris為帶標簽的一維數組&#xff0c;標簽即為索引。 1.Seri…

機器學習:分類_機器學習基礎:K最近鄰居分類

機器學習:分類In the previous stories, I had given an explanation of the program for implementation of various Regression models. Also, I had described the implementation of the Logistic Regression model. In this article, we shall see the algorithm of the K…

leetcode 714. 買賣股票的最佳時機含手續費(dp)

給定一個整數數組 prices&#xff0c;其中第 i 個元素代表了第 i 天的股票價格 &#xff1b;非負整數 fee 代表了交易股票的手續費用。 你可以無限次地完成交易&#xff0c;但是你每筆交易都需要付手續費。如果你已經購買了一個股票&#xff0c;在賣出它之前你就不能再繼續購買…

如何在Angular Material中制作自定義主題

by Charlee Li通過李李 如何在Angular Material中制作自定義主題 (How to make a custom theme in Angular Material) Angular Material is a great library that implements Material Design for Angular 2. The official document is sufficient regarding the component us…

最感嘆的莫過于一見如故,最悲傷的莫過于再見陌路。最深的孤獨,是你明知道自己的渴望,卻得對它裝聾作啞。最美的你不是生如夏花,而是在時間的長河里,波瀾不驚。...

最感嘆的莫過于一見如故&#xff0c;最悲傷的莫過于再見陌路。最深的孤獨&#xff0c;是你明知道自己的渴望&#xff0c;卻得對它裝聾作啞。最美的你不是生如夏花&#xff0c;而是在時間的長河里&#xff0c;波瀾不驚。轉載于:https://www.cnblogs.com/dj258/p/7003890.html

java vimrc_.vimrc技巧

-------------------------------------------------------------------" 設置字符編碼。參考&#xff1a;http://www.rainux.org/blog/index.php/2005/10/20/106" encoding: Vim 內部使用的字符編碼方式&#xff0c;包括 Vim 的buffer (緩沖區)、菜單文" 本、消…

將PDF和Gutenberg文檔格式轉換為文本:生產中的自然語言處理

Estimates state that 70%–85% of the world’s data is text (unstructured data). Most of the English and EU business data formats as byte text, MS Word, or Adobe PDF. [1]據估計&#xff0c;全球數據的70&#xff05;–85&#xff05;是文本(非結構化數據)。 大多數…

Go_筆試題記錄-指針與值類型實現接口的區別

1、如果Add函數的調用代碼為&#xff1a; func main() {var a Integer 1var b Integer 2var i interface{} &asum : i.(*Integer).Add(b)fmt.Println(sum) } 則Add函數定義正確的是&#xff08;&#xff09; A.type Integer int func (a Integer) Add(b Integer) Intege…

leetcode 48. 旋轉圖像

解題思路 將數組從里到外分為若干層&#xff0c; 數組 [1,2,3], [4,5,6][7,8,9]的最外層即為 [1,2,3] [4 6][7,8,9] &#xff0c;將一層分為4條邊&#xff0c;如741 123&#xff0c;將741放到123的位置&#xff0c;123放到369的位置&#xff0c;如此類推&#xff08;但是放置的…

如何恢復誤刪的OneNote頁面

今天不小心把半個月的日記刪掉了&#xff01;&#xff08;為了減少頁面數量&#xff0c;每個月的日記會放在同一個頁面上&#xff09;。 幸運的是OneNote有自動備份功能&#xff0c;喜極而泣。 操作方法來自微軟支持 打開丟失了最近筆記的筆記本。 單擊“文件”>“信息”&g…

javascript函數式_JavaScript中的函數式編程原理

javascript函數式After a long time learning and working with object-oriented programming, I took a step back to think about system complexity.經過長時間的學習和使用面向對象的編程&#xff0c;我退后了一步來思考系統的復雜性。 “Complexity is anything that mak…

java writeint_Java DataOutputStream.writeInt(int v)類型

DataOutputStream.writeInt(int v)方法示例DataOutputStream的DataOutputStream.writeInt(int v)方法具有以下語法。public final void writeInt(int v) throws IOException示例在下面的代碼中展示了如何使用DataOutputStream.writeInt(int v)方法。import java.io.DataInputSt…

協方差意味著什么_“零”到底意味著什么?

協方差意味著什么When I was an undergraduate student studying Data Science, one of my professors always asked the same question for every data set we worked with — “What does zero mean?”當我是一名研究數據科學的本科生時&#xff0c;我的一位教授總是對我們處…

Go_筆試題記錄-不熟悉的

1、golang中沒有隱藏的this指針&#xff0c;這句話的含義是&#xff08;&#xff09; A. 方法施加的對象顯式傳遞&#xff0c;沒有被隱藏起來 B. golang沿襲了傳統面向對象編程中的諸多概念&#xff0c;比如繼承、虛函數和構造函數 C. golang的面向對象表達更直觀&#xff0c;對…