ubuntu setup

创建用户

1
2
3
4
5
6
7
8
# 添加 group
$ groupadd {groupname}
# 添加用户
$ useradd -d /home/{username} -m -s /bin/bash -g {username} {groupname}
# 添加 sudo
$ sudo usermod -aG sudo {username}
# 设置密码
$ sudo passwd {username}

示例

1
2
3
4
groupadd wii
useradd -d /home/wii -m -s /bin/bash -g wii wii
sudo usermod -aG sudo wii
sudo passwd wii

sudo 权限无需密码

1
2
$ visudo
<username> ALL=(ALL) NOPASSWD: ALL

设置时区

timedatectl

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# 查看当前时区信息
$ timedatectl
Local time: 一 2023-06-26 16:21:01 CST
Universal time: 一 2023-06-26 08:21:01 UTC
RTC time: 一 2023-06-26 08:21:01
Time zone: Asia/Shanghai (CST, +0800)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
# 查看所有可配置的时区名称
$ timedatectl list-timezones
Africa/Abidjan
Africa/Accra
Africa/Addis_Ababa
Africa/Algiers
Africa/Asmara
Africa/Asmera
Africa/Bamako
Africa/Bangui
Africa/Banjul
Africa/Bissau
...
# 设置时区
$ sudo timedatectl set-timezone Asia/Shanghai

tzselect

临时需改时区,重启后失效。

1
$ tzselect

安装依赖

1
2
3
4
$ git clone https://github.com/sunzhenkai/env-init.git
$ cd env-init && ./activate
$ source ~/.bashrc
$ ii ubuntu -c

生成 ssh key

1
$ ssh-keygen -t ed25519 -C "your_email@example.com"
1
ssh-keygen -t ed25519 -C "zhenkai.sun@qq.com"

network - use wifi adapter

360 随身 wifi 1 代

驱动

这里这里

1
2
3
4
$ lsusb
...
Bus 001 Device 003: ID 148f:760b Ralink Technology, Corp. MT7601U Wireless Adapter
...

安装驱动

1
2
3
4
5
6
7
sudo apt install git dkms
git clone https://github.com/jeremyb31/mt7601u-5.4.git
sudo dkms add ./mt7601u-5.4
sudo dkms install mt7601u/1.0

# 重启
sudo reboot

360 随身 wifi 2 代

驱动

这里

k8s problems

Pod 无法解析域名

Pod DNS 策略模式是 ClusterFirst,系统 /etc/resolve.conf 内容如下。

1
2
3
nameserver 127.0.0.53
options edns0 trust-ad
search .

导致 Pod 里面的 /etc/resolv.conf 配置也是如此,无法正常解析域名。先删除 /etc/resolv.conf/run/systemd/resolve/stub-resolv.conf 的软链) ,再创建并写入如下内容。

1
2
nameserver 223.5.5.5
nameserver 8.8.8.8
1
2
sudo rm /etc/resolv.conf
sudo vim /etc/resolv.conf

重启 Pods。

1
kubectl delete pods --all -n=<namespace> # 删除所有 pods

pod didn’t trigger scale-up

错误信息

1
.. (combined from similar events): pod didn't trigger scale-up (it wouldn't fit if a new node is added): 2 Insufficient memory, 7 can't increase node group size

原因

  • pod 添加的 container 的内存、CPU 资源超过资源池机器的限制,导致无法扩容

解决

  • 减少 container 的 memory / cpu

Core Dump 及保存

设置 core dump 保存路径及命名

deployment.yaml 中配置,运行命令 echo "core.%p" > /proc/sys/kernel/core_pattern

映射 HostPath,容器重启不删除文件。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# deployment.yaml
spec:
template:
spec:
volumes:
- name: core-dump-volume
hostPath:
path: /data/core
type: DirectoryOrCreate
containers:
- name: {container-name}
volumeMounts:
- name: core-dump-volume
mountPath: /data/core

install python from source

从源码安装 Python3

设置版本

1
2
export PYTHON_VERSION=3.9.13
export PYTHON_MAJOR=3

下载

1
2
3
wget https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tgz
tar -xvzf Python-${PYTHON_VERSION}.tgz --no-check-certificate
cd Python-${PYTHON_VERSION}

配置

1
2
3
4
5
6
./configure \
--prefix=/opt/python/${PYTHON_VERSION} \
--enable-shared \
--enable-ipv6 \
LDFLAGS=-Wl,-rpath=/opt/python/${PYTHON_VERSION}/lib,--disable-new-dtags \
--enable-optimizations

编译安装

1
2
make
sudo make install

安装 pip

安装 python 3.9.13 时已安装 pip

1
2
curl -O https://bootstrap.pypa.io/get-pip.py
sudo /opt/python/${PYTHON_VERSION}/bin/python${PYTHON_MAJOR} get-pip.py

使用安装命令

1
2
3
4
5
6
7
8
9
10
# ubuntu
apt install python-pip #python 2
apt install python3-pip #python 3

# centos
yum install epel-release
yum install python-pip
#
dnf install python-pip #Python 2
dnf install python3 #Python 3

k9s setup

Install

1
2
3
4
5
# brew
brew install derailed/k9s/k9s

# snap
sudo snap install k9s

连接集群

1
2
3
4
# microk8s
# 保存内容至 ~/.kube/config
# k9s 会读取配置并连接集群
microk8s config > ~/.kube/config

network

设置网关导致端口网关失效

参考这里

1
2
3
ip route add 192.168.6.0/24 dev br0 table 16
ip route add default via 192.168.6.1 dev br0 table 16
ip rule iif to ipproto tcp sport 10014 lookup 16

另外一种方式

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
ip route add 192.168.6.0/24 dev br0 table 10
ip route add default via 192.168.6.1 table 10
ip route add 192.168.9.0/24 dev br1 table 12
ip route add default via 192.168.9.1 table 12
ip rule add from 192.168.6.0/24 table 10 priority 1
ip rule add from 192.168.9.0/24 table 12 priority 2

# 添加 docker 网络
ip route add 172.17.0.0/16 dev docker0 table 10
ip route add 172.17.0.0/16 dev docker0 table 12

# 刷新配置
ip route flush cache

# 校验
$ ip route show table 12
default via 192.168.9.1 dev br1
172.17.0.0/16 dev docker0 scope link
192.168.9.0/24 dev br1 scope link

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
# out
ip route add default via 192.168.6.1 dev ens8 table 10
ip route add default via 192.168.9.1 dev ens9 table 12
# in
ip rule add from 192.168.6.0/24 table 10 priority 1
ip rule add from 192.168.9.0/24 table 12 priority 2 # 可以不设置 priority

# 如果有设置了默认的路由,可以忽略其中的一个,比如有如下默认路由
ip route add default via 192.168.6.1 dev ens8
# 那么只需要设置 192.168.9.0/24
# ip route add default via 192.168.9.1 dev ens9 table 12
ip route add 192.168.9.0/24 dev ens9 proto kernel scope link src 192.168.9.8
ip rule add from 192.168.9.0/24 table 12

连接路由器的 VPN 之后无法访问内网服务

原因

路由器局域网网段和外网网段冲突,导致访问局域网 ip 不走 vpn 网络。

设置

1
2
3
4
5
6
7
# macos, route 命令
## 查看路由表
sudo netstat -rn
192.168.6.6 link#6 UHRLWIi en0 8
## en0 是 wifi 网络接口, vpn 的网络端口是 utun3
## 修改路由, 把 192.168.6.0/24 所有网段的路由走 vpn
sudo route change 192.168.6.0/24 -interface utun3

USB 外接网卡

1
2
3
4
5
6
7
8
9
10
$ lshw -c network
WARNING: you should run this program as super-user.
*-network
...
logical name: enp0s31f6
...
*-network DISABLED
...
logical name: enxf8e43b1a1229
...

pve - usage

直通

硬盘直通

1
2
3
4
# sata 硬盘直通
qm set {vm-id} -sata0 /dev/disk/by-id/{disk-id}
# 示例
qm set 105 -sata0 /dev/disk/by-id/ata-HS-SSD-A260_1024G_30066931838

samba server

安装

1
2
3
# ubuntu
sudo apt update
sudo apt install samba

配置

1
2
3
4
5
6
7
sudo vim /etc/samba/smb.conf
# 在文档最后添加
[sambashare]
comment = Samba on Ubuntu
path = /home/username/sambashare
read only = no
browsable = yes

重启服务

1
sudo service smbd restart

添加用户并设置密码

1
sudo smbpasswd -a <username>

HTTPS 证书

CertBot

使用 CertBot 进行证书签发及自动更新。

1
2
3
4
5
6
7
8
9
10
# 安装 certbot
$ sudo snap install --classic certbot
$ sudo ln -s /snap/bin/certbot /usr/bin/certbot

# 证书签发
# 需要: 关闭监听 80 端口的 web server
$ sudo certbot certonly --standalone
# 依次输入 邮箱、域名等
# 证书会放在 /etc/letsencrypt/live/{domain}/ 下
# CertBot 会创建定时任务刷新证书

Caddy

Caddy Server 可以自动识别证书,无需指定证书位置。

1
2
3
exploring.fun {
reverse_proxy http://172.60.2.1:30800
}