前端技术
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
[GUID 全局唯一标识符 ]的搜索结果
这里是文章列表。热门标签的颜色随机变换,标签颜色没有特殊含义。
点击某个标签可搜索标签相关的文章。
点击某个标签可搜索标签相关的文章。
转载文章
...“卓越性能”模式。 GUID(全局唯一标识符) , 全局唯一标识符是一种由算法生成的长度固定、格式确定、保证全球唯一的字符串型标识符。在文章中提到的“电源方案 GUID”,指的是操作系统内部用于区分不同电源计划的独特标识,例如。 “卓越性能”模式 , 这是Windows 10操作系统中的一项高级电源管理模式,专为高性能硬件配置和专业应用场景设计,如企业版和工作站版用户。该模式旨在优化系统资源调度,减少不必要的后台活动,从而最大化提升处理器、内存和存储设备等硬件组件的性能表现,尤其适用于处理大量数据、进行复杂计算或运行高性能软件的专业场景。普通家庭版、商用版、专业版或教育版用户默认情况下无法看到此模式选项,但可通过特定命令开启。
2023-06-26 12:46:08
385
转载
Beego
...中,我们常常需要生成全局唯一的标识符,也就是我们常说的UUID。UUID是一个128位的数字,可以用来表示一个特定的对象。在Go语言中,我们可以使用标准库中的math/rand包和time包来生成UUID。 go import ( "crypto/rand" "encoding/hex" "math/big" "time" ) func NewUUID() string { var b [16]byte _, err := rand.Read(b[:]) if err != nil { panic(err) } now := time.Now().UnixNano() b[6] = byte((now >> 40) & 0xf) b[7] = byte(now >> 32) b[8] = byte(now >> 24) b[9] = byte(now >> 16) b[10] = byte(now >> 8) b[11] = byte(now) return hex.EncodeToString(b[:]) } 二、自增ID生成 自增ID是一种常见的数据库主键生成方式,它通过不断增加一个整数值来保证数据的唯一性。在Beego这个框架里头,如果你想实现自动增长ID的功能,完全可以这样做:先定义一个模型,然后在这个模型里头添加一个类型为uint的ID字段,这就搞定了自增ID的需求。就像是给每一条记录分配一个独一无二的数字身份证一样,每次新增记录时,这个ID会自动加一,省去了手动指定ID的麻烦。 go type User struct { ID uint orm:"column(id);auto" Name string Email string Phone string Address string } 以上代码中,我们在User模型中定义了一个名为ID的字段,并设置了它的类型为uint和auto。这样,每次插入一条新的用户记录时,ID字段都会自动递增。 三、UUID和自增ID的选择 在实际开发中,我们常常需要根据具体的需求来选择生成哪种类型的ID。如果我们正在捣鼓一个分布式系统,那么选用UUID绝对是个更酷的选择。为啥呢?因为它可以在全球这个大舞台上保证每个ID都是独一无二的,就像每个人都有自己的指纹一样独特。假如我们正在捣鼓一个单机应用,那么选择自增ID可能是个更省心省力的办法。为啥呢?因为它生成的速度贼快,而且出岔子的概率也低得多,这样一来,我们就不用在这方面费太多心思啦! 四、总结 总的来说,生成UUID或自增ID是我们在开发Web应用时经常会遇到的问题。在Beego中,我们可以通过简单的代码就能实现这两种ID的生成。不过呢,具体要用哪种类型的ID,咱们还得根据实际需求来掂量决定。无论我们挑哪一个,只要能把数据的唯一性和安全性稳稳地守住,那就都是个没毛病的选择。
2023-11-17 22:27:26
589
翡翠梦境-t
转载文章
...在特定场景下,如遇到唯一键冲突时可能导致自增ID不连续的问题。近期,针对这一问题,有数据库专家和开发者们展开了深入探讨。 实际上,MySQL官方社区以及相关技术博客对此类问题已有多种解决方案提出。例如,除了文中提及的在每次插入操作后动态调整AUTO_INCREMENT值的方法外,还有一种观点是通过重构数据库设计,将自增ID与业务逻辑解耦,采用UUID或其他全局唯一标识符替代自增主键,以减少对连续性的依赖。同时,随着MySQL 8.0版本的发布,新增了序列(SEQUENCE)对象,提供了一种更为灵活的方式来生成唯一的序列号,可用于解决自增主键不连续的问题。 此外,在数据库优化方面,对于高并发环境下的插入操作,如何确保自增主键的连续性和唯一性变得更加复杂。一些大型互联网公司采用了分布式ID生成策略,如雪花算法(Snowflake),能够在分布式环境下实现高效且有序的ID生成,从而避免因单点故障或并发写入导致的自增主键断层。 值得注意的是,无论采取何种解决方案,都需要根据实际应用场景、数据量大小、并发访问量及性能需求等因素综合考虑。同时,理解并遵循数据库设计范式,合理规划表结构,也有助于从根本上减少此类问题的发生。总之,面对MySQL或其他数据库系统中的自增主键连续性挑战,持续关注最新的数据库技术和最佳实践,结合自身项目特点选择最优方案,才能确保系统的稳定、高效运行。
2023-08-26 08:19:54
92
转载
转载文章
...迁出即可 某些外键、唯一性约束功能 Postgres-XL架构 [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-M9lFuEIP-1640133702200)(./assets/postgre-xl.jpg)] 基于开源项目Postgres-XC XL增加了MPP,允许数据节点间直接通讯,交换复杂跨节点关联查询相关数据信息,减少协调器负载。 多个协调器(Coordinator) 应用程序的数据库连入点 分析查询语句,生成执行计划 多个数据节点(DataNode) 实际的数据存储 数据自动打散分布到集群中各数据节点 本地执行查询 一个查询在所有相关节点上并行查询 全局事务管理器(GTM:Global Transaction Manager) 提供事务间一致性视图 部署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
转载
PostgreSQL
...键功能,尤其对于需要唯一标识符的应用场景,如交易流水号、用户ID等。PostgreSQL的序列生成器功能强大且灵活,但在实际应用中,开发者还应考虑其并发环境下的性能和安全性问题。 近期,PostgreSQL官方社区发布了一篇深度技术文章,针对高并发场景下如何优化序列生成器的使用进行了探讨。文中指出,在多线程或多进程环境下,虽然序列生成器能确保生成的数字唯一,但如果不采取适当的并发控制策略,可能会导致序列号之间的间隙增大或序列生成效率降低。为此,建议采用“缓存”策略(例如通过设置CACHE大小),预先生成一组序列号,从而减少对序列对象的争用,提高并发性能。 此外,对于分布式系统中的全局唯一序列号生成需求,PostgreSQL提供的逻辑复制功能可以与序列生成器结合,实现跨多个数据库节点的全局唯一序列号分配。但这一过程涉及更复杂的架构设计与配置,开发者需深入理解并合理运用。 综上所述,尽管PostgreSQL的序列生成器为开发者提供了便利,但在实际应用时还需根据具体业务场景进行针对性优化,并时刻关注社区发布的最新技术动态,以便更好地利用数据库特性,提升系统的稳定性和性能。
2023-04-25 22:21:14
77
半夏微凉-t
CSS
...圾”,赶走那个捣乱的全局变量,防止它到处乱窜把环境搞得一团糟,这样一来,大家伙儿干活儿时碰到冲突的机会就大大减少了。而且,这样做还能让团队协作变得更加溜,效率蹭蹭往上涨,就像咱们一起打游戏时配合得那叫一个天衣无缝,懂吧? 三、CSS模块化的基本概念 为了更好地理解和应用CSS模块化,我们需要了解以下几个基本概念: 1. CSS模块化文件 这是由一组相关的CSS规则组成的文件,通常具有一个特定的功能或者主题。 2. CSS模块化名称 每个CSS模块都有一个唯一的名称,用于标识这个模块。 3. CSS模块化引入 在HTML中,我们可以使用CSS模块化导入语句来引入其他模块的CSS样式。 四、CSS模块化配置步骤 以下是使用CSS模块化进行配置的基本步骤: 1. 创建CSS模块化文件 首先,我们需要创建一个新的CSS文件作为我们的模块化入口。嘿,你知道吗,在这个文件里,我们可以随心所欲地定制一些基础样式,就像是给文档穿上衣服、化妆打扮一样,比如可以捣鼓捣鼓页面的整体布局呀,字体的选用搭配啥的,都由咱们说了算! css / style.css / body { font-family: Arial, sans-serif; } .container { max-width: 800px; margin: 0 auto; } 2. 划分CSS模块 接下来,我们将把上述通用样式划分为不同的模块。在这里,我们将创建两个新的CSS文件:header.css和footer.css,分别用于定义头部和尾部的样式。 css / header.css / .header { background-color: f8f9fa; padding: 20px; } .header h1 { color: 6c757d; } / footer.css / .footer { background-color: 343a40; padding: 20px; } .footer p { color: fff; } 3. 定义CSS模块化名称 然后,我们需要给每个模块命名。在这个例子中,我们将头部和尾部的模块命名为header和footer。 4. 导入CSS模块化文件 最后,我们在需要使用这些模块的地方导入它们。这里,我们在index.html文件中导入了这两个模块。 html Document 这就是使用CSS模块化进行配置的基本步骤。你可以根据自己的需求,继续划分更多的模块,或者添加更多的样式。 五、总结 总的来说,CSS模块化是一个非常有用的工具,它可以帮助我们更有效地管理复杂的CSS项目。不过呢,要想把CSS模块化的好处全榨出来,咱们可得花点时间去研究和动手实践才行。我希望这篇文章能对你有所帮助,让你能够更快地掌握CSS模块化。
2023-02-21 14:04:27
464
幽谷听泉_t
PostgreSQL
...区进行维护和优化。 唯一索引 , 唯一索引是一种特殊的索引类型,用于确保索引字段中的所有值都是唯一的,即不允许出现重复值。在创建唯一索引后,数据库会自动阻止插入包含重复键值的新记录,从而有效保证了数据的一致性和完整性。在实际应用中,特别是在主键或其他需要唯一标识符的场景下,使用唯一索引能够避免数据冗余,同时也能在一定程度上提高相关查询的性能。
2023-06-12 18:34:17
502
青山绿水-t
Python
...位和访问列表内元素的唯一标识符。列表的索引是从0开始计数的整数,正索引表示从左向右读取元素的位置,而负索引则从右向左计数,-1表示最后一个元素。例如,在代码index = my_list.index(7)中,index变量将被赋值为列表my_list中数字7首次出现的索引位置,即它的索引编号。
2023-10-05 18:16:18
359
算法侠
Hadoop
...数据时,可以使用一个唯一的ID来标识每个数据项。这样就可以确保每个数据项只被写入一次。 python import uuid 生成唯一ID id = str(uuid.uuid4()) 2. 使用事务 在某些情况下,可以使用数据库事务来确保数据的一致性。这可以通过设置数据库的隔离级别来实现。 sql START TRANSACTION; INSERT INTO table_name (column1, column2) VALUES ('value1', 'value2'); COMMIT; 3. 使用MapReduce的输出去重特性 Hadoop提供了MapReduce的输出去重特性,可以在Map阶段就去除重复的数据,然后再进行Reduce操作。 java public static class MyMapper extends Mapper { private final static IntWritable one = new IntWritable(1); private Text word = new Text(); public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException { String[] words = value.toString().split(" "); for (String word : words) { word = word.toLowerCase(); if (!word.isEmpty()) { context.write(new Text(word), one); } } } } 以上就是关于Hadoop中的数据写入重复的一些介绍和解决方案。希望对你有所帮助。
2023-05-18 08:48:57
507
秋水共长天一色-t
转载文章
...&B)颁发的一种全球唯一标识符,用于对企业、组织和个人进行身份验证和管理。在iOS开发中,申请邓白氏编码可以帮助开发者更好地识别和管理其应用程序。本篇文章将详细介绍在iOS平台上申请邓白氏编码的流程,并提供相应的Java源代码作为演示。 步骤一:注册DUNS账号 首先,您需要在D&B官方网站注册一个DUNS账号。打开D&B官方网站并按照指引填写相关信息。完成注册后,您将获得一个唯一的DUNS账号。 步骤二:准备材料 在申请邓白氏编码之前,您需要准备一些必要的材料: 企业相关信息:包括企业名称、地址、法定代表人信息等。 联系人信息:提供能与您联系的邮箱地址、电话号码等。 营业执照或注册证明:提供企业的官方注册证明材料。 步骤三:填写申请表格 登录D&B官方网站,进入邓白氏编码申请页面。根据页面指引,填写相应的申请表格。在表格中准确地填写企业信息、联系人信息等。 步骤四:提交申请 在完成申请表格后,检查所有填写的信息是否正确无误。确认无误后,点击提交申请按钮。 步骤五:审核与确认 提交申请后,D&B将对您的申请进行审核。这个过程可能需要一定时间,请耐心等待。一旦审核通过,您将收到一封确认邮件,并获得您的邓白氏编码。 通过以上步骤,您已成功申请到了邓白氏编码。 本篇文章为转载内容。原文链接:https://blog.csdn.net/CodeJolt/article/details/132261815。 该文由互联网用户投稿提供,文中观点代表作者本人意见,并不代表本站的立场。 作为信息平台,本站仅提供文章转载服务,并不拥有其所有权,也不对文章内容的真实性、准确性和合法性承担责任。 如发现本文存在侵权、违法、违规或事实不符的情况,请及时联系我们,我们将第一时间进行核实并删除相应内容。
2024-03-15 12:18:54
507
转载
Redis
...中"uid"是用户的唯一标识符。 当用户访问一篇文章时,我们可以通过查询"news:articleX"这个键的值来获取文章的阅读状态。如果这个键的值为空,则表示用户还未阅读过这篇文章。反之,如果这个键的值不为空,则表示用户已经阅读过这篇文章。 接下来,我们可以通过修改"news:articleX"这个键的值来更新文章的阅读状态。比如,当咱发现有用户已经阅读过某篇文章了,咱们就可以把这篇文章对应的键值标记为"true",就像在小本本上做个记号一样。换种说法,假如我们发现用户还没读过某篇文章呢,那咱们就可以干脆把这篇文章对应的键的值清空掉,让它变成空空如也。 四、代码示例 下面是一个使用Python实现的简单示例: python import redis 创建Redis客户端对象 r = redis.Redis(host='localhost', port=6379, db=0) 获取文章的阅读状态 def get_article_read_status(article_id): key = f'news:{article_id}:read_status' return r.get(key) is not None 更新文章的阅读状态 def set_article_read_status(article_id, read_status): key = f'news:{article_id}:read_status' if read_status: r.set(key, 'true') else: r.delete(key) 五、总结 通过上述介绍,我们可以看到,使用Redis作为阅读状态数据库是一种非常可行的方法。它可以方便地存储和管理用户的阅读状态,而且因为Redis的特性,它的性能非常高,可以很好地应对高并发的情况。 当然,这只是一个基本的设计方案,实际的应用可能还需要考虑更多的因素,例如安全性、稳定性、可扩展性等等。不管咋说,Redis这款数据库工具真心值得我给你安利一波。它可是能实实在在地帮我们简化开发过程,这样一来,咱就能把更多的心思和精力花在琢磨业务逻辑上,让工作更加高效流畅。
2023-06-24 14:53:48
332
岁月静好_t
Kafka
...入复制组时必须指定的唯一标识符。 - replication.factor: 用于指定每个Partition的副本数量,也就是在一个复制组中,每个Partition应该有多少个副本。 - inter.broker.protocol.version: 用于指定跨数据中心复制时使用的网络协议版本。 四、使用Kafka API进行跨数据中心复制 除了通过配置文件进行跨数据中心复制之外,还可以直接使用Kafka的API进行手动操作。具体步骤如下: 1. 在生产者端,调用send()方法发送消息到Leader节点。 2. Leader节点接收到消息后,将其复制到所有的Follower节点。 3. 在消费者端,从Follower节点获取消息并进行处理。 五、总结 总的来说,通过设置Kafka的复制组参数和使用Kafka的API接口,我们可以轻松地实现在跨数据中心之间的数据复制。而且你知道吗,Kafka有个超赞的Replication机制,这玩意儿就像给数据上了个超级保险,让数据的安全性和稳定性杠杠的。哪怕某个地方突然出了状况,单点故障了,也能妥妥地防止数据丢失,可牛掰了! 六、致谢 感谢阅读这篇关于如何确保Kafka的跨数据中心复制的文章,如果您有任何疑问或建议,请随时与我联系,我将竭诚为您服务!
2023-03-17 20:43:00
531
幽谷听泉-t
Go-Spring
...属性指定bean的唯一标识符,class属性指定了bean的实现类。标签则用来设置bean的属性值。 3. XMLbean定义文件常见语法错误分析 错误示例一: xml ... 上述代码中,我们在定义class属性时忘记用双引号将其包围,这会导致XML解析器无法正确识别属性值,从而引发语法错误。 错误示例二: xml 在这个例子中,标签没有被正确关闭,这也是XML语法错误的一种常见表现。 4. 解决方案与实战演练 面对这些XMLbean定义文件的语法错误,我们需要遵循XML的基本语法规则来进行修正: - 确保属性值始终被引号包围 xml - 保证所有标签均有正确的开闭配对 xml 在整个排查和修复过程中,我们可以借助IDE的XML语法检查工具或在线XML校验器来辅助查找问题。同时,养成良好的编码习惯,例如使用清晰的缩进和注释,也能帮助我们在编写XMLbean定义文件时减少出错的可能性。 5. 结语 对于Go-Spring开发者而言,熟练掌握XMLbean定义文件的编写规范至关重要。面对语法错误,我们要善于运用各种工具和技术手段快速定位并解决问题。只有这样,才能充分发挥Go-Spring框架的优势,提升开发效率,构建更为稳定、高效的软件系统。下一次当你遭遇XMLbean定义文件的“拦路虎”时,希望这篇充满情感化和探讨性话术的文章能帮你轻松化解困境!
2023-04-04 12:42:35
472
星河万里
ActiveMQ
...java // 使用唯一标识符来避免重复消费 TextMessage message = session.createTextMessage("Hello, World!"); message.setJMSMessageID(UUID.randomUUID().toString()); producer.send(message); 6.2 预防措施 为了避免数据不一致,我们可以: - 使用唯一标识符:为每条消息添加一个唯一的标识符,以便识别重复消息。 - 保证消息顺序:确保消息按照正确的顺序被处理。 java // 使用事务来保证消息顺序 Session session = connection.createSession(true, Session.SESSION_TRANSACTED); // 发送多条消息 for (int i = 0; i < 10; i++) { TextMessage message = session.createTextMessage("Message " + i); producer.send(message); } // 提交事务 session.commit(); 7. 结论 总之,ActiveMQ是一个功能强大的消息队列工具,但在使用过程中需要特别注意故障恢复策略。通过巧妙设置持久化方式和消息确认系统,我们能大幅减少数据丢失的几率。另外,用唯一标识符和事务来确保消息顺序,这样就能很好地避免数据打架的问题了。希望这篇文章能够帮助大家更好地理解和应对ActiveMQ中的这些问题。如果你有任何疑问或建议,欢迎在评论区留言交流! --- 这篇文章力求通过具体的代码示例和实际操作,帮助读者更好地理解和解决ActiveMQ中的故障恢复问题。希望它能对你有所帮助!
2025-02-06 16:32:52
22
青春印记
Java
...url等)生成的一串唯一标识符。这串签名用于前端与微信服务器进行交互时的身份验证,确保数据在传输过程中未被篡改,只有正确的签名才能使微信JS-SDK的功能得以正常使用。 SHA-1 , SHA-1(Secure Hash Algorithm 1)是一种广泛使用的加密散列函数,它将任意长度的数据映射为固定长度(160位)的哈希值,也称为“数字指纹”。在文中,SHA-1作为生成微信JS-SDK签名的加密算法,通过对拼接好的字符串进行SHA-1计算,得到一个唯一的签名值,以确保数据的安全性及防止数据被恶意篡改。由于原文中提到Java代码片段使用了SHA-1算法来生成签名,因此在这个语境下,SHA-1的作用尤为关键。
2023-09-10 15:26:34
315
人生如戏_
Nacos
...,每个配置项都有一个唯一标识符,即dataId。这个名词代表了存储在配置中心的特定配置资源的身份标签,如“gatewayserver-dev-$ server.env .yaml”,其中包含了配置文件的名称以及可能的环境变量占位符,使得服务可以根据不同的运行环境加载对应的配置内容。 命名与发现解决方案 , 这是一种在分布式系统中解决服务注册与发现问题的技术方案。在Nacos中,除了作为配置中心之外,它还提供了服务注册与发现的功能,允许服务实例在启动时向Nacos注册自己的网络地址和服务元数据,同时其他服务可以通过Nacos动态查找并连接到所需的依赖服务,从而实现系统的高可用性和可扩展性。 环境变量 , 环境变量是操作系统或程序中预定义的一类变量,用于存储与特定环境相关的信息,如服务器IP、端口、运行模式等。在本文讨论的场景下,\ server.env\ 可能是一个代表当前服务运行环境的环境变量,当Nacos尝试读取配置文件时,会根据实际设置的环境变量值替换掉\ $ server.env \ 部分,加载对应环境的正确配置。
2024-01-12 08:53:35
171
夜色朦胧_t
Apache Lucene
...文档都有其独一无二的标识符——document id。当我们试图使用相同的document id创建并添加一个新的文档到索引时,DocumentAlreadyExistsException就会闪亮登场。这是因为Lucene这个家伙,为了确保索引数据的整齐划一、滴水不漏,坚决不让两个相同ID的文档同时存在于它的数据库里。就像是图书管理员坚决不让两本同书名、同作者的书籍混进同一个书架一样,它对索引数据的一致性和完整性要求可是相当严格的呢! java // 创建一个新的文档 Document doc = new Document(); doc.add(new StringField("id", "123", Field.Store.YES)); doc.add(new TextField("content", "This is a sample document.", Field.Store.YES)); // 尝试将文档添加到索引(假设索引中已有id为"123"的文档) IndexWriter writer = new IndexWriter(directory, new IndexWriterConfig()); try { writer.addDocument(doc); } catch (DocumentAlreadyExistsException e) { System.out.println("Oops! A document with the same ID already exists."); // 这里是异常处理逻辑... } 3. 遇到DocumentAlreadyExistsException时的思考过程 首先,当此异常出现时,我们应当反思一下业务逻辑。是不是有用户不小心手滑了,或者咱们的系统设计上有个小bug,让一份文档被多次抓取进了索引里?要是真有这样的情况,那我们得在最上面的应用层好好瞅瞅,做点相应的检查和优化工作,确保同样的内容不会被反复提交上去。 其次,如果确实有更新文档的需求,而不是简单地添加新的文档,那么应该采用IndexWriter.updateDocument()方法替换原有的文档,而非addDocument(): java Term term = new Term("id", "123"); writer.updateDocument(term, updatedDoc); // 更新已存在的文档 最后,对于一些需要保证唯一性的场景,例如日志记录、订单编号等,可以考虑在索引建立阶段就设置IndexWriterConfig.setMergePolicy(NoDuplicatesMergePolicy.INSTANCE),从而避免因并发写入导致的重复文档问题。 4. 深入探讨与应对策略 在实践中,处理DocumentAlreadyExistsException不仅关乎对Lucene机制的理解,更需要结合具体应用场景来制定解决方案。比如,我们可以设想这样一种方案:定制一个独特的错误处理机制,这样一来,只要系统一检测到这个异常情况,就会自动启动文档内容合并流程,或者更贴心地告诉你,哎呀,这份文档已经存在了,需要你提供一个新的文档编号。 此外,对于高并发环境下的索引更新,除了利用Lucene提供的API外,还需要引入适当的并发控制策略,如乐观锁、分布式锁等,确保在多线程环境下,也能正确无误地处理文档添加与更新操作。 总结起来,DocumentAlreadyExistsException在Apache Lucene中扮演着守护者角色,提醒我们在构建高效、精准的全文搜索服务的同时,也要注意维护数据的一致性与完整性。如果咱们能全面摸清这个异常状况,并且妥善应对处理,那么咱们的应用程序就会变得更皮实耐造,这样一来,用户体验也绝对会蹭蹭地往上提升,变得超赞!
2023-01-30 18:34:51
458
昨夜星辰昨夜风
转载文章
...name)、OID(唯一标识符)等。在处理本文所述问题时,通过联合查询 pg_class 表和其他系统表,可以找到与被锁定表相关的后台进程信息。 pg_stat_activity 表 , pg_stat_activity 是 PostgreSQL 内置的一个系统视图,提供了关于数据库当前活动会话及其执行状态的信息,包括会话 ID(pid)、启动时间(backend_start)、应用程序名(application_name)、查询开始时间(query_start)、等待状态(waiting)、事务状态(state)以及当前执行的查询语句(query)等。在排查锁定问题时,通过查询 pg_stat_activity 表可了解哪些会话可能对问题表进行了锁定操作。
2023-09-22 09:08:45
126
转载
Etcd
...式存储,其中“键”是唯一的标识符,“值”可以是任意类型的数据。这种系统能够提供高可用性、强一致性以及水平扩展能力,使得在大规模分布式环境中,多个服务实例可以高效地共享和同步配置信息。 配置数据库 , 配置数据库是指专门用于存储应用程序配置信息的数据库系统,如etcd。它允许开发人员和服务动态获取和更新配置设置,确保在整个分布式系统中的配置数据保持一致性和实时性。相较于传统的配置文件方式,配置数据库能更好地支持服务发现、动态配置变更等云原生应用的需求。 初始集群配置 , 初始集群配置是etcd集群启动时需要的一个关键参数集,用于定义集群成员身份和关系。这个配置信息通常包含各个成员节点的唯一标识(名称或ID)、其所在主机地址及监听端口等。例如,在etcd的日志示例中提到的/etc/etcd/initial-cluster.conf文件,就可能包含了集群初始化所需的重要配置数据。当etcd尝试根据这些配置启动或加入集群时,如果配置文件存在错误或冲突,可能会导致etcd节点启动失败。
2023-10-11 17:16:49
572
冬日暖阳-t
HBase
...称或者需要锁定的资源标识。每个行只有一个列族(例如:"Lock"),并且这个列族下的唯一一个列(例如:"lock")的值并不重要,我们只需要关注它的存在与否来判断锁是否被占用。 4. 示例代码详解 下面是一个使用Java API实现HBase分布式锁的示例: java import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.Connection; import org.apache.hadoop.hbase.client.ConnectionFactory; import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.client.Table; public class HBaseDistributedLock { private final Connection connection; private final TableName lockTable = TableName.valueOf("distributed_locks"); public HBaseDistributedLock(Configuration conf) throws IOException { this.connection = ConnectionFactory.createConnection(conf); } // 尝试获取锁 public boolean tryLock(String lockName) throws IOException { Table table = connection.getTable(lockTable); Put put = new Put(Bytes.toBytes(lockName)); put.addColumn("Lock".getBytes(), "lock".getBytes(), System.currentTimeMillis(), null); try { table.put(put); // 如果这行已存在,则会抛出异常,表示锁已被占用 return true; // 无异常则表示成功获取锁 } catch (ConcurrentModificationException e) { return false; // 表示锁已被其他客户端占有 } finally { table.close(); } } // 释放锁 public void unlock(String lockName) throws IOException { Table table = connection.getTable(lockTable); Delete delete = new Delete(Bytes.toBytes(lockName)); table.delete(delete); table.close(); } } 5. 分析与讨论 上述代码展示了如何借助HBase实现分布式锁的核心逻辑。当你试着去拿锁的时候,就相当于你要在一张表里插一条新记录。如果发现这条记录竟然已经存在了(这就意味着这把锁已经被别的家伙抢先一步拿走了),系统就会毫不客气地抛出一个异常,然后告诉你“没戏,锁没拿到”,也就是返回个false。而在解锁时,只需删除对应的行即可。 然而,这种简单实现并未考虑超时、锁续期等问题,实际应用中还需要结合Zookeeper进行优化,如借助Zookeeper的临时有序节点特性实现更完善的分布式锁服务。 6. 结语 HBase的分布式锁实现是一种基于数据库事务特性的方法,它简洁且直接。不过呢,每种技术方案都有它能施展拳脚的地方,也有它的局限性。就好比选择分布式锁的实现方式,咱们得看实际情况,比如应用场景的具体需求、对性能的高标准严要求,还有团队掌握的技术工具箱。这就好比选工具干活,得看活儿是什么、要干得多精细,再看看咱手头有什么趁手的家伙事儿,综合考虑才能选对最合适的那个。明白了这个原理之后,咱们就可以动手实操起来,并且不断摸索、优化它,让这玩意儿更好地为我们设计的分布式系统架构服务,让它发挥更大的作用。
2023-11-04 13:27:56
437
晚秋落叶
Docker
...的核心组成部分,用于唯一标识网络中的设备。根据IPv4协议,IP地址由32位二进制组成,通常被表示为四个十进制数,如192.168.1.1。在Docker这个大家庭里,每个小容器都会被赋予一个独一无二的IP地址,这样一来,它们之间就可以像好朋友一样自由地聊天交流,不仅限于此,它们还能轻松地和它们所在的主机大哥,甚至更远的外部网络世界进行沟通联络。 2. Docker容器IP地址分配 在Docker默认的桥接网络(bridge)模式中,每个容器会获取一个属于172.17.0.0/16范围的私有IP地址。另外,你还可以选择自己动手配置一些个性化的网络设置,像是“host”啦、“overlay”啦,或者之前我们提到的那个“vlan”,这样就能给容器分配特定的一段IP地址,让它们各用各的,互不干扰。 四、VLAN与IP地址在Docker网络中的关系 1. IP地址在VLAN网络中的角色 当Docker容器运行在一个包含VLAN网络中时,它们会继承VLAN网络的IP地址配置,从而在同一VLAN内相互通信。比如,想象一下容器A和容器B这两个家伙,他们都住在VLAN 10这个小区里面,虽然住在不同的单元格,但都能通过各自专属的“门牌号”(也就是VLAN标签)和“电话号码”(IP地址)互相串门聊天,完全不需要经过小区管理员——宿主机的同意或者帮忙。 2. 跨VLAN通信 若想让VLAN网络内的容器能够与宿主机或其他VLAN网络内的容器通信,就需要配置多层路由或者使用VXLAN等隧道技术,使得数据包穿越不同的VLAN标签并在相应的IP地址空间内正确路由。 五、结论 综上所述,VLAN与IP地址在Docker网络场景中各有其核心作用。VLAN这个小家伙,就像是咱们物理网络里的隐形隔离墙和保安队长,它在幕后默默地进行逻辑分割和安全管理工作。而IP地址呢,更像是虚拟化网络环境中的邮差和导航员,主要负责在各个容器间传递信息,同时还能带领外部的访问者找到正确的路径,实现内外的互联互通。当这两者联手一起用的时候,就像是给网络装上了灵动的隔断墙,既能灵活分区,又能巧妙地避开那些可能引发“打架”的冲突风险。这样一来,咱们微服务架构下的网络环境就能稳稳当当地高效运转了,就像一台精密调校过的机器一样。在咱们实际做项目开发这事儿的时候,要想把Docker网络策略设计得合理、实施得妥当,就得真正理解并牢牢掌握这两者之间的关系,这可是相当关键的一环。
2024-02-12 10:50:11
479
追梦人_t
转载文章
...s和端口一起是端点的唯一标识符。 如果远程客户端通过端口80连接到您的服务器,而不是目标IP和端口,则没有其他信息表明网络层必须识别哪个应用程序(在端口80上侦听)应该获得该数据包。 鉴于配置多个IP地址非常困难 - 在NAT上是不可能的 - 将数据包路由到正确的侦听器的唯一信息就是端口。 所以你不能让两个应用程序在同一个端口上侦听。 ... 您无法通过直接在浏览器中打开它来连接到WebSocket。 您应该使用某个HTML页面创建HTTP服务器和响应。 在此HTML页面中,您应该包含连接到WebSocket服务器的javascript: var socket = new WebSocket("ws://localhost:8080"); You can't connect to WebSocket by open it directly in a browser. You should crea ... 所以我通过握手解决了我的特殊问题,而且非常无聊。 我需要两套“\ r \ n”才能完成握手。 所以为了解决我上面描述的握手问题(Javascript WebSocket没有进入OPEN状态)我需要对我的服务器端PHP进行以下更改(注意最后的\ r \ n \ r \ n,doh) : function dohandshake($user,$buffer){ // getheaders and calcKey are confirmed working, can provide source ... 是。 独立的WebSocket服务器通常可以在任何端口上运行。 浏览器客户端打开与非HTTP(S)端口上的服务器的WebSocket连接没有问题。 默认端口为80/443的主要原因是它们是最可靠的大规模使用端口,因为它们能够遍历阻止所有其他端口上所有流量的许多企业防火墙。 如果这对您的受众来说不是问题(或者您有基于HTTP的回退),那么为WebSocket服务器使用备用端口是完全合理的(并且更容易)。 另一种选择是使用80/443端口,但使用单独的IP地址/主机名。 Yes. A standalo ... Tyrus抱怨Connection: keep-alive, Upgrade header。 Firefox在这里没有做错任何事。 关于如何处理Connection标头,Tyrus过于严格,没有遵循WebSocket规范( RFC-6455 )。 RFC 4.1中的RFC规定: 6. The request MUST contain a |Connection| header field whose value MUST include the "Upgrade" tok ... 说实话,我不能100%确定地说这是什么,但我有一个非常强烈的怀疑。 我的代码中包含了太多的命名空间,我相信在编译器等实际运行时会出现一些混乱。 显然,Microsoft.Web.Websockets和SignalR的命名空间都包含WebSocketHandler。 虽然我不知道SignalR的所有细节,但看起来THAT命名空间中的WebSocketHandler并不意味着在SignalR之外使用。 我相信这个类正在被引用,而不是Microsoft.Web.Websockets中的那个,因为它现在起 ... 您应该使用websocket处理程序,而不是请求处理程序,尝试使用此示例 You should use the websocket handler, not the request handler, try with this example 本篇文章为转载内容。原文链接:https://blog.csdn.net/weixin_34862561/article/details/119512220。 该文由互联网用户投稿提供,文中观点代表作者本人意见,并不代表本站的立场。 作为信息平台,本站仅提供文章转载服务,并不拥有其所有权,也不对文章内容的真实性、准确性和合法性承担责任。 如发现本文存在侵权、违法、违规或事实不符的情况,请及时联系我们,我们将第一时间进行核实并删除相应内容。
2023-03-19 12:00:21
52
转载
站内搜索
用于搜索本网站内部文章,支持栏目切换。
知识学习
实践的时候请根据实际情况谨慎操作。
随机学习一条linux命令:
tar -cvzf archive.tar.gz file_or_directory
- 创建gzip压缩格式的tar归档包。
推荐内容
推荐本栏目内的其它文章,看看还有哪些文章让你感兴趣。
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
历史内容
快速导航到对应月份的历史文章列表。
随便看看
拉到页底了吧,随便看看还有哪些文章你可能感兴趣。
时光飞逝
"流光容易把人抛,红了樱桃,绿了芭蕉。"