Java backend: learning notes on the basic use of Linux

Linux

brief introduction

  • The Linux kernel was originally written by Finnish Linus Torvalds as a hobby when he was studying at the University of Helsinki.

  • Linux is a UNIX like operating system that is free to use and spread. It is a multi-user, multi task, multi thread and multi CPU operating system based on POSIX (portable operating system interface) and UNIX.

  • Linux can run the main UNIX tools, software, applications and network protocols. It supports 32-bit and 64 bit hardware. Linux inherits the design idea of UNIX with network as the core. It is a multi-user network operating system with stable performance.

    At present, the well-known distribution versions on the market include Ubuntu, RedHat, CentOS, Debian, Fedora, SuSE, OpenSUSE, Arch Linux, SolusOS, etc.

Environment construction

Install CentOS image (VMware Workstation)

Purchase ECS

  1. Alibaba cloud purchases servers: https://www.aliyun.com/minisite/goods?userCode=0phtycgr

  2. After the purchase, get the ip address of the server, reset the server password, and you can log in remotely

  3. Download xShell tool for remote connection! The effect of successful connection is as follows:

[the external chain image transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-lqxxgygf-1622178778296) (C: \ users \ supreme host \ desktop \ notebook \ 1)]

Walk into Linux system

Boot login

Boot will start many programs. They are called "service s" in Windows and "daemon s" in Linux.

After the boot is successful, it will display a text login interface, which is the login interface we often see. In this login interface, the user will be prompted to enter the user name, and the user entered by the user will be passed to the login program as a parameter to verify the user's identity. The password is not displayed. Just enter after entering!

Generally speaking, there are three login methods for users:

  • Command line login
  • ssh login
  • Graphical interface login

The account with the highest authority is root, which can operate everything!

Shut down

In the field of linux, it is mostly used on the server, and rarely encountered the operation of shutdown. After all, running a service on the server is endless. It will be shut down only under special circumstances.

#Shutdown command
shutdown 
sync # Synchronize data from memory to hard disk.

shutdown # Shutdown instructions, you can man shutdown to see the help document. For example, you can run the following command to shut down:

shutdown –h 10 # This command tells you that the computer will shut down in 10 minutes

shutdown –h now # Turn it off immediately

shutdown –h 20:25 # The system will shut down at 20:25 today

shutdown –h +10 # Turn it off in ten minutes

shutdown –r now # The system restarts immediately

shutdown –r +10 # The system will restart in ten minutes

reboot # Is to restart, which is equivalent to shutdown – r now

halt # Shut down the system, equivalent to shutdown – h now and poweroff

First, write the data in the system to the disk, whether it is running or running sync. Finally, write the data in the system to the disk.

System directory

#Switch directory
[root@hecs-x-medium-2-linux-20210523182654 ~]# cd /
[root@hecs-x-medium-2-linux-20210523182654 /]# ls
bin  boot  CloudResetPwdUpdateAgent  CloudrResetPwdAgent  dev  etc  home  lib  lib64  lost+found  media  mnt  opt  patch  proc  root  run  sbin  srv  sys  tmp  usr  var  www

  • The following is an explanation of these directories:
    • /Bin: bin is the abbreviation of Binary. This directory stores the most frequently used commands.
    • /boot: here are some core files used when starting Linux, including some connection files and image files.
    • /Dev: dev is the abbreviation of device. It stores external devices of Linux. The way to access devices and files in Linux is the same.
    • /etc: this directory is used to store all configuration files and subdirectories required for system management.
    • /Home: the user's home directory. In Linux, each user has its own directory. Generally, the directory name is named after the user's account.
    • /lib: this directory stores the most basic dynamic connection shared library of the system, which is similar to the DLL file in Windows.
    • /lost+found: this directory is generally empty. When the system shuts down illegally, some files are stored here.
    • /media: the linux system will automatically identify some devices, such as U SB flash disk, optical drive, etc. when identified, linux will mount the identified devices to this directory.
    • /mnt: the system provides this directory to allow users to temporarily mount other file systems. We can mount the optical drive on / mnt /, and then enter this directory to view the contents of the optical drive.
    • /opt: This is the directory where additional software is installed for the host. For example, if you install an ORACLE database, you can put it in this directory. The default is empty.
    • /proc: this directory is a virtual directory, which is the mapping of system memory. We can access this directory directly to obtain system information.
    • /root: this directory is the user home directory of the system administrator, also known as the super authority.
    • /sbin: s means Super User. Here is the system management program used by the system administrator.
    • /srv: this directory stores some data to be extracted after the service is started.
    • /sys: This is Linux 2 A big change in the 6 kernel. A new file system sysfs in the 2.6 kernel is installed in this directory.
    • /tmp: this directory is used to store some temporary files.
    • /usr: This is a very important directory. Many applications and files of users are placed in this directory, which is similar to the program files directory under windows.
    • /usr/bin: application used by system users.
    • /usr/sbin: a relatively advanced hypervisor and system daemon used by super users.
    • /usr/src: the default placement directory of kernel source code.
    • /var: this directory stores things that are constantly expanding. We are used to putting those directories that are often modified under this directory. Including various log files.
    • /run: a temporary file system that stores information since the system was started. When the system restarts, the files in this directory should be deleted or cleared.

Common basic commands

File and directory management

cd/home #Enter '/ home' directory ' 
cd ..   #Return to parent directory
cd ../.. #Return to the upper two directories
pwd   #Non password -- > Print work directory
ls -all  #View files, including hidden files
cp -r sourceFolder targetFolder #Copy a file, including its children, to the target file
mkdir newFolder #Create file directory
mkdir -p /file1/file2/file3 #Create multiple file directories
mv -rf dir1 dir2 #Rename / move a directory
cp file1 file2 #Copy file
cp dir/* #Copy all files in dir directory to the current working directory
rmdir oldFolder	#Delete the file directory (it cannot be deleted when there are sub files under the directory)
rm -rf deleteFile #Delete files, including their children
chmod 777 file  #Modify file permissions (r:1,w:2,x:4) 7 means that all operations can be performed

#RPM
rpm -ivh package.rpm #Install an rpm package

#view file contents
cat file  #Forward viewing of file contents from the first byte
tac file  #Reverse the file contents from the last line
more file #View long file contents (space page turning / enter the next line)
head -n file #View the first n lines of the file
tail -n file #View the last n lines of the file


  • Vim editor

    • vim has the ability of program editing. It can distinguish the correctness of grammar by font color, which is convenient for program design;

    • Because the program is simple, the editing speed is quite fast.
      vim can be used as an upgraded version of vi. it can display some special information in a variety of colors.

    • vim will judge the content of the file according to the file extension or the beginning information in the file, and automatically execute the syntax judgment formula of the program, and then display the program code and general information in color.

    • vim adds many additional functions, such as regular expression search, multi file editing, block copy and so on.

    • General mode, edit mode and command line mode

      • Switch from general mode to edit mode: press i

      • Switch from general mode to command mode: wq leave after saving

      • Switch from edit mode to command mode: press Esc

    #Vim editor (upgraded version of Vi)	
    vim helloworld.java  #Edit file
    
  • process

    ps -ef|grep tomcat #View the process of tomcat
    kill -9 1989 #Terminate the thread with process number 1989
    lsof -i:1212 #View the thread with thread number 1213
    
  • Deploy Java SpringBoot project

    Take the jar package as a demonstration

    cd fileTarger   #Switch to the directory of Jar package
    
    #Normal deployment (you cannot enter other commands after the project runs in this mode)
    java -jar springboot.jar
    
    #Deploy in the background (you can continue to enter other commands after running)
    nohup java -jar springboot.jar  >/dev/null 2>&1 &
    
    

Environment configuration

JDK installation

  • First install jdk8 rpm (jdk-8u291-linux-x64.rpm)

  • First, check whether the Java environment has been configured

    [root@hecs-x-medium-2-linux-20210523182654 taylorswift]# java -version
    
  • Configuration environment

    [root@hecs-x-medium-2-linux-20210523182654 taylorswift]# rpm -ivh jdk-8u291-linux-x64.rpm
    
  • Delete environment

    [root@hecs-x-medium-2-linux-20210523182654 taylorswift]# rpm -e --nodeps jdk-8u291-linux-x64.rpm
    
  • Configure environment variables (this step can be ignored for rpm package configuration)

    Open / etc/profile and add a configuration at the end of the file [actually the same as the window installation environment variable]

    JAVA_HOME=/usr/java/jdk1.8.0_291-amd64
    CLASSPATH=%JAVA_HOME%/lib;%JAVA_HOME%/jre/lib
    PATH=$JAVA_HOME/bin;$JAVA_HOME/jre/bin
    export PATH CLASSPATH JAVA_HOME					#Export variables
    

Keywords: Java Linux

Added by ekosoftco on Tue, 08 Feb 2022 04:30:31 +0200