跳转至

2023

Docker

简介

基于 Go 语言 并遵从 Apache2.0 协议开源。Docker 可以让开发者打包他们的应用以及依赖包到一个轻量级、可移植的容器中,然后发布到任何流行的 Linux 机器上。

structure

Docker vs VMWare

相对于传统虚拟机,Docker 没有硬件虚拟化/hypervisor,可以运行在物理机、虚拟机, 甚至嵌套运行在 Docker 容器内,并且其不携带操作系统的,会轻巧很多。而且调用资源时利用 Docker Engine 去调用宿主的的资源,这时候过程是虚拟内存->真正物理内存。

Image title

Image title2

Linux内核的潜在兼容性问题

how docker run different ubuntu version Sharing the same running kernel? no SW conficts?

If your host kernel is "compatible enough" with the software in the container you want to run it will work; otherwise, it won't.1 So what does "compatible enough" mean? It depends on what requests the program makes of the kernel (system calls) and what features it expects the kernel to support. Some programs make requests that will break things; others don't.

Compatibility

on an Ubuntu 18.04 (kernel 4.19) or similar host:1 docker run centos:7 bash works fine. docker run centos:6 bash fails with exit code 139, meaning it terminated with a segmentation violation signal; this is because the 4.19 kernel doesn't support something that that build of bash tried to do. docker run centos:6 ls works fine because it's not making a request the kernel can't handle, as bash was. If you try docker run centos:6 bash on an older kernel, say 4.9 or earlier, you'll find it will work fine.

Portainer 统一管理

  • 安装Portainer Community Edition (CE)而不是Portainer Business Edition (BE)
  • WSL的安装和linux类似
    # 创建 Portainer Server 将用于存储其数据库的卷
    docker volume create portainer_data
    
    # 下载并安装 Portainer Server 容器, 9000为WebUI端口, 8000 是可选的,仅当您计划将边缘计算功能与边缘代理一起使用时才需要。
    docker run -d -p 8000:8000 -p 9000:9000 --name portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v /portainer_data:/data portainer/portainer-ce:2.11.1
    
  • Portainer里的docker部署: 建议使用 Stacks 下的 docker-compose 来进行

端口映射

2333:8000 为 容器内部端口8000,宿主机端口为2333

远程WebUI访问

默认部署在 http://localhost:9000, 可以如下操作来部署 http://222.195.72.218:9000/#!/home

# docker在服务器上时,可以关闭防火墙访问,也可以ssh代理到本地
brainiac1# ufw status
Status: inactive

Install

# 安裝 docker
curl -sSL get.docker.com | sh
# 將目前使用者新增到 docker 群組內,需要重新登入才會生效
sudo usermod -aG docker $USER

# 安裝 docker-compose
sudo curl -L "https://github.com/docker/compose/releases/download/$(curl -sL https://api.github.com/repos/docker/compose/releases/latest | grep tag_name | cut -d'"' -f 4)/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose

Relationship

dockerTripleThing

Dockerfile & Image & Container
  • Image like a static configed/compiled software using dockerfile/gcc.
  • And container is a running process that we can control.

Dockerfile

First, write an installation script for all of your dependencies. This script is written with Docker specific syntax and is called a Dockerfile(1).

  1. A Dockerfile is a script used to create a Docker image, which is a lightweight, standalone, and executable package that includes everything needed to run a piece of software, including the code, runtime, system tools, system libraries, and settings.

Building image using Dockerfile

Building image using Dockerfile
Using dockerfile in portainer

Images > Build image

Dockerfile

Here's a simple Dockerfile code snippet(it's usually built on official base image):

# Use an official base image
FROM ubuntu:20.04

# Set environment variables
ENV MY_ENV_VARIABLE my_value

# Run commands to install packages and set up the environment
RUN apt-get update && apt-get install -y \
    package1 \
    package2 \
    && rm -rf /var/lib/apt/lists/*

# Copy files from your local machine to the container
COPY local_directory /container_directory

# Set the working directory
WORKDIR /app

# Expose a port
EXPOSE 8080

# Define the command to run when the container starts
CMD ["command_to_start_application"]

In this example, and more options:

  • FROM specifies the base image, in this case, Ubuntu 20.04.
  • ENV sets an environment variable.
  • RUN executes commands to install packages.
  • COPY copies files from your local machine to the container.
  • WORKDIR sets the working directory within the container.
  • EXPOSE specifies that the container will listen on port 8080.
  • CMD defines the command that will be executed when the container starts.

Cheat Sheet

查看容器出错日志:docker logs --tail 1000 1fed0d4782cf最后一项是容器ID

docker换国内源加速

使用docker info可以查看到文件保存路径,和是否有换源:

root@UGREEN-A0E9:~# docker info
 Docker Root Dir: /mnt/dm-0/.ugreen_nas/6
 Registry: https://index.docker.io/v1/

nano /etc/docker/daemon.json 把以下内容复制进去:

{
    "registry-mirrors": [
        "https://y0xk2hg9.mirror.aliyuncs.com",
        "https://registry.hub.docker.com",
        "http://hub-mirror.c.163.com",
        "https://docker.mirrors.ustc.edu.cn",
        "https://registry.docker-cn.com"
    ]
}

重启systemctl restart docker, 检查docker info

代理

在构建 Docker 镜像时,如果需要通过代理访问外部网络资源(例如,安装软件包或依赖项),你可以通过以下几种方式设置代理:

1. 使用环境变量

你可以在 docker build 命令中使用 --build-arg 选项,传递代理相关的环境变量。

docker build \
  --build-arg http_proxy=http://your.proxy.server:port \
  --build-arg https_proxy=http://your.proxy.server:port \
  -t your-image-name .

在 Dockerfile 中,你需要使用 ARG 指令来声明这些构建参数,以便 Docker 在构建过程中能够使用它们:

ARG http_proxy
ARG https_proxy

# 继续其他 Dockerfile 指令...

2. 在 Docker 守护进程中配置全局代理

你也可以通过配置 Docker 守护进程,在全局范围内使用代理。具体操作步骤如下:

  1. 创建或编辑 /etc/systemd/system/docker.service.d/http-proxy.conf 文件(对于 HTTP 代理):

    [Service]
    Environment="HTTP_PROXY=http://your.proxy.server:port"
    Environment="HTTPS_PROXY=https://your.proxy.server:port"
    Environment="NO_PROXY=localhost,127.0.0.1"
    

  2. 重新加载守护进程配置,并重启 Docker:

    sudo systemctl daemon-reload
    sudo systemctl restart docker
    

  3. 通过 docker build 命令构建镜像时,Docker 守护进程会自动使用配置的代理。

3. 手动设置代理

在 Dockerfile 中直接设置代理环境变量:

ENV http_proxy=http://your.proxy.server:port
ENV https_proxy=http://your.proxy.server:port

# 继续其他 Dockerfile 指令...

4. 使用 ~/.docker/config.json

你还可以在 ~/.docker/config.json 文件中配置代理:

{
  "proxies": {
    "default": {
      "httpProxy": "http://your.proxy.server:port",
      "httpsProxy": "https://your.proxy.server:port",
      "noProxy": "localhost,127.0.0.1"
    }
  }
}

通过这些方法,你可以在 docker build 命令中使用代理,从而在需要外部网络资源的场景下顺利构建 Docker 镜像。

docker push/pull

  • It is in these containers that you will run or develop your code.
  • If you would like other people to be able to use your Docker image you can push to DockerHub (with docker push),
  • and if you want to use someone else’s image you can pull from DockerHub (with docker pull).3

网络问题

root@UGREEN-A0E9:~# docker pull dreamacro/clash
Using default tag: latest
Error response from daemon: Get "https://registry-1.docker.io/v2/": net/http: request canceled (Client.Timeout exceeded while awaiting headers)

需要换源

docker build

Then, run these commands to build a Docker image of your environment by using docker build.

Dockfile Path

docker build 基本的格式为 docker build [ 选项 ] 路径,该命令将读取指定路径下(包括子目录)的 Dockerfile,并将该路径下所有内容发送给 Docker 服务端,由服务端来创建镜像。因此一般建议放置 Dockerfile 的目录为空目录。也可以通过 .dockerignore 文件(每一行添加一条匹配模式)来让 Docker 忽略路径下的目录和文件。

option

option like

$ sudo docker build -t myrepo/myapp /tmp/test1/
$ docker build -t username/image_name:tag_name .

docker build use proxy

docker build --network=host\
    --build-arg http_proxy=http://127.0.0.1:7890 \
    --build-arg https_proxy=http://127.0.0.1:7890 \
    --build-arg "NO_PROXY=localhost,127.0.0.1,.example.com" \
    -t ithemal:latest .

You also can set the proxy in the Dockerfile.5

ENV http_proxy "http://127.0.0.1:7890"
ENV https_proxy "https://127.0.0.1:7890"

docker tag

镜像的完整 tag 不仅包含镜像名字, 还指明了镜像从哪里来, 要到哪里去, 就像一个 URL。可以通过 -t 选项指定镜像的标签信息,譬如:

$ docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]

docker run

Once successfully built, you can instantiate copies of this image as many times as you would like by using docker run to create Docker containers.

Container Lifecycle2

option
# 使用镜像nginx:latest以交互模式启动一个容器,在容器内执行/bin/bash命令。
$ docker run -it nginx:latest /bin/bash
# remove all stop container
$ docker container prune
  • -i: 以交互模式运行容器,通常与 -t 同时使用;
  • -t: 为容器重新分配一个伪输入终端,通常与 -i 同时使用;
  • -d: 后台运行容器,并返回容器ID;
  • -P: 随机端口映射,容器内部端口随机映射到主机的端口
  • -p: 指定端口映射,格式为:主机(宿主)端口:容器端口
  • --name="nginx-lb": 为容器指定一个名称;
  • -e username="ritchie": 设置环境变量;

docker Volumes

volumes allow me to interact with data outside of the docker container.

Volumes is better than bind mounts
  1. Volumes are easier to back up or migrate than bind mounts.
  2. Volumes work on both Linux and Windows containers. So option -v is better than --mount
options
docker run \
-v <path to datasets>:/datasets \
-v <path to approx-vision>:/approx-vision \
-it mbuckler/approx-vision \
/bin/bash

docker-compose

Compose 是用于定义和运行多容器 Docker 应用程序的工具。需要额外安装。通过 Compose,您可以使用 YML 文件来配置应用程序需要的所有服务。然后,使用一个命令,就可以从 YML 文件配置中创建并启动所有服务。

十分不建议使用docker-compose命令

使用root用户执行docker-compose up -d,不然会有文件权限问题。各种问题,软件版本问题等,十分折磨。

compose file
version: "3"

services:
  mihoyo-bbs:
    image: darkatse/mihoyo-bbs
    environment:
      - CRON_SIGNIN=30 9 * * *
      - MULTI=TRUE
    volumes: # 将主机的数据卷或着文件挂载到容器里。
      - .:/var/app
    logging: # driver:指定服务容器的日志记录驱动程序,默认值为json-file
      driver: "json-file"
      options:
        max-size: "1m" # 最多1m个文件,当达到文件限制上限,会自动删除旧得文件。

AutoMihoyoBBS4 将上述 YAML 文件保存为 docker-compose.yml,然后在包含该文件的目录中运行以下命令:

deploy

docker-compose logs -f命令来查看程序输出。 -f, --follow Follow log output

# docker-compose up 命令来启动并运行整个应用程序。
# docker-compose down 可以将整个应用停止并删除相关资源。
$ docker-compose up -d 
# 在后台执行该服务可以加上 -d 参数
Creating network "automihoyobbs_default" with the default driver
Pulling mihoyo-bbs (darkatse/mihoyo-bbs:)...
latest: Pulling from darkatse/mihoyo-bbs
df9b9388f04a: Pull complete
a1ef3e6b7a02: Pull complete
7a687728470e: Pull complete
4ecf30de1710: Pull complete
a1f99e431609: Pull complete
7e9141a60a66: Pull complete
7aa39aec04ec: Pull complete
a75b4b3d5690: Pull complete
dee0a6b07871: Pull complete
abed80702fed: Pull complete
Digest: sha256:10958801df87675c390a8cdcc153c2f87a41af92d35f9f2cf9b7758aa3e10d1b
Status: Downloaded newer image for darkatse/mihoyo-bbs:latest
Creating automihoyobbs_mihoyo-bbs_1 ... done

实例

AllForOne 脚本
#!/bin/bash
docker_name="mihoyo-bbs"
docker stop ${docker_name}
docker rm ${docker_name}
echo -e "\033[5;36mOrz 旧容器(镜像)已清理\033[0m"

time_now=$(date "+%m%d%H")
docker build -f dockerfile --tag ${docker_name}:"${time_now}" .
echo -e "\033[5;36mOrz 镜像重建完成\033[0m"

docker run -itd \
    --name ${docker_name} \
    --log-opt max-size=1m \
    -v $(pwd):/var/app \
    ${docker_name}:"${time_now}"
echo -e "\033[5;36mOrz 镜像启动完成\033[0m"
docker ps -a #顯示目前的 container 及狀態
docker logs ${docker_name} -f # -f, --follow         Follow log output
hackergame2020 的源码的dockerfile

奇怪的使用

启动docker并通过xhost保持tmux连接

  • docker/docker_connect.sh 或者 https://blog.csdn.net/winter2121/article/details/118223637
  • What if I want to use X forwarding from within a Docker container?3

Docker of VNC

在Linux服务器上使用Docker运行图形化界面的应用程序。为了实现这一点,您需要使用一个特别配置的Docker镜像,该镜像支持图形用户界面(GUI)。这通常涉及到安装一个桌面环境和任何必要的图形驱动程序。

以下是实现这一目的的基本步骤:

  1. 选择一个合适的基础镜像:您可以从一个已经包含了桌面环境的基础镜像开始,例如Ubuntu或Fedora。
  2. 安装图形界面:在Dockerfile中,您可以安装一个桌面环境,如GNOME、KDE或Xfce,以及任何其他必需的软件。
  3. 配置X11或其他显示服务器:为了让图形界面能够显示,您需要配置X11或类似的显示服务器。这可能涉及到暴露和映射一些端口,以及安装和配置VNC服务器或其他远程桌面软件。
  4. 运行容器并连接到图形界面:一旦容器运行起来,您需要通过VNC客户端或其他远程桌面工具连接到它。

这里是一个示例的Dockerfile,用于创建一个带有图形界面的Ubuntu容器:

FROM ubuntu:latest

# 安装必要的软件包
RUN apt-get update && apt-get install -y \
    ubuntu-desktop \
    vnc4server \
    xterm

# 设置VNC服务器
RUN mkdir /root/.vnc
RUN echo "your-password" | vncpasswd -f > /root/.vnc/passwd
RUN chmod 600 /root/.vnc/passwd

# 设置VNC启动脚本
COPY vnc_startup.sh /root/vnc_startup.sh
RUN chmod +x /root/vnc_startup.sh

# 暴露VNC端口
EXPOSE 5900

CMD ["/root/vnc_startup.sh"]

在这个Dockerfile中,ubuntu-desktopvnc4server被安装,以便提供图形界面和VNC访问。您需要创建一个VNC启动脚本(vnc_startup.sh),以启动VNC服务器并运行桌面环境。

请注意,运行图形界面的容器通常比标准的、无GUI的容器更加资源密集,并且可能需要更多的存储空间和内存。此外,确保遵循最佳安全实践,特别是在暴露VNC或其他远程访问服务时。

常见问题

Got permission denied while trying to connect to the Docker daemon socket
  1. sudo 运行
  2. 加入docker用户组
sudo groupadd docker     #添加docker用户组
sudo usermod -aG docker $USER #将登陆用户加入到docker用户组中
sudo gpasswd -a $USER docker    # or
groups # 重新登录查看是否生效
newgrp docker     #更新用户组
docker ps    #测试docker命令是否可以使用sudo正常使用
failed to create endpoint portainer on network bridge: adding interface xxx to bridge yyy failed: Device does not exist.

gpt's solution的无效答案

这个错误表明 Docker 在创建容器时遇到了问题,具体原因是无法将网络接口 veth2c573cd 添加到 Docker 网络桥 docker0,并且提示设备不存在。

查看 Docker 网络列表,确保相关的网络(可能是 bridge)存在:

docker network ls

如果不存在,你可以尝试删除并重新创建:

docker network rm yyy
docker network create yyy

然后再次运行你的 Docker 容器。

sudo password in docker image

link 1 2 3

参考文献

https://cloud.tencent.com/developer/article/1395434


  1. How can Docker run distros with different kernels? 

  2. Docker Commands for Managing Container Lifecycle (Definitive Guide) 

  3. Developing in Docker 

  4. https://github.com/Womsxd/AutoMihoyoBBS 

  5. https://cloud.tencent.com/developer/article/1806455 & http://www.debugself.com/2018/01/17/docker_network/ 

Visualization Ranking

Goal

横向条形图排序赛跑叫Bar chart race

visualization using echart

  1. 完整的中文官方教程和丰富的插件和相关项目
  2. 可以支持vue
  3. 支持动态折线图和动态柱状图

visualization using d3.js

参考项目

但是好像是静态的,而且只有一个排序的柱状图

visualization using anichart

参考文档, 使用template项目

git clone https://github.com/Kirrito-k423/leetcode-ranking-visualization-anichart.git

# Install Dependencies
npm install -g pnpm
pnpm i
pnpm build # error

由于项目还在开发,暂时不进一步尝试

需要进一步的研究学习

暂无

遇到的问题

暂无

开题缘由、总结、反思、吐槽~~

参考文献

Cuda Program Basic

CUDA编程水平高低的不同,会导致几十上百倍的性能差距。但是这篇将聚焦于CUDA的编程语法,编译与运行。

UnimportantView: Film & TV(Anime) Works Rating

如何评价影视剧(动漫作品)

我一向的观点是现实生活已经投入了很多时间体验了,影视剧(动漫作品)肯定要是看现实中没有的。这导致的第一个问题就是既然不存在,你怎么让观众相信呢?

  • 真实的氛围感
  • 真实的细节特效
  • 真实的演员反映和期望中的样子

如何评价对影视剧(动漫作品)角色的喜爱程度

  • 喜欢一个角色往往是没有什么理由的,虽然要追求格物致知。但是将最感性的情感拿来分析是不是有点无情呢?

  • 初印象的美好(40)

  • 外貌美(15):
    • 不一定要完美,但是要有特点,
    • 可以接受有缺陷,但是其一般要具有意义来完善人物塑造。
  • 可爱俏皮(5)
    • 可以拉进距离感
  • 性格好(乐观、勇敢、坚毅、聪明)(10)
    • 角色不可能不经历挫折,乐观还是要一点
    • 但是白给的老好人不行,还是要有基础原则的
    • 可以出发点很低(一开始比较恶劣,自闭),为角色后续成长留下了空间
  • 强烈独特独立的个性魅力、个人行为准则坚定(10)
    • 额外固执但是专情
    • 病娇(特别爱一个人),想守护妹妹的想法
    • 厌世,缺爱
  • 角色剧情行事逐渐展示出来的
  • 真实感(反差,与观众拉近距离) (20)
    • 平时严酷,但也会含羞
    • 总是公正,但也会偏私
  • 悲剧色彩,激发了同情心(共情)(0~30)
    • 努力却依旧失败、正义行事却危机四伏、爱而不得、无所谓付出。一哭 +10
    • 美好的东西被摧毁总是令人扼腕痛心,令人印象深刻。+10
    • 失去美好的未来
    • 刀人:刀友情,刀亲情 +10
  • 共鸣?观众随角色一同成长(40)
    • 如果观众一开始有一样的疑惑,(10)
    • 然后和角色一起寻找答案 (10)
    • 最后坚定的相信自己找到的 (20)

举例

  • 星野爱(113)
  • 外貌(5):不是特别感冒的形象
  • 可爱俏皮(2)
  • 乐观性格(6):演出也有时迷茫,却为了孩子开朗了起来
  • 独特和自我(10): 厌世,缺爱让人同情
  • 真实感(20):以谎言编织的怀孕偶像,是最大的反差
  • 悲剧色彩(30):
    • 想学会爱,但是到死还在努力
    • 失去了与孩子们的未来
    • 刀母爱
  • 共鸣与成长(40)
    • 疑惑: 不会爱的人怎么办
    • 寻找:以谎言代替
    • 结论:谎言也是我努力传达爱意的方式。但唯独我爱你们,这句话……绝对不是谎言
  • 亚斯娜(100)
  • 外貌(15):理想的人妻
  • 可爱俏皮(5)
  • 乐观性格(10):理想的姐姐人妻性格,爱你管你又不太束缚你
  • 独特和自我(10): 为了Kirito 愿意牺牲自己
  • 真实感(20):平时严酷,但也会含羞
  • 悲剧色彩(10):
    • 刀爱情, 差一点失去Kirito
  • 共鸣与成长(30)
    • 疑惑: 在虚拟世界里,存在的意义是什么
    • 寻找:寻找虚拟世界“红莫罗”的东西
    • 结论:这份感情与相遇的经历是真实的(10,结论不够动容)
  • 爱莉希雅Elysia(125)
  • 外貌(15):理想的人妻2
  • 可爱俏皮(10) 与芽衣打情骂俏,甜齁了(摸角)。额外加分+5
  • 乐观性格(10):理想的姐姐人妻性格,
  • 独特和自我(10): 真我 ~ 人之律者
  • 真实感(20):平时严酷,但也会含羞(神之子却爱上了人类)
  • 悲剧色彩(30):
    • 出生无知的律者,努力爱人类,却不被理解
    • 反而为人类牺牲
    • 本世代对抗侵蚀之律者,最终数据还被删除
  • 共鸣与成长(30)
    • 疑惑: 凡事任凭心意而为,自由自在,与副首领的身份格格不入的往事乐土的少女是谁
    • 寻找:寻找前世的真相与少女的秘密
    • 结论:即使往事乐土不存在了,但只要这份记忆还在,你就永远还在。愿时光永驻此刻(10,结论不够动容)
  • 光与焰(120)
  • 外貌(15):两个人各有特点
  • 可爱俏皮(5)
  • 乐观性格(10):理想的姐姐人妻性格,
  • 独特和自我(10): 光傲娇 焰体贴
  • 真实感(25):光性格上与焰完全相反,非常要强,不擅长表达自己的感情,但本性其实很温柔,内心很脆弱。
    • 高质量CG的游戏,真实沉浸感额外加分+5
  • 悲剧色彩(20):
    • 被坏人利用,虽然不愿意,但是伤害了世界,
    • 喜欢lex,最后还是牺牲了自己(lex,你一个人也没关系了吧!)
  • 共鸣与成长(35)
    • 疑惑: 无意间结实的少女
    • 寻找:寻找世界的真相与少女的秘密
    • 结论:即使有前世的经历。但是愿意忘记悲伤的过去。从现在开始彼此守护(15,结论不够动容)
  • 评价模板
  • 外貌(15):理想的人妻
  • 可爱俏皮(5)
  • 乐观性格(10):理想的人妻性格
  • 独特和自我(10):
  • 真实感(20):
  • 悲剧色彩(30):
    • 失去了
  • 共鸣与成长(40)
    • 疑惑:
    • 寻找:
    • 结论:

需要进一步的研究学习

暂无

遇到的问题

暂无

开题缘由、总结、反思、吐槽~~

看了星野爱之后,我又emo了

参考文献

GccOnWin10

路线

MinGW

  • MinGW(Minimalist GNU for Windows),又称mingw32,是将GCC编译器和GNU Binutils移植到Win32平台下的产物,包括一系列头文件(Win32API)、库和可执行文件。
  • 另有可用于产生32位及64位Windows可执行文件的MinGW-w64项目,是从原本MinGW产生的分支。如今已经独立发展
  • 安装gcc
  • MinGW Installation Manager 中 勾选gcc/g++ make gdb 等项
  • 貌似只能安装在C盘(这很不好
  • 但是如果安装的是便携版的git bash,就没有上述程序。

MSYS2

  • MSYS2是一组工具和库,为您构建、安装和运行本机Windows软件提供了一个易于使用的环境。
  • 包括类似
  • 命令行终端mintty、bash、
  • git和Subversion 版本控制系统、
  • tar和awk 工具,
  • AutoTools 构建系统,
  • Pacman的包管理系统, 来提供包的轻松安装和保持更新的方式,Arch Linux用户应该很熟悉这个系统。
  • 强大的功能: 例如依赖项解析和简单的完整系统升级,以及直接和可重复的包构建
  • 程序包库包含2800多个准备安装的预构建程序包。
  • 所有这些都是基于Cygwin的修改版本。尽管其中一些核心部分是基于Cygwin的,但MSYS2的主要关注点是为本地Windows软件提供一个build环境,并将使用Cygwin的部分保持在最低限度。
  • MSYS2为GCC、Mingw-W64、CPython、CMake、Meson、openssl、FFmpeg、Rust、Ruby等提供了最新的native builds。

Clang and GDB using MSYS2

  • MSYS2 Installation
  • 图形化界面自定义安装路径
  • 打开MSYS2 MSYS安装软件
        # 更新包管理 输入Y继续
        pacman -Syu
        # 安装 UCRT(Universal C Runtime)  版本的 clang gdb
        pacman -S --needed base-devel mingw-w64-ucrt-x86_64-clang mingw-w64-ucrt-x86_64-gdb
    
  • VSCODE 添加到MSYS2 MinGW UCRT 64-bit终端的路径下。 CTRL+O CTRL+X 保存退出
    • bash cd ~ nano .bashrc export PATH=$PATH:/e/commonSoftware/Microsoft\ VS\ Code/bin
    • 终端里code .就能打开
  • 或者系统路径添加E:\commonSoftware\msys32\ucrt64\bin VSCODE 就能正常访问g++

无法识别库

存在红色波浪线, 插件clangd导致的

无法点击头文件跳转

  • 激活跳转
  • 安装C/C++插件
  • 设置includePath
  • Ctrl+Shift+P输入C/C++ 编辑配置
  • 添加E:\\commonSoftware\\msys32\\ucrt64\\include

需求

  • 笔记本有g++, 台式机没有
  • vscode能顺利识别调用,并且gdb
    D:\PowerShell> which g++
    /c/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/bin/g++
    

需要进一步的研究学习

暂无

遇到的问题

暂无

开题缘由、总结、反思、吐槽~~

  • 原本我从来不配置Windows的编译器的,直到服务器zfs挂壁了
  • 看来还是要靠自己~

参考文献

https://solarianprogrammer.com/2021/06/11/install-clang-windows-msys2-mingw-w64/

https://blog.csdn.net/m0_51429482/article/details/125191731

Personal Image Management

导言

作为理工男 + 大直男,几乎没有注意个人形象管理。但是这马上要毕业了,也到了要开始找对象的年龄。

也不期望变帅哥,至少能实现给人的初印象是干净开朗男生的感觉。

为此需要从多个角度,指出现有问题、理性分析原因、量化改进指标、持续跟踪状态。

Gem5

简介

  • GEM5是一款模块化的离散事件驱动全系统模拟器,由C++与python编写
  • 它结合了M5(多处理器模拟器)和GEMS(存储层次模拟器)中最优秀的部分,是一款高度可配置、集成多种ISA和多种CPU模型的体系结构模拟器。
  • M5是由Michigan大学开发的一款开源的多处理机模拟器,受到了业内的广泛关注,很多高水平论文都采用M5作为研究工具。
  • 另一方面,Wisconsin推出的GEMS能够对储存层次进行详细而灵活的模拟,包括对多种不同的cache一致性协议和互联模型的支持。
  • 目前的GEM5是M5和GEMS的一个紧耦合版本。
  • GEM5已经能够支持多种商用ISA,包括X86、ARM、ALPHA、MIPS、Power、SPARC等,并且能够在X86、ARM、ALPHA上加载操作系统。

可选配置(灵活性)

  • 灵活性是指gem5提供了多种CPU模型、系统模型以及存储器模型。
  • CPU模型:Atomic、Timing、In-order、O3(Out of Order)
    • AtomicSimple是最简单规模的模型,一个cycle完成一条指令的执行,memory 模型比较理想化,访存操作为原子性操作。适用于快速功能模拟。
    • TimingSimple模拟器也是无流水线的模拟,但是使用了存储器访问时序模型,用以统计存储器访问延迟。
    • In-Order模型是GEM5模拟的新特性,强调指令时序与仿真精度,流水级为默认五级流水:取值、译码、执行、访存、写回。并且模拟了cache部件、执行部件、分支预测部件等。
    • O3模拟器是流水级模拟,O3模拟器模拟了乱序执行和超标量执行的指令间依赖,以及运行在多CPU上的并发执行的多线程。
    • 默认7级流水:取值、译码、重命名、发射、执行、写回、提交。
    • 模拟了物理寄存器文件、IO、LSQ、ROB功能部件池等。
    • 主要参数为流水管道间延迟、硬件线程数、IQ/LSQ/ROB项数、FU延迟、物理寄存器重命名、分支预测、访存依赖预测等。
  • 系统模型:SE(System-call emulation)、FS(Full System)。
  • 存储模型:Classic、Ruby。
    • M5的Classic mode存储器是最简单的模型,它提供了简洁快速的可配置性。
    • GEMS的Ruby模型注重于精确度并且支持不同的cache一致性协议。
    • Ruby存储模型支持庞大阵列的互联拓扑,包括两个不同的网络模型:Simple网络与Garnet网络。
      • Simple网络对链路、路由延迟与链路带宽进行建模,但并不建模路由资源竞争与流控。
      • Garnet网络详细建模路由微架构,包括所有相关的资源竞争与流控时序。

基本模式

  • System Call Emulation (SE) Mode
  • In this mode, one only needs to specify the binary file to be simulated. This binary file can be statically/dynamically linked.
  • full-system mode
  • This mode simulates a complete system which provides an operating system based simulation environment.
  • very slow, rendering it impractical for deployment in real-world applications.
time ./build/ARM/gem5.fast configs/example/se.py --cmd=/home/shaojiemike/test/llvmVSgem5/MV/MV_gem5 -n 32 --cpu-type=O3CPU --l1d_size=64kB --l1i_size=16kB --caches
  • L1d cache是每个核单独64KB(原因见后图)。但其实默认cache结构是L2共享的

安装

  • 在源目录下运行scons build/<config>/<binary> 建立模拟器。
  • <config> gem5的配置文件,如ARMX86
  • <binary> 模拟器的类型,有如下
    • gem5.debug 有关闭了优化,使gdb一类的工具更易于调试;
    • gem5.opt有打开优化,但保留了调试输出和断言;
    • gem5.fast去除了调试工具;
    • gem5.prof用于与gprof共同使用
scons build/ARM/gem5.fast --debug=presub --verbose -j 32

输入参数

gem5 安装的默认配置

可选选项在./build/ARM/gem5.fast configs/example/se.py -h或者 configs/common/Options.py 中查看

常规的配置:

  • 多级cache
  • CPU
  • 频率,核数
  • 指令发射宽度
    • commitWidth, decodeWidth, dispatchWidth, fetchWidth, issueWidth,
    • renameWidth, squashWidth, wbWidth ,
  • 端口模型的部件类型以及个数
  • 内存

cache設置

  • 只指定大小是沒用的,需要在L1cache 前加上 “--caches”,在l2cache前加上 “--l2cache“。命令結果類似
  • 默认cache是没有开硬件预取HWP的,类型通过--list-hwp-types查看。可以指定L1L2cache的HWP类型,如--l1d-hwp-type=TaggedPrefetcher
build/X86/gem5.opt configs/example/se.py 
  --caches --l1d_size=32kB --l1i_size=32kB 
  --l2cache --l2_size=256kB 
  --l3_size=8192kB  # l3 在 se里是不生效的
  -c tests/test-progs/hello/bin/x86/linux/hello 

# 建议将L3大小并入L2来模拟cycle的下限
build/X86/gem5.opt configs/example/se.py 
  --caches --l1d_size=32kB --l1i_size=32kB 
  --l2cache --l2_size=256kB+8192kB
  -c tests/test-progs/hello/bin/x86/linux/hello

进阶配置:

  1. 多核模拟时,配置独占cache
  2. 增加共享L3
  3. 添加共享的L3cache,并将L2cache改为独立的

输出文件

运行完SE模式,默认会在指令路径下生成m5out文件夹,其中各文件大致含义如下:

  • config.ini或者config.json 运行指令的系统参数
  • Contains a list of every SimObject created for the simulation and the values for its parameters.
  • json格式的文件能比较好的理清config的重要设置
  • [system.cpu] 有CPU的具体设置
  • [system.mem_ctrls.dram] 有DRAM读取数据的具体设置
  • [system.membus] BUS的相关设置
  • stats.txt 模拟结果数据(具体的周期数等)
  • A text representation of all of the gem5 statistics registered for the simulation.
  • system.clk_domain.clock 1000 # Clock period in ticks (Tick)
  • system.cpu_clk_domain.clock 500 # Clock period in ticks (Tick)
  • fs/proc/lscpu 模拟系统配置(类似lscpu)
  • config.dot.* 模拟的系统结构
  • config.dot 是以文字展示
  • config.dot.pdfconfig.dot.svg 都是以图片表示aliyuncs1
  • config.dot.svg 能展示每个部件的细节参数 aliyuncs2

运行

参考博客, 如果se.py無法滿足要求,可以自己編寫脚本

CPU参数解释

各阶段发射宽度

commitWidth, decodeWidth, dispatchWidth, fetchWidth, issueWidth, renameWidth, squashWidth, wbWidth

下面是行数占比最大的几个部分

branchPred

  • BTBEntries

decoder

fuPool

  • fuction pool 类似乱序执行的端口模型,ARM下的O3模拟的fuPool如下 ARM-O3-fuPool

gem5 模拟器误差来源分析

运行真实周期数

  • 使用perf stat test.exe, 可参考本博客perf文章

需要进一步的研究学习

暂无

遇到的问题

暂无

开题缘由、总结、反思、吐槽~~

参考文献

https://blog.csdn.net/ivy_reny/category_6666068.html

https://blog.csdn.net/wyj7260/category_1301132.html

Synology terminal

配置开机启动项

编写脚本/var/services/homes/shaojiemike/wgReboot.sh

#!/bin/bash
ip ro add default via 222.195.90.254 dev eth0 table eth0-table
ip ro a 114.214.233.0/24 via 222.195.90.254 dev eth0  src 222.195.90.2 table main
wg-quick up wg1
ip ro d default via 222.195.90.254 dev eth0  src 222.195.90.2 table main
  • 执行权限chmod +x
  • 群晖WebUI -> 控制面板 -> 任务计划 -> 新增 -> 触发的任务
  • 选择Root、开机事件
  • bash /var/services/homes/shaojiemike/wgReboot.sh

需要进一步的研究学习

暂无

遇到的问题

暂无

开题缘由、总结、反思、吐槽~~

参考文献

Reboot Task

最简单/etc/rc.lo­cal

默认是不开启的,文件/etc/rc.lo­cal默认也不存在

开启/etc/rc.lo­cal功能

  • ubuntu18.04不再使用initd管理系统,改用systemd
  • systemd有rc-local的配置文件,只需链接到/etc/systemd/system目录下启动即可
  • ln -fs /lib/systemd/system/rc-local.service /etc/systemd/system/rc-local.service

使用/etc/rc.lo­cal功能

touch /etc/rc.local
chmod 755 /etc/rc.local
vim /etc/rc.local
    eg. #!/bin/bash  echo "test rc " > /var/test.log

crontab @reboot

crontab -e
@reboot /home/user/test.sh

initd 启动管理系统

  • init.d目录包含许多系统各种服务的启动和停止脚本。它控制着所有从acpid到x11-common的各种事务。
  • 注意:ubuntu18.04不再使用initd管理系统,改用systemd

编写脚本

  • /etc/init.d目录下建立文件test
  • 按照README编写脚本
  • 赋予执行权限sudo chmod +x /etc/init.d/test

设置脚本启动

方法一:使用update-rc.d 命令将脚本放到启动脚本中去(debian中可以使用更新的insserv):

$ cd /etc/init.d
$ sudo update-rc.d test defaults 95

注:其中数字95是脚本启动的顺序号,按照自己的需要相应修改即可。在你有多个启动脚本,而它们之间又有先后启动的依赖关系时你就知道这个数字的具体作用了。更多说明建议看man update-rc.d。

方法二:手动在rc*.d中建立软连接

$ ls -s test ../rc5.d/S95test

rc*.d,*代表启动级别,在不同启动级别启动, K开头的脚本文件代表运行级别加载时需要关闭的, S开头的代表相应级别启动时需要执行, 数字代表顺序

卸载启动脚本的方法:

$ cd /etc/init.d
$ sudo update-rc.d -f test remove

手动调用脚本

/etc/init.d/test start
/etc/init.d/test stop
/etc/init.d/test restart

systemd 服务管理系统

使用sudo systemctl enable xxx

systemctl is-enabled servicename.service #查询服务是否开机启动
systemctl enable *.service #开机运行服务
systemctl disable *.service #取消开机运行
systemctl start *.service #启动服务
systemctl stop *.service #停止服务
systemctl restart *.service #重启服务
systemctl reload *.service #重新加载服务配置文件
systemctl status *.service #查询服务运行状态
systemctl --failed #显示启动失败的服务

systemctl 开机启动原理

  • Systemd 默认从目录/etc/systemd/system/读取配置文件。
  • 但是,里面存放的大部分文件都是符号链接,指向目录
  • /usr/lib/systemd/system/,真正的配置文件存放在那个目录。

systemctl enable命令用于在上面两个目录之间,建立符号链接关系。

> $ sudo systemctl enable [email protected]
# 等同于
$ sudo ln -s '/usr/lib/systemd/system/[email protected]' '/etc/systemd/system/multi-user.target.wants/[email protected]'
> 
* 如果配置文件里面设置了开机启动,systemctl enable命令相当于激活开机启动。 * 与之对应的,systemctl disable命令用于在两个目录之间,撤销符号链接关系,相当于撤销开机启动。
> $ sudo systemctl disable [email protected]
> 
* 配置文件的后缀名,就是该 Unit 的种类,比如sshd.socket。 * 如果省略,Systemd 默认后缀名为.service,所以sshd会被理解成sshd.service

把程序设置systemctl服务,并开机启动

进入目录/usr/lib/systemd/system,修改webhook.service

[Unit]
Description=Webhook receiver for GitHub

[Service]
Type=simple
ExecStart=/usr/local/bin/webhook

[Install]
WantedBy=multi-user.target
这里有几个模块: * [Unit] 区块:启动顺序与依赖关系。 * [Service] 区块:启动行为,如何启动,启动类型。 * [Install] 区块,定义如何安装这个配置文件,即怎样做到开机启动。

systemctl start nexus.service  #启动服务
systemctl enable nexus.service #设置开机启动
Loaded: loaded (/etc/systemd/system/webhook.service; enabled;这个enabled就是开机启动的意思

需要进一步的研究学习

暂无

遇到的问题

暂无

开题缘由、总结、反思、吐槽~~

参考文献

https://neucrack.com/p/91