debian12部署

1、查看版本

#系统内核信息
uname -r
#获取系统信息
cat /etc/os-release
#修改计算机名
hostname xx
#或
vi /etc/hostname

终端显示系统信息

#安装screenfetch
apt install screenfetch
#显示信息
screenfetch
#系统的电源管理信息
apt install acpi
#显示电量百分比信息
acpi

2、升级系统

#更新软件包列表
apt update
#更新系统所有软件包
apt upgrade

修改备份源 文件目录下 /etc/apt/sources.list

cp /etc/apt/sources.list /etc/apt/sources.list.bak
vi /etc/apt/sources.list

更换阿里云源

deb https://mirrors.aliyun.com/debian/ bookworm main non-free non-free-firmware contrib
deb-src https://mirrors.aliyun.com/debian/ bookworm main non-free non-free-firmware contrib
deb https://mirrors.aliyun.com/debian-security/ bookworm-security main
deb-src https://mirrors.aliyun.com/debian-security/ bookworm-security main
deb https://mirrors.aliyun.com/debian/ bookworm-updates main non-free non-free-firmware contrib
deb-src https://mirrors.aliyun.com/debian/ bookworm-updates main non-free non-free-firmware contrib
deb https://mirrors.aliyun.com/debian/ bookworm-backports main non-free non-free-firmware contrib
deb-src https://mirrors.aliyun.com/debian/ bookworm-backports main non-free non-free-firmware contrib

更换腾讯云源

deb https://mirrors.tencent.com/debian/ bookworm main non-free non-free-firmware contrib
deb-src https://mirrors.tencent.com/debian/ bookworm main non-free non-free-firmware contrib
deb https://mirrors.tencent.com/debian-security/ bookworm-security main
deb-src https://mirrors.tencent.com/debian-security/ bookworm-security main
deb https://mirrors.tencent.com/debian/ bookworm-updates main non-free non-free-firmware contrib
deb-src https://mirrors.tencent.com/debian/ bookworm-updates main non-free non-free-firmware contrib
deb https://mirrors.tencent.com/debian/ bookworm-backports main non-free non-free-firmware contrib
deb-src https://mirrors.tencent.com/debian/ bookworm-backports main non-free non-free-firmware contrib

桌面系统关闭休眠

systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target

查看休眠状态是否修改成功

systemctl status sleep.target

3、安装vim

apt install vim

4、修改ssh默认端口号

vi /etc/ssh/sshd_config

找到 #Prot 这一行,按 i 编辑模式

然后把 # 号去掉,修改默认端口号 22

root允许远程登录

取消注释PermitRootLogin前面的#号 ,后半截改为yes

PermitRootLogin yes

然后按Esc退出编辑模式,输入**:wq** 保存退出

 :w 保存,但不退出  
 :wq 保存并退出  
 :x 同:wq  
 :q 退出,如果当前文件没有保存,禁止退出  
 :q! 不保存退出

重启ssh服务

service sshd restart
#或者
systemctl restart sshd

出现重启报错,发现SELinux允许的ssh的端口号和ssh配置文件中设置的端口号不一致。

5、防火墙ufw命令

安装防火墙

apt install ufw

查看防火墙状态

ufw status verbose

允许ssh连接

#允许服务名称
ufw allow OpenSSH
#允许端口
ufw allow 333/tcp

启用/禁用防火墙

#启用UFW
ufw enable
#禁用UFW
ufw disable

开放指定端口

ufw allow 端口号/tcp
ufw reload

开放区域端口

ufw allow 8090:9090/tcp
#或者
ufw allow 8090:9090/udp

允许指定ip指定端口

ufw allow from 115.127.62.61 to any port 22
#允许子网(例如允许从192.168.1.1到192.168.1.254的IP地址到端口3306)
ufw allow from 192.168.1.0/24 to any port 3306
#允许连接到特定的网络接口(仅将3306端口访问特定网络接口eth2)
ufw allow in on eth2 to any port 3306

拒绝连接(黑名单)

#拒绝来自23.24.25.0/24的所有连接
ufw deny from 23.24.25.0/24
#拒绝从23.24.25.0/24访问端口80和443
ufw deny from 23.24.25.0/24 to any port 80
ufw deny from 23.24.25.0/24 to any port 443

删除UFW规则

#查看规则编号删除UFW规则
ufw status numbered
#例如删除找到的规则编号2
fw delete 2
#通过指定实际规则来删除
ufw delete allow 8069

重置防火墙

ufw reset

常用命令

ufw status #查看防火墙状态
 
ufw enable #开启防火墙
 
ufw disable #关闭防火墙
 
ufw reset #重置防火墙,将删除之前定义的所有过滤规则
 
ufw allow #允许通过
 
ufw deny #禁止通过

6、安装Docker

apt install docker.io
#查看安装后版本
docker -v
#再安装compose
apt install docker-compose
#查看compose是否安装成功
docker-compose -v
#设置docker开机自启
systemctl enable docker
#启动docker服务
service docker start

shell脚本安装一键安装

#!/bin/bash
echo "准备完善docker环境安装!"
sleep 1
echo "准备倒计时 3!"
sleep 1
echo "准备倒计时 2!"
sleep 1
echo "准备倒计时 1!"
echo "更新软件包索引"
apt-get update
echo "安装docker"
apt install -y docker.io
echo "查看安装后版本"
docker -v
echo "再安装compose"
apt install -y docker-compose
echo "查看compose是否安装成功"
docker-compose -v
echo "启动Docker"
systemctl start docker
echo "开机自启"
systemctl enable docker
echo "守护进程重启"
systemctl daemon-reload
echo "重启Docker服务"
systemctl restart docker
echo "查看Docker状态"
systemctl status docker
exit

7、安装 Nala

安装nala

apt install nala

列出镜像列表,速度排序

nala fetch

选择几个镜像,数字后空格 如:1 4 6

更新安装包

nala update
nala upgrade

常用命令:

install : 安装包
remove : 删除包
purge : 清除包
update :更新包列表,升级系统
upgrade : 更新别名
fetch :获取快速镜像以加快下载速度
show : 显示包详情
history : 显示命令历史
clean :清除检索到的包文件的本地存储库

可选参数:

-h , --help : 显示帮助信息并退出
-y , --assume-yes : 假设所有提示为“是”并以非交互方式运行
-d , --download-only : 包文件只被检索,不解包或安装
-v , --verbose : 记录额外的调试信息
--no-update : 跳过更新包列表
--no-autoremove : 阻止 Nala 自动删除包
--remove-essential :允许删除基本包
--raw-dpkg : 跳过所有格式并获得原始 dpkg 输出
--update :更新包列表
--debug : 记录额外的调试信息
--version : 显示程序的版本号并退出
--license : 读取编译入软件的许可证,然后读取 GPLv3

7、普通用户使用sudo

编辑 /etc/sudoers 文件 添加用户到 sudoers 文件。在文件末尾添加下面这一行

用户名 ALL=(ALL:ALL) ALL

不是 sudoers 文件 报错就没有了,可以正常使用sudo了

###8、其他 启动关闭GUI登录界面

systemctl disable lightdm