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

基于Linux的repmgr搭建

第一部分 说明

repmgr是一个开源工具套件,用于管理 PostgreSQL 服务器集群中的复制和故障转移。它通过设置备用服务器、监控复制和执行管理任务(例如故障转移或手动切换操作)的工具增强了 PostgreSQL 的内置热备用功能。
PostgreSQL在9.0后引入了流复制架构,并且支持hot standby特性,并且在往后的几个版本中不断完善和增强流复制架构,repmgr为PostgreSQL 的流复制机制提供了高级支持,因为它们是在 9.0 中引入的。当前的repmgr系列, repmgr 5,支持从 PostgreSQL 9.3 引入的复制功能的最新发展,例如级联复制、时间线切换和通过复制协议进行的基本备份
repmgr作为一个开源工具,旨在用于灵活、便捷地管理PostgreSQL集群。

第二部分 安装repmgr

2.1 yum在线安装

2.1.1 安装对应PostgreSQL版本的存储库

从列表中找到PostgreSQL对应版本的存储库RPM:Https://dl.2ndquadrant.com/ 。安装发行版和PostgreSQL版本的存储库定义(以postgresql12为例)

# curl https://dl.2ndquadrant.com/default/release/get/12/rpm | sudo bash

2.1.2 验证存储库安装

执行如下:

# sudo yum repolist

输出应该包含两个条目,如下所示:

2ndquadrant-dl-default-release-pg11/7/x86_64         2ndQuadrant packages (PG12) for 7 - x86_64               18
2ndquadrant-dl-default-release-pg11-debug/7/x86_64   2ndQuadrant packages (PG12) for 7 - x86_64 - Debug        8

2.1.3 yum安装repmgr

使用yum在线安装

# sudo yum install repmgr12

若要安装特定的包版本,请执行yum --showduplicates list关于所涉一揽子方案:

然后用连字符将适当的版本号附加到包名,例如:

# yum install repmgr12-5.2.0-1.rhel7

2.2 源码安装

源码包下载地址:https://repmgr.org/download/

2.2.1 解压源码包

解压下载的源码包,将解压目录修改属组

# tar -xzvf repmgr-5.3.1.tar.gz
# chown -R postrges:postgres repmgr-5.3.1/

2.2.2 编译安装

切换为postgres用户安装,查询pg_config的执行位置,选择对应PostgreSQL版本pg_config所在的bin目录

# su – postgres
$ which pg_config
/software/pgsql13/bin/pg_config

进入repmgr软件包目录,指定PostgreSQL软件位置进行编译安装

$ ./configure --prefix=/software/pgsql13/
$ make && make install

查看是否安装成功

$ repmgr –version
repmgr 5.3.1

2.3 设置基本复制群集的先决条件

必须在这两台服务器上安装PostgreSQL和repmgr软件,以及需要两个服务器之间的无密码SSH连接。

2.3.1配置postgres用户互信

主端服务器上生成秘钥

$ ssh-keygen -t rsa

将秘钥拷贝到远程机器

$ ssh-copy-id -i .ssh/id_rsa.pub postgres@node2

验证是否授权完成,不提示密码,直接返回日期说明配置正确

$ ssh node2 date

备端服务器上生成秘钥到用户主目录下的.ssh文件夹下

$ ssh-keygen -t rsa

将秘钥拷贝到远程机器

$ ssh-copy-id -i .ssh/id_rsa.pub postgres@node1

验证是否授权完成:不提示密码,直接返回日期说明配置正确

$ ssh node1 date

2.4 PostgreSQL配置

主库编辑配置文件postgresql.conf,并重启数据库

$ vi postgresql.conflisten_addresses = '*'
wal_log_hints = on
max_wal_senders = 10
max_replication_slots = 10
wal_level = 'replica'
hot_standby = on
archive_mode = on
archive_command = 'test ! -f /postgres/product/archivedir/%f && cp %p /postgres/product/archivedir/%f'     #归档路径根据具体情况修改
shared_preload_libraries = 'repmgr'

2.5 创建repmgr用户和数据库

创建repmgr流复制用户、数据库以及repmgr扩展,并赋予用户superuser权限

$ psql -d postgres -U postgres
postgres# create user repmgr replication password 'repmgrforrepl';
postgres# alter user repmgr superuser;
postgres# create database repmgr owner repmgr;
postgres# \c repmgr repmgr
repmgr# ALTER USER repmgr SET search_path TO repmgr, "$user", public;
repmgr# alter user repmgr superuser ;

进入该数据库创建repmgr模式,将模式添加到search path中

repmgr# create schema repmgr ;
repmgr# ALTER USER repmgr SET search_path TO repmgr, "$user", public;

创建repmgr扩展

$ psql -d repmgr -U repmgr
repmgr# create extension repmgr;

2.6 配置pg_hba.conf的身份验证

配置pg_hba.conf白名单文件,允许repmgr有连接访问和复制的权限。

local   replication   repmgr                                trust
host    replication   repmgr      127.0.0.1/32            trust
host    replication   repmgr      192.168.22.0/24         md5local   repmgr         repmgr                                trust
host    repmgr         repmgr      127.0.0.1/32            trust
host    repmgr         repmgr      192.168.22.0/24         md5

2.7 配置本地密码文件

在各节点postgres家目录下创建密码文件

$ vi ~/.pgpasss192.168.1.4:5432:repmgr:repmgr:repmgrforrepl
192.168.1.5:5432:repmgr:repmgr:repmgrforrepl
192.168.1.5:5435:repmgr:repmgr:repmgrforrepl
192.168.1.4:5432:replication:repmgr:repmgrforrepl
192.168.1.5:5432:replication:repmgr:repmgrforrepl
192.168.1.5:5435:replication:repmgr:repmgrforrepl

2.8 配置repmgr

在/postgres/app/repmgr_config目录(目录可自定义创建)下编辑repmgr.conf,添加以下:

node_id=1
node_name='node1'
conninfo='host=192.168.1.4 user=repmgr dbname=repmgr password=repmgrforrepl port=5432 connect_timeout=2'
data_directory='/postgres/product/data'
pg_bindir='/postgres/app/bin'
failover=automatic
promote_command='/postgres/app/bin/repmgr standby promote -f /postgres/app/repmgr_config/repmgr.conf --log-to-file'
follow_command='/postgres/app/bin/repmgr standby follow -f /postgres/app/repmgr_config/repmgr.conf --log-to-file --upstream-node-i
d=%n'
log_file='/postgres/app/repmgr_log/repmgr.log'

第三部分 主服务安装配置

3.1注册主服务器

若要支持复制群集,必须将主节点注册到repmgr。这将安装repmgr扩展和元数据对象,并为主服务器添加元数据记录

$ repmgr -f /postgres/app/repmgr_config/repmgr.conf standby register
INFO: connecting to primary database...
NOTICE: attempting to install extension "repmgr"
NOTICE: "repmgr" extension successfully installed
NOTICE: primary node record (id: 1) registered

验证集群状态

$ repmgr -f /postgres/app/repmgr_config/repmgr.conf cluster showID | Name  | Role    | Status    | Upstream | Location | Priority | Timeline | Connection string                                                                            
----+-------+---------+-----------+----------+----------+----------+----------+-----------------------------------------------------------------------------------------------1  | node1 | primary | * running |          | default  | 100      | 11       | host=192.168.1.4 user=repmgr dbname=repmgr password=repmgrforrepl port=5432 connect_timeout=2

记录repmgr的元数据表

repmgr=# SELECT * FROM repmgr.nodes;
-[ RECORD 1 ]----+----------------------------------------------------------------------------------------------
node_id          | 1
upstream_node_id | 
active           | t
node_name        | node1
type             | primary
location         | default
priority         | 100
conninfo         | host=192.168.1.4 user=repmgr dbname=repmgr password=repmgrforrepl port=5432 connect_timeout=2
repluser         | repmgr
slot_name        | 
config_file      | /postgres/app/repmgr_config/repmgr.conf

3.2克隆备用服务器

在node2节点上创建一个备用服务器上的repmgr.conf文件,添加以下内容:

$ vi /postgres/app/repmgr_config/repmgr.confnode_id=2
node_name='node2'
conninfo='host=192.168.1.5 user=repmgr dbname=repmgr password=repmgrforrepl port=5432 connect_timeout=2'
data_directory='/postgres/product/data'
pg_bindir='/postgres/app/bin'
failover=automatic
promote_command='/postgres/app/bin/repmgr standby promote -f /postgres/app/repmgr_config/repmgr.conf --log-to-file'
follow_command='/postgres/app/bin/repmgr standby follow -f /postgres/app/repmgr_config/repmgr.conf --log-to-file --upstream-node-i
d=%n'
log_file='/postgres/app/repmgr_log/repmgr.log'

使用如下命令查看克隆是否有问题

$ repmgr -h 192.168.1.4 -U repmgr -d repmgr -f /postgres/app/repmgr_config/repmgr.conf standby clone --dry-runNOTICE: destination directory "/software/pgsql13/datarepl " provided
INFO: connecting to source node
DETAIL: connection string is: host=192.168.1.1 user=repmgr dbname=repmgr
DETAIL: current installation size is 31 MB
INFO: "repmgr" extension is installed in database "repmgr"
INFO: replication slot usage not requested;  no replication slot will be set up for this standby
INFO: parameter "max_wal_senders" set to 10
NOTICE: checking for available walsenders on the source node (2 required)
INFO: sufficient walsenders available on the source node
DETAIL: 2 required, 10 available
NOTICE: checking replication connections can be made to the source server (2 required)
INFO: required number of replication connections could be made to the source server
DETAIL: 2 replication connections required
NOTICE: standby will attach to upstream node 1
HINT: consider using the -c/--fast-checkpoint option
INFO: all prerequisites for "standby clone" are met

若没有问题去掉调试模式,直接执行

$ repmgr -h 192.168.22.128 -U repmgr -d repmgr -p 5432 -f /postgres/app/repmgr_config/repmgr.confNOTICE: destination directory "/postgres/product/data" provided
INFO: connecting to source node
DETAIL: connection string is: host=192.168.1.4 user=repmgr dbname=repmgr
DETAIL: current installation size is 31 MB
INFO: replication slot usage not requested;  no replication slot will be set up for this standby
NOTICE: checking for available walsenders on the source node (2 required)
NOTICE: checking replication connections can be made to the source server (2 required)
INFO: creating directory "/pgdata/dataano"...
NOTICE: starting backup (using pg_basebackup)...
HINT: this may take some time; consider using the -c/--fast-checkpoint option
INFO: executing:pg_basebackup -l "repmgr base backup"  -D /postgres/product/data -h 192.168.1.4 -p 5432 -U repmgr -p 5432 -X stream 
NOTICE: standby clone (using pg_basebackup) complete
NOTICE: you can now start your PostgreSQL server
HINT: for example: pg_ctl -D /postgres/product/data start
HINT: after starting the server, you need to register this standby with "repmgr standby register"

启动node2节点服务

$ pg_ctl -D /postgres/product/data start

注册node2 standby角色信息

$ repmgr -f /postgres/app/repmgr_config/repmgr.conf standby register

主节点查看流复制状态正常,成功搭建

repmgr=# select * from pg_stat_replication ;
-[ RECORD 1 ]----+------------------------------
pid              | 24003
usesysid         | 16384
usename          | repmgr
application_name | node2
client_addr      | 192.168.1.5
client_hostname  | 
client_port      | 13360
backend_start    | 2022-03-10 16:06:17.005646+08
backend_xmin     | 
state            | streaming
sent_lsn         | 0/36002C78
write_lsn        | 0/36002C78
flush_lsn        | 0/36002C78
replay_lsn       | 0/36002C78
write_lag        | 00:00:00.000339
flush_lag        | 00:00:00.002684
replay_lag       | 00:00:00.002753
sync_priority    | 0
sync_state       | async
reply_time       | 2022-03-10 16:29:32.898743+08

3.3配置自动故障转移

创建一个新节点witness(node3),建议部署在另一个单独的服务器上,本文档将此节点安装在node2节点上。
在node3节点的repmgr.conf中添加以下参数

node_id=3
node_name='node3'
conninfo='host=192.168.1.5 user=repmgr dbname=repmgr password=repmgrforrepl port=5435 connect_timeout=2'
data_directory='/postgres/app/witness/data'
pg_bindir='/postgres/app/bin'
failover=automatic
promote_command='/postgres/app/bin/repmgr standby promote -f /postgres/app/witness/conf/repmgr.conf --log-to-file'
follow_command='/postgres/app/bin/repmgr standby follow -f /postgres/app/witness/conf/repmgr.conf --log-to-file --upstream-node-id
=%n'
log_file='/postgres/app/repmgr_log/repmgr_witness.log'

创建一个新的PostgreSQL实例,将参数文件设置和白名单访问设置同node1、node2节点。(参数配置步骤略)

$ initdb -D /postgres/app/witness/data

将witness节点注册为witness角色

$ repmgr -h 192.168.1.4 -U repmgr -d repmgr -p5432 -f /postgres/app/witness/conf/repmgr.conf witness register

在node1上执行查看各节点状态

$ repmgr -f /postgres/app/repmgr_config/repmgr.conf cluster showID | Name  | Role    | Status    | Upstream | Location | Priority | Timeline | Connection string                                                                            
----+-------+---------+-----------+----------+----------+----------+----------+-----------------------------------------------------------------------------------------------1  | node1 | primary | * running |          | default  | 100      | 11       | host=192.168.1.4 user=repmgr dbname=repmgr password=repmgrforrepl port=5432 connect_timeout=22  | node2 | standby |   running | node1    | default  | 100      | 11       | host=192.168.1.5 user=repmgr dbname=repmgr password=repmgrforrepl port=5432 connect_timeout=23  | node3 | witness | * running | node2    | default  | 0        | n/a      | host=192.168.1.5 user=repmgr dbname=repmgr password=repmgrforrepl port=5435 connect_timeout=2

各节点启动repmgrd程序

node1:
$ repmgrd -f /postgres/app/repmgr_config/repmgr.conf --pid-file /tmp/repmgrd.pidnode2:
$ repmgrd -f /postgres/app/repmgr_config/repmgr.conf --pid-file /tmp/repmgrd.pidnode3(witness):
$ repmgrd -f /postgres/app/witness/conf/repmgr.conf --pid-file /tmp/repmgrd_witness.pid

如果需要终止repmgrd程序,使用以下命令

$ kill `cat /tmp/repmgrd.pid`

3.3.1测试自动故障转移

node1上模拟测试关闭主库

$ pg_ctl stop

node2节点打开repmgr日志信息显示,输出如下则成功晋升为主节点

$ tail -30f /postgres/app/repmgr_log/repmgr.log
[2022-03-10 15:33:43] [NOTICE] promoting standby to primary
[2022-03-10 15:33:43] [DETAIL] promoting server "node2" (ID: 2) using pg_promote()
[2022-03-10 15:33:43] [NOTICE] waiting up to 60 seconds (parameter "promote_check_timeout") for promotion to complete
[2022-03-10 15:33:44] [NOTICE] STANDBY PROMOTE successful
[2022-03-10 15:33:44] [DETAIL] server "node2" (ID: 2) was successfully promoted to primary
[2022-03-10 15:33:44] [INFO] checking state of node 2, 1 of 6 attempts
[2022-03-10 15:33:44] [NOTICE] node 2 has recovered, reconnecting
[2022-03-10 15:33:44] [INFO] connection to node 2 succeeded
[2022-03-10 15:33:44] [INFO] original connection is still available
[2022-03-10 15:33:44] [INFO] 0 followers to notify
[2022-03-10 15:33:44] [INFO] switching to primary monitoring mode
[2022-03-10 15:33:44] [NOTICE] monitoring cluster primary "node2" (ID: 2)
[2022-03-10 15:33:44] [INFO] child node "node3" (ID: 3) is not yet attached
[2022-03-10 15:34:44] [NOTICE] new witness "node3" (ID: 3) has connected

查看备库是否晋升为主(f为主)

postgres=# select pg_is_in_recovery();pg_is_in_recovery 
-------------------f
(1 row)

node2上查看各节点状态,此时node2已经成为primary

$ repmgr -f /postgres/app/repmgr_config/repmgr.conf cluster show
ID | Name  | Role    | Status    | Upstream | Location | Priority | Timeline | Connection string                                                                            
----+-------+---------+-----------+----------+----------+----------+----------+-----------------------------------------------------------------------------------------------1  | node1 | primary | - failed  | ?        | default  | 100      |          | host=192.168.1.4 user=repmgr dbname=repmgr password=repmgrforrepl port=5432 connect_timeout=22  | node2 | primary | * running |          | default  | 100      | 12       | host=192.168.1.5 user=repmgr dbname=repmgr password=repmgrforrepl port=5432 connect_timeout=23  | node3 | witness | * running | node2    | default  | 0        | n/a      | host=192.168.1.5 user=repmgr dbname=repmgr password=repmgrforrepl port=5435 connect_timeout=2

3.3.2将原主库初始化为备库

确保node1原主库已经被关闭,并将其初始化为备库

$ repmgr -h 192.168.1.5 -U repmgr -d repmgr -f /postgres/app/repmgr_config/repmgr.conf standby clone -F

启动node1节点

$ pg_ctl start

将node1强制重新注册为standby

$ repmgr -f /postgres/app/repmgr_config/repmgr.conf standby register -F

查看集群状态

$ repmgr -f /postgres/app/repmgr_config/repmgr.conf cluster show
ID | Name  | Role    | Status    | Upstream | Location | Priority | Timeline | Connection string                                                                            
----+-------+---------+-----------+----------+----------+----------+----------+-----------------------------------------------------------------------------------------------1  | node1 | standby |  running  | node2    | default  | 100      | 12         | host=192.168.1.4 user=repmgr dbname=repmgr password=repmgrforrepl port=5432 connect_timeout=22  | node2 | primary | * running |          | default  | 100      | 12       | host=192.168.1.5 user=repmgr dbname=repmgr password=repmgrforrepl port=5432 connect_timeout=23  | node3 | witness | * running | node2    | default  | 0        | n/a      | host=192.168.1.5 user=repmgr dbname=repmgr password=repmgrforrepl port=5435 connect_timeout=2

3.4手动切换主备节点

node1节点强制提升为主节点

$ repmgr standby switchover -f /postgres/app/repmgr_config/repmgr.conf --siblings-follow --always-promote
DETAIL: promoting server "node1" (ID: 1) using pg_promote()
NOTICE: waiting up to 60 seconds (parameter "promote_check_timeout") for promotion to complete
NOTICE: STANDBY PROMOTE successful
DETAIL: server "node1" (ID: 1) was successfully promoted to primary
ERROR: new primary diverges from former primary and --force-rewind not provided
HINT: the former primary will need to be restored manually, or use "repmgr node rejoin"

查看各节点状态

$ repmgr -f /postgres/app/repmgr_config/repmgr.conf cluster show ID | Name  | Role    | Status    | Upstream | Location | Priority | Timeline | Connection string                                                                            
----+-------+---------+-----------+----------+----------+----------+----------+-----------------------------------------------------------------------------------------------1  | node1 | primary | * running |          | default  | 100      | 13        | host=192.168.1.4 user=repmgr dbname=repmgr password=repmgrforrepl port=5432 connect_timeout=22  | node2 | primary | - failed  | ?        | default  | 100      |          | host=192.168.1.5 user=repmgr dbname=repmgr password=repmgrforrepl port=5432 connect_timeout=23  | node3 | witness | * running | ? node2  | default  | 0        | n/a      | host=192.168.1.5 user=repmgr dbname=repmgr password=repmgrforrepl port=5435 connect_timeout=2WARNING: following issues were detected- unable to connect to node "node2" (ID: 2)- unable to connect to node "node3" (ID: 3)'s upstream node "node2" (ID: 2)

node2节点进行初始化克隆

$ repmgr -h 192.168.1.4 -U repmgr -d repmgr -f /postgres/app/repmgr_config/repmgr.conf standby clone -F

启动node2节点

$ pg_ctl start

重新注册为standby角色

$ repmgr -f /postgres/app/repmgr_config/repmgr.conf standby register -F

查看各节点状态

$ repmgr -f /postgres/app/repmgr_config/repmgr.conf cluster showID | Name  | Role    | Status    | Upstream | Location | Priority | Timeline | Connection string                                                                            
----+-------+---------+-----------+----------+----------+----------+----------+-----------------------------------------------------------------------------------------------1  | node1 | primary | * running |          | default  | 100      | 13        | host=192.168.1.4 user=repmgr dbname=repmgr password=repmgrforrepl port=5432 connect_timeout=22  | node2 | standby |   running | node1    | default  | 100      | 13       | host=192.168.1.5 user=repmgr dbname=repmgr password=repmgrforrepl port=5432 connect_timeout=23  | node3 | witness | * running | node1    | default  | 0        | n/a      | host=192.168.1.5 user=repmgr dbname=repmgr password=repmgrforrepl port=5435 connect_timeout=2

3.5集群维护

如果需要对PostgreSQL环境进行维护,例如配置修改、架构切换等,建议关闭各节点repmgrd自动故障转移进程。找到对应进程的pid文件或者pid执行关闭命令:

$ kill `cat /tmp/repmgrd.pid`

hhh6.jpg

相关文章:

基于Linux的repmgr搭建

第一部分 说明 repmgr是一个开源工具套件,用于管理 PostgreSQL 服务器集群中的复制和故障转移。它通过设置备用服务器、监控复制和执行管理任务(例如故障转移或手动切换操作)的工具增强了 PostgreSQL 的内置热备用功能。 PostgreSQL在9.0后引…...

Diff差异算法

目录 虚拟DOM Diff算法 Diff过程 示例 总结 在Vue.js中,虚拟DOM(Virtual DOM)是其核心特性之一,它极大地提高了DOM更新的效率。Vue.js使用虚拟DOM的diff算法来比较新旧虚拟DOM树,从而确定最小的DOM更新操作。这种…...

visionpro官方示例分析(一) 模板匹配工具 缺陷检测工具

1.需求:找出图像中的这个图形。 2.步骤 使用CogPMAlignTool工具,该工具是模板匹配工具,见名知意,所谓模板匹配工具就是说先使用该工具对一张图像建立模板,然后用这个模板在其他图像上进行匹配,匹配上了就说…...

字符串分割转换(Java Python JS C++ C )

题目描述 给定一个非空字符串S,其被N个‘-’分隔成N+1的子串,给定正整数K,要求除第一个子串外,其余的子串每K个字符组成新的子串,并用‘-’分隔。 对于新组成的每一个子串,如果它含有的小写字母比大写字母多,则将这个子串的所有大写字母转换为小写字母; 反之,如果它…...

第33章 - Go语言 云原生开发

第33章 - 云原生开发将深入探讨云原生技术及其在现代软件开发中的应用。我们将从云原生的基本概念开始,逐步介绍Kubernetes的基本使用方法,并结合具体的云服务提供商实例,通过Go语言编写的应用程序来展示如何实现云原生开发。 33.1 云原生的…...

springboot配置多数据源mysql+TDengine保姆级教程

提示&#xff1a;文章写完后&#xff0c;目录可以自动生成&#xff0c;如何生成可参考右边的帮助文档 文章目录 前言一、pom文件二、yamlDataSourceConfigServiceMapper.xml测试总结 前言 Mybatis-plus管理多数据源&#xff0c;数据库为mysql和TDengine。 一、pom文件 <de…...

RocketMQ负载均衡机制解析

消费者在消费消息的时候&#xff0c;需要知道从Broker的哪一个消息队列中去获取消息。 ❝ 所以&#xff0c;在消费者端必须要做负载均衡&#xff0c;即Broker端中多个消费队列分配给同一个消费者组中的哪些消费者消费。 在RocketMQ中&#xff0c;在消费者端有一个&#xff1a;R…...

PyTorch 模型转换为 ONNX 格式

PyTorch 模型转换为 ONNX 格式 在深度学习领域&#xff0c;模型的可移植性和可解释性是非常重要的。本文将介绍如何使用 PyTorch 训练一个简单的卷积神经网络&#xff08;CNN&#xff09;来分类 MNIST 数据集&#xff0c;并将训练好的模型转换为 ONNX 格式。我们还将讨论 PTH …...

大数据-234 离线数仓 - 异构数据源 DataX 将数据 从 HDFS 到 MySQL

点一下关注吧&#xff01;&#xff01;&#xff01;非常感谢&#xff01;&#xff01;持续更新&#xff01;&#xff01;&#xff01; Java篇开始了&#xff01; 目前开始更新 MyBatis&#xff0c;一起深入浅出&#xff01; 目前已经更新到了&#xff1a; Hadoop&#xff0…...

【人工智能】使用Python实现序列到序列(Seq2Seq)模型进行机器翻译

解锁Python编程的无限可能:《奇妙的Python》带你漫游代码世界 序列到序列(Sequence-to-Sequence, Seq2Seq)模型是解决序列输入到序列输出任务的核心架构,广泛应用于机器翻译、文本摘要和问答系统等自然语言处理任务中。本篇文章深入介绍 Seq2Seq 模型的原理及其核心组件(…...

elasticsearch安装ik分词器

本文主要记录如何安装ik分词器&#xff0c;如果你刚好刷到了这篇文章&#xff0c;希望对你有所帮助。 IKAnalyzer是一个开源的&#xff0c;基于java语言开发的轻量级的中文分词工具包。采用了特有的“正向迭代最细粒度切分算法“&#xff0c;支持细粒度和最大词长两种切分模式&…...

QT6之主站freemodbus1.6移植

本次使用的QT是6.8 下载1.6的freemodbus资源包&#xff1a;至少以上的吧 随便下载&#xff1a;官网也可以这个是STM芯片的教程&#xff0c;移植基本一样&#xff0c;略有不同&#xff1b; STM32 移植FreeModbus详细过程-CSDN博客 移植freemodbus&#xff1a; 添加资源文件&a…...

【错误❌】——槽函数定义好但未初始化

public slots:void onClose(); 初始化即可成功&#xff1a;...

数据结构(理解)

探索数据结构&#xff1a;计算机世界的基石 在计算机科学的领域中&#xff0c;数据结构就如同建筑中的基石&#xff0c;它们支撑着整个软件世界的运行。无论是简单的应用程序&#xff0c;还是复杂的大型系统&#xff0c;数据结构都在其中起着至关重要的作用。 一、什么是数据结…...

ROS2 细节知识学习

1. rosidl_generate_interfaces() 在 ROS2 中&#xff0c;rosidl_generate_interfaces是一个关键的构建工具功能。它主要用于从接口定义文件&#xff08;如.msg消息文件、.srv服务文件和.action动作文件&#xff09;生成不同编程语言&#xff08;如 C、Python 等&#xff09;可…...

SQL进阶——JOIN操作详解

在数据库设计中&#xff0c;数据通常存储在多个表中。为了从这些表中获取相关的信息&#xff0c;我们需要使用JOIN操作。JOIN操作允许我们通过某种关系&#xff08;如相同的列&#xff09;将多张表的数据结合起来。它是SQL中非常重要的操作&#xff0c;广泛应用于实际开发中。本…...

Android studio 签名加固后的apk文件

Android studio打包时&#xff0c;可以选择签名类型v1和v2&#xff0c;但是在经过加固后&#xff0c;签名就不在了&#xff0c;或者只有v1签名&#xff0c;这样是不安全的。 操作流程&#xff1a; 1、Android studio 对项目进行打包&#xff0c;生成有签名的apk文件&#xff…...

Mybatis-基础操作

Mybatis的基础操作就是通过Mybatis完成对数据的增删改查。我们通过例子来引入这些操作&#xff0c;之前的项目较久远&#xff0c;因此我们从零开始进行准备工作&#xff1a; 搭建项目 一、创建数据库user_list并插入数据&#xff1a; -- 创建数据库 create table user_list …...

【工具】JS解析XML并且转为json对象

【工具】JS解析XML并且转为json对象 <?xml version1.0 encodingGB2312?> <root><head><transcode>hhhhhhh</transcode></head><body><param>ccccccc</param><param>aaaaaaa</param><param>qqqq<…...

软件测试技术面试题及参考答案整理

一、什么是兼容性测试?兼容性测试侧重哪些方面? 参考答案&#xff1a; 兼容测试主要是检查软件在不同的硬件平台、软件平台上是否可以正常的运行&#xff0c;即是通常说的软件的可移植性。 兼容的类型&#xff0c;如果细分的话&#xff0c;有平台的兼容&#xff0c;网络兼…...

Python学习36天

面向对象编程综合 # 创建父类 class Employee:# 创建私有属性__name None__salary None# 创建构造器初始化属性def __init__(self, __name, __salary):self.__name __nameself.__salary __salarydef get_annual(self):# 返回员工年薪return self.__salary * 12# 创建公共方…...

C语言——海龟作图(对之前所有内容复习)

一.问题描述 海龟作图 设想有一只机械海龟&#xff0c;他在C程序控制下在屋里四处爬行。海龟拿了一只笔&#xff0c;这支笔或者朝上&#xff0c;或者朝下。当笔朝下时&#xff0c;海龟用笔画下自己的移动轨迹&#xff1b;当笔朝上时&#xff0c;海龟在移动过程中什么也不画。 …...

关于如何在k8s中搭建一个nsfw黄图鉴定模型

随着现在应用内图片越来越多&#xff0c;安全审查也是必不可少的一个操作了 下面手把手教你如何将huggingface中的黄图检测模型部署到自己的服务器上去 1.找到对应的模型 nsfw_image_detection 2.在本地先验证如何使用 首先安装transformers python库 pip install transform…...

istio结合wasm插件的实际应用

在 Istio 中&#xff0c;WASM 插件的常见使用场景和功能包括以下几个方面&#xff1a; 1. 流量管理与请求修改 请求与响应头处理&#xff1a;动态添加、删除或修改 HTTP 请求或响应头。URL 重写&#xff1a;根据特定规则调整请求的路径或参数。请求路由增强&#xff1a;实现复…...

日志logrus

https://blog.csdn.net/m0_70982551/article/details/143095729 https://blog.csdn.net/wslyk606/article/details/81670713 https://www.bilibili.com/opus/1002468521099132928 地鼠文档&#xff1a;https://www.topgoer.cn/docs/goday/goday-1crg2adjknouc 极客文档&#xf…...

11.29 代码随想录Day45打卡(动态规划)

115.不同的子序列 题目&#xff1a;给你两个字符串 s 和 t &#xff0c;统计并返回在 s 的 子序列 中 t 出现的个数。 题解&#xff1a; class Solution:def numDistinct(self, s: str, t: str) -> int:dp [[0] * (len(t) 1) for _ in range(len(s) 1)]for i in range…...

springboot336社区物资交易互助平台pf(论文+源码)_kaic

毕 业 设 计&#xff08;论 文&#xff09; 社区物资交易互助平台设计与实现 摘 要 传统办法管理信息首先需要花费的时间比较多&#xff0c;其次数据出错率比较高&#xff0c;而且对错误的数据进行更改也比较困难&#xff0c;最后&#xff0c;检索数据费事费力。因此&#xff…...

【Maven】Nexus私服

6. Maven的私服 6.1 什么是私服 Maven 私服是一种特殊的远程仓库&#xff0c;它是架设在局域网内的仓库服务&#xff0c;用来代理位于外部的远程仓库&#xff08;中央仓库、其他远程公共仓库&#xff09;。一些无法从外部仓库下载到的构件&#xff0c;如项目组其他人员开发的…...

【python量化教程】如何使用必盈API的股票接口,获取最新分时KDJ数据

分时KDJ数据简介 股票分时 KDJ 数据是用于分析股票盘中短期走势的指标。它由未成熟随机指标 RSV 计算出 K 值、D 值、J 值。取值范围上&#xff0c;K 和 D 是 0 - 100&#xff0c;J 值可超出此范围。20 以下为超卖区、80 以上是超买区。关键信号有金叉&#xff08;预示上涨&am…...

DI依赖注入详解

DI依赖注入 声明了一个成员变量&#xff08;对象&#xff09;之后&#xff0c;在该对象上面加上注解AutoWired注解&#xff0c;那么在程序运行时&#xff0c;该对象自动在IOC容器中寻找对应的bean对象&#xff0c;并且将其赋值给成员变量&#xff0c;完成依赖注入。 AutoWire…...

mysql sql语句 between and 是否边界值

在 MySQL 中&#xff0c;使用 BETWEEN 运算符时&#xff0c;边界值是包括在内的。这意味着 BETWEEN A AND B 查询会返回 A 和 B 之间的所有值&#xff0c;包括 A 和 B 自身。 示例 假设有一个表 employees&#xff0c;其中有一个 salary 列&#xff0c;您可以使用以下查询&am…...

飞塔防火墙只允许国内IP访问

飞塔防火墙只允许国内IP访问 方法1 新增地址对象&#xff0c;注意里面已经细分为中国内地、中国香港、中国澳门和中国台湾 方法2 手动新增国内IP的对象组&#xff0c;目前好像一共有8632个&#xff0c;每个对象最多支持600个IP段...

宠物之家:基于SpringBoot的领养平台

第1章 绪论 1.1 课题背景 二十一世纪互联网的出现&#xff0c;改变了几千年以来人们的生活&#xff0c;不仅仅是生活物资的丰富&#xff0c;还有精神层次的丰富。时代进步的标志&#xff0c;就是让人们过上更好的生活。在互联网诞生之前&#xff0c;地域位置往往是人们思想上不…...

golang 实现比特币内核:如何接入 RPC 后端获得特定交易的二进制数据

我们非常关注解析比特币的二进制数据,这使得我们的工作看起来是可行的。比特币是一个分布式网络系统,这意味着它需要全球各地的节点协同工作,甚至比特币核心库也需要连接其他节点来帮助它,就像查询交易费一样。 世界上没有免费的午餐。当你使用比特币系统进行交易时,你需…...

QML学习 —— 34、视频媒体播放器(附源码)

效果 说明 您可以单独使用MediaPlayer播放音频内容(如音频),也可以将其与VideoOutput结合使用以渲染视频。VideoOutput项支持未转换、拉伸和均匀缩放的视频演示。有关拉伸均匀缩放演示文稿的描述,请参见fillMode属性描述。 播放可能出错问题 出现的问题:      DirectS…...

宝塔Linux面板上传PHP文件或者修改PHP文件,总是转圈圈,其他文件正常,解决办法

目录 问题描述 寻找解决方案 1.重启宝塔面板 2.清理宝塔缓存 3.升级面板 4.ssh远程 5.清空回收站 6.换网络 7. IDE远程编辑 总结&#xff1a; 问题描述 一直用宝塔linux面板&#xff0c;感觉非常好用&#xff0c;点点就能搞定&#xff0c;环境也很好配置。 公司搬家&…...

Flink——进行数据转换时,报:Recovery is suppressed by NoRestartBackoffTimeStrategy

热词统计案例&#xff1a; 用flink中的窗口函数&#xff08;apply&#xff09;读取kafka中数据&#xff0c;并对热词进行统计。 apply:全量聚合函数&#xff0c;指在窗口触发的时候才会对窗口内的所有数据进行一次计算&#xff08;等窗口的数据到齐&#xff0c;才开始进行聚合…...

贪心算法题目合集

贪心算法题目合集 1319&#xff1a;【例6.1】排队接水 贪心策略思想 1319&#xff1a;【例6.1】排队接水 贪心策略思想 1319&#xff1a;【例6.1】排队接水 贪心算法与其说是算法&#xff0c;不如说是一种风格&#xff1a;每次做事情都选择自己认为的最优解。 贪心算法的题很…...

NSSCTF-做题笔记

[羊城杯 2020]easyre 查壳&#xff0c;无壳&#xff0c;64位&#xff0c;ida打开 encode_one encode_tow encode_three 那么我们开始一步一步解密&#xff0c;从最外层开始 def decode_three(encrypted_str):decrypted_str ""for char in encrypted_str:char_code …...

SpringBoot源码-spring boot启动入口ruan方法主线分析(一)

一、SpringBoot启动的入口 1.当我们启动一个SpringBoot项目的时候&#xff0c;入口程序就是main方法&#xff0c;而在main方法中就执行了一个run方法。 SpringBootApplication public class StartApp {public static void main(String[] args) {// testSpringApplication.ru…...

python json.dump()和json.dumps()的区别

用人话总结一下 json.dump()是针对文件的json和python的转换 json.dumps()主要是针对内容数据 json.dumps(obj, skipkeysFalse, ensure_asciiTrue, check_circularTrue, allow_nanTrue, clsNone, indentNone, separatorsNone, encoding“utf-8”, defaultNone, sort_keysFalse…...

快速排序hoare版本和挖坑法(代码注释版)

hoare版本 #define _CRT_SECURE_NO_WARNINGS 1 #include <stdio.h>// 交换函数 void Swap(int* p1, int* p2) {int tmp *p1;*p1 *p2;*p2 tmp; }// 打印数组 void _printf(int* a, int n) {for (int i 0; i < n; i) {printf("%d ", a[i]);}printf("…...

ELK(Elasticsearch + logstash + kibana + Filebeat + Kafka + Zookeeper)日志分析系统

文章目录 前言架构软件包下载 一、准备工作1. Linux 网络设置2. 配置hosts文件3. 配置免密登录4. 设置 NTP 时钟同步5. 关闭防火墙6. 关闭交换分区7. 调整内存映射区域数限制8. 调整文件、进程、内存资源限制 二、JDK 安装1. 解压软件2. 配置环境变量3. 验证软件 三、安装 Elas…...

SpringBoot中忽略实体类中的某个属性不返回给前端的方法

使用Jackson的方式&#xff1a; //第一种方式&#xff0c;使用JsonIgnore注解标注在属性上&#xff0c;忽略指定属性 public class PropertyDTO {JsonProperty("disable")private Integer disable;JsonProperty("placeholder")private String placeholde…...

Flink中普通API的使用

本篇文章从Source、Transformation&#xff08;转换因子&#xff09;、sink这三个地方进行讲解 Source&#xff1a; 创建DataStream本地文件SocketKafka Transformation&#xff08;转换因子&#xff09;&#xff1a; mapFlatMapFilterKeyByReduceUnion和connectSide Outpu…...

【人工智能】从零构建一个文本分类器:用Python和TF-IDF实现

《Python OpenCV从菜鸟到高手》带你进入图像处理与计算机视觉的大门! 文本分类是自然语言处理(NLP)领域的基础任务之一,广泛应用于垃圾邮件检测、情感分析和新闻分类等场景。本篇文章从零开始,通过详细讲解 TF-IDF 特征提取方法,以及如何将其与机器学习算法结合,实现一…...

原型模式

功能&#xff1a;复制一个运行时的对象&#xff0c;包括对象各个成员当前的值。并且能够通过父类的指针来克隆出子类的对象 主要解决&#xff1a;在运行期建立原型 优点&#xff1a;性能提高、避免了构造函数的约束 步骤&#xff1a; 1、定义抽象原型&#xff0c;声明纯虚接…...

基于FPGA的FM调制(载波频率、频偏、峰值、DAC输出)-带仿真文件-上板验证正确

基于FPGA的FM调制-带仿真文件-上板验证正确 前言一、FM调制储备知识载波频率频偏峰值个人理解 二、代码分析1.模块分析2.波形分析 总结 前言 FM、AM等调制是学习FPGA信号处理一个比较好的小项目&#xff0c;通过学习FM调制过程熟悉信号处理的一个简单流程&#xff0c;进而熟悉…...

open-instruct - 训练开放式指令跟随语言模型

文章目录 关于 open-instruct设置训练微调偏好调整RLVR 污染检查开发中仓库结构 致谢 关于 open-instruct github : https://github.com/allenai/open-instruct 这个仓库是我们对在公共数据集上对流行的预训练语言模型进行指令微调的开放努力。我们发布这个仓库&#xff0c;并…...

Java爬虫:获取1688商品详情接口的技术实现与代码示例

引言 1688作为中国领先的B2B电子商务平台&#xff0c;拥有海量的商品信息。对于商家和市场研究人员来说&#xff0c;能够从1688获取商品详情信息&#xff0c;对于市场分析、竞品研究等具有重要价值。本文将介绍如何使用Java编写爬虫&#xff0c;以合法、高效的方式获取1688商品…...