hege 发表于 2018-9-29 13:50:24

使用Maxscale实现mysql读写分离

vi /etc/maxscale.conf  

  
#全局配置:
  

  
threads=auto
  
log_info=1
  
log_notice=1
  
log_warning=1
  

  
#后端mysql定义
  

  
type=server
  
address=192.168.10.1
  
port=3306
  
protocol=MySQLBackend
  

  
type=server
  
address=192.168.10.2
  
port=3306
  
protocol=MySQLBackend
  

  
#监控配置
  

  
type=monitor
  
module=mysqlmon      #监控模块默认使用mysqlmon,当然还有其他可选择的模块
  
servers=server1,server2
  
user=admin      #admin监控后端mysql的复制状况,必须具有REPLICATION CLIENT权限
  
passwd=123456
  
monitor_interval=10000
  

  
#触发器定义 注意,以下两句的上下顺序不能变,不然无法生效
  
script=/opt/mysql_monitor.sh#定义事件触发脚本执行
  
events=master_down       #事件触发器当master down时,执行上面的脚本,maxscale内置了很
  
                                 多的events
  
#读写分离service
  

  
type=service
  
router=readwritesplit       #读写分离路由模式
  
servers=server1,server2
  
user=maxscale    #该用户从后端mysql获取用户信息,对客户端进行身份验证,必须具有mysql.user table的select权限
  
passwd=maxscale
  
max_slave_connections=100%
  
max_slave_replication_lag=3600000   #当slave的数据落后master小于3600秒时仍然可用
  
connection_timeout=300
  
router_options=master_failure_mode=error_on_write #允许master down掉,slave仍然可读
  
#router_options=master_accept_reads=true      #允许master接受读请求
  

  

  
type=listener
  
service=Read-Write Service
  
protocol=MySQLClient
  
port=3306
  

  
#管理服务配置
  

  
type=service
  
router=cli
  

  
#管理服务监听
  

  
type=listener
  
service=MaxAdmin Service
  
protocol=maxscaled
  
socket=default


页: [1]
查看完整版本: 使用Maxscale实现mysql读写分离