By default, Linux does not allow you to log in to the root user on the desktop

With # #save

Continue typing at the terminal

gedit /etc/pam.d/gdm-password
Copy the code

With # #save

restart

Executable script

Script Script, a program that explains execution Three scripts commonly used under Linux

  • A Shell script. Sh
  • The Perl script. Pl
  • Python scripts. Py

Script program, is essentially a text file

  • 1 It is a text file
  • 2 It has executable permissions

Demo: Hello. sh is a script program.

Scripts are executed by the interpreter

  • Shell script interpreter :/bin/sh
  • Perl script interpreter :/bin/perl
  • Python script interpreter :/bin/python3

When executing a script, the following two methods are equivalent

  • ./hello.py
  • /bin/python3 hello.py

A Shell script

  • Shell script: a script written according to the Shell syntax

  • Is a scripting language that comes with Linux

  • Equivalent to DOS batch scripts under Windows

The first line declares the interpreter

The executable (x) permission must be added before running, and the path must be added when executing

Variables in the SHELL

SHELL is a scripting language

  • Define variables
  • Execute the command
  • If judgment logic, while loop logic
  • Custom functions…

User environment variables

User environment variables: defined in ~ /.profile

In the home directory

  • ls -a
  • A indicates all, and all files are displayed
  • Note: Under Linux, to. Files at the beginning are hidden files

Log out after saving and open again

Principle: When the user opens the terminal, it automatically runs.profile, injecting variables into the current environment.

Key points and details

  • This configuration is valid only for the current user
  • Because each user has their own.profile profile, some Linux systems use.bash_profile

System environment variable

System environment variables: defined in /etc/profile

The environment variables in this are valid for all users

  • Run gedit /etc/profile as the root user
  • However, you do not modify /etc/profile directly
  • Instead, create a custom script in /etc/profile.d/

Presentation:

  • 1 Create a script using gedit

gedit /etc/profile.d/myprofile.sh

  • 2 Define environment variables

export TOMCAT=/opt/tomcat

  • 3 Log out and log in again

After you log in again, the environment variables take effect

PATH environment variable

Let’s start with a problem: create an executable script hello.sh

Direct execution:

Why can’t you find it in the current directory?

PATH, one of the most common environment variables, describes the search PATH of an executable program

echo $PATH
Copy the code

Multiple paths are separated by colons

usr/local/bin:/usr/local/sbin:/usr/bin:/usr
/sbin
Copy the code

By default, the system searches for executable programs from the following directories

/usr/bin For example, /usr/bin/tar /usr/sbin For example, /usr/sbin/useradd /usr/local/bin/usr/local/sbinCopy the code

Sbin is a program that can be executed only by the root user

/usr/local/is a built-in program installed by the user

Demo: Modify the PATH environment variable

  • The editor/etc/profile.d/myprofile.sh

Set the PATH environment variable export PATH=$PATH :/opt/tomcat/bin

  • Log out and take effect after you log in again

Before setting the PATH environment variable

Add PATH variable

after

Virtual Machine network

VMware software creates two virtual network cards, VMware Net 1 and 8

When a virtual machine accesses the Internet, it uses a VMwarenet8 network adapter

You can use the ping command to check whether there is a network, you can see yes, and then Ctrl+C exit, you can see 28 packets sent, 28 packets received, no packet loss phenomenon.

The VM is connected to the local host

IP address of the VM

The local IP address, command line: ipconfig

Check the status of the local NIC (VMnet8)

Notice A VM cannot ping a local host, but a local host can ping a VM

However, we can set up a service on the local host (using the IP address of VM8 network card).

The software is called HFS

Then access the vm through a browser

NAT Network Access Principle

Configure the network

In the terminal, the network is configured on the command line

Common commands :ifconfig, netstat, etc. By default, Ubuntu does not carry the ifconfig command

The APT package manager is required

  • Apt install net-tools install net-tools
  • Apt Remove Net-tools Removes a software package
  • Apt search XXX search
  • Apt list l grep XXX

Procedure 1 Check network configurations

ifconfigl
Copy the code

If indicates interface, which lists all network interfaces and the status of each interface

2 Enable or disable the network

sudo ifconfig xxx up
sudo ifconfig xxx down
Copy the code

FTP and SSH servers

Question to consider: How do I upload files to Ubuntu? 1. Copy on usb flash drive. 2

  • FTP
  • SFTP

Demo: Use FTP to transfer files

  • Client FileZilla (Windows)
  • Server VSFTPD (Ubuntu)

SSH server

This is more convenient than FTP

Presentation:

  • Log in remotely using Xshell

  • Transfer files using Xftp

SSH is a secure protocol based on the DU foundation at the application layer and bai transport layer. SSH uses THE TCP protocol for ZHI connection dao to transmit port 22 in the application.

FTP is the Abbreviation of File Transfer Protocol (FTP). In THE TCP/IP protocol, FTP occupies two ports. The TCP Port number of the FTP standard command is 21, and the data Port number is 20. While FTP can be encrypted over SSL to control connections, FTP is not encrypted when transferring data over a data port. You can use SSH to encrypt FTP data transmission, that is, SFTP.

In addition to being a security protocol, SSH is sometimes used as an application. For devices or systems that enable the SSH service, SSH client software (similar to TELNET) can be used to connect to the device or system on the terminal and even transfer files. I often use this to connect to LINUX servers and routes.

Text editing vim

  • Vi/Vim, a console-based text editor
  • Gedit, a GUi-based text editor
  • Vim is the upgraded version of VI

Switch mode

  • Insert Mode: Press I

  • Command Mode Command Mode: Press ESC

Exit the editor

(1) Press ESC to enter the command mode

(2)- Enter :wq to save the configuration and exit

  • The input:qexit
  • The input:q!Force exit (forego save)

Vim has more uses

The full use of Vim is very complex and varied, almost every key on the keyboard is a fast key, and it is not recommended to delve into it in depth. Vim itself is an inefficient tool

Linux text file editing

1 Desktop environment: Gedit

2 Terminal Environment:

  • Minor modification :vim
  • Mass modification: Edit on Windows, then upload to Linux

Open the Xshell

Drag and drop

Pay attention to format conversion!

Newline character of a text file

  • Windows : \r\n
  • Linux : \n

This difference can be observed in notepad + +, view | display symbol | end-of-line character

Line feed conversion:

Convert files to Linux first

Edit | | document format conversion into UNIX format

Note: This is only necessary when editing SHELL scripts; files in other formats, such as *.xml and *.java, generally do not need to be converted

The installation of Java

  • Jre: Required when running Java programs
  • JDK: Used when developing Java programs

Generally, it is recommended to install version 8, which is relatively stable. Ubuntu just needs to download the JRE and run the code on it

Its installation – 8 – jre – headless

ls /usr/bin/java
Copy the code

The default PATH is /usr/bin. You do not need to set the PATH

Tip: If in a custom location, you need to set the PATH

export PATH-$PATH:/opt/jdk8/binr
Copy the code

1 Develop and debug on Windows

2 release

  • The class file
  • Plain JAR files/executable JAR files

The two JAR files run differently:

java -cp your_program.jar your.MainClass
java -jar your_program.jar
Copy the code

3 Upload to Linux: FTP/SFTP

4 Running the program

java -jar simple.jar
Copy the code

5 Check the permission factor

Programs that need access to system files such as /etc/are run root, and programs that need access to TCP ports such as 80 are run root

Note that Java GUI programs cannot run on a terminal

However, we usually use scripts to run Java packages, such as the one that runs your_app.jar

Send the script to Linux via Xftp

Add permission, run the script

chmod +x run_java.sh
. /run_java.sh
Copy the code

Programs and processes

Program: Refers to a Program file, such as notepad.exe

Process: When a program is run, a record is created in the operating system that describes and controls its execution

Start a program

Enter the command to view all Linux processes

ps -ef
Copy the code

Sort by start time

You can find the process you just started

Where, the meanings of each field are:

  • UID: practitioner
  • PID: process ID
  • PPID: indicates the ID of the parent process
  • STIME: indicates the startup time
  • CMD: the command line invoked at startup
Ps - f | grep XXXCopy the code

Process monitoring

The output information is redirected to the grep command for filtering

The top command is equivalent to the Windows task manager command

  • Press up and down to browse
  • Press Q or CTRL+C to abort exit

Viewing a process (by process number)

top -p PID
Copy the code

End a process

kill -9 PID
Copy the code

Foreground and background processes

Foreground processes: Run in the foreground

Background processes: Run in the background

Demo: For example, running the Tomcat server

  • /run_tomcat run Run from the front desk (i.e. the current terminal) (CTRL+C abort)

  • /run_tomcat start Run in background mode

  • Difference 1: Console or not

Foreground process: has console, output to the current terminal

Background process: No console, no output

  • Difference 2: There is no parent process

Foreground process: has a parent process. The parent process is the current terminal. When the terminal is shut down, the foreground process is shut down together

Use CTRL+C to force the terminationCopy the code

Background process: The parent process is the system process (process 1). When the terminal is shut down, the background process is not affected

Run the kill -9 PID command to forcibly terminate the commandCopy the code

The server

Redis server

Redis is a memory based key-value database

  • Redis server installation
  • Redis configuration
  • Redis source code compilation

MySql server