当前位置: 首页 > news >正文

南通优普营销网站建设温州制作企业网站

南通优普营销网站建设,温州制作企业网站,网上自学平台,wordpress 替换google字体简介 Apache Cassandra是一个高度可扩展的高性能分布式数据库#xff0c;旨在处理许多商用服务器上的大量数据#xff0c;提供高可用性而没有单点故障。它是NoSQL数据库的一种。首先让我们了解一下NoSQL数据库的作用。 NoSQL 数据库 NoSQL数据库#xff08;有时称为“Not …简介 Apache Cassandra是一个高度可扩展的高性能分布式数据库旨在处理许多商用服务器上的大量数据提供高可用性而没有单点故障。它是NoSQL数据库的一种。首先让我们了解一下NoSQL数据库的作用。 NoSQL 数据库 NoSQL数据库有时称为“Not Only SQL”是一种数据库它提供了一种存储和检索关系数据库中使用的表格关系以外的数据的机制。这些数据库是无模式的支持简单的复制具有简单的API最终是一致的并且可以处理大量数据。 什么是Apache Cassandra Apache Cassandra是一个开源分布式和分散/分布式存储系统数据库用于管理分布在世界各地的大量结构化数据。它提供高可用性服务没有单点故障。 以下列出了Apache Cassandra的一些值得注意的地方- 它具有可伸缩性容错性和一致性。它是一个面向列的数据库。其分发设计基于亚马逊的Dynamo及其在Google的Bigtable上的数据模型。它创建于Facebook与关系数据库管理系统截然不同。Cassandra实现了Dynamo风格的复制模型没有单点故障但是添加了更强大的“column family”数据模型。一些大型公司例如FacebookTwitterCiscoRackspaceebayTwitterNetflix等正在使用Cassandra。 特性 弹性可扩展性 - Cassandra是高度可扩展的; 它允许添加更多的硬件以适应更多的客户和更多的数据根据要求。 始终基于架构 - Cassandra没有单点故障它可以连续用于不能承担故障的关键业务应用程序。 快速线性性能 - Cassandra是线性可扩展性的即它为你增加集群中的节点数量增加你的吞吐量。因此保持一个快速的响应时间。 灵活的数据存储 - Cassandra适应所有可能的数据格式包括结构化半结构化和非结构化。它可以根据您的需要动态地适应变化的数据结构。 便捷的数据分发 - 可以在多个数据中心之间复制数据可以灵活地在需要时分发数据。 事务支持 - Cassandra支持属性如原子性一致性隔离和持久性ACID。 快速写入 - Cassandra被设计为在廉价的商品硬件上运行。 它执行快速写入并可以存储数百TB的数据而不牺牲读取效率。 Cassandra特点 Cassandra由于其出色的技术特性而变得如此受欢迎。以下是Cassandra的一些功能 弹性可扩展性– Cassandra具有高度可扩展性它允许添加更多硬件以根据需求容纳更多客户和更多数据。始终在线-Cassandra没有单点故障并且可以连续用于无法承受故障的关键业务应用程序。快速的线性规模性能-Cassandra具有线性可扩展性即随着集群中节点数量的增加它可以提高吞吐量。因此它保持了快速的响应时间。灵活的数据存储-Cassandra可容纳所有可能的数据格式包括结构化半结构化和非结构化。它可以根据需要动态适应对数据结构的更改。轻松进行数据分发-Cassandra通过在多个数据中心之间复制数据提供了在所需位置分发数据的灵活性。事务支持-Cassandra支持原子性一致性隔离性和持久性ACID等属性。快速写入-Cassandra旨在在廉价的商品硬件上运行。它执行快速的写入并且可以存储数百TB的数据而不会牺牲读取效率。 架构 Cassandra的设计目标是在多个节点上处理大数据工作负载而不会出现任何单点故障。 Cassandra在其节点之间具有对等分布式系统并且数据分布在集群中的所有节点之间。 集群中的所有节点都扮演相同的角色。每个节点都是独立的并同时互连到其他节点。集群中的每个节点都可以接受读写请求而不管数据实际位于集群中的何处。当某个节点发生故障时可以从网络中的其他节点处理读/写请求。 Cassandra中的数据复制 在Cassandra中集群中的一个或多个节点充当给定数据段的副本。如果检测到某些节点响应的值过时则Cassandra会将最新值返回给客户端。返回最新值后Cassandra在后台执行读取修复以更新过时的值。 下图显示了Cassandra如何在集群中的节点之间使用数据复制以确保没有单点故障的示意图。 Cassandra使用Gossip协议以允许节点彼此通信并检测集群中的任何故障节点。入门安装使用docker-compose 安装 docker-compose.yaml version: 3.8 services:cassandra:image: cassandra:4.1container_name: cassandraports:- 9042:9042volumes:- $PWD/commitlog:/var/lib/cassandra/commitlog- $PWD/hints:/var/lib/cassandra/hints- $PWD/data:/var/lib/cassandra/data- $PWD/saved_caches:/var/lib/cassandra/saved_caches- $PWD/logs:/var/log/cassandra启动容器 使用如下指令启动容器 docker-compose up -d 注意如果如果没有在docker-compose.yaml文件所在目录或者文件名不是docker-compose.yaml需要通过-f指定文件所在位置。即如 docker-compose -f cassandra-start-up.yaml up -d 启动好之后可以进入到容器之中 ➜ cassandra docker-compose up -d Creating network cassandra_default with the default driver Pulling cassandra (cassandra:4.1)... 4.1: Pulling from library/cassandra eaead16dc43b: Pull complete 46e1869246ce: Pull complete bbd45db92608: Pull complete 6fcfd0f47989: Pull complete 996685dfbe33: Pull complete 4927828dcc1b: Pull complete 7f67cde8352d: Pull complete 09bb07e15655: Pull complete b8d7c6610af3: Pull complete Status: Downloaded newer image for cassandra:4.1 Creating cassandra ... done ➜ cassandra docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES cdf4f5b56a88 cassandra:4.1 docker-entrypoint.s… 10 minutes ago Up 10 minutes 7000-7001/tcp, 7199/tcp, 9160/tcp, 0.0.0.0:9042-9042/tcp cassandra ➜ cassandra docker exec -it cdf4f5b56a88 bash rootcdf4f5b56a88:/# cqlsh Connected to Test Cluster at 127.0.0.1:9042 [cqlsh 6.1.0 | Cassandra 4.1-beta1 | CQL spec 3.4.6 | Native protocol v5] Use HELP for help. cqlsh desc keyspaces;system system_distributed system_traces system_virtual_schema system_auth system_schema system_views可以看到我们已经通过cqlsh命令登录到了当前的Cassandra数据库。 但是这里会有疑惑产生 登录数据库的指令太过简单了吧如果需要登录指定主机地址的数据库应该怎么设置主机地址 登录数据库的指令不需要用户名和密码嘛 需要的话我的用户名和密码是什么就目前而言我并没有做任何设置。 如何设置用户名和密码   cqlsh的基本命令  选项    使用/作用 help    此命令用于显示有关CQLsh命令选项的帮助主题。 version    它用于查看您正在使用的CQLsh的版本。 color    它用于彩色输出。 debug    它显示其他调试信息。 execute    它用于引导shell接受并执行CQL命令。 show    显示当前会话详情 这里的options包括哪些呢? 官网写的很详细我就不抄了看这里 cqlsh: the CQL shell 我就挑几个最关心的看一下 -u USERNAME --usernameUSERNAME Authenticate as user. -p PASSWORD --passwordPASSWORD Authenticate using password. -k KEYSPACE --keyspaceKEYSPACE Authenticate to the given keyspace. 这三个是用来指定用户名和密码以及keySpace的。 –credentialsCREDENTIALS Specify an alternative credentials file location. 这个是用来指定credentials的。 为什么没有输入用户名和密码就直接登录了 这里是由于没有做任何个性化配置我们使用的相关配置是默认配置文件cassandra.yaml文件里的配置这个配置文件在容器里的/opt/cassandra/conf目录下。这里的配置内容是   #AllowAllAuthenticator performs no checks - set it to disable authentication. authenticator: AllowAllAuthenticator当这里配置为AllowAllAuthenticator的时候将不做任何的检查。是设置为关闭认证。 要想启用用户名密码登录就需要将其设置为PasswordAuthenticator authenticator: PasswordAuthenticator 不过这个时候会发现容器中没有vim也没有vi那就只能把容器里的文件copy出来修改完再copy回去了。 docker cp cdf4f5b56a88:/opt/cassandra/conf/cassandra.yaml . 我这是把文件从容器中copy当当前位置修改完之后再copy回去source和destination位置互换即: docker cp cassandra.yaml cdf4f5b56a88:/opt/cassandra/conf/ 替换完成之后再重新启动容器 docker restart cdf4f5b56a88 重启完之后再进入容器再使用cqlsh指令登录发得到如下错误 ➜  cassandra docker exec -it cdf4f5b56a88 bash rootcdf4f5b56a88:/# cqlsh Connection error: (Unable to connect to any servers, {127.0.0.1:9042: ConnectionRefusedError(111, Tried connecting to [(127.0.0.1, 9042)]. Last error: Connection refused)}) rootcdf4f5b56a88:/# 看上面的提示似乎也看不出来什么错误只是connection refused。那就想着用用户名和密码尝试一下吧由于我们没有设置用户名和密码这个时候就只能使用系统默认设置的用户名和密码都是cassandra的账户进行登录。 rootcdf4f5b56a88:/# cqlsh -u cassandra -p cassandraWarning: Using a password on the command line interface can be insecure. Recommendation: use the credentials file to securely provide the password.Connected to Test Cluster at 127.0.0.1:9042 [cqlsh 6.1.0 | Cassandra 4.1-beta1 | CQL spec 3.4.6 | Native protocol v5] Use HELP for help. cassandracqlsh创建新用户 cassnadra划分了三种角色类型 xxopr: 应用账号,只能进行对表的查询、数据插入、数据删除等DML操作 xxdata: 相当于数据OWNER用户对表空间内的对象拥有增删改查等DDL操作 cassandra: 超级用户用于创建表空间的DBA权限管理 这里先创建一个superuser create user root_cassandra with password 123456 superuser; 然后使用这个用户进行登录 rootcdf4f5b56a88:/# cqlsh -u root_cassandra -p 123456Warning: Using a password on the command line interface can be insecure. Recommendation: use the credentials file to securely provide the password.Connected to Test Cluster at 127.0.0.1:9042 [cqlsh 6.1.0 | Cassandra 4.1-beta1 | CQL spec 3.4.6 | Native protocol v5] Use HELP for help. root_cassandracqlsh list users;name | super | datacenters ------------------------------------cassandra | True | ALLroot_cassandra | True | ALL(2 rows) root_cassandracqlsh可以看到这里已经有两个超级用户了不想保留cassandra这个用户的可以直接drop掉。 drop user cassandra 简单操作 既然已经到这里了那就创建一个用户试试简单操作先 root_cassandracqlsh create user test_data with password 123456 nosuperuser; root_cassandracqlsh exit; rootcdf4f5b56a88:/# cqlsh -u test_data -p 123456Warning: Using a password on the command line interface can be insecure. Recommendation: use the credentials file to securely provide the password.Connected to Test Cluster at 127.0.0.1:9042 [cqlsh 6.1.0 | Cassandra 4.1-beta1 | CQL spec 3.4.6 | Native protocol v5] Use HELP for help. test_datacqlsh CREATE KEYSPACE IF NOT EXISTS store WITH REPLICATION { class : SimpleStrategy, replication_factor : 1 }; test_datacqlsh desc keyspaces;store system_auth system_schema system_views system system_distributed system_traces system_virtual_schematest_datacqlsh desc keyspace storeCREATE KEYSPACE store WITH replication {class: SimpleStrategy, replication_factor: 1} AND durable_writes true; test_datacqlsh CREATE TABLE IF NOT EXISTS store.shopping_cart (... userid text PRIMARY KEY,... item_count int,... last_update_timestamp timestamp... ); test_datacqlsh INSERT INTO store.shopping_cart... (userid, item_count, last_update_timestamp)... VALUES (9876, 2, toTimeStamp(now())); test_datacqlsh INSERT INTO store.shopping_cart... (userid, item_count, last_update_timestamp)... VALUES (1234, 5, toTimeStamp(now()));可以看到已经创建了一个keyspace为store的库创建了一个表shopping_cart,并插入了一些数据。查看一下表结构以及数据 test_datacqlsh:store select * from store.shopping_cart;userid | item_count | last_update_timestamp -----------------------------------------------------1234 | 5 | 2022-11-05 08:39:47.07700000009876 | 2 | 2022-11-05 08:39:46.2260000000(2 rows) test_datacqlsh:store desc table shopping_cart;CREATE TABLE store.shopping_cart (userid text PRIMARY KEY,item_count int,last_update_timestamp timestamp ) WITH additional_write_policy 99pAND bloom_filter_fp_chance 0.01AND caching {keys: ALL, rows_per_partition: NONE}AND cdc falseAND comment AND compaction {class: org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy, max_threshold: 32, min_threshold: 4}AND compression {chunk_length_in_kb: 16, class: org.apache.cassandra.io.compress.LZ4Compressor}AND memtable defaultAND crc_check_chance 1.0AND default_time_to_live 0AND extensions {}AND gc_grace_seconds 864000AND max_index_interval 2048AND memtable_flush_period_in_ms 0AND min_index_interval 128AND read_repair BLOCKINGAND speculative_retry 99p; test_datacqlsh:store到此完成了Cassandra的启动。  在SpringBoot中连接Cassandra 1.添加依赖 ?xml version1.0 encodingUTF-8? project xmlnshttp://maven.apache.org/POM/4.0.0 xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersionparentgroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-parent/artifactIdversion2.5.14/versionrelativePath//parentgroupIdcom.example/groupIdartifactIddemo/artifactIdversion0.0.1-SNAPSHOT/versionnamedemo/namedescriptionDemo project for Spring Boot/descriptionpropertiesjava.version1.8/java.version/propertiesdependenciesdependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-data-cassandra/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-test/artifactIdscopetest/scope/dependency/dependenciesbuildpluginsplugingroupIdorg.springframework.boot/groupIdartifactIdspring-boot-maven-plugin/artifactId/plugin/plugins/build/project2.添加配置 spring:data:cassandra:contact-points: localhostport: 9042keyspace-name: storeusername: root_cassandrapassword: 123456 3.添加配置类 package com.example.demo;import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component;Component ConfigurationProperties(prefix spring.data.cassandra,ignoreInvalidFields true) public class CassandraConfigurationProperties {private String contactPoints;private int port 9042;private String username;private String password;private String keyspaceName;public String getContactPoints() {return contactPoints;}public void setContactPoints(String contactPoints) {this.contactPoints contactPoints;}public int getPort() {return port;}public void setPort(int port) {this.port port;}public String getUsername() {return username;}public void setUsername(String username) {this.username username;}public String getPassword() {return password;}public void setPassword(String password) {this.password password;}public String getKeyspaceName() {return keyspaceName;}public void setKeyspaceName(String keyspaceName) {this.keyspaceName keyspaceName;} } package com.example.demo;import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Configuration; import org.springframework.data.cassandra.config.AbstractCassandraConfiguration; import org.springframework.data.cassandra.config.CqlSessionFactoryBean;Configuration EnableConfigurationProperties(CassandraConfigurationProperties.class) public class CassandraConfiguration extends AbstractCassandraConfiguration {Autowiredprivate CassandraConfigurationProperties cassandraConfigurationProperties;Overrideprotected String getKeyspaceName() {return cassandraConfigurationProperties.getKeyspaceName();}Overrideprotected String getContactPoints() {return cassandraConfigurationProperties.getContactPoints();}Overrideprotected int getPort() {return cassandraConfigurationProperties.getPort();}Overridepublic CqlSessionFactoryBean cassandraSession() {CqlSessionFactoryBean cqlSessionFactoryBean super.cassandraSession();cqlSessionFactoryBean.setPassword(cassandraConfigurationProperties.getPassword());cqlSessionFactoryBean.setUsername(cassandraConfigurationProperties.getUsername());return cqlSessionFactoryBean;}}设置对应的实体类 package com.example.demo;import org.springframework.data.cassandra.core.cql.PrimaryKeyType; import org.springframework.data.cassandra.core.mapping.Column; import org.springframework.data.cassandra.core.mapping.PrimaryKeyColumn; import org.springframework.data.cassandra.core.mapping.Table;import java.util.Date;Table(shopping_cart) public class ShoppingCart {PrimaryKeyColumn(type PrimaryKeyType.PARTITIONED)private String userid;Columnprivate int item_count;Columnprivate Date last_update_timestamp;public String getUserid() {return userid;}public void setUserid(String userid) {this.userid userid;}public int getItem_count() {return item_count;}public void setItem_count(int item_count) {this.item_count item_count;}public Date getLast_update_timestamp() {return last_update_timestamp;}public void setLast_update_timestamp(Date last_update_timestamp) {this.last_update_timestamp last_update_timestamp;}Overridepublic String toString() {return ShoppingCart{ userid userid \ , item_count item_count , last_update_timestamp last_update_timestamp };} }设置接口类 package com.example.demo;import org.springframework.data.cassandra.repository.CassandraRepository;public interface ShoppingCartRepo extends CassandraRepositoryShoppingCart, String { }设置SpringBoot启动类 package com.example.demo;import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;SpringBootApplication public class DemoApplication {public static void main(String[] args) {SpringApplication.run(DemoApplication.class, args);}}编写测试代码 package com.example.demo;import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.data.cassandra.core.CassandraTemplate;import java.util.List;SpringBootTest class DemoApplicationTests {Autowiredprivate CassandraTemplate cassandraTemplate;Testvoid query() {ShoppingCart cart cassandraTemplate.selectOne(select * from store.shopping_cart, ShoppingCart.class);System.out.println(cart);}Autowiredprivate ShoppingCartRepo shoppingCartRepo;Testvoid query2(){ListShoppingCart all shoppingCartRepo.findAll();System.out.println(all);}}
http://www.tj-hxxt.cn/news/231444.html

相关文章:

  • 洛夕网站建设想学软件开发报什么专业
  • 如何创建一个免费的网站网站管理和维护
  • 网站公司市场营销方案页面访问升级老域名
  • 郑州网站优化服务wordpress super 缓存
  • 宁波网站建站推广wordpress如何设置404页面跳转
  • iis网站怎么做全站伪静态网页设计与网站建设在线考试石油大学
  • 网站加速代码移动网站设计心得
  • 烟台网站建设设计西安企业建站排名
  • 网站建设网站制作做网站多少钱西宁君博美评
  • 网络设计课程总结网络优化公司哪家好
  • 网站 手机版 电脑版 怎么做国外服务器免费ip地址
  • 东莞门户网站建设东莞人才市场最新招聘信息
  • ipad怎么制作网站七冶建设集团网站
  • 嘉兴定制型网站建设免备案的网站
  • 山西龙采网站建设合同电子商务网站开发 什么框架
  • 龙江网站开发大连建设执业资格注册中心网站
  • 重庆渝北网站建设悟空建站seo服务
  • 免费制作音乐的软件app济南网站建设seo优化
  • 企业网站首页代码html网站更新
  • 网站建设案例策划蚌埠网站制作
  • 百度申请完域名怎么建设网站在沈阳做一个展示网站多少钱
  • 深圳做网站电话网络服务机构
  • 网站二级域名是什么视频模板套用免费
  • 潍坊哪家做网站做的最好网站常用的一种js幻灯片
  • 网络推广网站排名wordpress做表格插件
  • 阿里手机网站开发框架浙江温州乐清
  • 设计的有趣的网站网站免费软件
  • 如何学习网站开发编程定海建设规划网站
  • 上海网站备案广州网站建设咨询电话
  • 网站建设浙江如何做流量网站