当前位置:   article > 正文

cassandra 安装_cassandra.noarch.0.4.1.3-1 将被 安装 错误:invalid versio

cassandra.noarch.0.4.1.3-1 将被 安装 错误:invalid version flag: or
  1. # 获取镜像
  2. docker pull cassandra
  3. # 运行
  4. docker run -d --name cassandra cassandra:latest -p 9402:9402
  5. # 进入容器
  6. docker exec -it cassandra bash
  7. # 更新apt-get 并安装vim
  8. apt-get update
  9. apt-get install vim -y
  10. # 进入数据库
  11. cqlsh
  12. # 修改集群名称
  13. UPDATE system.local SET cluster_name = 'cass_cluster' where key='local';
  14. # 修改完成,退出
  15. exit
  16. # 修改配置文件
  17. vim /etc/cassandra/cassandra.yaml
  18. # 集群名称
  19. cluster_name:cass_cluster
  20. # 修改集群ip
  21. seeds: "127.0.0.1,127.0.0.2,127.0.0.3"
  22. 保存退出重启容器
  23. docker restart cassandra

创建集群失败 , docker集群跑不起来 , 最后使用yum 方式安装集群启动成功

下载地址

 

cassandra示例

Eugene Valchkou  方式处理业务

  1. <dependency>
  2. <groupId>com.valchkou.datastax</groupId>
  3. <artifactId>cassandra-driver-mapping</artifactId>
  4. </dependency>
  5. <dependency>
  6. <groupId>com.codahale.metrics</groupId>
  7. <artifactId>metrics-servlets</artifactId>
  8. </dependency>

配置文件 

  1. package com.wdz.cassandra.config;
  2. import com.datastax.driver.core.Cluster;
  3. import com.datastax.driver.core.PlainTextAuthProvider;
  4. import com.datastax.driver.core.Session;
  5. import com.datastax.driver.mapping.MappingSession;
  6. import org.springframework.boot.context.properties.ConfigurationProperties;
  7. import org.springframework.context.annotation.Bean;
  8. import org.springframework.context.annotation.Configuration;
  9. @Configuration
  10. @ConfigurationProperties(prefix = "spring.data.cassandra")
  11. public class CassandraConfig {
  12. private String clusterName;
  13. private String keyspaceName;
  14. private String username;
  15. private String password;
  16. private int port;
  17. private String contactPoints;
  18. private String consistencyLevel;
  19. @Bean
  20. public Cluster cluster() {
  21. Cluster build = Cluster.builder()
  22. .withCredentials(username,password)
  23. .withPort(port)
  24. .withClusterName(clusterName)
  25. .addContactPoints(contactPoints)
  26. .withAuthProvider(authProvider())
  27. .build();
  28. return build;
  29. }
  30. @Bean
  31. public PlainTextAuthProvider authProvider() {
  32. return new PlainTextAuthProvider(username,password);
  33. }
  34. @Bean
  35. public Session session(Cluster cluster) {
  36. // initialize datastax session.
  37. Session session = cluster.connect();
  38. return session;
  39. }
  40. @Bean
  41. public MappingSession mappingSession() {
  42. MappingSession session = new MappingSession(keyspaceName, session(cluster()));
  43. return session;
  44. }
  45. public String getClusterName() {
  46. return clusterName;
  47. }
  48. public void setClusterName(String clusterName) {
  49. this.clusterName = clusterName;
  50. }
  51. public String getKeyspaceName() {
  52. return keyspaceName;
  53. }
  54. public void setKeyspaceName(String keyspaceName) {
  55. this.keyspaceName = keyspaceName;
  56. }
  57. public String getUsername() {
  58. return username;
  59. }
  60. public void setUsername(String username) {
  61. this.username = username;
  62. }
  63. public String getPassword() {
  64. return password;
  65. }
  66. public void setPassword(String password) {
  67. this.password = password;
  68. }
  69. public int getPort() {
  70. return port;
  71. }
  72. public void setPort(int port) {
  73. this.port = port;
  74. }
  75. public String getContactPoints() {
  76. return contactPoints;
  77. }
  78. public void setContactPoints(String contactPoints) {
  79. this.contactPoints = contactPoints;
  80. }
  81. public String getConsistencyLevel() {
  82. return consistencyLevel;
  83. }
  84. public void setConsistencyLevel(String consistencyLevel) {
  85. this.consistencyLevel = consistencyLevel;
  86. }
  87. }

domain

  1. package com.wdz.cassandra.domian;
  2. import javax.persistence.Column;
  3. import javax.persistence.Id;
  4. import javax.persistence.Table;
  5. /**
  6. * demo
  7. */
  8. @Table(name = "device_locus")
  9. public class DeviceLocus {
  10. @Id
  11. private String device_key;
  12. @Column
  13. private Long timez;
  14. @Column
  15. private String latitude;
  16. @Column
  17. private String longitude;
  18. /**
  19. * 设备经纬度
  20. */
  21. @Column
  22. private String device_gps;
  23. /**
  24. * 设备时间戳
  25. */
  26. @Column
  27. private Long device_timez;
  28. @Column
  29. private Integer course;
  30. @Column
  31. private Float speed;
  32. public DeviceLocus() {
  33. }
  34. public DeviceLocus(String device_key, Long timez, String latitude, String longitude, Integer course, Float speed, String device_gps, Long device_timez) {
  35. this.device_key = device_key;
  36. this.timez = timez;
  37. this.latitude = latitude;
  38. this.longitude = longitude;
  39. this.course = course;
  40. this.speed = speed;
  41. this.device_gps = device_gps;
  42. this.device_timez = device_timez;
  43. }
  44. public DeviceLocus(String device_key, Long timez, String latitude, String longitude) {
  45. this.device_key = device_key;
  46. this.timez = timez;
  47. this.latitude = latitude;
  48. this.longitude = longitude;
  49. }
  50. public String getDevice_key() {
  51. return device_key;
  52. }
  53. public void setDevice_key(String device_key) {
  54. this.device_key = device_key;
  55. }
  56. public long getTimez() {
  57. return timez;
  58. }
  59. public void setTimez(long timez) {
  60. this.timez = timez;
  61. }
  62. public String getLatitude() {
  63. return latitude;
  64. }
  65. public void setLatitude(String latitude) {
  66. this.latitude = latitude;
  67. }
  68. public String getLongitude() {
  69. return longitude;
  70. }
  71. public void setLongitude(String longitude) {
  72. this.longitude = longitude;
  73. }
  74. public String getDevice_gps() {
  75. return device_gps;
  76. }
  77. public void setDevice_gps(String device_gps) {
  78. this.device_gps = device_gps;
  79. }
  80. public Long getDevice_timez() {
  81. return device_timez;
  82. }
  83. public void setDevice_timez(Long device_timez) {
  84. this.device_timez = device_timez;
  85. }
  86. public Integer getCourse() {
  87. return course;
  88. }
  89. public void setCourse(Integer course) {
  90. this.course = course;
  91. }
  92. public Float getSpeed() {
  93. return speed;
  94. }
  95. public void setSpeed(Float speed) {
  96. this.speed = speed;
  97. }
  98. @Override
  99. public String toString() {
  100. return "DeviceLocus{" +
  101. "device_key='" + device_key + '\'' +
  102. ", timez=" + timez +
  103. ", latitude='" + latitude + '\'' +
  104. ", longitude='" + longitude + '\'' +
  105. ", device_gps='" + device_gps + '\'' +
  106. ", device_timez=" + device_timez +
  107. ", course=" + course +
  108. ", speed=" + speed +
  109. '}';
  110. }
  111. }

  1. package com.wdz.cassandra;
  2. import com.datastax.driver.mapping.MappingSession;
  3. import com.wdz.cassandra.domian.DeviceLocus;
  4. import org.junit.jupiter.api.Test;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.boot.test.context.SpringBootTest;
  7. @SpringBootTest
  8. class CassandraBootApplicationTests {
  9. @Autowired
  10. private MappingSession mappingSession;
  11. @Test
  12. void contextLoads() {
  13. DeviceLocus deviceLocus = new DeviceLocus("8655", System.currentTimeMillis(), "34.22222", "123.123123");
  14. // demoService.insert(deviceLocus);
  15. mappingSession.save(deviceLocus);
  16. System.out.println("================");
  17. }
  18. }

  1. server:
  2. port: 8888
  3. spring:
  4. data:
  5. cassandra:
  6. clusterName: Test Cluster
  7. keyspaceName: test
  8. username: test
  9. password: test
  10. port: 9042
  11. contactPoints: 12.3.45.6
  12. consistencyLevel: ONE

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/126317
推荐阅读
相关标签
  

闽ICP备14008679号