主从-读写分离-集群
1、数据库主从管理[2.0分]
1. 基础情况安装
(1)修改主机名
将172.30.11.12主机名修改为mysql1;172.30.11.13主机名修改为mysql2,下令如下:
mysql1节点:
- [root@localhost ~]# hostnamectl set-hostname mysql1
- [root@localhost ~]# logout
- [root@mysql1 ~]# hostnamectl
- Static hostname: mysql1
- Icon name: computer-vm
- Chassis: vm
- Machine ID: 622ba110a69e24eda2dca57e4d306baa
- Boot ID: 859720a14f8f4b5e836f5a0fae7097e0
- Virtualization: kvm
- Operating System: CentOS Linux 7 (Core)
- CPE OS Name: cpe:/o:centos:centos:7
- Kernel: Linux 3.10.0-862.2.3.el7.x86_64
- Architecture: x86-64
复制代码 mysql2节点:
- [root@localhost ~]# hostnamectl set-hostname mysql2
- [root@localhost ~]# logout
- [root@mysql2 ~]# hostnamectl
- Static hostname: mysql2
- Icon name: computer-vm
- Chassis: vm
- Machine ID: 622ba110a69e24eda2dca57e4d306baa
- Boot ID: 5e41c48c85704016ad0bd940500cc255
- Virtualization: kvm
- Operating System: CentOS Linux 7 (Core)
- CPE OS Name: cpe:/o:centos:centos:7
- Kernel: Linux 3.10.0-862.2.3.el7.x86_64
- Architecture: x86-64
复制代码 (2)关闭防火墙及SELinux服务
两个节点关闭防火墙firewalld及SELinux服务,下令如下:
- # setenforce 0
- # systemctl stop firewalld
复制代码 (3)配置hosts文件
两个节点配置/etc/hosts文件,修改为如下:
- 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
- ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
- 172.30.11.12 mysql1
- 172.30.11.13 mysql2
复制代码 (4)配置YUM源
两个节点均利用提供的mariadb–10.3.23-repo.tar.gz的压缩包,解压并放在/opt目次下,进入/etc/yum.repos.d目次下,将原来的repo文件移除,新建local.repo文件并编辑内容,具体操作下令如下:
- # curl -O http://10.24.1.82/training/mariadb-10.3.23-repo.tar.gz
- # curl -O http://10.24.1.82/training/Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz
- # tar -zxvf mariadb-10.3.23-repo.tar.gz -C /opt/
- # cd /etc/yum.repos.d/
- # mv * /media/
- # vi local.repo
- # cat local.repo
- [mariadb]
- name=mariadb
- baseurl=file:///opt/
- gpgcheck=0
- enabled=1
复制代码 查看配置的YUM源是否可用,下令如下:
- # yum repolist
- Loaded plugins: fastestmirror
- Loading mirror speeds from cached hostfile
- repo id repo name status
- mariadb mariadb 19
- repolist: 19
复制代码 查看到repolist数量,即YUM源配置乐成。
(5)安装数据库服务并启动
配置完毕后,两个节点安装数据库服务,下令如下:
- # yum install -y mariadb mariadb-server
复制代码 两个节点启动数据库服务并设置开机自启,下令如下:
- # systemctl start mariadb
- # systemctl enable mariadb
- Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
复制代码 2. 初始化数据库并配置主从服务
(1)初始化数据库
两个节点初始化数据库,配置数据库root密码为000000,下令如下:
- # mysql_secure_installation
- /usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found
- NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
- SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
- In order to log into MariaDB to secure it, we'll need the current
- password for the root user. If you've just installed MariaDB, and
- you haven't set the root password yet, the password will be blank,
- so you should just press enter here.
- Enter current password for root (enter for none): #默认按Enter键
- OK, successfully used password, moving on...
- Setting the root password ensures that nobody can log into the MariaDB
- root user without the proper authorisation.
- Set root password? [Y/n] y
- New password: #输入数据库root密码000000
- Re-enter new password: #再次输入密码000000
- Password updated successfully!
- Reloading privilege tables..
- ... Success!
- By default, a MariaDB installation has an anonymous user, allowing anyone
- to log into MariaDB without having to have a user account created for
- them. This is intended only for testing, and to make 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 should only be allowed to connect from 'localhost'. This
- ensures that someone cannot guess at the root password from the network.
- Disallow root login remotely? [Y/n] n
- ... skipping.
- By default, MariaDB comes with a database named 'test' that anyone can
- access. This is also intended only for testing, and should be removed
- before moving into a production environment.
- Remove test database and access to it? [Y/n] y
- - Dropping test database...
- ... Success!
- - Removing privileges on test database...
- ... Success!
- Reloading the privilege tables will ensure that all changes made so far
- will take effect immediately.
- Reload privilege tables now? [Y/n] y
- ... Success!
- Cleaning up...
- All done! If you've completed all of the above steps, your MariaDB
- installation should now be secure.
- Thanks for using MariaDB!
复制代码 (2)配置mysql1主节点
修改mysql1节点的数据库配置文件,在配置文件/etc/my.cnf.d/server.cnf中的[mysqld]增添如下内容。
- [root@mysql1 ~]# cat /etc/my.cnf.d/server.cnf
- ... ...
- [mysqld]
- log_bin = mysql-bin #记录操作日志
- binlog_ignore_db = mysql #不同步MySQL系统数据库
- server_id = 12 #数据库集群中的每个节点id都要不同,一般使用IP地址的最后段的数字,例如172.30.11.12,server_id就写12
- ... ...
复制代码 重启数据库服务,并进入数据库,下令如下:
- [root@mysql1 ~]# systemctl restart mariadb
- [root@mysql1 ~]# mysql -uroot -p000000
- Welcome to the MariaDB monitor. Commands end with ; or \g.
- Your MariaDB connection id is 9
- Server version: 10.3.23-MariaDB-log MariaDB Server
- Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
- Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
- MariaDB [(none)]>
复制代码 在mysql1节点,授权在任何客户端呆板上可以以root用户登录到数据库,然后在主节点上创建一个user用户毗连节点mysql2,并赋予从节点同步主节点数据库的权限。下令如下:
- MariaDB [(none)]> grant all privileges on *.* to root@'%' identified by "000000";
- Query OK, 0 rows affected (0.00 sec)
- MariaDB [(none)]> grant replication slave on *.* to 'user'@'mysql2' identified by '000000';
- Query OK, 0 rows affected (0.00 sec)
复制代码 (3)配置mysql2从节点
修改mysql2节点的数据库配置文件,在配置文件/etc/my.cnf.d/server.cnf中的[mysqld]增添如下内容。
- [root@mysql2 ~]# cat /etc/my.cnf.d/server.cnf
- ... ...
- [mysqld]
- log_bin = mysql-bin #记录操作日志
- binlog_ignore_db = mysql #不同步MySQL系统数据库
- server_id = 13 #数据库集群中的每个节点id都要不同,一般使用IP地址的最后段的数字,例如172.30.11.13,server_id就写13
- ... ...
复制代码 修改完配置文件后,重启数据库服务,并在从节点mysql2上登录MariaDB数据库,配置从节点毗连主节点的毗连信息。master_host为主节点主机名mysql1,master_user为上一步中创建的用户user,下令如下:
- [root@mysql2 ~]# systemctl restart mariadb
- [root@mysql2 ~]# mysql -uroot -p000000
- Welcome to the MariaDB monitor. Commands end with ; or \g.
- Your MariaDB connection id is 9
- Server version: 10.3.23-MariaDB-log MariaDB Server
- Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
- Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
- MariaDB [(none)]> change master to master_host='mysql1',master_user='user',master_password='000000';
- Query OK, 0 rows affected (0.01 sec)
复制代码 配置完毕主从数据库之间的毗连信息之后,开启从节点服务。利用show slave status\G下令,并查看从节点服务状态,如果Slave_IO_Running和Slave_SQL_Running的状态都为YES,则从节点服务开启乐成。下令如下:
- MariaDB [(none)]> start slave;
- 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: 705
- Relay_Log_File: mysql2-relay-bin.000002
- Relay_Log_Pos: 1004
- 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: 705
- Relay_Log_Space: 1314
- 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: 12
- Master_SSL_Crl:
- Master_SSL_Crlpath:
- Using_Gtid: No
- Gtid_IO_Pos:
- Replicate_Do_Domain_Ids:
- Replicate_Ignore_Domain_Ids:
- Parallel_Mode: conservative
- SQL_Delay: 0
- SQL_Remaining_Delay: NULL
- Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
- Slave_DDL_Groups: 2
- Slave_Non_Transactional_Groups: 0
- Slave_Transactional_Groups: 0
- 1 row in set (0.000 sec)
复制代码 可以看到Slave_IO_Running和Slave_SQL_Running的状态都是Yes,配置数据库主从集群乐成。
3. 验证数据库主从服务
(1)主节点创建数据库
先在主节点mysql1中创建库test,并在库test中创建表company,插入表数据,创建完成后,查看表company数据,下令如下:
- [root@mysql1 ~]# mysql -uroot -p000000
- Welcome to the MariaDB monitor. Commands end with ; or \g.
- Your MariaDB connection id is 11
- Server version: 10.3.23-MariaDB-log MariaDB Server
- Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
- Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
- MariaDB [(none)]> create database test;
- Query OK, 1 row affected (0.00 sec)
- MariaDB [(none)]> use test;
- Database changed
- MariaDB [test]> create table company(id int not null primary key,name varchar(50),addr varchar(255));
- Query OK, 0 rows affected (0.01 sec)
- MariaDB [test]> insert into company values(1,"alibaba","china");
- Query OK, 1 row affected (0.01 sec)
- MariaDB [test]> select * from company;
- +----+---------+-------+
- | id | name | addr |
- +----+---------+-------+
- | 1 | alibaba | china |
- +----+---------+-------+
- 1 row in set (0.00 sec)
复制代码 (2)从节点验证复制功能
登录mysql2节点的数据库,查看数据库列表。找到test数据库,查询表,并查询内容验证从数据库的复制功能,下令如下:
- [root@mysql2 ~]# mysql -uroot -p000000
- Welcome to the MariaDB monitor. Commands end with ; or \g.
- Your MariaDB connection id is 12
- Server version: 10.3.23-MariaDB-log MariaDB Server
- Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
- Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
- MariaDB [(none)]> show databases;
- +--------------------+
- | Database |
- +--------------------+
- | information_schema |
- | mysql |
- | performance_schema |
- | test |
- +--------------------+
- 4 rows in set (0.00 sec)
- MariaDB [(none)]> use test;
- Reading table information for completion of table and column names
- You can turn off this feature to get a quicker startup with -A
- Database changed
- MariaDB [test]> show tables;
- +----------------+
- | Tables_in_test |
- +----------------+
- | company |
- +----------------+
- 1 row in set (0.00 sec)
- MariaDB [test]> select * from company;
- +----+---------+-------+
- | id | name | addr |
- +----+---------+-------+
- | 1 | alibaba | china |
- +----+---------+-------+
- 1 row in set (0.00 sec)
复制代码 可以查看到主数据库中刚刚创建的库、表、信息,验证从数据库的复制功能乐成。
1. 基础情况安装
(1)修改主机名
将172.30.11.14的主机名修改为mycat,下令如下:
- # hostnamectl set-hostname mycat
- # logout
- [root@mycat ~]# hostnamectl
- Static hostname: mycat
- Icon name: computer-vm
- Chassis: vm
- Machine ID: 622ba110a69e24eda2dca57e4d306baa
- Boot ID: c9e345d94abb4f0684ce75726c39dbcf
- Virtualization: kvm
- Operating System: CentOS Linux 7 (Core)
- CPE OS Name: cpe:/o:centos:centos:7
- Kernel: Linux 3.10.0-862.2.3.el7.x86_64
- Architecture: x86-64
复制代码 (2)安装JDK情况
在mycat节点安装Java JDK情况,具体操作步骤如下:
利用提供的mariadb-10.3.23-repo.tar.gz包上传至mycat节点的/root目次下,解压并配置本钱地yum源,下令如下:
- [root@mycat ~]# curl -O http://10.24.1.82/training/mariadb-10.3.23-repo.tar.gz
- [root@mycat ~]# tar -zxvf mariadb-10.3.23-repo.tar.gz -C /opt
- [root@mycat ~]# mv /etc/yum.repos.d/* /media/
- [root@mycat ~]# vi /etc/yum.repos.d/local.repo
- [root@mycat ~]# cat /etc/yum.repos.d/local.repo
- [mariadb]
- name=mariadb
- baseurl=file:///opt/
- gpgcheck=0
- enabled=1
复制代码 配置完yum源之后,举行安装Java JDK情况,下令如下:
- [root@mycat ~]# yum install -y java-1.8.0-openjdk java-1.8.0-openjdk-devel
- ... ...
复制代码 安装完之后,可以利用下令查看Java JDK情况,下令如下:
- [root@mycat ~]# java -version
- openjdk version "1.8.0_262"
- OpenJDK Runtime Environment (build 1.8.0_262-b10)
- OpenJDK 64-Bit Server VM (build 25.262-b10, mixed mode)
复制代码 2. 部署Mycat读写分离中间件服务
(1)安装Mycat服务
将Mycat服务的二进制软件包Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz上传到Mycat虚拟机的/root目次下,并将软件包解压到/use/local目次中。赋予解压后的Mycat目次权限。
- [root@mycat ~]# curl -O http://10.24.1.82/Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz
- [root@mycat ~]# tar -zxvf Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz -C /usr/local/
- [root@mycat ~]# chmod -R 777 /usr/local/mycat/
复制代码 (2)编辑Mycat的逻辑库配置文件
配置Mycat服务读写分离的schema.xml配置文件在/usr/local/mycat/conf/目次下,可以在文件中界说一个逻辑库,利用户可以通过Mycat服务管理该逻辑库对应的MariaDB数据库。在这里界说一个逻辑库schema,name为USERDB;该逻辑库USERDB对应数据库database为test(在部署主从数据库时已创建);设置数据库写入节点为主节点mysql1;设置数据库读取节点为从节点mysql2。(可以直接删除原来schema.xml的内容,替换为如下。)
注意:IP需要修改成现实的IP地址。
- [root@mycat ~]# cat /usr/local/mycat/conf/schema.xml
- <?xml version="1.0"?>
- <!DOCTYPE mycat:schema SYSTEM "schema.dtd">
- <mycat:schema xmlns:mycat="http://io.mycat/">
- <schema name="USERDB" checkSQLschema="true" sqlMaxLimit="100" dataNode="dn1"></schema>
- <dataNode name="dn1" dataHost="localhost1" database="test" />
- <dataHost name="localhost1" maxCon="1000" minCon="10" balance="3" dbType="mysql" dbDriver="native" writeType="0" switchType="1" slaveThreshold="100">
- <heartbeat>select user()</heartbeat>
- <writeHost host="hostM1" url="172.30.11.12:3306" user="root" password="000000">
- <readHost host="hostS1" url="172.30.11.13:3306" user="root" password="000000" />
- </writeHost>
- </dataHost>
- </mycat:schema>
复制代码 代码阐明:
- sqlMaxLimit:配置默认查询数量。
- database:为真实数据库名。
- balance=“0”:不开启读写分离机制,全部读操作都发送到当前可用的writeHost上。
- balance=“1”:全部的readHost与stand by writeHost到场select语句的负载平衡,简朴来说,当双主双从模式(M1->S1,M2->S2,而且M1与M2互为主备),正常情况下,M2、S1、S2都到场select语句的负载平衡。
- balance=“2”:全部读操作都随机的在writeHost、readhost上分发。
- balance=“3”:全部读哀求随机地分发到wiriterHost对应的readhost执行,writerHost不负担读压力,注意balance=3只在1.4及其以后版本有,1.3版本没有。
- writeType=“0”:全部写操作发送到配置的第一个writeHost,第一个挂了需要切换到还生存的第二个writeHost,重新启动后已切换后的为准,切换记录在配置文件dnindex.properties中。
- writeType=“1”:全部写操作都随机的发送到配置的writeHost。
(3)修改配置文件权限
修改schema.xml的用户权限,下令如下:
- [root@mycat ~]# chown root:root /usr/local/mycat/conf/schema.xml
复制代码 (4)编辑mycat的访问用户
修改/usr/local/mycat/conf/目次下的server.xml文件,修改root用户的访问密码与数据库,密码设置为000000,访问Mycat的逻辑库为USERDB,下令如下。
- [root@mycat ~]# cat /usr/local/mycat/conf/server.xml
复制代码 在配置文件的最后部分,
- <user name="root">
- <property name="password">000000</property>
- <property name="schemas">USERDB</property>
复制代码 然后删除如下几行:
- <user name="user">
- <property name="password">user</property>
- <property name="schemas">TESTDB</property>
- <property name="readOnly">true</property>
- </user>
复制代码 生存并退出server.xml配置文件。
(5)启动Mycat服务
通过下令启动Mycat数据库中间件服务,启动后利用netstat -ntpl下令查看虚拟机端口开放情况,如果有开放8066和9066端口,则表示Mycat服务开启乐成。端口查询情况如图2-1所示。
- [root@mycat ~]# /bin/bash /usr/local/mycat/bin/mycat start
复制代码 3. 验证数据库集群服务读写分离功能
(1)用Mycat服务查询数据库信息
先在Mycat虚拟机上利用Yum安装mariadb-client服务。
- [root@mycat ~]# yum install -y MariaDB-client
复制代码 在Mycat虚拟机上利用mysql下令查看Mycat服务的逻辑库USERDB,因为Mycat的逻辑库USERDB对应数据库test(在部署主从数据库时已安装),所以可以查看库中已经创建的表company。下令如下。
- [root@mycat ~]# mysql -h127.0.0.1 -P8066 -uroot -p000000
- Welcome to the MariaDB monitor. Commands end with ; or \g.
- Your MySQL connection id is 2
- Server version: 5.6.29-mycat-1.6-RELEASE-20161028204710 MyCat Server (OpenCloundDB)
- Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
- Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
- MySQL [(none)]> show databases;
- +----------+
- | DATABASE |
- +----------+
- | USERDB |
- +----------+
- 1 row in set (0.001 sec)
- MySQL [(none)]> use USERDB
- Reading table information for completion of table and column names
- You can turn off this feature to get a quicker startup with -A
- Database changed
- MySQL [USERDB]> show tables;
- +----------------+
- | Tables_in_test |
- +----------------+
- | company |
- +----------------+
- 1 row in set (0.003 sec)
- MySQL [USERDB]> select * from company;
- +----+---------+-------+
- | id | name | addr |
- +----+---------+-------+
- | 1 | alibaba | china |
- +----+---------+-------+
- 1 row in set (0.005 sec)
复制代码 (2)用Mycat服务添加表数据
在Mycat虚拟机上利用mysql下令对表company添加一条数据(2,“basketball”,“usa”),添加完毕后查看表信息。下令如下。
- MySQL [USERDB]> insert into company values(2,"bastetball","usa");
- Query OK, 1 row affected (0.050 sec)
- MySQL [USERDB]> select * from company;
- +----+------------+-------+
- | id | name | addr |
- +----+------------+-------+
- | 1 | alibaba | china |
- | 2 | bastetball | usa |
- +----+------------+-------+
- 2 rows in set (0.003 sec)
复制代码 (3)验证Mycat服务对数据库读写操作分离
在Mycat虚拟机节点利用mysql下令,通过9066端口查询对数据库读写操作的分离信息。可以看到全部的写入操作WRITE_LOAD数都在mysql1主数据库节点上,全部的读取操作READ_LOAD数都在mysql2主数据库节点上。由此可见,数据库读写操作已经分离到mysql1和mysql2节点上了。下令如下。
- [root@mycat ~]# mysql -h127.0.0.1 -P9066 -uroot -p000000 -e 'show @@datasource;'
复制代码 至此,Mycat读写分离数据库案例完成。
利用提供的OpenStack私有云平台,创建两台云主机vm1和vm2,镜像利用CentOS7.9,利用提供的mariadb-repo.tar.gz软件包,在这两台云主机上分别安装数据库服务,并配置成主从数据库,vm1节点为主库,vm2节点为从库(数据库密码设置为000000)。
- 1、下载
- yum install -y mariadb-server
- mysqladmin -uroot password 123456
- 2、授权
- mysql -uroot -p123456 -e "grant all on *.* to root@'%' identified by '123456'"
- 3、修改配置文件
- log-bin=mysql-bin
- server_id=短ip
- 4、重启服务
- systemctl restart mariadb
- 5、从节点执行
- change master to master_user='root',master_host='192.168.100.160',master_password='123456';
- 6、检测命令
- mysql -uroot -p000000 -e "show slave status\G"
- Slave_IO_Running: Yes||Slave_SQL_Running: Yes
复制代码 2、部署MariaDB集群
利用OpenStack私有云平台,创建3台系统为centos7.9的云主机,三台云主机举行安装高可用数据库集群(MariaDB_Galera_cluster,数据库密码设置为123456)的操作(所需的安装包在HTTP服务中)。
- 1、下载
- yum install -y mariadb-server
- mysqladmin -uroot password 123456
- 2、授权
- mysql -uroot -p123456 -e "grant all on *.* to root@'%' identified by '123456'"
- 3、修改配置文件
- wsrep_on=ON
- wsrep_provider=/usr/lib64/galera/libgalera_smm.so
- wsrep_cluster_address="gcomm://vm1,vm2,vm3" #添加集群ip
- binlog_format=row
- default_storage_engine=InnoDB
- innodb_autoinc_lock_mode=2
- bind-address=0.0.0.0 #取消注释
- 4、两个从节点stop mariadb
- 主节点启动 galera_new_cluster集群
- 然后从节点启动数据库服务。
- 5、检测命令
- ansible node1 -a "netstat -ntpl"
- 0 0.0.0.0:4567
- ansible node1 -m shell -a "mysql -uroot -p123456 -e "show status like 'wsrep_ready';" "
- wsrep_ready ON
- ansible node1 -m shell -a "mysql -uroot -p123456 -e "show status like 'wsrep_cluster_size';""
- wsrep_cluster_size 3
复制代码 3、mariadb 集群HA高可用
- yum install -y haproxy
- listen stats
- mode http
- bind vm1:9000
- stats uri /
- backend mariadb
- balance roundrobin
- mode tcp
- bind vm1:3307
- server vm1 vm1:3306 check weight 3
- server vm2 vm2:3306 check weight 3
- server vm3 vm3:3306 check weight 4
- 检测:
- 3307端口,weight
复制代码 免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |