文章插图
- MaxScale代理服务:192.168.26.152
- 主库:192.168.26.153(写)
- 从库:192.168.26.154(读)
- 客户端: 192.168.26.155
可以参考官方文档:https://mariadb.com/docs/deploy/topologies/primary-replica/enterprise-server-10-6/install-mxs/
安装包下载: https://downloads.mariadb.com/files/MaxScale
需要的依赖包下载:https://rpmfind.NET/linux/rpm2html/search.php
依赖安装
┌──[root@vms152.liruilongs.github.io]-[~]└─$yum -y install libatomic软件包 libatomic-4.8.5-44.el7.x86_64 已安装并且是最新版本无须任何处理
┌──[root@vms152.liruilongs.github.io]-[~]└─$wget https://rpmfind.net/linux/centos/7.9.2009/os/x86_64/Packages/trousers-0.3.14-2.el7.x86_64.rpm--2022-09-29 20:13:22-- https://rpmfind.net/linux/centos/7.9.2009/os/x86_64/Packages/trousers-0.3.14-2.el7.x86_64.rpm┌──[root@vms152.liruilongs.github.io]-[~]└─$rpm -ivh trousers-0.3.14-2.el7.x86_64.rpm准备中... ################################# [100%]正在升级/安装...1:trousers-0.3.14-2.el7 ################################# [100%]┌──[root@vms152.liruilongs.github.io]-[~]└─$
┌──[root@vms152.liruilongs.github.io]-[~]└─$wget https://rpmfind.net/linux/centos/7.9.2009/os/x86_64/Packages/nettle-2.7.1-8.el7.x86_64.rpm--2022-09-29 20:14:52-- https://rpmfind.net/linux/centos/7.9.2009/os/x86_64/Packages/nettle-2.7.1-8.el7.x86_64.rpm┌──[root@vms152.liruilongs.github.io]-[~]└─$rpm -ivh nettle-2.7.1-8.el7.x86_64.rpm准备中... ################################# [100%]正在升级/安装...1:nettle-2.7.1-8.el7 ################################# [100%]┌──[root@vms152.liruilongs.github.io]-[~]└─$
┌──[root@vms152.liruilongs.github.io]-[~]└─$wget https://rpmfind.net/linux/centos/7.9.2009/os/x86_64/Packages/gnutls-3.3.29-9.el7_6.x86_64.rpm--2022-09-29 20:15:50-- https://rpmfind.net/linux/centos/7.9.2009/os/x86_64/Packages/gnutls-3.3.29-9.el7_6.x86_64.rpm┌──[root@vms152.liruilongs.github.io]-[~]└─$rpm -ivh gnutls-3.3.29-9.el7_6.x86_64.rpm准备中... ################################# [100%]正在升级/安装...1:gnutls-3.3.29-9.el7_6 ################################# [100%]┌──[root@vms152.liruilongs.github.io]-[~]└─$
安装完依赖包安装 maxscale
安装 MaxScale
┌──[root@vms152.liruilongs.github.io]-[~]└─$rpm -ivh maxscale-2.5.21-1.rhel.7.x86_64.rpm警告:maxscale-2.5.21-1.rhel.7.x86_64.rpm: 头V4 RSA/SHA512 Signature, 密钥 ID e3c94f49: NOKEY准备中... ################################# [100%]正在升级/安装...1:maxscale-2.5.21-1.rhel.7 ################################# [100%]Created symlink from /etc/systemd/system/multi-user.target.wants/maxscale.service to /usr/lib/systemd/system/maxscale.service.┌──[root@vms152.liruilongs.github.io]-[~]└─$
配置 MaxScale┌──[root@vms152.liruilongs.github.io]-[~]└─$cp /etc/maxscale.cnf /etc/maxscale.cnf.bak┌──[root@vms152.liruilongs.github.io]-[~]└─$vim /etc/maxscale.cnf
备份配置文件,然后修改
┌──[root@vms152.liruilongs.github.io]-[~]└─$cat /etc/maxscale.cnf# MaxScale documentation:# https://mariadb.com/kb/en/mariadb-maxscale-25/# Global parameters# Complete list of configuration options:# https://mariadb.com/kb/en/mariadb-maxscale-25-mariadb-maxscale-configuration-guide/[maxscale]# 定义线程的个数,一个线程对应一个CPU核心数,线程数量要小于等于CPU核心数threads=auto# Server definitions# Set the address of the server to the network# address of a MariaDB server.# 指定要代理的数据库服务器信息[server1]type=serveraddress=192.168.26.153 #需要数据库服务器IPport=3306protocol=MariaDBBackend[server2]type=serveraddress=192.168.26.154port=3306protocol=MariaDBBackend# Monitor for the servers# This will keep MaxScale aware of the state of the servers.# MariaDB Monitor documentation:# https://mariadb.com/kb/en/maxscale-25-monitors/# 定义要监控的数据库服务器[MariaDB-Monitor]type=monitormodule=mariadbmonservers=server1,server2#指定监控用户maxscalemon,用于登录后端服务器,检查服务器的运行状态和主从状态user=maxscalemonpassword=liruilongmonitor_interval=10000# Service definitions# Service Definition for a read-only service and# a read/write splitting service.# ReadConnRoute documentation:# https://mariadb.com/kb/en/mariadb-maxscale-25-readconnroute/#定义只读服务器配置,需要注释掉,我们配置的是读写分离#[Read-Only-Service]#type=service#router=readconnroute#servers=server1#user=myuser#password=mypwd#router_options=slave# ReadWriteSplit documentation:# https://mariadb.com/kb/en/mariadb-maxscale-25-readwritesplit/#定义读写分离服务器配置[Read-Write-Service]type=servicerouter=readwritesplitservers=server1,server2 ##指定做读写分离服务的数据库服务器user=maxscaleroutepassword=liruilong##客户端通过用户名和密码向数据库发送请求,先访问maxscale代理服务器,再由代理服务器将请求转发##给后端数据库服务器;maxscale代理服务器是通过路由用户连接后端服务器,检测客户端的用户名和密码在##后端数据库中是否存在# Listener definitions for the services# These listeners represent the ports the# services will listen on.#[Read-Only-Listener]#type=listener#service=Read-Only-Service#protocol=MariaDBClient#port=4008# 定义读写分离服务使用的端口号[Read-Write-Listener]type=listenerservice=Read-Write-Serviceprotocol=MariaDBClientport=4006┌──[root@vms152.liruilongs.github.io]-[~]└─$
推荐阅读
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Linux网卡聚合交互式配置脚本
- 民间故事花木兰代父从军,关于花木兰替父从军的故事-
- 蛋白质|减肥饮食:关于保留蛋白质的改良快速饮食——PSMF
- 很搞笑的段子软件,很搞笑的段子关于拉屎的-
- 春节的10大习俗,你知道几个? 关于春节的习俗
- 七夕节是从什么演变而来的,关于七夕节的起源-_1
- 十大好玩的传奇游戏 关于传奇的网游
- 关于中秋节有哪些诗句简单点,关于中秋节的诗词名句 中秋诗词-
- 骨折不愈合的治疗原则
- 春节描写传统节日的古诗句,关于春节和过年的古代诗词-