apt update -y && apt upgrade -y && reboot #更新系统并重启
一、系统安装
1、软件安装镜像选择“网络”镜像
2、选择debian桌面环境+xfce+web server+SSH server+标准系统工具
二、基础设置
没有开通root账号的SSH登录权限之前可以先登录普通账号,然后输入su及root密码进入root状态
1、debian 11换源(换清华源)
cp /etc/apt/sources.list /etc/apt/sources.list_bak #备份原有源文件
方法一:纯命令方式(整体复制、整体粘贴,不要变成一行)
cat > /etc/apt/sources.list << EOF
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free
EOF
2、debian 12换源(换中科源)
cp /etc/apt/sources.list /etc/apt/sources.list_bak #备份原有源文件
方法一:纯命令方式(整体复制、整体粘贴,不要变成一行)
cat > /etc/apt/sources.list << EOF
deb https://mirrors.ustc.edu.cn/debian/ bookworm main contrib non-free
deb-src https://mirrors.ustc.edu.cn/debian/ bookworm main contrib non-free
deb https://mirrors.ustc.edu.cn/debian/ bookworm-updates main contrib non-free
deb-src https://mirrors.ustc.edu.cn/debian/ bookworm-updates main contrib non-free
deb https://mirrors.ustc.edu.cn/debian/ bookworm-backports main contrib non-free
deb-src https://mirrors.ustc.edu.cn/debian/ bookworm-backports main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free
EOF
apt update #重新载入软件源
2、安装基础软件
apt install -y sudo -y wget -y curl -y fuse -y mtr -y socat -y vim -y zip -y unzip -y binutils -y xz-utils && sudo apt install -y vnstat && sudo systemctl enable vnstat && update-rc.d vnstat enable && sudo systemctl start vnstat #除基本插件外另安装vnsta流量监控工具
apt install pluma gdebi net-tools samba minidlna #系统软件安装工具
安装rustdesk远程桌面:https://rustdesk.com/zh/
安装搜狗输入法linux版:https://shurufa.sogou.com/linux
安装fsearch搜索工具:https://software.opensuse.org//download.html?project=home%3Acboxdoerfer&package=fsearch#manualDebian
安装fsearch时可能缺少libicu依赖,到这里http://ftp.de.debian.org/debian/pool/main/i/icu/下载对应的文件安装
3、让reboot命令生效
whereis reboot #找到并记住reboot的文件路径
找到/etc/profile 这个配置文件后,进入文件改写
nano /etc/profile
在文件最下方加入下面这句话
export PATH=$PATH:/usr/sbin
export PATH=$PATH:xxx(xxx是你的reboot文件的目录路径)
比如上面图片中我的reboot文件路径是/usr/sbin
source /etc/profile #重新加载使修改生效
换做shutdown也类似
whereis shutdown(找到shutdown的文件路径)
4、开通root用户SSH登录权限
方法一:nano /etc/ssh/sshd_config #编辑sshd_config文件
把“#PermitRootLogin prohibit-password”改成“PermitRootLogin yes”
把“#PasswordAuthentication yes”改成“PasswordAuthentication yes”
方法二:sshd_config-2.zip下载此文件解压并改名,然后替换掉原系统文件
方法三:通过https://airportal.cn/ 传递文件
reboot #重启系统
5、安装Xrdp远程桌面
apt install xrdp tigervnc-standalone-server #安装 XRDP 和 TigerVNC 服务器
systemctl start xrdp #启动XRDP服务
systemctl enable xrdp #把XRDP加入开机启动
sudo systemctl status xrdp #查看支行状态,出现绿色表示正常
dpkg-reconfigure xserver-xorg-legacy #选“任何用户”
vncconfig -nowin& #开启跨操作系统复制粘贴
reboot #重启系统生效
三、进阶设置(服务器方向)
1、安装KVM虚拟机
apt install qemu qemu-system libvirt-clients libvirt-daemon-system
apt install qemu-kvm virtinst bridge-utils virt-viewer
sudo adduser $USER libvirt #将root添加到相关用户组
apt install virt-manager -y #安装virt-manager图形界面
2、安装Cockpit面板(web远程管理)
sudo apt install cockpit #安装 cockpit 及其依赖项后,使用 systemctl 命令:
sudo systemctl start cockpit #启动cockpit服务
sudo systemctl enable cockpit #加入开机自启
sudo systemctl status cockpit #查看cockpit状态
apt install cockpit-machines cockpit-podman cockpit-pcp -y #安装虚拟机、podman(docker管理工具)、pcp监控项目
运行以下命令以允许 UFW 防火墙系统使用端口 9090:(如果需要的话)
sudo ufw enable
sudo ufw allow 9090/tcp
sudo ufw status
3、设置静态固定IP(设置成192.168.8.2)
ip addr #查看系统网卡,一般有lo、 eno1,网卡名每台电脑都不太一样
cp /etc/network/interfaces /etc/network/interfacesbak #备份interfacesbak原有配置文件
修改interfaces文件,把下面这些绿色的东西复制进去代替原有的所有内容
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
allow-hotplug eno1
iface eno1 inet static
address 192.168.8.2
netmask 255.255.255.0
gateway 192.168.8.1
修改/etc/resolv.conf,把下面这些东西复制进去代替原有的所有内容
# Generated by NetworkManager
search lan
nameserver 223.5.5.5
nameserver 233.6.6.6
reboot #重启系统生效
4、配置KVM虚拟机桥接网络
cp /etc/network/interfaces /etc/network/interfaces.bakup #备份interfacesbak原有配置文件
编辑interfaces文件
eno1是电脑物理网卡名称,223.5.5.5、223.6.6.6是阿里的DNS
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto br0
iface br0 inet static
address 192.168.8.2
netmask 255.255.255.0
gateway 192.168.8.1
dns-nameservers 223.5.5.5 223.6.6.6
bridge_ports eno1
bridge_stp off
bridge_fd 0
bridge_maxwait 0
用上面内容替换原来的所有内容
reboot #重启系统
sudo brctl show #如果出现一个br0表示成功
ip addr #关键查看br0是否有ip地址,且ip为你之前物理网卡的ip,而且这个时候你的物理网卡应该没有ip了,主机通过br0上网
apt update -y && apt upgrade -y && reboot #更新系统并重启
5、其它硬盘挂载
mkdir /ywd #在根目录下新建一个名为ywd的文件夹用来挂载其它硬盘
打开Cockpit后台192.168.8.2:9090
打开“存储”,安装“NFS支持”
然后点击“系统 9.10TiB”,然后点“9.10 TiB ntfs 文件系统”右边的挂载
挂载点填“/ywd”,也就是上面新建的文件夹
6、设置SMB共享
准备把ywd目录共享出去,10T硬盘挂载到了ywd目录
apt-get -y install libcups2 samba samba-common cups #安装相应包
systemctl start smbd #启动samba服务
systemctl enable smbd #启用开机启动
chmod 777 /ywd #设置目录权限,目录后面不要加“/”
smbpasswd -a yw #设置yw为共享用户名(debian系统本身存在这个用户名),按照提示输入密码,密码可以空
编辑/etc/samba/smb.conf
在最后添加以下内容:
[10T]
comment = share
path = /ywd
available = yes
browseable = yes
writable = yes
valid users = yw
dos charset = UTF8
unix charset = UTF8
display charset = UTF8
配置
smbpasswd -a 【用户名】 #然后输入密码
pdbedit -w -L #列出现有的Samba用户列表
vim /etc/samba/smb.conf
chmod 777 /share #给共享目录权限,其实给个600权限更安全
[disk1]
path = /share
writable = yes
write list = 【用户名】
valid users =【用户名】
display charset = UTF-8
unix charset = UTF-8
dos charset = UTF-8
设置服务:
查看服务状态 systemctl status smbd
开启服务 systemctl start smbd
重启服务 systemctl restart smbd
停止 systemctl stop smbd
共享选项及说明,按照需求合理配置
[共享名称]:共享中看到的共享目录名
comment = 共享的描述.
path = 共享目录路径(可以用%u、%m这样的宏来代替路径如:/home/share/%u)
browseable = yes/no指定该共享是否在“网上邻居”中可见。
writable = yes/no指定该共享路径是否可写。
read only = yes/no设置共享目录为只读(注意设置不要与writable有冲突)
available = yes/no指定该共享资源是否可用。
admin users = bobyuan,jane指定该共享的管理员,用户验证方式为“security=share”时,此项无效。
valid users = bobyuan,jane允许访问该共享的用户或组-“@+组名”
invalid users = 禁止访问该共享的用户与组(同上)
write list = 允许写入该共享的用户
public = yes/no共享是否允许guest账户访问。
guest ok = yes/no意义同“public”。
create mask = 0700指定用户通过Samba在该共享目录中创建文件的默认权限。0600代表创建文件的权限为rw-------
directory mask = 0700指定用户通过Samba在该共享目录中创建目录的默认权限。0600代表创建目录的权限为rwx------
systemctl restart smbd.service #重新加载SMB服务使修改生效
或者
reboot #重启系统
如果配置文件丢失可以用一下命令恢复,恢复最原始的配置文件
sudo apt purge samba-common samba
sudo apt install samba
7、设置NFS共享
准备把ywd目录共享出去,10T硬盘挂载到了ywd目录
apt install nfs-kernel-server nfs-common #安装nfs相关软件
chown nobody:nogroup /ywd
chmod 777 /ywd #赋予ywd目录相关权限
编辑/etc/exports文件,在其底部添加下面这句话,0/24表示1-255整个IP段都行
/ywd 192.168.8.0/24(rw,sync,insecure,no_subtree_check)
结束
systemctl restart nfs-kernel-server #重新加载nfs服务使修改生效
或者
reboot #重启系统
ro:指定目录只能以只读方式挂载
rw:授予对目录的读写权限
no_root_squash:这是一个非常危险的选项,它允许远程“ root”用户与主机的“ root”用户享有相同的特权
subtree_check:指定在导出目录而不是整个文件系统的情况下,主机应验证主机文件系统上文件和目录的位置
no_subtree_check:指定主机不应检查通过主机文件系统访问的文件的位置
sync:这只是确保主机使上传到共享目录的所有更改保持同步
async:忽略同步检查以提高速度
insecure:允许使用大于1024的端口号连接NFS
linux系统客户端挂载nfs共享的方法
apt install nfs-kernel-server nfs-common #安装nfs相关软件
sudo mkdir /var/10T-dz #本地新建一个/var/10T-dz文件夹,文件夹名字随便取
sudo mount -t nfs 192.168.8.2:/ywd /var/10T-dz #把8.2上面的nfs共享文件夹ywd挂载到本机/var/10T-dz文件夹
编辑/etc/fstab文件,在文件最下面加上下面两局话,把nfs挂载添加到开机启动
# <file system> <dir> <type> <options> <dump> <pass>
192.168.8.2:/ywd /var/10T-dz nfs defaults 0 0
sudo service nfs-kernel-server restart #重启nfs服务