mycat一 (安裝與環境變量配置)

1、下載JDK,下載Java SE 8u231

https://www.oracle.com/technetwork/java/javase/downloads/index.html 

2、解壓到指定目錄

tar zxvf xxx.tar.gz  -C /usr/local/ 

3、配置環境變量

vi /etc/profile 

export JAVA_HOME=/usr/java/jdkxxxx

export PATH=$JAVA_HOME/bin:$PATH

export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

立即生效source /etc/profile 

4、下載mycat

https://github.com/MyCATApache/Mycat-download 

5、配置環境變量 

vi /etc/profile

export MYCAT_HOME=/usr/local/mycat

立即生效source /etc/profile 

6、修改mysql配置文件

[mysqld]

下面加入 lower_case_table_names = 1

#忽略大小寫

重啓MYSQL服務器

7、啓動mycat

./mycat start 

./mycat status

./mycat stop

./mycat restart

以控制檯方式啓動

./mycat console 

8、mycat配置文件

   1. Server.xml

           定義系統參數和授權 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mycat:server SYSTEM "server.dtd">
<mycat:server xmlns:mycat="http://io.mycat/">
	<system>
	<property name="defaultSqlParser">druidparser</property>	
	</system>
	<!-- name是用戶連接mycat的賬號 -->
	<user name="mycat_god">
		<property name="password">123</property>
		<!-- scheams 是對應schema.xml中對應的schemas標籤的名稱 -->
		<property name="schemas">shenyi</property>
	</user>

	<user name="mycat_dog">
		<property name="password">123</property>
		<property name="schemas">shenyi</property>
		<!-- 只讀 -->
		<property name="readOnly">true</property>
	</user>
	<!-- 
	<quarantine> 
	   <whitehost>
	      <host host="127.0.0.1" user="mycat"/>
	      <host host="127.0.0.2" user="mycat"/>
	   </whitehost>
       <blacklist check="false"></blacklist>
	</quarantine>
	-->

</mycat:server>

            

   2. schema.xml

          定義邏輯庫、表、分片節點

           Schema節點 :邏輯庫(好比數據庫),在裏面需要定義對各個表的“規則”

           dataNode節點:數據節點。上面的邏輯庫和這個dataNode要進行綁定

           dataHost:數據庫配置。dataNode節點和其進行綁定

           以上三者互綁

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

	<schema name="shenyi" checkSQLschema="false" sqlMaxLimit="100">
		<!-- auto sharding by id (long) -->
		<!--<table name="travelrecord" dataNode="dn1" rule="auto-sharding-long" />-->
	    <!-- name是實際數據庫表的表名  primaryKey是這個表的主鍵 type是全局表暫時忽略 dataNode表示從這些節點讀取 -->
		 <table name="news_main" primaryKey="news_id"  type="global" dataNode="dn1,dn2" />
		 
		 
	</schema> 
	<!-- name是node的名稱 dataHost對應dataHost標籤 database是實際的數據庫名稱 -->
	<dataNode name="dn1" dataHost="localhost1" database="jtthink" />
	<dataNode name="dn2" dataHost="localhost2" database="jtthink" />

	<!-- name是dataHost的名稱 maxCon最大連接數 balance負載均衡策略  -->
	<dataHost name="localhost1" maxCon="1000" minCon="10" balance="0"
		writeType="0" dbType="mysql" dbDriver="native" switchType="1"  slaveThreshold="100">
		<!-- 心跳 -->
		<heartbeat>select user()</heartbeat>
		<!-- can have multi write hosts -->
		<!-- host隨便起,url是實際數據庫地址 user是實際數據庫賬號 password是實際數據庫密碼 -->
		<writeHost host="hostM1" url="192.168.1.108:3306" user="root"
			password="123123">
		</writeHost>
 
	</dataHost>
	<dataHost name="localhost2" maxCon="1000" minCon="10" balance="0"
		writeType="0" dbType="mysql" dbDriver="native" switchType="1"  slaveThreshold="100">
		<heartbeat>select user()</heartbeat>
		<!-- can have multi write hosts -->
		<writeHost host="hostM1" url="192.168.1.101:3306" user="root"
			password="123">
		</writeHost>
		 
	</dataHost>
	 
</mycat:schema>

   3.rule.xml

         定義分片規則等

 

 

 

 

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章