丢了可惜,用起来不好用,下面一起来改造成一台测试服务器吧
制作启动盘
下载ubuntu server:https://cn.ubuntu.com/download/server/step1
制作启动盘:https://www.sysgeek.cn/make-ubuntu-usb-flash-drive/
mac上使用 balenaEtcher 工具制作:https://etcher.balena.io/
安装系统
插入U盘到笔记本
启动按F2进入BIOS
按F8选择插入的U盘启动
系统自动安装,设置密码和配置一些选项
连接网络
以太网直接插网线
wifi需要配置
cd /etc/netplan
ls
vi *-cloud-init.yaml # *改成你目录下的配置文件
# 按i编辑文件配置wifi
network:
ethernets:
enp1s0:
dhcp4: true
version: 2
wifis:
你的wifi接口: # 使用 ip link show 查看你的wifi接口,
addresses:
- 192.168.0.100/24 #根据你的内网配置静态IP
routes:
- to: default
via: 192.168.0.1 #根据你的内网配置网关
nameservers:
addresses:
- 8.8.8.8
- 8.8.4.4
dhcp4: no
access-points:
"wifi的ssid":
password: "wifi的密码"
# 按esc退出编辑模式,输入 :wq 保存退出
sudo netplan apply #应用配置
reboot #重启一下吧
配置笔记本不进入睡眠模式
编辑 logind.conf 文件: 打开终端并编辑
/etc/systemd/logind.conf
文件:sudo vi /etc/systemd/logind.conf
修改 HandleLidSwitch 设置: 在文件中找到
HandleLidSwitch
,并将其设置为ignore
。如果该行被注释掉了(以#
开头),请去掉注释并修改:HandleLidSwitch=ignore
保存并退出:按esc退出编辑模式,输入 :wq 保存退出 。
重启 systemd-logind 服务: 使更改生效,重启
systemd-logind
服务:sudo systemctl restart systemd-logind
完成以上步骤后,合上盖子时,Ubuntu 服务器将不会进入睡眠模式。
配置关闭文本模式的显示器
通过编辑 GRUB 配置文件来设置屏幕在一段时间不活动后自动关闭,这仅影响物理显示器的显示状态,不会影响远程连接(如 SSH)的使用。远程连接时,屏幕不会因为远程活动而重新点亮。
编辑 GRUB 配置文件:
sudo nano /etc/default/grub
找到以下行并修改:
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
修改为:
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash consoleblank=60"
这里的
60
表示 60 秒不活动后屏幕将自动关闭。你可以根据需要调整时间。更新 GRUB 配置:
sudo update-grub
重启系统:
sudo reboot
配置国内镜像源
不同的系统版本参考:
https://developer.aliyun.com/mirror/ubuntu?spm=a2c6h.13651102.0.0.3e221b11hLE2AJ
我这里是24.04
vi /etc/apt/sources.list
编辑文件配置
# Ubuntu sources have moved to /etc/apt/sources.list.d/ubuntu.sources
deb https://mirrors.aliyun.com/ubuntu/ noble main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ noble main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ noble-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ noble-security main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ noble-updates main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ noble-updates main restricted universe multiverse
# deb https://mirrors.aliyun.com/ubuntu/ noble-proposed main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ noble-proposed main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ noble-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ noble-backports main restricted universe multiverse
sudo apt update
设置root用户登录
在 Ubuntu 服务器上,默认情况下是禁用 root
用户通过 SSH 登录的。你可以通过以下步骤启用 root
用户的 SSH 登录:
编辑 SSH 配置文件: 打开终端并编辑
/etc/ssh/sshd_config
文件:sudo nano /etc/ssh/sshd_config
允许
root
登录: 找到以下行,并将其修改为yes
:PermitRootLogin yes
如果该行被注释掉了(以
#
开头),请去掉注释并修改。保存并退出: 保存文件并退出编辑器(在 nano 中,按
Ctrl+O
保存,然后按Ctrl+X
退出)。重启 SSH 服务: 使更改生效,重启 SSH 服务:
sudo systemctl restart ssh
设置
root
用户密码(如果还没有设置): 确保root
用户有一个密码:sudo passwd root
完成以上步骤后,你应该能够使用 root
用户通过 SSH 登录到你的 Ubuntu 服务器。
请注意,启用 root
用户的 SSH 登录存在安全风险,建议仅在必要时启用,并在不需要时禁用。更安全的做法是使用普通用户登录,然后使用 sudo
提升权限。
安装docker(可选)
参考:https://developer.aliyun.com/mirror/docker-ce?spm=a2c6h.13651102.0.0.73cf1b11OQYeaW
docker镜像网络解决方案
加前缀,具体参考:https://github.com/kubesre/docker-registry-mirrors
反向代理
参考:https://gofrp.org/zh-cn/docs/overview/
mac电脑安装双系统
参考:https://zhuanlan.zhihu.com/p/22517931
需要注意的细节:
ubuntu server 选择custom storge layout安装,千万不要选择整盘,会把mac系统覆盖掉!
挂载分区好的磁盘到根目录/,文件系统为 EXT4,挂载点为
/
然后安装配置ubuntu server即可
开机按住option,可以选择进入哪个系统