Linux7/Centos7 Mariadb主从配置过程

环境:RedHat7 同样适用于Centos7
(本文是在无网络环境部署mariadb主从)

卸载Mysql
(防止mysql和mariadb冲突 )

停止服务:systemctl stop mysqld

查询安装包:rpm -qa | grep mysql

卸载:

rpm -e mysql-server

rpm -e --nodeps mysql-libs

准备环境
查看磁盘挂载情况:df –h < 如果没有则挂载系统盘:mount/dev/cdrom /media >

PS: 在虚拟机设置里对以下步骤进行操作 如果有网络yum源就不需要挂载系统盘

(如果开机自动挂载到桌面上[带桌面的Linux系统],那么需要卸载,然后再进行重新挂载)

卸载:umonut/dev/cdrom

挂载:mount/dev/cdrom /media

使用本地yum源:

配置本地yum:cd /etc/yum.repos.d/

创建一个文件(以repo结尾),如:yum.repo,文件内容如下:进行配置:

开始安装
执行命令:yum -y install mariadb mariadb-server

拷贝文件:cp /usr/share/mysql/my-huge.cnf /etc/my.cnf

启动mariadb服务并开机自动运行。命令如下:

systemctl start mariadb

systemctl enable mariadb

查看防火墙状态:systemctl status firewalld

停止防火墙:systemctl stop firewalld

设置开机不启用防火墙:systemctl disable firewalld

开始设置Mariadb数据库, 执行脚本:/usr/bin/mysql_secure_installation

按照下面提示进行操作即可:

NOTE:RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB

SERVERS IN PRODUCTIONUSE! PLEASE READ EACH STEP CAREFULLY!

In order to log intoMariaDB to secure it, we‘ll need the current

password for the rootuser. If you‘ve just installed MariaDB,and

you haven‘t set the rootpassword yet, the password will be blank,

so you should just pressenter here.

Enter current passwordfor root (enter for none): 安装后默认没有root密码,直接回车

OK, successfully usedpassword, moving on...

Setting the rootpassword ensures that nobody can log into the MariaDB

root user without theproper authorisation.

Set root password? [Y/n]Y

New password: 输入root的新密码

Re-enter new password: 新密码确认

Password updated successfully!

Reloading privilegetables..

... Success!

By default, a MariaDBinstallation has an anonymous user, allowing anyone

to log into MariaDBwithout having to have a user account created for

them. This is intended only for testing, and tomake the installation

go a bit smoother. You should remove them before moving into a

production environment.

Remove anonymous users?[Y/n] 删除匿名用户 Y

... Success!

Normally, root shouldonly be allowed to connect from ‘localhost‘. This

ensures that someonecannot guess at the root password from the network.

Disallow root loginremotely? [Y/n] 关闭root远程登录 Y

... Success!

By default, MariaDBcomes with a database named ‘test‘ that anyone can

access. This is also intended only for testing, andshould be removed

before moving into aproduction environment.

Remove test database andaccess to it? [Y/n] 删除test数据库 Y

  • Dropping test database...

    ... Success!

  • Removing privileges on test database...

    ... Success!

Reloading the privilegetables will ensure that all changes made so far

will take effectimmediately.

Reload privilege tablesnow? [Y/n] 确定以上所有操作 Y

... Success!

Cleaning up...

All done! If you‘ve completed all of the above steps,your MariaDB

installation should nowbe secure.

Thanks for usingMariaDB!

配置MariaDB主从
修改vim /etc/my.cnf配置文件:

主节点不需要进行修改

从节点进行修改 server-id=2

PS:进行重启从节点(slave):systemctl restart mariadb

在主节点上建立账户并且授权Slave

登录MariaDB数据库:mysql -uroot –proot

建立主从复制用户并授权:

语法:

GRANT REPLICATION SLAVE ON .{所有权限} TO‘slave‘@‘%‘{用户名为slave,%为任意地址} identified by ‘slave‘;

命令:

GRANT REPLICATION SLAVE ON . TO‘slave‘@‘%‘ identified by ‘slave‘;

查询SQL(Master的状态)命令:SHOW MASTER STATUS;

配置从节点SLAVE:(注意在从节点上执行)

登录从服务器:mysql -uroot –proot进行配置:

语法:

CHANGE MASTER TO

MASTER_HOST=‘主节点的IP地址‘, MASTER_USER=‘主节点授权的用户‘, MASTER_PASSWORD=‘主节点授权的用户的密码‘,MASTER_LOG_FILE=‘mysql-bin.000007‘,MASTER_LOG_POS=2197;

命令:

CHANGEMASTER TO MASTER_HOST=‘192.168.1.31‘,MASTER_USER=‘slave‘,MASTER_PASSWORD=‘slave‘,MASTER_LOG_FILE=‘mysql-bin.000007‘,MASTER_LOG_POS=2197;
PS:注意语法逗号前后不要用空格。

查看主从状态验证:

命令:show slave status\G;

授权远程用户root登录:(主从都需要进行执行)

GRANT ALL PRIVILEGES ON . TO ‘root‘@‘%‘ IDENTIFIED BY ‘root‘ WITHGRANT OPTION;

FLUSH PRIVILEGES;

如果对此有兴趣,请扫下面二维码免费获取更多详情

原文地址:http://blog.51cto.com/11233498/2129185

时间: 2024-08-08 21:07:15

Linux7/Centos7 Mariadb主从配置过程的相关文章

mariadb主从配置

1.主从2台机器都安装mariadbyum -y install mariadb mariadb-server2.登陆mysqlmysql -uroot -p3.删掉test库drop database test;4.创建需要同步的数据库create database databasename default character set utf8 collate utf8_general_ci;5.创建同步的用户GRANT REPLICATION SLAVE,REPLICATION CLIENT

CentOS7 PostgreSQL 主从配置( 一)

主库配置 pg_hba.conf host replication all 10.2.0.0/0 trust postgresql.conf listen_addresses = '*' max_wal_senders = 5 wal_level = hot_standby 重启主库 从库配置 安装使用yum安装 (找源 http://yum.postgresql.org/) yum install https://download.postgresql.org/pub/repos/yum/9.

CentOS7 PostgreSQL 主从配置

PostgreSQL安装 安装使用yum安装 (找源 http://yum.postgresql.org/) yum install https://download.postgresql.org/pub/repos/yum/9.5/redhat/rhel-7-x86_64/pgdg-centos95-9.5-2.noarch.rpmyum install postgresql95-server postgresql95-contrib 设置开机启动 (centos 服务安装位置 cd /usr

CentOS7 PostgreSQL 主从配置( 三)

postgres 主备切换 主备查看 方法 ps -ef | grep wal (主库 sender)postgres 27873 27864 0 5月06 ? 00:00:10 postgres: wal sender process postgres 10.2.0.13(47582) streaming 0/906FF78postgres 27874 27864 0 5月06 ? 00:00:11 postgres: wal sender process postgres 10.2.0.15

Centos7+Mariadb集群-主从配置介绍

近期一直在恶补Linux相关的知识,主要是就是学Linux下的基本日常应用服务器的配置及优化,今天我们主要介绍一下在Centos7下安装及配置Mysql 集群,说到集群,其实就是为了提高服务的高可用性.对于高可用的相关服务今天不是主要介绍内容,今天主要介绍MYSQL的主从配置.对在Linux下的其他服务的介绍及服务高可用负载均衡我们将会在后期的文章中介绍.开始今天的介绍:Centos7+Mysql主从配置. 环境介绍: Hostname:A-S IP:192.168.5.21 Role:Mysq

Linux系统中的mariadb主从数据库搭建

主从服务器的优势 读写分离,使数据库能支撑更大的并发有的表sql语句非常的慢,可能会导致锁表,就影响前台服务.如果前台使用master,查询使用slave,那么将不会造成前台锁,保证了前台速度. 发扬不同表引擎的优点Myisam表的查询速度比innodb快,而写入并发innodb比myIsam要好.那么,我们可以使用innodb作为 master,处理高并发写入,使用master作为slave,接受查询.或在myisam slave中建立全文索引,解决innodb无全文索引的弱点 实现服务器负载

MySQL主从复制原理及配置过程

一.Mysql数据库的主从复制原理过程: Mysql的主从复制是一个异步的复制过程,数据将从一个Mysql数据库(master)复制到另一个Mysql数据库(slave),在Master和Slave之间实现整个主从复制的过程是由三个线程参与完成的.其中有两个线程(SQL线程和I/O线程)在Slave端,另外一个线程(I/O线程)在Master端 ,要实现Mysql的主从复制,首先必须打开Master端的binlog记录功能,否则就无法实现.因为整个复制过程实际上就是Slave从Master获取b

Redis的主从配置

一.主从配置过程 关于主从配置的过程,我们这里就不做具体详细解释了,看这个文章,还是不错的: https://www.cnblogs.com/ysocean/p/9143118.html 二.主从复制的原理 这才是我们的主要问题,我们来看一下 Redis的复制功能分为同步(sync)和命令传播(command propagate)两个操作. ①.旧版同步 当从节点发出 SLAVEOF 命令,要求从服务器复制主服务器时,从服务器通过向主服务器发送 SYNC 命令来完成.该命令执行步骤: 1.从服务

MySQL配置主从同步过程记录

今天由于工作需要,配置了一下主从同步,这里记录一下配置过程,以备查阅. 事先度娘了一番,主从同步需要保证主从服务器MySQL版本一致(我的略有差别,主服务器版本5.5.31,从服务器版本5.5.19). 1.初始化表结构,将主服务器上的表结构全部备份导入到从服务器上,之后,之后主服务器暂时不要做数据修改操作. 2.下载备份文件,并导入到从服务器,方式有很多,这里不再赘述. 3.修改主服务器master的MySQL配置文件,开启主服务器二进制日志,并设置服务器唯一ID,编辑/etc/my.cnf,