Linux Operating system

I. Introduction to Linux

1.1 the introduction

1. Development environment: We usually develop in Windows/MacOS environment. However, installing a large amount of software in a development environment may reduce the stability and security of the environment. 2. Production environment: An environment that runs services accessible to users. By professional personnel to maintain, ordinary people have no right to operate. 3. Test environment: generally, a copy of the production environment will be cloned, and the programs in the development environment will be deployed to the test environment. The main purpose of this environment is to detect the program process, find various problems in the program, and hand over to the developers for modification. Common operating systems in the production environment include Windows Server, Linux, and Unix. Linux operating system occupies a large market share in the production environment. It is mainly stable, reliable and free to become the most used server operating system in the world.Copy the code

The 1.2 Linux is introduced

Before the appearance of Linux operating system, there was another operating system Minix, which was developed by Andrew's university professor. At that time, the university professor bought a Unix operating system to teach students, wrote an operating system referring to Unix and named it Minix. At the same time, Minix was made open source for teaching and research within the school, and by 2000, Andrew had made Minix completely open source. Minix spread quickly on the Internet after being completely open source, but when people used it, they found that Minix was not perfect and had all kinds of internal problems. Therefore, everyone solved the problem and sent the patch to Andrew, but the original purpose of the professor was just for teaching and research. At the same time, Linus, a Finnish college student, appeared, added some patches and plug-ins on the basis of Minix, and named it Linux operating system, which was completely open source to the outside world. He started to maintain Linux system, and developed Git in the process.Copy the code

Linux version 1.3

Linux kernel version https://www.kernel.org/ Linux distribution the distribution we need to learn is CentOSCopy the code

1.4 Differences between Linux and Windows

Linux is case sensitive Linux all Files Linux does not distinguish file types by suffixes. Some common suffixes, such as tar.gz, are used for compressed filesCopy the code

The Linux installation

This step will not be detailed, generally use the server directly installed CentOS system.

Basic operation of Linxu

3.1Linux Directory Structure

The Windows directory structure has a drive letter: C:/ D:/ E:/ Linux does not have input in the Xterm terminal"ls /"Check out the top level directory for LinuxCopy the code

Root: this directory is the home directory of the system administrator. Bin: this directory contains frequently used commands. Boot: Some core files used to start Linux. Default software installation directory, similar to Program Files directory in Windows opt: Directory for installing additional software on the hostCopy the code

3.2 Simple Commands in Linux

# 1.Who am I2.Where am I3.Check the IP address IP a | address #4.The screen clear #5.Ping the domain name # | ping IP address6.Force stop Ctrl + CCopy the code

Linux command

The format of A command in Linux is as follows: Command [option] [Parameter] Some commands do not follow this format. For example, who am I When A command has multiple options, you can write them together and the options can be abbreviated as command - option A Option BCopy the code

4.1 Directory Commands

# 1.List directory ls [-ald] [directory name] # Directory name left blank, default is current directory # -a: list all contents, including hidden files # -l: list all information # -d: view only the directory itself ll # equal to ls -lCopy the code

Linux’s hidden directories start with “. “, the current directory uses “. “, and the upper directory uses “… “. said


# 2.Specific path switch catalog CD | symbolsCopy the code

Path Content that can be filled 👇

symbol Path of expression
. In the current directory
. Upper level directory
/ The root directory
~ The home directory of the current logged-in user
return
# 3.Create directory mkdir [-p] Directory name # -p: creates a multi-level directory, for example, mkdir a/b/cCopy the code

# 4.Delete a directory rmdir Directory name # Delete only an empty directory rm [-rf] Directory name # Delete a non-empty directory # -r: indicates recursive deletion of a directory # -f: deletes the directory without askingCopy the code

# 5.Copy directory cp -r Source directory Destination directory # -r: indicates recursive replicationCopy the code

# 6.Move/rename mv directory name new directory name mv directory name path # If the path of the second parameter does not exist, rename, otherwise, moveCopy the code

4.2 File Commands

# 1.Create an empty file touch file name1The file name2.Copy the code

# 2.Vi filename edit file # into vi view mode I | a | o # from view mode, enter the vi editor pattern # I: at the current cursor, enter edit mode; A: Enter edit mode one space after the current cursor; O: One space behind the current cursor, enter editing mode Esc # Exit to view mode: # Enter the bottom command mode of vi # Enter wq: Save and exit; The input q! : don't save and exit the # in view mode, double-click the capital Z (ZZ | Shift + ZZ), can quickly save and exitCopy the code

# 3.Other operations when editing files # In bottomline command mode, Set nu # View the line number of the file to the line number # Quickly jump to the specified line set nonu # Cancel the line number # Directly enter/specific content in view mode # Similar to Ctrl + F search the location of the specific content of the file to view the next available letter NCopy the code

# 4.Cat file name # show all tac file names from the first line # show nl file names from the last line # show all tac file names from the last line # show more file names You can scroll down page by page (click space) less filename # Can be arbitrarily upward or downward turn key (keyboard | PageUp/PageDown) head file name # # check before just a few lines of tail filename view after just a few lines of tail -f log # monitor logCopy the code

# 5.Move file mv file name New file name MV file name directoryCopy the code

# 6.Copy the file cp file name directoryCopy the code

# 7.Delete a file rm [-f] File name # -f: Whether to queryCopy the code

4.3 Operations performed on compressed packages

Tar /.tar.gz/. TGZ. However, Linux not only supports tar packages, but also supports Windows packages such asCopy the code

4.3.1 tarball

# 1. ExtractTar [-zxvf] Compressed package name [-c path]# -z: indicates that the compressed package suffix is. Gz
# -x: decompress
-v: Prints detailed information when decompressing
# -f: The -f option must be placed at the end of all options to indicate the file name
# - C:
# 2. PackagingTar [-zcvf] Compressed package Name File 1 File 2 Directory 1 Directory 2...# -c: stands for pack
Copy the code

4.3.2 zip zip

Linux does not support the zip package format by default. Two software packages need to be installed: zip & unzip Run the yum -y install zip yum -y install unzip commandCopy the code
Unzip package name # Decompress the zip package name file1file2directory1directory2. # packagedCopy the code

4.4 Operations performed by Users and User Groups

Linux is a multi-user operating system. If a user wants to operate the Linux operating system, he/she must apply for an account from the system administrator. A user account can help the system administrator track the current user's operations and control the current user's access to system resources.Copy the code

4.4.1 User Operations

Useradd [-cgd] useradd [-cgd] useradd [-cgD] useradd [-cgD] useradd [-cgD] useradd [-cgD] useradd [-cgD] useradd [-cgD] useradd [-cgD] useradd [-cgD] useradd [-cgDCopy the code

# 2.Set the password passwd [user name]Copy the code

Only the system administrator can specify a user name. If no user name is added, the current user name is specified

Only the system administrator can specify a user name. If no user name is added, the current user name is specified


# 3.Switch user su user name # [root@localhost ~]# : root Log in locally and currently in ~ directory, # indicates the super administrator # [Ning@localhost root] : Ning logs in locally and is currently in the root directory, where $indicates a normal userCopy the code

# 4.Delete user userdel [-r] User name # -r: Delete the user's home directory at the same timeCopy the code

# 5.Change the user name usermod [parameter specified by the -cgd option]Copy the code

4.4.2 User Group Operations

# 1.View the user name of the user groupCopy the code

# 2.Groupadd Specifies the name of the user groupCopy the code

# 3.Groupmod -n New user group name User group name # -n: Changes the user group nameCopy the code

# 4.Deleting a user group groupdel User group name # Delete only user groups that do not have usersCopy the code

4.5 File Permissions

In Linux type ls -l | ll see detailed information on files and directories

In the example, b directory attribute use d to identify the first b is a directory, tt, etc - to identify them is a normal file The back nine attributes are divided into three groups The first group of RWX: on behalf of the owner of the file permissions The second group RWX: set of user permissions on behalf of the file The third group RWX: on behalf of other users access to the operation of the current file r: representativeread, read permission W: write permission x: execute, execute permission The first root location indicates the owner of the current file the second root location indicates the owning group of the current file the size of the file and the last modification time respectivelyCopy the code

4.5.1 Operations on File Permissions

Use chmod to modify file permissions, either using numbers or symbols

# 1.Digital mode CHmod [-r]765File directory | # - R: when modifying a directory, the directory of all content, are modified to the back of the permissions # RWX weights of the three permissions, respectively4(100),2(010),1(001)
# 1-7The numeric signified meaning is similar to that of its binary number signified meaning # is above7(111) stands for RWX,6(110) stands for Rw -,5(101R minus x, so765On behalf of RWXRW - r - xCopy the code

# 2.# user:u,group:g, other:o, all:a
# read:r, write:w, execute: x # # add authorized way: +, cut: -, setting: = chmod [-r] a = rw file | directoryCopy the code

4.5.2 Modifying the File Owner and Owning Group

Chown [-r] owner: belongs to group of file directory | chown [-r] owner file directory | CHGRP [-r] belongs to group of file | directoryCopy the code

4.6 Other Linux Operation Commands

# 1.Process operation # check all the running process ps - specified process ps - ef ef # search | grep search content # kill kill the process9 pid
Copy the code

# 2.Service operation # for start, stop, restart, boot since the opening and banned boot from kai, check the service status systemctl start | stop | restart | enable | disable | status service nameCopy the code

# 3.View port usage # need to download the first function yum - y install.net - tools # view port usage netstat naop [| grep specified port]Copy the code

# 4.Curl Indicates the access addressCopy the code

# 5.Find files find path -type f | grep file nameCopy the code

Install the software in Linux

5.1 to install the JDK

Download the JDK package https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html using Xterm SFTP file pull to the Linux system Unzip the JDK to /usr/local

tar -zxvf jdk-8u251-linux-x64.tar.gz -C /usr/localChange the JDK directory name"jdk"Mv JDk1.8.0_251 JDK Environment variables Add the following content to the environment variablesexport JAVA_HOME=/usr/local/jdk

export PATH=$JAVA_HOME/bin:$PATHReload the environment variables filesource/etc/profile Tests java-versionCopy the code

Linux provides two types of file system level environment variables, which are stored in: /etc/profile user level environment variables, in: ~/.bashrcCopy the code

To run the executable file in the current directory, enter “./” before the file name.

Install MySQL 5.2

# open the MySQL website
https://www.mysql.com/
# Switch to DOWNLOADS
# Select the bottom community edition download
MySQL Community (GPL) Downloads
# select Yum
MySQL Yum Repository
Click the exclamation mark on the right of Repository Setup Packages
# Click on the Quick Guide to Using the MySQL Yum Repository to view the Quick start documentation
Steps for a Fresh Installation of MySQL
Copy the code

# 1. Install the MySQL YUM repository
# Select Red Hat Enterprise Linux 7 / Oracle Linux 7 (Architecture Independent) from MySQL Yum Repository RPM Package Click on the right Download
# Copy No thanks, just start my download The link address
https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
Enter the server ~ directory
# Yum install wget
yum -y install wget
# Use wget to download MySQL
wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
Copy the code

# 2. Install the downloaded RPM packageRPM -uvh Specifies the RPM package nameCheck the list of RPMS installed
rpm -qa
# check the RPM specifiedThe RPM - qa | grep content# Uninstall the RPM packageRPM -e --nodeps RPM package nameCopy the code

# 3. Select your distribution
View the distribution selected by default
yum repolist all | grep mysql
# yum config-manager yum config-manager
sudo yum-config-manager --disable mysql80-community
sudo yum-config-manager --enable mysql57-community
Repos. D /mysql-community. RepoChange 5.7 Enabled from 0 to 1 change 8.0 enabled from 1 to 0# can be saved, again through the yum repolist all | grep mysql view
Copy the code

# 4. Install MySQL Community Edition
yum -y install mysql-community-server
Copy the code

# 5. Start MySQL service and connect
Start the MySQL service
systemctl start mysqld.service
Initialize password
grep 'temporary password' /var/log/mysqld.log
Connect to the MySQL serverMysql -u root -p Enter password: indicates a random password# change password
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'P@ssw0rd! ';
The password must contain uppercase letters, lowercase letters, digits, and special characters
Copy the code

# 6. Enable remote connection and use graphical interface to operate
mysql> GRANT ALL PRIVILEGES ON *.* TO 'Username'@The '%' IDENTIFIED BY 'P@ssw0rd' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;
Copy the code

Install Tomcat 5.3

# 1. Download the Tomcat package
# open the official website
http://tomcat.apache.org/
# Select Left Download
Select Tomcat 8
# copy the link to tar.gz on the right
https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.5.60/bin/apache-tomcat-8.5.60.tar.gz
# server ~ directory downloadWget HTTP: / / https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.5.60/bin/apache-tomcat-8.5.60.tar.gzCopy the code

# 2. Unzip the package to /usr/localTar -zxvf apache-tomcat-8.5.60.tar.gz -c /usr/local
Copy the code

# 3. Start Tomcat and listen for logs
cd /usr/local/ apache tomcat - 8.5.60 / bin# start
./startup.sh
# Monitor log
cd ../logs
tail -f catalina.out
Copy the code

Deploy the SSM project

Note the following when deploying a project to Linux: Ensure that the project is trouble-free under Windows before deploying to Linux. Change configuration and so on from the development environment to the test environment. Location for storing database information File Location for storing log files Project path Problem Package the Maven project. Deploy to Tomcat based on the project path. Be sure to check the logs after deploying to Linux.Copy the code

The ports on the CentOS7 firewall are open

# 1. View the firewall- CMD --list-ports that are currently openCopy the code

Firewall-cmd --zone=public --add-port=8888/ TCP --permanentCopy the code

Firewall-cmd --reloadCopy the code