{"id":107871,"date":"2024-10-28T02:44:10","date_gmt":"2024-10-27T18:44:10","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=107871"},"modified":"2024-10-28T02:44:10","modified_gmt":"2024-10-27T18:44:10","slug":"mariadb-maxscale","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/mariadb-maxscale.html","title":{"rendered":"\u8be6\u89e3\uff1aMaxScale\u4e2d\u95f4\u4ef6\u90e8\u7f72\u6570\u636e\u5e93\u8bfb\u5199\u5206\u79bb"},"content":{"rendered":"
\u64cd\u4f5c\u7cfb\u7edf:CentOS Linux release 7.3.1611 (Core)<\/p>\n
\u6570\u636e\u5e93:MariaDB-10.2.6-linux-glibc_214-x86_64<\/p>\n
MaxScale\u670d\u52a1\u5668:10.200.10.55<\/p>\n
\u4e3b\u670d\u52a1\u5668:172.16.8.56<\/p>\n
\u4ece\u670d\u52a1\u5668:172.16.8.57<\/p>\n
\u4ece\u670d\u52a1\u5668:172.16.8.58<\/p>\n
1.maxscale\u7684\u5b89\u88c5\u65b9\u5f0f\u6709\u5f88\u591a\uff0c\u4f8b\u5982\u6e90\u7801\u5b89\u88c5\u3001rpm\u3001\u4e8c\u8fdb\u5236\u6784\u5efa\u7b49\uff0c\u6211\u9009\u62e9\u4e8c\u8fdb\u5236\u8fdb\u884c\u5b89\u88c5\u3002<\/p>\n
\u6839\u636e\u573a\u666f\u9700\u8981\u4e0b\u8f7d\u76f8\u5bf9\u5e94\u7684\u7248\u672c\uff0c\u4e0b\u8f7d\u5730\u5740\uff1bhttps:\/\/mariadb.com\/downloads\/maxscale<\/p>\n
\r\n [root@localhost ~]# groupadd maxscale\r\n [root@localhost ~]# useradd -g maxscale maxscale\r\n [root@localhost ~]# cd \/usr\/local\r\n [root@localhost local]# wget https:\/\/downloads.mariadb.com\/MaxScale\/2.1.3\/centos\/7server\/x86_64\/maxscale-2.1.3.centos.7.tar.gz\r\n [root@localhost local]# tar zxvf maxscale-2.1.3.centos.7.tar.gz\r\n [root@localhost local]# ln -s maxscale-2.1.3.centos.7 maxscale\r\n [root@localhost local]# cd maxscale\r\n [root@zhu56 maxscale]# chown -R maxscale var\r\n<\/pre>\n\u5efa\u8bae\u521b\u5efa\u8f6f\u8fde\u63a5\uff0c\u8fd9\u6837\u6709\u52a9\u4e8e\u4ee5\u540e\u7684\u7248\u672c\u5347\u7ea7\u53ca\u540e\u671f\u7ef4\u62a4\u3002<\/p>\n
2.\u9996\u6b21\u5b89\u88c5maxscale\u9700\u8981\u521b\u5efa\u65e5\u5fd7\u76f8\u5173\u76ee\u5f55<\/p>\n
\r\n [root@localhost ~]# mkdir \/var\/log\/maxscale\r\n [root@localhost ~]# mkdir \/var\/lib\/maxscale\r\n [root@localhost ~]# mkdir \/var\/run\/maxscale\r\n [root@localhost ~]# mkdir \/var\/cache\/maxscale\r\n<\/pre>\n3.\u4ee5\u4e0b\u76ee\u5f55\u5fc5\u987b\u5177\u5907maxscala\u7528\u6237\u6743\u9650<\/p>\n
\r\n [root@localhost ~]# chown maxscale \/var\/log\/maxscale\r\n [root@localhost ~]# chown maxscale \/var\/lib\/maxscale\r\n [root@localhost ~]# chown maxscale \/var\/run\/maxscale\r\n [root@localhost ~]# chown maxscale \/var\/cache\/maxscale\r\n<\/pre>\n4.\u4e3a\u4e86\u80fd\u8ba9Maxscale\u80fd\u987a\u5229\u542f\u52a8\uff0c\u8fd8\u9700\u8981\u521b\u5efa\u914d\u7f6e\u6587\u4ef6\uff0c\u5728Maxscale\u76ee\u5f55\u4e0b\u6709\u914d\u7f6e\u6587\u4ef6\u6a21\u677f\u62f7\u8d1d\u5230etc\u4e0b\u5373\u53ef\u3002<\/p>\n
\r\n [root@localhost ~]# cp \/usr\/local\/maxscale\/etc\/maxscale.cnf.template \/etc\/maxscale.cnf\r\n<\/pre>\n5.\u5728\u4fee\u6539\u914d\u7f6e\u6587\u4ef6\u4e4b\u524d\uff0c\u9700\u8981\u5728\u4e3b\u670d\u52a1\u5668\u4e0a\u521b\u5efa\u4e00\u4e2a\u7528\u6237\u5e76\u7ed9\u4e88\u6388\u6743\uff0c\u800c\u8fd9\u4e2a\u7528\u6237\u7528\u4e8eMySQL\u76d1\u63a7\u3001\u8def\u7531\u529f\u80fd<\/p>\n
\r\n MariaDB [(none)]> create user 'jiankongdb'@'%' identified by 'jiankong123';\r\n MariaDB [(none)]> grant SELECT on mysql.user to 'jiankongdb'@'%';\r\n MariaDB [(none)]> GRANT SELECT ON mysql.db TO 'jiankongdb'@'%';\r\n MariaDB [(none)]> GRANT SELECT ON mysql.tables_priv TO 'jiankongdb'@'%';\r\n MariaDB [(none)]> GRANT SHOW DATABASES ON *.* TO 'jiankongdb'@'%';\r\n MariaDB [(none)]> grant REPLICATION CLIENT on *.* to 'jiankongdb'@'%';\r\n\r\n MariaDB [(none)]> GRANT replication slave, replication client,SELECT ON *.* TO jiankongdb@'%';\r\n<\/pre>\n6.\u67e5\u770b\u6388\u6743\u60c5\u51b5<\/p>\n
\r\n MariaDB [(none)]> SHOW GRANTS FOR'jiankong'@'%';\r\n<\/pre>\n7.\u63a5\u4e0b\u6765\u5c31\u5f00\u59cb\u4fee\u6539maxscale.cnf\u914d\u7f6e\u6587\u4ef6\uff0c\u5426\u5219\u65e0\u6cd5\u542f\u52a8\u3002<\/p>\n
\r\n [root@localhost ~]# vim \/etc\/maxscale.cnf\r\n\r\n # MaxScale documentation on GitHub:\r\n # https:\/\/github.com\/mariadb-corporation\/MaxScale\/blob\/2.1\/Documentation\/Documentation-Contents.md\r\n\r\n # Global parameters\r\n #\r\n # Complete list of configuration options:\r\n # https:\/\/github.com\/mariadb-corporation\/MaxScale\/blob\/2.1\/Documentation\/Getting-Started\/Configuration-Guide.md\r\n #\u5168\u5c40\u914d\u7f6e\r\n [maxscale]\r\n threads=1\r\n\r\n # Server definitions\r\n #\r\n # Set the address of the server to the network\r\n # address of a MySQL server.\r\n #\r\n\r\n [server1]\r\n type=server\r\n address=172.16.8.56\r\n port=3306\r\n protocol=MySQLBackend\r\n serv_weight=1\r\n\r\n [server2]\r\n type=server\r\n address=172.16.8.57\r\n port=3306\r\n protocol=MySQLBackend\r\n serv_weight=3\r\n\r\n [server3]\r\n type=server\r\n address=172.16.8.58\r\n port=3306\r\n protocol=MySQLBackend\r\n serv_weight=3\r\n\r\n\r\n # Monitor for the servers\r\n #\r\n # This will keep MaxScale aware of the state of the servers.\r\n # MySQL Monitor documentation:\r\n # https:\/\/github.com\/mariadb-corporation\/MaxScale\/blob\/2.1\/Documentation\/Monitors\/MySQL-Monitor.md\r\n #MariaDB\u72b6\u6001\u76d1\u63a7\r\n [MySQL Monitor]\r\n type=monitor\r\n module=mysqlmon\r\n servers=server1,server2,server3\r\n user=jiankong\r\n passwd=jiankong123\r\n monitor_interval=10000\r\n detect_stale_master=true #\u5373\u4f7f\u4ece\u5168\u6302\u6389,\u4fdd\u8bc1\u4e3b\u62c5\u4efb\u8bfb\u5199\r\n\r\n # Service definitions\r\n #\r\n # Service Definition for a read-only service and\r\n # a read\/write splitting service.\r\n #\r\n\r\n # ReadConnRoute documentation:\r\n # https:\/\/github.com\/mariadb-corporation\/MaxScale\/blob\/2.1\/Documentation\/Routers\/ReadConnRoute.md\r\n #\u8bfb\r\n [Read-Only Service]\r\n type=service\r\n router=readconnroute\r\n servers=server1,server2,server3\r\n user=jiankong\r\n passwd=jiankong123\r\n router_options=slave\r\n enable_root_user=1 #\u5141\u8bb8root\u7528\u6237\u767b\u5f55\u6267\u884c\r\n weightby=serv_weight #\u4e3b\u4ece\u6743\u91cd\r\n\r\n # ReadWriteSplit documentation:\r\n # https:\/\/github.com\/mariadb-corporation\/MaxScale\/blob\/2.1\/Documentation\/Routers\/ReadWriteSplit.md\r\n #\u5199\r\n [Read-Write Service]\r\n type=service\r\n router=readwritesplit\r\n servers=server1,server2,server3\r\n user=jiankong\r\n passwd=jiankong123\r\n max_slave_connections=100%\r\n use_sql_variables_in=master #\u4fdd\u8bc1\u4f1a\u8bdd\u7684\u4e00\u81f4\u6027\r\n enable_root_user=1 #\u5141\u8bb8root\u767b\u5f55\r\n max_slave_replication_lag=3600 #\u5141\u8bb8\u4ece\u8d85\u51fa\u4e3b\u7684\u540c\u6b65\u65f6\u95f4,\u8d85\u51fa\u5219\u4e0d\u8def\u7531\r\n\r\n # This service enables the use of the MaxAdmin interface\r\n # MaxScale administration guide:\r\n # https:\/\/github.com\/mariadb-corporation\/MaxScale\/blob\/2.1\/Documentation\/Reference\/MaxAdmin.md\r\n\r\n [MaxAdmin Service]\r\n type=service\r\n router=cli\r\n\r\n # Listener definitions for the services\r\n #\r\n # These listeners represent the ports the\r\n # services will listen on.\r\n #\r\n\r\n [Read-Only Listener]\r\n type=listener\r\n service=Read-Only Service\r\n protocol=MySQLClient\r\n port=4008\r\n\r\n [Read-Write Listener]\r\n type=listener\r\n service=Read-Write Service\r\n protocol=MySQLClient\r\n port=4006\r\n\r\n [MaxAdmin Listener]\r\n type=listener\r\n service=MaxAdmin Service\r\n protocol=maxscaled\r\n socket=default\r\n<\/pre>\n\u4fdd\u5b58\u5e76\u9000\u51fa\u3002
\n8.\u4e0b\u9762\u521b\u5efa\u542f\u52a8\u811a\u672c<\/p>\n\r\n [root@localhost ~]# cp \/usr\/local\/maxscale-2.1.3.centos.7\/share\/maxscale.service \/usr\/lib\/systemd\/system\/\r\n [root@localhost ~]# vim \/usr\/lib\/systemd\/system\/maxscale.service\r\n<\/pre>\n9.\u4fee\u6539maxscale.service\u4e2d\u7684ExecStart=\/\/\/bin\/maxscale\u4e3aExecStart=\/usr\/local\/maxscale\/bin\/maxscale<\/p>\n
\r\n [root@localhost ~]# chmod 755 \/usr\/lib\/systemd\/system\/maxscale.service\r\n [root@localhost ~]# systemctl enable maxscale\r\n [root@localhost ~]# systemctl daemon-reload\r\n [root@localhost ~]# systemctl start maxscale\r\n<\/pre>\n10.\u6dfb\u52a0\u53d8\u91cf\u503c<\/p>\n
\r\n [root@localhost ~]# vi \/etc\/profile \/\/\u6700\u540e\u4e00\u884c\u6dfb\u52a0\u4ee5\u4e0b\u5185\u5bb9\u4fdd\u5b58\u9000\u51fa\uff01\r\n\r\n PATH=$PATH:\/usr\/local\/maxscale\/bin\r\n export PATH\r\n\r\n [root@localhost ~]# source \/etc\/profile \/\/\u4f7f\u5176\u53d8\u91cf\u7acb\u5373\u751f\u6548\r\n<\/pre>\n11.\u63a5\u4e0b\u6765\u5c31\u53ef\u4ee5\u4f7f\u7528MaxAdmin\u8fdb\u884c\u7ba1\u7406\u3002MaxAdmin\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u5ba2\u6237\u7aef\u7ba1\u7406\u754c\u9762\uff0c\u53ef\u7528\u4e8e\u4e0eMariaDB MaxScale\u670d\u52a1\u5668\u8fdb\u884c\u4ea4\u4e92\uff0c\u53ef\u4ee5\u663e\u793aMariaDB MaxScale\u5185\u90e8\u7684\u7edf\u8ba1\u4fe1\u606f\u72b6\u6001\u4ee5\u53ca\u5bf9MariaDB MaxScale\u64cd\u4f5c\u7684\u63a7\u5236\u3002\u8be6\u60c5\uff1a
\nhttps:\/\/mariadb.com\/kb\/en\/mariadb-enterprise\/maxadmin-admin-interface\/<\/p>\n\r\n [root@localhost ~]# maxadmin \/\/\u56de\u8f66\r\n MaxScale> list servers\r\n Servers.\r\n ---------------+--------------+-------+-------------+-----------------\r\n Server | Address | Port | Connections | Status \r\n ---------------+--------------+-------+-------------+-----------------\r\n server1 | 172.16.8.56 | 3306 | 0 | Master, Running\r\n server2 | 172.16.8.57 | 3306 | 0 | Slave, Running\r\n server2 | 172.16.8.58 | 3306 | 0 | Slave, Running\r\n ---------------+--------------+-------+-------------+-----------------\r\n<\/pre>\n12.\u81f3\u6b64MaxScale\u5df2\u7ecf\u914d\u7f6e\u5b8c\u6210\u3002\u73b0\u5728\u5c31\u53ef\u4ee5\u4f7f\u7528\u5ba2\u6237\u7aef\u8fde\u63a5Maxscale\u670d\u52a1\u5668\u7aef \u7aef\u53e3\u4e3a4006\u3002<\/p>\n
\n\u539f\u6587\u6765\u81ea\uff1ahttps:\/\/renwole.com\/archives\/253<\/a><\/p>\n