Linux | 无头 Linux 服务器安装和设置

注:本文为 “Headless Linux” 相关文章合辑。

机翻未校。


How to Install and Set Up Headless Linux Server

如何安装和设置无头 Linux 服务器

Winnie Ondara
Last Updated: January 31, 2023

A vast majority of Linux users are familiar with a Linux desktop PC which provides a graphical environment with which you can interact with the system. However, unlike a Linux desktop, a headless server is an operating system that runs without a GUI (Graphical User Environment).

大多数 Linux 用户都熟悉带有图形界面的 Linux 桌面电脑,用户可以通过图形环境与系统进行交互。然而,与 Linux 桌面不同,无头服务器是一种没有图形用户界面的操作系统。

It is installed on hardware that is not connected to any peripheral device such as a monitor, keyboard, or mouse during its operation (although these are required during the initial setup).

在运行过程中,它安装在未连接任何外设(如显示器、键盘或鼠标)的硬件上(尽管在初始设置期间需要这些设备)。

In most cases, headless servers are remotely accessed and administered on the command line via the SSH protocol using SSH clients.

在大多数情况下,无头服务器通过 SSH 协议使用 SSH 客户端 在命令行上进行远程访问和管理。

The main goal of headless servers is to provide access to crucial services such as web and database services to clients or users. Headless servers are mostly found in data centers and run enterprise or production workloads.

无头服务器的主要目标是为客户端或用户提供对关键服务(如 Web 和数据库服务)的访问权限。无头服务器主要出现在数据中心,用于运行企业或生产工作负载。

Pros of a Headless Linux System

无头Linux系统的优点

Graphical installations are usually associated with high resource overhead. Applications such as the Firefox browser, and GIMP are resource-intensive programs and end up hogging lots of system memory and CPU.

图形安装通常与高资源开销相关联。像 Firefox 浏览器和 GIMP 这样的应用程序是资源密集型程序,会占用大量系统内存和 CPU。

This impacts the performance of critical production workloads or applications which have to make do with the few resources that are available.

这会影响关键生产工作负载或应用程序的性能,因为它们只能使用有限的资源。

Since there are no graphical components on headless servers, most of the resources are accorded to critical applications which results in optimized performance.

由于无头服务器上没有图形组件,大多数资源都被分配给关键应用程序,从而实现了优化的性能。

Headless servers ensure critical enterprise workloads run smoothly since there is no competition for system resources with other non-critical applications. It’s, therefore, efficient to host your applications on a headless server since there are no fancy graphical applications that will impact performance.

无头服务器确保关键企业工作负载顺利运行,因为它们不会与其他非关键应用程序争夺系统资源。因此,在无头服务器上托管应用程序是高效的,因为没有华丽的图形应用程序会影响性能。

Installation of a Headless Linux Server

安装无头 Linux 服务器

The installation of a headless Linux server is similar to installing a Linux OS with a graphical environment. Most Linux distributions such as Ubuntu, Rocky Linux, AlmaLinux, and Debian provide a minimal ISO installation image which has a small memory footprint and provides only the essential tools to install the operating system.

无头 Linux 服务器的安装过程与安装带有图形环境的 Linux 操作系统类似。大多数 Linux 发行版,如 Ubuntu、Rocky Linux、AlmaLinux 和 Debian,都提供了一个最小化的 ISO 安装镜像,该镜像占用内存小,仅提供安装操作系统的基本工具。

This is different from a full DVD ISO which is usually quite large – mostly gigabytes in memory – and provides all the graphical tools and utilities.

这与通常很大的完整 DVD ISO 不同,后者通常占用数 GB 的内存,并提供所有的图形工具和实用程序。

Download Linux ISO Image

下载 Linux ISO 映像

For this guide, we will demonstrate how you can get started with installing the Debian 11 server (Debian Bullseye). So, head over to the Debian Download Page and grab the net installer ISO which is roughly 400MB in size.

在本指南中,我们将展示如何开始安装 Debian 11 服务器(Debian Bullseye)。因此,请前往 Debian 下载页面,下载大约 400MB 的网络安装程序 ISO。

Also, note you can use any Linux distribution ISO image to set up a headless server.

请注意,您可以使用任何 Linux 发行版的 ISO 镜像来设置无头服务器。

Create a Bootable Linux USB Drive

创建可启动的 Linux USB 驱动器

Once you have downloaded the ISO image, the next step is to burn the ISO to a USB drive which will be used as the bootable medium.

下载 ISO 镜像后,下一步是将 ISO 镜像刻录到 USB 驱动器,该驱动器将用作可引导介质。

You can create a LiveUSB medium using USB creator tools or you can also do this on the command line using the dd command as shown.

您可以使用 USB 创建工具 创建 LiveUSB 介质,也可以使用命令行中的 dd 命令来完成此操作。

$ dd if=~/Downloads/debian-11.6.0-amd64-netinst.iso of=/dev/sdx bs=4M status=progress

Installing Linux Headless Server Using USB Drive

使用 USB 驱动器安装 Linux 无头服务器

With the bootable USB drive in place, plug it into the bare metal server which should, at first, be connected to a monitor and keyboard for the initial setup.

准备好可引导 USB 驱动器后,将其插入裸金属服务器,该服务器最初应连接显示器和键盘以进行初始设置。

Power on the server and navigate to the BIOS settings. Ensure that the USB drive is first on the boot order priority. Save and changes and continue booting.

打开服务器电源并进入 BIOS 设置。确保 USB 驱动器是启动顺序中的第一优先级。保存更改并继续启动。

Once the system powers on, you will be presented with a list of menu options. Here, we will go with Graphical Install which provides a graphical installation method to make work easier.

系统启动后,您将看到一个菜单选项列表。在这里,我们将选择 图形安装,它提供了一种图形化安装方法,使工作更轻松。

在这里插入图片描述

Debian 图形安装

The next steps will require you to make a couple of selections. These include choosing the installation language, timezone, keyboard layout, hostname, creating a regular user account and root account as well as partitioning the hard drive.

接下来的步骤需要您进行一些选择,包括选择安装语言、时区、键盘布局、主机名、创建普通用户账户和根账户,以及分区硬盘。

Lastly, you will be presented with a ‘Software Selection’ step that provides a wide array of desktop environments to choose from.

最后,您将看到一个“软件选择”步骤,提供多种桌面环境供您选择。

But since our mission is to install a headless server, we will only select the ‘SSH Server’ and ‘Standard system utilities’ options and click ‘Continue’. This ensures that we only install the necessary packages required for the headless server to run.

但由于我们的目标是安装无头服务器,因此我们只会选择“SSH 服务器”和“标准系统工具”选项,然后点击“继续”。这确保我们只安装无头服务器运行所需的必要软件包。

在这里插入图片描述

Debian 软件选择

From here onwards, proceed with the Debian installation till the end and reboot the system.

从这里开始,继续完成 Debian 的安装,直到最后重启系统。

Debian Post-Installation

Debian 安装后

Upon rebooting your server you will see the following screen. The first option is already pre-select, so simply press ENTER.

重新启动服务器后,您将看到以下屏幕。第一个选项已经被预选,因此只需按 ENTER

在这里插入图片描述

启动 Debian Linux

On the login screen, provide your username and password and press ENTER on both occasions to access the system. Evidently, there’s no graphical environment, and going forward, access to the system will be on the command line via the SSH protocol.

在登录屏幕上,输入用户名和密码,然后两次按 ENTER 以访问系统。显然,没有图形环境,今后将通过 SSH 协议在命令行上访问系统。

在这里插入图片描述

Debian 登录

Testing Remote Connection to Headless Server

测试与无头服务器的远程连接

Speaking of SSH, we need to confirm if the service is running. To verify this, switch to the root user

说到 SSH,我们需要确认服务是否正在运行。为此,请切换到 root 用户

$ su -

Then run the following command to check the running status of SSH.

然后运行以下命令以检查 SSH 的运行状态。

# systemctl status sshd

The following output confirms that the service is running. Be sure to enable the service to autostart on boot.

以下输出确认服务正在运行。请确保启用该服务以在启动时自动启动。

# systemctl enable sshd

在这里插入图片描述

检查 SSH 服务器

To test remote connectivity to the server, first, check its IP address by running the ip command:

要测试对服务器的远程连接,请首先通过运行 ip 命令来检查其 IP 地址:

# ip a

Locate your active interface – in this case enp0s3 – and check the address prefixed by the ‘inet’ directive. In our case, the IP of our server is 192.168.2.113.

找到您的活动接口(在本例中为 enp0s3),并检查以“inet”开头的地址。在我们的例子中,服务器的 IP 地址是 192.168.2.113

Next, head over to a remote PC within the LAN and try to ping the server. If you get positive ping results, this implies that the server is reachable.

接下来,在局域网内的远程计算机上尝试 ping 服务器。如果收到积极的 ping 结果,这意味着服务器是可达的。

Finally, you can use an SSH client like PuTTY to access and login into the server.

最后,您可以使用 SSH 客户端,如 PuTTY,来访问并登录服务器。

在这里插入图片描述

SSH 连接到远程无头服务器

Perfect! This confirms that we have successfully installed and set up a Headless Linux system. At this point, you can now disconnect the monitor, keyboard, and mouse since the server will now be accessed and managed remotely via the SSH service.

完美!这证实我们已成功安装并设置了一个无头 Linux 系统。此时,您可以断开显示器、键盘和鼠标,因为服务器将通过 SSH 服务进行远程访问和管理。

Conclusion

结论

In this guide, we have demonstrated how you can go about setting up a headless Linux system using Debian 11. The procedure for accomplishing the same feat is similar in other distributions, of course with slight variations here and there.

在本指南中,我们展示了如何使用 Debian 11 设置无头 Linux 系统。在其他发行版中完成相同任务的步骤大致相似,当然会有一些细微的差异。

But rest assured, the minimal ISO provided by a Linux distribution is all you need to successfully install and set up a headless server.

但请放心,Linux 发行版提供的最小化 ISO 镜像足以成功安装并设置无头服务器。


在 ubuntu 服务器上使用 Chrome Headless

Shuangquan IP 属地:湖北
2017.08.24 12:08:31

Install Google Chrome

几个月前发布的 Chrome 59 beta 推出了 headless 模式。原生的 Chrome,更好的通用性,更快的速度…… 似乎是时候和 Phantomjs、Ghost 们说再见了。搜索一圈发现大多数人都是在桌面版的 linux 或者 mac 上尝了鲜,然而要将 Chrome 用于 web2.0 爬虫的话,还是得在服务器版的 linux 中运行。

安装 chrome

测试环境: Ubuntu 16.04 如果是桌面版的 ubuntu,直接到官网下载最新版 chrome 安装就好。对于服务器版的 chrome,只能用命令行安装服务器版本 Chrome _

sudo apt-get install libxss1 libappindicator1 libindicator7
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome*.deb  # Might show "errors", fixed by next line
sudo apt-get install -f

测试

启动 chrome

google-chrome --headless --remote-debugging-port=9222 https://chromium.org --disable-gpu

这里是使用 headless 模式进行远程调试,ubuntu 上大多没有 gpu,所以 --disable-gpu 以免报错。之后使用另一个命令行访问本地的 9222 端口:

curl http://localhost:9222

能够看到调试信息应该就是装好了。

下载 chromedriver

chromedriver 提供了操作 chrome 的 api,是 selenium 控制 chrome 的桥梁。[下载链接] https://sites.google.com/a/chromium.org/chromedriver/downloads] 查看最新的 Chrome 版本。下载并解压:

wget https://chromedriver.storage.googleapis.com/2.31/chromedriver_linux64.zip
unzip chromedriver_linux64.zip

运行
这里我们直接用 selenium 来控制 chrome 在 headless 模式下运行:

from selenium import webdriverchrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')client = webdriver.Chrome(chrome_options=chrome_options, executable_path='/home/chromedriver')  # 如果没有把 chromedriver 加入到 PATH 中,就需要指明路径client.get("https://jiayi.space")  # 替换为实际的 URL
content = client.page_source.encode('utf-8')print(content)
client.quit()

当然这里是打印出了页面的内容。之后我找了一个以前爬过的网站来试试,它做了 js 加密重定向,而且检测到 phantomjs 请求直接丢弃。结果 Chrome headless 成功拿到渲染后的页面。基于简单的测试后,感觉一切都还很完美。还不知道在生产环境下有没有什么 bug,遇到再更新咯。

最后编辑于 :2018.06.05 11:02:44


via:

  • How to Install and Set Up Headless Linux Server
    https://www.tecmint.com/setup-headless-linux-server/

  • 在 ubuntu 服务器上使用 Chrome Headless - 简书
    https://www.jianshu.com/p/4ede64b7ccdb

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/bicheng/76031.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

AI赋能数据库管理“最后一公里”,融合架构重塑数据库承载成本效能——zCloud 6.7与zData X 3.3正式发布

点击蓝字 关注我们 在数据驱动的新时代,数据库的多元化和智能化已成不可逆的趋势。3月31日,云和恩墨以“奇点时刻数智跃迁”为主题举办线上发布会,云和恩墨创始人兼总经理盖国强、公司数据库和生态产品群总经理熊军共同带来 zCloud 6.7与 zD…

I have something to say about Vue Node.js

关于Vue Node.js,我真的说了很多次了,让我难以理解为啥这么粗糙的东西能流行一起。真疯狂的世界。 vue让感觉就像玩猫德一样的,如此的疯狂,天哪。睡觉了 Node.js v13 window7_nodejsv13-CSDN博客

【橘子大模型】使用streamlit来构建自己的聊天机器人(下)

一、简介 我们之前完成了一个简易的聊天机器人,但是还留下了一些问题没有解决,比如如何开启新的会话。如何切换session_id,如何把对话做成流式的输出。这些我们就会在今天来完成。 二、关于新的会话和session_id from dotenv import load_…

php-cgi参数注入攻击经历浅谈

起因: 阿里云服务器再次警告出现挖矿程序。上一次服务器被攻击后,怕有恶意程序残留,第一时间重装了系统,也没有详查攻击入口。不过事后还是做了一些防范,这台留作公网访问的服务器上并未保留业务数据,只作…

自动驾驶中的实时挑战:如何优化车辆动力学模型

自动驾驶中的实时优化:自行车模型与双轨模型的计算复杂度权衡 在自动驾驶领域,车辆动力学建模是实现精准控制和路径规划的关键。自行车模型和双轨模型作为两种主流的建模方法,在实时性需求下如何平衡计算复杂度与精确度,是工程师们必须面对的挑战。本文将深入探讨这两种模…

Hybrid 架构的概念,以及如何优化Hybrid 通信方案,提升页面加载速度和渲染性能

1. 什么是 Hybrid 架构? Hybrid(混合)架构是指 结合 Web 技术和 Native(原生)技术 的移动应用开发模式,通常由以下部分组成: Web 部分:使用 HTML、CSS、JavaScript(或前…

关于类模板STL中vector容器的运用和智能指针的实现

代码题&#xff1a;使用vector实现一个简单的本地注册登录系统 注册&#xff1a;将账号密码存入vector里面&#xff0c;注意防重复判断 登录&#xff1a;判断登录的账号密码是否正确 #include <iostream> #include <cstring> #include <cstdlib> #in…

OpenCV 从入门到精通(day_04)

1. 绘制图像轮廓 1.1 什么是轮廓 轮廓是一系列相连的点组成的曲线&#xff0c;代表了物体的基本外形。相对于边缘&#xff0c;轮廓是连续的&#xff0c;边缘不一定连续&#xff0c;如下图所示。其实边缘主要是作为图像的特征使用&#xff0c;比如可以用边缘特征可以区分脸和手…

Python错误分析与调试

在Python编程的过程中&#xff0c;我们难免会遇到各种各样的错误&#xff0c;而有效地分析和调试这些错误&#xff0c;能让我们的代码快速恢复正常运行&#xff0c;今天就来和大家聊聊Python中错误分析与调试的相关内容。 错误分析 Python中的错误大致可以分为语法错误和逻…

Browser-use:基于 Python 的智能浏览器自动化 AI 工具调研与实战

Browser-use&#xff1a;基于 Python 的智能浏览器自动化 AI 工具调研与实战 一、概述 Browser-use 是一个旨在将 AI “智能体”&#xff08;Agents&#xff09;与真实浏览器进行交互的 Python 库&#xff0c;可以轻松实现浏览器自动化。在配合 LLM&#xff08;如 GPT 系列&a…

网络空间安全(51)邮件函数漏洞

前言 邮件函数漏洞&#xff0c;特别是在PHP环境中使用mail()函数时&#xff0c;是一个重要的安全问题。 一、概述 在PHP中&#xff0c;mail()函数是一个用于发送电子邮件的内置函数。其函数原型为&#xff1a; bool mail ( string $to , string $subject , string $message [, …

LLaMA-Factory 数据集成从入门到精通

一、框架概述 LLaMA-Factory 框架通过Alpaca/Sharegpt双格式体系实现多任务适配&#xff0c;其中Alpaca专注结构化指令微调&#xff08;含SFT/DPO/预训练&#xff09;&#xff0c;Sharegpt支持多角色对话及多模态数据集成。核心配置依托 dataset_info.json 实现数据源映射、格…

如何根据设计稿进行移动端适配:全面详解

如何根据设计稿进行移动端适配&#xff1a;全面详解 文章目录 如何根据设计稿进行移动端适配&#xff1a;全面详解1. **理解设计稿**1.1 设计稿的尺寸1.2 设计稿的单位 2. **移动端适配的核心技术**2.1 使用 viewport 元标签2.1.1 代码示例2.1.2 参数说明 2.2 使用相对单位2.2.…

07-Spring Boot 自动配置原理全解析

Spring Boot 自动配置原理全解析&#xff08;EnableAutoConfiguration 源码追踪&#xff09; Spring Boot 之所以能大幅简化配置&#xff0c;核心就在于它的 自动配置机制&#xff0c;而这一机制背后主要依赖于 EnableAutoConfiguration 注解。本文将从使用、源码、常见问题及…

前端如何检测项目中新版本的发布?

前言 你是否也曾遇到过这种情况&#xff0c;每次发完版之后都还会有用户反馈问题没有被修复&#xff0c;一顿排查之后发现他用的还是旧的版本。 用户&#xff1a;在 XX 页面 XX 字段还是不展示 我&#xff1a;刷新下页面 用户&#xff1a;刷新了啊 我&#xff1a;强刷一下&…

Vue 项目使用 pdf.js 及 Elasticpdf 教程

摘要&#xff1a;本文章介绍如何在 Vue 中使用 pdf.js 及基于 pdf.js 的批注开发包 Elasticpdf。简单 5 步可完成集成部署&#xff0c;包括数据的云端同步&#xff0c;示例代码完善且简单&#xff0c;文末有集成代码分享。 1. 工具库介绍与 Demo 1.1 代码包结构 ElasticPDF基…

聊聊Spring AI的ChromaVectorStore

序 本文主要研究一下Spring AI的ChromaVectorStore 示例 pom.xml <dependency><groupId>org.springframework.ai</groupId><artifactId>spring-ai-starter-vector-store-chroma</artifactId></dependency>配置 spring:ai:vectorstore:…

整数编码 - 华为OD统一考试(A卷、Java)

题目描述 实现一种整数编码方法,使得待编码的数字越小,编码后所占用的字节数越小。 编码规则如下: 编码时7位一组,每个字节的低7位用于存储待编码数字的补码。字节的最高位表示后续是否还有字节,置1表示后面还有更多的字节,置0表示当前字节为最后一个字节。采用小端序编…

Linux 递归查找并删除目录下的文件

在 Linux 中&#xff0c;可以使用 find 命令递归查找并删除目录下的文件 1、示例命令 find /path/to/directory -type f -name "filename_pattern" -exec rm -f {} 2、参数说明 /path/to/directory&#xff1a;要查找的目标目录type f&#xff1a;表示查找文件&am…

【笔记】VS中C#类库项目引用另一个类库项目的方法

VS中C#类库项目引用另一个类库项目的方法 在 C# 开发中&#xff0c;有时我们需要在一个类库项目中引用另一个类库项目&#xff0c;但另一个项目可能尚未编译成 DLL。在这种情况下&#xff0c;我们仍然可以通过 Visual Studio 提供的项目引用功能进行依赖管理。 &#x1f3af; …