📚 我的文章

Mamba替代Conda

mamba是一个conda的替代品,可以加速conda的包管理,提升包管理的效率。

安装 #

brew install micromamba

配置 #

# 根据命令提示,修改~/.zshrc文件
micromamba shell init -s zsh -p ~/.micromamba
# 添加配置文件
$ cat ~/.mambarc
channels:
  - conda-forge
always_yes: false

使用 #

micromamba create -n python310 python=3.10
# 激活环境
micromamba activate python310
# 然后可以用 micromamba 或者 pip 装东西
micromamba install package_1 package_2=version
## 具体请参考 https://mamba.readthedocs.io/en/latest/
micromamba --help

Hugo网站建设

安装 Hugo #

下载地址:https://github.com/gohugoio/hugo/releases

创建网站 #

hugo new site book
cd book
git init
git submodule add https://github.com/alex-shpak/hugo-book themes/hugo-book

本地调试 #

hugo server --disableFastRender --minify --ignoreCache

github actions #

mkdir -p .github/workflows
touch .github/workflows/build.yml
name: Build
on:
  push:
    branches:
      - main # Set a branch to deploy
  pull_request:

jobs:
  deploy:
    runs-on: ubuntu-20.04
    concurrency:
      group: ${{ github.workflow }}-${{ github.ref }}
    steps:
      - uses: actions/checkout@v3
        with:
          submodules: true # Fetch Hugo themes (true OR recursive)
          fetch-depth: 0 # Fetch all history for .GitInfo and .Lastmod

      - name: Setup Hugo
        uses: peaceiris/actions-hugo@v2
        with:
          hugo-version: '0.123.7'
          # 是否启用 hugo extend
          extended: true

      - name: Build
        run: hugo --minify

      - name: Deploy
        uses: peaceiris/actions-gh-pages@v3
        if: ${{ github.ref == 'refs/heads/main' }}
        with:
          github_token: ${{ secrets.GH_PAGE_ACTION_TOKEN }}
          publish_dir: ./public

github pages #

可以在项目的 Settings 中开启 Pages 服务,然后选择 Branch 为gh-pages即可。
如果想要定制域名,可以参考官方文档 About custom domains and GitHub Pages

...

FFmpeg检测透明通道

检测透明通道 #

FFmpeg命令 #

$ ffmpeg -v error -i 123.mp4 -vf "select='eq(n,0)', alphaextract" -f null /dev/null

[Parsed_alphaextract_1 @ 0x7fe8f5208100] Requested planes not available.
[Parsed_alphaextract_1 @ 0x7fe8f5208100] Failed to configure input pad on Parsed_alphaextract_1
[vf#0:0 @ 0x7fe8f5005f40] Error reinitializing filters!
Failed to inject frame into filter network: Invalid argument
Error while filtering: Invalid argument
[out#0/null @ 0x7fe8f5004900] Nothing was written into output file, because at least one of its streams received no packets.

判断条件 #

如果出现以上报错信息,则说明视频中没有透明通道。

...

ssh客户端于服务端保持连接

linux ssh 默认没有开启心跳,所以很容易导致连接断开。

服务端设置 #

sudo vim /etc/ssh/sshd_config

TCPKeepAlive yes
ClientAliveInterval 60
ClientAliveCountMax 3

客户端设置 #

一般还是建议在客户端设置。

sudo vim /etc/ssh/ssh_config

TCPKeepAlive yes
ServerAliveInterval 60
ServerAliveCountMax 3

Centos7系统升级内核版本

使用ELRepo仓库升级系统内核

查看内核版本 #

uname -r

uname -a

cat /etc/redhat-release

安装ELRepo yum源 #

rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm

查看可用的内核版本 #

yum --disablerepo="*" --enablerepo="elrepo-kernel" list available

...
kernel-lt.x86_64              4.4.155-1.el7.elrepo
kernel-lt-devel.x86_64        4.4.155-1.el7.elrepo
...

安装稳定版本内核 #

yum --enablerepo=elrepo-kernel install kernel-lt

设置引导(grub2) #

查看所有内核版本 #

sudo awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg

0 : CentOS Linux (4.4.241-1.el7.elrepo.x86_64) 7 (Core)
1 : CentOS Linux (3.10.0-957.el7.x86_64) 7 (Core)
2 : CentOS Linux (0-rescue-651e1b90bb3149809cdeb8cc80e72c43) 7 (Core)

设置新的默认引导的内核版本 #

方法1

...

dnsmasq安装与配置

dnsmasq是一个小巧且方便地用于配置DNS和DHCP的工具,适用于小型网络,它提供了DNS功能和可选择的DHCP功能。

安装服务 #

sudo yum install dnsmasq

常用配置 #

cat /etc/dnsmasq.conf

#######这里表示 严格按照 resolv-file 文件中的顺序从上到下进行 DNS 解析, 直到第一个成功解析成功为止
#strict-order

###同时发送所有的查询到所有的dns服务器,谁快就用谁
all-servers

listen-address=127.0.0.1

###不让dnsmasq去读/etc/hosts文件
no-hosts

## 设置缓存条目
cache-size=10240

#允许客户端缓存的时间单位为秒
local-ttl=10
max-cache-ttl=15

###开启日志
#log-queries
##配置日志文件
#log-facility=/data/logs/dnsmasq.log
cat /etc/resolv.dnsmasq.conf

nameserver 223.5.5.5
nameserver 114.114.114.114
nameserver 222.246.129.80

启动服务 #

systemctl start dnsmasq

验证方法 #

dig www.zhangwenbing.com

其他配置 #

国内指定DNS #

server=/cn/114.114.114.114
server=/taobao.com/114.114.114.114
server=/taobaocdn.com/114.114.114.114

国外指定DNS #

server=/google.com/8.8.8.8

屏蔽网页广告 #

address=/ad.youku.com/127.0.0.1
address=/ad.iqiyi.com/127.0.0.1

其他功能 #

除了DNS,还支持DHCP和TFTP,由于暂时用不到,这里就不一一例举了。

...

使用ssh配置跳板机

简单的修改/etc/ssh/ssh_config文件即可通过跳板机,直达目标服务器。

配置方法 #

cat /etc/ssh/ssh_config

Host jump-server
    User xxxx
    Hostname yyy.yyy.yyy.yyy
    Port 22

Host 10.*
    ProxyCommand ssh -q -W %h:%p jump-server

Host 支持通配符 *?

...

centos6镜像站停止维护的解决办法

2020年11月30日 centos6各大开源镜像站已经停止维护了,但是阿里云还有其他源可以使用。

错误提示 #

 http://mirrors.aliyun.com/epel/6/x86_64/repodata/repomd.xml: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 404 Not Found"

解决办法 #

cat /etc/yum.repos.d/CentOS-Base.repo

# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-6.10 - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos-vault/6.10/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-6

#released updates
[updates]
name=CentOS-6.10 - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos-vault/6.10/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-6

#additional packages that may be useful
[extras]
name=CentOS-6.10 - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos-vault/6.10/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-6

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-6.10 - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos-vault/6.10/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-6

#contrib - packages by Centos Users
[contrib]
name=CentOS-6.10 - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos-vault/6.10/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-6
yum clean all
yum makecache

ffmpeg规范音频的响度

通过FFmpeg内置滤镜、手动调整音量、或者ffmpeg-normalize实现对响度的控制。

内置归一化滤波器 #

loudnorm:通过EBU R.128进行响度标准化。您可以设置积分的体积目标,体积范围目标或最大真实峰。建议用于发布音频和视频,并被世界各地的广播公司使用。

...

tcpdump之UDP抓包

使用tcpdump抓UDP包,过滤过滤IP和port,并且自动拆分片段。

安装tcpdump #

yum install -y tcpdump

使用方法 #

tcpdump -i bond0 udp port xxxx and host xxx.x.xx.xxx -s0 -G 600  -w %Y_%m%d_%H%M_%S.pcap

参数说明 #

-i 指定监听的网卡

...