前端技术
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
[Proxy ]的搜索结果
这里是文章列表。热门标签的颜色随机变换,标签颜色没有特殊含义。
点击某个标签可搜索标签相关的文章。
点击某个标签可搜索标签相关的文章。
转载文章
...nManager" proxy-target-class="true" /><aop:aspectj-autoproxy expose-proxy="true"/></beans> logback.xml <?xml version="1.0" encoding="UTF-8"?><!--scan:当此属性设置为true时,配置文件如果发生改变,将会被重新加载,默认值为true。scanPeriod:设置监测配置文件是否有修改的时间间隔,如果没有给出时间单位,默认单位是毫秒当scan为true时,此属性生效。默认的时间间隔为1分钟。debug:当此属性设置为true时,将打印出logback内部日志信息,实时查看logback运行状态。默认值为false。--><configuration scan="false" scanPeriod="60 seconds" debug="false"><!-- 定义日志的根目录 --><!-- <property name="LOG_HOME" value="/app/log" /> --><!-- 定义日志文件名称 --><property name="appName" value="netty"></property><!-- ch.qos.logback.core.ConsoleAppender 表示控制台输出 --><appender name="stdout" class="ch.qos.logback.core.ConsoleAppender"><Encoding>UTF-8</Encoding><!--日志输出格式:%d表示日期时间,%thread表示线程名,%-5level:级别从左显示5个字符宽度%logger{50} 表示logger名字最长50个字符,否则按照句点分割。 %msg:日志消息,%n是换行符--><encoder><pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern></encoder></appender><!-- 滚动记录文件,先将日志记录到指定文件,当符合某个条件时,将日志记录到其他文件 --> <appender name="appLogAppender" class="ch.qos.logback.core.rolling.RollingFileAppender"><Encoding>UTF-8</Encoding><!-- 指定日志文件的名称 --> <file>${appName}.log</file><!--当发生滚动时,决定 RollingFileAppender 的行为,涉及文件移动和重命名TimeBasedRollingPolicy: 最常用的滚动策略,它根据时间来制定滚动策略,既负责滚动也负责出发滚动。--><rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"><!--滚动时产生的文件的存放位置及文件名称 %d{yyyy-MM-dd}:按天进行日志滚动 %i:当文件大小超过maxFileSize时,按照i进行文件滚动--><fileNamePattern>${appName}-%d{yyyy-MM-dd}-%i.log</fileNamePattern><!-- 可选节点,控制保留的归档文件的最大数量,超出数量就删除旧文件。假设设置每天滚动,且maxHistory是365,则只保存最近365天的文件,删除之前的旧文件。注意,删除旧文件是,那些为了归档而创建的目录也会被删除。--><MaxHistory>365</MaxHistory><!-- 当日志文件超过maxFileSize指定的大小是,根据上面提到的%i进行日志文件滚动 注意此处配置SizeBasedTriggeringPolicy是无法实现按文件大小进行滚动的,必须配置timeBasedFileNamingAndTriggeringPolicy--><timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"><maxFileSize>100MB</maxFileSize></timeBasedFileNamingAndTriggeringPolicy></rollingPolicy><!--日志输出格式:%d表示日期时间,%thread表示线程名,%-5level:级别从左显示5个字符宽度 %logger{50} 表示logger名字最长50个字符,否则按照句点分割。 %msg:日志消息,%n是换行符--> <encoder><pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [ %thread ] - [ %-5level ] [ %logger{50} : %line ] - %msg%n</pattern></encoder></appender><!-- logger主要用于存放日志对象,也可以定义日志类型、级别name:表示匹配的logger类型前缀,也就是包的前半部分level:要记录的日志级别,包括 TRACE < DEBUG < INFO < WARN < ERRORadditivity:作用在于children-logger是否使用 rootLogger配置的appender进行输出,false:表示只用当前logger的appender-ref,true:表示当前logger的appender-ref和rootLogger的appender-ref都有效--><!-- <logger name="edu.hyh" level="info" additivity="true"><appender-ref ref="appLogAppender" /></logger> --><!-- root与logger是父子关系,没有特别定义则默认为root,任何一个类只会和一个logger对应,要么是定义的logger,要么是root,判断的关键在于找到这个logger,然后判断这个logger的appender和level。 --><root level="debug"><appender-ref ref="stdout" /><appender-ref ref="appLogAppender" /></root></configuration> 2、余额宝代码 package com.zhuguang.jack.controller;import com.alibaba.fastjson.JSONObject;import com.zhuguang.jack.service.OrderService;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.ResponseBody;@Controller@RequestMapping("/order")public class OrderController {/ @Description TODO @param @return 参数 @return String 返回类型 @throws 模拟银行转账 userID:转账的用户ID amount:转多少钱/@AutowiredOrderService orderService;@RequestMapping("/transfer")public @ResponseBody String transferAmount(String userId, String amount) {try {orderService.updateAmount(Integer.valueOf(amount), userId);}catch (Exception e) {e.printStackTrace();return "===============================transferAmount failed===================";}return "===============================transferAmount successfull===================";} } 消息监听器 package com.zhuguang.jack.listener;import com.alibaba.fastjson.JSONObject;import com.zhuguang.jack.service.OrderService;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.http.client.SimpleClientHttpRequestFactory;import org.springframework.stereotype.Service;import org.springframework.transaction.annotation.Transactional;import org.springframework.web.client.RestTemplate;import javax.jms.JMSException;import javax.jms.Message;import javax.jms.MessageListener;import javax.jms.ObjectMessage;@Service("queueMessageListener")public class QueueMessageListener implements MessageListener {private Logger logger = LoggerFactory.getLogger(getClass());@AutowiredOrderService orderService;@Transactional(rollbackFor = Exception.class)@Overridepublic void onMessage(Message message) {if (message instanceof ObjectMessage) {ObjectMessage objectMessage = (ObjectMessage) message;try {com.zhuguang.jack.bean.Message message1 = (com.zhuguang.jack.bean.Message) objectMessage.getObject();String userId = message1.getUserId();int count = orderService.queryMessageCountByUserId(userId);if (count == 0) {orderService.updateAmount(message1.getAmount(), message1.getUserId());orderService.insertMessage(message1.getUserId(), message1.getMessageId(), message1.getAmount(), "ok");} else {logger.info("异常转账");}RestTemplate restTemplate = createRestTemplate();JSONObject jo = new JSONObject();jo.put("messageId", message1.getMessageId());jo.put("respCode", "OK");String url = "http://jack.bank_a.com:8080/alipay/order/callback?param="+ jo.toJSONString();restTemplate.getForObject(url,null);} catch (JMSException e) {e.printStackTrace();throw new RuntimeException("异常");} }}public RestTemplate createRestTemplate() {SimpleClientHttpRequestFactory simpleClientHttpRequestFactory = new SimpleClientHttpRequestFactory();simpleClientHttpRequestFactory.setConnectTimeout(3000);simpleClientHttpRequestFactory.setReadTimeout(2000);return new RestTemplate(simpleClientHttpRequestFactory);} } package com.zhuguang.jack.service;public interface OrderService {public void updateAmount(int amount, String userId);public int queryMessageCountByUserId(String userId);public int insertMessage(String userId,String messageId,int amount,String status);} package com.zhuguang.jack.service;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.http.client.SimpleClientHttpRequestFactory;import org.springframework.jdbc.core.JdbcTemplate;import org.springframework.stereotype.Service;import org.springframework.transaction.annotation.Transactional;import org.springframework.web.client.RestTemplate;@Service@Transactional(rollbackFor = Exception.class)public class OrderServiceImpl implements OrderService {private Logger logger = LoggerFactory.getLogger(getClass());@AutowiredJdbcTemplate jdbcTemplate;/ 更新数据库表,把账户余额减去amountd/@Overridepublic void updateAmount(int amount, String userId) {//1、农业银行转账3000,也就说农业银行jack账户要减3000String sql = "update account set amount = amount + ?,update_time=now() where user_id = ?";int count = jdbcTemplate.update(sql, new Object[] {amount, userId});if (count != 1) {throw new RuntimeException("订单创建失败,农业银行转账失败!");} }public RestTemplate createRestTemplate() {SimpleClientHttpRequestFactory simpleClientHttpRequestFactory = new SimpleClientHttpRequestFactory();simpleClientHttpRequestFactory.setConnectTimeout(3000);simpleClientHttpRequestFactory.setReadTimeout(2000);return new RestTemplate(simpleClientHttpRequestFactory);}@Overridepublic int queryMessageCountByUserId(String messageId) {String sql = "select count() from message where message_id = ?";int count = jdbcTemplate.queryForInt(sql, new Object[]{messageId});return count;}@Overridepublic int insertMessage(String userId, String message_id,int amount, String status) {String sql = "insert into message(user_id,message_id,amount,status) values(?,?,?)";int count = jdbcTemplate.update(sql, new Object[]{userId, message_id,amount, status});if(count == 1) {logger.info("Ok");}return count;} } activemq.xml <?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:amq="http://activemq.apache.org/schema/core"xmlns:jms="http://www.springframework.org/schema/jms"xmlns:context="http://www.springframework.org/schema/context"xmlns:mvc="http://www.springframework.org/schema/mvc"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-4.1.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-4.1.xsdhttp://www.springframework.org/schema/mvchttp://www.springframework.org/schema/mvc/spring-mvc-4.1.xsdhttp://www.springframework.org/schema/jmshttp://www.springframework.org/schema/jms/spring-jms-4.1.xsdhttp://activemq.apache.org/schema/corehttp://activemq.apache.org/schema/core/activemq-core-5.12.1.xsd"><context:component-scan base-package="com.zhuguang.jack" /><mvc:annotation-driven /><amq:connectionFactory id="amqConnectionFactory"brokerURL="tcp://192.168.88.131:61616"userName="system"password="manager" /><!-- 配置JMS连接工长 --><bean id="connectionFactory"class="org.springframework.jms.connection.CachingConnectionFactory"><constructor-arg ref="amqConnectionFactory" /><property name="sessionCacheSize" value="100" /></bean><!-- 定义消息队列(Queue) --><bean id="demoQueueDestination" class="org.apache.activemq.command.ActiveMQQueue"><!-- 设置消息队列的名字 --><constructor-arg><value>zg.jack.queue</value></constructor-arg></bean><!-- 显示注入消息监听容器(Queue),配置连接工厂,监听的目标是demoQueueDestination,监听器是上面定义的监听器 --><bean id="queueListenerContainer"class="org.springframework.jms.listener.DefaultMessageListenerContainer"><property name="connectionFactory" ref="connectionFactory" /><property name="destination" ref="demoQueueDestination" /><property name="messageListener" ref="queueMessageListener" /></bean><!-- 配置JMS模板(Queue),Spring提供的JMS工具类,它发送、接收消息。 --><bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate"><property name="connectionFactory" ref="connectionFactory" /><property name="defaultDestination" ref="demoQueueDestination" /><property name="receiveTimeout" value="10000" /><!-- true是topic,false是queue,默认是false,此处显示写出false --><property name="pubSubDomain" value="false" /></bean></beans> OK~~~~~~~~~~~~大功告成!!!, 如果大家觉得满意并且对技术感兴趣请加群:171239762, 纯技术交流群,非诚勿扰。 本篇文章为转载内容。原文链接:https://blog.csdn.net/luoyang_java/article/details/84953241。 该文由互联网用户投稿提供,文中观点代表作者本人意见,并不代表本站的立场。 作为信息平台,本站仅提供文章转载服务,并不拥有其所有权,也不对文章内容的真实性、准确性和合法性承担责任。 如发现本文存在侵权、违法、违规或事实不符的情况,请及时联系我们,我们将第一时间进行核实并删除相应内容。
2023-04-16 22:34:52
499
转载
Kubernetes
...cker、kube-proxy和kubelet等。 Taint 和 Label , 在Kubernetes中,Label是用于对对象(如节点、Pods、服务等)进行分类和组织的关键字/值对,使得用户可以根据标签来选择和操作资源。而Taint则是节点的一个属性,带有特定taint的节点只能调度接受相应toleration(即能容忍该taint)的Pod,用以实现节点的亲和性和反亲和性策略。 Pod , 在Kubernetes中,Pod是最小的部署单元,它是容器的逻辑分组,代表集群上运行的一个进程及其存储资源。一个Pod中可以包含一个或多个紧密相关的容器,这些容器共享网络命名空间、IP地址以及存储卷,从而形成一个协同工作的应用程序单元。 kubectl , kubectl是Kubernetes提供的命令行工具,用于与集群进行交互,执行各种操作,例如创建、修改、删除资源对象,检查集群状态,以及获取日志和监控信息等。在处理Pod不在预期节点上运行的问题时,运维人员会频繁使用kubectl执行诸如查看节点状态、编辑DaemonSet配置、调整Pod数量等相关操作。
2023-04-13 21:58:20
207
夜色朦胧-t
Kubernetes
...起请求时,kube-proxy组件会负责转发请求到对应的Pod。 yaml apiVersion: v1 kind: Service metadata: name: my-service spec: selector: app: MyApp ports: - protocol: TCP port: 80 targetPort: 9376 上述YAML配置文件定义了一个名为my-service的Service,它会选择标签app=MyApp的所有Pod,并暴露80端口给外部,请求会被转发到Pod的9376端口。 2.2 kube-proxy的工作机制 kube-proxy是Kubernetes集群中用于实现Service网络代理的重要组件。有多种模式可选,如iptables、IPVS等,这里以iptables为例: - iptables:kube-proxy会动态更新iptables规则,将所有目标地址为目标Service ClusterIP的流量转发到实际运行Pod的端口上。这种方式下,集群内部的所有服务发现和负载均衡都是由内核级别的iptables规则完成的。 bash 这是一个简化的iptables示例规则 -A KUBE-SVC-XXXXX -d -j KUBE-SEP-YYYYY -A KUBE-SEP-YYYYY -m comment --comment "service/my-service" -m tcp -p tcp -j DNAT --to-destination : 3. DNS服务发现 除了通过IP寻址外,Kubernetes还集成了DNS服务,使得服务可以通过域名进行发现。每个创建的Service都会自动获得一个与之对应的DNS记录,格式为..svc.cluster.local。这样一来,应用程序只需要晓得服务的名字,就能轻松找到对应的服务地址,这可真是把不同服务之间的相互调用变得超级简便易行,就像在小区里找邻居串门一样方便。 4. 探讨与思考 Kubernetes的服务发现机制无疑为分布式系统带来了便利性和稳定性,它不仅解决了复杂环境中服务间互相定位的问题,还通过负载均衡能力确保了服务的高可用性。在实际做开发和运维的时候,如果能真正搞明白并灵活运用Kubernetes这个服务发现机制,那可是大大提升我们工作效率的神器啊,这样一来,那些烦人的服务网络问题引发的困扰也能轻松减少不少呢。 总结来说,Kubernetes的服务发现并非简单的IP映射关系,而是基于一套成熟且灵活的网络模型构建起来的,包括但不限于Service资源定义、kube-proxy的智能代理以及集成的DNS服务。这就意味着我们在畅享便捷服务的同时,也要好好琢磨并灵活运用这些特性,以便随时应对业务需求和技术挑战的瞬息万变。 以上就是对Kubernetes服务发现机制的初步探索,希望各位读者能从中受益,进一步理解并善用这一强大工具,为构建高效稳定的应用服务打下坚实基础。
2023-03-14 16:44:29
128
月影清风
Etcd
...d-metrics-proxy进行中间件代理以减轻Prometheus直接抓取Etcd数据的压力,并通过调整Raft算法参数以适应特定业务场景的读写需求。 为了进一步提升Etcd在故障排查及性能调优方面的实践指导,不少专家和博客作者分享了基于真实案例的深度分析文章,从实战角度剖析如何有效运用Etcd的内置诊断工具进行问题定位,以及如何借助压力测试工具模拟极端情况,确保Etcd在高并发场景下的高效稳定运行。 总之,在持续演进的云计算领域,Etcd作为关键基础设施的重要一环,其监视与诊断能力的发展和完善将直接影响到整个微服务体系的健壮性与可靠性。对于技术人员而言,紧跟Etcd的最新技术和最佳实践,无疑有助于构建和维护更加稳健高效的分布式系统。
2023-11-29 10:56:26
385
清风徐来
转载文章
...性视图 部署GTM Proxy实例,以提高性能 Postgre-XL主要组件 GTM (Global Transaction Manager) - 全局事务管理器 GTM是Postgres-XL的一个关键组件,用于提供一致的事务管理和元组可见性控制。 GTM Standby GTM的备节点,在pgxc,pgxl中,GTM控制所有的全局事务分配,如果出现问题,就会导致整个集群不可用,为了增加可用性,增加该备用节点。当GTM出现问题时,GTM Standby可以升级为GTM,保证集群正常工作。 GTM-Proxy GTM需要与所有的Coordinators通信,为了降低压力,可以在每个Coordinator机器上部署一个GTM-Proxy。 Coordinator --协调器 协调器是应用程序到数据库的接口。它的作用类似于传统的PostgreSQL后台进程,但是协调器不存储任何实际数据。实际数据由数据节点存储。协调器接收SQL语句,根据需要获取全局事务Id和全局快照,确定涉及哪些数据节点,并要求它们执行(部分)语句。当向数据节点发出语句时,它与GXID和全局快照相关联,以便多版本并发控制(MVCC)属性扩展到集群范围。 Datanode --数据节点 用于实际存储数据。表可以分布在各个数据节点之间,也可以复制到所有数据节点。数据节点没有整个数据库的全局视图,它只负责本地存储的数据。接下来,协调器将检查传入语句,并制定子计划。然后,根据需要将这些数据连同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
转载
MySQL
...mazon RDS Proxy、Azure Database for MySQL Flexible Server等,它们提供了细粒度的访问控制、负载均衡及日志审计等功能,有助于提升远程访问MySQL数据库的整体安全性。 总之,在实现MySQL数据库远程访问便利性的同时,务必重视并实施严格的安全措施,以确保数据库资源不被恶意利用,有效保障企业信息资产的安全。
2023-12-17 16:15:36
63
数据库专家
MySQL
... 1. MySQL Proxy:MySQL Proxy是一个轻量级的可插入的中间件,用于分发数据库负载,并实现复制和高可用性(HA)。它可以处理大量的并发连接和查询,并能够将这些请求转发到不同的MySQL数据库上。MySQL Proxy提供了可编程性,使其能够扩展和自定义,以适应不同的需求。 2. MySQL Cluster:MySQL Cluster是一个基于InnoDB存储引擎的面向事务的分散式数据库系统。它使用自己的数据节点和数据复制技术,实现平滑的水平扩展,提供高可用性和高可扩展性,支持分散式事务和分区表。MySQL Cluster尤其适合处理实时的在线业务应用,如电信、金融、电子商务等。 总之,MySQL的分散式是现代互联网应用的必备技术之一,它可以提高MySQL的可扩展性和高效能,同时也增加了系统的稳定性和可用性。对于需要处理大量读写请求和海量数据存储的应用,MySQL的分散式是一个非常好的解决方案。
2023-02-25 16:35:15
123
逻辑鬼才
Nginx
...ation / { proxy_pass http://localhost:8080; } } } 最后,我们可以通过运行以下命令来启动Nginx服务器: css docker build -t my-nginx . docker run -d --name my-nginx -p 80:80 my-nginx 现在,我们已经成功地使用Docker启动了一个Nginx服务器,并且可以通过访问http://localhost/来测试。 如何解决浏览器跨域问题? 为了能够在Nginx服务器上解决浏览器跨域问题,我们需要在nginx.conf文件中添加一些配置。具体来说,我们需要添加以下两个配置: javascript add_header 'Access-Control-Allow-Origin' ''; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; 这两个配置的作用分别是: Access-Control-Allow-Origin:指定允许跨域请求的来源。 Access-Control-Allow-Methods:指定允许跨域请求的方法。 注意,我们在location块中添加了proxy_pass指令,这个指令的作用是转发HTTP请求到另一个服务器。嘿,伙计,这次的情况是这样的,我们把请求给“嗖”地一下转送到了localhost那个家伙的8080端口上啦。 现在,我们已经成功地在Nginx服务器上解决了浏览器跨域问题。我们可以再次访问http://localhost/来测试。 总结 总的来说,使用Docker启动Nginx服务器是一种非常简单且有效的方式来解决浏览器跨域问题。只需要几个简单的步骤,咱们就能轻松搞定Nginx服务器的配置,让它帮咱们顺顺利利解决跨域这个小麻烦。而且,这种方式还可以让我们更方便地管理和扩展我们的应用程序。如果你还没有尝试过使用Docker和Nginx,那么我强烈建议你去试试看!
2023-11-18 17:50:15
154
断桥残雪_t
VUE
...例如,Vue 3采用Proxy替代Object.defineProperty进行数据绑定,使得响应式系统更加高效且能更好地处理数组变化。此外,Vue 3还提供了Teleport组件以实现跨组件定位内容,以及Suspense组件用于异步加载和状态管理,这些改进都为开发者构建复杂的Web应用程序提供了更多可能。 另一方面,在矢量图形动画方面,SVGA格式的应用也在不断拓宽边界。近期,许多知名移动应用开始采用SVGA格式优化动画效果,如在游戏启动画面、用户引导流程中提升用户体验。同时,随着5G时代的到来,为了满足用户对高质量视觉体验的需求,SVGA动画因其体积小、渲染效率高的特点,在AR/VR场景中的应用也逐渐崭露头角。不仅如此,开发社区围绕SVGA生态正在逐步完善,出现了诸多支持编辑、预览和播放SVGA动画的工具,大大降低了设计师与开发者的工作门槛。 综上所述,无论是Vue.js的持续迭代升级,还是SVGA格式在移动端动画领域的广泛采纳,都在印证着前端技术和用户体验设计日新月异的发展趋势。对于开发者来说,紧跟这些技术潮流,掌握并运用到实际项目中,无疑将有助于打造出更具竞争力的产品。
2023-01-11 22:10:45
97
程序媛
Beego
...网格中的Envoy Proxy就提供了丰富的路由规则配置,允许开发者根据请求元数据、头部信息、权重分配等多种条件进行动态路由决策,实现服务版本灰度发布、故障隔离等功能。 与此同时,Golang社区也在持续优化和完善其标准库net/http的路由功能。近期推出的httprouter库凭借高效的路由匹配算法和灵活的中间件支持,备受开发者青睐,成为了构建高性能Go Web服务的有力工具之一。 此外,在API设计和管理层面,诸如Swagger、OpenAPI等规范的广泛应用也进一步提升了路由设计的重要性。通过定义清晰的接口路径和参数结构,开发者可以方便地生成文档、执行自动化测试,并利用工具自动完成部分路由配置工作,从而提升整体项目质量和开发效率。 综上所述,路由设计已成为现代Web开发的核心环节之一,而像Beego这样的框架以及相关领域的最新发展,都在不断推动路由技术向更高效、智能的方向演进。对于开发者而言,紧跟行业趋势并熟练掌握各种路由机制,无疑将大大增强其在复杂项目中的应对能力和竞争力。
2023-04-05 20:57:26
552
林中小径-t
Nginx
...如,你瞧这三个参数:proxy_connect_timeout、proxy_send_timeout和proxy_read_timeout,如果它们没被咱们好好调教一番,设定得不恰当的话,那可就有戏看了——可能会闹腾出连接超时啊、丢包之类的问题,让人头疼得很呐。以下是这三个参数的作用和配置示例: 1. proxy_connect_timeout: 设置从客户端发起连接请求到Nginx成功接收并建立连接的时间限制。 示例: python proxy_connect_timeout 60; 2. proxy_send_timeout: 设置Nginx向后端服务器发送数据包的时间限制。 示例: python proxy_send_timeout 60; 3. proxy_read_timeout: 设置Nginx从后端服务器接收数据包的时间限制。 示例: python proxy_read_timeout 60; 四、网络环境问题 除了Nginx配置问题外,网络环境也可能导致tcping nginx端口出现超时丢包的现象。例如,网络拥塞、路由器故障等问题都可能导致这种情况的发生。为了避免出现这情况,我们可以采取一些实打实的招数来给咱的网络环境整整容、升升级。比如说,让带宽再宽绰点,路由节点再精简些,还有那个路由器的配置,也得好好捯饬捯饬,让它发挥出最佳效能。 五、解决办法 针对以上问题,我们提出以下几种解决办法: 1. 调整Nginx配置 通过合理设置proxy_connect_timeout、proxy_send_timeout和proxy_read_timeout这三个参数,可以有效地避免连接超时和丢包的问题。 2. 优化网络环境 通过优化网络环境,例如增加带宽、减少路由节点、优化路由器配置等,也可以有效避免tcping nginx端口出现超时丢包的问题。 3. 使用心跳包机制 如果您的应用支持心跳包机制,可以在Nginx和后端服务器之间定期发送心跳包,这样即使出现网络延迟或拥塞等情况,也不会导致连接丢失。 六、结语 总的来说,造成tcping nginx端口出现超时丢包的问题主要由Nginx配置不合理和网络环境问题引起。如果我们能恰到好处地调整Nginx的配置,再把网络环境好好优化一番,就能妥妥地把这些烦人的问题挡在门外,让它们无处发生。同时呢,采用心跳包这个小妙招也超级管用,无论啥情况,都能稳稳地让连接状态棒棒哒。希望这篇文章能对你有所帮助!
2023-12-02 12:18:10
192
雪域高原_t
Docker
...ation / { proxy_pass http://localhost:8080; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; } } 在这个示例中,我们将SpringBoot应用暴露在端口8080上,并通过Nginx将其映射到端口80上。 三、问题的出现与原因分析 然而,在实际的应用场景中,当我们试图在Docker Nginx中反向代理多个SpringBoot应用时,却可能遇到问题。具体来说,当我们在Nginx配置文件中指定了多个location块,每个block对应一个SpringBoot应用时,却发现只有第一个location块能够正常工作,而其他location块则无法访问。这是为什么呢? 经过分析,我们认为这个问题的主要原因是,Nginx在处理请求时,只会选择匹配的第一个location块来响应请求。换句话说,假如Nginx里头有多个location区域,甭管客户端用什么URL发送请求,Nginx都会优先挑中第一个对得上的location区域来处理这个请求。 四、解决方案 那么,我们该如何解决这个问题呢?其实,只需要稍作改动,就可以让Nginx能够正确地处理所有的location块。简单来说,我们可以在每个location区域前头,加一个“万能”location区域,它的作用就是抓住所有其他location没抓到的请求。就像是在门口安排一个接待员,专门接待那些其他部门都没接走的客人一样。以下是具体的示例: bash server { listen 80; server_name example.com; location /app1 { proxy_pass http://localhost:8081; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; } location ~ ^/(?!app1)(.)$ { proxy_pass http://localhost:8082; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; } } 在这个示例中,我们首先创建了一个匹配所有未被其他location块匹配的请求的location块,然后在其内部指定了第二个SpringBoot应用的proxy_pass设置。这样,无论客户端发送的请求URL是什么,Nginx都能够正确地处理它。 五、总结 总的来说,虽然Docker Nginx反向代理多个SpringBoot应用可能会遇到一些问题,但只要我们了解了问题的原因,并采取相应的措施,就能够有效地解决这些问题。所以,对广大的开发者盆友们来说,掌握Docker和Nginx这两门“武功秘籍”可是灰常重要的!
2024-01-24 15:58:35
617
柳暗花明又一村_t
SpringBoot
...ation / { proxy_pass http://127.0.0.1:8080; } } 这个配置的意思是,当用户访问example.com的时候,Nginx会将请求转发到127.0.0.1的8080端口。这样一来,外部的朋友们就可以直接通过example.com这个网址,轻轻松松地访问到我们的应用程序啦! 三、Nginx的SSL配置 接下来,我们将配置Nginx的SSL证书。首先,我们需要生成一个自签名的SSL证书。这可以通过openssl命令来完成。 csharp openssl req -newkey rsa:2048 -nodes -keyout key.pem -x509 -days 365 -out cert.pem 然后,我们需要在Nginx的配置文件中添加SSL的相关配置。 bash server { listen 443 ssl; server_name example.com; ssl_certificate cert.pem; ssl_certificate_key key.pem; location / { proxy_pass http://127.0.0.1:8080; } } 四、Spring Boot中的请求路径获取 在Spring Boot中,我们可以通过HttpServletRequest对象的getRequestURI()方法来获取请求的完整路径。例如: typescript @RequestMapping("/path") public String handlePath(HttpServletRequest request) { String path = request.getRequestURI(); return "Hello, " + path; } 五、总结 以上就是使用Nginx进行反向代理,并配置SSL证书,以及在Spring Boot中获取请求路径的方法。通过这种方式,我们可以实现一个安全且易于访问的应用程序。 六、参考资料 1. Nginx官方文档 https://nginx.org/en/docs/ 2. Spring Boot官方文档 https://docs.spring.io/spring-boot/docs/current/reference/html/ 感谢您的阅读!如果您有任何问题或建议,欢迎随时联系我。
2024-01-22 11:19:49
386
落叶归根_t
Java
...PI(组合API)和Proxy对象,以更高效、灵活的方式解决了变量引用问题。 Proxy是ES6提供的新特性,Vue3利用它代替了Vue2中的Object.defineProperty,能更全面地代理对象的所有属性,包括新增、删除属性等操作,使得Vue能够实时监测到深层次数据的变化。例如,在Vue3中,无论是直接替换引用类型还是修改深层次对象属性,都能准确触发视图更新。 此外,Vue3的Composition API允许开发者以更加模块化和可复用的方式组织代码,使得处理复杂状态逻辑时对变量引用的管理更为清晰和可控。通过setup函数可以更直观地定义响应式状态和相关逻辑,大大降低了因变量引用导致的视图更新问题。 因此,随着前端技术的发展和Vue框架自身的迭代更新,理解和掌握Vue3的响应式原理与API设计思路,不仅有助于解决旧版本中的变量引用问题,更能提升开发效率和应用性能,为构建高质量的现代Web应用提供有力支持。同时,深入学习这些内容也有助于我们在实际项目中更好地运用Vue进行复杂的业务场景开发,紧跟时代步伐,不断提升自己的技术水平。
2023-03-17 11:19:08
363
笑傲江湖_
Go Iris
...ang based proxy服务器“Katran”也分享了他们在设计和实施大规模服务优雅下线的经验,强调了状态同步、流量调度以及超时控制等方面的细致考量。 综上所述,理解并有效运用Graceful Shutdown不仅限于单个框架或语言环境,更需要结合当下云原生环境的特点及业界最佳实践,以提升整体系统的稳定性和用户体验。
2023-02-05 08:44:57
477
晚秋落叶
Nginx
...ation / { proxy_pass http://localhost:8080; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } } 这段配置做了两件事:一是监听80端口(即HTTP协议的标准端口),二是将所有请求转发到本地的8080端口。 4.4 测试并重启Nginx 配置完成后,我们需要测试配置是否正确,并重启Nginx服务: bash sudo nginx -t sudo systemctl restart nginx 4.5 验证配置 最后,打开浏览器访问http://example.com,如果一切正常,你应该能够看到你的Web应用,而不需要输入任何端口号! 5. 深入探讨 在这个过程中,我不得不感叹Nginx的强大。它不仅可以轻松地完成反向代理的任务,还能帮助我们解决很多实际问题。当然啦,Nginx 能做的可不仅仅这些呢。比如说 SSL/TLS 加密和负载均衡,这些都是挺有意思的玩意儿,值得咱们好好研究一番。 6. 结语 通过今天的分享,希望大家对如何使用Nginx反向代理来隐藏端口号有了更深入的理解。虽说配置起来得花些时间和耐心,但等你搞定后,肯定会觉得这一切都超级值!说到底,让用户体验更贴心、更简便,这可是咱们每个程序员努力的方向呢!希望你们也能在自己的项目中尝试使用Nginx,体验它带来的便利!
2025-02-07 15:35:30
111
翡翠梦境_
SpringCloud
...件间的协作。 代理(Proxy) , 在计算机科学中,尤其是在面向对象编程领域,代理是一个设计模式,它为另一个对象提供一种替代或补充功能。在Spring框架中,当@Configuration类被代理时,实际上是创建了一个代理对象,这个代理对象在方法调用时会执行额外的逻辑(如拦截器),同时保持对原始对象的引用以便必要时调用其原有方法。
2023-10-23 20:18:43
128
海阔天空_t
VUE
...之一,它通过ES6的Proxy或Object.defineProperty等机制实现数据绑定。在Vue应用中,当数据发生变化时,响应式系统能自动、高效地追踪到依赖于这些数据的组件,并触发相应的视图更新,从而确保视图与数据始终保持一致。 Diff算法 , Diff算法是Vue在进行虚拟DOM更新时所采用的一种高效的比较算法。当数据变化引起组件需要重新渲染时,Vue不会直接操作真实DOM,而是创建一个新的虚拟DOM树并与旧的进行比较(即执行Diff算法)。这个过程能够找出最小化的DOM更新操作,只对真正发生变化的部分进行实际DOM节点的更新,极大提高了页面渲染性能。 虚拟DOM , 虚拟DOM(Virtual DOM)是一种编程概念,它是实际DOM结构在内存中的抽象表示。Vue.js会将组件渲染为虚拟DOM树,这样在状态改变时,Vue可以先对比新旧虚拟DOM树的差异,然后仅针对有变化的部分更新真实DOM,而不是每次都完全重新渲染整个页面。这一技术有效减少了DOM操作的频率,提升了前端应用的性能表现。 生命周期钩子 , 在Vue组件中,生命周期钩子是一系列预定义的函数,它们会在组件的不同阶段被Vue自动调用。例如created、mounted、updated和beforeDestroy等。开发者可以通过编写相应生命周期钩子里的业务逻辑来控制组件的行为,如初始化数据、添加事件监听器、执行DOM操作或清理资源等。过度频繁的生命周期调用可能导致性能下降,因此合理利用生命周期钩子是Vue应用优化的重要环节。 动态导入(异步组件) , Vue.js支持动态导入功能,允许开发者按需加载组件,以提高大型项目中的初始加载速度和运行效率。通过使用JavaScript动态import()语法,组件在实际需要渲染时才会被加载,而非一次性加载所有组件资源。这种按需加载的方式可以显著减少首次加载时的数据传输量,改善用户体验,特别是对于包含大量组件和模块的单页面应用来说至关重要。
2023-02-07 14:18:17
138
落叶归根
Nginx
...ation / { proxy_pass http://backend; } } } 在这个配置文件中,我们定义了一个名为backend的上游服务器组,它包含两个后端服务器。然后,在server块中,我们指定了监听80端口,并将所有请求转发到backend组。这样一来,当客户端的请求找到Nginx时,Nginx就会按照负载均衡的规则,把请求派给后端的服务器们去处理。 4. Nginx的高级功能 定制化与扩展性 Nginx不仅仅是一个基本的反向代理服务器,它还提供了许多高级功能,可以满足各种复杂的需求。比如说,你可以用Nginx来搞缓存,这样就能少给后端服务器添麻烦,减轻它的负担啦。以下是一个简单的缓存配置示例: nginx location /images/ { proxy_cache my_cache; proxy_cache_valid 200 1h; proxy_pass http://backend; } 在这个配置中,我们定义了一个名为my_cache的缓存区,并设置了对200状态码的响应缓存时间为1小时。这样一来,对于那些静态资源比如图片,Nginx会先看看缓存里有没有。如果有,就直接把缓存里的东西给用户,根本不需要去后台问东问西的。 5. 总结与展望 Nginx带给我的启示 通过这段时间的学习和实践,我对Nginx有了更深入的理解。这不仅仅是个能扛事儿的Web服务器和反向代理,还是应对高并发访问的超级神器呢!在未来的项目中,我相信Nginx还会继续陪伴着我,帮助我们应对各种挑战。希望这篇分享能对你有所帮助,如果你有任何问题或想法,欢迎随时交流! --- 希望这篇文章能够帮助你更好地理解和使用Nginx。如果你有任何疑问或想要了解更多细节,请随时提问!
2025-01-17 15:34:14
70
风轻云淡
PHP
...nset http_proxy https_proxy composer config -g secure-http false composer clear-cache composer require vendor/package 3. 权限问题引发的报错 示例情况: bash [RuntimeException] The HOME or COMPOSER_HOME environment variable must be set for composer to run correctly 解析与解决: 当Composer没有足够的权限去读写必要的文件或目录时,就会出现这样的错误。确保你以具有足够权限的用户身份运行Composer命令,或者直接修改相关目录的权限: bash sudo chown -R $USER:$USER ~/.composer composer require vendor/package 4. 版本冲突引发的报错 示例情况: bash Your requirements could not be resolved to an installable set of packages. Problem 1 - Root composer.json requires packageA ^1.2 -> satisfiable by packageA[1.2.0]. - packageB v2.0.0 requires packageA ^2.0 -> no matching package found. - Root composer.json requires packageB ^2.0 -> satisfiable by packageB[v2.0.0]. 解析与解决: 这种报错意味着你试图安装的组件之间存在版本兼容性问题。你需要根据错误提示调整composer.json中的版本约束,例如: json { "require": { "packageA": "^1.2 || ^2.0", "packageB": "^2.0" } } 然后重新运行 composer update 或 composer install 来解决版本冲突。 5. 结语 拥抱挑战,不断探索 在面对Composer安装组件时的种种“小插曲”,身为PHP开发者的我们不仅要学会及时解决问题,更要在每一次调试中积累经验,理解Composer背后的工作原理,从而更加游刃有余地驾驭这一强大工具。毕竟,编程这趟旅程可不是全程顺风顺水的,正是这些时不时冒出来的小挑战、小插曲,才让我们的技术探索之路变得丰富多彩,充满了思考琢磨、不断成长的乐趣和惊喜。
2023-06-18 12:00:40
85
百转千回_
Java
...avaScript Proxy、React Hooks等特性实现对组件样式的细粒度控制。而它们与Java后端服务的数据绑定,则可以通过RESTful API、GraphQL等方式实现,进一步提升了样式切换乃至整个应用状态管理的响应速度与用户体验。 此外,在微前端架构中,Java后端服务还可作为一个集中式的服务端,统一管理和分发不同前端应用的样式资源,通过模块化加载策略优化样式切换时的性能表现。而在即将来临的WebAssembly时代,Java等后端语言甚至有望直接参与到前端计算与DOM操作中,彻底打破前后端的边界,实现更为深度的样式控制与切换。 因此,深入研究这些前沿技术和最佳实践,将有助于我们更好地理解和掌握Java在Web样式切换乃至整个全栈开发流程中的角色演变和实际应用。
2023-08-26 16:47:56
317
人生如戏_
Java
...是一个在使用Vue proxy Table转发数据时总是报错504的问题。这个问题我也是在一段时间前遇到了,当时也花了不少时间去解决。然而,当我把这个问题给攻克之后,我真是打心眼里感受到了解决问题的那种爽歪歪的乐趣,而且实实在在地感觉自己技术水平也有了一个质的飞跃,就像升级打怪一样,level up了! 二、问题背景 我们在进行Vue项目开发时,有时候需要将数据从后台获取到前端展示。这就需要用到proxyTable来进行数据转发。proxyTable是Vue-cli提供的一种用于开发环境的数据代理工具,它可以在本地模拟请求服务器端数据,让我们在没有实际服务器的情况下也能进行开发和调试。 然而,在使用proxyTable转发数据时,我们可能会遇到各种各样的问题。其中,最常见的问题就是报错504了。这个错误出现,多半是因为服务器“罢工”啦,它表示我们请求的时间太长,超出了它的忍耐限度——最大等待时间,于是乎,服务器就不得不狠心地把我们的请求给“拒之门外”了。 三、解决方案 对于这个问题,我们首先要做的就是找到问题的根源。一般来说,报错504的原因有两个:一是服务器响应时间过长;二是网络连接问题。这两个问题都需要我们一一排查。 首先,我们需要检查一下服务器的响应时间。这可以通过浏览器的开发者工具来查看。如果发现服务器的反应速度有点慢,就像个老人家在处理复杂问题似的磨磨蹭蹭,那我们就得琢磨琢磨了,是不是该给服务器“动个小手术”,提升一下它的性能呢?或者,也可能是请求参数设置得不太对劲儿,需要我们适当调整一下,让它变得更加灵活高效。 其次,我们需要检查一下网络连接。这可以通过ping命令或者traceroute命令来查看。如果发现网络连接有问题,那么我们就需要尝试修复网络连接。 四、实战演练 好了,理论讲完了,下面我们来通过一个具体的例子来看看如何解决这个问题。想象一下,如果我们从后台得到的数据打包成了一个JSON格式的小礼物,我们现在想要把这个小礼物传递给前端,让他们展示出来。下面是我使用的代码: java const router = new VueRouter({ mode: 'history', routes: [ { path: '/', name: 'home', component: Home, meta: { requireAuth: true } }, { path: '/users', name: 'users', component: Users, meta: { requireAuth: true } }, { path: '/login', name: 'login', component: Login } ] }) 在这段代码中,我们可以看到我们在创建路由实例时,传入了一个名为router的变量。这个变量实际上是我们之前定义的一个Vue Router实例。 五、总结 总的来说,处理这个问题的关键是要找到问题的根源,并针对性地进行解决。如果你也碰到了类似的问题,不如就试试我刚刚说的那些办法吧,我打包票,你肯定能顺利解决掉这个问题哒! 六、结语 通过这篇文章,我想让大家明白一个问题:编程不仅仅是编写代码,更重要的是解决问题。每一次解决问题都是一次学习的机会,都能让我们变得更加优秀。所以,甭管你在捣鼓编程的时候遇到啥头疼的问题,都千万别轻易举白旗投降啊!一定要咬紧牙关坚持到底,信我,到时候你绝对会发现,你付出的每一份努力,都会像种下的种子一样,结出满满的果实来回报你。
2023-03-05 23:22:24
343
星辰大海_t
站内搜索
用于搜索本网站内部文章,支持栏目切换。
知识学习
实践的时候请根据实际情况谨慎操作。
随机学习一条linux命令:
netcat -l -p port_number
- 启动监听特定端口的简单服务器。
推荐内容
推荐本栏目内的其它文章,看看还有哪些文章让你感兴趣。
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
历史内容
快速导航到对应月份的历史文章列表。
随便看看
拉到页底了吧,随便看看还有哪些文章你可能感兴趣。
时光飞逝
"流光容易把人抛,红了樱桃,绿了芭蕉。"