linux-directory structure

Directory Structure

Directory Structure Preliminary Knowledge

  • Structural Features Description

    1. The directory under the linux root is a hierarchical tree structure

    2. Each directory of linux can be mounted on a different device (disk)

    What is mount:

    like a disk-Equipment (room) Want to store things to enter from the door>:directory (mount point)
    Disk device "-- mount --> Portal (directory)
    
  • Practical operation to realize the mounting process

    First step: owning a storage device (optical drive)

    The second step: find the corresponding optical drive device

     [root@jasonNB ~]# ls /dev/cdrom/dev/cdrom
     [root@jasonNB ~]# ls -l /dev/cdrom
     lrwxrwxrwx. 1 root root 3 Dec 6 09:07/dev/cdrom -> sr0
    

    The third process: carry out the mount operation

    mount /dev/cdrom /mnt/ (the mount point directory must exist)

    The fourth step: confirm whether the mount is successful ----> ls /mnt

    Fifth process: unmount ----> umount /mnt

Directory Structure Description

  • The evolution of the directory structure

    ​ One disk: root directory

    ​ Two disks: /usr directory

    ​ Extension: FHS file system directory specification

Important Directory Data Information Notes

NIC configuration file

Order instruction
network card configuration file /etc/sysconfig/network-scripts/ifcfg-eth0 or ens33
Backup in advance when editing network card files cp xxx /tmp/xxx.bak
Invoke the last parameter information of the previous command ps:esc + .
After the network card file is modified, restart the network service systemctl restart network

Initialize software installation yum install -y vim tree bashcompletion (provides command parameter completion function systemctl)

  • Information about the internal field data of the network card configuration file

    BOOTPROTO=none 	Start the agreement Get IP How to get the address automatically dhcp Manually
     set up
    DEFROUTE=yes 	The default route network is enabled (default route dynamic route static route
     Depend on)
    NAME=eth0 		Network card logical name
    UUID=... 		Identify some hardware device information in the virtualization software
    DEVICE=eth0 	Network card device name
    ONBOOT=yes 		Make sure the network card is active
    IPADDR=10.0.0.200 IP address settings
    PREFIX=24 		Set the subnet mask to ensure how many hosts can be connected to a local area network Default 253
    GATEWAY=10.0.0.254 Gateway information The necessary gateway for communication between different LANs 
    					required and in the virtual editor nat The network card settings remain the same
    IPV6_PRIVACY=no
    DNS=114.114.114.114 DNS Domain Name Resolution Service 
    
    

DNS service setting method

1. Set as the address of the Alibaba Cloud dns server

223.5.5.5
223.6.6.6

2. Generic dns server address

114.114.114.114
114.114.114.119

3. Use mobile dns server (Google dns server)

8.8.8.8

4. Use the gateway address as the dns server address

10.0.0.254

Network card domain name resolution configuration file / etc/resolv.conf

  • Editing command operations of the configuration file of network card domain name resolution

    vi /etc/resolv.conf
    nameserver 114.114.114.114
    nameserver 223.5.5.5
    

    After the configuration is completed, it will take effect immediately. The dns configuration of the network card takes precedence over the configuration in the resolv.conf file

hostname profile

  • Different hostname profiles for different versions

    Version command path
    centos6 /etc/sysconfig/network
    centos7 /etc/hostname
  • Modify hostname

    • The first step: modify the host name using the command (temporary modification)

      hostname jasonNB
      

      After the modification is completed, you need to reconnect for the command to take effect.

    • The second step: Edit and modify the configuration file (permanent modification)

      vi /etc/hostname
      centos7 There are special ways to modify the host name:
       hostnamectl set-hostname oldboyds05
      

Local domain name resolution file /etc/hosts

  • Website page information change

    Small companies directly debug online servers Usually operate at night with few users, easy to maintain

    Large enterprises Directly debug and test server test access Simulate real environment access

  • Large business case

    ​ JD online website server address 112.65.34.1

    ​ JD.com offline website server address 10.0.0.200

    Modulate the local domain name

    [root@jasonNB ~]# vi /etc/hosts
    10.0.0.200 www.jd.com # Specify the mapping relationship
    

Network failure troubleshooting process

1. Confirm whether the gateway address is unblocked

2. Confirm whether the network card configuration is correct

3. Confirm that the network management service is closed

systemctl stop NetworkManager
systemctl disable NetworkManager

Important data files in the etc directory

/etc/fstab

​ filesystem table system mount information table

Disk --- Partition formatting --- Disk device can be seen in the system --- Mount (open a page)

All storage devices must be mounted before they can be used

  • Mounting is divided into temporary mounting and permanent mounting

    ​ Temporary mount: mount /dev/cdrom /mnt

    ​ Permanent mount: Modify a configuration file /etc/fstab related to auto-mounting at boot

  • settings file

    device file mount point
    /dev/first partition /boot
    /dev/ second partition swap
    /dev/ third partition /

    View the file content: cat /etc/fstab

    View disk partition: blkid

  • Summarize

    Realize disk storage devices, mount operations take effect permanently, and automatically load mount information when booting

/etc/rc.local

​ This file can only store linux system command operation information

  • This file operation process

    ①The system is loaded and started normally

    ②Read the rc.local file

    ③The file mainly saves command information

    ④Execute the command in the file

    ⑤The system starts successfully

  • Automatic backup at boot

    cp /etc/sysconfig/network-scripts/ifcfg-eth0/tmp/ifcfg-eth0.bak
    
    
    echo "cp /etc/sysconfig/network-scripts/ifcfgeth0 /tmp/ifcfg-eth0.bak" >> /etc/rc.local
    

    centos6: Just follow the instructions above

    centos7: chmod +x /etc/rc.d/rc.local

  • Operation and maintenance operation specification (operation and maintenance personnel == firefighters)

    ①Check before operation

    ② Backup before operation

    ③Confirm after operation

    ④Summary after the operation

  • specific operation

    ①Check whether there is a backup file in the corresponding path. There is a backup file: delete it

    ② Test execution on the command line first

    ③ Edit the configuration file rc.local to automatically load the command at startup

    ④Restart the system to confirm

/etc/inittab centos6 vs centos7

  • system startup runlevel

    A System startup: Network service running, Security service running, Storage service running Level 01
    B System startup: Security service running Storage service running Level 02
    C System startup: storage service running level 03
    

    Three systems: different startup levels

  • centos6 (7 runlevels)

     0 shutdown level ( init 0)  
     1 Single user mode (reset user password information root Repair system) rescue mode 
     2 multi-user mode NFS (no internet service) 
     3 Multi-User Mode (Command Line Mode) 
     4 unknown unused 
     5 Graphical interface mode ( init 5) 
     6 restart level
    
  • centos7 (target target)

    ls /usr/lib/systemd/system/runlevel*target -l
     poweroff.target
     rescue.target
     multi-user.target
     multi-user.target
     multi-user.target
     graphical.target
     reboot.target
    
  • Adjust system runlevel

    1.centos6

    ​ init level information Temporary modification

    ​ vim /etc/inittab permanent modification

    2.centos7

    ​ systemctl get-default Get level information

    ​ systemctl set-default modified the level

/etc/profile

Configure environment variable information or alias information file (important)

  • Environment Variable Characteristics

    1. All environment variables are represented by uppercase letters.

    2. Environment variables can be used by all users

    3. The environment is generally set up after system installation

  • Mileage of environment variables

    Step 1: Defining Variables

    [root@jasonNB ~]# oldboy=123
    

    The second process: call variable information

    [root@jasonNB ~]# echo $oldboy
    

    The third step: adjust the variable value information

    [root@jasonNB ~]# oldboy=456
    [root@jasonNB ~]# echo $oldboy
    

/etc/bashrc

​ Specially used to set alias information

  • Aliases simplify complex commands

  • 'The definition of aliases can be set either in profile or in bashrc

    /etc/profile national law 
     /etc/bashrc national law
     ~/.bashrc House rules
     ~/.bash_profile House rules
    

/etc/motd

​ Prompt information after the user logs in to the system

/etc/issue /etc/issue.net(centos7 more)

​ Prompt information before the user logs in to the system

Important data files in the usr directory

/usr/local/ is used to save user-installed software program information

How to install software in linux system (four ways)

  • 1.yum installation software

    ​ Can resolve software dependencies

    E.g:

    Everything you need to buy takeaway is ready to be collected:
    yum install -y tree vim bash-completion
     For the software in question, you can reinstall it to fix:
    yum reinstall -y tree vim bash-completion
    
  • 2. Install software in rpm package

    A software installation package is required in the system

    Unable to resolve software dependencies 
    rpm -ivh xxx.rpm
    -i install Install
    -v verbose show details
    -h human Display information in a way that is better understood by humans
    
    rpm -qa tree
    -q query Inquire
    -a all All software information 
    
    rpm -ql vim-enhanced
    -l list Displays list information of software installation directories
    
    rpm -e tree Uninstall software
    	-e erase wipe out==delete
    

    ps:yum remove tree Do not use this method to uninstall

  • 3. Compile and install the software

    ​ Installation software is more flexible

    eg: buy raw materials (non-finished products) for cooking, you can flexibly adjust the taste of the food

    Set the software installation path Specify the software function information

  • 4. Binary package installation software

    ​ Install software and deploy efficiently

    eg: small zero instant ready-to-use convenient and simple

    CS software installation package (green version free installation)

Important data files in the var directory

Frequently changing files are stored in variable

Frequently changing files >>>: log file

Order effect
/var/log/messages Service operation information, system operation or abnormal information
/var/log/secure User login information save file
  • Check log information regularly

    [root@jasonNB ~]# grep # Three Musketeers Central Three 
     [root@jasonNB ~]# grep "Failed" /var/log/secure
    # If the log file is too large, it must be cut
     cat /etc/services >> a.txt # continuous append
     cat a.txt # Check for stuttering
     secure-0k > secure-100k > Size range 10 M > cut securebak01 secure
     ls -l /var/log/secure* # View Default Cut Policy Cut by Days
    
    

Important data files in the proc directory

Log some hardware usage Hardware details

​ CPU # /proc/cpuinfo

  • Command to view CPU information

    lscpu
     CPU(s): 4 How many cores does the entire server have
     Core(s) per socket: 2 each CPU how many cores
     Socket(s): 2 There are several servers CPU
    
  • Command to view memory information

    cat /proc/meminfo
     MemTotal: 2030172 kB --- The total memory capacity of the server
     MemFree: 1755372 kB --- server unused CPU capacity
     MemAvailable: 1728900 kB --- The server can also use
     Buffers: 2076 kB 
     Cached: 86716 kB
     real-time usage
     free,free -h
    
  • Command to view disk information

    df -h
     Check the load
     cat /proc/loadavg
        
     	0.00	 					0.01			 0.03
     Average load per minute 				Average 5 minute load 	Average 15 minute load
     The value of the load cannot exceed the number of cores of the server 	8 nuclear			 7(threshold)
        
    Use commands to view load information
     [root@oldboysh03 ~]# w
     15:39:53 up 43 min, 	2 users, load average: 0.00,0.01, 0.03
     Current time Server running time Number of connected users Average load	
    
    View mount information
     df -h
     cat /proc/mounts # Record system mount information
    

Tags: Linux

Posted by misseether on Wed, 19 Oct 2022 16:43:35 +0530