Ubuntu下:启用SSH内置的SFTP服务器

  • 测试平台: Ubuntu 24.04
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    # 创建提供SFTP服务的用户和用户组
    adduser sftp-user-01
    groupadd sftp-users
    adduser sftp-user-01 sftp-users

    # 创建SFTP服务根目录
    mkdir /sftp-root
    chown root:root /sftp-root
    mkdir /sftp-root/sftp-user-01
    chown sftp-user-01:sftp-users /sftp-root/sftp-user-01
    chmod 755 /sftp-root/sftp-user-01

    # 编辑SSH服务配置文件
    vi /etc/ssh/sshd_config
    # 注释掉下面的行
    Subsystem sftp /usr/lib/openssh/sftp-server
    # 添加下面的配置
    Subsystem sftp internal-sftp
    Match User sftp-user-01
    ChrootDirectory /sftp-root
    X11Forwarding no
    PasswordAuthentication yes
    ForceCommand internal-sftp

    # 重启SSH服务,通过SFTP软件登录系统验证文件上传
    systemctl restart ssh

2024-09-12 VirtualBox 7.1.0 发布 支持Mac芯片 - macOS M1/M2芯片安装 VirtualBox

2024-09-12 官方正式发布 VirtualBox 7.1.0 支持Mac芯片, logo/UI也进行了挺多更新。
VirtualBox 7.1.0下载
安装AlmaLinux OS 9.4 Minimal ISO亲测可用!


下面是旧内容,请无视。

VirtualBox官方的下载链接,默认只提供Intel芯片的macOS安装包。
但是可以从旧版本的下载链接中找到针对M芯片开发人员测试版。
亲测可以安装,另外需要按照安装提示开启权限。

旧版本网页,在VirtualBox 7.0.8小节下: Download VirtualBox (Old Builds): VirtualBox 7.0
Developer preview for macOS / Arm64 (M1/M2) hosts 下载链接

Docker的MySQL服务器容器配置sql_mode

  1. 宿主机通过my.cnf配置,然后挂载到docker容器

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    vi my.cnf
    [mysqld]
    sql_mode=NO_ENGINE_SUBSTITUTION

    # docker-compose.yml文件如下

    version: '2'
    services:
    db:
    image: mysql:8.0
    volumes:
    - /path/to/my.cnf:/etc/mysql/conf.d/my.cnf
    environment:
    MYSQL_ROOT_PASSWORD: root
  2. 宿主机通过docker的启动command设置

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    # docker-compose.yml文件如下

    version: '2'
    services:
    db:
    image: mysql:8.0
    command:
    - --sql-mode=NO_ENGINE_SUBSTITUTION
    environment:
    MYSQL_ROOT_PASSWORD: root

MacOS node版本升级 - 问题解决

  • 查看现在的版本

    1
    2
    $ node -v
    v10.15.0
  • 使用brew install升级,提示错误【无法创建链接 /usr/local/bin/node】,node -v版本无变化

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    $ brew install node
    ==> Auto-updating Homebrew...
    Adjust how often this is run with HOMEBREW_AUTO_UPDATE_SECS or disable with
    HOMEBREW_NO_AUTO_UPDATE. Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
    ==> Auto-updated Homebrew!
    ==> Updated Homebrew from 4.3.18 (2971755498) to 4.3.23 (29c22e0ab3).
    ...
    ==> Pouring openssl@3--3.3.2.sequoia.bottle.tar.gz
    🍺 /usr/local/Cellar/openssl@3/3.3.2: 6,984 files, 32.9MB
    ==> Installing node
    ==> Pouring node--22.9.0.sonoma.bottle.tar.gz
    Error: The `brew link` step did not complete successfully
    The formula built, but is not symlinked into /usr/local
    Could not symlink bin/node
    Target /usr/local/bin/node
    already exists. You may want to remove it:
    rm '/usr/local/bin/node'

    To force the link and overwrite all conflicting files:
    brew link --overwrite node

    To list all files that would be deleted:
    brew link --overwrite node --dry-run

    Possible conflicting files are:
    ...
    Warning: The post-install step did not complete successfully
    You can try again using:
    brew postinstall node
    Warning: Removed Sorbet lines from backtrace!
    Rerun with `--verbose` to see the original backtrace
    ==> Caveats
    Bash completion has been installed to:
    /usr/local/etc/bash_completion.d
    ==> Summary
    🍺 /usr/local/Cellar/node/22.9.0: 2,064 files, 79.0MB
    ==> Running `brew cleanup node`...
    Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
    Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
    ==> Caveats
    ==> node
    Bash completion has been installed to:
    /usr/local/etc/bash_completion.d

    $ node -v
    v10.15.0
  • 尝试提示的命令,无法解决问题

    1
    2
    3
    4
    5
    $   brew link --overwrite node

    Linking /usr/local/Cellar/node/22.9.0...
    Error: Could not symlink include/node/common.gypi
    /usr/local/include/node is not writable.
  • 解决方法:修改旧node相关目录的权限,重新建立链接。

    1
    2
    3
    4
    5
    6
    $ sudo chown -R $USER /usr/local/include/node/
    $ sudo chown -R $USER /usr/local/share/doc/node
    $ brew link --overwrite node
    Linking /usr/local/Cellar/node/22.9.0... 69 symlinks created.
    $ node -v
    v22.9.0
  • 升级npm到最新版本时报错。

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    $ npm -v
    6.4.1
    $ npm install -g npm@latest

    npm WARN npm npm does not support Node.js v22.9.0
    npm WARN npm You should probably upgrade to a newer version of node as we
    npm WARN npm can't make any promises that npm will work with this version.
    npm WARN npm Supported releases of Node.js are the latest release of 6, 8, 9, 10, 11.
    npm WARN npm You can find the latest version at https://nodejs.org/
    (node:19671) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
    (Use `node --trace-deprecation ...` to show where the warning was created)
    (node:19671) [DEP0060] DeprecationWarning: The `util._extend` API is deprecated. Please use Object.assign() instead.
    npm ERR! cb.apply is not a function

    npm ERR! A complete log of this run can be found in:
    npm ERR! /Users/aes/.npm/_logs/2024-09-21T00_19_02_958Z-debug.log
  • 解决方法: 删除npm的相关目录,重新安装node

    1
    2
    3
    4
    5
    6
    7
    8
    $ sudo rm -rf /usr/local/bin/npm
    $ sudo rm -rf /usr/local/lib/node_modules
    $ rm -rf ~/.npm
    $ brew reinstall node
    $ node -v
    v22.9.0
    $ npm -v
    10.8.3
  • hexo简单搭建

    1
    2
    3
    4
    5
    6
    7
    8
    $ npm install -g hexo-cli
    $ hexo init blog
    -bash: hexo: command not found
    # 可以用下面目录下的命令解决
    $ ~/.npm-global/bin/hexo init blog
    $ cd blog
    $ ~/.npm-global/bin/hexo g
    $ ~/.npm-global/bin/hexo s

Error converting image: Invalid type for Profile | Python

使用ImageCms.ImageCmsProfile加载文件时出现如下错误

1
2
3
4
5
        with open(profile_path, 'rb') as f:
profile_content = f.read()
profile = ImageCms.ImageCmsProfile(profile_content)

# Error converting image: Invalid type for Profile

错误原因:读取文件时,返回的是一个bytes对象,而ImageCms.ImageCmsProfile需要一个文件路径或者一个BytesIO对象
解决方法:使用BytesIO对象

1
2
3
with open(profile_path, 'rb') as f:
profile_content = f.read()
profile = ImageCms.ImageCmsProfile(io.BytesIO(profile_content))

Stable Diffusion 开通局域网访问

  • Stable Diffusion 开通局域网访问时,需要用 –listen –port xxx 指定监听端口

    1
    2
    3
    ./webui.sh --listen --port 8080 --enable-insecure-extension-access
    # --listen --port:通过8080端口提供服务
    # --enable-insecure-extension-access:允许安装不安全的扩展
  • 还有一种办法供外部访问的方式是通过 –share 参数,这样会通过gradio.live随机生成一个网址3天有效期,不如局域网安全。

    1
    2
    3
    ./webui.sh --share --enable-insecure-extension-access
    Running on public URL: https://afaaaaa22bb215cd6.gradio.live
    This share link expires in 72 hours. For free permanent hosting and GPU upgrades, run `gradio deploy` from Terminal to deploy to Spaces (https://hugg。。。

Linux服务器性能瓶颈分析(1) I/O负载过高

如果Linux服务器I/O负载过高,会导致生产环境服务无法工作,严重时SSH登录很慢,导致排障时间增加。
这个时候尽快定位并解决问题显得尤为重要。合适的排错路径会事半功倍。

  • 本文使用系统自带的【top/ps】命令和需要安装的【iostat、iotop】进行排查。
    安装命令如下

    1
    2
    # sudo apt install sysstat
    # sudo apt install iotop-c
  • 模拟故障:使用下面的命令模拟磁盘的大量写入

    1
    # dd if=/dev/zero of=/tmp/largefile bs=1M count=10240 oflag=direct
  1. top 命令确认是否是I/O负载问题
    【wa】值是指 CPU 处于空闲状态但等待磁盘或其他外部 I/O 操作(如网络 I/O)完成的时间比例。高【wa】值(较高的百分比):表示系统存在 I/O 瓶颈。

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    # top
    top - 05:06:58 up 68 days, 1:44, 3 users, load average: 0.65, 0.19, 0.06
    Tasks: 208 total, 1 running, 207 sleeping, 0 stopped, 0 zombie
    %Cpu(s): 0.0 us, 0.3 sy, 0.0 ni, 49.8 id, 49.9 wa, 0.0 hi, 0.0 si, 0.0 st
    MiB Mem : 3915.6 total, 315.7 free, 742.2 used, 3160.3 buff/cache
    MiB Swap: 3915.0 total, 3914.7 free, 0.2 used. 3173.4 avail Mem

    PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
    3905352 root 20 0 15224 7860 5760 S 0.3 0.2 0:02.33 sshd
    3946974 root 20 0 12072 6016 3712 R 0.3 0.2 0:00.02 top
    1 root 20 0 22700 14080 9728 S 0.0 0.4 1:18.21 systemd
  2. iostat -x 2 3 命令查看磁盘I/O使用率
    此命令按照2秒的间隔统计3次I/O数据,后两组数据代表最新的状态。
    【%util】列的值表示设备的使用率,即设备在处理 I/O 请求时被忙占用的时间百分比。
    此处sda磁盘使用率比较高,I/O瓶颈。

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    # iostat -x 2 3
    Linux 6.8.0-36-generic (ubuntu24) 09/11/2024 _x86_64_ (2 CPU)

    avg-cpu: %user %nice %system %iowait %steal %idle
    0.04 0.00 0.05 1.18 0.00 98.73

    Device r/s rkB/s rrqm/s %rrqm r_await rareq-sz w/s wkB/s wrqm/s %wrqm w_await wareq-sz d/s dkB/s drqm/s %drqm d_await dareq-sz f/s f_await aqu-sz %util
    dm-0 0.01 0.15 0.00 0.00 27.85 19.60 1.30 9.59 0.00 0.00 185.30 7.36 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.24 3.32
    loop0 0.00 0.00 0.00 0.00 0.00 1.27 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
    sda 0.01 0.26 0.00 18.33 28.32 33.09 0.71 9.68 0.60 45.65 181.64 13.62 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.13 3.33


    avg-cpu: %user %nice %system %iowait %steal %idle
    0.00 0.00 0.00 50.13 0.00 49.87

    Device r/s rkB/s rrqm/s %rrqm r_await rareq-sz w/s wkB/s wrqm/s %wrqm w_await wareq-sz d/s dkB/s drqm/s %drqm d_await dareq-sz f/s f_await aqu-sz %util
    dm-0 0.00 0.00 0.00 0.00 0.00 0.00 4.50 4608.00 0.00 0.00 205.89 1024.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.93 100.00
    loop0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
    sda 0.00 0.00 0.00 0.00 0.00 0.00 9.00 4608.00 0.00 0.00 206.00 512.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 1.85 100.00


    avg-cpu: %user %nice %system %iowait %steal %idle
    0.00 0.00 0.25 57.79 0.00 41.96

    Device r/s rkB/s rrqm/s %rrqm r_await rareq-sz w/s wkB/s wrqm/s %wrqm w_await wareq-sz d/s dkB/s drqm/s %drqm d_await dareq-sz f/s f_await aqu-sz %util
    dm-0 0.00 0.00 0.00 0.00 0.00 0.00 9.50 5648.00 0.00 0.00 184.37 594.53 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 1.75 100.00
    loop0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
    sda 0.00 0.00 0.00 0.00 0.00 0.00 12.00 5648.00 3.00 20.00 174.04 470.67 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 2.09 100.00
  3. iotop 命令查看当前进程中的高I/O命令和进程ID
    此处 3949828 的进程磁盘写入很高。

    1
    2
    3
    4
    5
    6
    # iotop
    Total DISK READ: 0.00 B/s ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ | Total DISK WRITE: 2033.76 K/s ⣶⣤⣶⣾⣴⣶⣶⣦⣾⣦⣶⣶⣴⣶⣴⣶⣴⣶⣶⣶⣶⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
    Current DISK READ: 0.00 B/s ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ | Current DISK WRITE: 2033.76 K/s ⣶⣤⣶⣾⣴⣶⣶⣦⣾⣦⣶⣶⣴⣶⣴⣶⣴⣶⣶⣶⣶⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
    TID PRIO USER DISK READ DISK WRITE GRAPH[R+W]▽ COMMAND [T](05:15:31)
    3949828 be/4 root 0.00 B/s 2033.76 K/s ⣶⣤⣶⣾⣴⣶⣶⣦⣾⣦⣶⣶⣴⣶⣴⣶⣴⣶⣶⣶⣶⠀⠀⠀dd ▲
    3748947 be/4 root 0.00 B/s 0.00 B/s ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀emd-journald
  4. 如果没有安装 iotop,可使用ps命令过滤进程状态为D的进程,然后查看PID的磁盘读写状态
    在 Linux 系统中,进程状态为 D 代表 不可中断的睡眠状态(Uninterruptible Sleep)。
    这意味着进程正在等待一个无法中断的系统事件,通常是与 I/O 相关的操作,例如等待磁盘或网络 I/O 完成。

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    # for x in `seq 1 1 3`; do ps -eo state,pid,cmd | grep "^D"; echo "----"; sleep 3; done
    D 3953121 dd if=/dev/zero of=/tmp/largefile bs=1M count=10240 oflag=direct
    ----
    D 3953121 dd if=/dev/zero of=/tmp/largefile bs=1M count=10240 oflag=direct
    ----
    D 3953121 dd if=/dev/zero of=/tmp/largefile bs=1M count=10240 oflag=direct
    ----

    # cat /proc/3953121/io
    rchar: 1120934832
    wchar: 1119879168
    syscr: 1080
    syscw: 1068
    read_bytes: 0
    write_bytes: 1120927744
    cancelled_write_bytes: 0

最后可以针对实际情况,优化任务或者紧急时停用进程。