跳到主要内容

博客

代码人生:编织技术与生活的博客之旅

查看登录失败次数

# 查看登录失败 (尝试攻击的情况)
sudo grep 'Failed password' /var/log/auth.log | awk '{print $1,$2}' | uniq -c
# 查看登录成功的情况
sudo grep 'session opened for user' /var/log/auth.log | awk '{print $1,$2}' | uniq -c

实况

基本上时时刻刻有人在尝试登陆,前天 8k 多次失败访问。

可怕的来了,登陆成功的情况也很多。

尝试解决

  • 开 file2ban 应该问题不大
    • sudo apt update && sudo apt install fail2ban && systemctl status fail2ban.service
    • head -20 /etc/fail2ban/jail.conf
    • fail2ban-client --help
  • 开的机器用户名默认不是 root,登录也只能通过 ssh key

想法

  • 做个脚本跑个定时任务,当 尝试次数过多 或者 登录次数过多 的时候就发个邮件过来提醒。

增加 google 验证

编程阅读需 1 分钟

trash-cli

安装

  • 安装 sudo apt install trash-cli

使用

  • trash-put: 把文件或目录移动到回收站
  • trash-empty: 清空回收站
  • trash-list: 列出回收站文件
  • trash-restore: 恢复回收站文件
  • trash-rm: 删除回收站文件

配置

  • 七天删除 (crontab -l ; echo "@daily $(which trash-empty) 7") | crontab -

    • 查看 cat /var/spool/cron/crontabs/root
  • 设置别名 alias rm='trash' (官方不推荐)

编程阅读需 1 分钟

sudo apt install rdfind
rdfind -deleteduplicates true /media/faonecze/资料存档/

windows 用 DoubleKiller.exe 还挺方便的

编程阅读需 1 分钟

自己喜欢啥,总要一遍一遍和朋友介绍,感觉比较麻烦,这样汇总一下,方便朋友一次性安利。

ps. 每个工具其实在 B 站都有视屏科普,大佬们也可以上 B 站看看。

硬件

键盘: Anne pro 2

  • 全键自定义
  • tap key: 支持轻触方向键
  • magic key: CaspLk 也可以自定义设置为 FN 键
  • 键盘宏
  • 自定义 rgb
  • type-C 充电
  • USB + 蓝牙双模
  • 四蓝牙连接
  • 带电量显示:Fn2 + 8

缺点是没有静音版本,选了红轴默认不按到底,勉勉强强声音不大。
有个注意点是,当线连接电脑,没关掉蓝牙的话,默认还是蓝牙输入输出,线支持充电。


鼠标:罗技 M590

静音,用电久,自定义鼠标滚轮左右方向,双蓝牙,多设备支持 Logitech Flow,缺点是不好看。

鼠标:罗技 M720

同上款,自定义按键更多,据说有二三十个。缺点是不静音。


软件

ps. 本人是全 windows 开发。

伪 Linux 系统

wsl2 支持 docker 了,Terminus 配上个炫酷的半透明界面,oh my zsh 自带各种插件好用的哼,一套下来,windows 变 Linux,并且 pycharm 支持基于 wsl 开发,巴适得很。

关于 sz rz 传输 我这里有个 解决方案

Terminus 需要准备一下

wsl2 默认 root 用户

  • ubuntu config --default-user root

一个 windows 路径转换脚本,建议放到用户执行目录上,复制的 windows 路劲快速转换为 Linux。

#!/usr/bin/env python
# encoding: utf-8
# Created by zza on 2021/6/9 14:23
import re

from prompt_toolkit.clipboard import pyperclip

def convert_path():
path = pyperclip.pyperclip.paste() # r'/mnt/d/Programs/ActivityWatch'
wsl_result = re.match(r"(^[A-Z]:)\\(.*)", path)
if wsl_result:
_disk_symbol = wsl_result[1][:-1].lower()
wsl_path = f'\\mnt\\{_disk_symbol}\\{wsl_result[2]}'.replace('\\', '/')
pyperclip.pyperclip.copy(wsl_path)
print(wsl_path)
return wsl_path
elif re.match(r"^/mnt/([a-z])/(.*)", path):
win_result = re.match(r"^/mnt/([a-z])/(.*)", path)
tail = win_result[2].replace("/", "\\")
win_path = f'{win_result[1].upper()}:\\{tail}'
pyperclip.pyperclip.copy(win_path)
print(win_path)
return win_path
else:
print(f'nothing to do with {path}')
return

if __name__ == '__main__':
pyperclip.pyperclip.copy('D:\\Programs\\ActivityWatch')
convert_path()
print(pyperclip.pyperclip.paste())

  • 输入一下命令切换剪贴板里的路径,还是很舒服的。

  • 之前用的 cmder 感觉还行,但是和 terminus 相比,界面就丑了很多。


办公套件 to do list + outlook

待办不管是上班还是平时都用得上。
[[outlook 支持将邮件自动转入待办]]。

顺便说一下,outlook 的日历管理也很香。

手机日历上选择 Exchange 导入方式导入日历,就手机端和电脑端同步了。


分屏利器 PowerToys

这个每个 帖子 都讲烂了,自己看把。

顺便说说 windows 虚拟桌面(部分小伙伴不知道)

windows + ctrl + d 创建桌面
windows + ctrl + f4 删除桌面
windows + ctrl +方向键 快速移动

好了恭喜你拥有了无数个虚拟桌面。可以给桌面命名,把摸鱼桌面,学习桌面,工作桌面,看板桌面分开。

番茄时钟

google play 搜索 Tea Time

  • 支持多个定时器同时启动
  • 自定义是闹钟还是震动
  • 安卓桌面组件,快速启动,支持自定义外观。


随笔阅读需 3 分钟

如何在 python 异步函数中 debug


import asyncio
from aredis import StrictRedis
import nest_asyncio

# pip3 install aredis[hiredis]
# pip3 install nest_asyncio

async def example():
client = StrictRedis(host='127.0.0.1', port=6379, db=0)
await client.flushdb()
# error await client.flushdb()
# error asyncio.get_event_loop().run_until_complete(client.flushdb())
# error asyncio.new_event_loop().run_until_complete(client.flushdb())
# error asyncio.run(client.flushdb())

await client.set('foo', 1)
assert await client.exists('foo') is True
await client.incr('foo', 100)

assert int(await client.get('foo')) == 101
await client.expire('foo', 1)
await asyncio.sleep(0.1)
await client.ttl('foo')
await asyncio.sleep(1)
assert not await client.exists('foo')

loop = asyncio.get_event_loop()
# success nest_asyncio.apply()
loop.run_until_complete(example())

Python阅读需 1 分钟

windows 进程 监控

  • windows wmi-exporter 进程监控
    • 对应的看板 dashboard Id 10467
    • 没有进程数据
      • 服务器管理器找到 WMI exporter
        • 添加参数 --collectors.enabled "[defaults],process,container"
Grafana Status Map Panel not working, shows "Panel plugin not found: flant-statusmap-panel" #197
  • 解决方法
    • Open your Grafana instance and go to the Plugins section in the left-hand -nu.
    • Search for "statusmap" in the search bar.
    • Click on the "Install" button for the "statusmap" plugin.
    • Wait for the installation to complete.\

Grafana + prometheus + node-exporter docker-compose.yml

vim prometheus/docker-compose.yml

version: "3.7"
services:
node_exporter:
image: quay.io/prometheus/node-exporter:latest
container_name: node_exporter
command:
- '--path.rootfs=/host'
user: "1000"
network_mode: host
# pid: host
restart: unless-stopped
volumes:
- '/:/host:ro,rslave'
prometheus:
image: prom/prometheus:latest
container_name: "prometheus"
restart: always
ports:
- "9111:9090"
volumes:
- "./prometheus.yml:/etc/prometheus/prometheus.yml"
- "./prometheus_data:/prometheus"
grafana:
image: grafana/grafana
container_name: "grafana"
ports:
- "3000:3000"
restart: always
volumes:
- "./grafana_data:/var/lib/grafana"
process-exporter:
image: ncabatoff/process-exporter
command: --procfs /host/proc -config.path /config/process-exporter-config.yml
privileged: true
volumes:
- /proc:/host/proc
- ./process-exporter-config.yml:/config/process-exporter-config.yml
ports:
- "9256:9256"
restart: always

vim prometheus/prometheus.yml - 需要根据自己的 ip 进行修改器

global:
scrape_interval: 15s # 默认抓取周期
external_labels:
monitor: "codelab-monitor"
scrape_configs:
- job_name: "node-exporter" #服务的名称
scrape_interval: 5s
metrics_path: /metrics #获取指标的 url
static_configs:
- targets: ["192.168.31.2:9100"] # 这个为监听指定服务服务的 ip 和 port,需要修改为自己的 ip,貌似云服务必须用公网 ip
- job_name: "process-exporter"
scrape_interval: 5s
metrics_path: /metrics
static_configs:
- targets: ["192.168.31.2:9256"]
- job_name: "windows-laptop"
scrape_interval: 5s
metrics_path: /metrics
static_configs:
- targets: ["192.168.31.3:9182"]
- job_name: "other-node-192.168.31.5-node-exporter"
scrape_interval: 5s
metrics_path: /metrics
static_configs:
- targets: ["192.168.31.5"]

node-exporter linux 服务器状态监控

prometheus 相关

看板 Grafana

  • http://ip:9111/3000

  • 配合 node - 的 Dashborad 编号是 9276

    • Grafana 直接搜索 id 就能找到别人分享的看板。
    • 需要单独配置下 网络 io 图表。
    • 都是可视化的 先再 node-exporter 里找到相关指标,然后可视化点点点就能出现数据。
编程阅读需 2 分钟

买了个二手 mini 主机,刷成 ubunu 在家里当服务器用。

服务器配置

  • 天虹迷你主机
    • 电脑型号 - X64 兼容笔记本电脑(扫描时间:2022 年 11 月 15 日)
    • 操作系统 - Windows 10 专业版 64 位 (4.09.000904)
    • 处理器 - AMDA6-Series A6-1450 四核
    • 主板 - U14G-M ( AMD PCI standard host CPU bridge )
    • 内存 - 8 GB(极匠 DDR3L1600MHz)
    • 主硬盘 - 极匠 GJN128G(128GB/固态硬盘)
    • 显卡 - AMD Radeon HD 8250/8280G(512 MB/AMD)
    • 显示器 - NTP2401NT24GMB18()(52 英寸)
    • 声卡 - 瑞 ALC662 @AMD High Definition Audio Controller
    • 网卡 - 博通 BCM430N 80211n Network Adapter

小服务器

  • 需求
    • docker
    • 旁路由
    • 移动硬盘共享
  • 优先
    • 声音小
    • 耗电小
  • 测量耗电量
    • 小米智能插座

需要调查

  • 网口理速度
    • ethtool enp2s0
      • 1000baseT/Full 理论支持千兆网
  • 硬盘直接插 和 usb3.0 插入的差别
    • usb3.0 5 GPS 625 MB/s
    • SATA2 3Gbps 375MB/s -> 300MB/s
    • SATA3 6Gbps 750MB/s -> 600MB/s
  • 网口 与 usb3.0 or usb2.0 转网口的速率区别
    • USB3.0 传输速率达 USB 2.0 十倍,USB 2.0 的速率为 480 Mbps,而 USB 3.0 则可达到 4.8 Gbps。
    • 自带网口速度差不多 1000 MB/s
  • 网速测试
    • 内网测速 iperf3
      • 2.24 GBytes
      • 321 Mbits/sec
    • 一键测速 speedtest-cli
      • Download: 30.12 Mbit/s
      • Upload: 16.61 Mbit/s

U 盘启动器下载

  • 微 pe
    • 不能装 Linux
  • linux 下载 - ubuntu-22.04.1-live-server-amd64.iso
  • Universal-USB-Installer-2.0.0.8.exe

ubuntu 联 wifi

network:
version: 2
renderer: NetworkManager
wifis:
wlan0:
dhcp4: true
access-points:
"holypangci_5G":
password: "111111111"
dhcp6: true

功耗

  • 用的小米智能插座
  • 刚开机 啥也不跑 0.1 kWh
  • 当前功率 10w
  • 月功率 0.27 kWH

挂载硬盘

  • 挂载硬盘

  • nas docker 参考

  • 开机检测 在开机的时候 检测到移动硬盘 自动挂载

    • sudo lsblk
    • sudo fdisk -l
    • sudo mount -t auto /dev/sda2 /mnt/data
  • systemctl restart smbd.service

  • [[clash]]

    network:
version: 2
renderer: networkd
ethernets:
enp2s0:
dhcp4: true
optional: true

docker

  • 摸鱼工具使用 docker run -it --rm svenstaro/genact

  • docker 安装

$ sudo vim /etc/docker/daemon.json

{
"registry-mirrors": [
"https://hub-mirror.c.163.com",
"https://ustc-edu-cn.mirror.aliyuncs.com",
"https://ghcr.io",
"https://mirror.baidubce.com"
]
}

通过正在运行的 docker pod 获取 docker-compose.yaml

docker run --rm -v /var/run/docker.sock:/var/run/docker.sock red5d/docker-autocompose <container-name-or-id>
sudo docker run --rm -v /var/run/docker.sock:/var/run/docker.sock red5d/docker-autocompose epic_bartik
sudo docker stop $(sudo docker ps -aq)

samba

硬盘读写测试

参考

  • ssd 读写
zza@zza-server:smb_tmp % time dd if=/dev/zero of=./testReadOrWrite bs=8k count=100000
记录了100000+0 的读入
记录了100000+0 的写出
819200000字节(819 MB,781 MiB)已复制,5.94344 s,138 MB/s
dd if=/dev/zero of=./testReadOrWrite bs=8k count=100000 0.16s user 4.67s system 80% cpu 6.003 total
zza@zza-server:smb_tmp % time dd if=./testReadOrWrite of=/dev/null bs=8k count=100000
记录了100000+0 的读入
记录了100000+0 的写出
819200000字节(819 MB,781 MiB)已复制,0.852206 s,961 MB/s
dd if=./testReadOrWrite of=/dev/null bs=8k count=100000 0.06s user 0.79s system 99% cpu 0.857 total
zza@zza-server:smb_tmp % time dd if=./testReadOrWrite of=./testReadAndWrite bs=8k count=100000
记录了100000+0 的读入
记录了100000+0 的写出
819200000字节(819 MB,781 MiB)已复制,6.46195 s,127 MB/s
dd if=./testReadOrWrite of=./testReadAndWrite bs=8k count=100000 0.13s user 5.27s system 83% cpu 6.507 total
  • 机械硬盘读写
zza@zza-server:tmp % time dd if=/dev/zero of=./testReadOrWrite bs=8k count=100000
记录了100000+0 的读入
记录了100000+0 的写出
819200000字节(819 MB,781 MiB)已复制,42.5608 s,19.2 MB/s
dd if=/dev/zero of=./testReadOrWrite bs=8k count=100000 0.28s user 7.69s system 18% cpu 42.591 total
zza@zza-server:tmp % time dd if=./testReadOrWrite of=/dev/null bs=8k count=100000
记录了100000+0 的读入
记录了100000+0 的写出
819200000字节(819 MB,781 MiB)已复制,0.835777 s,980 MB/s
dd if=./testReadOrWrite of=/dev/null bs=8k count=100000 0.08s user 0.76s system 99% cpu 0.840 total
zza@zza-server:tmp % time dd if=./testReadOrWrite of=./testReadAndWrite bs=8k count=100000
记录了100000+0 的读入
记录了100000+0 的写出
819200000字节(819 MB,781 MiB)已复制,42.0116 s,19.5 MB/s
dd if=./testReadOrWrite of=./testReadAndWrite bs=8k count=100000 0.29s user 8.90s system 21% cpu 42.039 total
随笔阅读需 4 分钟

  • [[服务器]]

  • 参考

  • 笔记本直接看这个人

    • 夏蒙乾
    • 但是最近(2023-02-09)还是不推荐买,能增加内存、ssd 的机型要么过于贵、要么其他方面不行。
    • [[笔记本挑选 2024-06-25]]
    • [[主装机配置清单]]

CPU 选择


总体配置

  • CPU+主板 B660M-PLUS + i7-12700F ¥3109

    • B660M-PLUS ¥1060
    • i7-12700F ¥2130
    • cpu 65 w
  • 散热 利民 PA120 ¥169

    • 光太亮了,不能直视。
  • 内存 骇客神条 16g x 2 = ¥1099.00

    • DDR4 会便宜很多,主板就得换一个(也会便宜很多)
  • 固态 宏碁 GM7000 1T 649

  • 电源 酷冷 GX850 ¥594

    • 后期如果要上 3090 还得是千瓦电源
  • 机箱 先马(SAMA)颜之神 钛灰色 ¥226

  • 风扇 利民 12 厘米风扇 3 个,安装在尾部和顶部 ¥53

    • 声音大
  • 显卡 3070 卡诺基 ¥2199

    • 购买日的前两天涨价了 200 块,卡诺基在翻新卡里算口碑不错的。
  • 总价 7449


功率

最简单粗暴的电源计算办法,把 CPU 和 GPU 的功耗加起来再加上 100W,可以粗略算出配置的整体功耗。】

电源 850w + 100w + 65w (cpu)

固态

空盘测试数据

AS SSD Benchmark

AS SSD Benchmark 2.0.7316.34247
------------------------------
Name: Fanxiang S690 2TB
Firmware: SN07443
Controller: stornvme
Offset: 16384 K - OK
Size: 1863.01 GB
Date: 2023/2/13 11:18:00
------------------------------
Sequential:
------------------------------
Read: 4215.19 MB/s
Write: 3722.04 MB/s
------------------------------
4K:
------------------------------
Read: 79.78 MB/s
Write: 222.97 MB/s
------------------------------
4K-64Threads:
------------------------------
Read: 2091.47 MB/s
Write: 1283.86 MB/s
------------------------------
Access Times:
------------------------------
Read: 0.016 ms
Write: 0.060 ms
------------------------------
Score:
------------------------------
Read: 2593
Write: 1879
Total: 5783
------------------------------

CrystalDiskMark

------------------------------------------------------------------------------
CrystalDiskMark 8.0.1 x64 (C) 2007-2021 hiyohiyo
Crystal Dew World: https://crystalmark.info/
------------------------------------------------------------------------------
* MB/s = 1,000,000 bytes/s [SATA/600 = 600,000,000 bytes/s]
* KB = 1000 bytes, KiB = 1024 bytes

[Read]
SEQ 1MiB (Q= 8, T= 1): 4858.861 MB/s [ 4633.8 IOPS] < 1509.94 us>
SEQ 1MiB (Q= 1, T= 1): 4486.361 MB/s [ 4278.5 IOPS] < 233.60 us>
RND 4KiB (Q= 32, T= 1): 883.414 MB/s [ 215677.2 IOPS] < 143.61 us>
RND 4KiB (Q= 1, T= 1): 79.243 MB/s [ 19346.4 IOPS] < 51.61 us>

[Write]
SEQ 1MiB (Q= 8, T= 1): 4467.455 MB/s [ 4260.5 IOPS] < 1849.33 us>
SEQ 1MiB (Q= 1, T= 1): 4459.696 MB/s [ 4253.1 IOPS] < 234.96 us>
RND 4KiB (Q= 32, T= 1): 423.689 MB/s [ 103439.7 IOPS] < 304.18 us>
RND 4KiB (Q= 1, T= 1): 257.067 MB/s [ 62760.5 IOPS] < 15.85 us>

Profile: Default
Test: 1 GiB (x5) [E: 0% (0/1863GiB)]
Mode: [Admin]
Time: Measure 5 sec / Interval 5 sec
Date: 2023/02/13 11:28:35
OS: Windows 10 Professional [10.0 Build 22621] (x64)

写入 1T+ 数据后

AS SSD Benchmark 2

AS SSD Benchmark 2.0.7316.34247
------------------------------
Name: Fanxiang S690 2TB
Firmware: SN07443
Controller: stornvme
Offset: 16384 K - OK
Size: 1863.01 GB
Date: 2023/2/14 11:04:19
------------------------------
Sequential:
------------------------------
Read: 4150.81 MB/s
Write: 4084.55 MB/s
------------------------------
4K:
------------------------------
Read: 63.06 MB/s
Write: 204.81 MB/s
------------------------------
4K-64Threads:
------------------------------
Read: 2089.18 MB/s
Write: 1283.93 MB/s
------------------------------
Access Times:
------------------------------
Read: 0.087 ms
Write: 0.071 ms
------------------------------
Score:
------------------------------
Read: 2567
Write: 1897
Total: 5776
------------------------------

CrystalDiskMark 2

------------------------------------------------------------------------------
CrystalDiskMark 8.0.1 x64 (C) 2007-2021 hiyohiyo
Crystal Dew World: https://crystalmark.info/
------------------------------------------------------------------------------
* MB/s = 1,000,000 bytes/s [SATA/600 = 600,000,000 bytes/s]
* KB = 1000 bytes, KiB = 1024 bytes

[Read]
SEQ 1MiB (Q= 8, T= 1): 4828.908 MB/s [ 4605.2 IOPS] < 1728.61 us>
SEQ 1MiB (Q= 1, T= 1): 4506.055 MB/s [ 4297.3 IOPS] < 232.57 us>
RND 4KiB (Q= 32, T= 1): 808.553 MB/s [ 197400.6 IOPS] < 156.88 us>
RND 4KiB (Q= 1, T= 1): 71.322 MB/s [ 17412.6 IOPS] < 57.27 us>

[Write]
SEQ 1MiB (Q= 8, T= 1): 4393.255 MB/s [ 4189.7 IOPS] < 1906.56 us>
SEQ 1MiB (Q= 1, T= 1): 4383.751 MB/s [ 4180.7 IOPS] < 239.06 us>
RND 4KiB (Q= 32, T= 1): 405.718 MB/s [ 99052.2 IOPS] < 322.86 us>
RND 4KiB (Q= 1, T= 1): 247.658 MB/s [ 60463.4 IOPS] < 16.43 us>

Profile: Default
Test: 1 GiB (x5) [E: 66% (1226/1863GiB)]
Mode: [Admin]
Time: Measure 5 sec / Interval 5 sec
Date: 2023/02/14 11:09:57
OS: Windows 10 Professional [10.0 Build 22621] (x64)

随笔阅读需 4 分钟