linux服务器使用 云主机当然是好的,我个人用过腾讯云和阿里云的,都是新用户首单比较便宜,但是续费的时候就比较贵了。加上我个人使用的频率比较低,且购买的云主机配置都比较低。决定放弃购买云主机(不再薅羊毛啦)。
可惜我对硬件不是很了解,也懒得自己动手组装。在网上观望了一下,决定在工控机和小主机中间做一个选择。想想家里的环境也没有车间那么恶劣,索性买个低功耗的小主机算了,毕竟颜值稍微高一点。
家中是电信的宽带,打个电话申请一下还是比较方便的。不过IP不是固定的,如果重启了路由,IP就会变化,且80端口是不开放的。
GKmini20220504
没啥经验,直接网上找个销量比较好的就买了,如下配置,约1100元。
品牌:零刻GKmini (单网口)
cpu: J4105,4核4线程
内存:8G DDR4
SSD:512G
内置的是ubuntu desktop 版本的系统。
ubuntu server22.04下载ISO镜像文件
Get Ubuntu Server | Download | Ubuntu
我下载的是
22.04LTS
UltraISO制作ubuntu安装u盘启动盘
安装ubuntu server系统,官网上说的很清楚:
GKmini按F7,然后选择USB启动,然后按照官网提示一步步做就可以了。
root默认是不允许ssh的。
sudo adduser xuqiudongvim /etc/passwd, 确保刚刚的用户拥有:/bin/bash,没有则加上。vim /etc/ssh/sshd_config添加 AllowUsers xuqiudongservice ssh restart测试:局域网ip远程登录成功;路由端口转发到此ip,通过公网ip也可以ssh登录成功。
su root 以及挂载/dev/sda2新建的用户
xuqiudong赋予sudo的权限。
授予新建用户 xuqiudong以sudo权限s
新建xuqiudong文件夹,把/dev/sda2 挂载到此文件夹,并把文件的拥有者改为xuqiudong
以下是部分操作:
1.赋予
sudoer文件写权限sudo chmod u+w /etc/sudoers2.编辑
sudoers文件,给对应的用户添加sudo权限sudo vi /etc/sudoers找到如下并参照书写,这里以给用户A添加sudo权限:
root ALL=(ALL:ALL) ALL添加
username ALL=(ALL:ALL) ALL3.撤销
sudoers的写权限(否则异常)sudo chmod u-w /etc/sudoers
新建一个文件夹xuqiudong赋给用户xuqiudong, 以后就在这个文件夹下操作吧。
sudo mkdir xuqiudong
sudo chown -R xuqiudong xuqiudong
安装系统的时候不知道怎么多出来个分区 /dev/sda2 (device ),而且490多G的空间都在它下面,想了下个还是把挂载到文件夹xuqiudong吧:
sudo mount /dev/sda2 /xuqiudong
ufw官网说的比较清楚了。而且22.04系统装好了默认就安装了
ufw,只是没有启用而已。
sudo ufw allow 22先开放22端口。
本来不准备更换源的,感觉直接在浏览器打开
ubuntu的还是挺快的。但是在安装几个依赖的时候,下载速度好像比较慢。 先替换为清华源试试。
/etc/apt/sources.listsources.list 文件前面加上清华源信息:deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
2025-04
# 备份原有源
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
# 替换为阿里云源(以 Ubuntu 22.04 为例)
sudo sed -i 's|http://.*archive.ubuntu.com|https://mirrors.aliyun.com|g' /etc/apt/sources.list
sudo apt update
替换后如下:
# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb https://mirrors.aliyun.com/ubuntu jammy main restricted
# deb-src https://mirrors.aliyun.com/ubuntu jammy main restricted
## Major bug fix updates produced after the final release of the
## distribution.
deb https://mirrors.aliyun.com/ubuntu jammy-updates main restricted
# deb-src https://mirrors.aliyun.com/ubuntu jammy-updates main restricted
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb https://mirrors.aliyun.com/ubuntu jammy universe
# deb-src https://mirrors.aliyun.com/ubuntu jammy universe
deb https://mirrors.aliyun.com/ubuntu jammy-updates universe
# deb-src https://mirrors.aliyun.com/ubuntu jammy-updates universe
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb https://mirrors.aliyun.com/ubuntu jammy multiverse
# deb-src https://mirrors.aliyun.com/ubuntu jammy multiverse
deb https://mirrors.aliyun.com/ubuntu jammy-updates multiverse
# deb-src https://mirrors.aliyun.com/ubuntu jammy-updates multiverse
## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb https://mirrors.aliyun.com/ubuntu jammy-backports main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu jammy-backports main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu jammy-security main restricted
# deb-src https://mirrors.aliyun.com/ubuntu jammy-security main restricted
deb https://mirrors.aliyun.com/ubuntu jammy-security universe
# deb-src https://mirrors.aliyun.com/ubuntu jammy-security universe
deb https://mirrors.aliyun.com/ubuntu jammy-security multiverse
# deb-src https://mirrors.aliyun.com/ubuntu jammy-security multiverse
sudo apt-get update, sudo apt-get upgrade