Debian是较为常用的GNU/Linux的一个分支,有众多衍生版本,本文也可作为其他Linux系统的参考


目录

  1. 安装前的准备
  2. 安装过程
  3. 安装完成
  4. 安装软件
  5. 系统维护
    1. 设置物理swap
    2. 关闭swap并开启zram
    3. 如果ssh登录不执行.bashrc
    4. 解决无法ping的问题
    5. 解压缩文件指令
  6. 配置watchdog
    1. 配置 screen
    2. 缓存清理
    3. 常见命令
    4. 硬盘分区/挂载相关
  7. ACPI相关
  8. 性能调节器
  9. 网络代理
  10. 错误排查
  11. WOL
  12. Ubuntu相关
  13. 香橙派相关
  14. 香橙派5 armbian相关
  15. CentOS相关
  16. 参考

安装前的准备

请不要直接将ISO解压到U盘里安装,使用Ventoy(推荐)或UltraISO创建硬盘镜像,否则将导致无法启用UEFI功能,会在没有CSM功能的主板上安装完毕后找不到启动设备。如果连接国内源特别慢的情况(在电信网上出现过,移动网未出现过),可以使用全量版系统安装并拔掉网线安装。

安装过程

安装时语言应该选英文,否则安装后中文一定会出现乱码,安装软件一定要选择SSH Server,标准系统工具,不建议安装桌面,注意安装的时候换国内源,否则安装会特别慢,并且会导致安装失败
安装完成若找不到启动项,在Bios里手动添加efi
File Browser Add Boot Option -你的设备-EFI - Debian- grub64.efi - 输入名字

安装完成

解决运行什么命令都command not find的问题

1
2
nano .bashrc
export PATH=$PATH:/usr/sbin

禁用poweroff //避免自己脑子瓦特

1
alias poweroff="poweroff -w"

使修改生效

1
source .bashrc

如果安装未选择ssh,可以手动安装

1
apt install openssh-server

安装后中文乱码

1
2
3
apt-get install locales
dpkg-reconfigure locales
勾选en_US.UTF-8 UTF-8,其他不勾选,保存退出

设置管理员密码

1
passwd root

修改用户密码

1
passwd pi

设置ssh

1
2
3
nano /etc/ssh/sshd_config
AddressFamily inet //只监听ipv4
PermitRootLogin yes //允许root登录SSH

重启ssh服务生效

1
systemctl restart ssh

安装软件

如果提示缺少xxx,就访问Debianpkgs搜索缺少的文件就能找出未安装的依赖
一些必要软件

1
apt-get install curl gnupg net-tools

安装Python3&GCC

1
apt-get install python3-pip python3-dev libffi-dev gcc make

搭建云媒体库,参考云存储解决方案
搭建云IDE,参考云存储解决方案
安装Syncthing,参考备份软件的使用
搭建Minecraft服务器,参考搭建Minecraft服务器
安装ZeroTier,参考内网穿透软件
搭建NovelAI前端,参考StableDiffusion服务器搭建
设置ipv6DDNS,详见DNS相关内容
搭建Waifu2x前端,详见Waifu2x服务器搭建
配置代理服务器,详见搭建代理服务器
安装Wordpress,参考使用Wordpress建站
安装Webmin管理服务器,参考Linux性能监控
配置自定义的服务,参考Linux配置服务
配置定时任务,参考Linux配置定时任务
安装文件服务器,参考搭建文件服务器
安装Aria2,参考跨平台下载器的使用
安装Debian驱动,参考安装Linux驱动

卸载软件

1
2
3
4
apt list --installed  //查看所有安装包
apt-get purge nginx //apt-get卸载单个
apt-get autoremove cuda* //卸载所有
aptitude purge nginx //aptitude卸载

系统维护

设置物理swap

1
2
3
4
5
6
7
8
dd if=/dev/zero of=/swapfile1 bs=1M count=4096	(这个自己改)
chmod 600 /swapfile1
mkswap /swapfile1
swapon /swapfile1
swapon -s
cp /etc/fstab /etc/fstab.mybackup
echo /swapfile1 swap swap defaults 0 0 >> /etc/fstab
reboot

关闭swap并开启zram

此部分内容验证未通过,慎用
查看swap位置:cat /proc/swaps
打开配置文件:nano /etc/fstab
注释掉:# UUID=xxxx-xxxx-xxxx none swap sw 0 0
查看状态zramctl
重启后确认free -h


如果ssh登录不执行.bashrc

1
nano ~/.bash_profile //写到这里就行了

解决无法ping的问题

编辑网络配置文件

1
nano /etc/network/interfaces

如果是DHCP,内容为

1
2
3
4
auto lo
auto 你的网卡
iface lo inet loopback
iface 你的网卡 inet dhcp

如果是静态地址,内容为

1
2
3
4
5
6
auto lo enp4s0
iface lo inet loopback
iface enp4s0 inet static
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.1

编辑DNS服务器

1
nano /etc/resolv.conf

编辑host

1
nano /etc/hosts

重启网络服务

1
/etc/init.d/networking restart

解压缩文件指令

1
2
tar.gz	tar -xzf
tar.xz tar -xvf

配置watchdog

1
2
apt-get install watchdog
nano /etc/default/watchdog
1
2
run_watchdog=1  
watchdog_module="iTCO_wdt"

开启iTCO_wdt

1
2
3
modprobe iTCO_wdt
nano /var/run/watchdog.pid
nano /etc/watchdog.conf

反注释掉

1
watchdog-device         = /dev/watchdog

开启服务

1
2
3
modprobe softdog
watchdog
systemctl enable watchdog.service

查看服务状态(存疑)

1
2
ls /dev/watchdog
cat /dev/watchdog

杀死watchdog会导致重启(存疑)

1
kill -9 

配置 screen

安装screen

1
apt-get install screen

nano .bashrc,写入下面的内容

1
2
3
alias sl="screen -ls"				//输入sl就可以查看运行中的screen
alias sb="screen bash" //输入sb就可以打开一个sreen
alias sr='func() { screen -D -r $1;}; func' //输入sr +screen_id就可以返回screen

直接在screen里运行命令

1
screen -dm +命令

缓存清理

清理apt缓存

1
2
3
apt-get autoclean
apt-get clean
apt-get autoremove

清理pip缓存

1
rm- r ~/.cache/pip

清除cache

1
echo 2 > /proc/sys/vm/drop_caches

常见命令

创建软连接,可链接文件或文件夹

1
ln /mnt/hdd/hym/音乐相关 /var/www/html/mu/music -s

查看磁盘占用

1
2
du -h --max-depth=1 //以文件夹形式查看
df -h //以分区查看

查看时间:date
设置时区:cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
给权限:chmod 777 n.sh
某些文件删不掉:chattr -i .user.ini


硬盘分区/挂载相关

检查坏块:badblocks -v -s -o a.out /dev/nvme0n1p2
安装硬盘SMART监视工具:apt-get install smartmontools
查找磁盘:fdisk -l
硬盘格式化为exfat:mkfs.ext4 /dev/sda
挂载硬盘

1
2
mkdir /mnt/disk
mount /dev/sda1 /mnt/disk

卸载硬盘umount /dev/sda
开机自动挂载磁盘

1
2
3
blkid /dev/sda	#查询sda的UUID
nano /etc/fstab #在文件后面添加配置
UUID=XXXX /mnt/disk/ ext4 defaults 0 0

查看挂载是否生效:df -h


ACPI相关

合上盖子无操作

1
nano /etc/systemd/logind.conf

追加此代码

1
HandleLidSwitch=ignore

性能调节器

查看调节器

1
cat /sys/devices/system/cpu/cpu2/cpufreq/scaling_governor

调整调节器

1
2
3
echo performance > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor		//性能模式
echo powersave > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor //节能模式
echo ondemand > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor //平衡模式

网络代理

设置代理,详见搭建代理服务器

1
2
3
4
nano /etc/apt/apt-proxy.conf
Acquire::http::proxy "http://192.168.1.5:2333/";
Acquire::https::proxy "http://192.168.1.5:2333/";
apt-get update -c /etc/apt/apt-proxy.conf

错误排查

更新软件

1
apt upgrade

修复apt

1
2
apt --fix-broken install
apt-get update --fix-missing

查看端口占用

1
lsof -i:2333

WOL

注意关闭快速启动
安装ethtool

1
apt-get install ethtool

假设网卡叫enp4s0(ifconfig查询),运行命令

1
ethtool enp4s0

查看到就算支持,

1
Supports Wake-on: pumbg

如果是ug就不支持

1
Supports Wake-on: ug

如果看到g,就是启用的

1
Wake-on: g

如果显示为d

1
Wake-on: d

则手动启用

1
ethtool -s enp4s0 wol g

如果重启后失效,可使用脚本启动

1
nano /etc/network/interfaces.d/enp4s0

写入下面内容

1
2
3
auto enp4s0
iface enp4s0 inet dhcp
ethernet-wol g

唤醒其他机器

1
2
apt install etherwake
wakeonlan -i 192.168.1.255 50:eb:f6:97:00:fd

Ubuntu相关

Ubuntu源:

1
2
http://mirrors.aliyun.com/ubuntu/
https://mirrors.tuna.tsinghua.edu.cn/ubuntu/

Debian源:

1
2
3
4
5
6
7
8
9
nano /etc/apt/sources.list
deb https://mirrors.aliyun.com/debian/ bullseye main non-free contrib
deb-src https://mirrors.aliyun.com/debian/ bullseye main non-free contrib
deb https://mirrors.aliyun.com/debian-security/ bullseye-security main
deb-src https://mirrors.aliyun.com/debian-security/ bullseye-security main
deb https://mirrors.aliyun.com/debian/ bullseye-updates main non-free contrib
deb-src https://mirrors.aliyun.com/debian/ bullseye-updates main non-free contrib
deb https://mirrors.aliyun.com/debian/ bullseye-backports main non-free contrib
deb-src https://mirrors.aliyun.com/debian/ bullseye-backports main non-free contrib

如果换源后报错The certificate is NOT trusted

1
2
touch /etc/apt/apt.conf.d/99verify-peer.conf \
&& echo >>/etc/apt/apt.conf.d/99verify-peer.conf "Acquire { https::Verify-Peer false }"

香橙派相关

连接串口后CH340的串口波特率为115200、8、1、N、N
ubuntu默认账号和密码orangepi passwd root设置root密码
armbian默认账号密码root 1234登陆成功后需要修改密码
debian默认账号和密码orangepi,root密码也是orangepi
串口显示[233]HELLO! BOOT0 is starting!说明启动成功

香橙派5 armbian相关

默认账号密码是root 1234 选择bash

1
nano /etc/apt/sources.list

追加

1
2
3
4
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-security main restricted universe multiverse

CentOS相关

网络安装源地址

1
http://mirrors.aliyun.com/centos/7/os/x86_64/

模式区别

1
2
InfrastructureServer:服务器中使用的CentOS基本安装,不包含桌面。
Basic WebServer:PHP,Web server,还有MySQL和PostgreSQL数据库的客户端,无桌面。

安装服务器

1
2
3
4
5
6
7
8
9
10
yum install httpd
rpm -ivh http://mirrors.ustc.edu.cn/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum install php70w
service httpd start
chkconfig httpd on
ps -ef | grep apache
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --reload
firewall-cmd --list-ports

必备软件

1
yum install python3 python3-pip cmake

参考

Debian WakeOnLan