前端技术
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
[故障切换 Failover ]的搜索结果
这里是文章列表。热门标签的颜色随机变换,标签颜色没有特殊含义。
点击某个标签可搜索标签相关的文章。
点击某个标签可搜索标签相关的文章。
Redis
...康状态。当主节点出现故障时,Redis Sentinel能够自动检测到问题,并执行故障转移操作,将从节点提升为主节点,从而确保服务的连续性和数据的可靠性。在本文中,探讨了Redis Sentinel配置错误或无法启动的问题及其解决方法。 分布式系统 , 分布式系统是由多个通过网络进行通信的独立计算机节点组成的系统,这些节点共同协作完成一个共同的任务。在本文语境下,Redis Sentinel作为分布式系统的一部分,其作用是在大规模、分布式部署的Redis环境中实现高可用与故障恢复功能。 环境变量 , 环境变量是在操作系统中用于存储有关当前运行环境信息的一种特殊变量,它们能被操作系统、shell脚本以及应用程序访问和使用。在本文中提到的Redis Sentinel配置问题中,环境变量未设置可能会导致Redis Sentinel无法获取必要的运行参数或路径信息,从而无法正常启动。 故障切换(Failover) , 在分布式系统尤其是数据库系统中,故障切换是指当主节点发生故障时,系统能够自动或手动地将服务切换到备份节点的过程,以保证服务的连续性和数据的完整性。在Redis Sentinel的场景下,故障切换由Sentinel组件自动触发并执行,确保即使主Redis服务器宕机,也能快速恢复服务。
2023-03-26 15:30:30
457
秋水共长天一色-t
Redis
...s能够更好地应对单点故障问题。 3.1 工作原理 哨兵模式由一组哨兵实例组成,它们负责监控Redis实例的状态。当哨兵发现主节点挂了,就会用Raft算法选出一个新老大,并告诉所有的小弟们赶紧更新配置信息。这个过程是自动完成的,无需人工干预。 3.2 代码示例 要启用哨兵模式,需要先配置哨兵实例。假设你已经安装了Redis,并且主节点运行在localhost:6379上。接下来,你需要创建一个哨兵配置文件sentinels.conf,内容如下: conf sentinel monitor mymaster 127.0.0.1 6379 2 sentinel down-after-milliseconds mymaster 5000 sentinel failover-timeout mymaster 60000 sentinel parallel-syncs mymaster 1 然后启动哨兵实例: bash redis-sentinel sentinels.conf 现在,当你故意关闭主节点时,哨兵会自动选举出一个新的主节点,并通知从节点进行切换。 4. 集群模式 最后,我们来看看Redis集群模式(Cluster Mode),这是一种更加复杂但也更强大的数据同步机制。集群模式允许Redis实例分布在多个节点上,每个节点都可以同时处理读写请求。 4.1 集群架构 在集群模式下,Redis实例被划分为多个槽(slots),每个槽可以归属于不同的节点。当你用客户端连到某个节点时,它会通过键名算出应该去哪个槽,然后就把请求直接发到对的节点上。这样做的好处是,即使某个节点宕机,也不会影响整个系统的可用性。 4.2 实现步骤 为了建立一个Redis集群,你需要准备至少六个Redis实例,每个实例监听不同的端口。然后,使用redis-trib.rb工具来创建集群: bash redis-trib.rb create --replicas 1 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 创建完成后,你可以通过任何节点来访问集群。例如: bash redis-cli -c -h 127.0.0.1 -p 7000 5. 总结 通过以上介绍,我们可以看到Redis提供了多种数据同步机制,每种机制都有其独特的应用场景。不管是基本的主从复制,还是复杂的集群模式,Redis都能搞定数据同步,让人放心。当然啦,每种方法都有它的长处和短处,到底选哪个还得看你自己的具体情况和所处的环境。希望今天的分享能对你有所帮助,也欢迎大家在评论区讨论更多关于Redis的话题!
2025-03-05 15:47:59
27
草原牧歌
MySQL
...,并集成了自动备份、故障切换等高级特性,大大简化了数据库运维工作。 另外,针对数据库优化及安全防护方面,定期审计MySQL日志、合理设置索引策略、采用SSL加密通信协议以保护数据传输安全等也是现代数据库管理员必备的知识点。近期,业界还提出了通过机器学习算法预测数据库性能瓶颈,提前进行资源调度的新方法,这一创新研究为MySQL数据库的高效稳定运行提供了新的可能。 综上所述,在实际操作MySQL服务的基础上,关注其最新版本特性、云端部署趋势以及数据库优化和安全领域的前沿动态,将有助于我们在日常工作中更高效地利用MySQL这一强大而灵活的关系型数据库管理系统。
2023-10-18 17:15:18
48
电脑达人
MySQL
...ter实现实时同步和故障切换,确保数据服务的连续性和可靠性。持续关注MySQL社区、官方文档和技术博客,将有助于紧跟技术潮流,不断提升自身数据库开发与管理能力。
2023-04-24 15:12:40
49
电脑达人
MySQL
...QL提供了自动备份、故障切换、读副本等功能,帮助企业实现数据库的高可用与扩展性。 此外,对于MySQL的学习者来说,社区资源与教程也不断推陈出新。诸如“MySQL 8.0从入门到精通”、“实战MySQL:高性能SQL优化、架构及集群”的在线课程和书籍,帮助初学者快速上手,并为有经验的开发者深入解析MySQL的内核机制和最佳实践。 综上所述,在MySQL的实际应用中,不仅应关注其安装配置,更要紧贴技术发展趋势,掌握最新的产品特性以提升数据库系统的性能与安全性,并结合云服务优势进行高效便捷的数据库管理与维护。同时,持续学习和跟进MySQL相关的教育资源,有助于不断提升自身技术水平,适应日益复杂多变的应用场景需求。
2023-09-19 12:58:09
133
算法侠
MySQL
...水平扩展,还提供自动故障切换、备份恢复等一系列高级特性,大大降低了企业在部署和维护分布式MySQL数据库时的技术门槛和运维成本。 此外,随着微服务架构的流行,NewSQL数据库如TiDB逐渐崭露头角,它兼容MySQL协议,同时实现了分布式事务处理以及水平扩展能力,为需要强一致性和高可扩展性的业务场景提供了新的选择。 综上所述,理解并掌握MySQL分布式技术的同时,关注相关领域的最新动态和技术发展,将有助于企业在实际业务中更好地运用MySQL及其衍生产品来应对日益增长的数据挑战,实现业务的持续稳定和快速发展。
2023-02-25 16:35:15
123
逻辑鬼才
MySQL
...服务提供了自动备份、故障切换及水平扩展等功能,使得在保持高性能的同时,也能方便地管理和添加海量数据(来源:阿里云官方文档,MySQL数据库解决方案)。 综上所述,除了基础的MySQL数据插入技巧外,关注数据库领域的最新发展动态和技术趋势,结合实际情况选择合适的数据库架构和服务,将有助于我们在实践中更加高效、安全地管理和添加数据。
2024-02-04 16:16:22
70
键盘勇士
Datax
...进NameNode的故障切换机制、优化网络通信协议等,从而降低此类连接失败的风险。此外,对于复杂网络环境下的防火墙策略配置,有专家建议采用SDN(Software-Defined Networking)技术进行智能管理,以自动适应不同服务间的端口需求,避免因人为误配导致的服务中断。 同时,针对大规模数据迁移场景下的挑战,业内研究者正积极探索基于容器化和Kubernetes编排技术的新一代数据同步解决方案,旨在通过灵活调度和资源优化进一步提高Datax等工具的性能表现和容错能力。这些前沿动态和实践经验为我们解决类似Datax与HDFS交互中出现的问题提供了新的思路和方法论,值得广大技术人员深入学习和借鉴。
2023-02-22 13:53:57
551
初心未变-t
Etcd
...Etcd存储层优化与故障恢复机制的深度分析报告,详尽阐述了如何通过改进snapshot策略、增强数据持久化能力以及实现跨地域多副本冗余,以降低由于硬件故障或网络问题导致的数据丢失风险。 同时,CNCF社区也正在积极推动Etcd项目的持续演进,包括对Raft一致性算法的优化、性能提升以及安全特性的增强等方面。针对Etcd的运维管理,有专业团队分享了实战经验,比如定期执行健康检查、监控关键指标,并结合自动化工具进行故障切换演练和备份恢复测试,确保在实际生产环境中能够快速有效地应对类似“Etcdserver无法从数据目录启动”的问题。 总之,理解并掌握Etcd的核心功能与运维要点,紧密跟踪其发展动态和技术前沿,对于构建和维护健壮高效的分布式系统具有重要的现实意义。
2023-01-07 12:31:32
512
岁月静好-t
MemCache
...服务,不仅提供了自动故障切换、备份恢复等功能,还整合了多层缓存架构设计,助力企业在面对大规模并发访问时仍能保持高效的数据读取性能。 然而,值得注意的是,在引入更复杂、功能更全面的缓存解决方案时,也需要权衡其带来的额外运维成本与资源开销。因此,如何根据实际业务场景和技术栈特点,合理选用和配置缓存系统,将是每一位开发者和架构师持续探索和实践的重要课题。
2023-09-25 18:48:16
60
青山绿水
SpringBoot
...时,不仅能够自动排除故障节点,还能基于实时的Broker性能指标动态调整发送目标,确保消息高效、均匀地分布到集群中的各个broker上,从而显著提升系统的稳定性和吞吐量。 此外,为了进一步增强消息传输的安全性与可靠性,RocketMQ 5.0还支持跨地域多活部署以及事务消息2.0特性,即使面临数据中心级别的故障切换,也能保证消息不丢失且严格有序地送达消费者,这对于构建高可用、高性能的分布式系统具有重要价值。 同时,随着云原生理念的普及,RocketMQ也积极拥抱Kubernetes等容器编排技术,提供云原生环境下的无缝集成方案,使得开发者能够便捷地在各类云环境或混合云场景下部署和管理RocketMQ集群,有效应对大规模分布式系统中的消息处理挑战。 因此,对于正在使用或计划采用RocketMQ作为消息中间件的开发者来说,持续关注其最新版本的功能演进和技术突破,结合实际业务场景灵活运用,无疑将助力提升整个系统的韧性和效率,实现微服务架构下的最佳实践。
2023-06-16 23:16:50
39
梦幻星空_t
Kafka
...服务通常提供自动化的故障切换和备份策略,增强了Kafka在实际生产环境中的稳定性。 此外,近年来微服务架构和Serverless计算模型的发展,对消息队列系统的弹性提出了更高要求。因此,研究者和开发者们正在积极探索将Kafka与其他新兴技术(如Service Mesh、Event-driven Architecture)相结合,构建更为健壮且适应性强的消息传递系统,以应对未来可能遇到的各种网络挑战。 总之,尽管网络不稳定性是大数据处理中难以避免的问题,但随着Kafka自身功能的不断完善以及云计算等相关技术的支持,我们有理由相信,在实际应用场景中,Kafka能够更好地发挥其优势,为分布式系统提供稳定可靠的消息传输服务。
2023-04-26 23:52:20
549
星辰大海
Beego
...,如基于权重的路由、故障切换和灰度发布等功能,这对于构建高可用和可扩展的微服务体系至关重要。此外,FastAPI等新兴框架也在路由设计上做出了创新,其通过Python类型提示系统来定义路由和参数,既提高了代码的可读性,又增强了API文档的一致性和准确性。 同时,对于RESTful API设计原则的深入理解和应用也是提升路由设计质量的关键所在。REST架构风格强调资源导向和状态转移,提倡URL的语义化设计,使API易于理解和使用。例如,遵循HTTP方法的语义(GET用于获取资源,POST用于创建,PUT用于更新,DELETE用于删除)可以简化客户端与服务器的交互逻辑,并有助于优化缓存机制。 综上所述,在掌握Beego框架下的路由定制技巧后,结合当下流行的微服务架构理念、先进的API设计模式以及对RESTful原则的深入理解,将能助您构建出更加高效、灵活且易于维护的Web应用程序。不断关注行业动态,学习并借鉴相关领域的最新研究成果和实践经验,是持续优化路由设计,提升整体项目质量的重要途径。
2023-07-13 09:35:46
621
青山绿水
转载文章
...负载均衡、资源共享、故障切换等功能,从而提高系统的可用性和扩展性。例如,旗鱼云梯就提供了良好的集群化功能,允许用户无限制添加自己的服务器进行统一管理。
2023-10-25 12:23:09
517
转载
PostgreSQL
... 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
人生如戏
MemCache
...一键部署、自动扩展和故障切换等功能,还在底层增强了跨区域的数据复制和一致性保证机制,极大地降低了用户在处理分布式缓存管理与同步时的技术复杂性。 同时,随着开源技术的发展,新型分布式缓存系统如Redis Cluster凭借其原生支持的分布式特性,以及对数据分片和主从同步的优秀设计,正逐渐成为高并发场景下的另一种主流选择。对于寻求更高数据一致性和容错性的团队而言,Redis Cluster提供了更完善的一站式解决方案。 此外,学术界也在持续研究分布式缓存的一致性算法和策略,例如“CRDTs(Conflict-free Replicated Data Types)”无冲突复制数据类型,能够在分布式环境下提供最终一致性保障,为未来缓存技术的发展开辟了新的可能。 因此,在实际项目中,除了掌握MemCache的传统部署和管理方式,关注和学习业界前沿技术和理论成果,适时引入更为先进的分布式缓存架构和服务,将有助于我们更好地应对日益复杂的业务需求和挑战。
2023-11-14 17:08:32
69
凌波微步
转载文章
...SQL服务的高可用和故障切换。 综上所述,MySQL的持续学习和最佳实践探索是每一位数据库管理员的重要任务,时刻关注官方更新动态、加强安全意识,并深入了解高级配置技巧,才能让Linux环境下运行的MySQL发挥出最大效能,为企业业务稳定高效运转提供坚实基础。
2023-05-24 19:00:46
119
转载
PostgreSQL
...种架构能够提供冗余和故障切换能力,从而实现高可用性。 然而,为了构建真正的分布式集群以应对大数据量和高并发场景,我们需要借助如PGPool-II、pg_bouncer等中间件,或者采用逻辑复制、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
追梦人_
Dubbo
...常后,又能悄无声息地切换回去的呢?这就是我们今天要一起揭开的趣味小秘密! 二、Dubbo的容错机制(序号2) 2.1 负载均衡与集群容错 Dubbo通过集成多种负载均衡策略如随机、轮询、最少活跃调用数等,并结合集群容错模式(默认为failover),巧妙地处理了服务消费者故障问题。 java // 创建一个具有容错机制的引用 ReferenceConfig reference = new ReferenceConfig<>(); reference.setInterface(DemoService.class); // 设置集群容错模式为failover,即失败自动切换 reference.setCluster("failover"); 在failover模式下,若某台服务提供者出现故障或网络中断,Dubbo会自动将请求路由到其他健康的提供者节点,有效避免因单点故障导致的服务不可用。 2.2 超时与重试机制 此外,Dubbo还提供了超时控制和重试机制: java // 设置接口方法的超时时间和重试次数 reference.setTimeout(1000); // 1秒超时 reference.setRetries(2); // 允许重试两次 这意味着,如果服务消费者在指定时间内未收到响应,Dubbo将自动触发重试逻辑,尝试从其他提供者获取结果,从而在网络不稳定时增强系统的鲁棒性。 三、心跳检测与隔离策略(序号3) 3.1 心跳检测 Dubbo的心跳检测机制可以实时监控服务提供者的健康状态,一旦发现服务提供者宕机或网络不通,会立即将其剔除出可用列表,直到其恢复正常: java // 在服务提供端配置心跳间隔 ProviderConfig providerConfig = new ProviderConfig(); providerConfig.setHeartbeat(true); // 开启心跳检测 providerConfig.setHeartbeatInterval(60000); // 每60秒发送一次心跳 3.2 隔离策略 针对部分服务提供者可能存在的雪崩效应,Dubbo还支持sentinel等多种隔离策略,限制并发访问数量,防止资源耗尽引发更大范围的服务失效: java // 配置sentinel限流 reference.setFilter("sentinel"); // 添加sentinel过滤器 四、总结与探讨(序号4) 综上所述,Dubbo凭借其丰富的容错机制、心跳检测以及隔离策略,能够有效地应对服务消费者宕机或网络不稳定的问题。但是呢,对于我们这些开发者来说,也得把目光放在实际应用场景的优化上,比如像是给程序设定个恰到好处的超时时间啦,挑选最对胃口的负载均衡策略什么的,这样一来才能让咱的业务需求灵活应变,不断升级! 每一次对Dubbo特性的探索,都让我们对其在构建高可用分布式系统中的价值有了更深的理解。在面对这瞬息万变、充满挑战的生产环境时,Dubbo可不仅仅是个普通的小工具,它更像是我们身边一位超级给力的小伙伴,帮我们守护着服务质量的大门,让系统的稳定性蹭蹭上涨,成为我们不可或缺的好帮手。在实践中不断学习和改进,是我们共同的目标与追求。
2024-03-25 10:39:14
484
山涧溪流
转载文章
...Node的高可用性和故障切换机制得到增强,确保了大规模集群的稳定运行。 另一方面,为应对云原生时代的挑战,Hadoop社区正积极将HDFS与Kubernetes等容器编排平台进行整合。如Open Data Hub项目就提供了在Kubernetes上部署HDFS及整个Hadoop生态系统的解决方案,使企业能够更加灵活高效地构建和管理基于云的大数据服务。 同时,对于那些寻求超越HDFS局限性的用户,可以关注到像Apache Hudi、Iceberg这样的开源项目,它们在HDFS之上构建了事务性数据湖存储层,支持ACID事务、时间旅行查询等功能,极大地丰富了大数据处理的可能性。 总之,掌握HDFS是理解和使用大数据技术的基础,而关注其演进路径以及相关的创新技术和解决方案,则有助于我们在实际应用中更好地利用HDFS及其生态系统的力量,解决日益复杂的数据管理和分析需求。
2023-12-05 22:55:20
276
转载
转载文章
...入策略,以降低因硬件故障、程序异常导致的数据损坏风险。同时,该版本还改进了WAL(Write Ahead Log)模式下的性能和可靠性,使得即使在高并发场景下也能更有效地防止数据库损坏。 此外,一些数据库管理工具如DB Browser for SQLite和SQLite Expert Personal等,也开始集成更为先进的数据库维护功能,如定期健康检查、自动修复及实时备份功能,这些都能够有效帮助开发者和用户在SQLite数据库出现问题时快速恢复数据,减少潜在的数据丢失风险。 值得注意的是,在实际应用中,结合云存储服务进行增量备份和容灾也是提升SQLite数据库安全性的有力手段。例如,将本地SQLite数据库定期同步至云端,并通过云端数据库的冗余备份和故障切换机制,能够在设备断电或App崩溃时,最大程度地保障用户数据的安全性和完整性。 总之,随着SQLite数据库技术的不断演进及其配套工具的日益完善,开发者们在面对数据库损坏问题时有了更多解决方案和选择,为移动应用尤其是聊天记录这类重要数据的持久化存储提供了更强有力的保障。在未来,继续关注SQLite的最新研究动态和技术革新,将是优化数据管理、提升用户体验的重要一环。
2023-11-23 18:22:40
127
转载
转载文章
...且可以通过键盘上下键切换命令。但是可以通过--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
转载
站内搜索
用于搜索本网站内部文章,支持栏目切换。
知识学习
实践的时候请根据实际情况谨慎操作。
随机学习一条linux命令:
fc -e -
- 打开编辑器编辑并重新执行上一条命令。
推荐内容
推荐本栏目内的其它文章,看看还有哪些文章让你感兴趣。
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
历史内容
快速导航到对应月份的历史文章列表。
随便看看
拉到页底了吧,随便看看还有哪些文章你可能感兴趣。
时光飞逝
"流光容易把人抛,红了樱桃,绿了芭蕉。"