目前創(chuàng)新互聯(lián)已為上1000家的企業(yè)提供了網(wǎng)站建設(shè)、域名、雅安服務(wù)器托管、網(wǎng)站托管、服務(wù)器租用、企業(yè)網(wǎng)站設(shè)計、北戴河網(wǎng)站維護等服務(wù),公司將堅持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。
master1IP地址:192.168.144.167
master2IP地址:192.168.144.151
slave1IP地址:192.168.144.168
slave2IP地址:192.168.144.145
monitorIP地址:192.168.144.164
[root@master1 ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo //獲取源地址
[root@master1 ~]# yum -y install epel-release //安裝epel源
[root@master1 ~]# yum clean all && yum makecache //yum緩存清空
[root@master1 ~]# yum -y install mariadb-server mariadb //安裝mariadb數(shù)據(jù)庫
[root@master1 ~]# systemctl stop firewalld.service //關(guān)閉防火墻
[root@master1 ~]# setenforce 0
[root@master1 ~]# systemctl start mariadb.service //開啟數(shù)據(jù)庫
[root@master1 ~]# vim /etc/my.cnf //進入編輯配置文件
[mysqld]
log_error=/var/lib/mysql/mysql.err //錯誤日志文件
log=/var/lib/mysql/mysql_log.log //主從日志存放位置
log_slow_queries=/var/lib/mysql_slow_queris.log //man日志
binlog-ignore-db=mysql,information_schema //二進制文件
character_set_server=utf8 //字符集
log_bin=mysql_bin //二進制日志文件
server_id=11 //服務(wù)id(不能相同)
log_slave_updates=true //允許從服務(wù)器更新
sync_binlog=1 //同步日志
auto_increment_increment=2 //自增列
auto_increment_offset=1 //起始點
[root@master1 ~]# systemctl restart mariadb.service //重啟數(shù)據(jù)庫
[root@master1 ~]# scp /etc/my.cnf root@192.168.144.151:/etc/ (server-id=22)
[root@master1 ~]# scp /etc/my.cnf root@192.168.144.168:/etc/ (server-id=33)
[root@master1 ~]# scp /etc/my.cnf root@192.168.144.145:/etc/ (server-id=44)
[root@master1 ~]# netstat -anpt | grep 3306 //查看端口3306
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 4235/mysqld
[root@master1 ~]# mysql ##進入數(shù)據(jù)庫
MariaDB [(none)]> show master status; ##查看主服務(wù)器的狀態(tài)信息
+------------------+----------+--------------+--------------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+--------------------------+
| mysql_bin.000001 | 245 | | mysql,information_schema |
+------------------+----------+--------------+--------------------------+
1 row in set (0.00 sec)
MariaDB [(none)]> grant replication slave on *.* to 'replication'@'192.168.144.%' identified by '123456'; //授權(quán)給144段的網(wǎng)段復(fù)制的權(quán)限用戶名replication密碼123456
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> change master to master_host='192.168.144.167',master_user='replication',master_password='123456',master_log_file='mysql_bin.000001',master_log_pos=245; //在master2上同步master1服務(wù)器
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> grant replication slave on *.* to 'replication'@'192.168.144.%' identified by '123456'; //在master2上授權(quán)復(fù)制權(quán)限
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> show master status; //查看master2的服務(wù)器的狀態(tài)信息
+------------------+----------+--------------+--------------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+--------------------------+
| mysql_bin.000001 | 410 | | mysql,information_schema |
+------------------+----------+--------------+--------------------------+
1 row in set (0.00 sec)
MariaDB [(none)]> flush privileges; //刷新權(quán)限
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> change master to master_host='192.168.144.151',master_user='replication',master_password='123456',master_log_file='mysql_bin.000001',master_log_pos=410; //master1同步master2服務(wù)器數(shù)據(jù)庫
Query OK, 0 rows affected (0.03 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> start slave; //開啟同步
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> show slave status\G; //查看同步狀態(tài)信息
...
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
...
MariaDB [(none)]> change master to master_host='192.168.144.167',master_user='replication',master_password='123456',master_log_file='mysql_bin.000001',master_log_pos=245; //在從服務(wù)器上同步master1主服務(wù)器
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> flush privileges; //刷新權(quán)限
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> start slave; //開啟同步
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> show slave status\G; //查看同步的狀態(tài)信息
...
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
...
MariaDB [(none)]> create database school; //創(chuàng)建數(shù)據(jù)庫
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> show databases; //查看數(shù)據(jù)庫
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| school |
| test |
+--------------------+
5 rows in set (0.00 sec)
MariaDB [(none)]> show databases; //實現(xiàn)主主,主從同步
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| school |
| test |
+--------------------+
5 rows in set (0.00 sec)
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum -y install epel-release
yum clean all && yum makecache
yum -y install mysql-mmm*
yum -y install mysql-mmm*
[root@master1 ~]# vim /etc/mysql-mmm/mmm_common.conf //所有主機上都要配置,直接復(fù)制多份
……
<host default>
cluster_interface ens33 //修改網(wǎng)卡
…
replication_user replication //修改用戶名
replication_password 123456 //密碼
agent_user mmm_agent
agent_password 123456 //密碼
<host db1>
ip 192.168.144.167 //master1地址
mode master
peer db2
</host>
<host db2>
ip 192.168.144.151 //master2地址
mode master
peer db1
</host>
<host db3>
ip 192.168.144.168 //slave1地址
mode slave
</host>
<host db4>
ip 192.168.144.145 //slave2地址
mode slave
</host>
<role writer>
hosts db1, db2 ##寫服務(wù)器虛擬ip
ips 192.168.144.250
mode exclusive
</role>
<role reader>
hosts db3, db4 ##讀服務(wù)器虛擬ip
ips 192.168.144.251, 192.168.144.252
mode balanced
</role>
##復(fù)制到其他的服務(wù)器中
[root@master1 ~]# scp /etc/mysql-mmm/mmm_common.conf root@192.168.144.151:/etc/mysql-mmm/
root@192.168.144.151's password:
mmm_common.conf 100% 836 267.1KB/s 00:00
[root@master1 ~]# scp /etc/mysql-mmm/mmm_common.conf root@192.168.144.168:/etc/mysql-mmm/
root@192.168.144.168's password:
mmm_common.conf 100% 836 863.2KB/s 00:00
[root@master1 ~]# scp /etc/mysql-mmm/mmm_common.conf root@192.168.144.145:/etc/mysql-mmm/
root@192.168.144.145's password:
mmm_common.conf 100% 836 904.7KB/s 00:00
[root@master1 ~]# scp /etc/mysql-mmm/mmm_common.conf root@192.168.144.164:/etc/mysql-mmm/
[root@monitor ~]# vim /etc/mysql-mmm/mmm_mon.conf
<host default>
monitor_user mmm_monitor
monitor_password 123456 ##修改monitor的密碼
</host>
MariaDB [(none)]> grant super, replication client, process on *.* to 'mmm_agent'@'192.168.144.%' identified by '123456'; //授權(quán)代理
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> grant replication client on *.* to 'mmm_monitor'@'192.168.144.%' identified by '123456'; //授權(quán)監(jiān)控
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> flush privileges; //刷新權(quán)限
Query OK, 0 rows affected (0.00 sec)
[root@master1 ~]# vim /etc/mysql-mmm/mmm_agent.conf
this db1 //根據(jù)規(guī)劃進行逐一調(diào)整
[root@master2 ~]# vim /etc/mysql-mmm/mmm_agent.conf
this db2 //根據(jù)規(guī)劃進行逐一調(diào)整
[root@slave1 ~]# vim /etc/mysql-mmm/mmm_agent.conf
this db3 //根據(jù)規(guī)劃進行逐一調(diào)整
[root@slave2 ~]# vim /etc/mysql-mmm/mmm_agent.conf
this db4 //根據(jù)規(guī)劃進行逐一調(diào)整
##所有數(shù)據(jù)庫開啟
[root@master1 ~]systemctl start mysql-mmm-agent.service //開啟代理服務(wù)
[root@master1 ~]systemctl enable mysql-mmm-agent.service //加入開機自啟動
[root@monitor ~]# vim /etc/mysql-mmm/mmm_mon.conf
<monitor>
ip 127.0.0.1
pid_path /run/mysql-mmm-monitor.pid
bin_path /usr/libexec/mysql-mmm
status_path /var/lib/mysql-mmm/mmm_mond.status
ping_ips 192.168.144.167,192.168.144.151,192.168.144.168,192.168.144.145 //所有數(shù)據(jù)庫服務(wù)器地址
auto_set_online 10 //自動在線時間
[root@monitor ~]# systemctl stop firewalld.service //關(guān)閉防火墻
[root@monitor ~]# setenforce 0
[root@monitor ~]# systemctl start mysql-mmm-monitor.service /開啟監(jiān)控服務(wù)
[root@monitor ~]# mmm_control show //查看主從的飄逸地址
db1(192.168.144.167) master/ONLINE. Roles: writer(192.168.144.250)
db2(192.168.144.151) master/ONLINE. Roles:
db3(192.168.144.168) slave/ONLINE. Roles: reader(192.168.144.252)
db4(192.168.144.145) slave/ONLINE. Roles: reader(192.168.144.251)
[root@master1 ~]# systemctl stop mariadb.service //模擬停止master1服務(wù)器
[root@monitor ~]# mmm_control show
db1(192.168.144.167) master/HARD_OFFLINE. Roles:
db2(192.168.144.151) master/ONLINE. Roles: writer(192.168.144.250)
db3(192.168.144.168) slave/ONLINE. Roles: reader(192.168.144.252)
db4(192.168.144.145) slave/ONLINE. Roles: reader(192.168.144.251)
(重啟master1數(shù)據(jù)庫服務(wù),虛擬地址不會被搶占到master1)
mmm_control checks all //需要各種OK
mmm_control move_role writer db1 //可以切換虛擬地址
[root@monitor ~]# yum install mysql -y
//master1服務(wù)器上授權(quán)monitor地址訪問//
MariaDB [(none)]> grant all on *.* to 'testdba'@'192.168.144.164' identified by '123456';
##授權(quán)monitor地址訪問
Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]> flush privileges; ##刷新權(quán)限
Query OK, 0 rows affected (0.00 sec)
[root@monitor ~]# mysql -utestdba -p -h 192.168.144.250 ##使用虛擬地址即可登錄數(shù)據(jù)庫
Enter password:
MariaDB [(none)]>
文章名稱:MySQL架構(gòu)——mmm部署實例
鏈接URL:http://jinyejixie.com/article16/ijcddg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供企業(yè)網(wǎng)站制作、網(wǎng)站排名、品牌網(wǎng)站設(shè)計、移動網(wǎng)站建設(shè)、手機網(wǎng)站建設(shè)、網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)