下载xshell与xftp
然后将下载好的jdk和mycat上传到linux的服务器上
解压文件
# tar -zxvf jdk-8u20-linux-x64.tar.gz -C /usr/local
# tar -zxvf Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz -C /usr/local
第三步:配置环境变量:
使用vim /etc/profile编辑profile文件,在/etc/profile底部加入如下内容:
[root@localhost ~]# vim /etc/profile
# /etc/profile
# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc
# It's NOT a good idea to change this file unless you know what you
# are doing. It's much better to create a custom.sh shell script in
# /etc/profile.d/ to make custom changes to your environment, as this
# will prevent the need for merging in future updates.
pathmunge () {
case ":${PATH}:" in
*:"$1":*)
;;
*)
if [ "$2" = "after" ] ; then
PATH=$PATH:$1
else
PATH=$1:$PATH
fi
esac
}
if [ -x /usr/bin/id ]; then
if [ -z "$EUID" ]; then
# ksh workaround
EUID=`/usr/bin/id -u`
UID=`/usr/bin/id -ru`
fi
USER="`/usr/bin/id -un`"
LOGNAME=$USER
MAIL="/var/spool/mail/$USER"
fi
# Path manipulation
if [ "$EUID" = "0" ]; then
pathmunge /usr/sbin
pathmunge /usr/local/sbin
else
pathmunge /usr/local/sbin after
pathmunge /usr/sbin after
fi
HOSTNAME=`/usr/bin/hostname 2>/dev/null`
HISTSIZE=1000
if [ "$HISTCONTROL" = "ignorespace" ] ; then
export HISTCONTROL=ignoreboth
else
export HISTCONTROL=ignoredups
fi
export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL
# By default, we want umask to get set. This sets it for login shell
# Current threshold for system reserved uid/gids is 200
# You could check uidgid reservation validity in
# /usr/share/doc/setup-*/uidgid file
if [ $UID -gt 199 ] && [ "`/usr/bin/id -gn`" = "`/usr/bin/id -un`" ]; then
umask 002
else
umask 022
fi
for i in /etc/profile.d/*.sh ; do
if [ -r "$i" ]; then
if [ "${-#*i}" != "$-" ]; then
. "$i"
else
. "$i" >/dev/null
fi
fi
done
unset i
unset -f pathmunge
export JAVA_HOME=/usr/local/jdk1.8.0_20
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
export MYCAT_HOME=/usr/local/mycat
export HADOOP_HOME=/usr/local/hadoop
export PATH=$PATH:$MYCAT_HOME/bin:$HADOOP_HOME/bin
第四步:使用source /etc/profile让profile文件立即生效
[root@localhost ~]# source /etc/profile
第五步:命令测试
java -version
出现以下成功
java version "1.8.0_20"
Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)
配置wrapper.conf
进入MyCat的配置文件目录:/usr/local/mycat/conf,找到wrapper.conf,然后修改。设 置wrapper.java.command的值为jdk的安装路径。这里为:wrapper.java.command=/usr/local/jdk1.8.0_20/bin/java
二.配置Mycat文件,实现简单的读写分离
1.修改mycat/conf/server.xml文件,具体修改如下
- <user name="root">
- <property name="password">root</property>
- <property name="schemas">TESTDB</property>
- </user>
- <user name="user">
- <property name="password">root</property>
- <property name="schemas">TESTDB</property>
- <property name="readOnly">true</property>
- </user>
- <!--以上配置的是连接mycat的用户名和密码-->
- <?xml version="1.0"?>
<!DOCTYPE mycat:schema SYSTEM "schema.dtd">
<mycat:schema xmlns:mycat="http://io.mycat/">
<schema name="TESTDB" checkSQLschema="false" sqlMaxLimit="100">
<table name="travelrecord" dataNode="dn1,dn2,dn3" rule="auto-sharding-long" />
</schema>
<!-- <dataNode name="dn1$0-743" dataHost="master" database="db$0-743"
/> -->
<dataNode name="dn1" dataHost="master" database="db1" />
<dataNode name="dn2" dataHost="master" database="db2" />
<dataNode name="dn3" dataHost="master" database="db3" />
<dataHost name="master" maxCon="1000" minCon="10" balance="2"
writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">
<heartbeat>select user()</heartbeat>
<!-- can have multi write hosts -->
<writeHost host="hostM1" url="173.16.80.70:3307" user="root"
password="root">
</writeHost>
<writeHost host="host2M1" url="173.16.80.107:3304" user="root"
password="root">
</writeHost>
</dataHost>
</mycat:schema>
4.启动mycat服务
./mycat console
./mycat start
./mycat status
打开navicat 连接ip+8066端口 打开mycat
如果连接了navicat打不开mycat 请关闭防火墙
ystemctl stop firewalld.service
systemctl disable firewalld.service