nix-rebuild命令

nix-rebuil命令

1
2
3
4
5
6
7
nixos-rebuild {switch | boot | test | build | dry-build | dry-activate | edit | build-vm | build-vm-with-bootloader}
[{ --upgrade | --upgrade-all }] [--install-bootloader] [--no-build-nix] [--fast] [--rollback] [--builders builder-spec]
[--flake flake-uri] [--override-input input-name flake-uri]
[{ --profile-name | -p } name]
[--build-host host] [--target-host host] [--use-remote-sudo]
[--show-trace] [-I path] [{--verbose | -v}] [{--impure}] [{--max-jobs | -j} number] [{--keep-failed | -K}] [{--keep-going | -k}]

几个常见的命令

1
2
3
4
5
nixos-rebuild list-generations
sudo nix-collect-garbage -d
sudo nixos-rebuild boot
sudo nixos-rebuild switch -p profile-name

其中最后一条命令详解如下:

1
2
3
4
5
6
7
8
9
10
--profile-name,  -p

Instead of using the Nix profile /nix/var/nix/profiles/system to keep track of the current and previous system configurations, use /nix/var/nix/profiles/system-profiles/name. When you use GRUB 2, for every system profile created with this flag, NixOS will create a submenu named “NixOS - Profile 'name'” in GRUB’s boot menu, containing the current and previous configurations of this profile.

For instance, if you want to test a configuration file named test.nix without affecting the default system profile, you would do:

$ nixos-rebuild switch -p test -I nixos-config=./test.nix

The new configuration will appear in the GRUB 2 submenu “NixOS - Profile 'test'”.

可以在/nix/var/nix/profiles/system-profiles/ 目录下找到标签相关的文件,删除掉标签目录,重新执行一次sudo nixos-rebuild boot 就可以删除标签相关grub启动项目。

阅读更多

安装nixos后要做的事情

更新channel源

1
2
sudo nix-channel --add https://mirrors.tuna.tsinghua.edu.cn/nix-channels/nixos-24.11 nixos
sudo nix-channel --update

注意修改nixos-24.11到匹配的版本

启用flatpak

  1. /etc/nixos/configuration.nix中添加如下代码,启用flatpak
1
2
3
4
# flatpak support
xdg.portal.extraPortals = [ pkgs.xdg-desktop-portal-kde ];
xdg.portal.enable = true;
services.flatpak.enable = true;
  1. 启用蓝牙
1
2
hardware.bluetooth.enable = true; # enables support for Bluetooth
hardware.bluetooth.powerOnBoot = true; # powers up the default Bluetooth controller on boot
  1. 启用系统级工具
1
2
3
4
5
6
7
8
9
10
11
12
13
environment.systemPackages = with pkgs; [
vim
wget
pkgs.git
pkgs.nodejs_20
pkgs.texliveSmall
cpkgs.hexo-cli
pkgs.pandoc
pkgs.vscode
pkgs.microsoft-edge
pkgs.texliveSmall

];
  1. 安装字体及输入法
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
i18n.inputMethod = {

enable = true;
type = "fcitx5";
fcitx5.addons = with pkgs; [
fcitx5-gtk # alternatively, kdePackages.fcitx5-qt
fcitx5-chinese-addons # table input method support
fcitx5-nord # a color theme
fcitx5-fluent
fcitx5-material-color
rime-data
fcitx5-rime
];

};

fonts = {
packages = with pkgs; [
noto-fonts
noto-fonts-cjk-sans
noto-fonts-cjk-serif
source-code-pro
hack-font
jetbrains-mono
];
};

  1. 配置网络
1
2
3
4
5
6
7
8
9
# Enable networking
networking.networkmanager.enable = true;
networking.networkmanager.dns = "none";
networking.nameservers = [
"223.5.5.5"
"8.8.8.8"
"114.114.114.114"
];

  1. 更新系统执行sudo nixos-rebuild switch更新系统

  2. 修改flatpak源,并安装常用软件

1
2
3
4
sudo flatpak remote-modify flathub --url=https://mirrors.ustc.edu.cn/flathub

flatpak install flathub md.obsidian.Obsidian

阅读更多

Pandoc将Markdown文件导出成PDF文件

Pandoc将Markdown文件转换成PDF文件时是先将Markdown文件转换成Latex文件,再将Latex文件专程PDF文件。参考命令:

1
pandoc example.md -o example.pdf --from markdown --pdf-engine=xelatex --template=eisvogel --listings

选择编译引擎

一般默认的编译引擎是pdflatex编译引擎,这个引擎对中文支撑不太友好,可以通过–pdf-engine=xelatex 修改编译引擎。

选择模板

使用pandoc模板 eisvogel ,eisvogel可以导出很漂亮的PDF文件。

  1. 将 eisvogel 模板拷贝到pandoc用户模板目录下,具体配置:

    • 在Linux系统下:/home/USERNAME/.local/share/pandoc/templates/
    • 在Windows系统下:C:\Users\USERNAME\AppData\Roaming\pandoc\templates\
  2. 改善中文支持,需要在eisvogel添加如下参数:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    \else % if not pdftex
    $if(mainfont)$
    $else$
    \usepackage[fallback]{xeCJK}
    \setCJKmainfont{SimSun}[BoldFont=SimHei, ItalicFont=KaiTi] %配置中文字体
    \setCJKfallbackfamilyfont{rm}{SimSun}
    \usepackage[default]{sourcesanspro}
    \usepackage{sourcecodepro}

  3. 增加首行缩进,在 eisvogel.tex 文件中查找,在\begin{document}请增加一段代码:

    1
    2
    3
    4
    \usepackage{ctex} %调用中文字体宏包
    \usepackage{indentfirst} %调用首行缩进宏包
    \setlength{\parindent}{2em} %设置首行缩进为2字符
    \begin{document}
阅读更多

云计算中VM资源利用率和宿主机资源利用率之间的关系

资源分配模型

  1. 虚拟机利用率:指分配给VM的CPU、内存、磁盘I/O等资源被实际使用的百分比。
  2. 宿主机利用率:宿主机物理资源被所有运行中VM实际消耗的总和。
  3. 关系公式(简化为CPU场景):

$$
\text{Host利用率} = \sum_{i=1}^{n}\left(\text{VM}_i利用率 \times \frac{\text{vM}_i分配量}{\text{Host总资源}} \right)
$$

note

假设宿主机有16个物理CPU核心和64GB内存:

  1. 静态分配:若为4个VM各分配4核+16GB,则宿主机利用率上限为:
  2. CPU利用率 = Σ(VM实际使用CPU时间) / 宿主机总CPU时间
  3. 内存利用率 = Σ(VM实际使用内存) / 64GB
  4. 动态超售:若超售50%(分配24核+96GB),实际利用率可能超过100%,但需依赖调度算法避免性能下降。
阅读更多

安装中文LaTeX环境

安装中文LaTeX环境

1
sudo apt install texlive texlive-xetex texlive-latex-extra texlive-fonts-recommended texlive-fonts-extra -y

更换Hexo渲染引擎

更换渲染引擎

hexo-renderer-markdown-it渲染引擎,自带很多插件,社区也比较活跃。可以将自带的渲染引擎替换成。

  1. 首先卸载原有的渲染引擎

    1
    2
    3
    npm un hexo-renderer-marked --save
    npm un hexo-renderer-pandoc --save

    默认渲染引擎:hexo-renderer-marked

  2. 安装新引擎 npm i hexo-renderer-markdown-it --save

  3. 在_config文件中增加配置,启用新引擎的特性,具体配置如下:

    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
    markdown:
    preset: "default"
    render:
    html: true
    xhtmlOut: false
    langPrefix: "language-"
    breaks: true
    linkify: true
    typographer: true
    quotes: "“”‘’"
    enable_rules:
    disable_rules:
    plugins:
    - markdown-it-abbr
    - markdown-it-attrs
    - markdown-it-cjk-breaks
    - markdown-it-deflist
    - markdown-it-emoji
    - markdown-it-footnote
    - markdown-it-ins
    - markdown-it-mark
    - markdown-it-sub
    - markdown-it-sup
    - name: markdown-it-container
    options: success
    - name: markdown-it-container
    options: tips
    - name: markdown-it-container
    options: warning
    - name: markdown-it-container
    options: danger

    anchors:
    level: 2
    collisionSuffix: ""
    permalink: false
    permalinkClass: "header-anchor"
    permalinkSide: "left"
    permalinkSymbol: "¶"
    case: 0
    separator: "-"

测试新渲染引擎

  1. markdown-it-container插件,支持容器显示内容

    测试
    测试markdown-it-container生效

  2. 支持上述内容显示,还需要在主题的css文件中增加样式,参考样式如下:

    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
    // custom css for markdown-it-container
    .tips {
    padding-left: 10px;
    background-color rgba(52,152,219,.3);
    border-left 6px solid rgb(52,152,219);
    color: darken(rgb(52,152,219),20%);
    }
    .success {
    padding-left: 10px;
    background-color rgba(46,204,113,.3);
    border-left 6px solid rgb(46,204,113);
    color: darken(rgb(46,204,113),20%);
    }
    .warning {
    padding-left: 10px;
    background-color rgba(241,196,15,.3);
    border-left 6px solid rgb(241,196,15);
    color: darken(rgb(241,196,15),20%);
    }
    .danger {
    padding-left: 10px;
    background-color rgba(231,76,60,.3);
    border-left 6px solid rgb(231,76,60);
    color: darken(rgb(231,76,60),20%);
    }

阅读更多

Hexo 支持admonition 插件

安装hexo-admonition 插件

  1. 在Blog目录下执行如下命令安装插件

    1
    npm install hexo-admonition --save
  2. 在修改主题样式,增加admonition样式

    • 在Blog根目录下找到./node_modules/hexo-theme-icarus/source/css目录
    • 在style.styl中添加css代码

如何使用hexo-admonition

1
2
3
4
5
6
7
8
9
10
!!! note Hexo-admonition 插件使用示例
这是基于 hexo-admonition 插件渲染的一条提示信息。类型为 note,并设置了自定义标题。
**提示内容开头留 4 个空格**,可以有多行,最后用空行结束此标记。

提示类型 type 将用作 CSS 类名称,暂支持如下类型:
- note
- info, todo
- warning, attention, caution
- error, failure, missing, fail

Hexo-admonition 插件使用示例

这是基于 hexo-admonition 插件渲染的一条提示信息。类型为 note,并设置了自定义标题。 提示内容开头留 4 个空格,可以有多行,最后用空行结束此标记。

提示类型 type 将用作 CSS 类名称,暂支持如下类型:
- note
- info, todo
- warning, attention, caution
- error, failure, missing, fail

阅读更多

安装Linux发行版本日常工具

安装Linux

无论安装那个Linux发行版本都要注意下载完成镜像文件以后需要验证一下sha256sum文件一致。

1
sha256sum /path/Linux.iso

使用国内镜像源

  1. 修改Linux系统源,以下以POP OS为例
1
2
3
4
sudo sed -i 's@http://apt.pop-os.org/@https://mirror.sjtu.edu.cn/pop-os/@g' /etc/apt/sources.list.d/pop-os-apps.sources
sudo sed -i 's@http://apt.pop-os.org/@https://mirror.sjtu.edu.cn/pop-os/@g' /etc/apt/sources.list.d/pop-os-release.sources
sudo sed -i 's@http://apt.pop-os.org/@https://mirror.sjtu.edu.cn/@g' /etc/apt/sources.list.d/system.sources

  1. 以NixOS为例
1
2
3
sudo nix-channel --add https://mirrors.tuna.tsinghua.edu.cn/nix-channels/nixos-22.11 nixos
sudo nix-channel --update

  1. 修改flatpak源
1
sudo flatpak remote-modify flathub --url=https://mirrors.ustc.edu.cn/flathub
阅读更多

分布式数据库以及应用改造

分布式数据库

典型的分布式数据库及实现

  1. 增加分布式数据中间件(即在多个独立数据库实例前增加一个数据库中间件),由分布式数据库中间件实现分库分表,分布式SQL执行,分布式事务等。
  2. 内置分布式数据库中间件(将分布式数据库中间件作为分布式数据的一个组件)
  3. 不论是内置还是外置的数据库中间件都会接管数据库客户端和数据库服务之间的链接,一般会提供如下能力:
    1. 分库能力
    2. 分表能力
    3. 分布式事务(有限的分布式事务能力:Local、XA、Free/Base)
    4. 支持读写分离
    5. 兼容有限的数据库协议和客户端
    6. 支持水平扩展,(可选)提供前端负载均衡能力
阅读更多

大数据通用架构

Lambda架构

Lambda架构
  1. Lambda架构有三层,批处理层、速度层和服务层。
    1. 批处理层:批处理层是基于Hadoop生态,随着数据的更新会对所有数据进行重计算并将计算结果保存到NoSQL数据库中(如:electicalsearch、HBase、Redis、Hive等),提供批处理视图,批处理视图会整体批量更新;
    2. 速度层:由于批处理的机制导致延迟较大(天级/小时级),如果需要尽快的处理实时数据则需要提供单独的机制产生实时视图,通常只需要保存少量近期数据;
    3. 服务层:只会调用批处理视图和实时视图(汇总实时图和批处理视图),为应用系统提供查询服务;
  2. Lambda架构特点:
    1. 有批处理层、速度层和服务层三层;
    2. 所有数据最终都需要放在统一分布式存储上;
    3. 批处理层重新计算以后速度层的视图就可以丢弃;
    4. Lambda平台实现逻辑复杂(实时数据和批处理数据是两套处理)
阅读更多