大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
创新互联建站专注于青铜峡企业网站建设,成都响应式网站建设公司,商城网站定制开发。青铜峡网站建设公司,为青铜峡等地区提供建站服务。全流程按需策划设计,专业设计,全程项目跟踪,创新互联建站专业和态度为您提供的服务
如果在生产环境中可能有一个主服务器,也是读写服务器,并可能会有多个从服务器,但这个主服务器会随之从服务器的增加而变的性能下降,所以最好主服务器只有一个从,其它的从服务器再从这人从服务器进行复制,减少主服务器的压力,这样中间服务器专做复制从而最小化影响主服务器的性能
[root@centos7 ~]#yum install mariadb-server
[root@centos7 ~]#mkdir /data/{MySQL,logs}
[root@centos7 ~]#chown mysql:mysql /data/{mysql,logs}
[root@master ~]#vi /etc/my.cnf
[mysqld]
log-bin=/data/logs/bin
datadir=/data/mysql
server-id=17
[root@master ~]#systemctl start mariadb
[root@master ~]#mysql < hellodb_innodb.sql
MariaDB [(none)]> grant replication slave on *.* to repluser@'192.168.205.%' identified by 'centos';
[root@master ~]#mysqldump -A --single-transaction --master-data=1 > /data/all.sql
[root@master ~]#scp /data/all.sql 192.168.205.27:/data
[root@middle ~]#vi /etc/my.cnf
[mysqld]
datadir=/data/mysql
log-bin=/data/logs/bin
server-id=27
read-only
log_slave_updates
[root@middle ~]#vi /data/all.sql
CHANGE MASTER TO
MASTER_HOST='192.168.205.17',
MASTER_USER='repluser',
MASTER_PASSWORD='centos',
MASTER_PORT=3306,
MariaDB [(none)]> source /data/all.sql
MariaDB [(none)]> start slave;
MariaDB [(none)]> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.205.17
Master_User: repluser
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: bin.000003
Read_Master_Log_Pos: 7973
Relay_Log_File: mariadb-relay-bin.000004
Relay_Log_Pos: 604
Relay_Master_Log_File: bin.000003
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
[root@middle ~]#mysqldump -A --single-transaction --master-data=1 > /data/middle.sql
[root@middle ~]#scp /data/middle.sql 192.168.205.37:/data
[root@slave ~]#vi /etc/my.cnf
[mysqld]
datadir=/data/mysql
server-id=37
read_only
[root@slave ~]#vi /data/middle.sql
CHANGE MASTER TO
MASTER_HOST='192.168.205.27',
MASTER_USER='repluser',
MASTER_PASSWORD='centos',
MASTER_PORT=3306,
[root@slave ~]#mysql < /data/middle.sql
[root@slave ~]#systemctl start mariadb
MariaDB [(none)]> start salve;
MariaDB [(none)]> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.205.27
Master_User: repluser
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: bin.000005
Read_Master_Log_Pos: 326
Relay_Log_File: mariadb-relay-bin.000003
Relay_Log_Pos: 604
Relay_Master_Log_File: bin.000005
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
MariaDB [(none)]> create database zhaoli;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| db1 |
| db2 |
| hellodb |
| mysql |
| performance_schema |
| test |
| zhaoli |
+--------------------+
8 rows in set (0.00 sec)