本文最后更新于 2024年7月27日 晚上
@TOC
系统概述 需求分析
作为影迷,有一定的观影需求,同时也有兼职剪辑。考虑苹果新M1的macbook air的剪辑配置,唯一缺陷就是容量太小又不可拓展,所以搭配nas作为存储延伸。
为何选择Debian,因为作为计算机专业,折腾的过程也是学习的过程,linux可以有更多功能选择,不需要装虚拟机就能All in One (boom) ,可以做服务器,我写了一个网站可以挂在上面让大家访问。也可以做软路由,安装***等转发流量就可以全局。
该教程主要为提供思路,记录一些配置过程使用的命令,也作为自己备忘录,具体详细过程无法一一描述,若有建议或者疑问,欢迎大家一起讨论
功能实现
挂载硬盘作为nas存储视频等文件
部署网站供大家访问
作为软路由转发流量
系统配置简介
梅捷N3150L主板
CPU是N3150(4核6W支持AES 稍弱于J1900但可硬解4k)
4G内存1600HZ
8+14T机械硬盘
U盘16G作为系统盘
TP-link WiFi6的路由器进行DDNS和端口转发
Debian10的镜像下载与安装
镜像链接:Debian原网站镜像
U盘工具:Ventory
用另一个U盘作为系统盘(可节约一个SATA接口
系统配置准备 oh my zsh安装 装机第一件事就是要看得舒服
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 apt-get install zsh#安装zsh作为shell chsh -s /bin/zsh#激活环境 sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"# 个性化配置 # 可以记住历史目录,不需要一直cd 如果卡住可能是需要认证rsa.pub的公钥 ssh-kengen生成一下,添加到github的设置->SSH and GPG keys git clone https://github.com/joelthelion/autojump cd autojump ./install.py git clone https://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions#自动补全命令 git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting#语法高亮 vim ~/.zshrc 把插件加到文件中
vim ~/.zshrc配置文件的plugins 加上autojump zsh-syntax-highlighting zsh-autosuggestions生效,最后再source ~/.zshrc重新编译zsh,此时autojump已经生效。其他同理
ssh远程访问 1 2 3 4 cd /etc/ssh nano sshd_config //添加一行 PermitRootLogin yes //ctrl x保存退出
将#PasswordAuthentication no的注释去掉,并且将NO修改为YES 完成上述更改后,请重新启动SSH服务器:
1 /etc/init.d/ssh restart 或者service ssh start
添加开机自启动
免明文登陆 1 2 ssh-keygen -t rsa ssh-copy-id -i ~/.ssh/id_rsa root@ipp
开机自动登录root
进入root用户,编辑文件/lib/systemd/system/getty@.service1 2 nano /lib/systemd/system/getty@.service //ctrl x保存
设置字段ExecStart
1 2 3 ExecStart=-/sbin/agetty --autologin root --noclear %I $TERM//添加或修改这行数据 //ctrl x保存
白嫖cloudflare的服务穿透内网,前提是需要域名 参考链接
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 curl -L 'https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64' -o /usr/bin/cloudflared chmod +x /usr/bin/cloudflared cloudflared tunnel login# 然后会让打开浏览器登陆验证 A browser window should have opened at the following URL: https://dash.cloudflare.com/arg***# 注意:授权一次只能选择一个网站。如果存在多个不同域名的网站,请授权完成后不要关闭网页,点击第二个、第三个要授权的域名,进行多次授权。 cloudflared tunnel create <隧道名字>#比如 webserver-1# 然后有uuid要记下 Tunnel credentials written to /root/.cloudflared/12345-123-123-123-12345.json. cloudflared chose this file based on where your origin certificate was found. Keep this file secret. To revoke these credentials, delete the tunnel. Created tunnel webserver-1 with id 12345-123-123-123-12345 ......
rclone使用 rclone不仅可以挂载网盘还能挂FTP、sftp等等,当作同步的工具也很不错,这里介绍下sftp的挂载
1 2 3 4 5 6 7 8 9 10 # 一键安装最新的版本,自带的比较老 sudo -v ; curl https://rclone.org/install.sh | sudo bash ssh-keygen -q -t rsa -b 4096 -C "rclone key" -N "" -f ~/.ssh/rclone cd ~/.ssh/ cat rclone* > rclone-merged # 配置除了地址账号密码这些一切都默认,除了下面这个 key_file> ~/.ssh/rclone-merged
1 2 3 apt install fuse3 rclone mount -vv alist: /alist --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000 --vfs-cache-mode writes --daemon
Tailscale
需要客户端,不是很方便1 2 curl -fsSL https://tailscale.com/install.sh | sh tailscale up
图形化界面卸载 图形化界面比较占内存,而我多数时候SSH也用不上,所以将其卸载
1 2 3 4 apt autoremove gdm3 apt autoremove --purge gnome* //reboot重启
网路配置
向运营商申请外网IP,一般打电话就行(现在可能不容易了)
申请一个域名,我用的阿里的
因为拨号上网IP不会固定,所以需要路由器的DDNS通过域名绑定IP访问
在路由器的虚拟服务器上面设置端口转发,可以转发被禁的80或者443端口
编辑设置:vim /etc/network/interfaces
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 source /etc/network/interfaces.d/*# # The loopback network interface auto lo iface lo inet loopback# The primary network interface allow-hotplug enp2s0# # iface enp3s0 inet dhcp # iface enp3s0 inet loopback # iface enp2s0 inet static address 192.168.1.107# address 192.168.101.111 netmask 255.255.255.0 gateway 192.168.1.1 auto enp2s0
网络自动重连 写了个脚本自动检测网络,断开则重连,下面是环境需要
1 2 3 pip install selenium apt install chrome-driver apt-get install -y libnss3-dev libgconf-2-4 xvfb
磁盘相关命令
磁盘分区 1 2 3 4 fdisk -l //查看所有磁盘信息 fdisk /dev/sdb //对sdb磁盘进行分区
若磁盘大于2T,需要parted命令分区 1 2 3 4 5 parted /dev/sdb //分区磁盘sdb mklabel gpt //parted命令只能针对gpt格式的磁盘进行操作 mkpart ext4 0% 1.5T//将0到1.5T划为一个分区 (parted) p //查看所有磁盘信息 mkfs -t ext4 /dev/sdb1 //格式化分区sdb1
查看当前已挂载磁盘
挂载磁盘1 2 mount /dev/sdb1 /mnt/fodername1 //将磁盘sdb1挂载到相同的逻辑文件/data下,卸载则换为umount
开机自动挂载磁盘1 2 3 4 5 6 7 vim /etc/fstab //打开fstab文件写入命令 UUID=b394c406-5c0e-4e16-9d80-a212c34a8d32 /mnt ext4 defaults 0 /dev/sdb1 /mnt/Film ext4 defaults 0 /dev/sdb2 /mnt/Material ext4 defaults 0
磁盘通电时间等详细参数1 2 3 4 apt-get install smartmontools //下载磁盘测试工具 smartctl -A /dev/sdb //测试sda磁盘
磁盘读写速度1 2 hdparm -Tt /dev/sda //sda换为测试的硬盘
磁盘清理查看1 2 3 apt install ncdu ncdu / --exclude /foldername //可按照文件占用大小排序查看
虚拟环境 Docker安装 1 2 curl -fsSL https://get.docker.com -o get-docker.sh sh get-docker.sh
conda 比起virtualenv,conda最大优点是可以自动安装指定新版本python,不用本地环境
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 wget -4 -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-py39_4.9.2-Linux-x86_64.sh# 第二步安装 sh Miniconda3-py39_4.9.2-Linux-x86_64.sh -b -p /root/miniconda3# 第三步配置conda镜像 export PATH=/root/miniconda3/bin:$PATH# alias ohmyzsh="mate ~/.oh-my-zsh" vim ~/.zshrc# # >>> conda initialize >>> # !! Contents within this block are managed by 'conda init' !! __conda_setup="$('/root/miniconda3/bin/conda' 'shell.zsh' 'hook' 2> /dev/null)" if [ $? -eq 0 ]; then eval "$__conda_setup" else if [ -f "/root/miniconda3/etc/profile.d/conda.sh" ]; then . "/root/miniconda3/etc/profile.d/conda.sh" else export PATH="/root/miniconda3/bin:$PATH" fi fi unset __conda_setup# <<< conda initialize <<< source ~/.zshrc conda create -n py39 python=3.9 conda activate py39
Jupyter lab 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 conda install jupyterlab# 创建密码 jupyter lab password# 生成配置文件 jupyter lab --generate-config# 编辑文件 vim /root/.jupyter/jupyter_lab_config.py# c.ServerApp.root_dir = '' # 设置默认工作目录 c.ServerApp.ip = '*' # 允许访问此服务器的 IP,星号表示任意 IP c.ServerApp.password = '****************' # 之前生成的密码 hash 字串在/root/.jupyter/jupyter_server_config.json, 粘贴进去 c.ServerApp.open_browser = False # 运行时不打开本机浏览器 c.ServerApp.port = 8888 # 使用的端口,随意设置,但是要记得你设定的这个端口 c.ServerApp.enable_mathjax = True # 启用 MathJax c.ServerApp.allow_remote_access = True # 允许远程访问 c.ServerApp.allow_root = True # 允许root权限
Jellyfin安装配置 1 2 3 docker pull nyanmisaka/jellyfin docker run -d -p 8096:8096 -v /jellyfin/config:/config -v /mnt/AllMedia:/media -v /mnt/Other:/Film3 -v /mnt/Film:/Film2 --restart=always nyanmisaka/jellyfin
-p 后面是jellyfin服务的端口号,安装时可以指定,这里使用默认的8096;
-v 后面是指定的配置路径,比如 /mnt/film 就是我原来的影音物理路径,/media就是jellyfin的映射路径
可以通过http://本地ip:8096 来访问jellyfin服务了,后期也可以转发端口在外网用域名访问
Samba安装配置 Debian终端
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 apt install samba nano /etc/samba/smb.conf //最后加上 [share] comment = Provides Filesystem For Anyone path = /share browsable = yes create mask = 0777 directory mask = 0777 read only = no writable = yes guest ok = yes public = yes forceuser=root forcegroup=root //创建共享目录并设置权限 mkdir /share chmod -R 0777 /share //客户端 apt install smbclient //重启服务 systemctl restart smbd.service && systemctl restart nmbd.service
Windows终端
打开我的电脑,地址栏输入 \192.168.. (NAS所在局域网IP)会看到几个文件名
注意,window上面映射地址不是挂载地址,而必须与上面文件累的path路径名称(/share)完全一致,包括大小写,不然会提示拼写错误
iPad也可用nPlayer的SMB配置访问这个地址
NFS Samba配置太繁琐了,现在也不用Windows
1 2 3 4 5 6 7 8 9 10 11 12 13 apt-get install nfs-kernel-server apt-get install nfs-common #MAC客户端自带,可不用安装 vim /etc/exports# 添加 *代表所有ip访问 /mnt *(rw,fsid=0,sync,no_root_squash,no_subtree_check,insecure) /mnt/Other *(rw,sync,no_root_squash,no_subtree_check,insecure) /mnt/AllMedia *(rw,sync,no_subtree_check,no_root_squash,insecure) systemctl restart nfs-kernel-service#重启nfs服务# Mac挂载命令 mount -t nfs -o nolocks 192.168.101.111:/mnt /Users/gawaintan/NAS
注意:*代表所有ip都允许访问,/mnt作为父级目录fsid=0只能出现一次,no_root_squash授予root权限,谨慎使用,insecure为了我避免客户端permission denied
网口 我买了块千兆网卡,但是装机插另一个网口了,导致开机默认不启动 所以需要设置一下
1 2 3 4 5 6 7 vim /etc/network/interfaces auto enp2s0 #设置网卡自启动 iface wlan0 inet static #设置网卡使用静态IP address 192.168.101.111 netmask 255.255.255.0 gateway 192.168.101.1
安装配置aria2 …不怎么用了
mysql安装配置 在Debian的默认存储库中不可用,MariaDB是Debian 10中的默认数据库系统,我将介绍如何安装mysql8
1 2 3 4 5 6 7 8 wget http://repo.mysql.com/mysql-apt-config_0.8.13-1_all.deb # 下载完成后,以具有sudo 权限的用户身份安装发行包: apt install ./mysql-apt-config_0.8.13-1_all.deb# 选择MySQL Server & Cluster(当前选择:mysql-8.0)确定安装 # 通过运行以下命令更新包列表并安装MySQL服务器包: sudo apt update sudo apt install mysql-server
等待安装,完成后用 systemctl status mysql检验安装是否成功 运行mysql_secure_installation设置密码,按照喜好选择Y mysql -u root -p输入设置,密码登陆
软路由流量分发 其他命令 局域网网速测试 1 2 3 4 5 6 # Linux端 apt-get install iperf3 iperf3 -s#将linux作为服务器端# windows端,官网下载iperf3,cmd命令到该目录下 Iperf3 -c 192.168.101.119
网络端口查看 1 2 3 4 apt-get install net-tools #新的系统可能不带该命令,也无法通过install ifconfig下载,只能用该命令 ethtool enp2s0#查看网口信息
screen命令的使用 方便切换进程,可以在一个进程未完成的时候将其挂起
1 2 3 4 5 screen screen -ls#展示所有进程 screen -d id#detach该进程,可用切换远程终端访问 screen -r id #进入该进程
定时自动关机 因为寝室0:30停电,然后设置了主办来电自动开机
1 2 3 4 vim /etc/crontab# 最后添加一行代表0:22自动关机 22 0 * * * root /sbin/halt
开机启动管理工具 1 2 3 apt-get install sysv-rc-conf sysv-rc-conf --level 345 mysql on #mysql可换其他服务sysv-rc-conf# 可查看选择启动权限
小工具集合
htop用于观察系统占用资源情况
ncdu /目录 可将该目录下所有文件从大到小排序
Alist https://alist.nn.ci/zh/guide/install/script.html
1 2 curl -fsSL "https://alist.nn.ci/v3.sh" | bash -s install