美文网首页
Centos7环境下Maxscale安装配置

Centos7环境下Maxscale安装配置

作者: 武斌OUC | 来源:发表于2017-06-07 13:48 被阅读0次

    下载软件

    maxscale-2.1.2-1.centos.7.x86_64.rpm

    安装

    yum install libaio.x86_64 libaio-devel.x86_64 novacom-server.x86_64 libedit -y
    rpm -ivh maxscale-2.1.2-1.centos.7.x86_64.rpm
    

    配置

    创建监控用户

    MySQL [(none)]> create user scalemon@'%' identified by "password";
    Query OK, 0 rows affected (0.02 sec)
    
    MySQL [(none)]> grant replication slave, replication client on *.* to scalemon@'%';
    Query OK, 0 rows affected (0.00 sec)
    
    

    创建路由用户

    MySQL [(none)]> create user maxscale@'%' identified by "password";
    Query OK, 0 rows affected (0.01 sec)
    
    MySQL [(none)]> grant select on mysql.* to maxscale@'%';
    Query OK, 0 rows affected (0.00 sec)
    

    配置mascale

    vim /etc/maxscale.cnf
    

    找到 [server1] 部分,修改其中的 address 和 port,指向 master 的 IP 和端口

    复制1次 [server1] 的整块儿内容,改为 [server2] ,同样修改其中的 address 和 port,指向 slave:

    [server1]
    type=server
    address=172.19.6.209
    port=3306
    protocol=MySQLBackend
    
    [server2]
    type=server
    address=172.19.10.204
    port=3306
    protocol=MySQLBackend
    

    找到 [MySQL Monitor] 部分,修改 servers 为 server1,server2,修改 user 和 passwd 为之前创建的监控用户的信息(scalemon,scalemon2017SaasHisenseHics)

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

    找到 [Read-Write Service] 部分,修改 servers 为 server1,server2,修改 user 和 passwd 为之前创建的路由用户的信息(maxscale,maxscale2017SaasHisenseHics)

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

    由于我们使用了 [Read-Write Service],需要删除另一个服务 [Read-Only Service],删除其整块儿内容即可

    配置完成,保存并退出编辑器

    启动MaxScale

    maxscale --config=/etc/maxscale.cnf
    

    查看状态

    $maxadmin -S /tmp/maxadmin.sock
    MaxScale> list servers
    Servers.
    -------------------+-----------------+-------+-------------+--------------------
    Server             | Address         | Port  | Connections | Status              
    -------------------+-----------------+-------+-------------+--------------------
    server1            | 172.19.6.209    |  3306 |           0 | Master, Running
    server2            | 172.19.10.204   |  3306 |           0 | Slave, Running
    -------------------+-----------------+-------+-------------+--------------------
    

    测试

    先在 master 上创建一个测试用户

    mysql> grant ALL PRIVILEGES on *.* to rtest@”%” Identified by “111111”;
    

    使用 Mysql 客户端到连接 MaxScale

    mysql -h MaxScale所在的IP -P 4006 -u rtest -p111111
    

    执行查看数据库服务器名的操作来知道当前实际所在的数据库:

    mysql> select @@hostname;
    +-------------------------+
    | @@hostname              |
    +-------------------------+
    | iZ2zei5qxdafjnxte8val2Z |
    +-------------------------+
    1 row in set (0.00 sec)
    
    mysql> start transaction;
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> select @@hostname;
    +-------------------------+
    | @@hostname              |
    +-------------------------+
    | iz2ze1wvn1qznw6fmoqhcnz |
    +-------------------------+
    1 row in set (0.00 sec)
    
    mysql> rollback;
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> select @@hostname;
    +-------------------------+
    | @@hostname              |
    +-------------------------+
    | iZ2zei5qxdafjnxte8val2Z |
    +-------------------------+
    1 row in set (0.00 sec)
    

    注意事项

    如果使用root用户安装的MaxScale,当使用systemctl命令启动MaxScale时会启动失败,这时候需要调整启动的参数:

    vim /usr/lib/systemd/system/maxscale.service
    

    修改用户和组内容如下:

    # Use the default user and group
    User=root
    Group=root
    
    $systemctl daemon-reload 
    $systemctl enable maxscale.service 
    Created symlink from /etc/systemd/system/multi-user.target.wants/maxscale.service to /usr/lib/systemd/system/maxscale.service.
    

    相关文章

      网友评论

          本文标题:Centos7环境下Maxscale安装配置

          本文链接:https://www.haomeiwen.com/subject/tunofxtx.html