La realización de linux basada en la separación de lectura y escritura de mycat

Escrito desde el principio: el experimento requiere un servidor mycat, un servidor maestro y un servidor esclavo, y se debe realizar la separación maestro-esclavo. (Si no utiliza la replicación maestro-esclavo, puede consultar el blog previamente publicado)
1. La separación de lectura y escritura se basa en la replicación maestro-esclavo, por lo que debe realizar la separación de lectura y escritura después de la replicación maestro-esclavo .
2. Instale el entorno java:

[root@mycat tools]# ls
jdk-8u60-linux-x64.tar.gz
mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
[root@mycat tools]# tar xf jdk-8u60-linux-x64.tar.gz 
[root@mycat tools]# ls
jdk1.8.0_60
jdk-8u60-linux-x64.tar.gz
mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
[root@mycat tools]# mv jdk1.8.0_60/ /usr/local/java8
[root@mycat tools]# cd /usr/local/java8/
[root@mycat ~]# vim /etc/profile.d/java.sh

Inserte la descripción de la imagen aquí

export JAVA_HOME=/usr/local/java8
export CLASSPATH=$JAVA_HOME/lib/
export PATH=$PATH:$JAVA_HOME/bin
[root@mycat ~]# source /etc/profile
##[root@mycat ~]# source /etc/profile.d/java.sh 
[root@mycat ~]# java -version
java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)

3. Instala mycat

[root@mycat tools]# ls
jdk-8u60-linux-x64.tar.gz
Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz
mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
[root@mycat tools]# ls
jdk-8u60-linux-x64.tar.gz
mycat
Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz
mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
[root@mycat tools]# mv mycat/ /usr/local/
[root@mycat tools]# useradd -M -s /sbin/nologin  mycat
[root@mycat tools]# chown -R mycat:mycat /usr/local/mycat/
[root@mycat tools]# vim /etc/profile.d/mycat.sh
export MYCAT_HOME=/usr/local/mycat
export PATH=$PATH:$MYCAT_HOME/bin

Inserte la descripción de la imagen aquí

[root@mycat tools]# source /etc/profile.d/mycat.sh 
[root@mycat ~]# cd /usr/local/mycat/
[root@mycat mycat]# ls
bin  catlet  conf  lib  logs  version.txt
[root@mycat mycat]# cd conf/
[root@mycat conf]# ls

Inserte la descripción de la imagen aquí

[root@mycat conf]# vim ./schema.xml

Inserte la descripción de la imagen aquí

[root@mycat conf]# vim server.xml
<property name="useSqlStat">0</property>
<property name="useGlobleTableCheck">0</property>                                            
<property name="useHandshakeV10">1</property>
<property name="processorBufferPoolType">0</property>
<property name="serverPort">3310</property>
<property name="managerPort">9066</property>
<property name="maxStringLiteralLength">65535</property>
<property name="sequnceHandlerType">0</property>
<property name="backSocketNoDelay">1</property>
<property name="frontSocketNoDelay">1</property>
<property name="processorExecutor">16</property>
<property name="sequnceHandlerType">2</property>

Inserte la descripción de la imagen aquí
Inserte la descripción de la imagen aquí
El segundo nombre de usuario se cambia a "mycat".

4.autorización de la biblioteca maestra maestra

mysql> grant all on *.* to [email protected] identified by '123123';
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

5. Mycat View
Netstat View puerto
Inserte la descripción de la imagen aquí
3310 9066 El puerto está abierto La
Inserte la descripción de la imagen aquí
disposición de separación de lectura y escritura se ha realizado correctamente.

6. Instale la prueba de la base de datos ( yum -y install mariadb mariadb-server)

Servidor Mycat:

[root@mycat ~]# mysql -uroot -p123123 -h 127.0.0.1 -P9066

Inserte la descripción de la imagen aquí

MySQL [(none)]> use HEADSHOW;
Database changed
MySQL [HEADSHOW]>

Luego ingrese la operación 3310 (base de datos lógica)

[root@mycat ~]# mysql -uroot -p123123 -h 127.0.0.1 -P3310
MySQL [(none)]> show databases;

Inserte la descripción de la imagen aquí

MySQL [(none)]> use HEADSHOW;
MySQL [HEADSHOW]> show tables;
MySQL [HEADSHOW]> create table abc(id int(2));
MySQL [HEADSHOW]> show tables;

Inserte la descripción de la imagen aquí

Ingrese a la biblioteca principal maestra y la biblioteca esclava esclava para verificar si mycat puede conectarse a la biblioteca principal y la biblioteca esclava.

mysql> use test;
mysql> show tables;

7. Deshabilite la separación de prueba de lectura y escritura de la biblioteca
1) Ingrese a la biblioteca esclava

mysql> stop slave io_thread;
mysql> use test;
mysql> show tables;
mysql> select * from abc;

Inserte la descripción de la imagen aquí
2) Ingrese a la biblioteca principal maestra

mysql> stop slave io_thread;
mysql> use test;
mysql> show tables;
mysql> select * from abc;

Inserte la descripción de la imagen aquí
3) Entra mycat

 MySQL [HEADSHOW]> insert into abc values(2);

Inserte la descripción de la imagen aquí

MySQL [HEADSHOW]> select * from abc

Inserte la descripción de la imagen aquí
4) Ingrese a la biblioteca principal principal para ver si hay datos

mysql> select * from abc;

Inserte la descripción de la imagen aquí
¡La operación de separación de lectura y escritura de prueba se realizó con éxito! ! !

El contenido del archivo de configuración es el siguiente:
schema.xml

<?xml version="1.0"?>
<!DOCTYPE mycat:schema SYSTEM "schema.dtd">
<mycat:schema xmlns:mycat="http://io.mycat/">

	<schema name="HEADSHOW" checkSQLschema="false" sqlMaxLimit="100" dataNode='dn1'></schema>
	<dataNode name="dn1" dataHost="localhost1" database="test" />
	<dataHost name="localhost1" maxCon="1000" minCon="10" balance="1"
	 writeType="0" dbType="mysql" dbDriver="native" switchType="1"  slaveThreshold="100">
		<heartbeat>select user()</heartbeat>
		<!-- can have multi write hosts -->
		<writeHost host="192.168.9.9" url="192.168.9.9:3306" user="root"
				   password="123123">
			<!-- can have multi read hosts -->
			<readHost host="192.168.9.10" url="192.168.9.10:3306" user="root" password="123123" />
		</writeHost>
		<writeHost host="hostS1" url="localhost:3316" user="root"
				   password="123456" />
		<!-- <writeHost host="hostM2" url="localhost:3316" user="root" password="123456"/> -->
	</dataHost>
	<!--
		<dataHost name="sequoiadb1" maxCon="1000" minCon="1" balance="0" dbType="sequoiadb" dbDriver="jdbc">
		<heartbeat> 		</heartbeat>
		 <writeHost host="hostM1" url="sequoiadb://1426587161.dbaas.sequoialab.net:11920/SAMPLE" user="jifeng" 	password="jifeng"></writeHost>
		 </dataHost>

	  <dataHost name="oracle1" maxCon="1000" minCon="1" balance="0" writeType="0" 	dbType="oracle" dbDriver="jdbc"> <heartbeat>select 1 from dual</heartbeat>
		<connectionInitSql>alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss'</connectionInitSql>
		<writeHost host="hostM1" url="jdbc:oracle:thin:@127.0.0.1:1521:nange" user="base" 	password="123456" > </writeHost> </dataHost>

		<dataHost name="jdbchost" maxCon="1000" 	minCon="1" balance="0" writeType="0" dbType="mongodb" dbDriver="jdbc">
		<heartbeat>select 	user()</heartbeat>
		<writeHost host="hostM" url="mongodb://192.168.0.99/test" user="admin" password="123456" ></writeHost> </dataHost>

		<dataHost name="sparksql" maxCon="1000" minCon="1" balance="0" dbType="spark" dbDriver="jdbc">
		<heartbeat> </heartbeat>
		 <writeHost host="hostM1" url="jdbc:hive2://feng01:10000" user="jifeng" 	password="jifeng"></writeHost> </dataHost> -->

	<!-- <dataHost name="jdbchost" maxCon="1000" minCon="10" balance="0" dbType="mysql"
		dbDriver="jdbc"> <heartbeat>select user()</heartbeat> <writeHost host="hostM1"
		url="jdbc:mysql://localhost:3306" user="root" password="123456"> </writeHost>
		</dataHost> -->
</mycat:schema>

server.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- - - Licensed under the Apache License, Version 2.0 (the "License"); 
	- you may not use this file except in compliance with the License. - You 
	may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 
	- - Unless required by applicable law or agreed to in writing, software - 
	distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT 
	WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the 
	License for the specific language governing permissions and - limitations 
	under the License. -->
<!DOCTYPE mycat:server SYSTEM "server.dtd">
<mycat:server xmlns:mycat="http://io.mycat/">
	<system>
<property name="useSqlStat">0</property>
<property name="useGlobleTableCheck">0</property>                                            
<property name="useHandshakeV10">1</property>
<property name="processorBufferPoolType">0</property>
<property name="serverPort">3310</property>
<property name="managerPort">9066</property>
<property name="maxStringLiteralLength">65535</property>
<property name="sequnceHandlerType">0</property>
<property name="backSocketNoDelay">1</property>
<property name="frontSocketNoDelay">1</property>
<property name="processorExecutor">16</property>
<property name="sequnceHandlerType">2</property>
			<!--
			off heap for merge/order/group/limit      1开启   0关闭
		-->
		<property name="useOffHeapForMerge">1</property>

		<!--
			单位为m
		-->
		<property name="memoryPageSize">1m</property>

		<!--
			单位为k
		-->
		<property name="spillsFileBufferSize">1k</property>

		<property name="useStreamOutput">0</property>

		<!--
			单位为m
		-->
		<property name="systemReserveMemorySize">384m</property>


		<!--是否采用zookeeper协调切换  -->
		<property name="useZKSwitch">true</property>


	</system>
	
	<!-- 全局SQL防火墙设置 -->
	<!-- 
	<firewall> 
	   <whitehost>
	      <host host="127.0.0.1" user="mycat"/>
	      <host host="127.0.0.2" user="mycat"/>
	   </whitehost>
       <blacklist check="false">
       </blacklist>
	</firewall>
	-->
	
	<user name="root">
		<property name="password">123123</property>
		<property name="schemas">HEADSHOW</property>
		
		<!-- 表级 DML 权限设置 -->
		<!-- 		
		<privileges check="false">
			<schema name="TESTDB" dml="0110" >
				<table name="tb01" dml="0000"></table>
				<table name="tb02" dml="1111"></table>
			</schema>
		</privileges>		
		 -->
	</user>

	<user name="mycat">
		<property name="password">123123</property>
		<property name="schemas">HEADSHOW</property>
		<property name="readOnly">true</property>
	</user>

</mycat:server>

Supongo que te gusta

Origin blog.csdn.net/qq_39109226/article/details/111478339
Recomendado
Clasificación