修改hostname
vi /etc/hostname
vi /etc/hosts
修改时区
# 查看时区
timedatectl
timedatectl list-timezones | grep -i shanghai
# 修改时区
sudo timedatectl set-timezone Asia/Shanghai
创建用户
# 创建用户
sudo adduser yzchen
# 添加sudoer
sudo su
chmod +w /etc/sudoers
visudo # 相当于vi /etc/sudoers
## 添加以下行
username ALL=(ALL) ALL
chmod -w /etc/sudoers
ssh免密登录
创建密钥
ssh-keygen
复制公钥到要登录的服务器
ssh-copy-id username@host
bashrc配置
配置语言
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
常用alias
alias quick-push="git add --all && git commit -m 'update' && git push -u origin master"
alias json_pp="json_pp -json_opt pretty,utf8"
国内源
Mirrors
pip
临时使用
# 中科大
pip install <some-package> -i https://mirrors.ustc.edu.cn/pypi/simple
# 清华
pip install <some-package> -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple
默认使用
# 中科大
pip install -i https://mirrors.ustc.edu.cn/pypi/simple pip -U
pip config set global.index-url https://mirrors.ustc.edu.cn/pypi/simple
# 清华
pip install -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple pip -U
pip config set global.index-url https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple
# 配置多个源
pip config set global.extra-index-url "<url1> <url2>..."
conda
添加配置到 $HOME/.condarc
- 中科大:
channels:
- defaults
show_channel_urls: true
default_channels:
- https://mirrors.ustc.edu.cn/anaconda/pkgs/main
- https://mirrors.ustc.edu.cn/anaconda/pkgs/r
- https://mirrors.ustc.edu.cn/anaconda/pkgs/msys2
custom_channels:
conda-forge: https://mirrors.ustc.edu.cn/anaconda/cloud
bioconda: https://mirrors.ustc.edu.cn/anaconda/cloud
- 清华:
channels:
- defaults
show_channel_urls: true
default_channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
清除缓存:conda clean -i
恢复默认设置
conda config --remove-key channels
docker
添加配置到 /etc/docker/daemon.json
- 中科大:
{
"registry-mirrors": ["https://docker.mirrors.ustc.edu.cn/"]
}
重启 docker
sudo systemctl restart docker
Ubuntu
- 中科大
将 /etc/apt/sources.list 或 /etc/apt/sources.list.d/ubuntu.sources 文件中 Ubuntu 默认的源地址 http://archive.ubuntu.com/ 替换为 https://mirrors.ustc.edu.cn/
或者
sudo sed -i 's@//.*archive.ubuntu.com@//mirrors.ustc.edu.cn@g' /etc/apt/sources.list
sudo sed -i 's/security.ubuntu.com/mirrors.ustc.edu.cn/g' /etc/apt/sources.list
sudo sed -i 's/http:/https:/g' /etc/apt/sources.list
-
清华:https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/
-
更新索引以生效
sudo apt-get update
homebrew
安装 homebrew
- 中科大
export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.ustc.edu.cn/brew.git"
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.ustc.edu.cn/homebrew-core.git"
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles"
export HOMEBREW_API_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles/api"
/bin/bash -c "$(curl -fsSL https://github.com/Homebrew/install/raw/HEAD/install.sh)"
- 清华
export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"
export HOMEBREW_INSTALL_FROM_API=1
/bin/bash -c "$(curl -fsSL https://github.com/Homebrew/install/raw/master/install.sh)"
替换源
- 中科大
export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.ustc.edu.cn/brew.git"
brew update
- 清华
export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"
brew update
- 重置
unset HOMEBREW_BREW_GIT_REMOTE
git -C "$(brew --repo)" remote set-url origin https://github.com/Homebrew/brew
git
gitclone
git clone https://gitclone.com/github.com/vllm-project/vllm.git
gitee
从 github 导入后下载
git clone https://gitee.com/Godspeed_Ribaldry_0009/vllm
hugging face
HF-Mirror
export HF_ENDPOINT=https://hf-mirror.com
安装 huggingface_hub 和 hf_transfer
pip install -U huggingface_hub hf_transfer
下载模型
huggingface-cli download --resume-download openai-community/gpt2-medium --local-dir /path/to/your/directory
开启 hf_transfer
export HF_HUB_ENABLE_HF_TRANSFER=1
Self-hosted
git
- 创建git用户
sudo adduser git
sudo passwd git
- 把所有公钥导入到
/home/git/.ssh/authorized_keys - 初始化Git仓库
cd /home/git/srv
mkdir sample.git
sudo git init --bare sample.git
sudo chown -R git:git sample.git
- 禁用shell登录
在/etc/passwd中加上git:x:1001:1001:,,,:/home/git:/usr/bin/git-shell
- 克隆远程仓库
git clone git@server:srv/sample.git
配置 HTTP 访问
- 安装 nginx
sudo apt install nginx
- 配置 nginx
sudo vi /etc/nginx/sites-available/git
server {
listen 80;
server_name git.yourdomain.com; # Replace with your domain or server IP
root /home/git;
location / {
auth_basic "Git Repository";
auth_basic_user_file /etc/nginx/git-htpasswd;
autoindex on;
}
location ~ (/.*) {
auth_basic "Git Repository";
auth_basic_user_file /etc/nginx/git-htpasswd;
include fastcgi_params;
fastcgi_pass unix:/var/run/fcgiwrap.socket;
fastcgi_param SCRIPT_FILENAME /usr/lib/git-core/git-http-backend;
fastcgi_param GIT_HTTP_EXPORT_ALL "";
fastcgi_param GIT_PROJECT_ROOT /home/git;
fastcgi_param PATH_INFO $1;
}
}
sudo ln -s /etc/nginx/sites-available/git /etc/nginx/sites-enabled/
- 设置密码
sudo apt install apache2-utils
sudo htpasswd -c /etc/nginx/git-htpasswd your_username
- 安装 Git HTTP Backend
sudo apt install fcgiwrap -y
sudo chmod +x /usr/lib/git-core/git-http-backend
5.设置仓库
cd /home/git/repo.git
sudo git update-server-info
增加以下配置 vi /home/git/repo.git/config
[http]
receivepack = true
- 重启 nginx
sudo systemctl restart nginx
- 测试
git clone http://your_server_ip/repo.git
docker-hub
创建 Docker network 与 Redis 容器:
docker network create docker-registry
docker rm -f redis
docker run \
--name=redis \
-itd \
--net=docker-registry \
--restart=always \
redis \
redis-server --maxmemory 512m
镜像缓存容器:
docker rm -f dockerhub-mirror
docker run -itd \
--name dockerhub-mirror \
--restart=always \
--net=docker-registry \
-v /srv/docker/dockerhub/data:/var/lib/registry \
-v /srv/docker/dockerhub/config.yml:/etc/docker/registry/config.yml:ro \
-p 127.0.0.1:5000:5000/tcp \
--log-driver=journald \
--log-opt tag="dockerd-dockerhub" \
registry:2
frp
安装
wget https://github.com/fatedier/frp/releases/download/v0.37.0/frp_0.37.0_linux_amd64.tar.gz
tar -zxvf frp_0.37.0_linux_amd64.tar.gz
服务端配置
[common]
bind_port = 7000
# 不启用dashboard可以不配
dashboard_port =7500
dashboard_user = admin
dashboard_pwd = admin
服务端启动,记得在云服务器上放通6000和7000端口
nohup ./frps -c ./frps.ini > frps.log 2>&1 &
客户端配置
[common]
server_addr = 服务器的公网ip
server_port = 7000
[ssh]
type = tcp
local_ip = 127.0.0.1
local_port = 22
remote_port = 6000
客户端启动
nohup ./frpc -c ./frpc.ini > frps.log 2>&1 &
外网访问
ssh -p 6000 your_username@服务器的公网ip
配置开机启动
服务端
sudo cp ./frps /usr/bin/frps
sudo mkdir /etc/frp && sudo cp ./frps.ini /etc/frp/frps.ini
sudo cp ./systemd/frps.service /etc/systemd/system/
sudo systemctl enable frps
客户端
sudo cp ./frpc /usr/bin/frpc
sudo mkdir /etc/frp && sudo cp ./frpc.ini /etc/frp/frpc.ini
sudo cp ./systemd/frpc.service /etc/systemd/system/
sudo systemctl enable frpc
Mac端配置安全链接
需要被安全穿透的服务器配置
[samba]
type = stcp
# 只有 sk 一致的用户才能访问到此服务
sk = your_password
local_ip = 127.0.0.1
local_port = 445
下载客户端,下载darwin_amd64版本,配置frpc.ini如下
[samba-access]
type = stcp
# stcp 的访问者
role = visitor
# 要访问的 stcp 代理的名字
server_name = samba
sk = your_password
# 绑定本地端口用于访问服务
bind_addr = 127.0.0.1
bind_port = 6000
接下来使用smb://localhost:6000即可链接
配置开机启动
下载客户端,复制到/Users/your_username/Applications/
新建frpc.plist文件
sudo vim ~/Library/LaunchAgents/frpc.plist
写入以下内容
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC -//Apple Computer//DTD PLIST 1.0//EN
http://www.apple.com/DTDs/PropertyList-1.0.dtd >
<plist version="1.0">
<dict>
<key>Label</key>
<string>frpc</string>
<key>ProgramArguments</key>
<array>
<string>/Users/your_username/Applications/frp_0.42.0_darwin_amd64/frpc</string>
<string>-c</string>
<string>/Users/your_username/Applications/frp_0.42.0_darwin_amd64/frpc.ini</string>
</array>
<key>KeepAlive</key>
<true/>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
配置生效
sudo chown root ~/Library/LaunchAgents/frpc.plist
sudo launchctl load -w ~/Library/LaunchAgents/frpc.plist
Samba
服务端安装
sudo apt update
sudo apt install samba
配置
sudo vi /etc/samba/smb.conf
[Data1]
comment = Data1
path = /data1
read only = no
browsable = no
[Share]
comment = Share
path = /data1/Share
read only = no
browsable = yes
[Datap]
comment = Datap
path = /datap
read only = no
browsable = yes
sudo systemctl reload smbd
sudo ufw allow samba
由于小米只支持SMBv1协议,如果想要支持小米电视,还要加上一行
[global]
server min protocol = NT1
添加用户
sudo smbpasswd -a your_username
客户端连接
# 安装
sudo apt-get install smbclient
# 连接
smbclient -L ip_address -U admin%password
# 进入客户端
smbclient //ip_address/dir_name -U admin%password
# mount
sudo apt update && sudo apt install samba samba-common-bin smbclient cifs-utils
sudo mount.cifs //ip_address/share /home/pi/smb-dir -o user=<name>
Finder链接慢的问题
- 取消
.DS_Store:
defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool TRUE
- 取消MacOS自动signing
sudo -s
echo "[default]" >> /etc/nsmb.conf
echo signing_required=no >> /etc/nsmb.conf
exit
Webdav
docker启动
docker run -d \
--name webdav \
--restart always \
-v /data/webdav:/var/lib/dav \
-e AUTH_TYPE=Digest \
-e USERNAME=username \
-e PASSWORD=password \
--publish host_port:80 \
bytemark/webdav:2.4
Nextcloud
https://nextcloud.com/install/#instructions-server
https://github.com/docker-library/docs/blob/master/nextcloud/README.md
docker-compose启动
version: '2'
volumes:
nextcloud:
db:
services:
db:
image: mariadb:10.5
restart: always
command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
volumes:
- /data/nextcloud-mysql:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD={db_password}
- MYSQL_PASSWORD={db_password}
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=nextcloud
app:
image: nextcloud:22.2
restart: always
ports:
- {http_port}:80
links:
- db
volumes:
- /data/nextcloud:/var/www/html
environment:
- MYSQL_PASSWORD={db_password}
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=nextcloud
- MYSQL_HOST=db
- APACHE_DISABLE_REWRITE_IP=1
- OVERWRITEHOST={your_host}:{https_port}
- OVERWRITEPROTOCOL=https
- OVERWRITECLIURL=https://{your_host}:{https_port}
配置nginx https转发
server {
listen {https_port} ssl;
server_name nextcloud;
ssl_certificate /usr/local/nginx/ssl/cert.pem;
ssl_certificate_key /usr/local/nginx/ssl/key.pem;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
# 允许大文件上传
client_max_body_size 10000m;
location / {
proxy_pass http://localhost:{http_port}/;
}
}
安装Ubuntu客户端
sudo add-apt-repository ppa:nextcloud-devs/client
sudo apt update
sudo apt install nextcloud-client
nextcloudcmd --path {{remote_sync_folder}} --user {{username}} --password {{password}} --trust {{local_sync_folder}} https://{{host}}:{{port}}
WebDAV 访问地址,参考 Accessing Nextcloud files using WebDAV,例如 https://yzchen.space/nextcloud/remote.php/dav/files/USERNAME/
SRS
启动服务
docker run -d --name srs \
-p 1935:1935 -p 1985:1985 -p 8080:8080 \
registry.cn-hangzhou.aliyuncs.com/ossrs/srs:4 ./objs/srs -c conf/docker.conf
推流
ffmpeg \
-re \
-i <input> \
-c:v libx264 \
-c:a aac \
-f flv \
rtmp://localhost/live/livestream
观看:
- RTMP:
rtmp://localhost/live/livestream - HTTP:
http://localhost:{port}/players/srs_player.html?autostart=true&stream=livestream.flv&port={port}&schema=http
Jellyfin
docker run -d \
--restart unless-stopped \
--name jellyfin \
-v /data/Jellyfin/config:/config \
-v /data/Jellyfin/cache:/cache \
-v /data/Jellyfin/media:/media \
--net=host \
-e HTTP_PROXY=socks5://127.0.0.1:1080 \
-e HTTPS_PROXY=socks5://127.0.0.1:1080 \
jellyfin/jellyfin:10.8.0
捎刮插件
Photo Hub
Immich
name: immich
services:
immich-server:
container_name: immich_server
image: ghcr.io/immich-app/immich-server:${IMMICH_VERSION:-release}
command: ['start.sh', 'immich']
volumes:
- ${UPLOAD_LOCATION}:/usr/src/app/upload
- /etc/localtime:/etc/localtime:ro
env_file:
- .env
ports:
- 2283:3001
depends_on:
- redis
- database
restart: always
immich-microservices:
container_name: immich_microservices
image: ghcr.io/immich-app/immich-server:${IMMICH_VERSION:-release}
# extends: # uncomment this section for hardware acceleration - see https://immich.app/docs/features/hardware-transcoding
# file: hwaccel.transcoding.yml
# service: cpu # set to one of [nvenc, quicksync, rkmpp, vaapi, vaapi-wsl] for accelerated transcoding
command: ['start.sh', 'microservices']
volumes:
- ${UPLOAD_LOCATION}:/usr/src/app/upload
- /etc/localtime:/etc/localtime:ro
env_file:
- .env
depends_on:
- redis
- database
restart: always
immich-machine-learning:
container_name: immich_machine_learning
# For hardware acceleration, add one of -[armnn, cuda, openvino] to the image tag.
# Example tag: ${IMMICH_VERSION:-release}-cuda
image: ghcr.io/immich-app/immich-machine-learning:${IMMICH_VERSION:-release}
# extends: # uncomment this section for hardware acceleration - see https://immich.app/docs/features/ml-hardware-acceleration
# file: hwaccel.ml.yml
# service: cpu # set to one of [armnn, cuda, openvino, openvino-wsl] for accelerated inference - use the `-wsl` version for WSL2 where applicable
volumes:
- model-cache:/cache
env_file:
- .env
restart: always
redis:
container_name: immich_redis
image: registry.hub.docker.com/library/redis:6.2-alpine@sha256:84882e87b54734154586e5f8abd4dce69fe7311315e2fc6d67c29614c8de2672
restart: always
database:
container_name: immich_postgres
image: registry.hub.docker.com/tensorchord/pgvecto-rs:pg14-v0.2.0@sha256:90724186f0a3517cf6914295b5ab410db9ce23190a2d9d0b9dd6463e3fa298f0
environment:
POSTGRES_PASSWORD: ${DB_PASSWORD}
POSTGRES_USER: ${DB_USERNAME}
POSTGRES_DB: ${DB_DATABASE_NAME}
volumes:
- ${DB_DATA_LOCATION}:/var/lib/postgresql/data
restart: always
volumes:
model-cache:
Music
Navidrome
docker run -d \
--name navidrome \
--restart=unless-stopped \
--user $(id -u):$(id -g) \
-v /data/navidrome/music:/music \
-v /data/navidrome/data:/data \
-p 4533:4533 \
-e ND_LOGLEVEL=info \
-e ND_BASEURL=/navidrome \
deluan/navidrome:latest
feishin
remove from quarantine:
xattr -r -d com.apple.quarantine /Applications/Feishin.app
Proxy
HTTP Proxy
Caddy
配置 L7 反向代理
:8080 {
reverse_proxy host:8080
}
Nginx
HAProxy
TCP Proxy
Caddy
未测试过,可以参考以下文档
Nginx
HAProxy
其他
安装字体
sudo mv your_font.tff /usr/share/fonts/
fc-cache -f -v
fc-list | grep your_font
重装
- 惠普按F10
- 联想/戴尔按F12
- 微星:Del or F11
制作 Windows 安装盘
- 格式化 U 盘:GUID Partition Map + FAT32
- 下载 Windows ISO
- 加载 ISO 文件:
hdiutil mount ~/Downloads/Win10_1903_V1_English_x64.iso - 复制到 U 盘
- 复制除了install.wim之外的文件:
rsync -vha --exclude=sources/install.wim /Volumes/CCCOMA_X64FRE_EN-GB_DV9/* /Volumes/WIN11 - 复制 install.wim
brew install wimlibmkdir /Volumes/WIN11/sourceswimlib-imagex split /Volumes/CCCOMA_X64FRE_EN-GB_DV9/sources/install.wim /Volumes/WIN11/sources/install.swm 3800
- 复制除了install.wim之外的文件:
- 弹出 U 盘
常见问题
- Ubuntu 进入命令行界面:
Ctrl + Alt + F3 - 安装显卡驱动:
sudo ubuntu-drivers autoinstall - 网卡 state down:
sudo dhclient <interface>sudo vi /etc/netplan/00-installer-config.yaml
network:
ethernets:
eno1:
dhcp4: true
<interface>:
dhcp4: true
version: 2
- Windows 10 安装后无法连接以太网
- 通过 Andriod 手机用 USB 共享网络,到 HP 官方下载网络驱动并安装
- Windows 11 无法安装:This PC can’t run Windows 11
- This PC can’t run Windows 11 – Bypass/Fix
- 按 Shift + F10 进入命令行,输入
regedit打开注册表 - 在
HKEY_LOCAL_MACHINE\SYSTEM\Setup路径下创建 Key:LabConfig,并写入 DWORD- BypassCPUCheck
- BypassRAMCheck
- BypassSecureBootCheck
- BypassStorageCheck
- BypassTPMCheck
- 没有系统配置图标
- 安装 gnome-control-center:
sudo apt install gnome-control-center
- 安装 gnome-control-center: