Linux7/centos7 mariadb Master-slave configuration process

Source: Internet
Author: User

Environment: REDHAT7 is also suitable for CENTOS7
(This article is a MARIADB master-slave deployment in a network-free environment)

Uninstall MySQL
(prevents MySQL and mariadb conflicts)

Stop service: Systemctl stop mysqld

Query installation package: RPM-QA | grep MySQL

Unloading:

Rpm-e Mysql-server

RPM-E--nodeps Mysql-libs

Prepare the Environment
To view disk mounts: Df–h < mount the system disk if it is not: Mount/dev/cdrom/media >

PS: Perform the following steps in the virtual machine setup if you have a network yum source, you don't need to mount the system disk

(If the boot automatically mounts to the desktop [Linux system with desktop], then you need to uninstall and then re-mount)

Uninstall: Umonut/dev/cdrom

Mount: Mount/dev/cdrom/media

Use local Yum Source:

Configure local yum:cd/etc/yum.repos.d/

To create a file (ending in repo), such as: Yum.repo, the file content is as follows: Configure:

Start installation
Execute command: yum-y install mariadb Mariadb-server

Copy file: cp/usr/share/mysql/my-huge.cnf/etc/my.cnf

Start the MARIADB service and run it automatically. The command is as follows:

Systemctl Start mariadb

Systemctl Enable MARIADB

View firewall status: Systemctl status Firewalld

Stop firewall: Systemctl stop FIREWALLD

Set boot not enabled firewall: Systemctl Disable FIREWALLD

Start setting up the MARIADB database and execute the script:/usr/bin/mysql_secure_installation

Follow the instructions below:

Note:running all PARTS of this SCRIPT are 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 would be blank,

So your should just pressenter here.

Enter current Passwordfor root (enter for none): After installation, the default root password is not followed by direct return

OK, successfully usedpassword, moving on ...

Setting The Rootpassword ensures that nobody can logs into the MariaDB

Root user without theproper authorisation.

Set root Password? [y/n] Y

New password: Enter the password for root

Re-enter new password: password confirmation

Password Updated successfully!

Reloading Privilegetables.

... success!

By default, a mariadbinstallation have an anonymous user, allowing anyone

To log into mariadbwithout has to has a user account created for

them. This was 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] Delete anonymous user Y

... success!

Normally, Root shouldonly is allowed to connect from ' localhost '. This

Ensures that someonecannot guess at the root of password from the network.

Disallow root loginremotely? [y/n] Close root telnet Y

... success!

By default, mariadbcomes with a database named ' test ' that anyone can

Access. This was also intended only for testing, Andshould was removed

Before moving into aproduction environment.

Remove Test Database andaccess to it? [y/n] Delete test database Y

    • Dropping test database ...

      ... success!

    • Removing privileges on test database ...

      ... success!

Reloading the privilegetables would ensure that all changes made so far

would take effectimmediately.

Reload privilege Tablesnow? [y/n] Determine all of the above operations Y

... success!

Cleaning up ...

All done! If you ' ve completed all of the above Steps,your MariaDB

Installation should nowbe secure.

Thanks for usingmariadb!

Configuring MARIADB Master-Slave
To modify the VIM/ETC/MY.CNF configuration file:

Primary node does not need to be modified

Modifying from a node server-id=2

PS: Reboot from Node (slave): systemctl restart MARIADB

Establish an account on the master node and authorize slave

Login MARIADB Database: mysql-uroot–proot

Establish a master-slave replication user and authorize:

Grammar:

GRANT REPLICATION SLAVE on . {All Permissions} To ' slave ' @ '% ' {user name slave,% is any address} identified by ' slave ';

Command:

GRANT REPLICATION SLAVE on . To ' slave ' @ '% ' of ' identified by ' slave ';

Query SQL (State of Master) command: SHOW MASTER status;

Configuration from node Slave: (Note on slave node execution)

Login from server: Mysql-uroot–proot to configure:

Grammar:

Change MASTER to

Master_host= ' master node IP address ', master_user= ' master node authorized user ', master_password= ' master ' user's password ', master_log_file= ' mysql-bin.000007 ' , master_log_pos=2197;

Command:

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: Be careful not to use spaces before or after the syntax comma.

To view master-slave status verification:

Command: show slave status\g;

Authorize remote user root login: (both master and slave need to execute)

GRANT all privileges on . To ' root ' @ '% ' identified by ' root ' withgrant OPTION;

FLUSH privileges;

If you are interested in this, please scan the QR code below for free for more details

Linux7/centos7 mariadb Master-slave configuration process

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.