Mycat安装
1.环境准备
基于centos7操作系统
1.jdk安装包(jdk1.7+): jdk-8u131-linux-x64.tar.gz
下载地址: https://www. oracle.com/java/technol ogies/javase-jdk8-downloads.html
2.MySQL安装包:mysql-5.7.29-1.el7.x86_64.rpm-bundle.tar
下载地址: http:// mirrors.163.com/mysql/D ownloads/MySQL-5.7/mysql-5.7.29-1.el7.x86_64.rpm-bundle.tar
3.Mycat安装包:Mycat-server-1.6.6.1-release-20181031195535-linux.tar.gz
下载地址: http:// dl.mycat.io/1.6.6.1/Myc at-server-1.6.6.1-release-20181031195535-linux.tar.gz
2.jdk安装
1.解压
tar -xzvf jdk-8u131-linux-x64.tar.gz -C /usr/local/
2.配置java环境变量
vi /etc/profile
在文件末尾追加:
export JAVA_HOME=/usr/local/java/jdk1.8.0_131
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
3.执行配置生效命令:
source /etc/profile
4.验证:
java -version
3.安装MySQL安装
1.在mysql安装包同目录下创建mysql目录
mkdir mysql
2.解压
tar -xvf mysql-5.7.29-1.el7.x86_64.rpm-bundle.tar -C mysql
4.安装
cd mysql
yum install mysql-community-{server,client,common,libs}-*
5.mysql默认文件和目录
/usr/bin 客户端程序脚本
/usr/sbin mysqld server
/etc/my.cnf 配置文件
/var/lib/mysql 数据目录
/var/log/mysqld.log 日志文件
/var/run/mysqld/mysqld.pid Pid 文件
/var/lib/mysql/mysql.sock Socket
6.Linux 环境下MySQL 要配置好忽略表名大小写,否则使用Mycat 的时候会提示找不到 表的错误
vim /etc/my.cnf
lower_case_table_names=1
7.启动MySQL
systemctl start mysqld
8.修改root用户密码
grep 'temporary password' /var/log/mysqld.log
mysql -uroot -p FE*?yowA;2oR
alter user 'root'@localhost identified by 'root!@#8567';
此处,如果root用户的密码要设置成简单的可以按下面步骤设置:
mysql> set global validate_password_length=6;
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password_policy=LOW;
Query OK, 0 rows affected (0.00 sec)
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.01 sec)
mysql> grant all privileges on *.* to 'root'@'%' identified by '123456';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
4.Mycat安装
1.安装包到目标安装目录:
tar -xzvf Mycat-server-1.6.6.1-release-20181031195535-linux.tar.gz -C /usr/local/
2.环境变量配置
vi /etc/profile
source /etc/profile
3.新增用户mycat(建议不要用root用户来运行mycat):
useradd mycat
passwd mycat
4.修改mycat安装目录权限
chown -R mycat:mycat /usr/local/mycat
5.启动mycat
su mycat
bin/mycat start
查看mycat进程
至此mycat安装完成!那么,如何连接mycat测试一下呢?
在mycat安装目录下有3个重要配置文件:
server.xml 是Mycat 服务器参数调整和用户授权的配置文件,
schema.xml 是逻辑库定义和表以及分片定义的配置文件,
rule.xml 是分片规则的配置文件,分片规则的具体一些参数信息单独存放为文件
6.配置mycat
在server.xml中有
连接mycat端口 serverPort 默认为:8066
管理mycat端口managerPort 默认为:9066
那么,连接mycat端口就填写:8066
修改conf/server.xml配置文件,设置root用户,密码:123456 ,数据库:mydb1
...
<user name="root" defaultAccount="true">
<property name="password">123456</property>
<property name="schemas">mydb1</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="user">
<property name="password">user</property>
<property name="schemas">TESTDB</property>
<property name="readOnly">true</property>
</user>
</mycat:server>
修改conf/schema.xml配置文件,增加数据库配置:
<schema name="mydb1" checkSQLschema="false" sqlMaxLimit="100" dataNode="mydn2">
</schema>
整体配置如下:
<?xml version="1.0"?>
<!DOCTYPE mycat:schema SYSTEM "schema.dtd">
<mycat:schema xmlns:mycat="http://io.mycat/">
<schema name="mydb1" checkSQLschema="false" sqlMaxLimit="100" dataNode="mydn2">
</schema>
<dataNode name="mydn1" dataHost="dbhost1" database="orders" />
<dataNode name="mydn2" dataHost="dbhost2" database="orders" />
<dataHost name="dbhost1" maxCon="1000" minCon="10" balance="1"
writeType="0" dbType="mysql" dbDriver="native">
<heartbeat>select user()</heartbeat>
<writeHost host="myhostM1" url="192.168.1.201:3306" user="root"
password="123456">
<readHost host="myhostS1" url="192.168.1.202:3306" user="repl1" password="123456" weight="1"/>
</writeHost>
</dataHost>
<dataHost name="dbhost2" maxCon="1000" minCon="10" balance="1"
writeType="0" dbType="mysql" dbDriver="native">
<heartbeat>select user()</heartbeat>
<writeHost host="myhostSM2" url="192.168.1.201:3306" user="root" password="123456">
</writeHost>
<writeHost host="myhostS2" url="192.168.1.202:3306" user="repl1" password="123456">
</writeHost>
</dataHost>