题目

使用VMWare创建两台centos7系统的虚拟机,安装数据库服务,并将两台数据库配置为主从数据库模式(master和slave)。配置完成后,在从节点,执行show status slaveG查看从节点的复制状态。将查看从节点服务状态的返回结果以文本形式提交到答题框。(数据库用户名root,密码000000;关于数据库的命令均使用小写)

节点规划

IP主机名节点
192.168.200.11mysql1主数据库
192.168.200.12mysql2从数据库

准备

关闭服务器防火墙、SELINUX

网络配置

主机名模式IP
mysql1仅主机192.168.100.11
NAT192.168.200.11
mysql2仅主机192.168.100.12
NAT192.168.200.12

配置主机名

1、配置第一台主机名为mysql1

[root@localhost ~]# hostnamectl set-hostname mysql1
[root@localhost ~]# bash
[root@mysql1 ~]# 

2、配置第二台主机名为mysql2

[root@localhost ~]# hostnamectl set-hostname mysql2
[root@localhost ~]# bash
[root@mysql2 ~]# 

添加host

1、配置mysql1的host,将下列内容加入/etc/hosts

[root@mysql1 ~]# vi /etc/hosts
192.168.200.11 mysql1
192.168.200.12 mysql2

2、利用远程复制将mysql1的hosts文件替换mysql2中的hosts文件

[root@mysql1 ~]# scp /etc/hosts 192.168.200.12:/etc/hosts
The authenticity of host '192.168.200.12 (192.168.200.12)' can't be established.
ECDSA key fingerprint is 14:57:da:84:0b:98:67:83:88:d7:c4:62:bf:87:60:f6.
Are you sure you want to continue connecting (yes/no)?  #yes
Warning: Permanently added '192.168.200.12' (ECDSA) to the list of known hosts.
root@192.168.200.12's password:  #输入密码
hosts                                    100%  202     0.2KB/s   00:00  

配置yum源(mysql1)

1、备份原yum源

[root@mysql1 ~]# mkdir /etc/yumback
[root@mysql1 ~]# mv /etc/yum.repos.d/* /etc/yumback

2、挂载镜像

[root@mysql1 ~]# mkdir /opt/centos
[root@mysql1 ~]# vi /etc/fstab    #将下列命令添加到最后一行
/root/CentOS-7-x86_64-DVD-1511.iso /opt/centos/ iso9660 defaults,loop 0 0
#先不要重启,运行下列命令验证是否能挂载成功
[root@mysql1 ~]# mount -a   

3、配置yum

[root@mysql1 ~]# vi /etc/yum.repos.d/local.repo
[centos]
name=centos
baseurl=file:///opt/centos
gpgcheck=0
enabled=1

4、清理缓存,建立缓存

[root@mysql1 ~]# yum clean all
[root@mysql1 ~]# yum makecache

安装FTP(mysql1)

安装配置ftp

[root@mysql1 ~]# yum install -y vsftpd
[root@mysql1 ~]# vi /etc/vsftpd/vsftpd.conf
#在最后一行添加下行
anon_root=/opt

[root@mysql1 ~]# systemctl start vsftpd
[root@mysql1 ~]# systemctl enable vsftpd
Created symlink from /etc/systemd/system/multi-user.target.wants/vsftpd.service to /usr/lib/systemd/system/vsftpd.service.

配置yum(mysql2)

1、备份原yum源

[root@mysql2 ~]# mkdir /opt/yumback
[root@mysql2 ~]# mv /etc/yum.repos.d/* /opt/yumback

2、配置yum

[root@mysql2 ~]# vi /etc/yum.repos.d/ftp.repo
[mysql1]
name=mysql1
baseurl=ftp://192.168.100.11/centos
gpgcheck=0
enabled=1

3、清理缓存,建立缓存

[root@mysql2 ~]# yum clean all
[root@mysql2 ~]# yum makecache

主节点安装mariadb

安装mariadbmariadb服务

[root@mysql1 ~]# yum install mariadb mariadb-server -y
[root@mysql1 ~]# systemctl start mariadb
[root@mysql1 ~]# systemctl enable mariadb
#初始化数据库
#!!!!!!!!!一定要启动mariadb服务再初始化!!!!!!!!!
[root@mysql1 ~]# mysql_secure_installation

从节点安装mariadb

安装mariadbmariadb服务

[root@mysql2 ~]# yum install mariadb mariadb-server -y
[root@mysql2 ~]# systemctl start mariadb
[root@mysql2 ~]# systemctl enable mariadb
#初始化数据库
#!!!!!!!!!一定要启动mariadb服务再初始化!!!!!!!!!
[root@mysql2 ~]# mysql_secure_installation

主节点配置数据库

1、修改数据库配置文件

[root@mysql1 ~]# vi /etc/my.cnf
#在[mysqld]中添加以下内容(已经有的就不需要加了):
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log_bin = mysql-bin   # 打开日志(主机需要打开),这个mysql-bin 可自定义,也可加上路径
binlog_ignore_db = mysql   #不给从机同步的库(多个写多行)
server_id = 11
[root@mysql1 ~]# systemctl restart mariadb

2、开放mysql1数据库权限

[root@mysql1 ~]# mysql -uroot -p000000
MariaDB [(none)]> grant all privileges on *.* to root@'%' identified by "000000";
MariaDB [(none)]> grant replication slave on *.* to 'user'@'mysql2' identified by '000000';
MariaDB [(none)]> exit

从节点配置数据库

1、修改数据库配置文件

[root@mysql2 ~]# vi /etc/my.cnf
在[mysqld]中添加以下内容(已经有的就不需要加了):
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log_bin = mysql-bin    # 打开日志(主机需要打开),这个mysql-bin 可自定义,也可加上路径
binlog_ignore_db = mysql  #不给从机同步的库(多个写多行)
server_id = 12
[root@mysql2 ~]# systemctl restart mariadb

2、开放mysql2数据库权限

[root@mysql2 ~]# mysql -uroot -p000000
MariaDB [(none)]> change master to master_host='mysql1',master_user='user',master_password='000000';
MariaDB [(none)]> start slave;
MariaDB [(none)]> show slave status\G;

提交内容

MariaDB [(none)]> show slave status\G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: mysql1
                  Master_User: user
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000001
          Read_Master_Log_Pos: 529
               Relay_Log_File: mariadb-relay-bin.000002
                Relay_Log_Pos: 813
        Relay_Master_Log_File: mysql-bin.000001
             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: 529
              Relay_Log_Space: 1109
              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: 11
1 row in set (0.00 sec)
最后修改:2021 年 09 月 26 日
如果觉得我的文章对你有用,请随意赞赏