安装MYCAT环境,配置主从复制
主服务器
yum install -y vim lrzsz mariadb mariadb-server
[root@localhost ~]# systemctl restart mariadb
[root@localhost ~]# mysql -uroot
MariaDB [(none)]>MariaDB [(none)]> GRANT REPLICATION SLAVE ON *.* TO 'repluser'@'172.16.66.%' IDENTIFIED BY 'replpass';
Query OK, 0 rows affected (0.000 sec)
MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.001 sec)
[root@localhost ~]# vim /etc/my.cnf.d/mariadb-server.cnf
[mysqld]
server-id=1
log-bin
[root@localhost ~]# systemctl restart mariadb
MariaDB [(none)]> show master status;
+--------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+--------------------+----------+--------------+------------------+
| mariadb-bin.000002 | 330 | | |
+--------------------+----------+--------------+------------------+
1 row in set (0.000 sec)
从服务器
[root@localhost ~]# vim /etc/my.cnf.d/mariadb-server.cnf
[mysqld]
server-id=2
MariaDB [(none)]> CHANGE MASTER TO MASTER_HOST='172.16.66.81', MASTER_USER='repluser', MASTER_PASSWORD='replpass', MASTER_LOG_FILE='mariadb-bin.000002', MASTER_LOG_POS=330;
Query OK, 0 rows affected (0.005 sec)
MariaDB [(none)]> start slave;
Query OK, 0 rows affected (0.003 sec)
MariaDB [(none)]> show slave status \G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 172.16.66.81
Master_User: repluser
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mariadb-bin.000002
Read_Master_Log_Pos: 330
Relay_Log_File: mariadb-relay-bin.000002
Relay_Log_Pos: 557
Relay_Master_Log_File: mariadb-bin.000002
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
安装mycat服务器
[root@localhost ~]# yum -y install java mariadb
[root@localhost ~]# wget http://dl.mycat.org.cn/1.6.7.4/Mycat-server-1.6.7.4-release/Mycat-server-1.6.7.4-release-20200105164103-linux.tar.gz
[root@localhost ~]# mkdir /app
[root@localhost ~]# tar xvf Mycat-server-1.6.7.4-release-20200105164103-linux.tar.gz -C /app
[root@localhost ~]# echo 'PATH=/app/mycat/bin:$PATH' > /etc/profile.d/mycat.sh
[root@localhost ~]# source /etc/profile.d/mycat.sh
[root@localhost ~]# mycat start
Starting Mycat-server...
[root@localhost ~]# ss -tlnp
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 0.0.0.0:22 0.0.0.0:* users:(("sshd",pid=911,fd=4))
LISTEN 0 1 127.0.0.1:32000 0.0.0.0:* users:(("java",pid=11815,fd=4))
LISTEN 0 100 *:8066 *:* users:(("java",pid=11815,fd=91))
LISTEN 0 50 *:44041 *:* users:(("java",pid=11815,fd=66))
LISTEN 0 100 *:9066 *:* users:(("java",pid=11815,fd=87))
LISTEN 0 50 *:45553 *:* users:(("java",pid=11815,fd=68))
LISTEN 0 128 [::]:22 [::]:* users:(("sshd",pid=911,fd=6))
LISTEN 0 50 *:1984 *:* users:(("java",pid=11815,fd=67))
修改mycat账号
[root@localhost ~]# vi /app/mycat/conf/server.xml
修改mycat代理的mariadb
[root@localhost ~]# vi /app/mycat/conf/schema.xml
<?xml version="1.0"?>
<!DOCTYPE mycat:schema SYSTEM "schema.dtd">
<mycat:schema xmlns:mycat="http://io.mycat/">
<schema name="TESTDB" checkSQLschema="***false***" sqlMaxLimit="100" dataNode="***dn1***"></schema>
<dataNode name="dn1" dataHost="localhost1" database="***mycat***" />
<dataHost name="localhost1" maxCon="1000" minCon="10" balance="***1***" writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">
<heartbeat>select user()</heartbeat>
***<writeHost host="host1" url="172.16.66.81:3306" user="root"password="ptg123">***
***<readHost host="host2" url="172.16.66.82:3306" user="root"password="ptg123" />***
</writeHost>
</dataHost>
</mycat:schema>
~