• Centos8上部署MySQL主从备份


    虚拟机环境如下

    Node1192.168.1.110Centos8        
    Node2192.168.1.111Centos8

    1.在Node1和Node2上安装数据库;

    yum install -y mysql*

    2.关闭防火墙服务,关闭开启自启;

    1. systemctl stop firewalld
    2. systemctl disable firewalld

    3.开启数据库服务,并设置开机自启;

    1. systemctl start mysqld
    2. systemctl enable mysqld

    4.初始化数据库;

    1. mysql_secure_installation \\初始化mysqld服务
    2. New password: \\输入设置密码
    3. Re-enter new password:
    4. Estimated strength of the password: 100
    5. Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
    6. By default, a MySQL installation has an anonymous user,
    7. allowing anyone to log into MySQL without having to have
    8. a user account created for them. This is intended only for
    9. testing, and to make the installation go a bit smoother.
    10. You should remove them before moving into a production
    11. environment.
    12. Remove anonymous users? (Press y|Y for Yes, any other key for No) :
    13. ... skipping.
    14. Normally, root should only be allowed to connect from
    15. 'localhost'. This ensures that someone cannot guess at
    16. the root password from the network.
    17. Disallow root login remotely? (Press y|Y for Yes, any other key for No) :
    18. ... skipping.
    19. By default, MySQL comes with a database named 'test' that
    20. anyone can access. This is also intended only for testing,
    21. and should be removed before moving into a production
    22. environment.
    23. Remove test database and access to it? (Press y|Y for Yes, any other key for No) :
    24. ... skipping.
    25. Reloading the privilege tables will ensure that all changes
    26. made so far will take effect immediately.
    27. Reload privilege tables now? (Press y|Y for Yes, any other key for No) :
    28. ... skipping.
    29. All done!

    5.在Node1虚拟机上,修改配置文件/etc/my.cnf;

    1. vim /etc/my.cnf
    2. 添加以下内容:
    3. [mysqld]
    4. server-id=1 \\指定ID,主从的两台虚拟机ID必须不同
    5. log-bin=mysql-bin \\mysql根据配置自动设置指定的二进制文件名

    6.在Node1虚拟机上,使用systemctl重启数据库服务;

    systemctl restart mysqld

    7.在Node1虚拟机上,进入交互模式,配置同步账户。

    (1)通过mysql命令进入数据库交互模式;
    1. mysql -uroot -p
    2. \\输入密码
    (2)创建同步账户synch;
    create user 'synch'@'192.168.100.131' identified by '123456';
    
    (3)授权账户synch;
    grant replication slave on *.* to 'synch'@'192.168.100.131';
    
    (4)通过select命令查看用户是否创建成功;
    select * from mysql.user where User='synch'\G;
    
    (5)通过show命令检查synch权限;
    show grants for 'synch'@'192.168.100.131';
    
    (6)刷新系统权限;
    flush privileges;
    
    (7)通过show命令查看当前数据库,即主数据库的状态;

    8.在Node2虚拟机上,修改配置文件/etc/my.cnf;

    1. vim /etc/my.cnf
    2. 添加以下内容
    3. [mysqld]
    4. server-id=2
    5. replicate-do-db=test \\指定要复制的数据库

    9.在Node2虚拟机上,使用systemctl重启数据库服务;

    systemctl restart mysqld

    10.在Node2虚拟机上,进入交互模式,开启同步。

    (1)通过mysql命令进入数据库交互模式;
    1. mysql -uroot -p
    2. \\输入密码
    (2)停止同步,默认为开启;
    stop slave;
    (3)修改MASTER的状态;
    1. change
    2. master to
    3. master_host='192.168.100.130', \\IP地址为Node1的IP地址
    4. master_port=3306,
    5. master_user='synch',
    6. master_password='123456',
    7. master_log_file=‘mysql-bin.000002', \\文件和位置为show master status图片的内容
    8. master_log_pos=1902;
    (4)修改完成后,开启同步;
    start slave;

    11.在Node2数据库上进入交互模式,查看同步状态;

    show slave status\G;

    在同步状态查看到Slave_IO_Running和Slave_SQL_Running两个状态皆为YES即证明主从数据库配置成功。

  • 相关阅读:
    图像保存为二进制文件及二进制文件读出图像数据
    Jackson 注解 使用示例
    Java练习题第二十七期:幸运的袋子
    PS的抠图算法原理剖析 1
    C++之多态<polymorphism>
    HTTP VS HTTPS
    6.二叉树.题目3
    长事务管理不再难:Saga模式全面解析
    swiper删除虚拟slide问题
    java-net-php-python-ssm二手手机回购网站计算机毕业设计程序
  • 原文地址:https://blog.csdn.net/weixin_47460431/article/details/134537155