系统学习Linux-keepalived

news2025/1/24 17:42:00

目录

keepalived双机热备

keepalived+lvs(DR)

1.实验环境 

先配置主调度器

web节点配置        


keepalived双机热备

web服务器安装nginx和keepalived

配置好这些可以进行漂移了 

复制keepalived.conf 进行修改web1为主web2为从优先级设置好

#web1服务器
[root@localhost ~]# yum install -y keepalived nginx
[root@localhost ~]# cd /etc/keepalived/
[root@localhost keepalived]# cp keepalived.conf keepalived.conf.bak
[root@localhost keepalived]# vim keepalived.conf.bak 
! Configuration File for keepalived

global_defs {
   router_id NGINX1
}

vrrp_instance VI_1 {
    state MASTER
    interface ens33
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.31.100
        192.168.31.101
        192.168.31.102
    }
}
[root@localhost keepalived]# systemctl restart keepalived.service 

#web2服务器
[root@localhost ~]# yum install -y keepalived nginx
[root@localhost ~]# cd /etc/keepalived/
[root@localhost keepalived]# cp keepalived.conf keepalived.conf.bak
[root@localhost keepalived]# vim keepalived.conf.bak 
! Configuration File for keepalived

global_defs {
   router_id NGINX2
}

vrrp_instance VI_1 {
    state BACKUP
    interface ens33
    virtual_router_id 51
    priority 90
    advert_int 1
    authentication { 
        auth_type PASS
        auth_pass 1111
    }         
    virtual_ipaddress {
        192.168.31.100
        192.168.31.101
        192.168.31.102
    }       
}   
[root@localhost keepalived]# systemctl restart keepalived.service 
   

启动服务后ip a查看主从ip

web1虚ip已存在

#web1
[root@localhost keepalived]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet 192.168.31.200/32 brd 192.168.31.200 scope global lo:0
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:12:94:c3 brd ff:ff:ff:ff:ff:ff
    inet 192.168.31.5/24 brd 192.168.31.255 scope global noprefixroute ens33
       valid_lft forever preferred_lft forever
    inet 192.168.31.100/32 scope global ens33
       valid_lft forever preferred_lft forever
    inet 192.168.31.101/32 scope global ens33
       valid_lft forever preferred_lft forever
    inet 192.168.31.102/32 scope global ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe12:94c3/64 scope link 
       valid_lft forever preferred_lft forever
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
    link/ether 52:54:00:45:34:d8 brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
       valid_lft forever preferred_lft forever
4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN group default qlen 1000
    link/ether 52:54:00:45:34:d8 brd ff:ff:ff:ff:ff:ff

#web2
[root@localhost ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet 192.168.31.200/32 brd 192.168.31.200 scope global lo:0
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:49:51:51 brd ff:ff:ff:ff:ff:ff
    inet 192.168.31.6/24 brd 192.168.31.255 scope global noprefixroute ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe49:5151/64 scope link 
       valid_lft forever preferred_lft forever
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
    link/ether 52:54:00:45:34:d8 brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
       valid_lft forever preferred_lft forever
4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN group default qlen 1000
    link/ether 52:54:00:45:34:d8 brd ff:ff:ff:ff:ff:ff

写入web1与web2网页内容

#web1
[root@localhost keepalived]# cd /usr/share/nginx/html/
[root@localhost html]# ls
404.html  50x.html  en-US  icons  img  index.html  nginx-logo.png  poweredby.png
[root@localhost html]# echo nginx1 > index.html 
[root@localhost html]# systemctl restart nginx

#web2
[root@localhost ~]# cd /usr/share/nginx/html/
[root@localhost html]# ls
404.html  50x.html  en-US  icons  img  index.html  nginx-logo.png  poweredby.png
[root@localhost html]# echo nginx2 > index.html 
[root@localhost html]# systemctl restart nginx

主测试

因master正常运行所以现在访问的是web1主服务

[root@localhost keepalived]# curl 192.168.31.100
nginx1
[root@localhost keepalived]# curl 192.168.31.101
nginx1
[root@localhost keepalived]# curl 192.168.31.102
nginx1

 ​​​​​​如果停掉master会自动切换到backup(web2上)

注这里有一个问题配置文件复制修改的是keepalived.conf.bak这个是有错误的,修改原配置文件才可以适配到所以我删除了复制出来的bak,修改的原文件才适配成功

#web1
[root@localhost html]# systemctl stop keepalived.service 

#web2
[root@localhost keepalived]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet 192.168.31.200/32 brd 192.168.31.200 scope global lo:0
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:49:51:51 brd ff:ff:ff:ff:ff:ff
    inet 192.168.31.6/24 brd 192.168.31.255 scope global noprefixroute ens33
       valid_lft forever preferred_lft forever
    inet 192.168.31.100/32 scope global ens33
       valid_lft forever preferred_lft forever
    inet 192.168.31.101/32 scope global ens33
       valid_lft forever preferred_lft forever
    inet 192.168.31.102/32 scope global ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe49:5151/64 scope link 
       valid_lft forever preferred_lft forever
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
    link/ether 52:54:00:45:34:d8 brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
       valid_lft forever preferred_lft forever
4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN group default qlen 1000
    link/ether 52:54:00:45:34:d8 brd ff:ff:ff:ff:ff:ff

 到主上测试自动切换master成功

[root@localhost keepalived]# curl 192.168.31.100
nginx2
[root@localhost keepalived]# curl 192.168.31.101
nginx2
[root@localhost keepalived]# curl 192.168.31.102
nginx2

测试断掉web1网卡等待地址漂移到web2上

网卡测试失败有bug或者过慢(正常停网卡可以)

停网卡形成脑裂现象服务还在,主依然是主,从依然是从,

停服务可以直接跳到web2服务


主机上配置FNS共享目录

#主机上配置NFS共享
[root@localhost keepalived]# mkdir /opt/pub
[root@localhost keepalived]# vim /etc/exports
/opt/pub        192.168.31.0/24(rw,sync,no_root_squash)

rpcbind安装fns-utils和fns

[root@localhost keepalived]# systemctl start nfs
[root@localhost keepalived]# showmount -e
Export list for localhost.localdomain:
/opt/put 192.168.31.0/24

#命令用于查找 showmount 命令的路径。
[root@localhost keepalived]# which showmount
/usr/sbin/showmount
#命令用于查询已安装软件包中包含指定文件的软件包。
[root@localhost keepalived]# rpm -qf /usr/sbin/showmount 
nfs-utils-1.3.0-0.68.el7.x86_64
#命令用于重新导出所有已经在 /etc/exports 文件中定义的共享目录。
[root@localhost keepalived]# exportfs -arv
exporting 192.168.31.0/24:/opt/pub

web2、3

[root@localhost keepalived]# showmount -e 192.168.31.4
Export list for 192.168.31.4:
/opt/pub 192.168.31.0/24
[root@localhost keepalived]# mount 192.168.31.4:/opt/pub /usr/share/nginx/html/



[root@localhost keepalived]# showmount -e 192.168.31.4
Export list for 192.168.31.4:
/opt/pub 192.168.31.0/24
[root@localhost keepalived]# mount 192.168.31.4:/opt/pub /usr/share/nginx/html/

403是因为没有共享的网页文件内容

[root@localhost keepalived]# cd /opt/pub/
[root@localhost pub]# echo test > index.html

 去web1停掉服务后继续测试网页

[root@localhost keepalived]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet 192.168.31.200/32 brd 192.168.31.200 scope global lo:0
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:12:94:c3 brd ff:ff:ff:ff:ff:ff
    inet 192.168.31.5/24 brd 192.168.31.255 scope global noprefixroute ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe12:94c3/64 scope link 
       valid_lft forever preferred_lft forever
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
    link/ether 52:54:00:45:34:d8 brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
       valid_lft forever preferred_lft forever
4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN group default qlen 1000
    link/ether 52:54:00:45:34:d8 brd ff:ff:ff:ff:ff:ff

依然可以访问内容ip虽然一样但现在访问的已经是web2的虚地址 

#web2
[root@localhost keepalived]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet 192.168.31.200/32 brd 192.168.31.200 scope global lo:0
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:49:51:51 brd ff:ff:ff:ff:ff:ff
    inet 192.168.31.6/24 brd 192.168.31.255 scope global noprefixroute ens33
       valid_lft forever preferred_lft forever
    inet 192.168.31.100/32 scope global ens33
       valid_lft forever preferred_lft forever
    inet 192.168.31.101/32 scope global ens33
       valid_lft forever preferred_lft forever
    inet 192.168.31.102/32 scope global ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe49:5151/64 scope link 
       valid_lft forever preferred_lft forever
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
    link/ether 52:54:00:45:34:d8 brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
       valid_lft forever preferred_lft forever
4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN group default qlen 1000
    link/ether 52:54:00:45:34:d8 brd ff:ff:ff:ff:ff:ff

挂过来如果目录从755变成644需要改回去


keepalived+lvs(DR)

使用keepalived解决lvs的单点故障

高可用集群


1.实验环境 

四台主机

vip(虚拟地址):192.168.31.200

角色主机名IP接口
从调度器ds01 192.168.31.3enss33
主调度器ds02 192.168.31.4enss33
rs节点1rs01192.168.31.5enss33
rs节点2rs02192.168.31.6enss33

加入LVS就需要设置以下配置

主从需要安装并加载mod

yum install -y keepalived

yum install -y ipvsadm

modprobe ip_vs

先配置主调度器

#主调度器ds02
[root@localhost keepalived]# vim keepalived.conf 
! Configuration File for keepalived

global_defs {
   notification_email {
     acassen@firewall.loc
     failover@firewall.loc
     sysadmin@firewall.loc
   }
   notification_email_from Alexandre.Cassen@firewall.loc
   smtp_server 192.168.200.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL1
   vrrp_skip_check_adv_addr
#  vrrp_strict
   vrrp_garp_interval 0
   vrrp_gna_interval 0
}

vrrp_instance VI_1 {
    state MASTER
    interface ens33
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.31.200
    }
}
! Configuration File for keepalived

    }
}

virtual_server 192.168.31.200 80 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    persistence_timeout 50
    protocol TCP

    real_server 192.168.31.5 80 {
        weight 1
        HTTP GET {
            url {
              path /
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
            real_server 192.168.31.6 80 {
        weight 1
        HTTP_GET {
            url {
              path /
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
}

复制配置内容到从调度器ds01或者scp传输

#从调度器ds01
[root@localhost keepalived]# vim keepalived.conf 


! Configuration File for keepalived

global_defs {
   notification_email {
     acassen@firewall.loc
     failover@firewall.loc
     sysadmin@firewall.loc
   }
   notification_email_from Alexandre.Cassen@firewall.loc
   smtp_server 192.168.200.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL2
   vrrp_skip_check_adv_addr
#  vrrp_strict
   vrrp_garp_interval 0
   vrrp_gna_interval 0
}

vrrp_instance VI_1 {
    state BACKUP
    interface ens33
    virtual_router_id 51
    priority 90
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.31.200
    }
}

    virtual_ipaddress {
        192.168.31.200
    }
}

virtual_server 192.168.31.200 80 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    persistence_timeout 50
    protocol TCP

    real_server 192.168.31.5 80 {
        weight 1
        HTTP GET { 
            url {
              path /
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
            real_server 192.168.31.6 80 {
        weight 1
        HTTP_GET {
            url {
              path /
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
}

重启服务并查看查看lvs节点状态

#主调度器ds02
[root@localhost pub]# systemctl restart keepalived.service 
[root@localhost keepalived]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  192.168.31.200:80 rr persistent 50
  -> 192.168.31.5:80              Route   1      0          0     
  -> 192.168.31.6:80              Route   1      0          0   

#从调度器ds01
[root@localhost pub]# systemctl restart keepalived.service 
[root@localhost keepalived]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  192.168.31.200:80 rr persistent 50
  -> 192.168.31.5:80              Route   1      0          0     
  -> 192.168.31.6:80              Route   1      0          0   

web节点配置        

调整ARP参数(rs1、2节点都需要配置)

net.ipv4.conf.all.arp_ignore=1
net.ipv4.conf.all.arp_announce=2
net.ipv4.conf.default.arp_ignore=1
net.ipv4.conf.default.arp_announce = 2
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce=2

[root@localhost keepalived]# vim /etc/sysctl.conf
[root@localhost keepalived]# sysctl -p
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.default.arp_ignore = 1
net.ipv4.conf.default.arp_announce = 2
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2

配置虚拟IP地址

#rs节点1、2相同配置
[root@localhost keepalived]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# cp ifcfg-lo ifcfg-lo:0
[root@localhost network-scripts]# vim ifcfg-lo:0

DEVICE=lo:0
IPADDR=192.168.31.200
NETMASK=255.255.255.255
ONBOOT=yes
NAME=loopback:0
#添加回环路径
[root@localhost network-scripts]# route add -host 192.168.31.200/32 dev lo:0

测试

停掉主调度器ds02

systemctl stop keepalived.service 

此时依然可以访问证明主从搭建成功,从已经开始工作

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/924425.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

WPF网格拖动自动布局效果

WPF网格拖动自动布局效果 使用Canvas和鼠标相关事件实现如下的效果: XAML代码: <Window x:Class="CanvasTest.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:

WebGL 缓冲区对象介绍,创建并使用缓冲区,使用缓冲区对象向顶点着色器传入多个顶点数据的所有步骤

目录 使用缓冲区对象 使用缓冲区对象向顶点着色器传入多个顶点的数据&#xff0c;需要遵循以下五个步骤。 创建缓冲区对象&#xff08;gl.createBuffer&#xff08;&#xff09;&#xff09; gl.createBuffer&#xff08;&#xff09;的函数规范 gl.deleteBuffer &#…

[管理与领导-46]:IT基层管理者 - 8项核心技能 - 1 - 目标管理

目录 前言&#xff1a; 一、什么是目标管理 二、管理目标的维度 2.1 个人目标维度 2.2 绩效评估的维度 三、目标的分解 四、目标制定的SMART原则 五、目标管理的误解 六、目标管理的注意事项 七、目标无法实现的因素 前言&#xff1a; 管理者存在的价值就是制定目标…

React Diff算法

文章目录 React Diff算法一、它的作用是什么&#xff1f;二、React的Diff算法1.了解一下什么是调和&#xff1f;2.react的diff算法3.React Diff的三大策略4.tree diff&#xff1a;1、如果DOM节点出现了跨层级操作&#xff0c;Diff会怎么办? 5. component diff&#xff1a;6. e…

maven工程的目录结构

https://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html maven工程的目录结构&#xff1a; 在maven工程的根目录下面&#xff0c;是pom.xml文件。此外&#xff0c;还有README.txt、LICENSE.txt等文本文件&#xff0c;便于用户能够…

Jenkins 详细安装流程及填坑记录「图文」

目录 一、前言 二、环境准备 三、安装步骤 1、安装jdk 2、安装jenkins 3、配置修改 4、jenkins启动 四、登录jenkins 一、前言 省流&#xff1a;本文仅记录Jenkins详细安装过程&#xff0c;以及安装过程中经常遇到的问题。 二、环境准备 Linux系统&#xff1a;CentOS…

spdlog输出日志等级控制由set_level运行时和#define SPDLOG_ACTIVE_LEVEL编译时共同控制

spdlog输出日志等级控制由set_level运行时和#define SPDLOG_ACTIVE_LEVEL编译时共同控制 common.h中 spdlog.h中 控制log活跃级别是INFO

网络安全工具和资源推荐: 介绍网络安全领域中常用的工具、框架、资源和学习资料

章节1: 前言 随着数字化时代的不断深入&#xff0c;网络安全的重要性愈发凸显。在这个信息爆炸的时代&#xff0c;我们必须保护个人隐私、敏感数据以及网络基础设施免受各种威胁。本文将为您介绍一些网络安全领域中常用的工具、框架、资源和学习资料&#xff0c;帮助您更好地入…

CSS中的vertical-align属性

vertical-align 1.CSS属性 - vertical-align 2.深入理解vertical-align – line boxes This property affects the vertical positioning inside a line box of the boxes generated by an inline-levelelement. 官方文档的翻译&#xff1a;vertical-align会影响 行内块级元素…

VSCode 如何解决 scanf 的输入问题——Code is already running!

文章如何使用 VSCode 软件运行C代码中已经介绍了如何在 VSCode 软件中运行C代码&#xff0c;但最近在使用 scanf 想从键盘输入时&#xff0c;运行代码后显示“Code is already running!”&#xff0c;如下图所示&#xff0c;在输出窗口是无法通过键盘输入的。 解决办法如下&am…

vue若依导出word文件,简单的实现

首先前端导包,注意exportDocx的导包位置要修改成你自己的 import {exportDocx} from /utils/docUtil/docutil.js; import {addDays} from date-fns; import {listGongyi} from "/api/system/detail";然后新建一个测试按钮 <el-col :span"1.5"><…

C++中<iostream> 的cin >> str 和<string>的getline(cin, str) 用来读取用户输入的两种不同方式的不同点

C中<iostream> 的cin >> str 和<string>的getline(cin, str) 用来读取用户输入的两种不同方式的不同点 getline()函数语法如下【https://cplusplus.com/reference/string/string/getline/】&#xff1a; istream& getline (istream& is, string&am…

LLaMA中ROPE位置编码实现源码解析

1、Attention中q&#xff0c;经下式&#xff0c;生成新的q。m为句长length&#xff0c;d为embedding_dim/head θ i 1 1000 0 2 i d \theta_i\frac{1}{10000^\frac{2i}{d}} θi​10000d2i​1​ 2、LLaMA中RoPE源码 import torchdef precompute_freqs_cis(dim: int, end: i…

自动化测试之Selenium

自动化测试Selenium介绍环境搭建如何操作浏览器定位元素css类选择器定位元素xpath定位元素css选择语法xpath选择语法 常用操作添加等待打印信息浏览器更多操作键盘事件鼠标事件特殊场景只选复选框iframe标签下拉框处理弹窗显示上传文件 关闭浏览器切换窗口截图 自动化测试 自动…

ubuntu20.04 直接安装vpp23.06 测试双 VPP Tunnel Ike2

环境信息&#xff1a;VMware Workstation 17 Pro ubuntu20.04 (清华源) ubuntu 源点进去选&#xff1a;ubuntu-22.04.3-desktop-amd64.iso 如果之前装过VPP&#xff0c;用以下命令确定是否卸载干净&#xff1a; dpkg -l | grep vpp dpkg -l | grep DPDK 卸载&#xff1a; …

ChatGPT + Flutter快速开发多端聊天机器人App

下载地址&#xff1a;ChatGPT Flutter快速开发多端聊天机器人App 下载地址&#xff1a;ChatGPT Flutter快速开发多端聊天机器人App

SpringCloud学习笔记(五)_Consul注册中心

本章使用的Consul版本是 1.7.2 项目架构图如下&#xff1a; 搭建服务提供者 1、新建一个maven项目&#xff08;test-springcloud-provider-payment8006&#xff09; 结构如下&#xff1a; 2、引入依赖&#xff0c;编辑pom文件 1 <!-- spring-cloud 整合 consul --> 2…

MyBatis分页与特殊字符处理

文章目录 一、分页1.1 分页插件PageHelper1.2 使用1.2.1 导入pom依赖1.2.2 Mybatis.cfg.xml配置拦截器1.2.3. 配置 Mapper.xml1.2.4 测试 二、特殊字符处理2.1 使用CDATA区段2.2 使用实体引用 一、分页 1.1 分页插件PageHelper PageHelper 是 Mybatis 的一个插件。官网 Page…

SOLIDWORKS提高装配效率的方法:阵列特征驱动阵列

相信SOLIDWORKS用户很喜欢SOLIDWORKS阵列命令&#xff0c;因为阵列可以提高设计效率&#xff0c;减少错误&#xff0c;修改也很方便&#xff0c;但是大家一般在零件里用阵列来阵列特征&#xff0c;在装配体里用阵列来阵列零件&#xff0c;那有没有办法用零件中的阵列特征来驱动…

开源与专有软件:比较与对比

&#x1f337;&#x1f341; 博主猫头虎 带您 Go to New World.✨&#x1f341; &#x1f984; 博客首页——猫头虎的博客&#x1f390; &#x1f433;《面试题大全专栏》 文章图文并茂&#x1f995;生动形象&#x1f996;简单易学&#xff01;欢迎大家来踩踩~&#x1f33a; &a…