WSL

WSL安装Ubuntu

  • 来源

    • 直接在微软商店安装ubuntu即可
  • 迁移

    • 由于默认安装到C盘下的C:\Users\<username>\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu<version>onWindows_<code>目录下,所以最好进行迁移

    • 迁移步骤:

      1. 查看系统:wsl -l -v
      2. 导出指定系统到指定位置:wsl --export <Name> <目标压缩包绝对路径>,例如wsl --export Ubuntu d:\ubuntu.tar
      3. 卸载当前版本:wsl --unregister <Name>
      4. 重新导入:wsl --import <NewName> <TargetPath> <目标压缩包位置> --version <WSL版本>,例如wsl --import Ubuntu F:\Linux\ubuntu D:\Ubuntu.tar --version 2
      5. 设置默认登录用户(否则为root):<系统Name> config --default-user <username>

      然后可以彻底删除微软商店下载的ubuntu app

  • 配置apt-get的镜像:

    1. 管理员身份进入:cd /etc/apt

    2. 备份自带的源:cp sources.list sources.list.bak

    3. 修改源配置:vim sources.list

    4. 替换内容为阿里云的源:

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
      deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
      deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
      deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
      deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
      deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
      deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
      deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
      deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
      deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
    5. 更新软件列表:apt-get update

    6. 升级:apt-get upgrade

配置SSH到外层主机

  • 安装openssh-server

    1. 最好先移除先前的版本:apt remove openssh-server

    2. 安装:apt install openssh-server

    3. 修改配置信息:vim /etc/ssh/sshd_config

    4. 配置相关信息:

      1
      2
      3
      4
      Port 2222                   # 监听的端口,可以是其它的
      ListenAddress 0.0.0.0 # 0.0.0.0 表示所有的地址
      PasswordAuthentication yes # 把原来的no改成yes,意思是可以用密码登录
      PermitRootLogin yes # 把原来的prohibit-password改成yes
    5. 重启ssh服务:service ssh restart

  • 连接

    • 在cmd或PowerShell:ssh <子系统内用户名>@localhost -p <端口>,例如ssh taoyyz@localhost -p 2222
  • 此时可以直接通过访问本机的2222端口ssh到WSL内的Ubuntu系统

参考自CSDN:SSH连接WSL2踩坑记录与增加端口转换规则,实现外网与WSL2的连接

系统服务操作

适用与 Linux 的 Windows 的子系统(WSL) 默认情况下是无法使用 systemctl 命令,使用该命令 WSL 将抛出如下错误。

System has not been booted with systemd as init system (PID 1). Can’t operate.

image-20230703143944594

参考自CSDN:WSL 错误 System has not been booted with systemd as init system (PID 1). Can‘t operate

切换dash与bash

  • 区别:
    • dash:全称Debian Almquist Shell,它主要是为了执行脚本而出现,而不是交互,它速度更快,但功能相比bash要少很多,语法严格遵守POSIX标准。
    • bash:全称GNU Bourne-Again Shell
  • 查看当前系统的shell解释器:
    • ls -l /bin/sh
      • 输出/bin/sh -> dash为dash
      • 否则输出/bin/sh -> /bin/bash为bash
  • 切换解释器:
    • 切换为bash:sudo ln -fs /bin/bash /bin/sh
    • 切换为dash:sudo ln -fs /bin/dash /bin/sh

性能与优化

  • 开启systemctl
  • 开机自启WSL
  • 设置WSL的cpu和内存(默认全核心以及一半的物理机内存)

参考自CSDN:使用WSL2必看的配置优化

设置frp

  • 后台运行:windows下也可以使用nohup &包裹启动frp的命令
  • 查看运行的nohup:jobs -l
  • 关闭frp,也可以通过任务管理器中进程名称为frpc.exe

我的当前frp配置

  • 服务端:http://116.63.171.90
    • 通信端口:7000
    • 管理台端口:7002,使用http://116.63.171.90:7002访问
      • 用户名:admin
      • 密码:qwer2222
  • 客户端:
    • 已开设的端口转发:
      • c2222 -> s2222:ssh
      • c2223 -> s99:nginx
      • c9000 -> s9000:portainer
  • 端口转发个人规则:
    • 端口从99设置为nginx用
      • 后端转发:
        • 通过远程ip:99/back_端口即可访问指定端口的后端服务
    • 端口从100开始:
      • 100:redis
      • 101:mysql
      • 9000:portainer
        • 用户名:admin
        • 密码:3344520tjjTJJ

已运行的个人服务

mysql

  • 运行命令

    1
    2
    3
    4
    5
    6
    7
    8
    9
    docker run \
    --name mysql_tjj \
    -e MYSQL_ROOT_PASSWORD=taoyyz@028hhh \
    -p 101:3306 \
    -v /home/taoyyz/software/docker/mysql/conf/hmy.cnf:/etc/mysql/conf.d/hmy.cnf \
    -v /home/taoyyz/software/docker/mysql/logs:/var/log/mysql \
    -v /home/taoyyz/software/docker/mysql/data:/var/lib/mysql \
    -e TZ=Asia/Shanghai \
    -d mysql:latest

redis

  • 运行命令

    1
    2
    3
    4
    5
    6
    7
    docker run  \
    -p 100:6379 \
    --name redis_tjj \
    -v /home/taoyyz/software/docker/redis/redis.conf:/etc/redis/redis.conf \
    -v /home/taoyyz/software/docker/redis/data:/data \
    -d redis:latest \
    redis-server /etc/redis/redis.conf

portainer

  • 运行命令

    1
    2
    3
    4
    docker run -d --name portainer_zh_tjj -p 9000:9000 --restart=always \
    -v /var/run/docker.sock:/var/run/docker.sock \
    -v /home/taoyyz/software/docker/portainer-zh/data:/data \
    6053537/portainer-ce

Redis性能测试

redis-benchmark

  • 帮助
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
[root@redis-test-slave ~ ]$ redis-benchmark --help
Usage: redis-benchmark [-h <host>] [-p <port>] [-c <clients>] [-n <requests]> [-k <boolean>]

-h <hostname> Server hostname (default 127.0.0.1)
-p <port> Server port (default 6379)
-s <socket> Server socket (overrides host and port)
-a <password> Password for Redis Auth
-c <clients> Number of parallel connections (default 50)
-n <requests> Total number of requests (default 100000)
-d <size> Data size of SET/GET value in bytes (default 2)
--dbnum <db> SELECT the specified db number (default 0)
-k <boolean> 1=keep alive 0=reconnect (default 1)
-r <keyspacelen> Use random keys for SET/GET/INCR, random values for SADD
Using this option the benchmark will expand the string __rand_int__
inside an argument with a 12 digits number in the specified range
from 0 to keyspacelen-1. The substitution changes every time a command
is executed. Default tests use this to hit random keys in the
specified range.
-P <numreq> Pipeline <numreq> requests. Default 1 (no pipeline).
-e If server replies with errors, show them on stdout.
(no more than 1 error per second is displayed)
-q Quiet. Just show query/sec values
--csv Output in CSV format
-l Loop. Run the tests forever
-t <tests> Only run the comma separated list of tests. The test
names are the same as the ones produced as output.
-I Idle mode. Just open N idle connections and wait.

  • 案例
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
Examples:

Run the benchmark with the default configuration against 127.0.0.1:6379:
# 运行默认配置下的测试
$ redis-benchmark

Use 20 parallel clients, for a total of 100k requests, against 192.168.1.1:
# 指定并发数20,总请求数为10W,redis server主机IP为192.168.1.1
$ redis-benchmark -h 192.168.1.1 -p 6379 -n 100000 -c 20

Fill 127.0.0.1:6379 with about 1 million keys only using the SET test:
# 测试SET随机数性能
$ redis-benchmark -t set -n 1000000 -r 100000000

Benchmark 127.0.0.1:6379 for a few commands producing CSV output:
# 测试结果输出到csv
$ redis-benchmark -t ping,set,get -n 100000 --csv

Benchmark a specific command line:
# 执行特定命令下的测试
$ redis-benchmark -r 10000 -n 10000 eval 'return redis.call("ping")' 0

Fill a list with 10000 random elements:
# 测试list入队的速度
$ redis-benchmark -r 10000 -n 10000 lpush mylist __rand_int__

On user specified command lines __rand_int__ is replaced with a random integer
with a range of values selected by the -r option.
  • 浅玩了一下

    • 本地docker内直接运行redis-benchmark -t set -n 1000000 -r 100000000 -a taoyyz@028hhh,大约27w/s,平均响应时间0.11ms,最大响应时间3ms

      1
      2
      3
      4
      5
      Summary:
      throughput summary: 270051.31 requests per second
      latency summary (msec):
      avg min p50 p95 p99 max
      0.112 0.032 0.103 0.183 0.271 3.191
    • 服务器远程调用,大约1500rps,平均响应时间32ms

      1
      2
      3
      4
      5
      Summary:
      throughput summary: 1503.56 requests per second
      latency summary (msec):
      avg min p50 p95 p99 max
      33.243 28.736 32.543 37.471 47.615 264.703

安装Xshell

安装包

  • Xshell安装包已经下载到我的E:\破解软件\XshellPlus - 7.rar
  • 云盘:XshellPlus - 7.rar
  • 安装方法:运行内部的bat脚本即可破解安装

可能出现的问题

  • 由于找不到MSVCP110.dll,无法继续执行代码
    • 原因:需要vc++的库
    • 解决方法:下载vc++相关的库
    • 库名称:Visual C++ Redistributable for Visual Studio 2012 Update 4
    • 链接:Surface运行库下载
  • 踩坑:点击下载后,可选择x86、x64、arm的exe文件,但我只装了x64还不够,还同时需要装x86的库
  • 安装包位置:已下载到E:\破解软件\vc运行时库
  • 参考了CSDN:xshell运行报错:由于找不到msvcr110.dll 无法继续执行

Git配置

给Git配置代理

当前项目的仓库

给Git当前项目的本地仓库配置代理

  • HTTP代理:

    1
    2
    git config http.proxy 'http://127.0.0.1:10809'
    git config https.proxy 'https://127.0.0.1:10809'
  • SOCKS5代理:

    1
    2
    git config http.proxy 'socks5://127.0.0.1:10808'
    git config https.proxy 'socks5://127.0.0.1:10808'

取消当前项目的Git本地仓库的代理配置

1
2
git config --unset http.proxy
git config --unset https.proxy

全局仓库

给Git全局仓库配置代理

  • HTTP代理:

    1
    2
    git config --global http.proxy 'http://127.0.0.1:10809'
    git config --global https.proxy 'https://127.0.0.1:10809'
  • SOCKS5代理:

    1
    2
    git config --global http.proxy 'socks5://127.0.0.1:10808'
    git config --global https.proxy 'socks5://127.0.0.1:10808'

取消全局仓库的代理配置

1
2
git config --global --unset http.proxy
git config --global --unset https.proxy

查看Git配置

查看当前Git仓库的配置

1
git config --list

查看全局配置

1
git config --list --global

安装Miniconda

Linux下

  1. Miniconda官网下载对应系统的sh脚本

  2. 下载完成后,把sh脚本放到任意位置,然后执行以下命令添加执行权限并执行:

    1
    2
    chmod 777 Miniconda3-latest-Linux-x86_64.sh
    sh Miniconda3-latest-Linux-x86_64.sh
  3. 一路回车,注意有些地方需要输入yes

  4. 安装完成后,~目录应该会有.condarc,并且~目录的.bashrc最后应该会有miniconda的路径

  5. 此时执行conda -v查看,如果命令没有找到,执行source ~/.bashrc使配置立即生效

  6. 出现PackagesNotFoundError: The following packages are missing from the target environment等问题,可能是源不正确,尝试:conda config --remove-key channels

参考了此链接

windows下

  1. 同样的,在miniconda官网下载安装包

  2. 下载完成后打开安装程序,过程中取消勾选了为当前用户安装(不推荐)

    • 为所有用户安装后,可能需要自己配置环境变量,在环境变量中配置如下内容:

      • 一个名为MINI_CONDA_HOME的系统变量

      • Path变量中,分别添加以下几条:

        1
        2
        3
        4
        5
        %MINI_CONDA_HOME%
        %MINI_CONDA_HOME%\Library\mingw-w64\bin
        %MINI_CONDA_HOME%\Library\usr\bin
        %MINI_CONDA_HOME%\Library\bin
        %MINI_CONDA_HOME%\Scripts

        Windwos下会把Python和一些pip安装的包,映射为exe程序。所以依赖scripts文件夹

    • 此时,在CMD中输入conda应该可以访问到Miniconda的程序

      • 由于为所有用户安装,导致环境和包会默认下载到C:\Users\当前用户\.conda文件夹中

      • 需要修改(没有则创建)C:\Users\当前用户\.condarc文件,并填写内容:

        1
        2
        envs_dirs:
        - D:\env\miniconda3\envs
      • 此时仍然可能未生效,最好在创建环境时,使用绝对路径:

        1
        2
        3
        conda create --prefix 目标环境文件夹的绝对路径 python=版本
        # 例如:conda create --prefix D:\env\miniconda3\envs\py3.8 python=3.8
        # 上述将创建一个3.8版本的Python环境到D盘环境的py3.8中去

常用操作

  • 列举环境:conda env list
  • 搜索包:conda search 包名
  • 创建环境:conda create -n 环境名 python=版本号
  • 切换环境:conda activate 环境名
  • 退出环境:conda deactivate
  • 查看pip包安装位置和其他信息:pip show 包名

安装homeassistant

环境:

  • 安装homeassistant2023.8.4需要Python3.11版本,使用conda创建python3.11版本环境并切换

  • 安装homeassistant需要的一些依赖:

    • pip3 install home-assistant-frontend,核心依赖,缺少会导致启动一大堆报错

      参考自社区

    • pip3 install pycountry,国家地图依赖

    • pip3 install webrtcvad,核心依赖,缺少会导致cloud、mobile-app等一堆报错

      参考自社区

    • pip3 install homeassistant==2023.8.4,homeassistant自身

  • 运行hass启动homeassistant服务

  • 访问localhost:8123即可

CMD操作

  • 切换盘符:盘符:,例如切换到D盘:d:回车即可
  • 查看当前文件夹内容:dir
  • 查看命令所在位置:where 命令
------ 本文结束,感谢您的阅读 ------
看的开心的话可以请我喝杯奶茶~热狗也行呜呜呜
支付宝
微信