实验架构: master 192.168.0.92 mysql slave 192.168.0.93 mysql mycat 192.168.0.94 mycat jdk client 192.168.0.95 mysql 1、环境配置 参照:https://www.cnblogs.com/effortsing/p/10367025.html 2、配置mysql实现主从复制 参照: https://www.cnblogs.com/effortsing/p/10367257.html 3、安装jdk 参照:https://www.cnblogs.com/effortsing/p/10012211.html 4、安装mycat实现读写分离 tar zxf Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz -C /usr/local cat>>/etc/profile<<EOF export MYCAT_HOME=/usr/local/mycat export PATH=$PATH:/usr/local/mycat/bin EOF source /etc/profile 配置server.xml 打开文件,搜索password定位修改 vi /usr/local/mycat/conf/server.xml <user name="root"> <property name="password">jenkins@123</property> # 这里的用户名密码是要访问的mysql的用户名密码 <property name="schemas">TESTDB</property> # 这是原先自带的全局表数据库名,不要动,否则mycat无法启动 配置schema.xml 搜索 writeType 进行定位修改 vi /usr/local/mycat/conf/schema.xml <dataHost name="localhost1" maxCon="1000" minCon="10" balance="1" #这里改成1,表示开启读写分离模式 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.0.92:3306" user="jenkins@123" #这里填写主库的地址和mysql的登录密码 password="123456"> <!-- can have multi read hosts --> <readHost host="hostS2" url="192.168.0.93:3306" user="root" password="jenkins@123" /> #这里填写主库的地址和mysql的登录密码 </writeHost> 说明:schema.xml里面其他的内容不要乱动 启动mycat mycat start [root@test4 ~]# mycat start Starting Mycat-server... 查看mycat状态 mycat status [root@test4 ~]# mycat status Mycat-server is running (3646). 停止mycat mycat stop [root@test4 ~]# mycat stop Stopping Mycat-server... Stopped Mycat-server. 查看报错日志: cat /usr/local/mycat/logs/wrapper.log 查看端口 [root@test4 ~]# netstat -tnlp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 127.0.0.1:32000 0.0.0.0:* LISTEN 3648/java tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 938/sshd tcp6 0 0 :::1984 :::* LISTEN 3648/java tcp6 0 0 :::8066 :::* LISTEN 3648/java # mycat登录端口 tcp6 0 0 :::34727 :::* LISTEN 3648/java tcp6 0 0 :::9066 :::* LISTEN 3648/java tcp6 0 0 :::44438 :::* LISTEN 3648/java tcp6 0 0 :::22 :::* LISTEN 938/sshd 客户端192.168.0.95 验证读写分离 说明:登录到mycat无法同步过来主库里面的数据库test,怎么改也不行,暂时先不解决了 登录到连接端口 其中8066是mycat的监听端口,类似于mysql的3306端口,其中-u,-p,-h分别是用户名,密码和主机,-D是连接的逻辑库 [root@test5 script]# mysql -h 192.168.0.94 -P 8066 -uroot -pjenkins@123 -DTEST mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.6.29-mycat-1.6-RELEASE-20161028204710 MyCat Server (OpenCloundDB) Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show databases; +----------+ | DATABASE | +----------+ | TESTDB | +----------+ 1 row in set (0.02 sec) 登录管理端口 [root@test5 script]# mysql -h 192.168.0.94 -P 9066 -uroot -pjenkins@123 mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.6.29-mycat-1.6-RELEASE-20161028204710 MyCat Server (monitor) Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> exit 报错解决:Caused by: io.mycat.config.util.ConfigException: SelfCheck### schema test refered by user root is not exist! 原因是server.xml里面的数据库写成了小写,必须改成大写 vi /usr/local/mycat/conf/server.xml <user name="root"> <property name="password">jenkins@123</property> # 这里的用户名密码是要访问的mysql的用户名密码 <property name="schemas">TEST</property> # 要测试的数据库,不要用小写,必须大写,否则mycat启动失败,其他的不要动 参照文档: http://blog.51cto.com/13598811/2087379 http://blog.51cto.com/12323501/2151261 https://www.jianshu.com/p/26513f428ecf https://www.cnblogs.com/lyming/p/8573869.html
mycat实现读写分离---未完成
猜你喜欢
转载自www.cnblogs.com/effortsing/p/10369287.html
今日推荐
周排行