linux arp 参数整理

linux arp相关参数 在 Linux 中,有多个内核参数可以控制 ARP(地址解析协议)的行为。这些参数可以通过 /proc/sys/net/ipv4/conf/*/ 目录下的文件来配置,或者使用 sysctl 命令来设置。以下是一些常用的 ARP 内核参数及其含义: arp_ignore: 控制系统对不同网络接口上收到的 ARP 请求的响应行为。 取值范围: 0:在任何网络接口上收到 ARP 请求时,系统都会进行响应(默认值)。 1:只有当目标 IP 地址在收到请求的网络接口上配置时,系统才会响应。 2:只有当目标 IP 地址是最接近请求源的地址时,系统才会响应 arp_announce: 控制系统在发送 ARP 请求时,源 IP 地址的选择策略。 取值范围: 0 (默认): 允许使用任意网卡上的 IP 地址作为 ARP 请求的源 IP 地址。通常情况下,会使用 IP 数据包的源 IP。 1: 尽量避免使用不属于该发送网卡子网的本地地址作为发送 ARP 请求的源 IP 地址。 2: 忽略 IP 数据包的源 IP 地址,选择该发送网卡上最合适的本地地址作为 ARP 请求的源 IP 地址。 arp_accept: 控制系统GARP处理,当IP不在ARP表中。(GARP的源地址和目标地址一样), 如果存在直接更新不会判断这个标志 取值范围: 0 (默认值): 始终接受 GARP 数据包并相应地更新 ARP 表。即使 GARP 数据包包含未分配给其任何接口的 IP 地址,系统也会更新其 ARP 缓存。 1: 仅当数据包中的源 IP 地址与分配给系统接口之一的 IP 地址匹配时,才接受 GARP 数据包。这是一种更保守的方法,因为它只更新系统实际使用的地址的 ARP 缓存。 2:(自 Linux 内核 v6.0起)仅当源 IP 地址与接收数据包的接口位于同一子网时,才接受 GARP 数据包。这通过确保仅从同一网络上的设备接受 GARP 数据包来增加另一层安全性。 arp_notify; ...

2024-06-22 · 10 min · 1959 words

负载均衡

负载均衡的定义 In computing, load balancing is the process of distributing a set of tasks over a set of resources (computing units), with the aim of making their overall processing more efficient. Load balancing can optimize response time and avoid unevenly overloading some compute nodes while other compute nodes are left idle. Load balancing is the subject of research in the field of parallel computers. Two main approaches exist: static algorithms, which do not take into account the state of the different machines, and dynamic algorithms, which are usually more general and more efficient but require exchanges of information between the different computing units, at the risk of a loss of efficiency. ...

2024-06-02 · 7 min · 1334 words

VLAN

VLAN A virtual local area network (VLAN) is any broadcast domain that is partitioned and isolated in a computer network at the data link layer (OSI layer 2).[2][3] In this context, virtual refers to a physical object recreated and altered by additional logic, within the local area network. VLANs work by applying tags to network frames and handling these tags in networking systems – creating the appearance and functionality of network traffic that is physically on a single network but acts as if it is split between separate networks. In this way, VLANs can keep network applications separate despite being connected to the same physical network, and without requiring multiple sets of cabling and networking devices to be deployed. ...

2024-05-05 · 27 min · 5562 words

C语言宏参数转换为字符串

用宏定义来定义一个SQL语句, 用来指定字段的长度。那就拼接一下 #include <stdio.h> // 定义字段长度 #define NAME_LENGTH 50 // 定义创建表的SQL语句,使用宏来指定字段长度 #define CREATE_TABLE_SQL "CREATE TABLE Users (ID INT, Name VARCHAR(" NAME_LENGTH "))" int main() { // 输出创建表的SQL语句 printf("SQL Statement: %s\n", CREATE_TABLE_SQL); return 0; } # gcc test2.c -o test2 test2.c: In function ‘main’: test2.c:4:21: error: expected ‘)’ before numeric constant 4 | #define NAME_LENGTH 50 | ^~ test2.c:7:70: note: in expansion of macro ‘NAME_LENGTH’ 7 | #define CREATE_TABLE_SQL "CREATE TABLE Users (ID INT, Name VARCHAR(" NAME_LENGTH "))" | ^~~~~~~~~~~ c的预处理器没有将数字转化为字符串。 ...

2024-04-25 · 1 min · 201 words

conflicts with file from package kernel-debuginfo

安全更新 dnf upgrade-minimal –security 报错信息: install of kernel-debuginfo-5.10.134-16.3.al8.x86_64 conflicts with file from package kernel-debuginfo-5.10.134-16.2.al8.x86_64 Linux 系统上两个版本的 kernel-debuginfo 包之间存在文件冲突。 环境: # cat /etc/redhat-release Alibaba Cloud Linux release 3 (Soaring Falcon) 处理步骤: the older version (5.10.134-16.2.al8.x86_64) the newer verion (5.10.134-16.3.al8.x86_64) ## Remove the older version of the debuginfo package sudo dnf remove kernel-debuginfo-5.10.134-16.2.al8.x86_64 ##Clean the package manager cache sudo dnf clean all ##Reinstall the newer version: sudo dnf install kernel-debuginfo-5.10.134-16.3.al8.x86_64 ##Check for remaining conflicts: sudo dnf check ...

2024-04-13 · 1 min · 77 words

案例学习-Sysbench压测故障

背景: 故障源于知识星球的一个案例: 我们的数据库需要做在线升级丝滑的验证,所以构造了一个测试环境,客户端Sysbench 用长连接一直打压力,同时Server 端的数据库做在线升级,这个在线升级会让 Server进程重启,所以毫无疑问连接会断开重连,所以期望升级的时候 Sysbench端 QPS 跌0几秒钟然后快速恢复。 但是每次升级都是 Sysbench端 QPS永久跌0,再也不能恢复,所以需要分析为什么,问题出在哪里?有人说是服务端的问题因为只有服务端做了变更 整个测试过程中 Sysbench 是配置的2个连接去压 Server 故障重现: https://articles.zsxq.com/id_zj5qazqa4odz.html 下面也保留一份。 1. 数据库 docker run -it -d --net=host -e MYSQL_ROOT_PASSWORD=123 --name=plantegg mysql 2. 安装依赖包 yum install -y java-1.8.0-openjdk.x86_64 java-1.8.0-openjdk-devel.x86_64 podman-docker.noarch wireshark sysbench mysql.x86_64 mysql -h127.1 -uroot -p123 3. 生成数据库 mysql -h127.1 -uroot -p123 -e "create database test" 4. 生成测试数据 sysbench --mysql-user='root' --mysql-password='123' --mysql-db='test' --mysql-host='127.0.0.1' --mysql-port='3306' --tables='16' --table-size='10000' --range-size='5' --db-ps-mode='disable' --skip-trx='on' --mysql-ignore-errors='all' --time='1180' --report-interval='1' --histogram='on' --threads=1 oltp_read_only prepare 5. 压测 sysbench --mysql-user='root' --mysql-password='123' --mysql-db='test' --mysql-host='127.0.0.1' --mysql-port='3306' --tables='16' --table-size='10000' --range-size='5' --db-ps-mode='disable' --skip-trx='on' --mysql-ignore-errors='all' --time='1180' --report-interval='1' --histogram='on' --threads=1 oltp_read_only run 6. kill,mysql进程,复现故障 # mysql -h127.1 -uroot -p123 Welcome to the MariaDB monitor. Commands end with ; or \g. Your MySQL connection id is 14 Server version: 8.3.0 MySQL Community Server - GPL Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MySQL [(none)]> show processlist; +----+-----------------+-----------------+------+---------+------+------------------------+------------------+ | Id | User | Host | db | Command | Time | State | Info | +----+-----------------+-----------------+------+---------+------+------------------------+------------------+ | 5 | event_scheduler | localhost | NULL | Daemon | 94 | Waiting on empty queue | NULL | | 13 | root | 127.0.0.1:33492 | test | Sleep | 0 | | NULL | | 14 | root | 127.0.0.1:51398 | NULL | Query | 0 | init | show processlist | +----+-----------------+-----------------+------+---------+------+------------------------+------------------+ MySQL [(none)]> kill 13; Query OK, 0 rows affected (0.000 sec) ...

2024-04-01 · 6 min · 1098 words

LeetCode - First Duplicate Value

问题: 给定一个整数数组,编写一个函数,返回从左到右读取数组时出现多次的第一个整数。数组元素取值范围是整数1到n, 数组长度为n. 比较特殊情况 [2,3,4,2,3,5] 返回2 [2,3,4,4,2,5] 返回4, 虽然2也是重复数字但是再2之后。 解答: 遍历查找, 两次嵌套循环,同时标注最小索引。 def firstDuplicateValue(array): # Write your code here. max = len(array) value = -1 for i in range(len(array)): for j in range(len(array)): if (j > i and array[j] == array[i]): if (j < max): max = j value = array[i] return value 使用哈希表 def firstDuplicateValue(array): seen = set() for value in array: if value in seen: return value seen.add(value) return -1 ...

2024-03-18 · 1 min · 159 words

MQTT

MQTT ( Message Queuing Telemetry Transport).它是一种轻量级的发布-订阅网络协议,用于在设备之间传输消息。 MQTT 专为硬件资源有限或网络带宽有限的远程位置连接而设计,非常适合 machine-to-machine (M2M) 通信和物联网 (IoT) 应用。 历史: Andy Stanford-Clark (IBM ) 和 Arlen Nipper(当时在Eurotech, Inc.工作)于 1999 年编写了该协议的第一个版本。 它用于监控SCADA工业控制系统内的石油管道。目标是建立一个带宽高效、重量轻且消耗很少电池电量的协议,因为这些设备是通过卫星链路连接的,而卫星链路在当时是极其昂贵的。 从历史上看,“MQTT”中的“MQ”来自IBM MQ(当时的“MQSeries”)产品线,代表“消息队列”,其实他并没有队列。 涉及几个版本: v3.1, 3.1.1 ,5.0。应用比较广泛的是3.1.1版本。MQTT-SN(传感器网络的 MQTT)是主要协议的变体,针对非 TCP/IP 网络上的电池供电嵌入式设备,例如Zigbee。 from wiki https://en.wikipedia.org/wiki/MQTT#cite_note-6 优势及缺点 1. 优势 效率和低带宽使用:MQTT消息小且需要最小的带宽,使得该协议成为具有有限处理能力的IoT设备和带宽受限网络环境的理想选择。 轻量级协议:其简单性和低代码占用使其易于在具有有限内存和处理能力的设备上实施,例如微控制器和小型传感器。 解耦通信:发布-订阅模型允许设备和服务器之间进行解耦通信。发布者和订阅者不需要彼此了解,提高了系统的可扩展性和灵活性。 服务质量等级:MQTT支持三个级别的服务质量(QoS)进行消息传递,使用户可以根据应用程序要求选择更快的传递但可靠性较低,或者传递速度较慢但保证传递。 保留消息:MQTT代理可以保留主题上的消息,确保新订阅者立即收到最后发布的消息,即使在他们订阅之前就已发送。 Last Will 和 Testament (LWT)功能:如果设备意外断开连接,允许设备发布消息到指定的主题,使得设备断开连接的监控和通知更加方便。 安全性:支持使用SSL/TLS进行消息加密的安全通信,除了应用层安全实践,如身份验证和授权。 2. 缺点 依赖代理:中心代理架构可能成为失败的单一点。如果代理关闭,整个消息系统将受到影响。 安全开销:虽然MQTT支持SSL/TLS,但实施这些安全措施可能会增加复杂性和开销,特别是在非常受限的设备上。 服务质量开销:更高的QoS级别(1和2)确保消息传递,但引入了额外的开销,这可能影响性能,特别是在受限网络上。 消息载荷:MQTT不强制执行任何载荷格式,这意味着消息的解释取决于发布者和订阅者之间的协议。这种灵活性很强大,但如果不仔细管理,也可能导致不一致。 代理性能和可扩展性:MQTT系统的性能和可扩展性可能严重依赖于代理的能力。大量的消息或大量的客户端需要一个健壮、配置良好的代理。 其中MQTT的payload格式是没有要求的, 可以是二进制, 名为字符串, json/xml或者自定义个格式, 对于业务的哦通讯协议要双方协定好。 使用场景 1. 物联网(IoT) MQTT 在 IoT 中得到广泛使用,用于将各种设备、传感器和执行器连接到互联网或其他网络。这使得可以远程监控和控制设备,如智能家电、环境传感器和工业机器。 智能家居:远程控制照明、供暖、安全系统和其他家用电器。 农业:监控土壤湿度和温度传感器,以优化灌溉系统。 2. 工业自动化 ...

2024-03-17 · 3 min · 528 words

curl support TLCP using TASSL

TLCP 传输层密码协议TLCP 对应 TLS协议, 在GB/T 38636-2020规范中定义。支持国密sm2, sm3, sm4密钥套件。增加加密证书, 6.4.5.3章节中提到 选择ECC, ECDHE算法,密钥交换算法使用用加密证书公钥。 https://blog.csdn.net/shenshaojun/article/details/114576162 这里对密钥体系进行了说明, 目前没看到标准里介绍,加密证书CA生成,并拥有私钥。这样的涉及对于信息保密性要依赖CA机构? CURL curl工具目前还不支持TLCP,一般需要进行简单修改。 目前支持国密库: GMSSL Tongsuo 铜锁 江南天安TASSL TencentKonaSMSuite curl支持TLCP: GMSSL 开源版本 : https://github.com/pengtianabc/curl-gm Tongsuo : https://github.com/Tongsuo-Project/curl CURL compile using TASSL 具体实现:https://github.com/weida/Curl-with-TASSL-support-for-TLCP 需要注意新版本curl的参数使用二分查找,参数需要自己排序 "src/tool_getparam.c" /* this array MUST be alphasorted based on the 'lname' */ static const struct LongShort aliases[]= { ... 目前测试环境仅有linux版本,只提了个linux patch。 参考及引用: https://zhuanlan.zhihu.com/p/564452283 https://www.cnblogs.com/anding/p/17627553.html 图片from陳丁光

2024-02-16 · 1 min · 61 words

http3 - nginx with quictls

nginx 从1.25开始支持QUIC和http3 # quictls 编译安装 ./Configure --prefix=$HOME/quictls --openssldir=$HOME/openssl-quic -fPIC no-shared make && make install # nginx 编译安装 auto/configure --with-debug --with-http_v3_module --with-http_v2_module --with-cc-opt="-I $HOME/quictls/include" --with-ld-opt="-L $HOME/quictls/lib64" --prefix=$HOME/nginx-quic --with-cc-opt="-DNGX_QUIC_DEBUG_PACKETS -DNGX_QUIC_DEBUG_CRYPTO" --with-openssl=$HOME/install/openssl make && make install nginx.conf user root; worker_processes 1; error_log logs/error.log debug; #pid logs/nginx.pid; events { worker_connections 1024; } http { log_format quic '$remote_addr - $remote_user [$time_local] ' '"$request" $status $body_bytes_sent ' '"$http_referer" "$http_user_agent" "$http3"'; access_log logs/access.log quic; server { # for better compatibility it's recommended # to use the same port for quic and https listen 443 quic reuseport; listen 443 ssl ; http3 on; http2 on; quic_retry on; ssl_early_data on; #server_name server_name; ssl_certificate certs/cert.pem; ssl_certificate_key certs/priv.key; ssl_protocols TLSv1.3; add_header Alt-Svc 'h3=":443"; ma=86400'; location / { index index.html index.htm; } } } ...

2024-02-16 · 2 min · 215 words