我在 Ubuntu 16.04 上的 2 个节点上安装了 MariaDB Galera 集群。
这里来自node1的信息:
root@localhost:~# sudo more /etc/mysql/conf.d/galera.cnf
[mysqld]
binlog_format=ROW
default-storage-engine=innodb
innodb_autoinc_lock_mode=2
bind-address=0.0.0.0
# Galera Provider Configuration
wsrep_on=ON
wsrep_provider=/usr/lib/galera/libgalera_smm.so
# Galera Cluster Configuration
wsrep_cluster_name="galera_cluster"
wsrep_cluster_address="gcomm://192.168.143.81,192.168.148.75"
# Galera Synchronization Configuration
wsrep_sst_method=rsync
# Galera Node Configuration
wsrep_node_address="192.168.143.81"
wsrep_node_name="Node1"
这里是来自node2的信息:
mysqld]
binlog_format=ROW
default-storage-engine=innodb
innodb_autoinc_lock_mode=2
bind-address=0.0.0.0
# Galera Provider Configuration
wsrep_on=ON
wsrep_provider=/usr/lib/galera/libgalera_smm.so
# Galera Cluster Configuration
wsrep_cluster_name="galera_cluster"
wsrep_cluster_address="gcomm://192.168.143.81,192.168.148.75"
# Galera Synchronization Configuration
wsrep_sst_method=rsync
# Galera Node Configuration
wsrep_node_address="192.168.148.75"
wsrep_node_name="Node2”
我正在从 Java 应用程序访问数据库。具有以下属性:
spring.datasource.url=jdbc:mysql://192.168.143.81:3306/can_peris_db
spring.datasource.username=peris
spring.datasource.password=3nRam0nD3L3s0l1v3s
spring.jpa.show-sql=false
spring.jpa.properties.hibernate.format_sql=true
hibernate.dialect=org.hibernate.dialect.MySQLDialect
一切正常,数据在两个数据库中都复制了。但是当我关闭服务器 192.168.143.81 时出现错误java.net.NoRouteToHostException: No route to host (Host unreachable)
有没有办法自动连接到可用的主机?