高效文件处理工具 yq

在处理小程序文章索引 JSON 文件时,发现了这个好工具 yq,特分享给大家。 yq 是一个轻量级、命令行驱动的文件处理工具,专门用于处理 YAML、JSON、XML 等结构化数据格式。它类似于著名的 jq(专门处理 JSON 的工具),但扩展了对 YAML 的原生支持,并能够处理多种文件格式之间的转换。 yq 采用 Go 语言编写,具有跨平台特性,可以在 Linux、macOS 和 Windows 系统上运行。它的核心功能包括查询、过滤、修改和转换结构化数据文件。 yq 在大多数 Linux 发行版可以通过包管理器安装: # Ubuntu/Debian sudo apt install yq # CentOS/RHEL sudo yum install yq # macOS (使用 Homebrew) brew install yq 或者从 Github 发布页面下载预编译的二进制文件。 yq 常用于: 配置文件处理,例如在 DevOps 和云原生环境中处理 YAML 等配置文件。 数据转换,在不同格式(YAML/JSON/XML/CSV)之间进行转换 数据提取,从复杂数据结构中提取特定字段或值 批量修改,对多个文件中的特定字段进行统一修改 自动化脚本,在 shell 脚本中处理结构化数据 数据验证,检查配置文件是否符合特定结构或值要求 下面是一些使用示例: 1,查询 YAML 文件 假设我们有一个 config.yaml 文件: server: port: 8080 host: "localhost" database: name: "test_db" user: "admin" 我们要获取服务器端口: ...

2025-02-01 · 3 min · Eagle

自签名证书无法在网盘cloudreve使用S3通过https协议连接Minio

Cloudreve是一个自托管文件管理与共享系统,支持多存储提供商。我们需要集成Minio的S3服务。现在碰到了问题,在填写参数后,无法在客户端上传文件。 我们的Minio服务使用自签名证书。排查发现应该是证书问题。现在需要在系统中安装证书。 我们已经解决,具体步骤如下: 1,检查证书是否PEM格式? 检查方法: cat public.crt 如果开头是 —–BEGIN CERTIFICATE—–,则是 PEM 格式。 如果是一堆乱码,则是 DER 格式。需要转换为PEM格式:openssl x509 -inform der -in public.crt -out public.pem 2,放置证书 在CentOS Linux中,需要将证书文件放在/etc/pki/ca-trust/source/anchors/目录下,并且后缀必须为.crt。如果文件名为public.pem,需要改为public.crt。 确认文件是否放置正确? ls /etc/pki/ca-trust/source/anchors/ 输出中应包含我们的证书。 3,激活证书 执行以下命令激活,依次执行: update-ca-trust extract update-ca-trust 4,验证证书是否激活成功 tail -n 20 /etc/pki/tls/certs/ca-bundle.crt 查看是否是自己的证书,如果还没有成功,执行命令追加: cat public.crt | sudo tee -a /etc/pki/tls/certs/ca-bundle.crt 最后,使用 grep 搜索证书中关键的信息 grep -i "域名信息" /etc/pki/tls/certs/ca-bundle.crt 这个时候应该可以搜索了。 5,验证在系统中使用证书 我们使用命令检验Minio是否可以使用自签名证书 curl -v https://yourdomain.com:9000 如果输出SSL证书信息,并显示Access 相关信息,则成功了。如果没有,则需要再次检查证书生成信息是否正确?例如,是否包含了正确的域名? 6,重启Cloudreve网盘服务 最后一定要重启Cloudreve网盘,只有重启之后才能加载系统自定义证书。

2025-01-13 · 1 min · Eagle

Netstat 常用命令

查询本机 IP 连接 netstat -an 查看网络 TCP 连接状态数量 netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}' 查看 8080 端口有多少个 TCP 连接 netstat -ant |grep 8080|wc -l 查看当前 TCP 连接状态为 ESTABLISHED 的数量 netstat -ant|grep 8080|grep ESTABLISHED|wc -l 查看 TCP 连接 netstat -ant 过滤某个 TCP 端口 netstat -ant |grep 端口号 查看 UDP 连接 netstat -anu 过滤某个 UDP 端口 netstat -anu |grep 端口号 实时监控 UDP 连接信息,每隔 2 秒自动更新一次 watch -n 2 'netstat -anu' 使用 ss 或 netstat 关联进程和端口 ...

2025-01-01 · 2 min · Eagle

Asterisk 常见错误

Asterisk 是第一套以开放源代码软件实现的 用户交换机 (PBX) 系统。Asterisk 由 Digium 的创办人马克·史宾瑟(Mark Spencer)于 1999 年他还在奥本大学念书时所开发。与其他的用户交换机系统相同,Asterisk 同样支持电话拨打另一只分机,和拨打到公共交换电话网与 IP 电话系统。Asterisk 这个名称源自于星号 “*"。 网址:https://www.asterisk.org/ Asterisk 常见错误 403 登录失败 解决:等待 1 分钟,等超时之后重新连接即可。一般是切换 IP 时或者换软电话登录会碰到。 401 登录失败 解决:检查账户和密码是否正确?检查连接地址是否正确?检查 Asterisk 是否启动?检查防火墙端口是否打开? 408 连接超时 解决:一般是 Asterisk 服务不通,检查 Asterisk 服务是否启动,检查防火墙是否打开? 可以拨通,没有声音? 一般是 NAT 造成,配置这三个参数:rtp_symmetric,force_rport,rewrite_contact。 SIP 客户端没有自动挂机? 一般是没有设置 stun 造成的,在 SIP 客户端,设置 stun 即可。如果没有 stun server,可以设置这个stun.l.google.com:19302 AGI 脚本返回状态 4,正常应该为 0? 查看网上资料,是 AGI 脚本中调用 Hangup 导致,将脚本中的 Hangup 去掉,放在拨号计划配置文件中执行 Hangup,可以解决这个问题。 AGI Script agidemo completed, returning 0 解决 asterisk 没有声音的问题 在配置好 asterisk 之后,拨打 8000 没有听到声音。 ...

2025-01-01 · 1 min · Eagle

Bash 常用命令

查看内存占用 ps aux | grep soffice | grep -v grep | awk '{print $6/1024 " MB"}' 查看日志 查询 IP 信息,查找某条请求记录,然后打印出 IP 那一列,进行排序,再去重。可以得出请求的 IP 信息。 cat golog/20240905_ad.log |grep 'ad'|awk '{print $9}'|sort|uniq 从 IP 归属地库查询省份城市信息 cat ip.merge.txt |grep '河南省'|awk -v FS="|" '{print $5}'|sort|uniq 将行记录变成一行,并以逗号分割。 cat ip.merge.txt |grep '河南省'|awk -v FS="|" '{print $5}'|sort|uniq|paste -s -d "," Awk awk 是一种处理文本文件的语言,是一个强大的文本分析工具。 使用分隔符指定列: awk -F',' '{print $1, $2}' file 打印满足条件的行数: awk '/pattern/ {print NR, $0}' file SCP 正则匹配复制文件 scp 可以使用正则复制文件,一次复制多个文件 scp -P 2222 \*.mp4 root@host:/data/upfile/ scp 还可以复制文件夹,使用-r 属性,递归复制,例如下面的格式: ...

2025-01-01 · 2 min · Eagle

Curl 用法

cURL(Client URL)是一个功能强大的命令行工具,用于通过 URL 传输数据,支持多种协议(如 HTTP/HTTPS、FTP、SFTP、SCP 等)。它广泛用于 API 测试、文件传输、数据提交等场景。 安装 Linux (Debian/Ubuntu) sudo apt-get install curl macOS brew install curl # 通过Homebrew安装/更新 Windows 从官网下载二进制文件 或使用 Chocolatey: choco install curl 基本用法 发起 GET 请求 curl https://example.com 保存响应到文件 curl -o custom_filename.html https://example.com # 自定义文件名 curl -O https://example.com/file.zip # 使用远程文件名 常用选项 选项 说明 -v 显示详细日志(请求头、响应头、SSL 信息) -L 自动跟随重定向 -s 静默模式(隐藏进度条和错误信息) -i 显示响应头 + 响应体 -I 仅显示响应头(发送 HEAD 请求) -k 跳过 SSL 证书验证(不安全,谨慎使用) -A 设置 User-Agent,如 -A "Mozilla/5.0" HTTP 方法 POST 请求(表单数据) curl -X POST https://api.example.com/data -d "name=John&age=30" POST 请求(JSON 数据) curl -X POST -H "Content-Type: application/json" \ -d '{"name":"John", "age":30}' https://api.example.com/data PUT/DELETE 请求 curl -X PUT https://api.example.com/item/1 -d "data=example" curl -X DELETE https://api.example.com/item/1 处理 HTTP 头 查看响应头 curl -I https://example.com 发送自定义头 curl -H "Authorization: Bearer token123" \ -H "X-Custom-Header: value" https://api.example.com 文件传输 上传文件(表单) curl -F "file=@/path/to/file.txt" https://example.com/upload 上传文件(FTP) curl -T file.txt ftp://example.com/upload/ 断点续传 curl -C - -O https://example.com/large-file.zip 认证 基本认证(Basic Auth) curl -u username:password https://example.com Cookie 管理 curl -c cookies.txt https://example.com/login # 保存Cookie curl -b cookies.txt https://example.com/dashboard # 发送Cookie 高级功能 限速下载(100KB/s) curl --limit-rate 100K -O https://example.com/large-file.zip 使用代理 curl -x http://proxy-server:8080 https://example.com 调试请求 curl --trace-ascii debug.txt https://example.com 实际示例 下载 GitHub 仓库 curl -L -O https://github.com/user/repo/archive/master.zip 模拟浏览器访问 curl -A "Mozilla/5.0" -H "Accept-Language: en-US" https://example.com 调试 HTTPS 请求 curl -v -k https://example.com # 查看SSL握手过程(忽略证书错误) 注意事项 敏感数据:避免在命令行中直接暴露密码,推荐使用--netrc或环境变量。 HTTPS 安全:生产环境中尽量不使用-k(跳过证书验证)。 命令顺序:组合选项时注意顺序(如-L -O需先重定向再保存文件)。 速率限制:使用--limit-rate避免占用过多带宽。

2025-01-01 · 2 min · Eagle

Docker 常用命令

DOCKER Docker 是一个开源的应用容器引擎,基于 Go 语言 并遵从 Apache2.0 协议开源。 Docker 可以让开发者打包他们的应用以及依赖包到一个轻量级、可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟化。 容器是完全使用沙箱机制,相互之间不会有任何接口(类似 iPhone 的 app),更重要的是容器性能开销极低。 Docker 网址:https://www.docker.com/ Docker 常用命令: docker init # Creates Docker-related starter files docker build -t friendlyname . # Create image using this directory's Dockerfile docker run -p 4000:80 friendlyname # Run "friendlyname" mapping port 4000 to 80 docker run -d -p 4000:80 friendlyname # Same thing, but in detached mode docker exec -it [container-id] bash # Enter a running container docker ps # See a list of all running containers docker stop <hash> # Gracefully stop the specified container docker ps -a # See a list of all containers, even the ones not running docker kill <hash> # Force shutdown of the specified container docker rm <hash> # Remove the specified container from this machine docker rm -f <hash> # Remove force specified container from this machine docker rm $(docker ps -a -q) # Remove all containers from this machine docker images -a # Show all images on this machine docker rmi <imagename> # Remove the specified image from this machine docker rmi $(docker images -q) # Remove all images from this machine docker logs <container-id> -f # Live tail a container's logs docker login # Log in this CLI session using your Docker credentials docker tag <image> username/repository:tag # Tag <image> for upload to registry docker push username/repository:tag # Upload tagged image to registry docker run username/repository:tag # Run image from a registry docker system prune # Remove all unused containers, networks, images (both dangling and unreferenced), and optionally, volumes. (Docker 17.06.1-ce and superior) docker system prune -a # Remove all unused containers, networks, images not just dangling ones (Docker 17.06.1-ce and superior) docker volume prune # Remove all unused local volumes docker network prune # Remove all unused networks DOCKER COMPOSE docker-compose up # Create and start containers docker-compose up -d # Create and start containers in detached mode docker-compose down # Stop and remove containers, networks, images, and volumes docker-compose logs # View output from containers docker-compose restart # Restart all service docker-compose pull # Pull all image service docker-compose build # Build all image service docker-compose config # Validate and view the Compose file docker-compose scale <service_name>=<replica> # Scale special service(s) docker-compose top # Display the running processes docker-compose run -rm -p 2022:22 web bash # Start web service and runs bash as its command, remove old container. DOCKER SERVICES docker service create <options> <image> <command> # Create new service docker service inspect --pretty <service_name> # Display detailed information Service(s) docker service ls # List Services docker service ps # List the tasks of Services docker service scale <service_name>=<replica> # Scale special service(s) docker service update <options> <service_name> # Update Service options DOCKER STACK docker stack ls # List all running applications on this Docker host docker stack deploy -c <composefile> <appname> # Run the specified Compose file docker stack services <appname> # List the services associated with an app docker stack ps <appname> # List the running containers associated with an app docker stack rm <appname> # Tear down an application DOCKER MACHINE docker-machine create --driver virtualbox myvm1 # Create a VM (Mac, Win7, Linux) docker-machine create -d hyperv --hyperv-virtual-switch "myswitch" myvm1 # Win10 docker-machine env myvm1 # View basic information about your node docker-machine ssh myvm1 "docker node ls" # List the nodes in your swarm docker-machine ssh myvm1 "docker node inspect <node ID>" # Inspect a node docker-machine ssh myvm1 "docker swarm join-token -q worker" # View join token docker-machine ssh myvm1 # Open an SSH session with the VM; type "exit" to end docker-machine ssh myvm2 "docker swarm leave" # Make the worker leave the swarm docker-machine ssh myvm1 "docker swarm leave -f" # Make master leave, kill swarm docker-machine start myvm1 # Start a VM that is currently not running docker-machine stop $(docker-machine ls -q) # Stop all running VMs docker-machine rm $(docker-machine ls -q) # Delete all VMs and their disk images docker-machine scp docker-compose.yml myvm1:~ # Copy file to node's home dir docker-machine ssh myvm1 "docker stack deploy -c <file> <app>" # Deploy an app

2025-01-01 · 4 min · Eagle

Firewall-Cmd 常用命令

firewall 是 Linux CentOS 等操作系统的防火墙。 使用 rich rule 封禁 IP firewall-cmd --permanent --add-rich-rule="rule family='ipv4' source address='222.222.222.222' reject" 单个IP firewall-cmd --permanent --add-rich-rule="rule family='ipv4' source address='222.222.222.0/24' reject" IP段 firewall-cmd --permanent --add-rich-rule="rule family=ipv4 source address=192.168.1.2 port port=80 protocol=tcp accept" 单个IP的某个端口 firewall-cmd --list-rich-rules 查看封禁IP 使用 ip set 封禁 IP firewall-cmd --permanent --new-ipset=dog --type=hash:ip 封禁IP firewall-cmd --permanent --ipset=dog --add-entry=ip地址 firewall-cmd --permanent --new-ipset=blacklist --type=hash:net 封禁网段 firewall-cmd --permanent --ipset=blacklist --add-entry=222.222.222.0/24 firewall-cmd --permanent --add-rich-rule='rule source ipset=blacklist drop' 使ipset生效 删除一个 ipset ...

2025-01-01 · 1 min · Eagle

Mdbook 常用命令

mdBook 是一个工具,可以将 Markdown 文件呈现为更适合 HTML 或 EPUB 等最终用户形式。 mdbook 使用步骤: 1, 编写 markdown 格式的文章内容 2, 整理 SUMMARY.md 文件 3, 使用 mdbook 浏览和编译 4, 上传编译后的书籍内容到 Web 服务器 mdbook 使用新的端口开发: mdbook serve -p 13000 将文章内容编译为书籍,默认存放在项目目录的 book 文件夹下。可以将该目录上传到 Web 服务器,然后启动 Web 服务器就可以访问书籍了。 mdbook build 集成 google 统计 一番搜索后,找到可以集成 google 统计,并且这个功能在 7 年前已经有了,但是网上没有一篇文章介绍这个。经过查看源码,现将集成 google 统计的步骤记录下来。 第一阶段,是在[output.html]配置中直接配置 google 统计,例如在 book.toml 中下面的配置 [output.html] default-theme = "rust" google-analytics = "XXXXXXX" 当使用这种配置后,mdbook 编译会输出警告,这个 google 统计在将来的版本中会删除,推荐放在 theme 中的 head.hbs 文件中。 首先,在项目目录下创建 mytheme 文件夹,然后放入 head.hbs 文件。文件的内容,就是 google 统计的代码,例如: ...

2025-01-01 · 1 min · Eagle

Mosquitto安装与配置

MQTT(Message Queuing Telemetry Transport)是一种轻量级、基于发布-订阅模式的消息传输协议,适用于资源受限的设备和低带宽、高延迟或不稳定的网络环境。它在物联网应用中广受欢迎,能够实现传感器、执行器和其它设备之间的高效通信。 Eclipse Mosquitto 是一个开源(EPL/EDL 许可)消息代理,实现了 MQTT 协议版本 5.0、3.1.1 和 3.1。Mosquitto 重量轻,适用于从低功耗单板计算机到全服务器的所有设备。 在 CentOS 源码安装 mosquitto 1,从 https://mosquitto.org/download/ 下载源码到 Linux 服务器。 2,解压缩后,编译安装 make make install 在编译时,提示 cJSON 找不动,先安装 cJSON。 从该地址下载:https://github.com/DaveGamble/cJSON make make install 3,配置 mosquitto,在/etc/mosquitto 目录下,将 mosquitto.conf.example 改为 mosquitto.conf。 将以下内容修改: # 端口 listener 1883 # 日志 log_dest file /var/log/mosquitto/mosquitto.log log_type warning connection_messages true log_timestamp true log_timestamp_format %Y-%m-%dT%H:%M:%S # 安全 allow_anonymous false password_file /etc/mosquitto/pwfile acl_file /etc/mosquitto/aclfile 这里,浪费了我很长时间,在添加 password_file 之后,服务无法启动。后经排查,是权限的问题。 我使用的 root 账户,这是最终的修复脚本: chmod 0700 /etc/mosquitto/pwfile chown mosquitto:mosquitto /etc/mosquitto/pwfile chmod 0700 /etc/mosquitto/aclfile chown mosquitto:mosquitto /etc/mosquitto/aclfile pwfile 可以使用 mosquitto_passwd 命令创建,脚本如下: ...

2025-01-01 · 4 min · Eagle