MySQL master slave replication setup

mysql master slave replication setup


mysql Master and slave copy build


-------------------------Mysql Master slave copy --------------------------------------
Environmental Science
master 192.168.100.150
slave01 192.168.100.160
slave02 192.168.100.170
amoeba 192.168.100.130
client mysql 192.168.100.120
-------------------------- master server
master 192.168.100.150
1. modify /etc/my.cnf The configuration file , Add servers id, Configure binary log options
systemctl stop firewalld
set enforce 0
vim /etc/my.cnf
server-id = 11
log-bin=master-bin
log-slave-updates=true
systemctl restart mysqld.service
mysql -uroot -pabc123
mysql> grant replication slave on *.* to 'myslave'@'192.168.100.%' identified by '123456';
mysql> flush privileges;
mysql> show master status;
-------------------------- From the server -----------------------
slave01 192.168.100.160
vim /etc/my.cnf
'//mysqld Modify the field below '
server-id = 22
relay-log=relay-log-bin
relay-log-index=slave-relay-bin.index
mysql> change master to master_host='192.168.100.150',master_user='myslave',master_password='123456',master_log_file='master-bin.000013',master_log_pos=154;
flush privileges;
flush privileges;
mysql> start slave;
mysql> show slave status\G;
slave02 192.168.100.170
vim /etc/my.cnf
'//mysqld Modify the field below '
server-id = 23
relay-log=relay-log-bin
relay-log-index=slave-relay-bin.index
systemctl restart mysqld.service
mysql -uroot -pabc23
Enter password:
mysql> change master to master_host='192.168.100.150',master_user='myslave',master_password='123456',master_log_file='master-bin.000013',master_log_pos=154;
flush privileges;
mysql> start slave;
mysql> show slave status\G;
Slave_IO_Running: Yes '// Find out IO It's normal '
Slave_SQL_Running: Yes '//SQL It's normal '
---------------------------------- Read / write separation ----------------------------------
### The premise of read-write separation is that the master-slave service has been deployed
cd /opt
Upload jdk-6u14-linux-x64.bin amoeba-mysql-binary-2.2.0.tar.gz Two documents
cp jdk-6u14-linux-x64.bin /usr/local/
cd /usr/local/
chmod +x jdk-6u14-linux-x64.bin
./jdk-6u14-linux-x64.bin
Do you agree to the above license terms? [yes or no]
yes
mv jdk1.6.0_14/ jdk1.6
vim /etc/profile
export JAVA_HOME=/usr/local/jdk1.6
export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
export PATH=$JAVA_HOME/lib:$JAVA_HOME/jre/bin:$PATH:$HOME/bin
export AMOEBA_HOME=/usr/local/amoeba
export PATH=$PATH:$AMOEBA_HOME/bin
source /etc/profile
mkdir /usr/local/amoeba
cd /opt
tar zxvf amoeba-mysql-binary-2.2.0.tar.gz -C /usr/local/amoeba/
chmod -R 755 /usr/local/amoeba/
/usr/local/amoeba/bin/amoeba
Show amoeba start|stop // Description installation successful
*** Three stations mysql The server adds permissions and users to amoeba visit
mysql> grant all on *.* to 'test'@'192.168.100.%' identified by '123.com';
mysql> flush privileges;
show grants for 'test'@'192.168.100.%';
cd /usr/local/amoeba/conf
**** edit amoeba Master profile
vim amoeba.xml
// The first 30 Line modification
30 <property name="user">amoeba</property> // Customer access amoeba Account
31
32 <property name="password">123456</property> // Use 123456 Password access amoeba The server '
// The first 115 Line modification
// Turn on the read / write function pool settings '
115 <property name="defaultPool">master</property> // Modify the default address pool to master
116
117 <!-- --> '//117 Line uncomment '
118 <property name="writePool">master</property> // Revise and write as follows master
119 <property name="readPool">slaves</property> // Read it as slaves
120 //120 Line delete --> Annotation symbols
'// Edit database profile '
vim dbServers.xml
22 <!-- mysql schema -->
23 <property name="schema">mysql</property> '//amoeba The library read by default will test It is amended as follows mysql;23 That's ok test It is amended as follows mysql' 5.5 Version here is test, There was this library ,5.7 I didn't bring this with me test library , So revise
24
//' Set up amoeba visit mysql Database users and passwords '
25 <!-- mysql user -->
26 <property name="user">test</property> '//26 Line to modify the user name '
27
28 <!-- mysql password --> '//28 That's ok -30 Line uncomment '
29 <property name="password">123.com</property> '//29 Line change password '
45 <dbServer name="master" parent="abstractServer"> '//45 Owner mysql Change the server name to master'
46 <factoryConfig>
47 <!-- mysql ip -->
48 <property name="ipAddress">192.168.100.150</property> '48 That's ok // Modify the master server IP'
49 </factoryConfig>
50 </dbServer>
51
52 <dbServer name="slave1" parent="abstractServer"> '//52 Line modification from server 1 The name of '
53 <factoryConfig>
54 <!-- mysql ip -->
55 <property name="ipAddress">192.168.100.160</property> '// Modify from server 1 The address of '
56 </factoryConfig>
57 </dbServer>
58 ' Configure the above from the server 7 Copy the line and change the name slave2 and ip Address '
59 <dbServer name="slave2" parent="abstractServer"> '// Modify from server 2 The name of '
60 <factoryConfig>
61 <!-- mysql ip -->
62 <property name="ipAddress">192.168.100.170</property> '// Modify from server 1 The address of
63 </factoryConfig>
64 </dbServer>
65 '// Modify the database from the server pool '
66 <dbServer name="slaves" virtual="true"> // Change the name of the server to slaves'
67 <poolConfig class="com.meidusa.amoeba.server.MultipleServerPool">
68 <!-- Load balancing strategy: 1=ROUNDROBIN , 2=WEIGHTBASED , 3=HA-->
69 <property name="loadbalance">1</property>
70
71 <!-- Separated by commas,such as: server1,server2,server1 -->
72 <property name="poolNames">slave1,slave2</property> '// Add two slave server names slave1,slave2'
73 </poolConfig>
74 </dbServer>
Turn on amoeba Software , Put it in the background
[root@amoeba conf]# /usr/local/amoeba/bin/amoeba start &
[3] 11060
[root@amoeba conf]# log4j:WARN log4j config load completed from file:/usr/local/amoeba/conf/log4j.xml
2020-08-27 00:26:27,797 INFO context.MysqlRuntimeContext - Amoeba for Mysql current versoin=5.1.45-mysql-amoeba-proxy-2.2.0
log4j:WARN ip access config load completed from file:/usr/local/amoeba/conf/access_list.conf
2020-08-27 00:26:27,916 INFO net.ServerableConnectionManager - Amoeba for Mysql listening on 0.0.0.0/0.0.0.0:8066.
2020-08-27 00:26:27,916 INFO net.ServerableConnectionManager - Amoeba Monitor Server listening on /127.0.0.1:5790.
'// At this point, it is under continuous monitoring , Unable to enter command , But don't shut down , Connect a window to see if the port is open '
[root@amoeba ~]# netstat -ntap | grep 8066
tcp6 0 0 :::8066 :::* LISTEN 11060/java
-------------------------------------------- Client installation mysql verification --------------------------------------------[root@localhost ~]# yum install -y mysql
systemctl stop firewalld.service
setenforce 0
yum install mysql -y
mysql -u amoeba -pabc123 -h 192.168.100.130 -P8066
*** Test read-write separation , Turn off master-slave replication
Two slave servers shut down slave function
stop slave;
show slave status\G;
... Omit the content
Slave_IO_Running: No '// Discovery has been turned off '
Slave_SQL_Running: No
... Omit the content
*** Configure data from the server , Verify read-write separation
The client
MySQL [(none)]> create database accp;
Query OK, 1 row affected (0.02 sec)
mysql> show databases; // The master server can see accp library
+--------------------+
| Database |
+--------------------+
| information_schema |
| accp |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.00 sec)
mysql> show databases; // Neither can be seen from the server accp library
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
'// You will find that the primary server has , But the slave server doesn't have , Indicates that the master-slave copy function has been turned off '
*** Verify read separation
mysql> use mysql;
Database changed
mysql> create table info (id int not null,name char(10));
Query OK, 0 rows affected (0.01 sec)
mysql> insert into info values(1,'zhangsan'); '// add to zhangsan Record '
Query OK, 1 row affected (0.02 sec)
mysql> select * from info;
+----+----------+
| id | name |
+----+----------+
| 1 | zhangsan |
+----+----------+
1 row in set (0.00 sec)
'//slave1 Set up from the server :'
mysql> use mysql;
Database changed
mysql> create table info(id int not null,name char(10));
Query OK, 0 rows affected (0.01 sec)
mysql> insert into info values(2,'lisi'); '// add to lisi Record '
Query OK, 1 row affected (0.02 sec)
mysql> select * from info;
+----+------+
| id | name |
+----+------+
| 2 | lisi |
+----+------+
1 row in set (0.00 sec)
**** Client side test
MySQL [(none)]> use mysql;
MySQL [mysql]> select * from info;
+----+----------+
| id | name |
+----+----------+
| 1 | zhangsan |
+----+----------+
1 row in set (0.00 sec)
MySQL [mysql]> select * from info;
+----+------+
| id | name |
+----+------+
| 2 | lisi |
+----+------+
1 row in set (0.01 sec)
'// Found that every query will be polled in slave1 and slave2 Query data on , If you turn on master-slave replication , Then the data will be the same '
'// The separation of reading and writing was successful '
版权声明
本文为[http://www.bing.com/searc....tin-round+rock+texas]所创,转载请带上原文链接,感谢

  1. 【计算机网络 12(1),尚学堂马士兵Java视频教程
  2. 【程序猿历程,史上最全的Java面试题集锦在这里
  3. 【程序猿历程(1),Javaweb视频教程百度云
  4. Notes on MySQL 45 lectures (1-7)
  5. [computer network 12 (1), Shang Xuetang Ma soldier java video tutorial
  6. The most complete collection of Java interview questions in history is here
  7. [process of program ape (1), JavaWeb video tutorial, baidu cloud
  8. Notes on MySQL 45 lectures (1-7)
  9. 精进 Spring Boot 03:Spring Boot 的配置文件和配置管理,以及用三种方式读取配置文件
  10. Refined spring boot 03: spring boot configuration files and configuration management, and reading configuration files in three ways
  11. 精进 Spring Boot 03:Spring Boot 的配置文件和配置管理,以及用三种方式读取配置文件
  12. Refined spring boot 03: spring boot configuration files and configuration management, and reading configuration files in three ways
  13. 【递归,Java传智播客笔记
  14. [recursion, Java intelligence podcast notes
  15. [adhere to painting for 386 days] the beginning of spring of 24 solar terms
  16. K8S系列第八篇(Service、EndPoints以及高可用kubeadm部署)
  17. K8s Series Part 8 (service, endpoints and high availability kubeadm deployment)
  18. 【重识 HTML (3),350道Java面试真题分享
  19. 【重识 HTML (2),Java并发编程必会的多线程你竟然还不会
  20. 【重识 HTML (1),二本Java小菜鸟4面字节跳动被秒成渣渣
  21. [re recognize HTML (3) and share 350 real Java interview questions
  22. [re recognize HTML (2). Multithreading is a must for Java Concurrent Programming. How dare you not
  23. [re recognize HTML (1), two Java rookies' 4-sided bytes beat and become slag in seconds
  24. 造轮子系列之RPC 1:如何从零开始开发RPC框架
  25. RPC 1: how to develop RPC framework from scratch
  26. 造轮子系列之RPC 1:如何从零开始开发RPC框架
  27. RPC 1: how to develop RPC framework from scratch
  28. 一次性捋清楚吧,对乱糟糟的,Spring事务扩展机制
  29. 一文彻底弄懂如何选择抽象类还是接口,连续四年百度Java岗必问面试题
  30. Redis常用命令
  31. 一双拖鞋引发的血案,狂神说Java系列笔记
  32. 一、mysql基础安装
  33. 一位程序员的独白:尽管我一生坎坷,Java框架面试基础
  34. Clear it all at once. For the messy, spring transaction extension mechanism
  35. A thorough understanding of how to choose abstract classes or interfaces, baidu Java post must ask interview questions for four consecutive years
  36. Redis common commands
  37. A pair of slippers triggered the murder, crazy God said java series notes
  38. 1、 MySQL basic installation
  39. Monologue of a programmer: despite my ups and downs in my life, Java framework is the foundation of interview
  40. 【大厂面试】三面三问Spring循环依赖,请一定要把这篇看完(建议收藏)
  41. 一线互联网企业中,springboot入门项目
  42. 一篇文带你入门SSM框架Spring开发,帮你快速拿Offer
  43. 【面试资料】Java全集、微服务、大数据、数据结构与算法、机器学习知识最全总结,283页pdf
  44. 【leetcode刷题】24.数组中重复的数字——Java版
  45. 【leetcode刷题】23.对称二叉树——Java版
  46. 【leetcode刷题】22.二叉树的中序遍历——Java版
  47. 【leetcode刷题】21.三数之和——Java版
  48. 【leetcode刷题】20.最长回文子串——Java版
  49. 【leetcode刷题】19.回文链表——Java版
  50. 【leetcode刷题】18.反转链表——Java版
  51. 【leetcode刷题】17.相交链表——Java&python版
  52. 【leetcode刷题】16.环形链表——Java版
  53. 【leetcode刷题】15.汉明距离——Java版
  54. 【leetcode刷题】14.找到所有数组中消失的数字——Java版
  55. 【leetcode刷题】13.比特位计数——Java版
  56. oracle控制用户权限命令
  57. 三年Java开发,继阿里,鲁班二期Java架构师
  58. Oracle必须要启动的服务
  59. 万字长文!深入剖析HashMap,Java基础笔试题大全带答案
  60. 一问Kafka就心慌?我却凭着这份,图灵学院vip课程百度云