前端技术
HTML
CSS
Javascript
前端框架和UI库
VUE
ReactJS
AngularJS
JQuery
NodeJS
JSON
Element-UI
Bootstrap
Material UI
服务端和客户端
Java
Python
PHP
Golang
Scala
Kotlin
Groovy
Ruby
Lua
.net
c#
c++
后端WEB和工程框架
SpringBoot
SpringCloud
Struts2
MyBatis
Hibernate
Tornado
Beego
Go-Spring
Go Gin
Go Iris
Dubbo
HessianRPC
Maven
Gradle
数据库
MySQL
Oracle
Mongo
中间件与web容器
Redis
MemCache
Etcd
Cassandra
Kafka
RabbitMQ
RocketMQ
ActiveMQ
Nacos
Consul
Tomcat
Nginx
Netty
大数据技术
Hive
Impala
ClickHouse
DorisDB
Greenplum
PostgreSQL
HBase
Kylin
Hadoop
Apache Pig
ZooKeeper
SeaTunnel
Sqoop
Datax
Flink
Spark
Mahout
数据搜索与日志
ElasticSearch
Apache Lucene
Apache Solr
Kibana
Logstash
数据可视化与OLAP
Apache Atlas
Superset
Saiku
Tesseract
系统与容器
Linux
Shell
Docker
Kubernetes
[逻辑复制 Logical Replica...]的搜索结果
这里是文章列表。热门标签的颜色随机变换,标签颜色没有特殊含义。
点击某个标签可搜索标签相关的文章。
点击某个标签可搜索标签相关的文章。
PostgreSQL
...成效率降低的现象。 逻辑复制(Logical Replication) , 逻辑复制是数据库系统中一种高级复制技术,它将数据库层面的逻辑更改(如INSERT、UPDATE、DELETE操作)以事务的形式复制到其他数据库节点上,而非物理磁盘块级别的复制。在PostgreSQL中,逻辑复制可以与序列生成器结合使用,实现在分布式系统中的全局唯一序列号分配,确保即使在多节点环境中也能保持序列号的全局唯一性。
2023-04-25 22:21:14
77
半夏微凉-t
PostgreSQL
...r等中间件,或者采用逻辑复制、streaming replication等内置机制来构建跨节点的PostgreSQL集群。 3. PostgreSQL集群架构实战详解 3.1 Streaming Replication(流复制) Streaming Replication是PostgreSQL提供的原生数据复制方案,它允许主从节点之间近乎实时地进行数据同步。 sql -- 在主节点上启用流复制并设置唯一标识 ALTER SYSTEM SET wal_level = 'logical'; SELECT pg_create_physical_replication_slot('my_slot'); -- 在从节点启动复制进程,并连接到主节点 sudo -u postgres pg_basebackup -h -D /var/lib/pgsql/12/data -U repuser --slot=my_slot 3.2 Logical Replication Logical Replication则提供了更灵活的数据分发机制,可以基于表级别的订阅和发布模式。 sql -- 在主节点创建发布者 CREATE PUBLICATION my_publication FOR TABLE my_table; -- 在从节点创建订阅者 CREATE SUBSCRIPTION my_subscription CONNECTION 'host= user=repuser password=mypassword' PUBLICATION my_publication; 3.3 使用中间件搭建集群 例如,使用PGPool-II可以实现负载均衡和读写分离: bash 安装并配置PGPool-II apt-get install pgpool2 vim /etc/pgpool2/pgpool.conf 配置主从节点信息以及负载均衡策略 ... backend_hostname0 = 'primary_host' backend_port0 = 5432 backend_weight0 = 1 ... 启动PGPool-II服务 systemctl start pgpool2 4. 探讨与思考 PostgreSQL集群架构的设计不仅极大地提升了系统的稳定性和可用性,也为开发者在实际业务中提供了更多的可能性。在实际操作中,咱们得根据业务的具体需求,灵活掂量各种集群方案的优先级。比如说,是不是非得保证数据强一致性?或者,咱是否需要横向扩展来应对更大规模的业务挑战?这样子去考虑就对了。另外,随着科技的不断进步,PostgreSQL这个数据库也在马不停蹄地优化自家的集群功能呢。比如说,它引入了全局事务ID、同步提交组这些酷炫的新特性,这样一来,以后在处理大规模分布式应用的时候,就更加游刃有余,相当于提前给未来铺好了一条康庄大道。 总的来说,PostgreSQL集群架构的魅力在于其灵活性和可扩展性,它像一个精密的齿轮箱,每个组件各司其职又相互协作,共同驱动着整个数据库系统高效稳健地运行。所以,在我们亲手搭建和不断优化PostgreSQL集群的过程中,每一个细微之处都值得我们去仔仔细细琢磨,每一行代码都满满地倾注了我们对数据管理这门艺术的执着追求与无比热爱。就像是在雕琢一件精美的艺术品一样,我们对每一个细节、每一段代码都充满敬畏和热情。
2023-04-03 12:12:59
248
追梦人_
PostgreSQL
...tgreSQL 数据复制问题深度解析与实践 1. 引言 在当今的大数据时代,数据库的稳定性、高效性和数据一致性显得尤为重要。PostgreSQL这款开源的对象关系型数据库系统,那家伙可厉害了!人家凭仗着无比强大的功能和顶呱呱的性能表现,在江湖上那是赢得了一片叫好声,圈粉无数啊!然而,在实际操作中,我们总会遇到一个挠头的大问题:怎样才能既快速又稳妥地复制数据,确保系统高度稳定、随时可恢复,还能适应分布式部署的各种需求呢?本文将深入探讨PostgreSQL的数据复制问题,并通过实例代码带您一起走进实战环节。 2. PostgreSQL 数据复制基础概念 2.1 复制类型 PostgreSQL提供了物理复制和逻辑复制两种方式。物理复制这东西,就好比有个超级认真的小秘书,它利用WAL(提前写日志)的方法,实时、同步地把数据库所有的改动“原封不动”地搬到另一个地方。而逻辑复制呢,则更像是个懂业务的翻译官,专门关注SQL这种高级命令或者一连串的操作事务,特别适合那些需要把数据分发到多个数据库,或者在传输过程中还需要对数据进行转换处理的情况。 2.2 主从复制架构 典型的PostgreSQL数据复制采用主-从架构,其中主节点负责处理写入请求并生成WAL日志,从节点则订阅并应用这些日志,从而实现数据的实时同步。 3. 物理复制实践 3.1 配置主从复制 让我们首先通过一段示例配置开启主从复制: postgresql -- 在主库上创建复制用户并赋予权限 CREATE ROLE replication_user WITH REPLICATION LOGIN ENCRYPTED PASSWORD 'your_password'; GRANT ALL PRIVILEGES ON DATABASE your_database TO replication_user; -- 查看主库的当前WAL位置 SELECT pg_current_wal_lsn(); -- 在从库上设置主库信息 RECOVERY.conf 文件内容如下: standby_mode = 'on' primary_conninfo = 'host=master_host port=5432 user=replication_user password=your_password' -- 刷新从库并启动复制进程 pg_ctl restart -D /path/to/your_slave_node_data_directory 3.2 监控与故障切换 当主库出现故障时,可以手动提升从库为新的主库。但为了实现自动化,通常会借助 Patroni 或者其它集群管理工具来管理和监控整个复制过程。 4. 逻辑复制实践 4.1 创建发布与订阅 逻辑复制需在主库上创建发布(publication),并在从库上创建订阅(subscription): postgresql -- 在主库上创建发布 CREATE PUBLICATION my_pub FOR TABLE table1, table2; -- 在从库上创建订阅 CREATE SUBSCRIPTION my_sub CONNECTION 'dbname=your_dbname host=master_host user=replication_user password=your_password' PUBLICATION my_pub; 4.2 实时同步与冲突解决 逻辑复制虽然提供更灵活的数据分发方式,但也可能引入数据冲突的问题。所以在规划逻辑复制方案的时候,咱们得充分琢磨一下冲突检测和解决的策略,就像是可以通过触发器或者应用程序自身的逻辑巧妙地进行管控那样。 5. 结论与思考 PostgreSQL的数据复制机制为我们提供了可靠的数据冗余和扩展能力,但同时也带来了一系列运维挑战,如复制延迟、数据冲突等问题。在实际操作的时候,我们得瞅准业务的特性跟需求,像挑衣服那样选出最合身的复制策略。而且呢,咱们还得像个操心的老妈子一样,时刻盯着系统的状态,随时给它调校调校,确保一切运转正常。甭管是在追求数据完美同步这条道上,还是在捣鼓系统性能提升的过程中,每一次对PostgreSQL数据复制技术的深入理解和动手实践,都像是一场充满挑战又收获满满的探险之旅。 记住,每个数据库背后都是鲜活的业务需求和海量的数据故事,我们在理解PostgreSQL数据复制的同时,也在理解着这个世界的数据流动与变迁,这正是我们热衷于此的原因所在!
2023-03-15 11:06:28
343
人生如戏
Kafka
...st:9092 --replication-factor 1 --partitions 2 --topic my-topic 上述命令会告诉Kafka在本地服务器上创建一个名为my-topic的主题,并指定其拥有两个分区和一个副本。 3. 查看Topic列表 创建了Topic之后,我们可能想要查看当前Kafka集群中存在的所有Topic。执行如下命令: bash bin/kafka-topics.sh --list --bootstrap-server localhost:9092 屏幕上将会列出所有已存在的Topic名称,其中包括我们刚才创建的my-topic。 4. 查看Topic详情 进一步地,我们可以获取某个Topic的详细信息,包括分区数量、副本分布等。比如查询my-topic的详细信息: bash bin/kafka-topics.sh --describe --bootstrap-server localhost:9092 --topic my-topic 此命令返回的结果将包含每个分区的详细信息,如分区编号、领导者(Leader)、副本集及其状态等。 5. 修改Topic配置 有时我们需要调整Topic的分区数或者副本因子,这时可以使用kafka-topics.sh的--alter选项: bash bin/kafka-topics.sh --alter --bootstrap-server localhost:9092 --topic my-topic --partitions 3 这个命令将会把my-topic的分区数量从原来的2个增加到3个。 6. 删除Topic 若某个Topic不再使用,可通过以下命令将其删除: bash bin/kafka-topics.sh --delete --bootstrap-server localhost:9092 --topic my-topic 但请注意,删除Topic是一个不可逆的操作,一旦删除,该Topic下的所有消息也将一并消失。 总结一下,Kafka提供的命令行工具极大地简化了我们在日常运维中的管理工作。无论是创建、查看、修改还是删除话题,你只需轻松输入几条命令,就像跟朋友聊天一样简单,就能搞定一切!在这个过程中,咱们不仅能实实在在地感受到Kafka那股灵活又顺手的劲儿,更能深深体验到身为开发者或是运维人员,那种对系统玩转于掌心、一切尽在掌握中的爽快与乐趣。当然啦,遇到更复杂的场合,咱们还能使上编程API这个神器,对场景进行更加精细巧妙的管理和操控。这可是我们在未来学习和实践中一个大有可为、值得好好琢磨探索的领域!
2023-11-26 15:04:54
457
青山绿水
MemCache
...新时,需要通过应用层逻辑来保障一致性。常见的一种做法是“先更新数据库,再清除相关缓存”。 python 假设我们有一个更新用户信息的方法 def update_user_info(user_id, new_info): 先更新数据库 db.update_user(user_id, new_info) 清除MemCache中相关的缓存数据 memcached_client.delete(f'user_{user_id}') 另一种策略是引入消息队列,例如使用Redis Pub/Sub或者RabbitMQ等中间件,当数据库发生变更时,发布一条消息通知所有MemCache节点删除对应的缓存项。 4. MemCache节点的维护与监控 为了保证MemCache集群的稳定运行,我们需要定期对各个节点进行健康检查和性能监控,及时发现并处理可能出现的内存溢出、节点失效等问题。可以通过编写运维脚本定期检查,或者接入诸如Prometheus+Grafana这样的监控工具进行可视化管理。 bash 示例:简单的shell脚本检查MemCache节点状态 for node in $(cat memcache_nodes.txt); do echo "Checking ${node}..." telnet $node 11211 <<< stats | grep -q 'STAT bytes 0' if [ $? -eq 0 ]; then echo "${node} is down or not responding." else echo "${node} is up and running." fi done 总的来说,要在分布式环境中有效管理和维护多个MemCache节点,并实现数据的分布式存储与同步更新,不仅需要合理设计数据分布策略,还需要在应用层面对数据一致性进行把控,同时配合完善的节点监控和运维体系,才能确保整个缓存系统的高效稳定运行。在整个探险历程中,咱们得时刻动脑筋、动手尝试、灵活应变、优化咱的计划,这绝对是一个挑战多多、趣味盎然的过程,让人乐在其中。
2023-11-14 17:08:32
69
凌波微步
Kafka
...需求,因此需要将数据复制到多个数据中心进行分布式处理。Kafka这款分布式流处理神器,本身就自带了跨数据中心数据复制的绝活儿。这篇文会手把手教你如何玩转Kafka,通过调整它的那些配置参数,再配上灵活运用Kafka的API接口,就能轻松实现让数据在不同数据中心之间复制、传输,就像变魔术一样简单有趣。 二、Kafka的跨数据中心复制原理 Kafka的跨数据中心复制是基于它的Replication(复制)机制实现的。在Kafka中,每个Topic下的每个Partition都会有一个Leader和多个Follower。Leader负责接收生产者发送的消息,并将消息传递给Follower进行复制。当Leader节点突然撂挑子罢工了,Follower里的小弟们可不会干瞪眼,它们会立马推选出一个新的Leader,这样一来,咱们整个系统的稳定性和可用性就能得到妥妥的保障啦。而跨数据中心复制这回事儿,其实就像是把Leader节点这位“数据大队长”派到其他的数据中心去,这样一来,各个数据中心之间的数据就能手牵手、肩并肩地保持同步啦。 三、如何设置Kafka的跨数据中心复制 1. 设置Zookeeper 在进行跨数据中心复制之前,需要先在Zookeeper中设置好复制组(Cluster)。复制组就像是由一群手拉手的好朋友组成的,这些好朋友其实是一群Kafka集群。每个Kafka集群都是这个大家庭中的一个小分队,它们彼此紧密相连,共同协作。咱们现在得在Zookeeper这家伙里头建一个新的复制小组,然后把所有参与跨数据中心数据同步的Kafka集群小伙伴们都拽进这个小组里去。 2. 配置Kafka服务器 在每个Kafka服务器中,都需要配置复制组相关的参数。其中包括: - bootstrap.servers: 用于指定复制组中各个Kafka服务器的地址。 - group.id: 每个客户端在加入复制组时必须指定的唯一标识符。 - replication.factor: 用于指定每个Partition的副本数量,也就是在一个复制组中,每个Partition应该有多少个副本。 - inter.broker.protocol.version: 用于指定跨数据中心复制时使用的网络协议版本。 四、使用Kafka API进行跨数据中心复制 除了通过配置文件进行跨数据中心复制之外,还可以直接使用Kafka的API进行手动操作。具体步骤如下: 1. 在生产者端,调用send()方法发送消息到Leader节点。 2. Leader节点接收到消息后,将其复制到所有的Follower节点。 3. 在消费者端,从Follower节点获取消息并进行处理。 五、总结 总的来说,通过设置Kafka的复制组参数和使用Kafka的API接口,我们可以轻松地实现在跨数据中心之间的数据复制。而且你知道吗,Kafka有个超赞的Replication机制,这玩意儿就像给数据上了个超级保险,让数据的安全性和稳定性杠杠的。哪怕某个地方突然出了状况,单点故障了,也能妥妥地防止数据丢失,可牛掰了! 六、致谢 感谢阅读这篇关于如何确保Kafka的跨数据中心复制的文章,如果您有任何疑问或建议,请随时与我联系,我将竭诚为您服务!
2023-03-17 20:43:00
531
幽谷听泉-t
ClickHouse
...。 2. 使用Replication(复制)机制 2.1 配置Replicated表 ClickHouse支持ZooKeeper或Raft协议实现的多副本复制功能。例如,创建一个分布式且具有复制特性的表: sql CREATE TABLE replicated_table ( ... ) ENGINE = ReplicatedMergeTree('/clickhouse/tables/{database}/{table}', 'replica1') PARTITION BY ... ORDER BY ... 这里,/clickhouse/tables/{database}/{table}是一个 ZooKeeper 路径,用于协调多个副本之间的数据同步;'replica1'则是当前副本标识符。 2.2 数据自动同步与容灾 一旦某台服务器上的数据出现异常,其他拥有相同Replicated表的服务器仍保留完整的数据。当有新的服务器小弟加入集群大家庭,或者主节点大哥不幸挂掉的时候,Replication机制这个超级替补队员就会立马出动,自动把数据同步得妥妥的,确保所有数据都能保持一致性、完整性,一个字都不会少。 3. 数据一致性检查与修复 3.1 使用checksum函数 ClickHouse提供checksum函数来计算表数据的校验和,可用于验证数据是否完整: sql SELECT checksum() FROM table_name; 定期执行此操作并记录结果,以便在后续时间点对比校验和的变化,从而发现可能的数据丢失问题。 3.2 表维护及修复 若发现数据不一致,可以尝试使用OPTIMIZE TABLE命令进行表维护和修复: sql OPTIMIZE TABLE table_name FINAL; 该命令会重新整理表数据,并尝试修复任何可能存在的数据损坏问题。 4. 实践思考与探讨 尽管我们可以通过上述方法来减少和应对ClickHouse中的数据丢失风险,但防患于未然总是最优策略。在搭建和运用ClickHouse系统的时候,千万记得要考虑让它“坚如磐石”,也就是要设计出高可用性方案。比如说,我们可以采用多副本这种方式,就像备份多个小帮手一样,让数据安全无忧;再者,跨地域冗余存储也是一招妙计,想象一下,即使地球另一边的机房挂了,这边的数据也能照常运作,这样就大大提升了系统的稳健性和可靠性啦!同时,建立一个完善、接地气的数据监控系统,能够灵敏捕捉并及时解决那些可能冒头的小问题,这绝对是一个无比关键的步骤。 总结起来,面对ClickHouse数据丢失问题,我们需采取主动防御和被动恢复相结合的方式,既要做好日常的数据备份和Replication配置,也要学会在问题发生后如何快速有效地恢复数据,同时结合数据一致性检查以及表维护等手段,全面提升数据的安全性和稳定性。在实践中不断优化和完善,才能真正发挥出ClickHouse在海量数据分析领域的强大威力。
2023-01-20 13:30:03
445
月影清风
Kafka
...文件中的相关设置。 Replication Factor , 在Kafka中,复制因子是指每个主题分区的副本数量。它决定了消息在集群中被复制的次数,从而影响了数据的冗余度和容错能力。例如,如果一个主题的复制因子设置为3,则该主题的每个分区都会在不同broker上保存3个副本。在文章中提到的场景中,由于尝试创建的主题设置了与实际集群规模不符的复制因子,引发了UnknownReplicaAssignmentException异常。解决方法是将复制因子调整为与当前Kafka集群规模相匹配的值,确保所有指定的副本都能成功分配到存在的broker上。
2023-02-04 14:29:39
435
寂静森林
Apache Solr
...ache Solr的复制(Replication)出现问题 1. 引言 嘿,大家好!今天我要跟大家聊聊Apache Solr中一个让人头疼的问题——复制(Replication)。这玩意儿在Solr里头可重要了,是保证数据高可用性和一致性的关键。但有时候它也会闹脾气,搞得我们焦头烂额。我呢,也是在最近的一次项目中碰上了这个难题。本来以为复制配置很简单,结果发现坑还挺多的。今天我想跟大家分享一下我遇到的问题和我是怎么解决的,希望对大家有点帮助。 2. 复制的基本概念 首先,咱们得知道复制是什么。简单说,就是把一个Solr服务器上的索引文件拷贝到另一个Solr服务器上,就跟把文件从这个文件夹拖到另一个文件夹那样。这样做有几个好处: - 高可用性:即使某个Solr实例宕机,其他实例仍然可以提供服务。 - 负载均衡:多个副本可以分担查询压力,提高整体性能。 - 数据备份:万一主节点数据丢失,副本可以迅速恢复。 但是,如果复制过程中出现问题,就可能导致数据不一致、服务中断等问题。我碰上的是这么个情况,开始还以为是设置不对,结果捣鼓半天才发现原来是网络的事儿。 3. 常见的复制问题 在实际操作中,我遇到了几个常见的问题,包括但不限于: - 网络延迟或断开:这是最常见的问题之一,特别是在跨数据中心的情况下。 - 配置错误:比如主从节点之间的URL配置错误,或者版本不匹配。 - 磁盘空间不足:复制需要大量的磁盘空间,如果空间不足会导致复制失败。 - 权限问题:某些情况下,权限设置不当也会导致复制失败。 4. 解决方案 针对这些问题,我整理了一些解决方案,希望能帮助大家避免类似的麻烦。 4.1 网络问题 先说说网络问题吧,这可能是最头疼的一个。我碰到的问题是主节点和从节点之间的网络有时候会断开,结果复制任务就卡住了,甚至直接失败。解决方法如下: 1. 检查网络连接 确保主节点和从节点之间网络稳定,可以通过ping命令来测试。 2. 增加重试机制 可以在Solr配置文件中设置重试次数,比如: xml 00:00:30 true 5 60 4.2 配置错误 配置错误也很常见,尤其是对于新手来说。有个小窍门,在配置文件里多加点注释,这样就能大大降低出错的几率啦!比如: xml commit schema.xml,stopwords.txt http://localhost:8983/solr/collection1/replication http://localhost:8983/solr/collection1/replication 00:00:30 4.3 磁盘空间问题 磁盘空间不足也是常见的问题,尤其是在大规模数据量的情况下。解决方法是定期清理旧的索引文件,或者增加磁盘容量。Solr提供了清理旧索引的API,可以定时调用: bash curl http://localhost:8983/solr/collection1/admin/cores?action=UNLOAD&core=collection1&deleteIndex=true&deleteDataDir=true 4.4 权限问题 权限问题通常是因为用户没有足够的权限访问Solr API。解决方法是给相关用户分配正确的角色和权限。例如,在Solr的配置文件中设置用户权限: xml etc/security.json true 然后在security.json文件中添加用户的权限信息: json { "authentication": { "class": "solr.BasicAuthPlugin", "credentials": { "admin": "hashed_password" } }, "authorization": { "class": "solr.RuleBasedAuthorizationPlugin", "permissions": [ { "name": "access-replication-handler", "role": "admin" } ], "user-role": { "admin": ["admin"] } } } 5. 总结 通过上面的分享,希望大家都能够更好地理解和处理Apache Solr中的复制问题。复制虽然重要,但也确实容易出错。但只要我们细心排查,合理配置,还是可以解决这些问题的。如果你也有类似的经历或者更好的解决方案,欢迎在评论区留言交流! 最后,我想说的是,技术这条路真的是越走越远,每一个问题都是一次成长的机会。希望大家都能在技术之路上越走越远,越走越稳!
2025-03-11 15:48:41
91
星辰大海
转载文章
...级Await表达式、Logical Assignment Operators等,并进一步优化了@babel/preset-env预设的行为,允许开发者更精细地控制转换目标与兼容范围。同时,为了更好地配合现代模块打包工具,例如Webpack 5和Rollup,Babel开始加强对Tree Shaking的支持,使得代码体积得到更有效的压缩。 此外,Babel社区也积极推动生态建设,不断涌现出新的插件以支持最新的提案或特定场景需求,如@babel/plugin-proposal-logical-assignment-operators处理逻辑赋值运算符,以及@babel/plugin-syntax-top-level-await实现顶层await操作的支持。 值得关注的是,针对遗留项目和渐进式升级的需求,Babel官方文档提供了详尽的迁移指南和常见问题解答,帮助开发者从Babel 6平滑过渡至Babel 7,确保项目的稳定性和兼容性。 综上所述,无论是在跟进最新标准还是优化项目构建流程方面,Babel都在与时俱进并保持活跃发展。对于广大前端开发者而言,深入理解和熟练运用Babel的各项配置与最佳实践,无疑将极大地提升开发效率和代码质量。建议密切关注Babel的官方博客和技术论坛,及时掌握最新动态和技术趋势,以应对日新月异的前端开发挑战。
2024-01-16 22:15:54
121
转载
Spark
...st:9092 --replication-factor 1 --partitions 1 4.2 发送数据到Kafka 接下来,我们可以编写一个简单的脚本来向Kafka的主题中发送一些数据。这里我们使用Python的kafka-python库来实现。 python from kafka import KafkaProducer producer = KafkaProducer(bootstrap_servers='localhost:9092') for _ in range(10): message = "Hello, Kafka!".encode('utf-8') producer.send('test-topic', value=message) print("Message sent:", message.decode('utf-8')) producer.flush() producer.close() 4.3 使用Spark读取Kafka数据 现在,我们来编写一个Spark程序,用于读取刚才发送到Kafka中的数据。这里我们使用Spark的Structured Streaming API。 scala import org.apache.spark.sql.SparkSession val spark = SparkSession.builder.appName("SparkKafkaIntegration").getOrCreate() val df = spark.readStream .format("kafka") .option("kafka.bootstrap.servers", "localhost:9092") .option("subscribe", "test-topic") .load() val query = df.selectExpr("CAST(value AS STRING)") .writeStream .outputMode("append") .format("console") .start() query.awaitTermination() 这段代码会启动一个Spark应用程序,从Kafka的主题中读取数据,并将其打印到控制台。 4.4 实时处理 接下来,我们可以在Spark中对数据进行实时处理。例如,我们可以统计每秒钟接收到的消息数量。 scala import org.apache.spark.sql.functions._ val countDF = df.selectExpr("CAST(value AS STRING)") .withWatermark("timestamp", "1 minute") .groupBy( window($"timestamp", "1 minute"), $"value" ).count() val query = countDF.writeStream .outputMode("complete") .format("console") .start() query.awaitTermination() 这段代码会在每分钟的时间窗口内统计消息的数量,并将其输出到控制台。 5. 总结与反思 通过这次实战,我们成功地将Spark与Kafka进行了集成,并实现了数据的实时处理。虽然过程中遇到了一些挑战,但最终还是顺利完成了任务。这个经历让我明白,书本上的知识和实际动手做真是两码事。不一次次去试,根本没法真正搞懂怎么用这门技术。希望这次分享对你有所帮助,也期待你在实践中也能有所收获! 如果你有任何问题或想法,欢迎随时交流讨论。
2025-03-08 16:21:01
76
笑傲江湖
Hadoop
...op支持文件的跨硬件复制 1. 初识Hadoop 为什么我们需要它? 大家好!今天我们要聊聊一个超级酷的东西——Hadoop。作为一个程序员或者数据工程师,你可能已经听说过这个名字。Hadoop是一种开源的大数据处理框架,它的核心功能是存储和处理海量的数据。不过,我今天想带大家深入探讨的是Hadoop的一个非常实用的功能:跨硬件复制文件。 为什么这个功能这么重要呢?想象一下,如果你正在运行一个大型的分布式系统,突然某个节点挂了怎么办?数据丢了?那可太惨了!Hadoop通过分布式文件系统(HDFS)来解决这个问题。HDFS 可不只是简单地把大文件切成小块儿,它还特聪明,会把这些小块儿分散存到不同的机器上。这就跟把鸡蛋放在好几个篮子里一个道理,哪怕有一台机器突然“罢工”了(也就是挂掉了),你的数据还是稳稳的,一点都不会丢。 那么,Hadoop是如何做到这一点的呢?咱们先来看看它是怎么工作的。 --- 2. HDFS的工作原理 数据块与副本 HDFS是一个分布式的文件系统,它的设计理念就是让数据更加可靠。简单讲啊,HDFS会把一个大文件切成好多小块儿(每块默认有128MB这么大),接着把这些小块分开放到集群里的不同电脑上存着。更关键的是,HDFS会为每个数据块多弄几个备份,一般是三个副本。这就相当于给你的数据买了“多重保险”,哪怕有一台机器突然“罢工”或者出问题了,你的数据还是妥妥地躺在别的机器上,一点都不会丢。 举个例子,假设你有一个1GB的文件,HDFS会把这个文件分成8个128MB的小块,并且每个小块会被复制成3份,分别存储在不同的服务器上。这就意味着啊,就算有一台服务器“挂了”或者出问题了,另外两台服务器还能顶上,数据照样能拿得到,完全不受影响。 说到这里,你可能会问:“为什么要复制这么多份?会不会浪费空间?”确实,多副本策略会占用更多的磁盘空间,但它的优点远远超过这一点。先说白了就是,它能让数据更好用、更靠谱啊!再说了,在那种超大的服务器集群里头,这样的备份机制还能帮着分散压力,不让某一个地方出问题就整个崩掉。 --- 3. 实战演示 如何使用Hadoop进行跨硬件复制? 接下来,让我们动手试试看!我会通过一些实际的例子来展示Hadoop是如何完成文件跨硬件复制的。 3.1 安装与配置Hadoop 首先,你需要确保自己的环境已经安装好了Hadoop。如果你还没有安装,可以参考官方文档一步步来配置。对新手来说,建议先试试伪分布式模式,相当于在一台电脑上“假装”有一个完整的集群,方便你熟悉环境又不用折腾多台机器。 3.2 创建一个简单的文本文件 我们先创建一个简单的文本文件,用来测试Hadoop的功能。你可以使用以下命令: bash echo "Hello, Hadoop!" > test.txt 然后,我们将这个文件上传到HDFS中: bash hadoop fs -put test.txt /user/hadoop/ 这里的/user/hadoop/是HDFS上的一个目录路径。 3.3 查看文件的副本分布 上传完成后,我们可以检查一下这个文件的副本分布情况。使用以下命令: bash hadoop fsck /user/hadoop/test.txt -files -blocks -locations 这段命令会输出类似如下的结果: /user/hadoop/test.txt 128 bytes, 1 block(s): OK 0. BP-123456789-192.168.1.1:50010 file:/path/to/local/file 1. BP-123456789-192.168.1.2:50010 file:/path/to/local/file 2. BP-123456789-192.168.1.3:50010 file:/path/to/local/file 从这里可以看到,我们的文件已经被复制到了三台不同的服务器上。 --- 4. 深度解读 Hadoop的副本策略 在前面的步骤中,我们已经看到了Hadoop是如何将文件复制到不同节点上的。但是,你知道吗?Hadoop的副本策略其实是非常灵活的。它可以根据网络拓扑结构来决定副本的位置。 例如,默认情况下,第一个副本会放在与客户端最近的节点上,第二个副本会放在另一个机架上,而第三个副本则会放在同一个机架的不同节点上。这样的策略可以最大限度地减少网络延迟,提高读取效率。 当然,如果你对默认的副本策略不满意,也可以自己定制。比如,如果你想让所有副本都放在同一个机架内,可以通过修改dfs.replication.policy参数来实现。 --- 5. 总结与展望 通过今天的讨论,我们了解了Hadoop是如何通过HDFS实现文件的跨硬件复制的。虽然这个功能看似简单,但它背后蕴含着复杂的设计理念和技术细节。正是这些设计,才使得Hadoop成为了一个强大的大数据处理工具。 最后,我想说的是,学习新技术的过程就像探险一样,充满了未知和挑战。嘿,谁还没遇到过点麻烦事儿呢?有时候一头雾水,感觉前路茫茫,但这不正是探索的开始嘛!别急着放弃,熬过去你会发现,那些让人头疼的问题其实藏着不少小惊喜,等你拨开云雾时,成就感绝对让你觉得值了!希望这篇文章能给你带来一些启发,也希望你能亲自尝试一下Hadoop的实际操作,感受一下它的魅力! 好了,今天的分享就到这里啦!如果你有任何疑问或者想法,欢迎随时留言交流。让我们一起探索更多有趣的技术吧!
2025-03-26 16:15:40
97
冬日暖阳
Hadoop
...调整那个叫dfs.replication的参数! xml dfs.replication 3 3. 磁盘I/O瓶颈 磁盘读写速度是影响HDFS性能的一个重要因素。要是你的服务器用的是那些老掉牙的机械硬盘,那读文件的速度肯定就慢得像乌龟爬了。 实验验证: 为了测试磁盘I/O的影响,可以尝试将一部分数据迁移到SSD上进行对比实验。好啦,想象一下,你手头有一堆日志文件要对付。先把它们丢到普通的老硬盘(HDD)里待着,然后又挪到固态硬盘(SSD)上,看看读取速度变了多少。是不是感觉像在玩拼图游戏,只不过这次是在折腾文件呢? 三、进阶优化技巧 经过前面的分析,我们可以得出结论:要提高HDFS的读取速度,不仅仅需要关注硬件层面的问题,还需要从软件配置上下功夫。以下是一些更高级别的优化建议: 1. 增加带宽 带宽就像是高速公路的车道数量,车道越多,车辆通行就越顺畅。对于HDFS来说,增加带宽意味着可以同时传输更多的数据块。 实际操作: 联系你的网络管理员,询问是否有可能升级现有的网络基础设施,比如更换更快的交换机或者部署新的光纤线路。 2. 调整副本策略 默认情况下,HDFS会将每个文件的三个副本均匀分布在整个集群中。然而,在某些特殊场景下,这种做法并不一定是最优解。比如说,你家APP平时就爱扎堆在那几个服务器节点上干活儿,那就可以把副本都放一块儿,这样它们串门聊天、传文件啥的就方便多了,也不用跑太远浪费时间啦! 配置修改: xml dfs.block.local-path-access.enabled true 3. 使用缓存机制 缓存就像冰箱里的剩饭,拿出来就能直接吃,不用重新加热。HDFS也有类似的机制,叫做“DataNode Cache”。打开这个功能之后啊,那些经常用到的数据就会被暂时存到内存里,这样下次再用的时候就嗖的一下快多了! 启用步骤: bash hadoop dfsadmin -setSpaceQuota 100g /cachedir hadoop dfs -cache /inputfile /cachedir 四、总结与展望 通过今天的讨论,我相信大家都对HDFS读取速度慢的原因有了更深的理解。其实,无论是网络延迟、数据本地性还是磁盘I/O瓶颈,都不是不可克服的障碍。其实吧,只要咱们肯花点心思去琢磨、去试试,肯定能找出个适合自己情况的办法。 最后,我想说的是,作为一名技术人员,我们应该始终保持好奇心和探索精神。不要害怕失败,也不要急于求成,因为每一次挫折都是一次成长的机会。希望这篇文章能给大家带来启发,让我们一起努力,让Hadoop变得更加高效可靠吧! --- 以上就是我对“HDFS读取速度慢”的全部看法和建议。如果你还有其他想法或者遇到类似的问题,请随时留言交流。咱们共同进步,一起探索大数据世界的奥秘!
2025-05-04 16:24:39
102
月影清风
转载文章
...data 10.3 复制默认数据存放文件夹到/data/mysql_data cp -a /var/lib/mysql /data/mysql_data 10.4 修改/etc/my.cnf.d/server.cnf vim /etc/my.cnf.d/server.cnf 在[mysqld]标签下添加如下内容 datadir=/data/mysql_data/mysqlsocket=/var/lib/mysql/mysql.sockdefault-character-set=utf8character_set_server=utf8slow_query_log=onslow_query_log_file=/data/mysql_data/slow_query_log.loglong_query_time=2 10.5 配置MariaDB慢查询 touch /data/mysql_data/slow_query_log.logchown mysql:mysql /data/mysql_data/slow_query_log.log 10.6 重启数据库 systemctl start mariadb 10.7 注意: 1、配置文件my.cnf存在,但是修改的并不是my.cnf,而是/etc/my.cnf.d/server.cnf; 2、并没有更改mysql.sock的路径配置; 3、没有修改/etc/init.d/mysql中的内容; 4、没有修改mysql_safe中的内容; 5、增加了数据库的慢查询配置。 11. Mariadb主从复制 11.1 主从库初始化 这条命令可以初始化mysql,删除匿名用户,设置root密码等等....mysql_secure_installation1.输入当前密码,初次安装后是没有密码的,直接回车2.询问是否使用 'unix_socket' 进行身份验证: n3.为 root 设置密码:y4.输入 root 的新密码: root5.确认输入 root 的新密码: root6.是否移除匿名用户,这个随意,建议删除: y7.拒绝用户远程登录,这个建议开启:n8.删除 test 库,可以保留:n9.重新加载权限表:y 11.2 修改主库配置 [root@mster mysql] grep -Ev "^$|^" /etc/my.cnf.d/server.cnf[server][mysqld]character-set-server=utf8collation-server=utf8_general_ciserver_id = 13 一组主从组里的每个id必须是唯一值。推荐用ip位数log-bin= mysql-bin 二进制日志,后面指定存放位置。如果只是指定名字,默认存放在/var/lib/mysql下lower_case_table_names=1 不区分大小写binlog-format=ROW 二进制日志文件格式log-slave-updates=True slave更新是否记入日志sync-master-info=1 值为1确保信息不会丢失slave-parallel-threads=3 同时启动多少个复制线程,最多与要复制的数据库数量相等即可binlog-checksum=CRC32 效验码master-verify-checksum=1 启动主服务器效验slave-sql-verify-checksum=1 启动从服务器效验[galera][embedded][mariadb][mariadb-10.6][root@mster-k8s mysql] 11.2 修改从库配置 [mysqld]character-set-server=utf8collation-server=utf8_general_ciserver_id=14log-bin= mysql-bin log-bin是二进制文件relay_log = relay-bin 中继日志, 后面指定存放位置。如果只是指定名字,默认存放在/var/lib/mysql下lower_case_table_names=1 11.3 重启主库和从库服务 systemctl restart mariad 11.4 master节点配置 MariaDB [huawei]> grant replication slave, replication client on . to 'liu'@'%' identified by '123456';Query OK, 0 rows affected (0.001 sec)MariaDB [huawei]> show master status;+------------------+----------+--------------+------------------+| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |+------------------+----------+--------------+------------------+| mysql-bin.000001 | 4990 | | |+------------------+----------+--------------+------------------+1 row in set (0.000 sec)MariaDB [huawei]> select binlog_gtid_pos('mysql-bin.000001', 4990 );+-------------------------------------------+| binlog_gtid_pos('mysql-bin.000001', 4990) |+-------------------------------------------+| 0-13-80 |+-------------------------------------------+1 row in set (0.000 sec)MariaDB [huawei]> flush privileges; 11.5 slave节点配置 MariaDB [(none)]> set global gtid_slave_pos='0-13-80';Query OK, 0 rows affected (0.004 sec)MariaDB [(none)]> change master to master_host='101.34.141.216',master_user='liu',master_password='123456',master_use_gtid=slave_pos;Query OK, 0 rows affected (0.008 sec)MariaDB [(none)]> start slave;Query OK, 0 rows affected (0.005 sec)MariaDB [(none)]> 11.6 验证salve状态 MariaDB [(none)]> show slave status\G 1. row Slave_IO_State: Waiting for master to send eventMaster_Host: 101.34.141.216Master_User: liuMaster_Port: 3306Connect_Retry: 60Master_Log_File: mysql-bin.000001Read_Master_Log_Pos: 13260Relay_Log_File: relay-bin.000002Relay_Log_Pos: 10246Relay_Master_Log_File: mysql-bin.000001Slave_IO_Running: YesSlave_SQL_Running: YesReplicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0Last_Error: Skip_Counter: 0Exec_Master_Log_Pos: 13260Relay_Log_Space: 10549Until_Condition: NoneUntil_Log_File: Until_Log_Pos: 0Master_SSL_Allowed: NoMaster_SSL_CA_File: 本篇文章为转载内容。原文链接:https://blog.csdn.net/l363130002/article/details/126121255。 该文由互联网用户投稿提供,文中观点代表作者本人意见,并不代表本站的立场。 作为信息平台,本站仅提供文章转载服务,并不拥有其所有权,也不对文章内容的真实性、准确性和合法性承担责任。 如发现本文存在侵权、违法、违规或事实不符的情况,请及时联系我们,我们将第一时间进行核实并删除相应内容。
2023-07-12 10:11:01
310
转载
Kafka
...st:2181 --replication-factor 1 --partitions 3 --topic user_events 这里的关键点在于,主题的名字要尽量简单明了,避免使用特殊字符或者空格。哎呀,这就好比你给文件夹起个特别绕口的名字,结果自己都记不住路径了,Kafka也是一样!它会根据主题的名字创建对应的文件夹结构,但要是主题名太复杂,搞不好就会在找东西的时候迷路,路径解析起来就容易出岔子啦。而且啊,主题的名字最好起得通俗易懂一点,让大伙儿一眼扫过去就明白这是干啥用的。 2.2 分区(Partition):主题的分身术 接着说分区(Partition)。每个主题都可以被划分为多个分区,每个分区就是一个日志文件。分区的作用是什么呢?它可以提高并发性和扩展性。比如说,你有个主题叫orders(订单),你可以把它分成5个区(分区)。这样一来,不同的小伙伴就能一起开工,各自处理这些区里的数据啦! java // 查看主题的分区信息 kafka-topics.sh --describe --zookeeper localhost:2181 --topic orders 分区的数量决定了并发的上限。所以,在设计主题时,你需要仔细权衡分区数量。太多的话,管理起来麻烦;太少的话,可能无法充分利用资源。我一般会根据预计的消息量来决定分区的数量。比如说,如果一秒能收到几千条消息,那分区设成10到20个就挺合适的。毕竟分区太多太少了都不好,得根据实际情况来调,不然可能会卡壳或者资源浪费啊! 2.3 消费者组(Consumer Group):团队协作的秘密武器 最后,我们来说消费者组(Consumer Group)。消费者组是一组消费者的集合,它们共同消费同一个主题的消息。每个消费者组都有一个唯一的名称,这个名字同样非常重要。 java // 创建一个消费者组 kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic user_events --group my_consumer_group 消费者组的设计理念是为了实现负载均衡和故障恢复。比如说,如果有两个小伙伴在一个小组里,系统就会帮他们自动分配任务(也就是主题的分区),这样大家就不会抢来抢去,重复干同样的活儿啦!而且呢,要是有个消费者挂掉了或者出问题了,其他的消费者就会顶上来,接手它负责的那些分区,接着干活儿,完全不受影响。 --- 3. 组织结构 Kafka的大脑与四肢 3.1 集群(Cluster):Kafka的心脏 Kafka集群是由多个Broker组成的,Broker是Kafka的核心组件,负责存储和转发消息。一个Broker就是一个节点,多个Broker协同工作,形成一个分布式的系统。 java // 启动Kafka Broker nohup kafka-server-start.sh config/server.properties & Broker的数量决定了系统的容错能力和性能。其实啊,通常咱们都会建议弄三个Broker,为啥呢?就怕万一有个家伙“罢工”了,比如突然挂掉或者出问题,别的还能顶上,整个系统就不耽误干活啦!不过,Broker的数量也不能太多,否则会增加管理和维护的成本。 3.2 Zookeeper:Kafka的大脑 Zookeeper是Kafka的协调器,它负责管理集群的状态和配置。没有Zookeeper,Kafka就无法正常运作。比如说啊,新添了个Broker(也就是那个消息中转站),Zookeeper就会赶紧告诉其他Broker:“嘿,快看看这位新伙伴,更新一下你们的状态吧!”还有呢,要是某个分区的老大换了(Leader切换了),Zookeeper也会在一旁默默记好这笔账,生怕漏掉啥重要信息似的。 java // 启动Zookeeper nohup zookeeper-server-start.sh config/zookeeper.properties & 虽然Zookeeper很重要,但它也有一定的局限性。比如,它可能会成为单点故障,影响整个系统的稳定性。因此,近年来Kafka也在尝试去掉对Zookeeper的依赖,开发了自己的内部协调机制。 3.3 日志(Log):Kafka的四肢 日志是Kafka存储消息的地方,每个分区对应一个日志文件。嘿,这个日志设计可太聪明了!它用的是顺序写入的方法,就像一条直线往前跑,根本不用左顾右盼,写起来那叫一个快,效率直接拉满! java // 查看日志路径 cat config/server.properties | grep log.dirs 日志的大小可以通过参数log.segment.bytes来控制。默认值是1GB,你可以根据实际情况调整。要是日志文件太大了,查个东西就像在大海捞针一样慢吞吞的;但要是弄得太小吧,又老得换新的日志文件,麻烦得很,还费劲。 --- 4. 实战演练 从零搭建一个Kafka环境 说了这么多理论,咱们来实际操作一下吧!假设我们要搭建一个简单的Kafka环境,用来收集用户的登录日志。 4.1 安装Kafka和Zookeeper 首先,我们需要安装Kafka和Zookeeper。可以从官网下载最新的二进制包,解压后按照文档配置即可。 bash 下载Kafka wget https://downloads.apache.org/kafka/3.4.0/kafka_2.13-3.4.0.tgz 解压 tar -xzf kafka_2.13-3.4.0.tgz 4.2 创建主题和消费者 接下来,我们创建一个名为login_logs的主题,并启动一个消费者来监听消息。 bash 创建主题 bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 3 --topic login_logs 启动消费者 bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic login_logs --from-beginning 4.3 生产消息 最后,我们可以编写一个简单的Java程序来生产消息。 java import org.apache.kafka.clients.producer.KafkaProducer; import org.apache.kafka.clients.producer.ProducerRecord; import java.util.Properties; public class KafkaProducerExample { public static void main(String[] args) { Properties props = new Properties(); props.put("bootstrap.servers", "localhost:9092"); props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer"); props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer"); KafkaProducer producer = new KafkaProducer<>(props); for (int i = 0; i < 10; i++) { producer.send(new ProducerRecord<>("login_logs", "key" + i, "value" + i)); } producer.close(); } } 这段代码会向login_logs主题发送10条消息,每条消息都有一个唯一的键和值。 --- 5. 总结 Kafka的魅力在于细节 好了,到这里咱们的Kafka之旅就告一段落了。通过这篇文章,我希望大家能更好地理解Kafka的命名规范和组织结构。Kafka为啥这么牛?因为它在设计的时候真是把每个小细节都琢磨得特别透。就像给主题起名字吧,分个区啦,还有消费者组怎么配合干活儿,这些地方都能看出人家确实是下了一番功夫的,真不是随便凑合出来的! 当然,Kafka的学习之路还有很多内容需要探索,比如监控、调优、安全等等。其实我觉得啊,只要你把命名的规矩弄明白了,东西该怎么放也心里有数了,那你就算是走上正轨啦,成功嘛,它就已经在向你招手啦!加油吧,朋友们! --- 希望这篇文章对你有所帮助,如果有任何疑问,欢迎随时交流哦!
2025-04-05 15:38:52
95
彩虹之上
转载文章
...数据节点之间,也可以复制到所有数据节点。数据节点没有整个数据库的全局视图,它只负责本地存储的数据。接下来,协调器将检查传入语句,并制定子计划。然后,根据需要将这些数据连同GXID和全局快照一起传输到涉及的每个数据节点。数据节点可以在不同的会话中接收来自各个协调器的请求。但是,由于每个事务都是惟一标识的,并且与一致的(全局)快照相关联,所以每个数据节点都可以在其事务和快照上下文中正确执行。 Postgres-XL继承了PostgreSQL Postgres-XL是PostgreSQL的扩展并继承了其很多特性: 复杂查询 外键 触发器 视图 事务 MVCC(多版本控制) 此外,类似于PostgreSQL,用户可以通过多种方式扩展Postgres-XL,例如添加新的 数据类型 函数 操作 聚合函数 索引类型 过程语言 安装 环境说明 由于资源有限,gtm一台、另外两台身兼数职。 主机名 IP 角色 端口 nodename 数据目录 gtm 192.168.20.132 GTM 6666 gtm /nodes/gtm 协调器 5432 coord1 /nodes/coordinator xl1 192.168.20.133 数据节点 5433 node1 /nodes/pgdata gtm代理 6666 gtmpoxy01 /nodes/gtm_pxy1 协调器 5432 coord2 /nodes/coordinator xl2 192.168.20.134 数据节点 5433 node2 /nodes/pgdata gtm代理 6666 gtmpoxy02 /nodes/gtm_pxy2 要求 GNU make版本 3.8及以上版本 [root@pg ~] make --versionGNU Make 3.82Built for x86_64-redhat-linux-gnuCopyright (C) 2010 Free Software Foundation, Inc.License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>This is free software: you are free to change and redistribute it.There is NO WARRANTY, to the extent permitted by law. 需安装GCC包 需安装tar包 用于解压缩文件 默认需要GNU Readline library 其作用是可以让psql命令行记住执行过的命令,并且可以通过键盘上下键切换命令。但是可以通过--without-readline禁用这个特性,或者可以指定--withlibedit-preferred选项来使用libedit 默认使用zlib压缩库 可通过--without-zlib选项来禁用 配置hosts 所有主机上都配置 [root@xl2 11] cat /etc/hosts127.0.0.1 localhost192.168.20.132 gtm192.168.20.133 xl1192.168.20.134 xl2 关闭防火墙、Selinux 所有主机都执行 关闭防火墙: [root@gtm ~] systemctl stop firewalld.service[root@gtm ~] systemctl disable firewalld.service selinux设置: [root@gtm ~]vim /etc/selinux/config 设置SELINUX=disabled,保存退出。 This file controls the state of SELinux on the system. SELINUX= can take one of these three values: enforcing - SELinux security policy is enforced. permissive - SELinux prints warnings instead of enforcing. disabled - No SELinux policy is loaded.SELINUX=disabled SELINUXTYPE= can take one of three two values: targeted - Targeted processes are protected, minimum - Modification of targeted policy. Only selected processes are protected. mls - Multi Level Security protection. 安装依赖包 所有主机上都执行 yum install -y flex bison readline-devel zlib-devel openjade docbook-style-dsssl gcc 创建用户 所有主机上都执行 [root@gtm ~] useradd postgres[root@gtm ~] passwd postgres[root@gtm ~] su - postgres[root@gtm ~] mkdir ~/.ssh[root@gtm ~] chmod 700 ~/.ssh 配置SSH免密登录 仅仅在gtm节点配置如下操作: [root@gtm ~] su - postgres[postgres@gtm ~] ssh-keygen -t rsa[postgres@gtm ~] cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys[postgres@gtm ~] chmod 600 ~/.ssh/authorized_keys 将刚生成的认证文件拷贝到xl1到xl2中,使得gtm节点可以免密码登录xl1~xl2的任意一个节点: [postgres@gtm ~] scp ~/.ssh/authorized_keys postgres@xl1:~/.ssh/[postgres@gtm ~] scp ~/.ssh/authorized_keys postgres@xl2:~/.ssh/ 对所有提示都不要输入,直接enter下一步。直到最后,因为第一次要求输入目标机器的用户密码,输入即可。 下载源码 下载地址:https://www.postgres-xl.org/download/ [root@slave ~] ll postgres-xl-10r1.1.tar.gz-rw-r--r-- 1 root root 28121666 May 30 05:21 postgres-xl-10r1.1.tar.gz 编译、安装Postgres-XL 所有节点都安装,编译需要一点时间,最好同时进行编译。 [root@slave ~] tar xvf postgres-xl-10r1.1.tar.gz[root@slave ~] ./configure --prefix=/home/postgres/pgxl/[root@slave ~] make[root@slave ~] make install[root@slave ~] cd contrib/ --安装必要的工具,在gtm节点上安装即可[root@slave ~] make[root@slave ~] make install 配置环境变量 所有节点都要配置 进入postgres用户,修改其环境变量,开始编辑 [root@gtm ~]su - postgres[postgres@gtm ~]vi .bashrc --不是.bash_profile 在打开的文件末尾,新增如下变量配置: export PGHOME=/home/postgres/pgxlexport LD_LIBRARY_PATH=$PGHOME/lib:$LD_LIBRARY_PATHexport PATH=$PGHOME/bin:$PATH 按住esc,然后输入:wq!保存退出。输入以下命令对更改重启生效。 [postgres@gtm ~] source .bashrc --不是.bash_profile 输入以下语句,如果输出变量结果,代表生效 [postgres@gtm ~] echo $PGHOME 应该输出/home/postgres/pgxl代表生效 配置集群 生成pgxc_ctl.conf配置文件 [postgres@gtm ~] pgxc_ctl prepare/bin/bashInstalling pgxc_ctl_bash script as /home/postgres/pgxl/pgxc_ctl/pgxc_ctl_bash.ERROR: File "/home/postgres/pgxl/pgxc_ctl/pgxc_ctl.conf" not found or not a regular file. No such file or directoryInstalling pgxc_ctl_bash script as /home/postgres/pgxl/pgxc_ctl/pgxc_ctl_bash.Reading configuration using /home/postgres/pgxl/pgxc_ctl/pgxc_ctl_bash --home /home/postgres/pgxl/pgxc_ctl --configuration /home/postgres/pgxl/pgxc_ctl/pgxc_ctl.confFinished reading configuration. PGXC_CTL START Current directory: /home/postgres/pgxl/pgxc_ctl 配置pgxc_ctl.conf 新建/home/postgres/pgxc_ctl/pgxc_ctl.conf文件,编辑如下: 对着模板文件一个一个修改,否则会造成初始化过程出现各种神奇问题。 pgxcInstallDir=$PGHOMEpgxlDATA=$PGHOME/data pgxcOwner=postgres---- GTM Master -----------------------------------------gtmName=gtmgtmMasterServer=gtmgtmMasterPort=6666gtmMasterDir=$pgxlDATA/nodes/gtmgtmSlave=y Specify y if you configure GTM Slave. Otherwise, GTM slave will not be configured and all the following variables will be reset.gtmSlaveName=gtmSlavegtmSlaveServer=gtm value none means GTM slave is not available. Give none if you don't configure GTM Slave.gtmSlavePort=20001 Not used if you don't configure GTM slave.gtmSlaveDir=$pgxlDATA/nodes/gtmSlave Not used if you don't configure GTM slave.---- GTM-Proxy Master -------gtmProxyDir=$pgxlDATA/nodes/gtm_proxygtmProxy=y gtmProxyNames=(gtm_pxy1 gtm_pxy2) gtmProxyServers=(xl1 xl2) gtmProxyPorts=(6666 6666) gtmProxyDirs=($gtmProxyDir $gtmProxyDir) ---- Coordinators ---------coordMasterDir=$pgxlDATA/nodes/coordcoordNames=(coord1 coord2) coordPorts=(5432 5432) poolerPorts=(6667 6667) coordPgHbaEntries=(0.0.0.0/0)coordMasterServers=(xl1 xl2) coordMasterDirs=($coordMasterDir $coordMasterDir)coordMaxWALsernder=0 没设置备份节点,设置为0coordMaxWALSenders=($coordMaxWALsernder $coordMaxWALsernder) 数量保持和coordMasterServers一致coordSlave=n---- Datanodes ----------datanodeMasterDir=$pgxlDATA/nodes/dn_masterprimaryDatanode=xl1 主数据节点datanodeNames=(node1 node2)datanodePorts=(5433 5433) datanodePoolerPorts=(6668 6668) datanodePgHbaEntries=(0.0.0.0/0)datanodeMasterServers=(xl1 xl2)datanodeMasterDirs=($datanodeMasterDir $datanodeMasterDir)datanodeMaxWalSender=4datanodeMaxWALSenders=($datanodeMaxWalSender $datanodeMaxWalSender) 集群初始化,启动,停止 初始化 pgxc_ctl -c /home/postgres/pgxc_ctl/pgxc_ctl.conf init all 输出结果: /bin/bashInstalling pgxc_ctl_bash script as /home/postgres/pgxc_ctl/pgxc_ctl_bash.Installing pgxc_ctl_bash script as /home/postgres/pgxc_ctl/pgxc_ctl_bash.Reading configuration using /home/postgres/pgxc_ctl/pgxc_ctl_bash --home /home/postgres/pgxc_ctl --configuration /home/postgres/pgxc_ctl/pgxc_ctl.conf/home/postgres/pgxc_ctl/pgxc_ctl.conf: line 189: $coordExtraConfig: ambiguous redirectFinished reading configuration. PGXC_CTL START Current directory: /home/postgres/pgxc_ctlStopping all the coordinator masters.Stopping coordinator master coord1.Stopping coordinator master coord2.pg_ctl: directory "/home/postgres/pgxc/nodes/coord/coord1" does not existpg_ctl: directory "/home/postgres/pgxc/nodes/coord/coord2" does not existDone.Stopping all the datanode masters.Stopping datanode master datanode1.Stopping datanode master datanode2.pg_ctl: PID file "/home/postgres/pgxc/nodes/datanode/datanode1/postmaster.pid" does not existIs server running?Done.Stop GTM masterwaiting for server to shut down.... doneserver stopped[postgres@gtm ~]$ echo $PGHOME/home/postgres/pgxl[postgres@gtm ~]$ ll /home/postgres/pgxl/pgxc/nodes/gtm/gtm.^C[postgres@gtm ~]$ pgxc_ctl -c /home/postgres/pgxc_ctl/pgxc_ctl.conf init all/bin/bashInstalling pgxc_ctl_bash script as /home/postgres/pgxc_ctl/pgxc_ctl_bash.Installing pgxc_ctl_bash script as /home/postgres/pgxc_ctl/pgxc_ctl_bash.Reading configuration using /home/postgres/pgxc_ctl/pgxc_ctl_bash --home /home/postgres/pgxc_ctl --configuration /home/postgres/pgxc_ctl/pgxc_ctl.conf/home/postgres/pgxc_ctl/pgxc_ctl.conf: line 189: $coordExtraConfig: ambiguous redirectFinished reading configuration. PGXC_CTL START Current directory: /home/postgres/pgxc_ctlInitialize GTM masterERROR: target directory (/home/postgres/pgxc/nodes/gtm) exists and not empty. Skip GTM initilializationDone.Start GTM masterserver startingInitialize all the coordinator masters.Initialize coordinator master coord1.ERROR: target coordinator master coord1 is running now. Skip initilialization.Initialize coordinator master coord2.The files belonging to this database system will be owned by user "postgres".This user must also own the server process.The database cluster will be initialized with locale "en_US.UTF-8".The default database encoding has accordingly been set to "UTF8".The default text search configuration will be set to "english".Data page checksums are disabled.fixing permissions on existing directory /home/postgres/pgxc/nodes/coord/coord2 ... okcreating subdirectories ... okselecting default max_connections ... 100selecting default shared_buffers ... 128MBselecting dynamic shared memory implementation ... posixcreating configuration files ... okrunning bootstrap script ... okperforming post-bootstrap initialization ... creating cluster information ... oksyncing data to disk ... okfreezing database template0 ... okfreezing database template1 ... okfreezing database postgres ... okWARNING: enabling "trust" authentication for local connectionsYou can change this by editing pg_hba.conf or using the option -A, or--auth-local and --auth-host, the next time you run initdb.Success.Done.Starting coordinator master.Starting coordinator master coord1ERROR: target coordinator master coord1 is already running now. Skip initialization.Starting coordinator master coord22019-05-30 21:09:25.562 EDT [2148] LOG: listening on IPv4 address "0.0.0.0", port 54322019-05-30 21:09:25.562 EDT [2148] LOG: listening on IPv6 address "::", port 54322019-05-30 21:09:25.563 EDT [2148] LOG: listening on Unix socket "/tmp/.s.PGSQL.5432"2019-05-30 21:09:25.601 EDT [2149] LOG: database system was shut down at 2019-05-30 21:09:22 EDT2019-05-30 21:09:25.605 EDT [2148] LOG: database system is ready to accept connections2019-05-30 21:09:25.612 EDT [2156] LOG: cluster monitor startedDone.Initialize all the datanode masters.Initialize the datanode master datanode1.Initialize the datanode master datanode2.The files belonging to this database system will be owned by user "postgres".This user must also own the server process.The database cluster will be initialized with locale "en_US.UTF-8".The default database encoding has accordingly been set to "UTF8".The default text search configuration will be set to "english".Data page checksums are disabled.fixing permissions on existing directory /home/postgres/pgxc/nodes/datanode/datanode1 ... okcreating subdirectories ... okselecting default max_connections ... 100selecting default shared_buffers ... 128MBselecting dynamic shared memory implementation ... posixcreating configuration files ... okrunning bootstrap script ... okperforming post-bootstrap initialization ... creating cluster information ... oksyncing data to disk ... okfreezing database template0 ... okfreezing database template1 ... okfreezing database postgres ... okWARNING: enabling "trust" authentication for local connectionsYou can change this by editing pg_hba.conf or using the option -A, or--auth-local and --auth-host, the next time you run initdb.Success.The files belonging to this database system will be owned by user "postgres".This user must also own the server process.The database cluster will be initialized with locale "en_US.UTF-8".The default database encoding has accordingly been set to "UTF8".The default text search configuration will be set to "english".Data page checksums are disabled.fixing permissions on existing directory /home/postgres/pgxc/nodes/datanode/datanode2 ... okcreating subdirectories ... okselecting default max_connections ... 100selecting default shared_buffers ... 128MBselecting dynamic shared memory implementation ... posixcreating configuration files ... okrunning bootstrap script ... okperforming post-bootstrap initialization ... creating cluster information ... oksyncing data to disk ... okfreezing database template0 ... okfreezing database template1 ... okfreezing database postgres ... okWARNING: enabling "trust" authentication for local connectionsYou can change this by editing pg_hba.conf or using the option -A, or--auth-local and --auth-host, the next time you run initdb.Success.Done.Starting all the datanode masters.Starting datanode master datanode1.WARNING: datanode master datanode1 is running now. Skipping.Starting datanode master datanode2.2019-05-30 21:09:33.352 EDT [2404] LOG: listening on IPv4 address "0.0.0.0", port 154322019-05-30 21:09:33.352 EDT [2404] LOG: listening on IPv6 address "::", port 154322019-05-30 21:09:33.355 EDT [2404] LOG: listening on Unix socket "/tmp/.s.PGSQL.15432"2019-05-30 21:09:33.392 EDT [2404] LOG: redirecting log output to logging collector process2019-05-30 21:09:33.392 EDT [2404] HINT: Future log output will appear in directory "pg_log".Done.psql: FATAL: no pg_hba.conf entry for host "192.168.20.132", user "postgres", database "postgres"psql: FATAL: no pg_hba.conf entry for host "192.168.20.132", user "postgres", database "postgres"Done.psql: FATAL: no pg_hba.conf entry for host "192.168.20.132", user "postgres", database "postgres"psql: FATAL: no pg_hba.conf entry for host "192.168.20.132", user "postgres", database "postgres"Done.[postgres@gtm ~]$ pgxc_ctl -c /home/postgres/pgxc_ctl/pgxc_ctl.conf stop all/bin/bashInstalling pgxc_ctl_bash script as /home/postgres/pgxc_ctl/pgxc_ctl_bash.Installing pgxc_ctl_bash script as /home/postgres/pgxc_ctl/pgxc_ctl_bash.Reading configuration using /home/postgres/pgxc_ctl/pgxc_ctl_bash --home /home/postgres/pgxc_ctl --configuration /home/postgres/pgxc_ctl/pgxc_ctl.conf/home/postgres/pgxc_ctl/pgxc_ctl.conf: line 189: $coordExtraConfig: ambiguous redirectFinished reading configuration. PGXC_CTL START Current directory: /home/postgres/pgxc_ctlStopping all the coordinator masters.Stopping coordinator master coord1.Stopping coordinator master coord2.pg_ctl: directory "/home/postgres/pgxc/nodes/coord/coord1" does not existDone.Stopping all the datanode masters.Stopping datanode master datanode1.Stopping datanode master datanode2.pg_ctl: PID file "/home/postgres/pgxc/nodes/datanode/datanode1/postmaster.pid" does not existIs server running?Done.Stop GTM masterwaiting for server to shut down.... doneserver stopped[postgres@gtm ~]$ pgxc_ctl/bin/bashInstalling pgxc_ctl_bash script as /home/postgres/pgxc_ctl/pgxc_ctl_bash.Installing pgxc_ctl_bash script as /home/postgres/pgxc_ctl/pgxc_ctl_bash.Reading configuration using /home/postgres/pgxc_ctl/pgxc_ctl_bash --home /home/postgres/pgxc_ctl --configuration /home/postgres/pgxc_ctl/pgxc_ctl.conf/home/postgres/pgxc_ctl/pgxc_ctl.conf: line 189: $coordExtraConfig: ambiguous redirectFinished reading configuration. PGXC_CTL START Current directory: /home/postgres/pgxc_ctlPGXC monitor allNot running: gtm masterRunning: coordinator master coord1Not running: coordinator master coord2Running: datanode master datanode1Not running: datanode master datanode2PGXC stop coordinator master coord1Stopping coordinator master coord1.pg_ctl: directory "/home/postgres/pgxc/nodes/coord/coord1" does not existDone.PGXC stop datanode master datanode1Stopping datanode master datanode1.pg_ctl: PID file "/home/postgres/pgxc/nodes/datanode/datanode1/postmaster.pid" does not existIs server running?Done.PGXC monitor allNot running: gtm masterRunning: coordinator master coord1Not running: coordinator master coord2Running: datanode master datanode1Not running: datanode master datanode2PGXC monitor allNot running: gtm masterNot running: coordinator master coord1Not running: coordinator master coord2Not running: datanode master datanode1Not running: datanode master datanode2PGXC exit[postgres@gtm ~]$ pgxc_ctl -c /home/postgres/pgxc_ctl/pgxc_ctl.conf init all/bin/bashInstalling pgxc_ctl_bash script as /home/postgres/pgxc_ctl/pgxc_ctl_bash.Installing pgxc_ctl_bash script as /home/postgres/pgxc_ctl/pgxc_ctl_bash.Reading configuration using /home/postgres/pgxc_ctl/pgxc_ctl_bash --home /home/postgres/pgxc_ctl --configuration /home/postgres/pgxc_ctl/pgxc_ctl.conf/home/postgres/pgxc_ctl/pgxc_ctl.conf: line 189: $coordExtraConfig: ambiguous redirectFinished reading configuration. PGXC_CTL START Current directory: /home/postgres/pgxc_ctlInitialize GTM masterERROR: target directory (/home/postgres/pgxc/nodes/gtm) exists and not empty. Skip GTM initilializationDone.Start GTM masterserver startingInitialize all the coordinator masters.Initialize coordinator master coord1.Initialize coordinator master coord2.The files belonging to this database system will be owned by user "postgres".This user must also own the server process.The database cluster will be initialized with locale "en_US.UTF-8".The default database encoding has accordingly been set to "UTF8".The default text search configuration will be set to "english".Data page checksums are disabled.fixing permissions on existing directory /home/postgres/pgxc/nodes/coord/coord1 ... okcreating subdirectories ... okselecting default max_connections ... 100selecting default shared_buffers ... 128MBselecting dynamic shared memory implementation ... posixcreating configuration files ... okrunning bootstrap script ... okperforming post-bootstrap initialization ... creating cluster information ... oksyncing data to disk ... okfreezing database template0 ... okfreezing database template1 ... okfreezing database postgres ... okWARNING: enabling "trust" authentication for local connectionsYou can change this by editing pg_hba.conf or using the option -A, or--auth-local and --auth-host, the next time you run initdb.Success.The files belonging to this database system will be owned by user "postgres".This user must also own the server process.The database cluster will be initialized with locale "en_US.UTF-8".The default database encoding has accordingly been set to "UTF8".The default text search configuration will be set to "english".Data page checksums are disabled.fixing permissions on existing directory /home/postgres/pgxc/nodes/coord/coord2 ... okcreating subdirectories ... okselecting default max_connections ... 100selecting default shared_buffers ... 128MBselecting dynamic shared memory implementation ... posixcreating configuration files ... okrunning bootstrap script ... okperforming post-bootstrap initialization ... creating cluster information ... oksyncing data to disk ... okfreezing database template0 ... okfreezing database template1 ... okfreezing database postgres ... okWARNING: enabling "trust" authentication for local connectionsYou can change this by editing pg_hba.conf or using the option -A, or--auth-local and --auth-host, the next time you run initdb.Success.Done.Starting coordinator master.Starting coordinator master coord1Starting coordinator master coord22019-05-30 21:13:03.998 EDT [25137] LOG: listening on IPv4 address "0.0.0.0", port 54322019-05-30 21:13:03.998 EDT [25137] LOG: listening on IPv6 address "::", port 54322019-05-30 21:13:04.000 EDT [25137] LOG: listening on Unix socket "/tmp/.s.PGSQL.5432"2019-05-30 21:13:04.038 EDT [25138] LOG: database system was shut down at 2019-05-30 21:13:00 EDT2019-05-30 21:13:04.042 EDT [25137] LOG: database system is ready to accept connections2019-05-30 21:13:04.049 EDT [25145] LOG: cluster monitor started2019-05-30 21:13:04.020 EDT [2730] LOG: listening on IPv4 address "0.0.0.0", port 54322019-05-30 21:13:04.020 EDT [2730] LOG: listening on IPv6 address "::", port 54322019-05-30 21:13:04.021 EDT [2730] LOG: listening on Unix socket "/tmp/.s.PGSQL.5432"2019-05-30 21:13:04.057 EDT [2731] LOG: database system was shut down at 2019-05-30 21:13:00 EDT2019-05-30 21:13:04.061 EDT [2730] LOG: database system is ready to accept connections2019-05-30 21:13:04.062 EDT [2738] LOG: cluster monitor startedDone.Initialize all the datanode masters.Initialize the datanode master datanode1.Initialize the datanode master datanode2.The files belonging to this database system will be owned by user "postgres".This user must also own the server process.The database cluster will be initialized with locale "en_US.UTF-8".The default database encoding has accordingly been set to "UTF8".The default text search configuration will be set to "english".Data page checksums are disabled.fixing permissions on existing directory /home/postgres/pgxc/nodes/datanode/datanode1 ... okcreating subdirectories ... okselecting default max_connections ... 100selecting default shared_buffers ... 128MBselecting dynamic shared memory implementation ... posixcreating configuration files ... okrunning bootstrap script ... okperforming post-bootstrap initialization ... creating cluster information ... oksyncing data to disk ... okfreezing database template0 ... okfreezing database template1 ... okfreezing database postgres ... okWARNING: enabling "trust" authentication for local connectionsYou can change this by editing pg_hba.conf or using the option -A, or--auth-local and --auth-host, the next time you run initdb.Success.The files belonging to this database system will be owned by user "postgres".This user must also own the server process.The database cluster will be initialized with locale "en_US.UTF-8".The default database encoding has accordingly been set to "UTF8".The default text search configuration will be set to "english".Data page checksums are disabled.fixing permissions on existing directory /home/postgres/pgxc/nodes/datanode/datanode2 ... okcreating subdirectories ... okselecting default max_connections ... 100selecting default shared_buffers ... 128MBselecting dynamic shared memory implementation ... posixcreating configuration files ... okrunning bootstrap script ... okperforming post-bootstrap initialization ... creating cluster information ... oksyncing data to disk ... okfreezing database template0 ... okfreezing database template1 ... okfreezing database postgres ... okWARNING: enabling "trust" authentication for local connectionsYou can change this by editing pg_hba.conf or using the option -A, or--auth-local and --auth-host, the next time you run initdb.Success.Done.Starting all the datanode masters.Starting datanode master datanode1.Starting datanode master datanode2.2019-05-30 21:13:12.077 EDT [25392] LOG: listening on IPv4 address "0.0.0.0", port 154322019-05-30 21:13:12.077 EDT [25392] LOG: listening on IPv6 address "::", port 154322019-05-30 21:13:12.079 EDT [25392] LOG: listening on Unix socket "/tmp/.s.PGSQL.15432"2019-05-30 21:13:12.114 EDT [25392] LOG: redirecting log output to logging collector process2019-05-30 21:13:12.114 EDT [25392] HINT: Future log output will appear in directory "pg_log".2019-05-30 21:13:12.079 EDT [2985] LOG: listening on IPv4 address "0.0.0.0", port 154322019-05-30 21:13:12.079 EDT [2985] LOG: listening on IPv6 address "::", port 154322019-05-30 21:13:12.081 EDT [2985] LOG: listening on Unix socket "/tmp/.s.PGSQL.15432"2019-05-30 21:13:12.117 EDT [2985] LOG: redirecting log output to logging collector process2019-05-30 21:13:12.117 EDT [2985] HINT: Future log output will appear in directory "pg_log".Done.psql: FATAL: no pg_hba.conf entry for host "192.168.20.132", user "postgres", database "postgres"psql: FATAL: no pg_hba.conf entry for host "192.168.20.132", user "postgres", database "postgres"Done.psql: FATAL: no pg_hba.conf entry for host "192.168.20.132", user "postgres", database "postgres"psql: FATAL: no pg_hba.conf entry for host "192.168.20.132", user "postgres", database "postgres"Done. 启动 pgxc_ctl -c /home/postgres/pgxc_ctl/pgxc_ctl.conf start all 关闭 pgxc_ctl -c /home/postgres/pgxc_ctl/pgxc_ctl.conf stop all 查看集群状态 [postgres@gtm ~]$ pgxc_ctl monitor all/bin/bashInstalling pgxc_ctl_bash script as /home/postgres/pgxc_ctl/pgxc_ctl_bash.Installing pgxc_ctl_bash script as /home/postgres/pgxc_ctl/pgxc_ctl_bash.Reading configuration using /home/postgres/pgxc_ctl/pgxc_ctl_bash --home /home/postgres/pgxc_ctl --configuration /home/postgres/pgxc_ctl/pgxc_ctl.conf/home/postgres/pgxc_ctl/pgxc_ctl.conf: line 189: $coordExtraConfig: ambiguous redirectFinished reading configuration. PGXC_CTL START Current directory: /home/postgres/pgxc_ctlRunning: gtm masterRunning: coordinator master coord1Running: coordinator master coord2Running: datanode master datanode1Running: datanode master datanode2 配置集群信息 分别在数据节点、协调器节点上分别执行以下命令: 注:本节点只执行修改操作即可(alert node),其他节点执行创建命令(create node)。因为本节点已经包含本节点的信息。 create node coord1 with (type=coordinator,host=xl1, port=5432);create node coord2 with (type=coordinator,host=xl2, port=5432);alter node coord1 with (type=coordinator,host=xl1, port=5432);alter node coord2 with (type=coordinator,host=xl2, port=5432);create node datanode1 with (type=datanode, host=xl1,port=15432,primary=true,PREFERRED);create node datanode2 with (type=datanode, host=xl2,port=15432);alter node datanode1 with (type=datanode, host=xl1,port=15432,primary=true,PREFERRED);alter node datanode2 with (type=datanode, host=xl2,port=15432);select pgxc_pool_reload(); 分别登陆数据节点、协调器节点验证 postgres= select from pgxc_node;node_name | node_type | node_port | node_host | nodeis_primary | nodeis_preferred | node_id-----------+-----------+-----------+-----------+----------------+------------------+-------------coord1 | C | 5432 | xl1 | f | f | 1885696643coord2 | C | 5432 | xl2 | f | f | -1197102633datanode2 | D | 15432 | xl2 | f | f | -905831925datanode1 | D | 15432 | xl1 | t | f | 888802358(4 rows) 测试 插入数据 在数据节点1,执行相关操作。 通过协调器端口登录PG [postgres@xl1 ~]$ psql -p 5432psql (PGXL 10r1.1, based on PG 10.6 (Postgres-XL 10r1.1))Type "help" for help.postgres= create database lei;CREATE DATABASEpostgres= \c lei;You are now connected to database "lei" as user "postgres".lei= create table test1(id int,name text);CREATE TABLElei= insert into test1(id,name) select generate_series(1,8),'测试';INSERT 0 8lei= select from test1;id | name----+------1 | 测试2 | 测试5 | 测试6 | 测试8 | 测试3 | 测试4 | 测试7 | 测试(8 rows) 注:默认创建的表为分布式表,也就是每个数据节点值存储表的部分数据。关于表类型具体说明,下面有说明。 通过15432端口登录数据节点,查看数据 有5条数据 [postgres@xl1 ~]$ psql -p 15432psql (PGXL 10r1.1, based on PG 10.6 (Postgres-XL 10r1.1))Type "help" for help.postgres= \c lei;You are now connected to database "lei" as user "postgres".lei= select from test1;id | name----+------1 | 测试2 | 测试5 | 测试6 | 测试8 | 测试(5 rows) 登录到节点2,查看数据 有3条数据 [postgres@xl2 ~]$ psql -p15432psql (PGXL 10r1.1, based on PG 10.6 (Postgres-XL 10r1.1))Type "help" for help.postgres= \c lei;You are now connected to database "lei" as user "postgres".lei= select from test1;id | name----+------3 | 测试4 | 测试7 | 测试(3 rows) 两个节点的数据加起来整个8条,没有问题。 至此Postgre-XL集群搭建完成。 创建数据库、表时可能会出现以下错误: ERROR: Failed to get pooled connections 是因为pg_hba.conf配置不对,所有节点加上host all all 192.168.20.0/0 trust并重启集群即可。 ERROR: No Datanode defined in cluster 首先确认是否创建了数据节点,也就是create node相关的命令。如果创建了则执行select pgxc_pool_reload();使其生效即可。 集群管理与应用 表类型说明 REPLICATION表:各个datanode节点中,表的数据完全相同,也就是说,插入数据时,会分别在每个datanode节点插入相同数据。读数据时,只需要读任意一个datanode节点上的数据。 建表语法: CREATE TABLE repltab (col1 int, col2 int) DISTRIBUTE BY REPLICATION; DISTRIBUTE :会将插入的数据,按照拆分规则,分配到不同的datanode节点中存储,也就是sharding技术。每个datanode节点只保存了部分数据,通过coordinate节点可以查询完整的数据视图。 CREATE TABLE disttab(col1 int, col2 int, col3 text) DISTRIBUTE BY HASH(col1); 模拟数据插入 任意登录一个coordinate节点进行建表操作 [postgres@gtm ~]$ psql -h xl1 -p 5432 -U postgrespostgres= INSERT INTO disttab SELECT generate_series(1,100), generate_series(101, 200), 'foo';INSERT 0 100postgres= INSERT INTO repltab SELECT generate_series(1,100), generate_series(101, 200);INSERT 0 100 查看数据分布结果: DISTRIBUTE表分布结果 postgres= SELECT xc_node_id, count() FROM disttab GROUP BY xc_node_id;xc_node_id | count ------------+-------1148549230 | 42-927910690 | 58(2 rows) REPLICATION表分布结果 postgres= SELECT count() FROM repltab;count -------100(1 row) 查看另一个datanode2中repltab表结果 [postgres@datanode2 pgxl9.5]$ psql -p 15432psql (PGXL 10r1.1, based on PG 10.6 (Postgres-XL 10r1.1))Type "help" for help.postgres= SELECT count() FROM repltab;count -------100(1 row) 结论:REPLICATION表中,datanode1,datanode2中表是全部数据,一模一样。而DISTRIBUTE表,数据散落近乎平均分配到了datanode1,datanode2节点中。 新增数据节点与数据重分布 在线新增节点、并重新分布数据。 新增datanode节点 在gtm集群管理节点上执行pgxc_ctl命令 [postgres@gtm ~]$ pgxc_ctl/bin/bashInstalling pgxc_ctl_bash script as /home/postgres/pgxc_ctl/pgxc_ctl_bash.Installing pgxc_ctl_bash script as /home/postgres/pgxc_ctl/pgxc_ctl_bash.Reading configuration using /home/postgres/pgxc_ctl/pgxc_ctl_bash --home /home/postgres/pgxc_ctl --configuration /home/postgres/pgxc_ctl/pgxc_ctl.confFinished reading configuration. PGXC_CTL START Current directory: /home/postgres/pgxc_ctlPGXC 在服务器xl3上,新增一个master角色的datanode节点,名称是datanode3 端口号暂定5430,pool master暂定6669 ,指定好数据目录位置,从两个节点升级到3个节点,之后要写3个none none应该是datanodeSpecificExtraConfig或者datanodeSpecificExtraPgHba配置PGXC add datanode master datanode3 xl3 15432 6671 /home/postgres/pgxc/nodes/datanode/datanode3 none none none 等待新增完成后,查询集群节点状态: postgres= select from pgxc_node;node_name | node_type | node_port | node_host | nodeis_primary | nodeis_preferred | node_id-----------+-----------+-----------+-----------+----------------+------------------+-------------datanode1 | D | 15432 | xl1 | t | f | 888802358datanode2 | D | 15432 | xl2 | f | f | -905831925datanode3 | D | 15432 | xl3 | f | f | -705831925coord1 | C | 5432 | xl1 | f | f | 1885696643coord2 | C | 5432 | xl2 | f | f | -1197102633(4 rows) 节点新增完毕 数据重新分布 由于新增节点后无法自动完成数据重新分布,需要手动操作。 DISTRIBUTE表分布在了node1,node2节点上,如下: postgres= SELECT xc_node_id, count() FROM disttab GROUP BY xc_node_id;xc_node_id | count ------------+-------1148549230 | 42-927910690 | 58(2 rows) 新增一个节点后,将sharding表数据重新分配到三个节点上,将repl表复制到新节点 重分布sharding表postgres= ALTER TABLE disttab ADD NODE (datanode3);ALTER TABLE 复制数据到新节点postgres= ALTER TABLE repltab ADD NODE (datanode3);ALTER TABLE 查看新的数据分布: postgres= SELECT xc_node_id, count() FROM disttab GROUP BY xc_node_id;xc_node_id | count ------------+--------700122826 | 36-927910690 | 321148549230 | 32(3 rows) 登录datanode3(新增的时候,放在了xl3服务器上,端口15432)节点查看数据: [postgres@gtm ~]$ psql -h xl3 -p 15432 -U postgrespsql (PGXL 10r1.1, based on PG 10.6 (Postgres-XL 10r1.1))Type "help" for help.postgres= select count() from repltab;count -------100(1 row) 很明显,通过 ALTER TABLE tt ADD NODE (dn)命令,可以将DISTRIBUTE表数据重新分布到新节点,重分布过程中会中断所有事务。可以将REPLICATION表数据复制到新节点。 从datanode节点中回收数据 postgres= ALTER TABLE disttab DELETE NODE (datanode3);ALTER TABLEpostgres= ALTER TABLE repltab DELETE NODE (datanode3);ALTER TABLE 删除数据节点 Postgresql-XL并没有检查将被删除的datanode节点是否有replicated/distributed表的数据,为了数据安全,在删除之前需要检查下被删除节点上的数据,有数据的话,要回收掉分配到其他节点,然后才能安全删除。删除数据节点分为四步骤: 1.查询要删除节点dn3的oid postgres= SELECT oid, FROM pgxc_node;oid | node_name | node_type | node_port | node_host | nodeis_primary | nodeis_preferred | node_id -------+-----------+-----------+-----------+-----------+----------------+------------------+-------------11819 | coord1 | C | 5432 | datanode1 | f | f | 188569664316384 | coord2 | C | 5432 | datanode2 | f | f | -119710263316385 | node1 | D | 5433 | datanode1 | f | t | 114854923016386 | node2 | D | 5433 | datanode2 | f | f | -92791069016397 | dn3 | D | 5430 | datanode1 | f | f | -700122826(5 rows) 2.查询dn3对应的oid中是否有数据 testdb= SELECT FROM pgxc_class WHERE nodeoids::integer[] @> ARRAY[16397];pcrelid | pclocatortype | pcattnum | pchashalgorithm | pchashbuckets | nodeoids ---------+---------------+----------+-----------------+---------------+-------------------16388 | H | 1 | 1 | 4096 | 16397 16385 1638616394 | R | 0 | 0 | 0 | 16397 16385 16386(2 rows) 3.有数据的先回收数据 postgres= ALTER TABLE disttab DELETE NODE (dn3);ALTER TABLEpostgres= ALTER TABLE repltab DELETE NODE (dn3);ALTER TABLEpostgres= SELECT FROM pgxc_class WHERE nodeoids::integer[] @> ARRAY[16397];pcrelid | pclocatortype | pcattnum | pchashalgorithm | pchashbuckets | nodeoids ---------+---------------+----------+-----------------+---------------+----------(0 rows) 4.安全删除dn3 PGXC$ remove datanode master dn3 clean 故障节点FAILOVER 1.查看当前集群状态 [postgres@gtm ~]$ psql -h xl1 -p 5432psql (PGXL 10r1.1, based on PG 10.6 (Postgres-XL 10r1.1))Type "help" for help.postgres= SELECT oid, FROM pgxc_node;oid | node_name | node_type | node_port | node_host | nodeis_primary | nodeis_preferred | node_id-------+-----------+-----------+-----------+-----------+----------------+------------------+-------------11739 | coord1 | C | 5432 | xl1 | f | f | 188569664316384 | coord2 | C | 5432 | xl2 | f | f | -119710263316387 | datanode2 | D | 15432 | xl2 | f | f | -90583192516388 | datanode1 | D | 15432 | xl1 | t | t | 888802358(4 rows) 2.模拟datanode1节点故障 直接关闭即可 PGXC stop -m immediate datanode master datanode1Stopping datanode master datanode1.Done. 3.测试查询 只要查询涉及到datanode1上的数据,那么该查询就会报错 postgres= SELECT xc_node_id, count() FROM disttab GROUP BY xc_node_id;WARNING: failed to receive file descriptors for connectionsERROR: Failed to get pooled connectionsHINT: This may happen because one or more nodes are currently unreachable, either because of node or network failure.Its also possible that the target node may have hit the connection limit or the pooler is configured with low connections.Please check if all nodes are running fine and also review max_connections and max_pool_size configuration parameterspostgres= SELECT xc_node_id, FROM disttab WHERE col1 = 3;xc_node_id | col1 | col2 | col3------------+------+------+-------905831925 | 3 | 103 | foo(1 row) 测试发现,查询范围如果涉及到故障的node1节点,会报错,而查询的数据范围不在node1上的话,仍然可以查询。 4.手动切换 要想切换,必须要提前配置slave节点。 PGXC$ failover datanode node1 切换完成后,查询集群 postgres= SELECT oid, FROM pgxc_node;oid | node_name | node_type | node_port | node_host | nodeis_primary | nodeis_preferred | node_id -------+-----------+-----------+-----------+-----------+----------------+------------------+-------------11819 | coord1 | C | 5432 | datanode1 | f | f | 188569664316384 | coord2 | C | 5432 | datanode2 | f | f | -119710263316386 | node2 | D | 15432 | datanode2 | f | f | -92791069016385 | node1 | D | 15433 | datanode2 | f | t | 1148549230(4 rows) 发现datanode1节点的ip和端口都已经替换为配置的slave了。 本篇文章为转载内容。原文链接:https://blog.csdn.net/qianglei6077/article/details/94379331。 该文由互联网用户投稿提供,文中观点代表作者本人意见,并不代表本站的立场。 作为信息平台,本站仅提供文章转载服务,并不拥有其所有权,也不对文章内容的真实性、准确性和合法性承担责任。 如发现本文存在侵权、违法、违规或事实不符的情况,请及时联系我们,我们将第一时间进行核实并删除相应内容。
2023-01-30 11:09:03
94
转载
CSS
...类选择器以及CSS Logical Properties and Values Level 1规范中的逻辑属性(如inset-inline-start),为hr元素的长度及位置控制带来了更多可能性。 因此,作为前端开发者,在关注基础的水平线长度设置技巧的同时,紧跟最新CSS标准和技术趋势,将有助于构建更为优雅、易读且具有优秀适应性的现代网页界面。同时,结合A11Y(无障碍访问)原则进行设计,确保水平线不仅在视觉上美观,也能在功能性和可访问性上满足所有用户的需求。
2023-02-11 22:13:41
497
码农
CSS
...草案中,提出了关于“逻辑属性与值”(Logical Properties and Values Level 4)的更新建议,允许开发者基于文本方向而非物理方向进行内边距、外边距和缩进等设置,极大地简化了国际化网站的文本排版处理。这对于需要支持多种语言环境的项目而言,无疑是文本排版技术的一大进步。 此外,在响应式设计领域,针对不同屏幕尺寸和设备类型调整文本缩进成为常态。一些新的CSS功能如clamp()函数,可以动态地为text-indent或padding-left设置适应性更强的值,确保跨设备的一致阅读体验。 综上所述,持续关注CSS标准的发展动向以及业界对于文本排版的最新实践案例,将有助于我们更好地运用各种CSS属性,包括但不限于text-indent和padding-left,以提升Web页面内容的可读性和美观度,紧跟Web前端开发的时代步伐。
2023-12-18 13:15:57
473
电脑达人
转载文章
...用法, 代码如下: 复制代码 代码如下: {capture name="banner"}aaaaaa{/capture} {$smarty.capture.banner} {capture assign="foo"}bbbbbb{/capture} {$foo} {capture append="arr"}hello{/capture} {capture append="arr"}world{/capture} {foreach $arr as $value} {$value} {/foreach} 第一种:{capture}使用name属性; 第二种:{capture}捕获内容到变量; 第三种:{capture}捕获内容到数组变量。 转载自 http://www.php.cn/php-notebook-167408.html 补充,看了下手册,name是必须的属性,上面的写法估计不严谨,简单记录一下吧。 本篇文章为转载内容。原文链接:https://blog.csdn.net/fjnjxr/article/details/95172043。 该文由互联网用户投稿提供,文中观点代表作者本人意见,并不代表本站的立场。 作为信息平台,本站仅提供文章转载服务,并不拥有其所有权,也不对文章内容的真实性、准确性和合法性承担责任。 如发现本文存在侵权、违法、违规或事实不符的情况,请及时联系我们,我们将第一时间进行核实并删除相应内容。
2023-12-03 17:52:39
79
转载
Java
...me属性原原本本地“复制粘贴”到person2里头。 正确的做法是,我们需要创建一个新的String对象,然后将其赋值给person2的name属性,即person2.setName(new String(person1.getName())); 5. 总结 通过对this关键字的理解,我们可以更好地处理一些复杂的问题。同时呢,咱也得留意一些常见的小误区,像是有人会误以为“this”关键字能直接复制属性啥的,这其实是个误区。希望这篇文章能帮助你更深入地理解Java中的this关键字,也希望你在学习编程的过程中能够保持对知识的热情和探索的精神。
2023-02-16 20:21:01
348
诗和远方_t
MySQL
...,增强了Group Replication功能,确保在分布式环境下的数据一致性与高可用性。 值得关注的是,全球知名的云服务提供商如AWS、阿里云等也针对MySQL分布式应用提供了托管服务,如Amazon Aurora和阿里云PolarDB,它们基于MySQL内核深度优化,不仅实现水平扩展,还提供自动故障切换、备份恢复等一系列高级特性,大大降低了企业在部署和维护分布式MySQL数据库时的技术门槛和运维成本。 此外,随着微服务架构的流行,NewSQL数据库如TiDB逐渐崭露头角,它兼容MySQL协议,同时实现了分布式事务处理以及水平扩展能力,为需要强一致性和高可扩展性的业务场景提供了新的选择。 综上所述,理解并掌握MySQL分布式技术的同时,关注相关领域的最新动态和技术发展,将有助于企业在实际业务中更好地运用MySQL及其衍生产品来应对日益增长的数据挑战,实现业务的持续稳定和快速发展。
2023-02-25 16:35:15
123
逻辑鬼才
JQuery
...以把它们直接拽过来,复制粘贴到自己的项目里头,亲自试试跑起来的效果。 3.1 直接获取当前URL地址 javascript // 获取当前URL地址 var currentUrl = window.location.href; // 输出结果 console.log(currentUrl); 这段代码会输出当前浏览器窗口的完整URL地址。 3.2 使用jQuery获取当前URL地址 javascript // 发起GET请求并获取URL地址 $.get(window.location.href, function(data) { console.log(window.location.href); }); // 或者 $.get(window.location.href).done(function(response) { console.log(response.url); }); 这两段代码都会向当前的URL地址发起一个GET请求,并输出URL地址。嗨,你知道吗?实际上我们并没有去动那个"data"参数,为啥呢?因为我们并不太关心服务器返回的那些具体细节内容啦~ 四、结论 总的来说,获取当前的URL地址是一件非常简单的事情。我们只需要使用JavaScript的window.location对象或者jQuery的$.get方法即可。希望本文能够帮助您更好地理解和使用这些方法。如果您还有其他问题,欢迎随时向我提问。
2023-01-20 12:04:33
353
海阔天空_t
站内搜索
用于搜索本网站内部文章,支持栏目切换。
知识学习
实践的时候请根据实际情况谨慎操作。
随机学习一条linux命令:
printf "%-10s %-10s\n" "Name" "Age"
- 打印格式化字符串,用于创建表格布局。
推荐内容
推荐本栏目内的其它文章,看看还有哪些文章让你感兴趣。
2023-04-28
2023-08-09
2023-06-18
2023-04-14
2023-02-18
2023-04-17
2024-01-11
2023-10-03
2023-09-09
2023-06-13
2023-08-07
2023-03-11
历史内容
快速导航到对应月份的历史文章列表。
随便看看
拉到页底了吧,随便看看还有哪些文章你可能感兴趣。
时光飞逝
"流光容易把人抛,红了樱桃,绿了芭蕉。"