In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to use MaxScale to achieve database read-write separation under Linux. It is very detailed and has a certain reference value. Interested friends must read it!
MaxScale is a mysql data middleware developed by maridb. It is easy to configure, can realize the separation of read and write, and can automatically switch the write library according to the master-slave state.
Operating system: CentOS Linux release 7.3.1611 (Core)
Database: MariaDB-10.2.6-linux-glibc_214-x86_64
MaxScale server: 10.200.10.55
Master server: 172.16.8.56
Slave server: 172.16.8.57
Slave server: 172.16.8.58
There are many ways to install 1.maxscale, such as source installation, rpm, binary construction, etc. I choose binary to install.
Download the corresponding version and download address according to the needs of the scene; https://mariadb.com/downloads/maxscale
[root@localhost ~] # groupadd maxscale [root@localhost ~] # useradd-g maxscale maxscale [root@localhost ~] # cd / usr/local [root@localhost local] # wget https://downloads.mariadb.com/MaxScale/2.1.3/centos/7server/x86_64/maxscale-2.1.3.centos.7.tar.gz [root@localhost local] # tar zxvf maxscale-2.1.3.centos.7.tar.gz [root@localhost local] # ln- S maxscale-2.1.3.centos.7 maxscale [root@localhost local] # cd maxscale [root@zhu56 maxscale] # chown-R maxscale var
It is recommended to create a soft connection, which is helpful for future version upgrades and post-maintenance.
two。 To install maxscale for the first time, you need to create log-related directories
[root@localhost ~] # mkdir / var/log/maxscale [root@localhost ~] # mkdir / var/lib/maxscale [root@localhost ~] # mkdir / var/run/maxscale [root@localhost ~] # mkdir / var/cache/maxscale
3. The following directories must have maxscala privileges
[root@localhost ~] # chown maxscale / var/log/maxscale [root@localhost ~] # chown maxscale / var/lib/maxscale [root@localhost ~] # chown maxscale / var/run/maxscale [root@localhost ~] # chown maxscale / var/cache/maxscale
4. In order to enable Maxscale to start smoothly, you also need to create a configuration file, which can be copied to etc with a configuration file template in the Maxscale directory.
[root@localhost ~] # cp / usr/local/maxscale/etc/maxscale.cnf.template / etc/maxscale.cnf
5. Before modifying the configuration file, you need to create and authorize a user on the primary server for MySQL monitoring and routing functions
MariaDB [(none)] > create user 'jiankongdb'@'%' identified by' jiankong123'; MariaDB [(none)] > grant SELECT on mysql.user to 'jiankongdb'@'%'; MariaDB [(none)] > GRANT SELECT ON mysql.db TO' jiankongdb'@'%'; MariaDB [(none)] > GRANT SELECT ON mysql.tables_priv TO 'jiankongdb'@'%'; MariaDB [(none)] > GRANT SHOW DATABASES ON *. * TO' jiankongdb'@'%' MariaDB [(none)] > grant REPLICATION CLIENT on *. * to 'jiankongdb'@'%'; MariaDB [(none)] > GRANT replication slave, replication client,SELECT ON *. * TO jiankongdb@'%'
6. Check the authorization status
MariaDB [(none)] > SHOW GRANTS FOR'jiankong'@'%'
7. Next, start modifying the maxscale.cnf configuration file, otherwise you can't start it.
[root@localhost ~] # vim / etc/maxscale.cnf # MaxScale documentation on GitHub: # https://github.com/mariadb-corporation/MaxScale/blob/2.1/Documentation/Documentation-Contents.md # Global parameters # # Complete list of configuration options: # https://github.com/mariadb-corporation/MaxScale/blob/2.1/Documentation/Getting-Started/Configuration-Guide.md # Global configuration [maxscale] threads=1 # Server definitions # # Set the address of the server to the network # address of a MySQL server. # [server1] type=server address=172.16.8.56 port=3306 protocol=MySQLBackend serv_weight=1 [server2] type=server address=172.16.8.57 port=3306 protocol=MySQLBackend serv_weight=3 [server3] type=server address=172.16.8.58 port=3306 protocol=MySQLBackend serv_weight=3 # Monitor for the servers # # This will keep MaxScale aware of the state of the servers. # MySQL Monitor documentation: # https://github.com/mariadb-corporation/MaxScale/blob/2.1/Documentation/Monitors/MySQL-Monitor.md # MariaDB status Monitoring [MySQL Monitor] type=monitor module=mysqlmon servers=server1,server2,server3 user=jiankong passwd=jiankong123 monitor_interval=10000 detect_stale_master=true # ensure that the master is responsible for reading and writing # Service definitions # # Service Definition for a read-only service and # a read/write splitting service. # # ReadConnRoute documentation: # https://github.com/mariadb-corporation/MaxScale/blob/2.1/Documentation/Routers/ReadConnRoute.md # read [Read-Only Service] type=service router=readconnroute servers=server1,server2 Server3 user=jiankong passwd=jiankong123 router_options=slave enable_root_user=1 # allows root users to log in to execute weightby=serv_weight # Master / Slave weights # ReadWriteSplit documentation: # https://github.com/mariadb-corporation/MaxScale/blob/2.1/Documentation/Routers/ReadWriteSplit.md # write [Read-Write Service] type=service router=readwritesplit servers=server1,server2 Server3 user=jiankong passwd=jiankong123 max_slave_connections=100% use_sql_variables_in=master # ensures session consistency enable_root_user=1 # allows root to log in to max_slave_replication_lag=3600 # allows slaves to exceed master synchronization time Do not route # This service enables the use of the MaxAdmin interface # MaxScale administration guide: # https://github.com/mariadb-corporation/MaxScale/blob/2.1/Documentation/Reference/MaxAdmin.md [MaxAdmin Service] type=service router=cli # Listener definitions for the services # # These listeners represent the ports the # services will listen on. # [Read-Only Listener] type=listener service=Read-Only Service protocol=MySQLClient port=4008 [Read-Write Listener] type=listener service=Read-Write Service protocol=MySQLClient port=4006 [MaxAdmin Listener] type=listener service=MaxAdmin Service protocol=maxscaled socket=default
Save and exit. 8. Let's create a startup script
[root@localhost ~] # cp / usr/local/maxscale-2.1.3.centos.7/share/maxscale.service / usr/lib/systemd/system/ [root@localhost ~] # vim / usr/lib/systemd/system/maxscale.service
9. Change ExecStart=///bin/maxscale in maxscale.service to ExecStart=/usr/local/maxscale/bin/maxscale
[root@localhost] # chmod 755 / usr/lib/systemd/system/maxscale.service [root@localhost ~] # systemctl enable maxscale [root@localhost ~] # systemctl daemon-reload [root@localhost ~] # systemctl start maxscale
10. Add variable value
[root@localhost ~] # vi / etc/profile / / add the following to the last line to save and exit! PATH=$PATH:/usr/local/maxscale/bin export PATH [root@localhost ~] # source / etc/profile / / make its variable effective immediately
11. You can then manage it using MaxAdmin. MaxAdmin is a simple client management interface that can be used to interact with the MariaDB MaxScale server and display the status of statistics within MariaDB MaxScale and the control of MariaDB MaxScale operations. Details: https://mariadb.com/kb/en/mariadb-enterprise/maxadmin-admin-interface/
[root@localhost ~] # maxadmin / / enter MaxScale > list servers Servers. -+-Server | Address | Port | Connections | Status-+ -+-server1 | 172.16.8.56 | 3306 | 0 | Master Running server2 | 172.16.8.57 | 3306 | 0 | Slave, Running server2 | 172.16.8.58 | 3306 | 0 | Slave, Running-+-
twelve。 At this point, MaxScale has been configured. You can now use the client to connect to the Maxscale server port of 4006.
The above is all the contents of the article "how to use MaxScale to achieve database read-write separation under Linux". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.