cassandra本地连接失败_无法连接到cassandra - NoHostAvailableException

I know there are several threads about the NoHostAvailableException but they simply don't provide a solution to my problem.

I can't connect to Cassandra with the Datastax Java Cassandra Driver. I get the Error:

com.datastax.driver.core.exceptions.NoHostAvailableException: All

host(s) tried for query failed (tried: [/54.221.241.107])

I am sure that the configuration is correct. I've set the configuration in cassandra.yaml:

start_native_transport: true

# port for the CQL native transport to listen for clients on

native_transport_port: 9042

My Cassandra installation is a standard installation on a EC2 instance on AWS. I've configured AWS to allow port 9042.

Cassandra is running on Windows Server 2008 R2 and I also configured the firewall to inbound and outbound connection on 9042.

My code looks like the following:

cluster = Cluster.builder()

.withPort(9042)

.addContactPoint("54.221.241.107").build();

I don't know what to do anymore since I always get this error. Any suggestions?

解决方案

Check your casssandra.yaml file. The native_transport uses the same address binding as the rpc_address. If it is bound to another address than "54.221.241.107" you would get this problem.

Try setting it to

rpc_address: 0.0.0.0

or to

rpc_address: 54.221.241.107

and see if it helps. Keep in mind that ec2-ips might change on restarts.

My guess is that is is bound to the internal ip of the ec-2. And remember to add some security if you are opening up your database to the public this way :-)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Spring Boot整合GeoMesa Cassandra是为了利用GeoMesa库的强大地理空间处理能力,与Cassandra NoSQL数据库结合,以便在Spring应用中方便地执行地理数据的CRUD操作。GeoMesa是一个高度可扩展的开源框架,它抽象了底层的数据存储,使得开发者能够更专注于业务逻辑。 以下是整合步骤: 1. 添加依赖: 在你的`pom.xml`文件中添加GeoMesa和Spring Data Cassandra的依赖: ```xml <dependency> <groupId>org.locationtech.geomesa</groupId> <artifactId>geomesa-spring-boot-starter-cassandra</artifactId> <version>XX.YY.ZZ</version> <!-- 用最新版本替换 --> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-cassandra</artifactId> </dependency> ``` 记得替换版本号为最新的稳定版。 2. 配置GeoMesa Cassandra:在`application.properties`或`application.yml`中配置Cassandra连接信息,包括主机、端口、用户名、密码等。 3. 创建数据源:在Spring Boot应用中,使用Spring Data Cassandra的Repository接口来定义地理空间数据源。例如,假设你有一个`Feature`实体映射到GeoMesa中的一个表,你可以创建一个类似这样的Repository接口: ```java public interface FeatureRepository extends GeoMesaFeatureDao<Feature, UUID> { // CRUD operations List<Feature> findByBbox(BoundingBox bbox); Feature findById(UUID id); void save(Feature feature); void deleteById(UUID id); } ``` 4. 使用Repository:注入`FeatureRepository`并进行CRUD操作: ```java @Autowired private FeatureRepository featureRepository; public void createFeature(Feature feature) { featureRepository.save(feature); } public Feature getFeatureById(UUID id) { return featureRepository.findById(id); } public void updateFeature(Feature updatedFeature) { featureRepository.save(updatedFeature); } public void deleteFeature(UUID id) { featureRepository.deleteById(id); } ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值