动态

详情 返回 返回

【Linux】《how linux work》第 十七 章 夯實基礎 - 动态 详情

Chapter 17. Building on the Basics (第 17 章 夯實基礎)

The chapters in this book have covered the fundamental components of a Linux system, from low-level kernel and process organization, to networking, to some of the tools used to build software. With all of that behind you, what can you do now? Quite a lot, as it turns out! Because Linux supports nearly every kind of non proprietary programming environment, it’s only natural that a plethora of applications is available. Let’s look at a few application areas where Linux excels and see how what you’ve learned in this book relates.

這本書的章節涵蓋了Linux系統的基本組成部分,從底層的內核和進程組織,到網絡,再到一些用於構建軟件的工具。

現在,你可以做些什麼呢?事實證明,你可以做很多!因為Linux支持幾乎所有非專有編程環境,所以自然而然地有大量的應用程序可供使用。

讓我們來看看Linux在一些應用領域的優勢,並瞭解一下你在本書中學到的知識如何與之相關。

17.1 Web Servers and Applications(網絡服務器和應用程序)

Linux is a popular operating system for web servers, and the reigning monarch of Linux application servers is the Apache HTTP Server (usually referred to as just “Apache”). Another web server that you’ll often hear about is Tomcat (also an Apache project), which provides support for Java-based applications.

Linux是一個流行的用於Web服務器的操作系統,而Linux應用服務器的統治者是Apache HTTP服務器(通常簡稱為“Apache”)。

另一個經常聽到的Web服務器是Tomcat(也是一個Apache項目),它提供了對基於Java的應用程序的支持。

By themselves, web servers don’t do much—they can serve files, but that’s about it. The end goal of most web servers such as Apache is to provide an underlying platform to serve web applications. For example, Wikipedia is built on the MediaWiki package, which you can use to set up your own wiki. Content management systems like Wordpress and Drupal let you build your own blogs and media sites. All of these applications are built on programming languages that run especially well on Linux. For example, MediaWiki, Wordpress, and Drupal are all written in PHP.

單獨的Web服務器並不能做很多事情——它們只能提供文件服務,僅此而已。

大多數Web服務器(如Apache)的最終目標是提供一個基礎平台來提供Web應用程序。

例如,維基百科是建立在MediaWiki軟件包上的,您可以使用它來搭建自己的維基。

像WordPress和Drupal這樣的內容管理系統可以讓您建立自己的博客和媒體網站。

所有這些應用程序都是基於在Linux上運行特別好的編程語言構建的。

例如,MediaWiki、WordPress和Drupal都是用PHP編寫的。

The building blocks that make up web applications are highly modular, so it’s easy to add your own extensions and create applications with frameworks such as Django, Flask, and Rails, which offer facilities for common web infrastructure and features, such as templates, multiple users, and database support.

構成Web應用程序的構建模塊非常模塊化,因此很容易添加自己的擴展,並使用Django、Flask和Rails等框架創建具有常見Web基礎設施和功能(如模板、多用户和數據庫支持)的應用程序。

A well-functioning web server depends on a solid operating system foundation. In particular, the material in Chapter 8 through Chapter 10 is particularly important. Your network configuration must be flawless, but perhaps more importantly, you must understand resource management. Adequately-sized, efficient memory and disk are critical, especially if you plan to use a database in your application.

良好運行的Web服務器依賴於堅實的操作系統基礎。

特別是,第8章到第10章的內容尤為重要。

您的網絡配置必須完美無缺,但更重要的是,您必須瞭解資源管理。

充足大小、高效的內存和磁盤至關重要,尤其是如果您計劃在應用程序中使用數據庫。

17.2 Databases(數據庫)

Databases are specialized services for storing and retrieving data, and many different database servers and systems run on Linux. Two primary features of databases make them attractive: They offer easy, uniform ways to manage individual pieces and groups of data, and superior access performance.

數據庫是專門用於存儲和檢索數據的服務,許多不同的數據庫服務器和系統在Linux上運行。

數據庫的兩個主要特點使其具有吸引力:它們提供了管理單個數據和數據組的簡單、統一的方式,並具有優越的訪問性能。

Databases make it easier for applications to examine and alter data, especially when compared with parsing and changing text files. For example, the /etc/passwd and /etc/shadow files on a Linux system can become difficult to maintain over a network of machines. Instead, you can set up a database that offers user information LDAP (Lightweight Directory Access Protocol) to feed this information into the Linux authentication system. The configuration on the Linux client side is easy; all you need to do is edit the /etc/ nsswitch.conf file and add a little extra configuration.

與解析和更改文本文件相比,數據庫使應用程序更容易地檢查和修改數據。

例如,在Linux系統上,/etc/passwd和/etc/shadow文件在機器網絡上變得難以維護。

相反,您可以設置一個數據庫,提供用户信息LDAP(輕量級目錄訪問協議),將此信息輸入Linux身份驗證系統。

在Linux客户端方面的配置很簡單;您只需要編輯/etc/nsswitch.conf文件並添加一些額外的配置即可。

The primary reason that databases generally offer superior performance when retrieving data is that they use indexing to keep track of data locations. For example, say you have a set of data representing a directory containing first and last names and telephone numbers. You can use a database to place an index on any of these attributes, like the last name. Then, when looking up a person by last name, the database simply consults the index for the last name rather than searching the entire directory.

數據庫通常在檢索數據時具有卓越性能的主要原因是它們使用索引來跟蹤數據位置。

例如,假設您有一組數據表示包含名字、姓氏和電話號碼的目錄。

您可以使用數據庫在任何這些屬性上建立索引,比如姓氏。

然後,當按照姓氏查找一個人時,數據庫只需查詢姓氏索引,而不是搜索整個目錄。

17.2.1 Types of Databases(數據庫類型

Databases come in two basic forms: relational and non-relational. Relational databases (also called Relational Database Management Systems, or RDBMS), such as MySQL, PostgreSQL, Oracle, and MariaDB, are general-purpose databases that excel in tying different sets of data together. For example, say you have two sets of data, one with postal (ZIP) codes and names, and another with the postal codes and their corresponding states. A relational database would allow you to very quickly retrieve all of the names located in a particular state. You normally talk to relational databases using a programming language called SQL (Structured Query Language).

數據庫有兩種基本形式:關係型和非關係型。

關係型數據庫(也稱為關係數據庫管理系統,或RDBMS),如MySQL、PostgreSQL、Oracle和MariaDB,是通用數據庫,擅長將不同的數據集合在一起。

例如,假設您有兩組數據,一組是郵政編碼和姓名,另一組是郵政編碼及其對應的州。

關係型數據庫可以讓您非常快速地檢索出位於特定州的所有姓名。

通常,您使用一種稱為SQL(結構化查詢語言)的編程語言與關係型數據庫進行交互。

Non-relational databases, sometimes known as NoSQL databases, tend to solve particular problems that relational databases don’t easily handle. For example, document-store databases, such as MongoDB, attempt to make storing and indexing entire documents easier. Key-value databases, such as redis, tend to focus on performance. NoSQL databases don’t have a common query language like SQL for access. Instead, you’ll talk to them using a variety of interfaces and commands.

非關係型數據庫,有時也稱為NoSQL數據庫,傾向於解決關係型數據庫難以處理的特定問題。

例如,文檔存儲數據庫(如MongoDB)試圖使存儲和索引整個文檔變得更加容易。

鍵值數據庫(如Redis)則更注重性能。

NoSQL數據庫沒有像SQL那樣的通用查詢語言來進行訪問。相反,您將使用各種接口和命令與它們進行交互。

The disk and memory performance issues discussed in Chapter 8 are extremely important in most database implementations because there’s a trade-off between how much you can store in RAM (which is fast) versus on disk. Most larger database systems also involve significant networking because they’re distributed over many servers. The most common such network setup is called replication, where one database is basically copied to a number of database servers to increase the number of clients that connect to the servers.

第8章中討論的磁盤和內存性能問題在大多數數據庫實現中非常重要,因為在RAM(快速)和磁盤上存儲的數據之間存在權衡。

大多數較大的數據庫系統還涉及到重要的網絡因素,因為它們分佈在許多服務器上。

最常見的網絡設置稱為複製,其中一個數據庫基本上被複制到多個數據庫服務器上以增加連接到服務器的客户端數量。

17.3 Virtualization(虛擬化)

In most large organizations, it’s inefficient to dedicate hardware to specific server tasks because installing an operating system tailored to one task on one server means that you’re limited to that task until you reinstall it. Virtual machine technology makes it possible to simultaneously install one or more operating systems (often called guests) on a single piece of hardware, and then activate and deactivate the systems at will. You can even move and copy the virtual machines to other machines.

在大多數大型組織中,為特定的服務器任務分配硬件是低效的,因為在一個服務器上安裝一個專為某個任務定製的操作系統意味着你只能限制在該任務上,直到重新安裝它。

虛擬機技術使得在一台硬件上同時安裝一個或多個操作系統(通常稱為客户機)成為可能,然後可以隨意激活和停用這些系統。

你甚至可以將虛擬機移動和複製到其他機器上。

There are many virtualization systems for Linux, such as the kernel’s KVM (kernel virtual machine) and Xen. Virtual machines are especially handy for web servers and database servers. Although it’s possible to set up a single Apache server to serve several websites, this comes at a cost of flexibility and maintainability. If those sites are all run by different users, you have to manage the servers and the users together. Instead, it’s usually preferable to set up virtual machines on one physical server with their own supporting users, so that they don’t interfere with each other and you can alter and move them at will.

Linux有許多虛擬化系統,如內核的KVM(內核虛擬機)和Xen。

虛擬機對於Web服務器和數據庫服務器特別方便。

雖然可以設置一個單獨的Apache服務器來為多個網站提供服務,但這會帶來靈活性和可維護性的成本。

如果這些站點都由不同的用户運行,你必須同時管理服務器和用户。

相反,通常更好的選擇是在一個物理服務器上設置虛擬機,每個虛擬機都有自己的支持用户,這樣它們彼此不會干擾,你可以隨意更改和移動它們。

The software that operates virtual machines is called a hypervisor. The hypervisor manipulates many pieces of the lower levels of a Linux system that you’ve seen in this book with the result that, if you install a Linux guest on a virtual machine, it should behave just like any other installed Linux system.

操作虛擬機的軟件稱為hypervisor。hypervisor操作Linux系統的許多低層組件,你在本書中已經見過,因此,如果在虛擬機上安裝Linux客户機,它應該表現得就像任何其他已安裝的Linux系統一樣。

17.4 Distributed and On-Demand Computing(分佈式計算和按需計算)

To ease local resource management, you can build sophisticated tools on top of virtual machine technology. The term cloud computing is a catch-all term that’s often used as label for this area. More specifically, infrastructure as a service (IaaS ) refers to systems that allow you to provision and control basic computing resources such as CPU, memory, storage, and networking on a remote server. The OpenStack project is one such API and platform that includes IaaS.

為了簡化本地資源管理,您可以在虛擬機技術的基礎上構建複雜的工具。

術語“雲計算”是一個總稱,經常用於描述這個領域。

更具體地説,基礎設施即服務(IaaS)是指允許您在遠程服務器上提供和控制基本計算資源,如CPU、內存、存儲和網絡的系統。

OpenStack項目是一個包括IaaS的API和平台。

Moving up past the raw infrastructure, you can also provision platform resources such as the operating system, database servers, and web servers. Systems that offer resources on this level are said to be platform as a service (PaaS).

在超越原始基礎設施之後,您還可以提供平台資源,如操作系統、數據庫服務器和Web服務器。

提供此級別資源的系統被稱為平台即服務(PaaS)。

Linux is central to many of these computing services, as it’s often the underlying operating system behind all of it. Nearly all of the elements that you’ve seen in this book, starting with the kernel, are reflected throughout these systems.

Linux在許多這些計算服務中起着核心作用,因為它通常是所有這些系統背後的底層操作系統。

您在本書中看到的幾乎所有元素,從內核開始,都在這些系統中得到體現。

17.5 Embedded Systems(嵌入式系統)

An embedded system is anything designed to serve a specific purpose, such as a music player, video streamer, or thermostat. Compare this to a desktop or server system that can handle many different kinds of tasks (but may not do one specific thing very well).

嵌入式系統是為特定目的而設計的系統,如音樂播放器、視頻流媒體或恆温器。

與之相比,台式機或服務器系統可以處理許多不同類型的任務(但可能無法很好地完成某項特定任務)。

You can think of embedded systems as almost the opposite of distributed computing; rather than expanding the scale of the operating system, an embedded system usually (but not always) shrinks it, often into a small device. Android is perhaps the most widespread embedded version of Linux in use today.

你可以把嵌入式系統看作與分佈式計算幾乎相反的系統;

嵌入式系統通常(但不總是)不是擴大操作系統的規模,而是將其縮小,通常縮小到一個小型設備中。

安卓可能是目前使用最廣泛的嵌入式 Linux 版本。

Embedded systems often combine specialized hardware with software. For example, you can set up a PC to do anything a wireless router can by adding enough network hardware and correctly configuring a Linux installation. But it’s usually preferable to buy a smaller, dedicated device consisting of the necessary hardware and eliminate any hardware that isn’t necessary. For example, a router needs more network ports than most desktops but doesn’t need video or sound hardware. And once you have custom hardware, you must tailor the system’s software, such as the operating system internals and user interface. OpenWRT, mentioned in Chapter 9, is one such customized Linux distribution.

嵌入式系統通常結合了專用硬件和軟件。

例如,你可以通過添加足夠的網絡硬件並正確配置Linux安裝來使PC執行無線路由器的任何功能。

但通常更傾向於購買一個更小、專用的設備,其中包含必要的硬件,並消除任何不必要的硬件。

例如,路由器需要比大多數桌面設備更多的網絡端口,但不需要視頻或聲音硬件。

一旦你擁有了定製的硬件,你必須調整系統的軟件,比如操作系統內部和用户界面。

OpenWRT就是這樣一個定製的Linux發行版,在第9章中有提到。

Interest in embedded systems is increasing as more capable small hardware is introduced, particularly system on-a-chip (SoC) designs that can cram a processor, memory, and peripheral interfaces into a small space. For example, the Raspberry Pi and BeagleBone single-board computers are based around such a design, with several Linux variants to choose from as an operating system. These devices have easily accessible output and sensor input that connects to language interfaces such as Python, making them popular for prototyping and small gadgets.

隨着越來越多功能強大的小型硬件的推出,對嵌入式系統的興趣不斷增加,特別是能夠將處理器、內存和外圍接口裝入一個小空間的片上系統(SoC)設計。

例如,樹莓派和BeagleBone單板計算機就是基於這樣的設計,有幾個可供選擇的Linux變體作為操作系統。

這些設備具有易於訪問的輸出和傳感器輸入,可以連接到Python等語言接口,因此在原型設計和小型小工具方面非常受歡迎。

Embedded versions of Linux vary in how many features from the server/ desktop version can be carried over. Small, very limited devices must strip out everything except the bare minimum because of lack of space, which often means that even the shell and core utilities come in the form of a single BusyBox executable. These systems tend to exhibit the most differences between a full-featured Linux installation, and you’ll often see older software on them, such as System V init.

嵌入式Linux的版本在多大程度上可以繼承服務器/桌面版本的功能是不同的。

由於空間有限,小型、非常有限的設備必須剝離除了最基本的之外的所有東西,這通常意味着連shell和核心工具也以單個BusyBox可執行文件的形式存在。

這些系統往往在完整功能的Linux安裝和它們之間存在最大的差異,你經常會看到其中運行着較舊的軟件,比如System V init。

You’ll normally develop software for embedded devices using a regular desktop machine. More powerful devices, such as the Raspberry Pi, have the luxury of more storage and the power to run newer and more complete software, so you can even natively run many development tools on them.

開發嵌入式設備的軟件通常是在普通的桌面機器上進行的。

像樹莓派這樣更強大的設備擁有更多的存儲空間和運行更新、更完整的軟件的能力,因此你甚至可以在它們上面本地運行許多開發工具。

Regardless of the differences, though, embedded devices still share the Linux genes described in this book: You’ll see a kernel, a bunch of devices, network interfaces, and an init alongside a bunch of user processes. Embedded kernels tend to be close (or identical) to regular kernel releases, simply with many features disabled. As you work your way up through user space, though, the differences become more pronounced.

不過,不管有何種差異,嵌入式設備仍然與本書中描述的Linux基因共享:你會看到一個內核、一堆設備、網絡接口和一個init,以及一堆用户進程。

嵌入式內核往往與常規內核發佈版本接近(或相同),只是禁用了許多功能。然而,當你進入用户空間時,差異變得更加明顯。

17.6 Final Remarks(結束語)

Whatever your goals for gaining a better understanding of Linux systems, I hope that you’ve found this book to be helpful. My goal has been to instill you with confidence when you need to get inside your system to make changes or do something new. At this point, you should feel like you’re really in control of your system. Now go and push it around a little and have some fun.

無論你想更好地瞭解 Linux 系統的目標是什麼,我都希望你能發現本書
有所幫助。

我的目標是在你需要進入你的系統進行修改或做一些新的事情時,給你灌輸信心。

進行更改或做一些新的事情。到此為止,你應該感覺到自己真正掌控了系統。

現在就去推動它,享受一些樂趣吧。

user avatar witt7 头像 jacklv 头像 shenchendexiaodao 头像
点赞 3 用户, 点赞了这篇动态!
点赞

Add a new 评论

Some HTML is okay.