• Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.

Linux Version Introduction

Fedora is a community version based on RHEL, CentOS, Scientific Linux, and Oracle Linux. Fedora packs significantly more packages than RHEL. One reason is the diverse community involved in building Fedora, which is not just a company. In this process, CentOS is used for events, demos, and experiments because it is freely available to end users and has a longer release cycle than Fedora (typically a new release every six months or so).

Debian is upstream of many distributions, including Ubuntu, which in turn is upstream of Linux Mint and others. Debian is widely used in both server and desktop computing. Debian is a pure open source project and focuses on one key point, stability. It also provides the largest and complete repository of software to users.

Distributions of Linux can be broadly divided into two categories: those maintained by commercial companies, such as the famous Redhat(RHEL), and those maintained by community organizations, such as Debian. Here are the features of each release:

Centos(Redhat)

Redhat includes RHEL(Redhat Enterprise Linux, also known as Redhat Advance Server, premium version), Fedora Core(developed from the original Redhat desktop version), Free version), CentOS(a community clone of RHEL, free).

Package management: The YUM package management mode based on RPM packages is adopted.

Debian

Debian is a paragon of community-class Linux and is by far the most GNU specification-compliant Linux system. Debian was originally created by Ian Murdock in 1993 and is divided into three release branches: stable, testing, and Unstable. Unstable is the latest test version that contains the latest software packages but has a relatively high number of bugs and is suitable for desktop users. The version of Testing has been tested with Unstable, which is relatively stable and supports many new technologies (such as SMP). Stable is typically used only on servers, and most of the packages are outdated, but stable and secure.

Package management: apt-get, DPKG package management is adopted.

Ubuntu

Ubuntu is not strictly a standalone distribution. It is a hard-core enhancement of Unstable Debian. Ubuntu is a near-perfect Linux desktop with everything that is good about Debian and everything that is good about it. Depending on the desktop you choose, there are three versions to choose from: Ubuntu based on Gnome, Kubuntu based on KDE, and Xubuntu based on Xfc. It features a very user-friendly, easy-to-use interface and comprehensive hardware support, making it the most suitable Linux distribution for desktop systems.

Package management: apt-get, DPKG package management is adopted.

To sum up and compare:

classification Centos Debian Ubuntu
Package management yum apt-get apt-get
A desktop application support Need another outfit support
System Resource Usage small A very small big
data most Relying on the community more
Update frequency For a decade 1 to 2 years 3 to 5 years
Software resources A new The latest new
Vulnerability to update slow Relying on the community Relying on the community
The default installation Very full There is no Very full
The stability of Relatively stable stable Relatively stable
System Operation Requirements higher high low
Maintenance requirements low high higher
Ease of use general poor good
customized general high poor

CentOS is the open source counterpart of RHEL distributions and is usually released soon after RedHat is released. It is stable, consumes less resources, can be easily searched on the network installation configuration documents, its own help document is very powerful. So, new learning recommendation: Centos

Common Software Applications

  • Databases: MySQL, Oracle, MongoDB, Redis
  • Web server:Nginx, Apache
  • Browsers: Chromium(Chrome), Firefox
  • Editor: Emacs,Vim, Nano, Atom, VScode, IntelliJ IDEA&Webstorm
  • Documentation: WPS Office, LibreOffice, Calligra(Ubuntu/Debian)
  • Download tools:Aria2, uGet(Ubuntu/Debian), XDM, qBittorrent
  • Virtualization: VirtualBox, VMWare,
  • System tools:git, rsync, sudo, unzip, tar
  • Others: Netease Music, Picture GIMP, Chat Wine QQ, player VLC

Installation method

Centos installation method

  1. Download mirror

Download on demand:

type DVD Minimal
Graphics installed support support
Delivered Software Package Whole family bucket, optional There is no
Image size 4G+ 800-900M
  1. Make a USB boot drive

    Windows Reference: Create a USB boot disk in Windows

    Mac/Linux Reference: Make a USB boot disk on the MacOS

  2. Change the BIOS boot sequence and restart the BIOS

  3. Installation configuration. euro

Create a USB boot disk in Windows

Operation steps:

  1. Format USB Flash Drive (FAT32 format)

  2. Downloading an ISO image

  3. Download the writer from the resource file

  4. Write image (tools below)

Resources download:

Centos官网 recommended:

USBwriter

Win32 Disk Imager

Ubuntu official website recommends:

rufus

Make USB boot disk in MacOS

  1. Formatting a USB Flash drive

  1. Use diskutil list to view the device name of U

    $diskutil list /dev/disk0 (internal): #: TYPE NAME SIZE IDENTIFIER 0: GUID_partition_scheme 500.3 GB Disk0 1: EFI EFI 314.6 MB disk0s1 2: Apple_APFS Container disk1 500.0 GB disk0s2 /dev/disk1 (synthesized): #: TYPE NAME SIZE IDENTIFIER 0: APFS Container Scheme - +500.0 GB Disk1 Physical Store Disk0S2 1: APFS Volume APPLE SSD 342.6 GB Disk1S1 2: APFS Volume Preboot 47.6 MB Disk1S2 3: APFS Volume Recovery 509.7 MB disk1S3 4: APFS Volume VM 4.3 GB disk1S4 /dev/disk2 (external, physical): # TYPE NAME SIZE IDENTIFIER 0: FDisk_partition_scheme *123.0 GB disk2 1: Windows_NTFS LIWEI 123.0 GB Disk2S1Copy the code

    In the figure above, /dev/disk2 is a USB disk

  2. Unmount the USB disk: diskutil umountDisk /dev/disk2 if the USB disk is /dev/disk2

    $ diskutil umountDisk /dev/disk2
    Unmount of all volumes on disk1 was successful
    Copy the code
  3. Sudo dd if=~/Downloads/ubuntu-16.04-desktop-amd64.iso of=/dev/disk2 bs=1m

    $ sudo dd if=~/Downloads/ubuntu-17.04-desktop-amd64.iso of=/dev/disk2 bs=1m
    Password:
    2151+1 records in
    2151+1 records out
    2256076800 bytes transferred in 90.277905 secs (24990354 bytes/sec)
    Copy the code
  4. After writing, it will prompt: “This computer cannot read the disk that can be inserted”, choose to push it out directly

Linux directory Structure

directory instructions note
/bin Common binary commands ls, cp, rm, mkdir
/usr System program directory Commands, help files, system configuration
/var This directory contains an ever-expanding collection of things The log
/lib The system’s most basic dynamic connection shared library Similar to DLL in Windows
/srv Store some data that needs to be extracted after the service is started It’s usually empty
/home User home directory It’s usually empty
/boot Linux kernel and system boot file directory
/dev Directory for device files Sound card, disk, CD drive, etc
/etc Default path of the binary software package configuration file System information, network configuration
/lost+found Some fragmented files generated when the system crashes
/mnt Temporarily mount storage devices U disk
/opt Optional software installation directory It’s usually empty
/proc Operating system process information directory
/sbin Administrator commands, system-level commands Sudo user
/tmp Temporary file directory After the restart, it is cleared
/run Temporary file system, information about the storage system since it was started After the restart, it is cleared
/sys The devices in the system are organized into hierarchies View hardware information in files

Knowledge about directory paths:

  1. View system kernel information

    # Centos$cat /proc/version Linux version 3.10.0-957.10.1.el7.x86_64 ([email protected]) (GCC version 4.8.5) 20150623 (Red Hat 4.8.5-36) (GCC))#1 SMP Mon Mar 18 15:06:45 UTC 2019
    
    # Ubuntu$cat /proc/version Linux version 4.15.7-041507-generic (kernel@gloin) (GCC version 7.2.0 (Ubuntu 7.2.0-8ubuntu3.2))#201802280530 SMP Wed Feb 28 10:31:47 UTC 2018
    Copy the code
  2. Viewing Network Information

    # Centos DHCP
    $ cat /etc/sysconfig/network-scripts/ifcfg-eth0
    DEVICE=eth0
    BOOTPROTO=dhcp
    ONBOOT=yes
    
    # or specify an IP address
    $ cat /etc/sysconfig/network-scripts/ifcfg-em1
    TYPE=Ethernet
    PROXY_METHOD=none
    BROWSER_ONLY=no
    BOOTPROTO=none
    DEFROUTE=yes
    IPV4_FAILURE_FATAL=no
    IPV6INIT=yes
    IPV6_AUTOCONF=yes
    IPV6_DEFROUTE=yes
    IPV6_FAILURE_FATAL=no
    IPV6_ADDR_GEN_MODE=stable-privacy
    NAME=em1
    UUID=fa335568-27db-47fd-a055-424173c42430
    DEVICE=em1
    ONBOOT=yes
    IPADDR=192.168.4.252
    PREFIX=24
    GATEWAY=192.168.4.50
    DNS1=192.168.4.50
    IPV6_PRIVACY=no
    ZONE=public
    
    # Ubuntu
    $ vi /etc/network/interfaces
    # This file describes the network interfaces available on your system
    # and how to activate them. For more information, see interfaces(5).
    
    source /etc/network/interfaces.d/*
    
    # The loopback network interface
    auto lo
    iface lo inet loopback
    
    # The primary network interfaceAuto ens3 iface ENS3 inet static Address 192.168.4.60 Netmask 255.255.255.0 Network 192.168.4.0 broadcast 192.168.4.255 Gateway 192.168.4.50# dns-* options are implemented by the resolvconf package, if installedDNS - nameservers 192.168.4.50 DNS - search itheimaCopy the code

    You usually use ifconfig to view the network card information

  3. The DNS configuration

    $ cat /etc/resolv.conf
    options timeout:2 attempts:3 rotate single-request-reopen
    ; generated by /usr/sbin/dhclient-script
    nameserver 100.100.2.136
    nameserver 100.100.2.138
    Copy the code
  4. The host file

    $cat /etc/hosts 127.0.0.1 localhost localhost. localDomain localhost4 localhost4. Localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6Copy the code
  5. User/group

    View user:

    $ cat /etc/passwd
    root:x:0:0:root:/root:/bin/bash
    daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
    bin:x:2:2:bin:/bin:/usr/sbin/nologin
    sys:x:3:3:sys:/dev:/usr/sbin/nologin
    sync:x:4:65534:sync:/bin:/bin/sync
    games:x:5:60:games:/usr/games:/usr/sbin/nologin
    man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
    lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
    ....
    Copy the code

    Check the group:

    $ cat /etc/group
    root:x:0:
    daemon:x:1:
    bin:x:2:
    sys:x:3:
    adm:x:4:syslog,bttech
    tty:x:5:
    disk:x:6:
    lp:x:7:
    mail:x:8:
    news:x:9:
    uucp:x:10:
    man:x:12:
    proxy:x:13:
    ....
    Copy the code
  6. View memory /CPU

    # to check the CPU$ cat /proc/cpuinfo processor : 0 vendor_id : GenuineIntel cpu family : 6 model : 45 model name : Intel(R) Xeon(R) CPU E5-2670 0 @ 2.60GHz Stepping: 7 Microcode: 0x714 CPU MHz: 2117.419 Cache Size: 20480 KB... Intel(R) Xeon(R) CPU E5-2670 0 @ 2.60GHz Stepping: 7 Microcode: 0x714 CPU MHz: 2117.419 Cache Size: 20480 KB...# check memory
    $ cat /proc/meminfo
    MemTotal:       131812048 kB
    MemFree:          460820 kB
    MemAvailable:   36657836 kB
    Buffers:               0 kB
    Cached:         34910784 kB
    SwapCached:      1051944 kB
    Active:         95183532 kB
    Inactive:       32382012 kB
    Active(anon):   77764844 kB
    Inactive(anon): 15015220 kB
    Active(file):   17418688 kB
    ...
    Copy the code
  7. other

    • /etc/fstab (Automatic mount list after startup)
    • /etc/rc.local (boot autostart file, boot autostart command, script)
    • /etc/init.d(service startup command script directory)
    • /etc/profile(global environment variable)
    • /usr/local(default installation directory for compiling installation software)
    • /var/log/message (System log)
    • /var/log/secure (System security logs)
    • /proc/mounts(System mounting information)

Linux Startup Process

Linux startup process:

  • Kernel boot

    The first is BIOS startup self-check, according to the BIOS setup of the boot device (usually hard disk) to start.

    These are basically drivers, basic operating instructions that take over all the hardware

  • Run init

    Just like the main function, it has a starting point, a service daemon, just like in Windows.

  • System initialization

    Users and software services start automatically

  • Set up the terminal

    Multi-user management for Linux.

    For users, there are three login methods:

    • Cli Login
    • SSH login
    • GUI Login
  • User Login

Common Commands (Key)

Documents related to

  1. Directory related
    • Ls: lists directories

      -la Can view some basic properties of hidden files

    • CD: Switch the directory

      Use the absolute/or./ relative path to go to the upper directory CD..

    • PWD: Displays the current directory

    • Mkdir: creates a new directory

    • Rmdir: Delete an empty directory

    • Cp: copies files or directories

      cp source target
      Copy the code
    • Rm: Deletes a file or directory

      # delete directory
      rm -r dirpath
      
      # force deleteRm - rf dirpath euroCopy the code
    • Mv: moves a file or directory or changes the file or directory name

      mv source target
      Copy the code
    • The cat command is used to view the contents of a file, the touch command is used to create a file, the echo command is used to write content to a file, and the more command is used to view and display the contents of a long file

  2. Basic attributes:
    • Permission management chmod

      The basic file properties are divided into 10 characters DRWXRWXRWX

      R indicates the read permission

      W indicates the write permission

      X indicates the execute execution permission

      D stands for table of contents

      Chmod -r is executed recursively, which is equivalent to changing the corresponding permissions of all files in the directory

      Chmod +x gives the file an execute/read/write permission

      There are two methods for modifying permissions:

      Mode 1: Digital mode

      7rwx

      6-rw-

      4r--

      0—- has no permissions at all,

      The first three are the permissions of the owner user,

      The middle three are group user permissions,

      The last three are the permissions of other users.

      For example:

      # Have read and write permission on the owning user
      chmod 600 ...
      
      -rwxrw-rw-, which is equivalent to canceling the group and other users' execution permission
      chmod 755 ...
      Copy the code

      Method 2:

      A stands for all, u stands for user, G stands for group and O stands for other.

      + means increase, – means decrease

      For example:

      Add read permission to all users
      chmod a+r ...
      
      Add write permission to user and group
      chmod ug+w ..
      Copy the code

      The way that individual compares recommend a number, better remember!!

    • User/group permission management chown

      Modify file/document owning/owning group

      Chown < owning user >:< Owning group > < file >Copy the code

      Directory:

      Chown -r < Owning user >:< Owning group > < file >Copy the code

      -r stands for recursion

User management/login

  1. Add useruseradd
  2. Delete useruserdel
  3. Changing user passwordspasswd
  4. (Extended) user groupsgroupadd/groupdel/groupmod

network

  1. Remote SSH Connection

    The configuration file is stored in the /etc/ssh/sshd_config directory

    If you need to modify port:

    • Modify thesshd_configIn thePortparameter
    • (Centos) still needs to be usedsemanage port -a -t ssh_port_t -p tcp <Port>
    • service sshd restart (Centos) / service ssh restart(Debian, Ubuntu)

    You can turn off the firewall on the server during testing, but this is not recommended for production systems.

    If the semanage command is not available, you can install it as follows:

    sudo yum install -y policecoreutils-python

    Or use yum Whatprovides semange to reverse check

    SSH -p Port < username >@< server address >

    Such as:

    $SSH -p 10022 [email protected]Copy the code

    Windows The XFTP terminal is recommended

    Iterm is recommended for the MAC

  2. View the nic configuration ifconfig

    If you do not have this command, you can use yum install net-tools to install it

    Ifconfig eth0 < IP > netmask 255.255.255.0Copy the code

    To disable or enable a network port

    ifconfig eth0 down/up
    Copy the code
  3. View network Netstat

    • -t: Lists TCP ports
    • -u: Lists UDP ports
    • -n: Use IP addresses and port numbers instead of domain names and service names
    • -l: Lists only the network services in the listening state
    • -a: Lists all network connections
    • -p: Lists the process information
    netstat -anpl | grep ssh
    Copy the code

    When using netstat | more scrolling, CTRL + f/b to turn on/on the next page

  4. Routing command route

    Route Viewing a route

    # add/del Add/delete routesRoute add -net 192.168.0.0 netmask 255.255.0.0 dev etho# del deleteRoute del-net 192.168.0.0 netmask 255.255.0.0# rejectRoute add-net 192.168.0.0 netmask 255.255.0.0 rejectCopy the code
  5. IP command IP

    ip addr show
    ip route show
    ip link set eth0 up/down
    Copy the code

    IP < command > help to view some of the parameters of the command

  6. DNS resolution: nslookup

    If the command does not exist in Centos, you can use the following methods to install it

    sudo yum install bind-utils
    Copy the code
  7. Viewing the Local IP Address

    Curl [url]Copy the code

    Several urls are also very easy to remember

    • Ip.cn (recommended)
    • Ipinfo.io (recommended)
    • Cip. Cc (recommended)
    • ifconfig.me
    • myip.ipip.net

GUI network configuration operations (graphical large method good ah) :

nmtui

Yum install -y NetworkManager-tui yum install -y NetworkManager-tui

Performance/Hardware

  1. The top command:

    To replace the top command, see 1 and 2

    Top # m Toggle to display memory information # t toggle to display CPU information # m To sort the memory in reverse order # P To sort the memory according to the percentage of CPU usedCopy the code
  2. The performance test

    • Bench.sh:

      Usage:

      wget -qO- bench.sh | bash
      
      # or
      
      curl -Lso- bench.sh | bash
      Copy the code

      Github address: github.com/teddysun/ac…

    • LemonBench

      Usage:

      wget -qO- https://ilemonrain.com/download/shell/LemonBench.sh | bash
      
      # or
      
      curl -fsSL https://ilemonrain.com/download/shell/LemonBench.sh | bash
      Copy the code

References:

  1. Official INSTALLATION instructions for USB flash drive
  2. Image download
  3. Centos7 installation tutorial
  4. Ubuntu official installation tutorial

FAQ:

  1. Centos7 USB disk installation card in starting Dracut initqueue hook
  2. Warning: dracut-initqueue timeout – starting timeout scripts