将系统写入emmc
输入 lsblk 查看磁盘命名
dd if=Armbian.img of=/dev/mmcblk0 bs=1M或
gzip -dc Armbian.img.gz | dd of=/dev/mmcblk0上传镜像包到当前目录,每个人的设备略有不同,并非所有的都是mmcblk0,具体请使用lsblk查看
配置网络
插入USB无线网卡,输入nmtui命令连接wifi
替换软件源
编辑/etc/apt/sources.list:
sudo nano /etc/apt/sources.list删除里面的内容,Debian-buster的软件源(如果源失效请自行上网寻找)
deb https://ftp.udx.icscoe.jp/debian/ bookworm main contrib non-free non-free-firmware
# deb-src https://ftp.udx.icscoe.jp/debian/ bookworm main contrib non-free non-free-firmware
deb https://ftp.udx.icscoe.jp/debian/ bookworm-updates main contrib non-free non-free-firmware
# deb-src https://ftp.udx.icscoe.jp/debian/ bookworm-updates main contrib non-free non-free-firmware
deb https://ftp.udx.icscoe.jp/debian/ bookworm-backports main contrib non-free non-free-firmware
# deb-src https://ftp.udx.icscoe.jp/debian/ bookworm-backports main contrib non-free non-free-firmware
deb http://ftp.riken.jp/Linux/debian/debian-security/ bookworm-security main contrib non-free non-free-firmware
# deb-src http://ftp.riken.jp/Linux/debian/debian-security/ bookworm-security main contrib non-free non-free-firmware中國推薦使用中科大源,注意安全更新使用Debian官方
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.ustc.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
# deb-src https://mirrors.ustc.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
deb https://mirrors.ustc.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
# deb-src https://mirrors.ustc.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
deb https://mirrors.ustc.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
# deb-src https://mirrors.ustc.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
deb https://security.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware
# deb-src https://security.debian.org/debian-security bookworm-security main contrib non-free non-free-firmwareDebian官方源
deb http://deb.debian.org/debian/ bookworm contrib main non-free non-free-firmware
deb-src http://deb.debian.org/debian/ bookworm contrib main non-free non-free-firmware
deb http://deb.debian.org/debian/ bookworm-updates contrib main non-free non-free-firmware
deb-src http://deb.debian.org/debian/ bookworm-updates contrib main non-free non-free-firmware
deb http://deb.debian.org/debian/ bookworm-proposed-updates contrib main non-free non-free-firmware
deb-src http://deb.debian.org/debian/ bookworm-proposed-updates contrib main non-free non-free-firmware
deb http://deb.debian.org/debian/ bookworm-backports contrib main non-free non-free-firmware
deb-src http://deb.debian.org/debian/ bookworm-backports contrib main non-free non-free-firmware
deb http://deb.debian.org/debian-security/ bookworm-security contrib main non-free non-free-firmware
deb-src http://deb.debian.org/debian-security/ bookworm-security contrib main non-free non-free-firmwareArmbian還需要編輯/etc/apt/sources.list.d/armbian.list或/etc/apt/sources.list.d/armbian.sources
https://mirrors.ustc.edu.cn/armbian直接替換
sudo sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list.d/debian.sources
sudo sed -i 's/beta.armbian.com/mirrors.ustc.edu.cn/g' /etc/apt/sources.list.d/armbian.sources更新软件列表和软件:
sudo apt update && apt upgrade中文本地化
校正系统时间
将时区改成上海
sudo timedatectl set-timezone Asia/Shanghai查看当前时区
timedatectl列出所有时区
timedatectl list-timezones编辑locale.gen
去掉zh_TW.UTF-8前面的#
sudo nano /etc/locale.gen安装中文字体
sudo apt install fonts-noto-cjk fonts-noto-cjk-extra fonts-noto-color-emoji如果要输入y/n的话,输入y并回车
编辑.xprofile
sudo nano ~/.xprofile添加:
export LC_ALL=zh_TW.UTF-8编辑locale
sudo nano /etc/default/locale把内容改成:
# File generated by update-locale
LC_MESSAGES=zh_TW.UTF-8
LANGUAGE=zh_TW.UTF-8
LANG=zh_TW.UTF-8
LC_ALL=zh_TW.UTF-8执行以下命令
sudo locale-gen zh_TW.UTF-8重启系统
sudo reboot挂载硬盘\& 配置smb服务
https://purenote.eu.org/linux/2220.html
清理无用软件
sudo apt purge gnome-2048 aisleriot atomix gnome-chess five-or-more hitori iagno gnome-klotski lightsoff gnome-mahjongg gnome-mines gnome-nibbles quadrapassel four-in-a-row gnome-robots gnome-sudoku swell-foop tali gnome-taquin gnome-tetravex goldendict anthy kasumi
sudo apt autoremove配置Debian服务器允许root用户远程SSH登录
修改/etc/ssh/sshd_config文件,将PermitRootLogin 设置为yes,PasswordAuthentication设置为yes即可,:wq保存退出即可。
nano /etc/ssh/sshd_config输入下面命令,重新启动SSH服务器:
/etc/init.d/ssh restart配置用户sudo权限
Debian 在安装时创建的非管理员用户并没有 sudo 权限。为了便于操作,需要为其添加 sudo 权限。 切换到 root 用户:su root 配置文件位于 /etc/sudoers ,编辑配置文件,在 root ALL=(ALL:ALL) ALL 下一行添加以下内容:
你的用户名 ALL=(ALL:ALL) ALL安装命令行工具
sudo apt install curl git wget gnupg dpkg apt-transport-https lsb-release ca-certificates p7zip-full unzip fastfetch btop ncdu rclone修改SSH端口
将默认的22端口修改为55520
sudo sed -i 's/^#\?Port 22.*/Port 55520/g' /etc/ssh/sshd_config重启sshd服务
sudo systemctl restart sshd密钥登录
一键生成你的密钥
wget -O key.sh https://raw.githubusercontent.com/yuju520/Script/main/key.sh && chmod +x key.sh && clear && ./key.sh安装fail2ban
apt install fail2ban配置fail2ban
fail2ban的配置文件通常位于 /etc/fail2ban/ 目录下,fail2ban的.conf配置文件都是可以被.local覆盖,所以配置方式建议是添加.local文件,不修改原来的配置文件。
nano /etc/fail2ban/jail.local配置文件如下:
[DEFAULT]
#忽略的IP列表,不受设置限制(白名单)
ignoreip = 127.0.0.1
#允许ipv6
allowipv6 = auto
#日志修改检测机制(gamin、polling和auto这三种)
backend = systemd
#针对各服务的检查配置,如设置bantime、findtime、maxretry和全局冲突,服务优先级大于全局设置
[sshd]
#是否激活此项(true/false)
enabled = true
#过滤规则filter的名字,对应filter.d目录下的sshd.conf
filter = sshd
#ssh端口
port = ssh
#动作的相关参数
action = iptables[name=SSH, port=ssh, protocol=tcp]
#检测的系统的登陆日志文件
logpath = /var/log/secure
#屏蔽时间,单位:秒
bantime = 86400
#这个时间段内超过规定次数会被ban掉
findtime = 86400
#最大尝试次数
maxretry = 3Ctrl+S保存并退出
设置开机自动启动fail2ban
sudo systemctl enable fail2ban重新启动fail2ban
sudo systemctl restart fail2ban查看fail2ban的状态
sudo systemctl status fail2ban查看所有可用jail的状态
fail2ban-client status关闭 armbian 系统中的 zram swap
因为我使用的主板有 32GB 内存,并且我的系统安装在 TF 卡上,所以我不需要,也不希望 SWAP 功能启用,它会影响整个设备的运行性能。
常规的停止 SWAP 方法,可以使用 swapoff 命令来停止 swap 服务:
然后,编辑 /etc/fstab 文件,删除 swap 相关内容。
但是,在 armbian 中,我们使用的 swap 类型是 zram swap,想要关闭这个服务,需要通过命令关闭 armbian-zram-config 服务。
sudo systemctl disable armbian-zram-config sudo systemctl stop armbian-zram-config完成上面的设置之后,重启即可让变更完全生效。重启后执行 free -h,将会看到:
此时 swap 已彻底永久关闭。
迁移 Docker 容器存储存储位置
默认情况下,Docker 会将数据存储在 /var/lib/docker/ 目录中,为了提高系统使用体验,我们可以将容器的数据保存在我们上面新创建并挂载的 SSD 磁盘中。
参考文章《迁移 Docker 容器储存位置》的方法进行处理即可。
完成设置之后,可以使用命令进行结果验证:
docker info | grep "Docker Root Dir"不出意外,将收到类似下面的日志输出:
Docker Root Dir: /data0/docker创建数据保存服务,避免数据丢失
在使用 armbian 提供的 radxa 镜像后,如果我们手动重启或断电,会发现经常出现数据丢失。
通过排查,发现是由于 armbian 默认的分区挂载参数中有一项:commit=120 参数。
# cat /etc/fstab UUID=b1a28769-69fa-4474-a788-c7c6e25999b9 / ext4 defaults,noatime,commit=120,errors=remount-ro 0 1 /dev/nvme0n1p1 /data0 ext4 defaults,nofail 0 2 /dev/nvme1n1p1 /data1 ext4 defaults,nofail 0 2 tmpfs /tmp tmpfs defaults,nosuid 0 0这个参数表示每 120 秒才强制提交一次缓存到磁盘,这可以提升性能,但一旦异常重启(如突然断电或不正确关机),就容易导致数据丢失或未保存。
想要解决这个问题,我们可以选择调整或去除 commit 参数,或者在计划重启的时候,手动、自动执行 sync 命令,让数据能够写入磁盘,完成保存。
为了简化这类操作,并尽可能不影响默认情况的设备性能,我们可以创建一个“懒人保存”服务,当设备关闭或者重启的时候,自动执行 sync 操作:
sudo vim /etc/systemd/system/sync-on-shutdown.service创建一个服务配置,在配置文件中写入下面的内容;
[Unit] Description=Sync Filesystems on Shutdown DefaultDependencies=no Before=shutdown.target reboot.target halt.target [Service] Type=oneshot ExecStart=/bin/sync [Install] WantedBy=halt.target reboot.target shutdown.target完成配置编写后,执行下面的命令,设置服务开机启动,让服务生效即可:
sudo systemctl enable sync-on-shutdown.service