Linux 踩坑笔记
原创大约 3 分钟
解决方案
网络带宽限制
1. 限制网络接口带宽
wondershaper -a <ADAPTER> -u <RATE> -d <RATE>
# 对 <ADAPTER> 进行带宽限制,上行为 <RATE> Kbps ,下行为 <RATE> Kbps
ip addr show
# 查看所有网络接口名称
wondershaper -a <ADAPTER> -c
# 清除 <ADAPTER> 上的限速设置
wondershaper -a eth0 -u 100 -d 200
# 限制 eth0 的带宽为:上行 100 Kbps,下行 200 Kbps。
注意
使用包管理器安装的 wondershaper 版本较老,不适用于上述指令。需要在 Github 仓库自行 clone 。安装方法详见 Github Repo。
2. 限制进程带宽
apt install trickle
# Debian/Ubuntu 安装 Trickle
trickle -s -u <RATE> -d <RATE> <command>
# 以独立模式运行 Trickle,受到带宽限制的进程是 <command>,上行 <RATE> KB/s,下行 <RATE> KB/s
trickle -s -u 512 -d 2048 firefox
# 以上行 512 KB/s,下行 2048 KB/s 的带宽运行 Firefox
Docker Hub 拉取容器
因不可抗力因素,中国大陆网络从 Docker Hub 官方镜像 拉取容器较为困难 ( 基本不可用 )。
此时可以使用其他服务商提供的镜像,此处列举部分:
- 百度云:https://mirror.baidubce.com
- 网易云:https://hub-mirror.c.163.com
- Docker Proxy:https://dockerproxy.com
- 阿里云: 登录控制台自行获取,每人独有地址。
以下服务商的镜像服务可能不可用,自行甄别:
- 谷歌云容器镜像:http://mirror.gcr.io ( 可能不可用 )
- 中科大镜像:https://docker.mirrors.ustc.edu.cn ( 仅供内部使用 )
修改 Docker 镜像源方法
修改文件 /etc/docker/daemon.json,粘贴以下内容:
{
"registry-mirrors": [
"https://mirror.baidubce.com",
"https://hub-mirror.c.163.com",
"https://dockerproxy.com"
]
}
重载服务
sudo systemctl daemon-reload
sudo systemctl restart docker
常用命令
Git 、Github 相关
git config --global user.name "user"
git config --global user.email user@example.com
# Git 设置用户名、邮箱
ssh-keygen -t ed25519 -C "user@example.com"
# 生成 SSH 密钥,并将公钥文件粘贴进 https://github.com/settings/keys
ssh -T git@github.com
# 如返回 'successfully authenticated' 等字样,则 SSH 密钥添加成功。
使用 git clone git@github.com:user/repo.git 方式拉取仓库时,git push 将不会要求身份认证,使用 Https 拉取仓库时则会每次要求输入密码。
Openwrt 单 LAN 口设置旁路由
接口
- 设置 DHCP 忽略 LAN
- 禁用 IPV6 分配长度 (如果不需要)
- 设置网关为主路由
- 使用 Openclash 也许可以关闭桥接。也可以在 Clash 里面指定 br-lan (?),比较玄学,还在研究中。
防火墙
- 关闭 SYN-flood 防御
- 打开 LAN-WAN 的 IP 动态伪装
- 添加自定义防火墙规则
iptables -t nat -I POSTROUTING -o eth0 -j MASQUERADE
Docker.service 启动时意外退出 error code 1"
sudo dockerd --debug 找报错点。
