配置数据库读写分离服务器
admin
2023-04-29 02:01:25
0

配置一主一从 主从同步结构,并在客户端测试配置
master51> grant all on webdb.* to webuser@"%" identified by " 123456";

装包
rpm -ivh maxscale-2.1.2-1.rhel.7.x86_64.rpm

[root@host56 ~]# rpm -qa | grep maxscale
maxscale-2.1.2-1.x86_64

[root@host56 ~]# rpm -qc maxscale
/etc/maxscale.cnf.template

[root@host56 ~]#
修改配置文件
[root@host56 ~]# ls /etc/maxscale.cnf
/etc/maxscale.cnf

[root@host56 ~]# cp /etc/maxscale.cnf /etc/maxscale.cnf.bak

[root@host56 ~]# vim /etc/maxscale.cnf
[maxscale]
threads=1  也可是是auto
[server1]
type=server
address=192.168.4.51
port=3306
protocol=MySQLBackend

[server2]
type=server
address=192.168.4.52
port=3306
protocol=MySQLBackend

[MySQL Monitor]
type=monitor
module=mysqlmon
servers=server1, server2
user=scalemon
passwd=123456
monitor_interval=10000

[Read-Write Service]
type=service
router=readwritesplit
servers=server1, server2
user=maxscale
passwd=123456
max_slave_connections=100%

[MaxAdmin Service]
type=service
router=cli

[Read-Write Listener]
type=listener
service=Read-Write Service
protocol=MySQLClient
port=4006

[MaxAdmin Listener]
type=listener
service=MaxAdmin Service
protocol=maxscaled
socket=default
port=4018

根据配置文件做相应的设置(在2台数据库服务器上添加用户)
监控数据库服务器时,连接数据库服务器的用户
mysql> grant replication slave, replication client on 星.星 to scalemon@'%' identified by "123456";

验证 访问数据时,连接数据库服务器使用的用户,是否在数据库服务器上存在的,连接用户
mysql> grant select on mysql.* to maxscale@'%' identified by "123456";

查看授权用户
mysql> select user,host from mysql.user where user in ("scalemon","maxscale");
+----------+------+
| user | host |
+----------+------+
| maxscale | % |
| scalemon | % |
+----------+------+

启动服务
[root@host56 ~]# maxscale -f /etc/maxscale.cnf

查看服务进程和端口

查看端口
[root@host56 ~]# netstat -utnlp | grep :4006
[root@host56 ~]# netstat -utnlp | grep :4018
[root@host56 ~]# ps -C maxscale

停止服务
[root@host56 ~]# ps -C maxscale
PID TTY TIME CMD
29688 ? 00:00:00 maxscale
[root@host56 ~]# kill -9 29688
[root@host56 ~]#
[root@host56 ~]#
[root@host56 ~]# kill -9 29688
-bash: kill: (29688) - 进程不存在

2.2.3 测试配置
A 在本机访问管理管端口查看监控状态

[root@host56 ~]# maxadmin -P4018 -uadmin -pmariadb
MaxScale> list servers
Servers.
-------------------+-----------------+-------+-------------+--------------------
Server | Address | Port | Connections | Status
-------------------+-----------------+-------+-------------+--------------------
server1 | 192.168.4.51 | 3306 | 0 | Master, Running
server2 | 192.168.4.52 | 3306 | 0 | Slave, Running
-------------------+-----------------+-------+-------------+--------------------
MaxScale> exit
[root@host56 ~]#

b 客户端访问数据读写分离服务器
]#which mysql
]# mysql -h292.168.4.56 -P4006 -uwebuser -p123456
mysql> select @@hostname;
mysql> 执行插入或查询 ( 在51 和 52 本机查看记录)

相关内容

热门资讯

检察机关依法对林景臻涉嫌受贿案... 检察日报全媒体记者5月13日从最高人民检察院获悉,中国银行股份有限公司原党委委员、副行长林景臻涉嫌受...
从“看山看水”到“乐享山水”—... “十五五”首个“五一”假期,文旅市场热力迸发、全线升温。从“看山看水”到“乐享山水”,从品文化到入生...
工作时间减少1%,肥胖率或下降... 澎湃新闻记者 季敬杰合理调整生活与工作的平衡可能会给健康带来意想不到的好处。近日一项研究指出,年度工...
美媒:中美元首会晤或讨论AI护... 据凤凰卫视援引美国媒体报道,美方希望借中美领导人会晤的机会,开启有关人工智能安全与管控的对话,并推动...
卫生间水管布置图尺寸高度 卫生间的水管布置可能比较复杂一些,因为卫生间的管道比较多。比如有热水器的通水管道,有座便器的冲水管道...
电脑尺寸在哪里看 电脑尺寸在哪里看1、可以选择手工测量法来测量电脑尺寸,这时测量一下屏幕对角线,因为显示面积都会小于显...
电脑机箱尺寸标准 常规的机箱一般是立体式,或桌面式,再就是横式。电脑机箱尺寸,目前市面上根据不同的规格有不同的方案。 ...
斯塔默发声:不会辞职 【环球时报驻英国特约记者 纪双城 环球时报特约记者 甄翔 于文】执政党工党在英国地方选举中遭遇“历史...
抽油烟机管道有异味怎么办 抽油烟机是厨房中不可或缺的设备,它能有效地排出油烟,保证室内空气的清新。但是,长时间使用后,抽油烟机...
抽油烟机管道有油垢怎么办 抽油烟机管道是我们家庭生活中必不可少的设备,但长时间的使用会导致管道内部积累大量的油垢,如不及时清理...