• notice
  • Congratulations on the launch of the Sought Tech site

Centos8 install mycat and mysql8 to achieve read/write separation

Today, the company opened two new database servers, the environment is centos8+mysql8, and I need to deploy mycat. I did this job a long time ago, but now I don’t have any impression of it. See my previous blog page for mycat. Description, but that is all about the explanation of each configuration item. I don’t know why these configuration items were posted instead of the specific operation. I am also confused, so I searched online and summarized it. It will be used and provided to those in need in the future.

1607506863.jpg

Here I will roughly talk about the process, so that the subsequent operations will be clear.

First of all, after downloading mycat, it is a green software package that can be used directly, but it needs a java environment to run, if not, install it.

In addition, to make it run, you need to configure 2 files. In addition, the data synchronization of multiple databases needs to use the master-slave data synchronization function that comes with mysql.

The first one is the conf/server.xml file, which only needs to configure the account information to connect to mycat

The second is the conf/server.xml file, which needs to configure our cluster structure and master-slave relationship as well as the login information of each node of the actual database.

After the configuration is complete, it can be started and used normally. At the end of this article, we will talk about how to add services and enable startup.


Well, with the above foreshadowing, I believe it will be easy to operate later.

If my mycat is placed in the / directory

Edit to add login information

vim / mycat / conf / server.xml _ _

In server.xml, you need to comment out the original user configuration, and then add your own configuration information, of course, you can also modify it directly.

1. Search <property name="nonePasswordLogin">

Change the 0 inside to 1

2. Search <property name="fakeMySQLVersion">

Remove the comment and set your simulated mysql version number

3. Search <user name="root" defaultAccount="true">

Comment out a whole paragraph of it

4. Search <user name="user">

Also comment out the entire section

Then create your own user login configuration information under it

<user name="mycatuser" defaultAccount="true">
                 <property name="password">mycatuserpassword</property>
                 <property name="schemas">mycatdb</property>
</user>

Note: 1, replace mycatuser with your own mycat connection user name, mycatuserpassword is the connection password, and mycatdb is the connection database name.


Users can set more than one. For details, please refer to the detailed description on the configuration file.


Edit cluster configuration information


vim / mycat / conf / schema.xml _ _

Here I suggest to back up the scheam.xml file for later viewing, and then clear the configuration file and rewrite the configuration file, because the rewritten configuration file has a clear structure and no comments, which is harmonious and concise.


Write content:

<?xml version="1.0"?>
<!DOCTYPE mycat:schema SYSTEM "schema.dtd">
<mycat:schema xmlns:mycat="http://io.mycat/">
<!--Define a database mycatdn and specify the host as dn1-->
<schema name="mycatdb" checkSQLschema="false" sqlMaxLimit="100" dataNode="dn1"></schema>
<!--Define a dn1 host and specify a link to localhost1-->
<dataNode name="dn1" dataHost="localhost1" database="mycatdb" />

<!--Define localhost1 host -->
<dataHost name="localhost1" maxCon="65535" minCon="10" balance="1" writeType="0" dbType="mysql" dbDriver="native" switchType="-1" slaveThreshold="100">

      <heartbeat>select user()</heartbeat>
      <!--Definition write library-->
      <writeHost host="hostM1" url="main server IP: 3306" user="main server login username" password="main server login password">
      <!--Definition read library-->
      <readHost host="hostS1" url="From server IP: 3306" user="From server login user name" password="From server login password" />
      </writeHost>
</dataHost>
<!--End of defining localhost1 host -->
</mycat:schema>

Make sure your server configuration is correct, otherwise there will definitely be problems.

Then save and exit,

Then you can start the service and test it


cd /mycat/bin/
./mycat console _ _ _ _ _

If there is no problem in starting, it is OK, otherwise check whether java is installed.


install java


yum -y install java - 11 - openjdk *

After completion, try to run the service again


It is assumed here that you have already started normally,

Then we log in to test.


mysql -u mycatuser -p -h 127.0 . 0.1 -P 8066 _ _ _

Then enter the set password, and you can log in normally. After entering, the operation is the same as using mysql.


As for data synchronization, it mainly uses mysql's own master-slave synchronization function. For specific articles, please see my response blog post.



Tags

Technical otaku

Sought technology together

Related Topic

0 Comments

Leave a Reply

+