一、准备环境
系统版本 | mysql版本 | maxscale版本 |
---|---|---|
rocky 9.0 | mysql 8.0.26 | maxscale-22.08.2-1.rocky.9.x86_64.rpm |
centos 7.6~7.9 | mysql 5.7.30 | maxscale-2.3.5-1.centos.7.x86_64.rpm |
centos 8.2 | mysql 8.0.26 | maxscale-2.4.7-1.centos.8.x86_64.rpm |
下载地址有两个:
第一个:https://downloads.mariadb.com/MaxScale/
第二个:https://mariadb.com/downloads/community/maxscale/
系统版本 | 我安装的版本链接 |
---|---|
rocky 9.0 | wget https://dlm.mariadb.com/2539033/MaxScale/22.08.2/rhel/9/x86_64/maxscale-22.08.2-1.rocky.9.x86_64.rpm |
centos 7.6~7.9 | wget https://downloads.mariadb.com/MaxScale/2.3.5/centos/7/x86_64/maxscale-2.3.5-1.centos.7.x86_64.rpm |
centos 8.2 | wget https://downloads.mariadb.com/MaxScale/2.4.7/centos/8/x86_64/maxscale-2.4.7-1.centos.8.x86_64.rpm |
mysql5.7.30 安装脚本及下载地址,下载地址脚本上方注释已经标明
mysql 8.0.26 下载地址:
链接:https://pan.baidu.com/s/13NFr8gYdayI85y3eZhdAQQ
提取码:8888
mysql 8.0.26 安装和 5.7.30差不多 但是不能使用 5.7.30脚本,脚本在制作中
mysql -u root -p '123456' 如果有以下报错 解决方式如下
报错:
./mysql: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory
./mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
解决方案:
cd /usr/lib64/
ln -s libtinfo.so.6 libtinfo.so.5
ln -s libncurses.so.6.2 libncurses.so.5
以上为mysql安装文档
主从配置地址:
两个前提完成之后 开始安装 maxscale
主库安装 从库不用
master ~]# yum -y install maxscale*.rpm
master主库创建监控用户
mysql -uroot -p123456
create user 'maxmon'@'%' identified by 'maxmon';
ALTER USER 'maxmon'@'%' IDENTIFIED WITH mysql_native_password BY 'maxmon';
grant replication slave,replication client on *.* to 'maxmon'@'%';
创建路由用户
create user 'maxrou'@'%' identified by 'maxrou';
ALTER USER 'maxrou'@'%' IDENTIFIED WITH mysql_native_password BY 'maxrou';
grant all on *.* to 'maxrou'@'%';
flush privileges;
修改配置文件 以下这个配置文件适用于maxscale低版本
vim /etc/maxscale.cnf
# MaxScale documentation:
# https://mariadb.com/kb/en/mariadb-enterprise/mariadb-maxscale-23/
# Global parameters
#
# Complete list of configuration options:
# https://mariadb.com/kb/en/mariadb-maxscale-23-mariadb-maxscale-configuration-usage-scenarios/
[maxscale]
threads=auto
logdir=/usr/local/mysql/maxscale/logs
datadir=/usr/local/mysql/maxscale/data
piddir=/usr/local/mysql/maxscale/logs
cachedir=/usr/local/mysql/maxscale/cache
# Server definitions
#
# Set the address of the server to the network
# address of a MariaDB server.
#
# 目前是两台为server1、server2 ,server2 是复制的 server1
[server1]
type=server
address=192.168.45.157
port=3306
protocol=MariaDBBackend
[server2]
type=server
address=192.168.45.158
port=3306
protocol=MariaDBBackend
# Monitor for the servers
#
# This will keep MaxScale aware of the state of the servers.
# MariaDB Monitor documentation:
# https://mariadb.com/kb/en/mariadb-maxscale-23-mariadb-monitor/
# 监控账户密码 和server集群
[MariaDB-Monitor]
type=monitor
module=mariadbmon
servers=server1,server2
user=maxmon
password=maxmon
monitor_interval=2000
# Service definitions
#
# Service Definition for a read-only service and
# a read/write splitting service.
#
# ReadConnRoute documentation:
# https://mariadb.com/kb/en/mariadb-maxscale-23-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-23-readwritesplit/
#路由账户密码
[Read-Write-Service]
type=service
router=readwritesplit
servers=server1,server2
user=maxrou
password=maxrou
# This service enables the use of the MaxAdmin interface
# MaxScale administration guide:
# https://mariadb.com/kb/en/mariadb-maxscale-23-maxadmin-admin-interface/
#新加这个模块
[MaxAdmin-Service]
type=service
router=cli
# 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=listener
service=Read-Write-Service
protocol=MariaDBClient
port=4006
#新建模块
[MaxAdmin-Listener]
type=listener
service=MaxAdmin-Service
protocol=maxscaled
#socket=default
port=4016 #默认端口 8989
修改配置文件 以下这个配置文件适用于maxscale高版本
# MaxScale documentation:
# https://mariadb.com/kb/en/mariadb-maxscale-6/
# Global parameters
#
# Complete list of configuration options:
# https://mariadb.com/kb/en/mariadb-maxscale-6-mariadb-maxscale-configuration-guide/
[maxscale]
threads=auto
logdir=/usr/local/mysql/maxscale/logs
datadir=/usr/local/mysql/maxscale/data
piddir=/usr/local/mysql/maxscale/logs
cachedir=/usr/local/mysql/maxscale/cache
# Server definitions
#
# Set the address of the server to the network
# address of a MariaDB server.
#
[server1]
type=server
address=192.168.45.157
port=3306
protocol=MariaDBBackend
[server2]
type=server
address=192.168.45.158
port=3306
protocol=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-6-monitors/
#
# Create the monitor user with:
#
# CREATE USER 'monitor_user'@'%' IDENTIFIED BY 'monitor_pw';
# GRANT REPLICATION CLIENT, FILE, SUPER, RELOAD, PROCESS, SHOW DATABASES, EVENT ON *.* TO 'monitor_user'@'%';
#
[MariaDB-Monitor]
type=monitor
module=mariadbmon
servers=server1,server2
user=maxmon
password=maxmon
# monitor_interval=2s
# Service definitions
#
# Service Definition for a read-only service and
# a read/write splitting service.
#
# Create the service user with:
#
# CREATE USER 'service_user'@'%' IDENTIFIED BY 'service_pw';
# GRANT SELECT ON mysql.user TO 'service_user'@'%';
# GRANT SELECT ON mysql.db TO 'service_user'@'%';
# GRANT SELECT ON mysql.tables_priv TO 'service_user'@'%';
# GRANT SELECT ON mysql.columns_priv TO 'service_user'@'%';
# GRANT SELECT ON mysql.procs_priv TO 'service_user'@'%';
# GRANT SELECT ON mysql.proxies_priv TO 'service_user'@'%';
# GRANT SELECT ON mysql.roles_mapping TO 'service_user'@'%';
# GRANT SHOW DATABASES ON *.* TO 'service_user'@'%';
#
# ReadConnRoute documentation:
# https://mariadb.com/kb/en/mariadb-maxscale-6-readconnroute/
#[Read-Only-Service]
#type=service
#router=readconnroute
#servers=server1
#user=service_user
#password=service_pw
#router_options=slave
#
# ReadWriteSplit documentation:
# https://mariadb.com/kb/en/mariadb-maxscale-6-readwritesplit/
[Read-Write-Service]
type=service
router=readwritesplit
servers=server1,server2
user=maxrou
password=maxrou
# Listener definitions for the services
#
# These listeners represent the ports the
# services will listen on.
#
#[MaxAdmin-Service]
#type=service
#router=cli
#[Read-Only-Listener]
#type=listener
#service=Read-Only-Service
#protocol=MariaDBClient
#port=4008
[Read-Write-Listener]
type=listener
service=Read-Write-Service
protocol=MariaDBClient
port=4006
启动
mkdir -p /usr/local/mysql/maxscale/logs
mkdir -p /usr/local/mysql/maxscale/data
mkdir -p /usr/local/mysql/maxscale/logs
mkdir -p /usr/local/mysql/maxscale/cache
maxscale --config=/etc/maxscale.cnf --user=mysql
#查看 4006 和 默认8989 端口起来没有 如果将端口修改了 就查看修改端口
netstat -ntelp
如果端口没起来,查看报错,我的报错如下:
more /usr/local/mysql/maxscale/logs/maxscale.log
MariaDB MaxScale /usr/local/mysql/maxscale/logs/maxscale.log Fri Dec 9 13:18:03 2022
-----------------------------------------------------------------------------------------
2022-12-09 13:18:03 notice : Using up to 37.69GiB of memory for query classifier cache
2022-12-09 13:18:03 notice : syslog logging is disabled.
2022-12-09 13:18:03 notice : maxlog logging is enabled.
2022-12-09 13:18:03 error : Failed to create directory '/var/lib/maxscale/maxscale.cnf.d': 13, Permission denied
alert : Can't access '/var/lib/maxscale/maxscale.cnf.d'.: No such file or directory.
2022-12-09 13:18:03 MariaDB MaxScale is shut down.
分别是权限被拒绝和缺一个目录文件
mkdir /var/lib/maxscale/maxscale.cnf.d
chown -R mysql:mysql /var/lib/maxscale/
再次启动 完成
登录MaxScale管理器,默认账户admin 密码 mariadb
不要在意IP地址,因为我每个版本都装了一次,大概意思就是如下,感觉还是高版本高大上一些
低版本登陆方式
查看服务
maxadmin --user=admin --password=mariadb
MaxScale> list servers
高版本登陆方式
查看服务
maxctrl
创建测试用户
create user 'db_test'@'%' identified by 'db_test';
ALTER USER 'db_test'@'%' IDENTIFIED WITH mysql_native_password BY 'db_test';
grant select,insert on testdb.* to 'db_test'@'%';
flush privileges;
mysql 连接 MaxScale
mysql -urtest -pdb_test -h'192.168.0.160' -P4006
Select @@hostname;
##开启事务,MaxScale切换到master
start transaction;
Select @@hostname;
回滚
rollback;
Select @@hostname;