Step-by-step building IoT system--gnu/linux powerful and free

Source: Internet
Author: User
Tags fpm gpg install php unpack nginx server

Gnu/linux Powerful and free

What is Linux

Linux is a free and open source Unix-like operating system kernel. There are many different Linux distributions that can be installed on a wide variety of computer hardware devices, from phones, tablets, routers and video game consoles, to desktop computers, large computers and supercomputers. Linux is a leading operating system kernel, and the world's fastest 10 supercomputers run on Linux kernel-based operating systems.

The Linux operating system is also the most famous example of free software and open source development. As long as you follow the GNU General Public License, anyone and the organization are free to use all the underlying source code of Linux and are free to modify and republish. Strictly speaking, the word Linux itself only represents the Linux kernel, but in fact people have become accustomed to using Linux to describe the entire Linux kernel, and use the GNU engineering various tools and databases of the operating system (also known as Gnu/linux). Typically, Linux is packaged into Linux distributions used by altar computers and servers. Some popular mainstream Linux distributions include Debian (and its derivative versions of Ubuntu), Fedora and openSUSE. Linux is named after the computer hobbyist Linus Torvalds.

Instead of the ~~linux operating system, as the Baidu Encyclopedia says, is a clone of the UNIX operating system. It was born in 1991 on the Linux desktop [1] October 5 (This is the first time officially announced). With the help of Internet networks and the concerted efforts of computer enthusiasts around the world, it has become the most widely used UNIX class operating system in the world today, and the number of users is growing rapidly. ~~

Linux is just a kernel, not an operating system, so let's take a look at what the operating system is made of.

Operating system

Operating System (English: Operating

System, or OS, is a computer program that manages computer hardware and software resources, and is also the core and cornerstone of the system. The operating system needs to deal with basic transactions such as managing and configuring memory, prioritizing system resource supply and demand, controlling input and output devices, operating networks, and managing file systems. The operating system also provides an operating interface that allows users to interact with the system.

The type of operating system is very diverse, with different machine-installed operating systems ranging from simple to complex, from the handset's embedded system to the supercomputer's large operating system. Many operating system makers also have inconsistent definitions of what it covers, for example, some operating systems integrate a graphical user interface (GUI), while others use the command-line interface (CLI) only, and the GUI as a non-essential application.

The operating system is located between the underlying hardware and the user, and is the bridge between the two. The user can enter commands through the user interface of the operating system. The operating system interprets commands, drives hardware devices, and implements user requirements. In modern standards, a standard PC's operating system should provide the following features:

    • Process management (processing management)
    • Memory Management (Management)
    • FileSystem (File System)
    • Network communication (Networking)
    • Security mechanism (safety)
    • UI (User interface)
    • Driver (Device drivers)

And let's look at the difference between the two, this is a Linux architecture diagram we can find that the kernel is just on the ground floor.

Linux Frame composition

User mode

Applications (SH, VI,, etc.)

Complex libraries (KDE, glib, etc.)

Simple library (opendbm, sin, etc.)

C Library (open, fopen, socket, exec, calloc, etc.)

Kernel mode
    • System interrupts, calls, errors and other hardware and software messages
    • Kernel (driver, process, network, memory management, etc.)
    • Hardware (processor, memory, various devices)

We can see that the Linux kernel +shell can form an operating system, and Linux itself is a kernel, which is the kernel mode in the diagram, which is responsible for controlling these parts of the system. That is, we can see that the Linux kernel forms a part of the operating system in addition to the user interface, and the shell is the last user interface.

Part of the Linux kernel is made up of the GNU program.


The shell is the user interface of the system and provides an interface for users to interoperate with the kernel. It receives the command entered by the user and feeds it into the kernel to execute.

The shell is actually a command interpreter that interprets the commands entered by the user and sends them to the kernel. In addition, the shell has its own programming language for editing commands, which allows the user to write programs composed of Shell commands. Shell programming languages have many features of a common programming language, such as a looping structure and branching control structures, and shell programs written in this programming language have the same effect as other applications.

Bash is a Unix shell written for the GNU program. Its name is a series of abbreviations: Bourne-again shell-This is a pun about the Bourne SHell (SH) (Bourne again/bornagain). The Bourne shell is an early, important shell that was written around 1978 by Steve Burn and released with version 7 Unix. Bash was created by Blaine Fox in 1987. In 1990, Chet Ramey became the main maintainer.

The shell will be one of the often-used tools we use in Gnu/linux to operate the computer. Before migrating to Linux we can try the Cygwin to simulate:

Cygwin is a collection of many free software that was originally developed by Cygnus Solutions and is used on various versions of Microsoft Windows to run UNIX class systems.


GCC (GNU Compiler Collection,gnu Compiler Set) is a set of programming language compilers developed by GNU. It is a set of free software issued under the GPL and LGPL licenses, a key part of the GNU program, and a standard compiler for the free Unix-like and Mac OS X operating systems of Apple computers. GCC (especially the C language compiler) is also often considered a de facto standard for cross-platform compilers.

GCC was formerly the GNU C language compiler (GNU C Compiler) because it could only handle the C language. GCC expands quickly to become able to handle C + +. It also became available to process Fortran, Pascal, Objective-c, Java, Ada, and go with other languages.

C#include <stdio.h>main () {  printf ("Hello world\n");}
bash~/temp/free> gcc hello.c-o hellohello.c:2:1:warning:type specifier missing, defaults to ' int ' [-wimplicit-int]ma In () ^~~~1 warning generated.~/temp/free>./hellohello World

Like the shell, the role of GCC can be irreplaceable for gnu/linux systems. Of course, if only for general purposes, GCC may not be useful for the general user, but on some gnu/linux systems, we may need to compile the source code into binary files, without packages, so its importance is self-evident. Naturally, if we compile the Gnu/linux operating system ourselves, we will understand its significance. Interested students can try: Linuxfrom Scratch (LFS).

To start the boot program

Finally, when we make up the above, we need a boot program to boot the system and boot into the kernel.

A startup program (bootloader) on a computer or other computer application refers to a program that boots the operating system. Startup program starting mode and program depending on the type of application. For example, on an ordinary PC, the bootstrapper is usually divided into two parts: the first stage bootstrapper is in the master boot record, which is used to boot the second-stage bootstrapper on a partition, such as NTLDR, Gnugrub, and so on.

When the BIOS is powered on, bootloader takes over the initialization of the hardware device and creates a mapping of the memory space to prepare the operating system kernel.

The right hardware and software environment.

Simple bootloader of the virtual sink code, such as the following eight instructions:

    • 0: Set the value of the P register to 8
    • 1: Check paper tape ({paper tape) reader, can read
    • 2: If it is not yet readable, skip to 1
    • 3: From the tape reader, read a byte to the accumulator
    • 4: If the end of the tape, jump to 8
    • 5: Store the value of the scratchpad to the address specified by the value in the P register
    • 6: Increase the value of the P register
    • 7: Jump to 1

But as the computer operating system more and more complex, the space in the MBR has not been placed in the boot operating system code, so there is a second stage of the boot program, and the function of the code in the MBR from the direct boot operating system to boot the second stage of the boot program.

Usually in a gnu/linux system to choose Gnugrub as a boot program, such as Ubuntu is used GRUB2.

GNU GRUB ("Grub") is a boot loader from the GNU project. Grub is the implementation of a multi-boot specification that allows users to have multiple operating systems at the same time on the computer and select the operating system that they want to run when the computer starts. Grub can be used to select different cores on the operating system partition or to pass startup parameters to those cores.

GNU Grub was formerly the Grand Unified Bootloader. It is mainly used for Unix-like systems; As with most Linux distributions, the GNU system uses GNU GRUB as its initiator. Solaris has also adopted GNU Grub as the initiator on the x86 system starting from version 10 1/06.

The above also constitutes a simple operating system.

Starting from compilation

Let's start our Linux learning Journey with a single compilation.

Before you begin
    • If you have not used gnu/linux, I think you need to install one on the virtual machine.
    • A mainstream gnu/linux distribution, such as Ubuntu,centos,debian,mint,opensuse,fedora and so on.
    • Learn how to open the shell (PS:BASH,ZSH,SH, etc.).

Or you can install Cygwin on Windows.

Compiling Nginx

1. Download the source code package for this software


Wget is a software for downloading, of course you can also use the software, just with wget seems to be faster than the graphical interface Oh.

2. Unpacking the Package

BASHTAR-VF nginx-1.7.4.tar.gz

-VF means extract, which is decompression, and tar is the name of the decompression software. It seems to copy much more than WinRAR, but you can time it out, from downloading to unpacking, and using your mouse faster than that.

3. To the Nginx directory

It needs to be done in two parts.

1). List all Files

Bashls-aldrwxr-xr-x   Fdhuang Staff   510B Sep  2 13:44 nginx-1.7.4-rw-r--r--    1 Fdhuang  Staff   798K  5 21:55 nginx-1.7.4.tar.gz

2). To the nginx-1.7.4 directory

4. Configure Nginx

One simple configuration is as follows


When you are skilled, you may be the same as I use the following configuration (note: The following code will make an error.) )

Bash./configure--user=www--group=www--add-module=. /ngx_pagespeed- /ngx_cache_purge--prefix=/usr/local/nginx--with-pcre--with-http_spdy_module--with-http_ssl_module--with-http_ Realip_module--with-http_addition_module--with-http_sub_module--with-http_dav_module--with-http_flv_module-- With-http_mp4_module--with-http_gunzip_module--with-http_gzip_static_module--with-http_random_index_module-- With-http_secure_link_module--with-http_stub_status_module--with-mail--with-mail_ssl_module--with-ipv6

You may be prompted to make a few mistakes in the process, and you will be happy to search for them with a search engine.


GCC will be used here and so on.


6. Running

If it runs smoothly, you should be able to directly


1. If there is no WGET,MAKE,GCC and other commands can be installed in a manner similar to the following method,

Bashsudo Apt-get Install Gcc,make,wget

2. Under normal circumstances an open source project will have a readme that will tell you how to do it.

Package Management

Gnu/linux the most convenient thing is the package management.

Instructions and images from openSUSE official website 1

    1. The Linux distribution is nothing more than a bunch of packages (package) applications, plus the tools to manage these applications as a whole. Often these Linux distributions, including OpenSUSE, are made up of thousands of different packages.

    2. Package: A package is more than a file containing all the files that make up the software, including the program itself, shared libraries, development packages, and instructions for use.

    3. Metadata (metadata) is included in the package and contains some of the information needed to run the software properly. After the package is installed, its metadata is stored in the local package database for package retrieval.

    4. Dependency relationships (dependencies) are an important aspect of package management. In fact, each package will involve other software packages, software packages in the operation of the program needs an executable environment (requires other programs, libraries, etc.), package dependencies are used to describe the relationship.

Software packages under Linux are usually in the following three formats:

    • Tgz-tar gzip file. This type of file is a basic compression package that can hold everything that a package maintainer deems useful. This format, in addition to its own compression format, does not have a standard for package content.
    • Deb-This format package is commonly used in Debian systems and is the standard Debian package format.
    • RPM-This format, created by Red Hat Linux and standardized by LSB, is now available for many Linux distributions and is an excellent package format. OpenSUSE is in this format. More information can be found here.

So this requires a Package manager that can automatically resolve dependencies. The package management system is a tool set that provides a unified way to install, upgrade, and remove software from the system.

Ubuntu LNMP

In the remainder of the chapters, we need to deploy and need to use Ubuntu. If you can use lamp under windows, but here we only say Ubuntu. Before you start, you need to install Ubuntu, whether it's on a virtual machine, on a real machine, or Docker.

Update package List

Apt-get is a package management tool for the Debian,ubuntu release. Apt-get update ensures that the list of our packages is up to date, here is a simple update process.

Open the terminal console such as terminal or Konsole and so on.

[email protected]:/# sudo apt-get updateign trusty inreleaseign/http trusty-updates inreleaseign trusty-security inreleaseign/http trusty-proposed inreleaseget:1 trusty release.gpg [933 b]get:2/HTTP/ trusty-updates release.gpg [933 b]get:3 trusty-security release.gpg [933 B ]get:4 trusty-proposed release.gpg [933 b]get:5 trusty Release [ 58.5 kb]get:6 trusty-updates Release [62.0 kb]get:7 Trusty-security release [62.0 kb]get:8 trusty-proposed Release [209 kb]get:9/HTTP/ Trusty/main Sources [1335 kb]get:10 trusty/restricted Sources [5335 b]get : trusty/universe Sources [7926 kb]get:12 Trusty/main AMD64 Packages [1743 kb]get:13 trusty/restricted amd64 Packages [16.0 kb]get:14 http://archive  . trusty/universe AMD64 Packages [7589 kb]64% [+ Packages 664 kb/7589 KB 9%] 58.3 kb/s 1min 58s

After the update, it should show:

bashfetched 20.5 MB in 5min 22s (63.6 kb/s) Reading package lists ... Done
Install MySQL

Installation commands

Bashsudo apt-get Install Mysql-server php5-mysql


[email protected]:/# sudo apt-get install mysql-server php5-mysqlreading Package lists ... 0%reading Package Lists ... Donebuilding dependency treereading state information ... Donethe following extra packages would be installed:libaio1 Libdbd-mysql-perl Libdbi-perl Libhtml-template-perl LIBMYSQLC lient18 libterm-readkey-perl libwrap0 lsof mysql-client-5.5 mysql-client-core-5.5 Mysql-common mysql-server-5.5 mysql-server-core-5.5 Php5-common php5-json psmisc tcpdsuggested Packages:libclone-perl Libmldbm-perl Libnet-daemon-perl libplrpc-perl libsql-statement-perl libipc-sharedcache-perl tinyca mailx php5-user-cacheThe Following NEW packages'll be installed:libaio1 libdbd-mysql-perl libdbi-perl Libhtml-template-perl libmysqlclient18 L Ibterm-readkey-perl libwrap0 lsof mysql-client-5.5 mysql-client-core-5.5 mysql-common mysql-server mysql-server-5.5 mysql-server-core-5.5 Php5-common Php5-json php5-mysql psmisc tcpd0 upgraded, newly installed, 0 to remove and UpgradeD.need to get 9982 KB of archives. After this operation, 99.1 MB of additional disk space would be used. Get:1 libaio1 amd64 0.3.109-4 [6364 b]get:2 Ubuntu/trusty-updates/main Mysql-common All 5.5.40-0ubuntu0.14.04.1 [14.1 kb]get:3 Trusty-updates/main libmysqlclient18 AMD64 5.5.40-0ubuntu0.14.04.1 [598 kb]get:4 Trusty/main libwrap0 AMD64 7.6.q-25 [46.2 kb]get:5 Libdbi-perl AMD64 1.630 -1 [879 kb]get:6 libdbd-mysql-perl amd64 4.025-1 [99.3 kb]get:7/HTTP/ Libterm-readkey-perl amd64 2.31-1 [27.4 kb]get:8 Ubuntu/trusty-updates/main mysql-client-core-5.5 AMD64 5.5.40-0ubuntu0.14.04.1 [703 kb]get:9/HTTP/ mysql-client-5.5 AMD64 5.5.40-0ubuntu0.14.04.1 [14Kb]get:10 Http:// mysql-server-core-5.5 AMD64 5.5.40-0ubuntu0.14.04.1 [3215 kb]47% [mysql-server-core-5.5 850 kb/3215 KB 26%] 79.9 kb/s 1min 6s

You will be asked to enter the database password during the installation process. (Default is empty)

Installing Nginx
Bashecho "Deb Http:// $ (LSB_RELEASE-SC) main" | sudo tee/etc/apt/sources.list.d/nginx-stable.listsudo apt-key adv--keyserver C300ee8csudo apt-get updatesudo apt-get Install Nginx

Start Nginx Server

Bashsudo Service Nginx Start
Install PHP

sudo apt-get install PHP5-FPM

installation process

[email protected]:/# sudo apt-get install php5-fpmreading package lists ... Donebuilding dependency treereading state information ... Donethe following extra packages would be installed:libsystemd-daemon0suggested packages:php-pearthe following NEW pack Ages'll is Installed:libsystemd-daemon0 PHP5-FPM0 upgraded, 2 newly installed, 0 to remove and upgraded. Need to get 2201 KB of archives. After this operation, 9326 KB of additional disk space would be used. Want to continue? [y/n] yget:1 libsystemd-daemon0 amd64 204-5ubuntu20.8 [9608 B] Get:2 php5-fpm amd64 5.5.9+dfsg-1ubuntu4.5 [2191 kb]fetched 2201 KB in 1min 5s (33.6 kb/s) Selecting previously unselected package libsystemd-daemon0:amd64. (Reading database ... 13105 files and directories currently installed.) Preparing to unpack .../libsystemd-daemon0_204-5ubuntu20.8_amd64.deb ... Unpacking Libsystemd-daemon0: AMD64 (204-5ubuntu20.8) ... Selecting previously unselected package php5-fpm. Preparing to unpack .../php5-fpm_5.5.9+dfsg-1ubuntu4.5_amd64.deb ... Unpacking php5-fpm (5.5.9+dfsg-1ubuntu4.5) ... Processing triggers for ureadahead (0.100.0-16) ... Setting up Libsystemd-daemon0:amd64 (204-5ubuntu20.8) ... Setting up PHP5-FPM (5.5.9+dfsg-1ubuntu4.5) ... Creating config File/etc/php5/fpm/php.ini with new versionphp5_invoke:enable module PDO for FPM sapiphp5_invoke:enable Module Pdo_mysql for FPM sapiphp5_invoke:enable module Opcache for FPM sapiphp5_invoke:enable module JSON for FPM SAPIPH p5_invoke:enable module MySQL for fpm sapiphp5_invoke:enable module mysqli for FPM Sapiinvoke-rc.d:policy-rc.d denied E Xecution of start. Processing triggers for Libc-bin (2.19-0ubuntu6.3) ... Processing triggers for ureadahead (0.100.0-16) ...

Online View: Building IoT systems in one step

Turing-e-book edition step-by-step building an Internet of things system

    1. Https://

    • This article is from: Linux Learning Network

Step-by-step building IoT system--gnu/linux powerful and free

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.