準備工作
因為MyCAT 2基于JDK 1.8開發。也需要在虛擬機中安裝JDK(JDK官網就能下載,我這提供一個捷徑)
jdk-8u401-linux-x64.rpmhttps://pan.baidu.com/s/1ywcDsxYOmfZONpmH9oDjfw?pwd=rhel下載對應的tar安裝包,以及對應的jar包
安裝程序包: http://dl.mycat.org.cn/2.0/install-template/mycat2-install-template-1.21.zip
Jar包:http://dl.mycat.org.cn/2.0/1.21-release/mycat2-1.21-release-jar-with-dependencies.jar
?有能力的翻墻,偷懶的點鏈接就行
下載包和JDKhttps://pan.baidu.com/s/1SPIc5ZLF-6FYaZfGoyzXcQ?pwd=rhel
準備工作完畢就可以著手安裝了
安裝步驟
把下載好的MyCAT壓縮包解壓到/usr/local目錄
[root@MyCAT ~]# unzip mycat2-install-template-1.21.zip -d /usr/local/
把所需的jar復制(也可以移動)到mycat/lib目錄 ?
[root@MyCAT ~]# mv mycat2-1.21-release-jar-with-dependencies.jar /usr/local/mycat/lib/
?安裝JDK
[root@MyCAT ~]# yum install jdk-8u401-linux-x64.rpm -y
?修改文件夾及以下文件的權限
##/usr/local/mycat/bin 目錄下都是命令或者可執行文件,所以要添加執行權限
[root@MyCAT bin]# chmod +x *
啟動MySQL
因為mycat代理啟動時需要一個默認的數據源,所以我們在啟動時為其準備一個數據源。
openEuler自帶mysql-server直接yum install安裝就行
[root@MyCAT bin]# yum install -y mysql-server
[root@MyCAT bin]# systemctl enable --now mysqld
Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service → /usr/lib/systemd/system/mysqld.service.
[root@MyCAT bin]# mysqladmin -uroot password 'root'
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
配置物理庫地址
[root@MyCAT bin]# vim /usr/local/mycat/conf/datasources/prototypeDs.datasource.json
{"dbType":"mysql","idleTimeout":60000,"initSqls":[],"initSqlsGetConnection":true,"instanceType":"READ_WRITE","maxCon":1000,"maxConnectTimeout":3000,"maxRetryCount":5,"minCon":1,"name":"prototypeDs","password":"root","type":"JDBC","url":"jdbc:mysql://localhost:3306/mysql?useUnicode=true&serverTimezone=Asia/Shanghai&characterEncoding=UTF-8","user":"root", #這個和上面的password需要留意,你用上什么登錄就填什么。要不會報錯"weight":0
}
啟動
[root@MyCAT bin]# ./mycat start
Starting mycat2...
[root@MyCAT bin]# ./mycat status
mycat2 is running (2675).
[root@MyCAT bin]# tail /usr/local/mycat/logs/wrapper.log
?查看日志啟動成功
測試
在本地使用MyCAT初始用戶登錄測試
登錄成功,環境正常