Liunx tutorial super detailed (complete)

Article directory

Linux

1. Computer hardware and software system

von Neumann architecture

  • The data and instructions processed by the computer are all represented by binary numbers
  • Sequential execution of programs
  • Computer hardware consists of five parts: arithmetic unit, controller, memory, input device and output device

Computer hardware composition

  • input device
  • output device
  • memory
    • Memory is used to store data and programs

    • RAM (random access memory) is random storage memory

      • Fast speed, small capacity
      • Volatile when power off
      • logical I/O
    • ROM (Read-Only Memory) is a read-only memory hard disk:

      • Large capacity, relatively slow speed
      • long-term preservation
      • Physical I/O
  • controller
    • The controller is mainly used to control and direct the input and operation of programs and data, and to process the operation results
  • calculator
    • The arithmetic unit mainly runs arithmetic operations and logic operations, and temporarily stores the intermediate results in the arithmetic unit

Hard disk classification

  • Mechanical hard disk (Hard Disk Driver, HDD)

    • Mechanical hard drives use magnetic discs to store data
    • Magnify the disk with a microscope, you will see that the surface of the disk is uneven, the convex places are magnetized, and the concave places are not.
    • be magnetized
    • The raised area represents the number 1 (magnetized as 1), and the concave area represents the number 0.
    • The hard disk can store information such as text and pictures in binary.
    • The hard disk can judge the quality of the hard disk according to the rotation speed 7200 rpm 100-200M/s
  • Solid State Disk (SSD)

    • SSDs store data through flash particles (arrays of solid-state electronic memory chips)
    • Read and write speed difference

network connection concept

  • IP address IPADDR
    • An IP address is a logical address used to identify each host in the network
      • IP address = network address + host address
      • The IP address is a 4 * 8bit (1 byte) digital string consisting of 0/1 (IP4 protocol)
  • subnet mask NETMASK
    • The subnet mask has only one function, which is to divide the IP address into two parts: the network address and the host address.
    • The subnet mask is used to determine whether the IP addresses of any two computers are in the same subnet.
  • default gateway GATEWAY
    • The role of the gateway is to realize communication and control between two networks
    • A device connected to two different networks can be called a gateway device
    • The gateway address is the IP address of the gateway device
  • domain name server DNS
    • DNS is a domain name server, which is used to resolve domain names (resolution between domain names and IPs).
    • If there is no such thing, you must enter the IP address of the website when you log in to a website. With DNS, you can directly enter the URL
    • the whole country
      • 114.114.114.114
    • worldwide
      • 8.8.8.8
    • C:\Windows\System32\drivers\etc\hosts

network connection mode

  • host-onboy (host mode)
    • VMNet1
  • bridged (bridged mode)
    • The virtual machine and the real host share a network
  • NAT (Network Address Translation Mode)
    • Build a separate subnet for virtual machines
    • VMNet8

Software classification

  • application
    • just to achieve certain business functions
    • The application software should be based on the corresponding system software
  • system software
    • Just to deal with the hardware
    • Mask the difference between application software and hardware
    • Classification
      • Window
        • The largest number of users in the world
        • Fees, not open source, more civilian use
        • A variety of software is relatively complete
      • Mac
        • Only limited to certain Apple brands
      • GNU/Linux
        • GNU is an open source software organization, all software in the world should be open source and free

Linux branch

  • RedHat (paid)

    • CentOS

      • Completely open source and free
      • Do not use the latest version of CentOS
    • Mainly for server version

  • Debain (free)

    • Ubuntu

      • Linux system with good Windows interface
      • Some mainstream software supports Ubuntu system

linux download

  • official website

    • https://linux.org/
  • download page

    • https://linux.org/pages/download/
  • CentOS7.6 download address

    • http://vault.centos.org/7.6.1810/
  • Classification of mirror images

    • everything
    • minimal
    • netinstall

2. Virtual machine installation and configuration

virtualization technology

  • Make better use of idle computer resources

  • We can virtualize multiple virtual machines in the computer to help us execute programs or businesses

  • The various components of the virtual machine are theoretically the same as the real host

  • If you want to use this technology, you only need to install the corresponding software

    • Virtualbox
    • VirtualMachine
  • install software

    • Win10

      • VirtualMachine 15.X version
    • Win11

      • VirtualMachine 16.X version

Create a virtual host

install the operating system

Configure common parameters

  • network

    • View your own virtual network card address

      • Edit –> Virtual Machine Network Editor –> vmnet8
    • Modify network configuration information

      • Modify network information

        • vi /etc/sysconfig/network-scripts/ifcfg-ens33

        • -Revise

          • ONBOOT=yes
          • BOOTPROTO=static //Static network IP dhcp dynamically obtains network IP
        • -Add to

          • ip address
          • gateway address
          • subnet mask
          • DNS1
        • delete------

          • UUID
      • Restart the network card to reload the configuration file

        • ip addr
        • systemctl restart network.service
        • ping www.baidu.com
        • ctrl+c terminates the execution of the command
  • Software installation restrictions

    • The operating system may refuse or warn the installation of unknown software, we need to disable this function

    • vi /etc/selinux/config

      • Revise

        • SELINUX=disabled
  • firewall

    • Protect the port of this machine from being maliciously accessed by others

    • If the port needs to be accessed by others, you need to add a firewall exception for the port

    • turn off firewall

      • The firewall is turned off in this boot state

        • systemctl stop firewalld (close the firewall in this service)
      • Firewall disabled after server restart

        • systemctl disable firewalld (disable firewall service)
      • View firewall status

        • systemctl status firewalld (disable firewall service)
  • shutdown

    • halt

      • Unplug the power directly
    • poweroff

      • Shut down the machine directly, but it is possible that other people are using the current virtual machine
    • shutdown -h now

      • Immediately shut down the computer, but can send messages to other users
    • reboot

      • Restart the virtual machine

Snapshots and clones

  • take a snapshot

    • Record the current state of the virtual machine
    • Be sure to power off when taking snapshots
  • go to

    • Go back to a node of a historical snapshot
  • clone

    • Copy a historical snapshot node

    • way of cloning

      • linked clone

        • The current node folder only stores differential data
        • The same data is stored on the original node
        • Advantages: save hard disk space Disadvantages: large coupling
      • full clone

        • It is based on the complete copy of the original node to the folder of the new node
        • Advantages: Coupling offset Disadvantages: Large use of hard disk space
        • Full grams recommended

Modify the configuration of the clone machine

  • Internet Information

    • Refer to modifying network information
  • CPU name

    • vi /etc/hostname

      • After the modification is completed, a restart is required to take effect
    • hostname xxxx

      • Valid during this startup, restart the virtual machine or use the original name

Connect to Linux server

  • Xshell

    • Responsible for entering commands into the virtual machine
  • XFtp

    • If so, transfer files to the virtual machine

3. Linux commands

command learning

  • Linux commands and parameters must be separated by spaces

  • Linux commands are case sensitive

  • If you enter the wrong command

    • -bash: abcd: command not found
    • wrong order
    • command not installed
  • type command type

    • cd is a shell builtin
    • ping is /bin/ping
    • ll is aliased to `ls -l --color=auto’
    • for is a shell keyword
  • Command help documentation

    • help

      • Help documentation for built-in commands
    • man

      • Help documentation for external commands

      • Because the current system is minimal, there is no man package for very basic

      • Man needs to be installed manually

        • yum install man man-pages -y
    • If you encounter unfamiliar commands in your future work, you can directly Baidu

      • If it is not for installing C, there is no need to check the command manual

Commonly used commands

  • whereis query the location of the command file
  • file View the type of the file
  • who View current online users
  • whoami who am I
  • pwd i was there
  • uname -a View kernel information
  • echo is similar to sout syso, print statement
  • clear clear screen
  • history history

Special characters

  • .point:

    • If the beginning of the file is. Indicates that the current file is a hidden file
    • . points to the current directory
    • ...points to the parent directory of the current directory
  • $

    • Indicates that this is a variable
    • $PATH Linux environment variable
  • *Asterisk

    • wildcard
  • ~

    • current user's home directory
    • Each user's home directory is different
    • The root user's home directory is under the system root directory
    • The home directory of other users is in /home/user name is home directory
  • space

    • Linux commands and parameters are separated by spaces
  • /

    • The file root directory of the entire Linux
  • command parameters

    • If it is a word, generally add –
    • If it is a letter or abbreviation, generally add -
  • Modify Xshell font color

    PS1=‘[\e[36;40m][\u@\h \W][\e[0m]\$ ’
    echo "PS1=’[\e[36;40m][\u@\h \W][\e[0m]\$ '">>~/.bashrc
    source ~/.bashrc

4. Linux file system

everything

  • So everything in Linux is operated as a file
  • In Linux, file access is not the same as in Windows. Window relies on access through drive letters
  • Linux maintains a tree-structured file model
    • There is only one root node, and his name is /
    • A node can have multiple child nodes
  • How to find files
    • relative path
      • Use the current path as a reference point to find other resources
      • vi …/etc/sysconfig/network
      • Use the root directory as a reference point to find other resources
      • vi /etc/sysconfig/network-scripts/ifcfg-ens33
    • In daily use, you only need to find the path, but if it is some configuration files, try to write the absolute path
  • Disk can be mounted at will
    • mount /dev/disk1 /usr/download disk1 1T mount /dev/disk2 /usr/upload disk2 100T mount /dev/disk3 /usr/upload/photo disk3 1P

Linux secondary file directory

  • /bin:
    • executable file
      • such as commands and scripts
  • /boot:
    • boot partition
  • /dev :
    • Device Information
  • /etc:
    • System core configuration information
  • /home:
    • Home directory (ordinary user)
  • /lib:
    • class library
  • /media:
    • media
  • /mnt:
    • Hard disk mount
  • /opt:
    • Custom installation software path
  • /proc:
    • process information
  • /root:
    • root user home directory
  • /sbin:
    • Relevant commands and permissions that administrators can execute
  • /srv
    • Store some data that needs to be started in advance
  • /sys:
    • System kernel information
  • /tmp:
    • temporary file directory name
  • /usr:
    • Areas shared by users
  • /was:
    • This directory stores things that are constantly expanding, and we are used to putting those frequently modified directories in this directory. Includes various log files.
  • /run:
    • Some system information and variables at runtime

Linux file operations

  • cd
    • change current working directory
  • ls ll
    • Display all files in the specified directory
    • file type
      • - normal file
      • d folder
  • lSoft link
    • -rw-r–r–. 1 root root 3384 Nov 11 23:51 install.log.syslog
  • mkdir
    • Create file directory
    • mkdir -pa/b/c/d/e/f will automatically create the parent directory of the file
    • mkdir -p lucky/{1234}ls can create multiple subdirectories at a time
  • is rm
    • delete empty folder
    • It is safe to delete the file directory
  • cp
    • copy file or file directory
    • cp source file destination directory
      • cp abcd /opt
      • cp /opt/abcd ./
  • copy folder
    • cp -r lucky /opt
    • Copy all contents of the folder
    • cp: omitting directory ‘/root/a1
  • mv
    • Move a file or folder
      • mv a1 /opt
      • mv abc /opt
    • Modify the file name
      • mv a abcd
  • rm
    • Delete Files
      • rm install.log
      • rm -f install.log
    • delete folder
      • rm -r abcd
      • Use rm -rf abcd with caution, from deleting libraries to running away
  • touch
    • Create a file if not
    • If the file already exists, modify the three times of the file and change the three times to the current time
  • stat
    • View file status
    • Inode The unique identifier of the current file in the file system, similar to ID
    • time
      • access access time

      • modify Modify the file content time

      • change Modify file metadata information time

        • Descriptive information for the file
        • file size, file owner, file permissions
  • ln
    • Create a link to the file
    • soft (symbolic) link
      • ln -s lucky01 sl
      • The soft link and the original file are not the same file
        • lucky1 131085
        • sl 131074
      • rm -rf lucky1
    • hard link
      • ln lucky02 hl
      • Hard link and original file use the same file in the file system
      • If you are afraid that a file will be accidentally deleted by others, you can use hard links to protect this file
    • When linking files with soft and hard links, it is recommended to use the absolute path of the file, otherwise problems may occur

read file information

  • cat
    • Load the entire document into memory and display it all at once
    • Unless the pipeline is used later, the data is passed
  • tac
    • Load the entire document into memory and perform a one-time display in reverse row order
  • more less
    • View document content by page
    • hot key
      • carriage return next line
      • space next page
      • b fallback
      • q quit
  • head
    • Read N lines from the beginning of the article
    • By default, if there are more than 10 lines, read 10 lines, otherwise read the current number of lines
    • head -5 profile
  • tail
    • Read N lines from the end of the article
    • head -3 profile | tail -1
      • Use the pipeline to read only the Nth line
      • The function of the pipeline is equivalent to passing the previous results to the subsequent commands as parameters.
    • read new data
      • ping www.baidu.com >>baidu
      • tail -F baidu
      • if f:
        • It will monitor the file data changes of the specified inode, but when the file is deleted
        • Even if the innovation is created, the inode will change, so the monitoring fails
      • If F
        • He will listen to the file with the specified name, and if the file is deleted, it will be recreated
        • He will re-monitor the data changes of the new file, and the monitoring will not be affected
  • find
    • Find the specified file
    • find the range to look for -name name
    • find /etc -name profile

VI and VIM editors

  • open a file

    • open normally
      • we profile
    • Open the file and place the cursor on line 8
      • we +8 profile
    • open the last line
      • we + profile
      • Press n to find next, press N to find previous
    • Open the location of the specified search word
      • vi +/if profile
  • three modes

    • edit mode
      • In edit mode, each key has other functions
    • input mode
      • What is pressed on each key, just like what is entered in the data in the text
    • last line (command line) mode
      • We can enter specific commands directly in VI
  • Three modes switch

  • edit mode

    • G last line
    • gg jump to the first line
    • The number gg jumps to the number line
    • w next word
    • number w
    • dw delete a word
    • 3dw delete three words
    • dd deletes a line
    • 3dd delete three lines
    • u Returns to the previous operation
    • .rollback the operation performed by u
    • yw copy a word
    • 3yw copy three words
    • yy copy a line
    • 3yy copy three lines
    • p paste
    • 6p paste 6 times
    • x cut
    • 3x cut three characters
    • r to replace, then enter a character to replace
    • 3r replace three
    • hjkl Arrow keys
    • ZZ save and exit
    • ctrl+s lock screen ctrl+q unlock
  • input mode

    • Nothing to say. what is what
  • last row pattern

    • set nu set the line number
    • set nonu cancel line number
    • w save
    • q quit
    • wq save and exit
    • q! Force quit without saving
    • If the last abnormal exit will keep the hidden file with the same name, it will give a prompt every time it starts
      • If you are sure that the current file is OK, delete the hidden file
    • /pattern
      • search for the specified string
      • /usr n look down N reverse lookup
    • s/p1/p2/g
      • replace string
      • g replace all of the current line, otherwise only replace the first one of the current line
        • s/abc/lucky/g
      • replace full text
        • g/abc/s//lucky/g

data transfer between computers

  • Window–Linux
    • stay
      • Need to install manually
        • yum install lrzsz -y
      • rz
        • Upload files from window to Linux
      • sz file
        • Transfer files from Linux to Windows
    • xftp
      • More general file transfer method
  • Linux–Linux

File size

  • partition information
    • df -h
  • Specify file directory size
    • du -h --max-depth=1 apache-tomcat-7.0.61
  • swap
    • A special partition with a hard disk instead of RAM
    • When the memory is full, part of the data can be written out to the swap partition

file compression

  • tar
    • The main target file is lucky.tar.gz
    • unzip
      • tar -zx (decompression) v (process) f (file) lucky.tar.gz
    • compression
      • tar -zc (compression) f (file) tomcat.tar.gz (compressed name) apache-tomcat-7.0.61 (source file)
      • tar -zxf tomcat.tar.gz -C /opt/
        • -C specifies the decompressed file directory
  • zip and unzip
    • Install
      • yum install zip unzip -y
    • compression
      • zip -r tomcat.zip apache-tomcat-7.0.61
    • unzip
      • unzip tomcat.zip

5. Linux network information

host name

  • Temporary modification
    • hostname bdp
  • permanent modification
    • vi /etc/hostname

DNS resolution

  • Domain name resolution service

  • Can convert domain name to IP address

  • DNS domain name hijacking

    • window --> C:\Windows\System32\drivers\etc\hosts
    • 123.56.138.186 www.baidu.com
    • 123.56.138.186 www.taodao.com
  • Modify host domain name

    • vi /etc/hosts
    • In the future, we need to configure hosts files for all virtual machines
    • 192.168.31.101 bd1601
    • 192.168.31.102 bd1602

Network related commands

  • ifconfig

    • View the configuration information of the current network card
    • This command belongs to a command in net-tools, but the minimal version in Centos7 does not integrate this package
    • So at 7, you need to install it manually
    • If there is no ifconfig, you can use ip addr instead
  • netstat

    • View current network status information
  • ping

    • Check whether the target IP address can be connected
  • telnet

    • Check whether the specified port with the target IP can be connected
    • yum install telnet -y
    • telnet 192.168.31.44 22
  • curl

    • restful All our resources have a unique location on the web
    • Then we can identify the specified resource through this unique location
    • http://localhost:8080/lucky/user.action/666
    • curl -X GET http://www.baidu.com
  • firewall


    • A technology that helps computer networks build a relatively isolated protective barrier between internal and external networks to protect user data and information security
    • #View firewall status systemctl status firewalld.service
    • # Temporarily stop firewall systemctl stop firewalld.service
    • The correct operation of opening a port
  • Encryption Algorithm

    • Irreversible encryption algorithm

      • The encrypted result can be calculated through the data, but the encrypted data cannot be calculated through the result
      • md5
      • Hash algorithm
    • Symmetric encryption algorithm

      • Representative algorithms are called DES, 3DES, Blowfish, IDEA, RC4, RC5, RC6, and AES
      • features
        • Encryption and decryption use the same key
  • Asymmetric encryption algorithm

    • Asymmetric encryption algorithms require a pair of keys (two keys):

      • Public key (public key) and private key (private key) (referred to as public key, private key).
      • The public key and the private key are generated as a pair
      • Encryption with a public key can only be decrypted with the corresponding private key, and encryption with a private key can only be decrypted with the corresponding public key
    • Representative algorithms are called RSA, ECC, Diffie-Hellman, El Gamal, DSA (for digital signatures)

    • advantage:

      • High security (almost hard to crack)
    • shortcoming

      • Encryption and decryption are relatively slow, the key is long, the amount of calculation is large, and the efficiency is low
    • Application Scenario

      • HTTPS (ssl) certificate production, CRS request certificate, financial communication encryption, Bluetooth and other hardware information encrypted pairing transmission, key login information verification.
  • Mutual key-free between hosts

    • You can connect to other hosts without a key through the ssh command

    • If it is the first time to establish a connection, you need to enter yes

      • The information of the previous access address (ip hostname) is recorded in the ~/.ssh/known_hosts file
      • When accessing the address, if it is not included in the known_hosts file, you need to enter yes
      • If it was included in known_hosts before, just enter the password directly
    • configuration steps

      • generate key
        • ssh-keygen -t rsa -P ‘’ -f ~/.ssh/id_rsa
        • If you want to log in someone without a secret key, you only need to pass your public key to the host of the other party.
        • This key should be placed in ~/.ssh/authorized_keys
      • Send the public key to the host that needs to be exempt from the secret key
    • Mutual secret key workflow

        • Prevent every new connection from being confirmed
      • Solution 1 – this time
      • Solution 2 – All
        • Modify the configuration of the /etc/ssh/ssh_config file, and this problem will not occur again in the future
        • Add at the end:
          • StrictHostKeyChecking no
          • UserKnownHostsFile /dev/null
  • user-group-permission

    • user

      • New users
        • useradd luckyboy
        • A group and home directory with the same name will be created
      • set password
        • passwd luckyboy
      • delete users
        • userdel -r luckyboy
        • Cascade deletion of home directories and groups
      • modify user information
        • usermod -l luckyss luckyls modify username
          • The home directory and group names will not be modified
        • usermod -L luckyss lock username
        • usermod -U luckyss Unlock username
      • common files
        • cat /etc/shadow
          • user name and password
        • cat /etc/passwd
          • 7.6 System 0-999 Ordinary 1000+
          • 6.5 System 0-499 Ordinary 500+
          • Username, number, group number, home directory, command, directory
      • switch account
        • su lucky boy
    • Group

      • create group
        • groupadd lucky
      • delete group
        • groupdel lucky
      • Modify group name
        • groupmod -n bdp lucky
      • View the group corresponding to the user
        • groups
        • groups bdpboy
          • When we create a user, a primary group with the same name will be created by default
    • permissions

      • View file permissions

        • Three sets of permissions, each set of 3 letters
        • r : read permission
        • w : write permission
        • x : execute permission
        • -:permission denied
      • UGO Model of Permissions

        • Three sets of permissions
        • Permissions of the owner: Permissions of the group: other permissions
        • All said: the permission to modify the file in the future can be modified from both rwx and ugo
      • Modify file permissions

        • Modify the file belongs to

          • chown n1 /var/lucky1
          • chown n1:m1 /var/lucky2
          • When modifying a folder, let subdirectories iteratively modify
            • chown -R n1:m1 bdp
          • chgrp m2 lucky3
            • When the user's group is modified, it is necessary to log in again to obtain the permissions of the new group
        • Modify the rwx of the file

          • chmod o+w lucky4
          • chmod and+rw lucky4
          • chmod ugo-rw lucky4
            • (Permission RWX corresponds to the numbers 4 2 1 5= 4+0+1 rx respectively)
    • Authorization

      • We can assign administrative permissions to ordinary users
      • The file location is in vim /etc/sudoers
      • But modifying this file requires the use of the command
        • visado
        • Modify Line 99
        • n1 ALL=(root) /sbin/useradd
        • n1 ALL=(root) /sbin/*
      • how to use
        • are n1
        • sudo chkconfig iptables off

6. Date and time

time command

  • check time zone
    • ll /etc/localtime
      • /etc/localtime -> .../usr/share/zoneinfo/USA/Los_Angeles
    • ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
  • date
    • View current system time
  • cal view calendar
    • cal 2020
  • Change the time
    • date -s 11:11:11
    • date -s 2019-11-11
    • date -s ‘2019-11-11 11:11:11’

Automatic date synchronization

  • First install the time synchronization service
  • yum install ntp -y
  • Automatic synchronization of network time centers
  • ntpdate cn.ntp.org.cn
  • Automatic synchronization of network time center local NTP service
    • NTP server
      • vi /etc/ntp.conf
      • Added to the end
        #access control====
        restrict default kod nomodify notrap nopeer noquery Reject IPV4 users
        restrict -6 default kod nomodify notrap nopeer noquery Reject IPV6 users
        restrict 210.72.145.44 Authorize National Time Service Center server to access local NTP
        restrict 133.100.11.8 Authorize 133.100.11. 8 Access local NTP
        restrict 127.0.0.1
        restrict -6 ::1
        restrict 192.168.88.2 mask 255.255.255.0 nomodify Local network segment authorized access
        #=source server===
        server cn.ntp.org.cn prefer Specify the upper-level update time server, and use this address first
        #=Difference Analysis===
        driftfile /var/lib/ntp/drift
        keys /etc/ntp/keys
      • Enable local NTP server
        • systemctl start ntpd.service
    • synchronised time
      • Other hosts to synchronize with this host t
        • ntpdate local ip

7. Pipelines and Redirection

pipeline

  • Pass the result of the previous command as an argument to the following command
  • grep
    • Powerful Text Search Tool
    • cat profile | grep if
    • ls / | grep ^t

redirect

  • Change the position and direction of data output
  • Replace >> Append

  • 0 in 1 out 2 err
    • ls / 1 > lucky stdout
    • ls / > lucky stdout
    • ls abcd 2>lucky error output
  • In conjunction with
    • ls /etc /abc >> lucky 2>&1
    • ls /etc /abc > lucky 2>&1

8. Linux system process

process information

  • ps -ef

    • UID PID PPID C STIME TTY TIME CMD
    • The user whose UID belongs to
    • PID current process number
    • PPID The parent process ID of the current process ID
  • ps -ef | grep redis

  • ps -aux

    • all information
  • ps -aux --sort -pcpu

  • top

    • Current server memory usage

backstage process

  • Just add an & symbol after the command
    • ping www.baidu.com >> baidu &
  • jobs -l
    • You can view the current background process
    • But only the current UI can get
  • nohup prevents background processes from being suspended
    • nohup ping www.baidu.com >> baidu 2>&1 &

kill process

  • kill -9 17599

9. Linux software installation

environment variable

  • 1. If multiple configured folders contain the command abc, abc in the first folder will be executed by default
  • 2. Try to configure some important folders and directories in the environment variables to reduce the time for command retrieval
  • 3. After modifying the configuration, you need to reload the configuration information
  • Linux environment variable location
    • /etc/profile
  • The window environment variable folder is separated by a semicolon; in LInux, it is separated by:

How to install the software

  • Archive
  • rpm package
    • Download the installation package yourself
    • Use unified software to help us install
  • Source package installation

Compression package installation

YUM installation

  • The role of yum

    • Can help us manage RPM packages
    • can help us install the software,
    • If the software has other dependencies, it will help us install the dependencies before installing the software
    • Similar to Maven
  • yum command

    • search query command or software
    • info
    • View package information
    • list / list jdk
    • Query the installed rpm package, or only query a certain week
  • Replace yum source

  • This mysql installation belongs to yum installation

rpm install

  • RedHat Package Manager, which belongs to Red Hat's package management method

  • This jdk installation belongs to the rpm installation

10. Linux Three Musketeers

common swordsman

  • cut

    • Split the text with the specified rules
    • cut -d’:’ -f1,2,3 passwd | grep bdp
  • sort

    • sort lucky

      • Sort lines in text
    • sort -t’ ’ -k2 lucky

      • Segment the data of each row and sort according to the second column
    • sort -t’ ’ -k2 -r lucky

      • reverse order
    • sort -t’ ’ -k2 -n lucky

      • Sort according to the size of the value, if there are letters, the letters come first
  • wc

    • Count the number of words
    • wc lucky
    • 4 15 79 lucky
      • -l line
      • -w word separate words by spaces
      • -c char

Swordsman No. 1: grep

  • text can be searched

  • Search multiple files simultaneously

  • Show matching line numbers

    • grep -n bdp passwd
  • Show unmatched ignore case

    • grep -nvi root passwd --color=auto
  • Match using regular expressions

    • grep -E “[1-9]+” passwd --color=auto

Swordsman 2: sed

  • sed is the abbreviation of Stream Editor (character stream editor), referred to as stream editor

  • Sed software reads one line from a file or pipeline, processes one line, and outputs one line; reads another line, processes another line, and outputs another line

  • The one-line-at-a-time design makes the sed software very performant

  • The vi command to open a file is to load the file into memory at one time

  • just understand

  • row selection mode

    • 10 tenth line
    • m,n --> line m to line n[m,n]
    • m,+n–>The first line to the fourth line [m,m+n]
    • m~n–>starting from line m, add n in turn
    • m, $ --> from m to the last line
    • /bdp/ -->Line matching to bdp
    • /u1/,/u4/–>From matching u1 to matching u4
  • increase

    • sed '2a luckyisgood' passwd
    • sed ‘2i luckyisgood’ passwd
      • print to console
    • sed -i '2a luckyisgood' passwd
      • modify directly to the file
  • delete

    • sed ‘3,10d’ passwd
  • change

    • replace whole line
      • sed ‘3,20c hahaha’ passwd
      • sed '3~1c hehehe' passwd
  • character replacement

    • sed ‘1,5s/root/lucky/g’ passwd
    • sed ‘1,5s#/#-#g’ passwd

Swordsman No. 3: awk

  • It's not a swordsman, it's a language

  • just understand

  • Modes and Actions

    • awk -F “:” ‘NR>=2&&NR<=6’ /etc/passwd
    • awk -F “:” ‘{print NR,$1}’ /etc/passwd
    • awk -F “:” ‘NR>=2&&NR<=6 {print NR,$1}’ /etc/passwd
    • awk -F “:” ‘NR==1{print NR,KaTeX parse error: Expected 'EOF', got '}' at position 2: 1}̲NR==2{print NR,NF}’ /etc/passwd

11. shell programming

As a big data developer, it is enough to have a basic understanding of shell programming. The following are just some basic shell programming knowledge suitable for learning and understanding. In terms of operation and maintenance, shell programming will be much more important.

Shell noun explanation

  • Kernel

    • The Linux kernel is mainly for dealing with hardware
  • Shell

    • command interpreter
    • Shell is a program written in C language. Shell is both a command language and a programming language.
  • There are two main streams of shell:

    • sh:

      • Bourne shell (sh), Solaris, hpux default shell
      • Bourne again shell (bash), Linux system default shell
    • csh

      • C shell(csh)
      • tc shell(tcsh)
  • #! statement

    • Tell the system that the program specified by the subsequent path is the shell program that interprets this script file

Execution of Shell scripts

  • Enter an absolute or relative path to the script

    • /root/helloworld.sh
    • ./helloworld.sh
    • Executing must be an executable file
  • bash or sh + script

    • sh helloworld.sh
    • When the script does not have x permission, root and file owner can execute normally in this way
  • Add "." or source before the path of the script

    • source helloworld.sh
  • the difference

    • The first and second types will open a new bash, and variables in different bashes cannot be shared.
    • The third is executed in the same shell
  • export : You can pass the variables of the current process to the child process for use

    • When configuring the profile in the future, all variables must be preceded by export

Getting Started with Shell Basics

  • shell variable
  • variable type
  • shell string
  • Shell array
  • Shell Notes
  • Shell parameter passing

Advanced Shell Advanced

  • Shell operator
  • Shell process control
  • echo print data
  • test command
  • Shell function

System Task Settings

  • System startup process

  • boot self-starting service

    • rc.local

      • First create the folder where the script is stored

        • mkdir -p /usr/local/scripts
      • Create script files in the folder

        • vim hello.sh
        • give execute permission
      • Go to the /etc/rc.d/rc.local file to add the absolute path of the script

        • Give rc.local execution permission
      • Restart the virtual machine

        • reboot
    • chkconfig

      • Create boot script file

        • vim schoolntpdate.sh

          • start of script

            #!/bin/bash
            #chkconfig: 2345 88 99
            #description:auto_run

            start scripting

      • Set execute permission to it

        • chmod u+x schoolntpdate.sh
      • Copy the script to the /etc/init.d directory

        • cp schoolntpdate.sh /etc/init.d/
      • add to service

        • chkconfig --add /etc/init.d/schoolntpdate.sh
      • restart server

        • reboot
  • timed task

    • In the system service center, crond is responsible for periodic tasks

      • systemctl status crond.service
    • Add tasks, edit the current user's task list

      • crontab -e
    • edit task

      30 21 * * * /usr/local/etc/rc.d/lighttpd restart
      The above example means to restart apache every night at 21:30.
      45 4 1,10,22 * * /usr/local/etc/rc.d/lighttpd restart
      The above example means to restart apache at 4:45 on the 1st, 10th, and 22nd of each month.
      10 1 * * 6,0 /usr/local/etc/rc.d/lighttpd restart
      The above example means to restart apache every Saturday and Sunday at 1:10.
      0,30 18-23 * * * /usr/local/etc/rc.d/lighttpd restart
      The above example means to restart apache every 30 minutes between 18:00 and 23:00 every day.
      0 23 * * 6 /usr/local/etc/rc.d/lighttpd restart
      The above example means to restart apache every Saturday at 11:00 pm.

      • */2 * * * /usr/local/etc/rc.d/lighttpd restart
        restarts apache every two hours
      • 23-7/1 * * * /usr/local/etc/rc.d/lighttpd restart
        between 11pm and 7am, restart apache every hour
        0 11 4 * mon-wed /usr/local/etc /rc.d/lighttpd restart
        Restart apache on the 4th of every month and every Monday to Wednesday at 11 o'clock
        0 4 1 jan * /usr/local/etc/rc.d/lighttpd restart
        Restart apache at 4 o'clock on January 1st
        – (Function description: display the year, month, day, hour, minute, and second)
        date "+%Y%m%d%H%M%S"
    • Restart crontab to make the configuration take effect

      • systemctl restart crond.service
    • via crontab -l

      • View current scheduled tasks
    • View the history of tasks

      • vim /var/spool/mail/root
    • clear task

      • crontab -r

Virtual machine initialization script

Virtual machines are free from each other's secret key

## Three hosts generate secret keys respectively
[123] ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa
##host verification
[123] vim /etc/ssh/ssh_config Add
StrictHostKeyChecking no
UserKnownHostsFile at the end /dev/null
##Copy the secret key to yourself and others
[123] ssh-copy-id -i ~/.ssh/id_rsa.pub root@node01
[123] ssh-copy-id -i ~/.ssh /id_rsa.pub root@node02
【123】ssh-copy-id -i ~/.ssh/id_rsa.pub root@node03
123456
##Turn off the host to take snapshot
power off

Guess you like

Origin blog.csdn.net/m0_49303490/article/details/126159590