[Linux] Common instructions in Linux and deploying the java program operating environment to Linux

Table of contents

1. Common commands of Linux

Log in and log out using the client

We use the xshell client to create and log in users

quit:

hot key

IS

PWD

cd

touch

echo

cat

mkdir

tree

rm

mv

cp

find

man

less

vim

date

ps

grep

netstat

2. Linux permission problem

user operation

three roles

File Types and Access Rights

Modify file permissions

3. Build an environment for running java programs

Basic introduction to yum:

git view git installation package command:

Install Maven

Install Tomcat

Notes: Since Tomcat 7 is the default on the yum source, and the following describes the way to install Tomcat 8, so yum will not be used for installation


1. Common commands of Linux

Log in and log out using the client

We use the xshell client to create and log in users

 A prompt message pops up: means the login is successful

quit:

 

Just use the exit command to exit directly 

hot key

When we use the Linux client to input commands, the shortcut keys we often use are as follows:

  • Use key completion tab 
  • use  Ctrl + c retype
  • use  Ctrl + insert copy
  • use paste Shift + insert 

IS

Syntax : ls [option] [directory or file]
Function: For a directory, this command lists all subdirectories and files under the directory. For files, the filename is listed along with other information.

Common options:

  • -a List all files in the directory, including hidden files starting with .
  • -d Display directories as files instead of the files under them. Such as: ls -d specifies the directory
  • -k Indicates the size of the file in k bytes. ls –alk specifies the file
  • -l Lists detailed information on files. Since this command is relatively common and has a quick input method, we can directly input ll (two L)
  • -r Sort directories in reverse.
  • -t Sort by time.
  • -R List files in all subdirectories. (recursive) 

In Linux, white is an ordinary file, blue is a directory, green is an executable file, and red is a compressed file

PWD

Syntax: pwd
Function: Display the directory where the user is currently located
Example: Display the directory where the current user is located

cd

In the Linux system, the files and directories on the disk are formed into a directory tree, and each node is a directory or a file.
Syntax: cd directory name
Function: Change the working directory. Change the current working directory to the specified directory. 

Several commonly used commands about cd:
cd .. : return to the parent directory
cd ~: enter the user's home directory
cd -: return to the most recently accessed directory

/: represents the root directory

~: represents the current working directory

Example: Enter the folder of java01

Several special directories:
/ is called the root directory
. It is called the current directory
.. It is called the parent directory of the current directory 

touch

grammar: touch 文件名

Function: Create a new file, the file name can be an absolute path or a relative path

Example: create a file (text.txt)

echo

grammar: echo > 文件名

Function: Write simple data to the file

Example: Write the hello string in the text.txt file (and use cat to view the contents of the file)

cat

Syntax: cat [option] [file]
Function: View the content of the target file
Common options: -n Number all lines of output

Example:

mkdir

Syntax: mkdir [option] dirname ...
Function: Create a directory named "dirname" under the current directory
Common options:
-p, --parents can be a path name. At this time, if some directories in the path do not exist yet, after adding this option, the system
will automatically create those directories that do not exist, that is, a multi-level directory can be created at one time.
For example: create a multi-level directory under the java001 directory

tree

grammar: tree 目录名

Function: Through the tree structure, display all the directories and files under the directory more intuitively

Note: The tree command is not included in Linux, you need to  install the tree command through the command to use it yum install tree -y

Example: View all directories and files under the java01 directory

rm

Syntax: rm [-firv] [dirName/dir]
Function: Delete files or directories
Common options:

  • -f delete without prompting
  • -i Ask for confirmation one by one before deleting (default)
  • -r recursively delete subdirectories or subfiles under the directory
  • -rf delete the specified directory without prompting (use with caution)

Example: Delete the java001 subdirectory and blog.sql file in the java01 directory

mv

Syntax: mv [option] source file or directory target file or directory
Function:  1. Depending on the type of the second parameter
in the mv command (whether it is a target file or a target directory), the mv command will rename the file or move it to a in the new directory. 2. When the second parameter type is a file, the mv command completes the file renaming. At this time, there can only be one source file (it can also be the source directory name), and it will rename the given source file or directory to the given The specified target file name. 3. When the second parameter is the name of an existing directory, there can be more than one source file or directory parameter, and the mv command will move the source files specified by each parameter to the target directory. Common options


  • -f : force means that if the target file already exists, it will be overwritten without asking
  • -i : If the target file (destination) already exists, it will ask whether to overwrite! (default)

Example: Move the java002 subdirectory under the java01 directory to the root directory

cp

Syntax: cp [option] source file or directory target file or directory
Function: copy file or directory
Explanation: cp command is used to copy files or directories, such as specifying more than two files or directories at the same time, and the final destination is an already exists, it will copy all the files or directories previously specified into this directory. If multiple files or directories are specified at the same time, and the final destination is not an existing directory, an error message will appear

Common options:

  • -f or --force Forcibly copy files or directories, regardless of whether the destination file or directory already exists
  • -i or --interactive ask user before overwriting files (default)
  • -r Recursive processing, processing the files and subdirectories under the specified directory together. If the form of the source file or directory does not belong to a directory
  • or symbolic links, they are all treated as ordinary files
  • -R or --recursive recursive processing, the files and subdirectories in the specified directory will be processed together

Example: Move text.txt and blog.sql in the java01 directory to the java003 subdirectory

find

grammar: find 目录 -name 文件名或目录名

Function: Find files or directories with key names in this directory

Example: Search for files or directories with the bin keyword in the root directory

man

Linux commands have many parameters, we can't remember all of them, we can get help by checking the online manual.
Syntax: man [options] command
common options

  • -k search manpage by keyword
  • num is only found in chapter num
  • man man can see several chapters and their meanings in the man manual. 

Example: Use the man command to view the relevant interpretation of the ls command

 

less

Syntax: less [parameters] file
Function: View file content. It will not load all file content into memory at once. It can also be searched.
Options:
jk / arrow keys: scroll up and down the screen.
-N display the line of each line number
/string: function to search down "string"
n: repeat previous search (related to / or ?)
q: quit

Example: View the content in blog.sql

vim

Syntax: vim filename

Function: vim is a text editor that can create or edit files

Three modes: After opening a file with vim, there will be three modes

  • Normal mode: The mode displayed upon entering is normal mode, which cannot be edited. Each key on the keyboard represents some special shortcut keys in this mode, such as entering the i key to enter the insert mode, and entering the : key to represent Enter bottom row mode
  • Insert mode: This mode is used to edit the content of the file. After editing, use the esc key to return to the normal mode
  • Bottom line mode: This mode is used to save and exit vim, w means save, q means exit, wq means save and exit, q! means force exit

Example: Use vim to edit the blog.sql file in the 111 directory under the home directory, and enter the aaa string

date

  • grammar: date [OPTION] [FORMAt]
  • Function: Display the time to be displayed according to a specific format
  • In terms of display time, you can set the format of the pre-display, the format is set to: date + "several marks"

  • %H : hours (00..23)
  • %M : minutes (00..59)
  • %S : seconds (00..61)
  • %X : Equivalent to %H:%M:%S
  • %d : day (01..31)
  • %m : month (01..12) 
  • %Y : full year (0000..9999)
  • %F : Equivalent to %Y-%m-%d
  • Convert the current time to a timestamp:date +%s

  • Convert timestamp to time:date -d@时间戳

示例:按照规定的格式打印时间并将时间转化为时间戳,将特定的时间戳转化为时间

ps

grammar: ps aux

Function: View the processes running on the current system

Example: Display processes currently running on the system

grep

grammar: grep [查找的内容]

Function: Used to filter output results (often used in conjunction with | pipeline, | is used to use the output of the previous command as the input of the next command)

Example: We are querying the running status of a specific thread

netstat

grammar: netstat -anp

Function: View the network status on the system

Example: Use netstat to view network status on a system

2. Linux permission problem

user operation


There are two types of users under Linux: super user (root) and ordinary user.
Super users: can do anything under the linux system without restrictions.
Ordinary users: do limited things under linux.
The command prompt of a super user is "#", and the command prompt of a normal user is "$".

Our server is bought, and the default is the root user. However, the root user has relatively great power, and if it is used improperly, it may cause serious consequences
(such as rm -rf /). Therefore, we will not directly use the root user to operate the server in the company. 
1. Create user
command useradd [username]
function: create a new user

Example: Create a user named ct

2. Configure password

  • grammar: passwd 用户名
  • Function: Set or modify user password
  • Example: Set a password for the ct user

 

3. Switch user

  • grammar: su 用户名
  • Function: switch user
  • Example: Switch from root user to normal user ct

 

three roles

People who access a file may fall into three categories .
Owner of files and file directories: u---User
Users in the group of the owner of files and file directories: g---Group
Other users: o---Others

File Types and Access Rights

We use the ll command to display detailed information for all files:

The details displayed in the following root directory introduce the meaning of the specific parameters

 

Modify file permissions

Syntax: chmod [options] permissions filename

Function: Set the access permission of the file, only the owner of the file or the root user can modify the file permission

Note: When modifying directory permissions, add option R to recursively modify directory file permissions

Method 1: +, -, = change permissions

u: indicates the owner, g: indicates the group, o: indicates other groups, a: indicates everyone (the sum of u, g, o)

chmod u=rwx, g=rx, o=x file name/directory name
The instruction to grant write permission to other groups: chmod o+w file name/directory
name instruction to remove the execution permission of everyone: chmod ax file/directory name

Method 2: Change permissions through numbers

r=4, w=2, x=1, rwx=4+2+1 (can be combined, such as 3=wx)

Command: chmod 751 file name/directory is equivalent to chmod u=rwx,g=rx,o=x file name/directory name

3. Build an environment for running java programs


Basic introduction to yum :

Yum (Yellow dog Updater Modified) is a commonly used package manager under Linux (like a mobile app store or a dependent central warehouse), mainly used in distributions such as Centos, RedHat and Fedora.

Common commands of yum: All commands of yum must ensure that the server's network is connected

View package list command: yum list | grep package keywords

Install the package command (requires root authority): yum install package name

Uninstall package command (requires root privilege): yum remove package name
 

git
view git installation package command:

yum list | grep git -w

-w parameter means full character match

Install git command:

yum install git.x86_64

Basic use of git:

# clone
git clone

# New
git add

# Submit
git commit

# push
git push

Install JDK
View JDK installation package command:

yum list | grep jdk

install JDK command:

yum install java-1.8.0-openjdk-devel.x86_64
You can easily install OpenJDK through yum. This is an open source JDK, which is slightly different from the official JDK, but the difference is very small.

Select the JDK version whose suffix is ​​devel (indicates software development kit) and matches your own system. After installation, you can verify whether the installation is successful through javac. If the installation is successful, the result is as follows:

Install Maven

View the Maven installation package command:

yum list | grep maven -w

install Maven command:

yum install maven.noarch

verify Maven command:

Mvn -v

If the installation is successful, the following results can be obtained through verification

Install Tomcat

Notes: Since Tomcat 7 is the default on the yum source, and the following describes the way to install Tomcat 8, so yum will not be used for installation

installation steps:

Download the Tomcat compressed package (Tomcat official website download address is: Apache Tomcat® - Apache Tomcat 8 Software Downloads )

wget https://dlcdn.apache.org/tomcat/tomcat-8/v8.5.77/bin/apache-tomcat-8.5.77.zip



You can download the compressed package through the specific download link address of wget Tomcat (pro-test, the download speed is a bit slow, it is recommended to download the compressed package directly to the local, and then directly drag it to the server

Drag and drop needs to install the following commands

yum install lrzsz

unzip Tomcat

unzip apache-tomcat-8.5.77.zip
If the unzip command is not found, you need to use

yum install unzip to install

修改可执行权限

# 进入 Tomcat 的 bin 目录
cd apache-tomcat-8.5.77/bin

# 将所有 .sh 后缀的文件加上可执行权限
chmod a+x *.sh

*.sh 表示该目录下所有后缀为 .sh 的文件

启动 Tomcat(下面命令是在 Tomcat 的 bin 目录中进行的)

sh startup.sh



Verify Tomcat

# Method 1: Check whether the Tomcat process exists
ps aux | grep tomcat

# Method 2: Check whether port 8080 is bound
nestat -anp | grep 8080

# Method 3: Use the curl command to access the default demo
curl 127.0.0.1:8080

Note: When you are using a cloud server, you may not be able to successfully open Tomcat in the browser after completing the above operations for the first time, because the cloud server The security group or firewall does not open port 8080. So you need to enter the console of your cloud server to open port 8080.

Installing MySQL
MySQL can also be installed using yum, but the configuration to be modified will be more complicated. For this reason, the installation of MariaDB is introduced here. This is a database similar to MySQL. After MySQL was acquired, the author of MySQL passed the same A database created from source code is compatible with both.

Note: If you want to install the MariaDB database, you must ensure that MySQL is not installed in your cloud server, otherwise the following installation steps may be wrong, this is a personal test!

installation steps:

Install mariaDB service

yum install -y mariadb-server

install mariaDB command line client

yum install -y mariadb

install mariaDB C library

yum install -y mariadb-libs

install mariaDB development package

yum install -y mariadb-devel

to change the configuration:

Change the /etc/my.cnf.d/client.cnf file and add the following configuration under [client]

default-character-set=utf8

Change the /etc/my.cnf.d/mysql-clients.cnf file, add the following configuration under [mysql]

default-character-set=utf8

Change the /etc/my.cnf.d/server.cnf file, add the following configuration under [mysqld]

collation-server = utf8_general_ci

init-connect='SET NAMES utf8'

character-set-server = utf8

sql-mode = TRADITIONAL

start the database:

start service

systemctl start mariadb

setting service starts automatically

systemctl enable mariadb

view service status

systemctl status mariadb

test connection:

Attempt to connect using the command line client

The results of mysql -uroot
are as follows, indicating that the installed database can run normally

The current mariadb user has no password, and the default password is an empty character. If you need to change the database password, you can do the following

mysql_secure_installation


 

After the change is completed, the next time the database is started, the mysql -uroot -p command can be used to connect to the database with a password

Guess you like

Origin blog.csdn.net/m0_65431718/article/details/130211608