当前位置:   article > 正文

linux搭建mysql集群_linux mysql集群搭建

linux mysql集群搭建

背景:有三台服务器master,slaver1,slaver2,想要搭建一个mysql数据库集群。

具体步骤:

1.首先要在三台服务器上安装好单机版的mysql,版本什么的都随意。

2.编辑/etc/my.cnf文件,这是mysql最重要的配置文件

在[mysqld]下面添加如下两行
log-bin=mysql-bin
server-id=18

其中需要注意的时server-id三台服务器不能相同

3.登录mysql命令行,执行如下命令

grant replication slave on *.* to root @'slaver1的ip' identified by 'root';

  1. MariaDB [mysql]> grant replication slave on *.* to root@'slaver1的ip' identified by 'root';
  2. Query OK, 0 rows affected (0.00 sec)

grant replication slave on *.* to root @'slaver2的ip' identified by 'root';

  1. MariaDB [mysql]> grant replication slave on *.* to root@'slaver2的ip' identified by 'root';
  2. Query OK, 0 rows affected (0.00 sec)

再执行show master status;命令查出以下内容,供下一步使用

  1. MariaDB [mysql]> show master status;
  2. +------------------+----------+--------------+------------------+
  3. | File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
  4. +------------------+----------+--------------+------------------+
  5. | mysql-bin.000001 | 459 | | |
  6. +------------------+----------+--------------+------------------+

4.在两台从服务器上分别执行如下命令,来绑定主从关系,如果执行失败可以执行flush privileges命令来刷新一下

  1. MariaDB [mysql]> change master to master_user='root',master_password='root',master_host='master',master_log_file='mysql-bin.000001',master_log_pos=459;
  2. Query OK, 0 rows affected (0.01 sec)

绑定之后可以通过以下命令查看刚刚的操作有没有执行成功。

  1. [root@slave-1 ~]# cd /var/lib/mysql/
  2. [root@slave-1 mysql]# cat master.info
  3. 18
  4. mysql-bin.000001
  5. 459
  6. master
  7. root
  8. root
  9. 3306
  10. 60
  11. 0

5.最后还要执行show slave status\G;命令验证一下两个参数

Slave_IO_Running: Yes
Slave_SQL_Running: Yes

如果都是yes,则成功了。

  1. MariaDB [mysql]> show slave status\G;
  2. *************************** 1. row ***************************
  3. Slave_IO_State: Queueing master event to the relay log
  4. Master_Host: master
  5. Master_User: root
  6. Master_Port: 3306
  7. Connect_Retry: 60
  8. Master_Log_File: mysql-bin.000001
  9. Read_Master_Log_Pos: 673
  10. Relay_Log_File: mariadb-relay-bin.002150
  11. Relay_Log_Pos: 529
  12. Relay_Master_Log_File: mysql-bin.000001
  13. Slave_IO_Running: Yes
  14. Slave_SQL_Running: Yes
  15. Replicate_Do_DB:
  16. Replicate_Ignore_DB:
  17. Replicate_Do_Table:
  18. Replicate_Ignore_Table:
  19. Replicate_Wild_Do_Table:
  20. Replicate_Wild_Ignore_Table:
  21. Last_Errno: 0
  22. Last_Error:
  23. Skip_Counter: 0
  24. Exec_Master_Log_Pos: 673
  25. Relay_Log_Space: 1448
  26. Until_Condition: None
  27. Until_Log_File:
  28. Until_Log_Pos: 0
  29. Master_SSL_Allowed: No
  30. Master_SSL_CA_File:
  31. Master_SSL_CA_Path:
  32. Master_SSL_Cert:
  33. Master_SSL_Cipher:
  34. Master_SSL_Key:
  35. Seconds_Behind_Master: 0
  36. Master_SSL_Verify_Server_Cert: No
  37. Last_IO_Errno: 0
  38. Last_IO_Error:
  39. Last_SQL_Errno: 0
  40. Last_SQL_Error:
  41. Replicate_Ignore_Server_Ids:
  42. Master_Server_Id: 18
  43. 1 row in set (0.00 sec)

最后感谢一下up主的支持https://www.bilibili.com/video/BV1Kt411M7vn?t=337

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/酷酷是懒虫/article/detail/1006013
推荐阅读
相关标签
  

闽ICP备14008679号