在 CentOS 7 上安装 MariaDB MaxScale
使用 ssh 连接到任意节点 maxscale.onitroad.com。
安装 MariaDB 和 MaxScale yum 存储库。
[root@maxscale ~]# curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | bash [info] Repository file successfully written to /etc/yum.repos.d/mariadb.repo. [info] Adding trusted package signing keys... [info] Succeessfully added trusted package signing keys.
构建 yum 缓存。
[root@maxscale ~]# yum makecache fast
使用 yum 命令安装 MariaDB MaxScale。
[root@maxscale ~]# yum install -y maxscale
现在连接到 MariaDB Galera Cluster 的一个实例,并创建一个用户以通过 MaxScale 进行监控和身份验证。
(由于我们的节点已经形成了集群,因此,我们只需要在任何节点上执行一次以下命令即可)。
[root@mariadb-01 ~]# mysql -u root -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 11 Server version: 10.3.12-MariaDB MariaDB Server Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]>
执行以下命令以创建具有必要权限的 MaxScale 用户,以正确执行其功能。
MariaDB [(none)]> create user 'maxscale'@'192.168.1.80' identified by '123'; Query OK, 0 rows affected (0.005 sec) MariaDB [(none)]> grant select on mysql.user to 'maxscale'@'192.168.1.80'; Query OK, 0 rows affected (0.041 sec) MariaDB [(none)]> grant select on mysql.db to 'maxscale'@'192.168.1.80'; Query OK, 0 rows affected (0.002 sec) MariaDB [(none)]> grant select on mysql.tables_priv to 'maxscale'@'192.168.1.80'; Query OK, 0 rows affected (0.043 sec) MariaDB [(none)]> grant show databases on *.* to 'maxscale'@'192.168.1.80'; Query OK, 0 rows affected (0.003 sec) MariaDB [(none)]> flush privileges; Query OK, 0 rows affected (0.004 sec)
创建具有从任何机器远程连接权限的用户。
我们的应用程序将使用此用户连接到 MariaDB Galera 集群。
MariaDB [(none)]> create user jackli@'%' identified by '123'; Query OK, 0 rows affected (0.005 sec) MariaDB [(none)]> grant show databases on *.* to jackli@'%'; Query OK, 0 rows affected (0.003 sec) MariaDB [(none)]> flush privileges; Query OK, 0 rows affected (0.004 sec) MariaDB [(none)]> exit Bye
现在,连接到 maxscale.onitroad.com 并配置 MaxScale 数据库代理。
编辑 MaxScale 配置。
[root@maxscale ~]# mv /etc/maxscale.cnf /etc/maxscale.cnf.old [root@maxscale ~]# vi /etc/maxscale.cnf
并添加以下指令。
(有关 MaxScale 配置参数的更多信息,请参阅 MaxScale 文档)
#Global MaxScale Settings [maxscale] threads=auto #Define Server Nodes [mariadb-01] type=server address=192.168.1.81 port=3306 protocol=MariaDBBackend [mariadb-02] type=server address=192.168.1.82 port=3306 protocol=MariaDBBackend #Define Monitoring Service [Galera-Monitor] type=monitor module=galeramon servers=mariadb-01,mariadb-02 user=maxscale password=123 monitor_interval=1000 #Define Galera Service [Galera-Service] type=service router=readconnroute router_options=synced servers=mariadb-01,mariadb-02 user=maxscale password=123 #Define Galera Listener [Galera-Listener] type=listener service=Galera-Service protocol=MariaDBClient port=4306 #Define Administration Service [MaxAdmin-Service] type=service router=cli #Define Administration Listener [MaxAdmin-Listener] type=listener service=MaxAdmin-Service protocol=maxscaled socket=default
允许 Linux 防火墙中的服务端口。
[root@maxscale ~]# firewall-cmd --permanent --add-port=4306/tcp success [root@maxscale ~]# firewall-cmd --reload success
启动并启用 MaxScale 服务。
[root@maxscale ~]# systemctl start maxscale.service [root@maxscale ~]# systemctl enable maxscale.service
使用 jackli 用户通过 MaxScale 数据库代理建立从客户端到 Galera 集群的一些连接。
[root@client-01 ~]# mysql -h maxscale.onitroad.com -P 4306 -u jackli -p
使用 ssh 连接到 maxscale.onitroad.com,并使用 maxadmin 命令查看与 MariaDB Galera 集群的连接状态。
[root@maxscale ~]# maxadmin MaxScale> list servers Servers. -------------------+-----------------+-------+-------------+------------------- Server | Address | Port | Connections | Status -------------------+-----------------+-------+-------------+------------------- mariadb-01 | 192.168.1.81 | 3306 | 2 | Slave, Synced, Running mariadb-02 | 192.168.1.82 | 3306 | 3 | Master, Synced, Running -------------------+-----------------+-------+-------------+------------------- MaxScale>
上面的命令显示了 MariaDB Galera 集群中节点的状态,包括活动连接和复制状态。
我们可以使用 help 命令获取有关 maxadmin 命令的帮助,或者参阅 maxadmin 文档以获取完整参考。
我们已经在 CentOS 7 服务器上成功安装了 MariaDB MaxScale 数据库代理。
MaxScale 是 MariaDB 开发的智能数据库代理。
MaxScale 在商业源许可 (BSL) 下是免费和开源的。
MaxScale 扩展了 MariaDB 服务器的高可用性、负载平衡、可扩展性和安全性,并通过将其与底层数据库基础架构解耦来简化应用程序开发。