In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail the questions about Python connecting Cassandra containers for querying. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.
First of all, Cassandra is deployed with microservices using docker-swarm.
The crux of the problem is to find port 9042 of Cassandra to get data.
Problem 1: in the IP of the Ping Cassandra container on the master node, the IP of the container connected by the docker-swarm bridge is not in the same network segment, so the ping failed and the port 9042 could not be obtained.
Question 2: enter ip addr into the Cassandra container and get the following results:
Get two IP fields, and the following IP field corresponds to the bridge created by docker-swarm. If you try ping on the master node, you will be able to ping. However, access to IP:9042 was denied.
Problem 3: when entering the container under the same IP address range, both IP fields of ping can be connected with ping, and port 9042 can be accessed. But it is troublesome to operate in the container, and my purpose is to operate in the node.
Solution: try to ping both on the node where the Cassandra container is located. Although the former still cannot ping, the latter can ping and execute in the container.
Cqlsh 172.18.0.3 # Bridge assignment IP
It is found that you can enter the database, and the IP assigned by the bridge can be connected, but port 9042 is not open on the node, so access is denied. Just open port 9042. Because of the time problem, I tested directly on the container node. The code is as follows:
#! / usr/bin/env python3 from cassandra.cluster import Clusterfrom cassandra.query import tuple_factoryfrom cassandra.policies import DCAwareRoundRobinPolicyfrom cassandra.policies import DowngradingConsistencyRetryPolicyfrom cassandra import ConsistencyLevelfrom cassandra.query import dict_factoryimport sys def conn (): cluster = Cluster (["172.18.0.3"]) session=cluster.connect ('jaeger_v1_dc1') return session if _ _ name__ =' _ main__': session= conn () data = session.execute ("select duration from traces limit 10") ") for i in data: print (I) session.shutdown () on" what are the problems of Python connecting Cassandra containers to query "this article ends here. I hope the above content can be of some help to you, so that you can learn more knowledge. If you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.