Avatar

Organizations

  • 不同版本中,不同的表现形式:

    • Python 2.x:reload() 是内置函数
    • Python 3.0 - 3.3:使用 imp.reload(module)
    • Python 3.4:imp 已经被废弃,取而代之的是 importlib
    from importlib import reload
    
    reload(<module>)
    

    参考文档

    reload python Created Fri, 20 Jan 2023 23:44:17 +0800
  • VsCode Remote SSH 默认是不支持 Alpine Linux 的,不过,对 Alpine Linux 进行一些改动,就可以实现,比较方便。

    步骤如下:

    安装

    1. 安装 Bash
    2. 安装需要的包
    $ apk del dropbear
    $ apk add gcompat libstdc++6 openssh wget git
    

    Alpine 配置

    $ nano /etc/ssh/sshd-config
    
    AllowTcpForwarding yes
    PermitTunnel       yes
    

    git 配置

    1. VsCode 连接 Alpine Linux
    2. F1 > “Preferences: Open Remote Settings (JSON) (SSH: )”
    3. 添加下面的内容:
    {
    	"git.path": "/usr/bin/git",
    }
    

    参考文档:

    alpine linux remote ssh vscode Created Tue, 03 Jan 2023 20:42:02 +0800
  • Alpine Linux 原始安装的是 busybox,小巧精干,但毕竟与主流的 Bash 还是有区别,特别是与其它系统联动时会比较麻烦,所以还是安装 Bash,统一 Shell 环境,方便日后使用。

    而且基本网上的安装教程都有问题,所以这里给出正确的安装步骤。

    安装

    $ apk add bash libuser
    

    配置

    $ touch /etc/login.defs
    $ mkdir /etc/default
    $ touch /etc/default/useradd
    $ lchsh <root>
    Changing shell for root.
    Password: <root password>
    New Shell [/bin/ash]: /bin/bash
    Shell changed.
    

    参考文档:

    linux bash alpine linux Created Tue, 03 Jan 2023 20:08:42 +0800
  • 1. 使用手册

    看完这3篇足以把服务建起来,非常方便

    2. 服务端安装配置

    可直接使用 Docker 的配置进行

    3. 客户端下载、 安装、运行

    原本也想使用Docker镜像,但发现kvm之间通过Docker通信好像有问题,所幸在宿主机上可以直接使用release文件。 【注意:每次添加新的客户端,要同步更新服务端的端口配置

    3.1. 下载

    官网下载地址注意:s, c两端使用的版本号要相同

    $ cd ~
    # 下载安装软件
    $ yum install wget tar git
    # 下载 frp
    $ wget -c https://github.com/fatedier/frp/releases/download/v0.34.3/frp_0.34.3_linux_amd64.tar.gz
    $ tar -axvf frp_0.34.3_linux_amd64.tar.gz
    $ rm -rf frp_0.34.3_linux_amd64.tar.gz
    # 下载 frp 配置
    $ git clone https://github.com/Cuile/frp.git
    

    3.2. 安装

    # 此处只能使用硬链接,使用软链接会导致无法启动服务
    # 安装配置文件
    $ mkdir /etc/frp
    $ ln -b ~/frp/conf/frpc-pve.ini /etc/frp/frpc.ini
    # 安装运行文件
    $ ln -b ~/frp_0.34.3_linux_amd64/frpc /usr/bin/frpc
    # 安装服务
    $ ln -b ~/frp_0.34.3_linux_amd64/systemd/frpc.service /lib/systemd/system/frpc.service
    

    3.3. 运行

    $ systemctl enable frpc.service           ##设定指定服务开机开启
    $ systemctl disable frpc.service          ##设定指定服务开机关闭
    
    $ systemctl start frpc.service
    $ systemctl stop frpc.service
    $ systemctl restart frpc.service
    
    $ systemctl status frpc.service
    $ systemctl list-units | grep frpc
    

    3.4. 更新

    通过 git 更新 frpc 的配置后,要重新链接配置文件

    frp proxy linux Created Wed, 28 Dec 2022 17:15:15 +0800
  • WindTerm 无法认证

    WindTerm客户端,取消 “会话设置 -> SSH -> 验证 -> 尝试键盘交互认证” 可已正常连接。

    安装 OpenSSH Server

    $ apk update
    $ apk add openssh-server openssh
    
    ; /etc/ssh/sshd_config
    
    # 开放Root登录
    - #PermitRootLogin prohibit-password
    + PermitRootLogin yes
    
    # 允许其它用户登录
    - #PasswordAuthentication yes
    + PasswordAuthentication yes
    
    # 解决ssh自动断开
    - #ClientAliveInterval 0
    - #ClientAliveCountMax 3
    + ClientAliveInterval 60
    + ClientAliveCountMax 3
    
    $ rc-service sshd start
    
    $ rc-service sshd restart
    # 设置开机启动
    $ rc-update add sshd
    # 删除开机启动服务
    $ rc-update del sshd
    # 显示所有服务
    # rc-status -a
    

    终端配置

    在 /etc/profile.d 文件夹下,创建sh文件来实现。

    linux cli alpine linux Created Wed, 28 Dec 2022 16:27:00 +0800
  • 已弃用,转到 Tmux 命令

    创建屏幕

    # 离线方式创建屏幕,一般用在启动脚本
    $ screen -S <screen_name> -d -m
    

    查年屏幕

    $ screen -ls
    

    执行命令

    # 在指定屏幕内输入cmd,注意\n代表回车
    $ screen -S <screen_name> -X stuff "<cmd>\n"
    # 在当前窗口内,通过另一个过滤进程控制窗口的输入或输出。
    # 非常复杂,还没有搞明白有什么用
    # 官方建议:小心使用!
    $ screen -S <screen_name> -X |<cmd>
    $ screen -S <screen_name> -X !..|<cmd>
    $ screen -S <screen_name> -X exec<cmd>
    

    参考文档

    离开屏幕

    在 screen 终端下,按 Ctrl+a d 键

    退出屏幕

    # 进入指定屏幕,再退出
    $ screen -r <screen_name|pid>
    $ exit
    # 指定屏幕,直接退出
    $ screen -S <screen_name> -X quit
    
    cli screen linux Created Wed, 28 Dec 2022 14:24:08 +0800
  • systemctl命令

    systemctl list-units            ##列出当前系统服务的状态
    systemctl list-unit-files       ##列出服务的开机状态
    systemctl status sshd           ##查看指定服务的状态
    systemctl stop sshd             ##关闭指定服务
    systemctl start sshd            ##开启指定服务
    systemctl restart sshd          ##从新启动服务
    systemctl enable sshd           ##设定指定服务开机开启
    systemctl disable sshd          ##设定指定服务开机关闭
    systemctl reload sshd           ##使指定服务从新加载配置
    systemctl list-dependencies sshd    ##查看指定服务的倚赖关系
    systemctl mask  sshd            ##冻结指定服务
    systemctl unmask sshd           ##启用服务
    systemctl set-default multi-user.target ##开机不开启图形
    systemctl set-default graphical.target  ##开机启动图形
    

    设置主机名

    $ _hostname_=XXXX
    $ hostnamectl --static set-hostname ${_hostname_}
    $ hostnamectl --transient set-hostname ${_hostname_}
    $ hostnamectl --pretty set-hostname ${_hostname_}
    

    修改服务器时区

    $ timedatectl set-timezone Asia/Shanghai
    
    CLI Systemd Linux Created Tue, 27 Dec 2022 17:29:08 +0800
  • 遇事不决,多读文档!

    虚拟机

    创建

    使用命令行创建 VM 非常方便,而且还可以使用各发行版的云镜像,快速创建速度又快,占用空间又小,非常方便。

    # 增加硬盘空间
    # 建议从模板创建虚拟机后,再增加虚拟机硬盘的空间,这样可以保持模板的大小
    qm disk resize <VM_ID> scsi0 +30G
    
    # 关闭
    qm stop <vmid>
    # 如果关闭失败
    qm list
    # 找到 vm 对应的 pid
    kill <pid>
    
    # 删除
    qm destroy <vmid> --destroy-unreferenced-disks 1 --purge 1 --skiplock 1
    
    # 强制删除
    rm -f /etc/pve/nodes/*/*/<vm_id>.conf
    # [修復Proxmox VE:無法刪除虛擬機器](https://blog.pulipuli.info/2014/08/proxmox-ve-fix-proxmox-ve-destroy.html#postcataproxmox-ve-fix-proxmox-ve-destroy.html0_anchor2)
    

    LXC容器

    # 关闭
    pct stop <vmid>
    pct list
    

    存储

    # 查看存储空间使用情况
    pvesm status
    
    # 查看存储内的文件
    pvesm list <storage>
    
    # 查看存储配置
    cat /etc/pve/storage.cfg
    
    # 给local存储添加存储类型
    pvesm set local --content snippets,rootdir,import,images,backup,vztmpl,iso
    # 注意!!!片段文件只能放在 /var/lib/vz/snippets/ 目录下,不支持子目录
    
    # 将local-lvm(LVM-Thin)合并到local
    # 移动虚拟机硬盘到local
    qm disk move <vmid> <disk> <storage> --format qcow2 --delete 1
    # 移动容器卷到local
    pct move-volume <vmid> <volume> <storage> --delete 1
    # 删除local-lvm存储
    lvremove pve/data
    # 空间合并到local
    lvextend -l +100%FREE -r pve/root
    # 在WebUI的“数据中心”-"存储"里,手动移除local-lvm
    
    CLI ProxmoxVE Created Tue, 27 Dec 2022 16:51:54 +0800
  • 使用Hyper-V安装CentOS虚拟机,使用起来非常方便。但遇到磁盘空间不够时,不像Windows虚拟机那样方便给磁盘空间扩容。 总体两分二步:

    1. vhdx扩容

    关闭虚拟机,然后给磁盘扩容,操作方便网上教程多,这里不再赘述。

    2. CentOS扩容

    2.1 查看分区表

    $ lsblk
    NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    sda               8:0    0   20G  0 disk 
    ├─sda1            8:1    0  200M  0 part /boot/efi
    ├─sda2            8:2    0    1G  0 part /boot
    └─sda3            8:3    0  8.8G  0 part 
      ├─centos-root 253:0    0  7.8G  0 lvm  /
      └─centos-swap 253:1    0    1G  0 lvm  [SWAP]
    

    以上内容可以看出,sda已经扩容到20G,但sda1+sda2+sda3只有10G说明vhdx扩容成功。

    2.2 建立新分区

    $ fdisk /dev/sda
    
    The device presents a logical sector size that is smaller than
    the physical sector size. Aligning to a physical sector (or optimal
    I/O) size boundary is recommended, or performance may be impacted.
    欢迎使用 fdisk (util-linux 2.23.2)
    更改将停留在内存中,直到您决定将更改写入磁盘。
    使用写入命令前请三思。
    
    
    命令(输入 m 获取帮助):n
    Partition type:
       p   primary (1 primary, 0 extended, 3 free)
       e   extended
    Select (default p): 
    Using default response p
    分区号 (2-4,默认 2)起始 扇区 (20971520-41943039,默认为 20971520)将使用默认值 20971520
    Last 扇区, +扇区 or +size{K,M,G} (20971520-41943039,默认为 41943039):+10G
    值超出范围。
    Last 扇区, +扇区 or +size{K,M,G} (20971520-41943039,默认为 41943039):+9.9G
    不支持的后缀:“.9G”。
    支持:10^N: KB (千字节), MB (兆字节), GB (吉字节)
                2^N: K  (约千字节), M  (约兆字节), G  (约吉字节)
    Last 扇区, +扇区 or +size{K,M,G} (20971520-41943039,默认为 41943039):+9G 
    分区 2 已设置为 Linux 类型,大小设为 9 GiB
    
    命令(输入 m 获取帮助):w
    The partition table has been altered!
    
    Calling ioctl() to re-read partition table.
    
    WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.
    The kernel still uses the old table. The new table will be used at
    the next reboot or after you run partprobe(8) or kpartx(8)
    正在同步磁盘。
    

    重读分区表时,发生错误

    $ partprobe
    Error: 备份 GPT 表不像应该的那样出现在磁盘的末尾。这可能意味这其它操作系统相信磁盘小一些。通过将备份移动到末尾 (并删除旧备份) 来修正?
    Warning: Not all of the space available to /dev/sda appears to be used, you can fix the GPT to use all of the space (an extra 20971520 blocks) or continue with the current setting? 
    

    查看分区表时,发现新分区未创建成功

    $ lsblk
    NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    sda               8:0    0   20G  0 disk 
    ├─sda1            8:1    0  200M  0 part /boot/efi
    ├─sda2            8:2    0    1G  0 part /boot
    └─sda3            8:3    0  8.8G  0 part 
      ├─centos-root 253:0    0  7.8G  0 lvm  /
      └─centos-swap 253:1    0    1G  0 lvm  [SWAP]
    

    使用 parted 修复分区表

    $ parted /dev/sda
    GNU Parted 3.1
    使用 /dev/sda
    Welcome to GNU Parted! Type 'help' to view a list of commands.
    (parted) p                                                                
    错误: 备份 GPT 表不像应该的那样出现在磁盘的末尾。这可能意味这其它操作系统相信磁盘小一些。通过将备份移动到末尾 (并删除旧备份) 来修正?
    修正/Fix/忽略/Ignore/放弃/Cancel? fix                                     
    警告: Not all of the space available to /dev/sda appears to be used, you can fix the GPT to use all of the space (an extra 20971520 blocks) or continue with the current
    setting? 
    修正/Fix/忽略/Ignore? fix                                                 
    Model: Msft Virtual Disk (scsi)
    Disk /dev/sda: 21.5GB
    Sector size (logical/physical): 512B/4096B
    Partition Table: gpt
    Disk Flags: 
    
    Number  Start   End     Size    File system  Name                  标志
     1      1049kB  211MB   210MB   fat16        EFI System Partition  启动
     2      211MB   1285MB  1074MB  xfs
     3      1285MB  10.7GB  9452MB                                     lvm
    
    (parted) p                                                                
    Model: Msft Virtual Disk (scsi)
    Disk /dev/sda: 21.5GB
    Sector size (logical/physical): 512B/4096B
    Partition Table: gpt
    Disk Flags: 
    
    Number  Start   End     Size    File system  Name                  标志
     1      1049kB  211MB   210MB   fat16        EFI System Partition  启动
     2      211MB   1285MB  1074MB  xfs
     3      1285MB  10.7GB  9452MB                                     lvm
    
    (parted) quit                                                             
    

    再次建立新分区

    $ fdisk /dev/sda
    WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.
    欢迎使用 fdisk (util-linux 2.23.2)
    更改将停留在内存中,直到您决定将更改写入磁盘。
    使用写入命令前请三思。
    
    
    命令(输入 m 获取帮助):n
    分区号 (4-128,默认 4)第一个扇区 (34-41943006,默认 20969472)Last sector, +sectors or +size{K,M,G,T,P} (20969472-41943006,默认 41943006):+10G
    已创建分区 4
    
    
    命令(输入 m 获取帮助):w
    The partition table has been altered!
    
    Calling ioctl() to re-read partition table.
    
    WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.
    The kernel still uses the old table. The new table will be used at
    the next reboot or after you run partprobe(8) or kpartx(8)
    正在同步磁盘。
    

    2.3 重读分区表

    $ partprobe
    

    重读分区表,正常不会有任何输出

    CentOS Hyper-V windows Created Mon, 26 Dec 2022 21:01:32 +0800
  • Hyper-V 环境下安装 Linux 是无法调节分辨率的,但可以通过设置指定分辨率,不过最大只能支持1920x1080

    1. 修改配置文件

    $ sudo nano /etc/default/grub
    

    将配置

    GRUB_CMDLINE_LINUX_DEFAULT="quiet splash "
    

    修改为

    GRUB_CMDLINE_LINUX_DEFAULT="quiet splash video=hyperv_fb:1920x1080"
    

    这里要注意屏幕的实际分辨率,在15寸的笔记本上,适合的分辨率为1600x900

    2. 更新 Grub

    $ sudo update-grub
    

    3. 重启

    $ reboot
    

    参考文档

    Hyper-V 下 Ubuntu/Deepin 如何设置分辨率

    Ubuntu Hyper-V windows Created Mon, 26 Dec 2022 20:58:50 +0800