分类目录归档:技术

Ceph 检查 rbd io 排名

好的,在 Ceph 中查看哪个 RBD (RADOS Block Device) 镜像的 I/O 读写最高,最常用的方法是使用 rbd perf image iotoprbd perf image iostat 命令。

这两个命令都需要指定 存储池 (pool) 的名称,因为 RBD 镜像是存在于特定的存储池中的。

方法一:使用 rbd perf image iotop (推荐)

这个命令会实时显示指定存储池中各个 RBD 镜像的 I/O 统计信息,并默认按总 I/O 操作数 (IOPS) 或总带宽排序,非常直观。

  1. 首先,确定 RBD 镜像所在的存储池。 如果不确定,可以使用 rbd pool lsceph osd lspools 列出所有存储池。
  2. 执行命令:
    rbd perf image iotop 
    <poolname>

将 `

` 替换为实际的存储池名称。 例如,如果你的 RBD 镜像在名为 `rbd_images` 的存储池中: “`bash rbd perf image iotop rbd_images “` 3. **查看输出:** 该命令会持续刷新输出,通常包含以下列: * `image`: RBD 镜像的名称。 * `rd_ops`, `wr_ops`, `total_ops`: 每秒读、写、总操作次数 (IOPS)。 * `rd_bytes`, `wr_bytes`, `total_bytes`: 每秒读、写、总带宽 (Bytes/s)。 输出通常会按 `total_ops` 或 `total_bytes` 降序排列,排在最前面的就是当前 I/O 最高的 RBD 镜像。按 `Ctrl+C` 退出。 **方法二:使用 `rbd perf image iostat`** 这个命令与 `iotop` 类似,也显示 I/O 统计,但格式可能略有不同,有时显示的是累积值或平均值,具体取决于 Ceph 版本和配置。 1. **确定存储池名称。** 2. **执行命令:** “`bash rbd perf image iostat “` 同样,将 ` ` 替换为实际的存储池名称。 例如: “`bash rbd perf image iostat rbd_images “` 3. **查看输出:** 分析输出中的读写 IOPS 和带宽列,找出数值最高的镜像。这个命令也可能持续刷新,按 `Ctrl+C` 退出。 **重要注意事项:** 1. **指定存储池:** 这两个命令都**必须**指定存储池名称。你需要对每个包含 RBD 镜像的存储池分别运行这些命令,才能找到整个集群中 I/O 最高的镜像。 2. **性能计数器:** 这些命令依赖于 Ceph 的性能计数器 (performance counters)。通常这些计数器是默认启用的,但如果遇到问题,可能需要检查相关配置。 3. **权限:** 执行这些命令需要相应的 Ceph 用户权限(通常是 client.admin 或具有针对特定存储池读写权限的用户)。 4. **Ceph 版本:** 命令的具体行为和输出格式可能随 Ceph 版本略有变化。 5. **Ceph Dashboard:** 如果你部署了 Ceph Dashboard(Web UI),通常在 Dashboard 的 “Block” -> “Images” 部分也能方便地查看各个 RBD 镜像的实时性能指标,包括 IOPS 和带宽,并且可以进行排序。这对于图形化监控来说更加友好。 **总结:** 使用 `rbd perf image iotop ` 是查找指定存储池中当前 I/O 活动最密集的 RBD 镜像的最直接和常用的命令行方法。记得要检查所有相关的存储池。

k8s csi-driver-nfs的一个坑

TL;DR

发现 k8s csi 组的社区项目 csi-driver-nfs v4.10v4.11 至少这两个版本存在删除 pv 时会连带将整个根删除的问题。

声明 StorageClass 时虽然支持 subDir ,类似这样:

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: nfs-aliyun-gz
provisioner: nfs.csi.k8s.io
parameters:
  share: "/csi"
  server: "28364f4a1fa-eok75.cn-guangzhou.nas.aliyuncs.com"
  #server: "172.26.12.20"
  #subDir: "${pvc.metadata.namespace}/${pvc.metadata.name}"
reclaimPolicy: Delete
#volumeBindingMode: WaitForFirstConsumer
volumeBindingMode: Immediate
allowVolumeExpansion: true
mountOptions:
#  - nolock,tcp,noresvport
  - vers=3,nolock,proto=tcp,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport

但如果类似这样使用 subDir 声明路径,同命名空间下的其他 pvc 删除,会导致整个 subDir 根目录都被删除。目前官方 pr 已经修复,但实测还是有问题,有空再研究一下代码,不知道是不是刻意为之。

回溯 issuer 历史发现是有人提了 bug 发现目录下出现很多空目录,认为需要删除,修复者修复这一问题时错误的将整个根删除。为了规避这一问题,暂时回退到更早的 4.9 版本 csi

helm upgrade --install csi-driver-nfs csi-driver-nfs/csi-driver-nfs --namespace kube-system --version v4.  
9.0 -f values.yaml

升级版本要谨慎,新装版本要充分测试,特别是这种涉及数据安全的!

最后发现 sig 组还有一个 nfs-subdir-external-provisioner 可以看一下。

References

k3s 容器 mirror 配置方法

TL; DR

root@tencent-sh1:~# cat /etc/rancher/k3s/registries.yaml 
mirrors:
  "docker.io":
    endpoint:
      - "https://harbor.xxx.me"
    rewrite:
      "^(.*)": "mirror-dockerhub/$1"
  "registry.k8s.io":
    endpoint:
      - "https://harbor.xxx.me"
    rewrite:
      "^(.*)": "mirror-registry-k8s-io/$1"
  "ghcr.io":
    endpoint:
      - "https://harbor.xxx.me"
    rewrite:
      "^(.*)": "mirror-registry-ghcr-io/$1"
  "quay.io":
    endpoint:
      - "https://harbor.xxx.me"
    rewrite:
      "^(.*)": "mirror-registry-quay-io/$1"

以上是我的配置,在 harbor 中镜像以上镜像源,之后这样 配置即可。

如果没有路径,比如使用 registry 镜像,忽略 rewrite 部分即可。

References

wordpress 使用 k8s 部署并使用 nginx ingress 代理无限 302 到 ssl 问题解决

发现容器化之后,wp 网站打开一直尝试 302 到 https 的页面,即使我当前已经是 https 了,经过排查是由于代理提供了 ssl 但 wordpress 不知道,默认会再重定向一次,出现无限 302 。

TL; DR

解决方法很简单,只需在 wp 配置文件 /wp-config.php 中增加这几行即可解决:

define( 'FORCE_SSL_ADMIN', true );
// in some setups HTTP_X_FORWARDED_PROTO might contain 
// a comma-separated list e.g. http,https
// so check for https existence
if( strpos( $_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false )
    $_SERVER['HTTPS'] = 'on';

方法来源于官网.

References

ArchLinux pacman 一键找到最快的镜像源清单

curl -s "https://archlinux.org/mirrorlist/?country=CN&protocol=https&use_mirror_status=on" | sed -e 's/^#Server/Server/' -e '/^#/d' | rankmirrors -n 5 -

运行这个命令,即可自动从 archlinux 官方 mirror 清单获取中国 (CN) 的镜像清单,并调用 rankmirrors 测速得到速度最快的前5个。

配置到 /etc/pacman.d/mirrorlist 目录中即可使用。

References

LLM 聚合 API 价格对比

List

  • gpt-4
  • gpt-4o
  • claude-3-7-sonnet-20250219
  • `claude-3-7-sonn

单位:Inout/Output /M

Model gpt-4o gpt-4o-mini deepseek-r1 deepseek-v3 claude-3-7-sonnet claude-3-5-sonnet
UniAPI $0.2871/$1.1484 $2.376/$11.88 $2.376/$11.88
GPTAPI ¥0.07/¥0.14 ¥5.25/¥26.25 ¥5.25/¥26.25
OpenRouter $5/$7 $3/$15 $3/$15
AiHubMix $0.62/$2.48 $3.3/$16.5
V3 API $1.8/$7.2 $7.4/$37

Refereneces

k8s 使用 pv-migrate 迁移 pvc

TL;DR

安装

wget https://github.com/utkuozdemir/pv-migrate/releases/download/v1.7.1/pv-migrate_v1.7.1_linux_x86_64.tar.gz
tar -xvf pv-migrate_v1.7.1_linux_x86_64.tar.gz
mv pv-migrate /usr/local/bin

用法

pv-migrate migrate \
  --source-namespace default \
  --dest-namespace default \
  localpv-vol csi-lvmpv

🚀 Starting migration
💭 Will attempt 3 strategies: mnt2, svc, lbsvc
🚁 Attempting strategy: mnt2
📂 Copying data... 100% |██████████████████████████████| (3.4 GB/s)     
📂 Copying data...   0% |                              |  [0s:0s]🧹 Cleaning up
📂 Copying data... 100% |██████████████████████████████|         
✨ Cleanup done
✅ Migration succeeded

References

k8s 使用 OpenEBS 存储

TL;DR

helm repo add openebs https://openebs.github.io/openebs
helm repo update

# 以默认值安装
helm install openebs --namespace openebs openebs/openebs --create-namespace

# 禁用副本存储类型、lvm 本地存储、zfs本地存储,仅保留本地路径存储
helm install openebs --namespace openebs openebs/openebs --set engines.replicated.mayastor.enabled=false --set engines.local.lvm.enabled=false --set engines.local.zfs.enabled=fa
lse --create-namespace
E0311 06:22:00.794754  111105 round_tripper.go:63] CancelRequest not implemented by *kube.RetryingRoundTripper
NAME: openebs
LAST DEPLOYED: Tue Mar 11 06:21:28 2025
NAMESPACE: openebs
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
Successfully installed OpenEBS.

Check the status by running: kubectl get pods -n openebs

The default values will install both Local PV and Replicated PV. However,
the Replicated PV will require additional configuration to be fuctional.
The Local PV offers non-replicated local storage using 3 different storage
backends i.e Hostpath, LVM and ZFS, while the Replicated PV provides one replicated highly-available
storage backend i.e Mayastor.

For more information, 
- view the online documentation at https://openebs.io/docs
- connect with an active community on our Kubernetes slack channel.
        - Sign up to Kubernetes slack: https://slack.k8s.io
        - #openebs channel: https://kubernetes.slack.com/messages/openebs

实际使用需充分阅读官方文档。

Local PV Hostpath 用法

定义 StorageClass

以下内容写入 local-hostpath-sc.yaml,默认的 openebs-hostpath 数据存放在主机的 /var/openebs/local 路径下,可以像下面这样自己创建一个。默认使用kubernetes.io/hostname=<node-name> 来标记节点。

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: openebs-local-hostpath
  annotations:
    openebs.io/cas-type: local
    cas.openebs.io/config: |
      - name: StorageType
        value: hostpath
      - name: BasePath
        value: /var/openebs/local
provisioner: openebs.io/local
reclaimPolicy: Delete
volumeBindingMode: WaitForFirstConsumer

PersistentVolumes 可以有多种回收策略,包括 “Retain“、”Recycle” 和 “Delete“。 对于动态配置的 PersistentVolumes 来说,默认回收策略为 “Delete"。 这表示当用户删除对应的 PersistentVolumeClaim 时,动态配置的 volume 将被自动删除。 如果 volume 包含重要数据时,这种自动行为可能是不合适的。 那种情况下,更适合使用 “Retain” 策略。 使用 “Retain” 时,如果用户删除 PersistentVolumeClaim,对应的 PersistentVolume 不会被删除。 相反,它将变为 Released 状态,表示所有的数据可以被手动恢复。

pvc 的迁移可以使用 pv-migrateVelero 进行,实现在主机间迁移。

定义 PVC

local-hostpath-pvc.yaml

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: local-hostpath-pvc
spec:
storageClassName: openebs-hostpath
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5G

Pod 使用

local-hostpath-pod.yaml

apiVersion: v1
kind: Pod
metadata:
name: hello-local-hostpath-pod
spec:
volumes:
- name: local-storage
persistentVolumeClaim:
claimName: local-hostpath-pvc
containers:
- name: hello-container
image: busybox
command:
- sh
- -c
- 'while true; do echo "`date` [`hostname`] Hello from OpenEBS Local PV." >> /mnt/store/greet.txt; sleep $(($RANDOM % 5 + 300)); done'
volumeMounts:
- mountPath: /mnt/store
name: local-storage

清理

kubectl delete pod hello-local-hostpath-pod
kubectl delete pvc local-hostpath-pvc
kubectl delete sc local-hostpath

# 可验证动态创建的 pv 也被删除
kubectl get pv

References

k3s 部署 kube-prometheus-stack 监控栈

TL;DR

$ helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
$ helm repo update
$ helm show values prometheus-community/kube-prometheus-stack
$ helm show values prometheus-community/kube-prometheus-stack > values.yaml
# Edit values.yaml
$ helm install prometheus-community prometheus-community/kube-prometheus-stack  --namespace monitoring -f values.yaml --create-namespace
# update values.yaml
$ helm upgrade --install prometheus-community prometheus-community/kube-prometheus-stack  --namespace monitoring -f values.yaml

References