One, the type of user
1. root administrator: all permissions (rwx)
2. file owner (u): who created Who owns
3. Main group (g): user group AAA {A1,A2}
4. Other users (o): does not belong to user group, nor is it the creation of files Who is not an administrator
5. All users (a): u, g, o
r–read–4, w–write–2 , X–execute–1
rwx
0 0 1===>1
0 1 0===>2
1 0 0===>4< br> 1 1 1===>7
【010101
0234
2330
0x323AF
U ,root】
2. Command: chmod 761 file name
-R and all files and subdirectories under the directory are changed< /p>
3. Modify file permissions (read, write, execute) 1,2,4
chmod 777 file name
chmod 0777 file name
2 10 8
189 = ( )b
189 = ()o
0–9, —>开头1–9 ,, 99==》 99
0–7, —” must start with 0, 077
chmod u+wrx, g-wr, o=wrx file name
chmod a=wr file name< /p>
Four, default permissions
1, view the default default permissions
umask -S
2, modify Default permissions
umask 022
1), ordinary file: 002
remove x
2), directory file: 002
7 7 7
775
umask 001
5. File redirection: redirection is for standard files
1. Standard input file (keyboard): 0
2. Standard output file (display): 1
3. Standard error file (display): 2
wc, cat: standard input and output commands
standard Input redirection: 0< / province略不写==》 cat f1 标准输出重定向: 1> / >, 1>> / >>
标准错误重定向: 2>,2>> p>
Standard error and standard output redirection: &>, &>>
Fifth, pipeline command: |
before The output of one command is used as the input of the next command
ls -l | wc
ll | grep f
ps -aux | grep vim< /p>
Six. Process management (program, process)
0-255 system process, 255-2048 reserved process, 2048- – The upper limit of unsigned integers
1. View the process ctrl + d Process is over
ps -aux
ps -ef
– a: All processes. ()
-u: Display users. ()
-x: List all tty processes, tty is the virtual terminal currently in use. ()
-e: All processes, slightly different from a, no specific distinction is made here.
-f: Full display of process information.
Example:
1. First check the process pid
ps -ef | grep process name
2. Display the maximum The process id number
========================================= =====================+++++++++++
ps -haux | awk'{print $2}’ | sort -nr | head -1> file.txt
ps -haux | awk'{print $1}’ | sort -nr | head -1 |xargs kill -9
(1) ps h does not display the “USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND” message
(2) Use awk to output your PID column
(3) Reverse order: n is sorted by number, r is sorted in reverse order
(4) Output the first line
Yours should be implemented in a similar way
You can try
The xargs command is a filter for passing parameters to other commands, and it is also a combination of multiple commands Of a tool.
ps auxh| awk'{print $2}’ | sort -nr | head -1
3. Kill
kill -9 process id
ctrl + c to forcibly end the process
ctrl+d to end the process normally
4. The STAT in the background process ps -aux is T, which means it is a background process< /p>
1) 命令&
2) ctrl + z
ps -aux ===>T
5.查看所有Background process:
jobs
6. Turn background process into foreground process in the terminal with background process
1) fg% task number == “the first column displayed by jobs
p>
2) fg% process number PID ===> the second column of ps -aux
7. View current system load
w: Used to display the list of users who have logged in to the system, and display the instructions that the user is executing.
By executing this command, you can know who are currently logged in to the system and the programs they are executing.
Executing the w command alone will display all users. You can also specify the user name to display only the relevant information of a certain user.
8. Dynamically monitor the system resources occupied by the process, changing every 3 seconds
top
top -p process id
The top command is often used to monitor Linux The system conditions of
such as the use of cpu and memory, programmers basically know this command, but the strange thing is that few people can use it well, such as the meaning of the memory value in the top monitoring view. Misunderstanding.
The first line:
10:01:23 — current system time
126 days, 14:29 — system has been running for 126 days, 14 hours and 29 minutes (during this period, it has not been restarted )
2 users — There are currently 2 users logged into the system.
load average: 1.15, 1.42, 1.44 — The three numbers behind the load average are the load conditions of 1 minute, 5 minutes, and 15 minutes.
The load average data is the value calculated by checking the number of active processes every 5 seconds, and then using a specific algorithm. If this number is divided by the number of logical CPUs, when the result is higher than 5, it indicates that the system is overloaded.
The second line:
Tasks — Tasks (processes), the system now has 183 processes, of which 1 are running and 182 are sleeping (sleep ), there are 0 in the stopped state, and 0 in the zombie state (zombies).
The third line: cpu status
6.7% us — the percentage of CPU occupied by user space.
0.4% sy — The percentage of the CPU occupied by the kernel space.
0.0% ni — the percentage of CPU occupied by the processes that have changed priority
92.9% id — the percentage of idle CPU
0.0% wa — the percentage of IO waiting to occupy the CPU
0.0% hi — hard interrupt ( Hardware IRQ) percentage of CPU occupied
0.0% si — percentage of CPU occupied by Software Interrupts
The CPU usage rate here is different from the concept of windows, if you don’t understand user space and kernel Space needs to be recharged.
Fourth line: memory status
8306544k total — total physical memory (8GB)
7775876k used — total memory in use (7.7GB)< br>530668k free — total amount of free memory (530M)
79236k buffers — amount of cached memory (79M)
The fifth line: swap partition
2031608k total — total amount of swap area (2GB )
2556k used — Total amount of swap area used (2.5M)
2029052k free — Total amount of free swap area (2GB)
4231276k cached — Total amount of buffered swap area (4GB)
What I want to explain here is that you cannot use the memory concept of windows to understand these data. If this server is “dangerous” according to the way of windows: the total memory of 8G is only 530M of usable memory. Linux’s memory management has its particularities, and the complexity needs a book to explain, here is just a brief description of the difference from our traditional concept (windows).
The total amount of memory in use (used) in the fourth line refers to the amount of memory controlled by the system kernel, and the total amount of free memory (free) means that the kernel has not yet been included The number of its scope of control. The memory included in the kernel management is not necessarily in use, but also includes memory that has been used in the past and can now be reused. The kernel does not return these reusable memory to free, so free memory on Linux will Less and less, but don’t worry about it.
If you want to calculate the amount of available memory out of habit, here is an approximate calculation formula: free in the fourth line + buffers in the fourth line + cached in the fifth line, according to this formula, the server is available Memory: 530668+79236+4231276 = 4.7GB.
For memory monitoring, in the top, we need to monitor the used of the fifth line of swap at all times. If this value is constantly changing, it means that the kernel is constantly exchanging data between memory and swap, which is true The memory is not enough.
The sixth line is a blank line
The seventh line and below: status monitoring of each process (task)
PID — process id
USER — process owner
PR — process priority
NI — nice value. Negative value means high priority, positive value means low priority
VIRT — the total amount of virtual memory used by the process, in kb. VIRT=SWAP+RES
RES — The size of physical memory used by the process that has not been swapped out, in kb. RES=CODE+DATA
SHR — Shared memory size, in kb
S — Process status. D=uninterruptible sleep state R=running S=sleeping T=tracking/stopping Z=zombie process
%CPU — the percentage of CPU time occupied from the last update to the present
%MEM — the percentage of physical memory used by the process
TIME+ — The total CPU time used by the process, in 1/100 second
COMMAND — Process name (command name/command line)
9. Monitor the current system status
vmstat
The vmstat command is the most common Linux/Unix monitoring tool. It can display the status value of the server at a given time interval, including the server’s CPU usage, memory usage, virtual memory exchange, IO read and write condition. This command is my favorite command for viewing Linux/Unix. One is supported by Linux/Unix. The other is that compared to top, I can see the CPU, memory, and IO usage of the entire machine, instead of just seeing each process. CPU usage and memory usage (the usage scenarios are different).
Generally, the use of the vmstat tool is accomplished through two digital parameters. The first parameter is the number of sampling intervals in seconds, and the second parameter is the number of samplings.
r represents the run queue (that is, how many processes are actually allocated to the CPU). The server I tested is currently idle and there are no programs running. When this value exceeds the number of CPUs, a CPU bottleneck will appear NS. This is also related to the load of the top. Generally, the load is higher if it exceeds 3, it is higher if it exceeds 5, and it is abnormal if it exceeds 10, and the state of the server is very dangerous. The load of top is similar to a run queue per second. If the run queue is too large, it means that your CPU is very busy, which generally results in high CPU usage.
b means a blocked process, not much to say, the process is blocked, everyone knows.
The used size of swpd virtual memory. If it is greater than 0, it means that your machine has insufficient physical memory. If it is not the cause of the program memory leak, then you should upgrade the memory or migrate the memory-consuming task to Other machines.
free The size of free physical memory, my machine has a total of 8G of memory, and the remaining 3415M.
The buff Linux/Unix system is used to store, what is in the directory, the permissions, etc., my machine occupies more than 300M
The cache cache is directly used to remember us Open files, buffer files, my computer occupies more than 300M (here is the cleverness of Linux/Unix, use part of the free physical memory to cache files and directories, in order to improve program execution Performance, when the program uses memory, buffer/cached will be used quickly.)
Si The size of the virtual memory read from the disk per second. If this value is greater than 0, it means that the physical memory is not enough or If the memory is leaked, it is necessary to find the memory-consuming process and solve it. My machine has plenty of memory and everything is normal.
so The size of the virtual memory written to disk per second, if this value is greater than 0, the same as above.
bi The number of blocks received by the block device per second. The block device here refers to all disks and other block devices on the system. The default block size is 1024byte. There is no IO operation on my machine, so it is always 0, but I have seen on a machine that processes a large amount of data (2-3T) that it can reach 140000/s, and the disk write speed is almost 140M per second
bo The number of blocks sent by the block device per second For example, when we read a file, bo must be greater than 0. Bi and bo are generally close to 0, otherwise the IO is too frequent and needs to be adjusted.
in The number of CPU interrupts per second, including time interrupts
cs The number of context switches per second. For example, when we call system functions, we must perform context switching and thread switching. For process context switching, this value should be as small as possible, and too large. Consider reducing the number of threads or processes. For example, in web servers such as apache and nginx, we generally perform several thousand concurrent performance tests when we perform performance tests. For tens of thousands of concurrent tests, the process of selecting a web server can be adjusted down by the peak value of the process or thread, and the pressure test until the cs reaches a relatively small value, the number of processes and threads is a more appropriate value. The same is true for system calls. Every time a system function is called, our code will enter the kernel space, leading to context switching. This is very resource intensive, and we must try to avoid calling system functions frequently. Too many context switches means that most of your CPU is wasted in context switching, resulting in less time for the CPU to do serious things, and the CPU is not fully utilized, which is undesirable.
us user CPU time. I used to work on a server that frequently performs encryption and decryption. I can see that the us is close to 100 and the r run queue reaches 80 (the machine is under stress testing and its performance is poor).
sy system CPU time, if it is too high, it means that the system call time is long, such as frequent IO operations.
id idle CPU time, generally speaking, id + us + sy = 100, generally I think id is the idle CPU usage rate, us is the user CPU usage rate, and sy is the system CPU usage rate.
wt wait for IO CPU time.
9. Check the memory usage
free
The output of free has four lines, and the fourth line is the information of the exchange area, which is exchange The total amount (total),
used amount and how much free swap area there is (free), this is relatively clear, not to say too much.
The second and third lines of free output are quite confusing. These two lines are used to describe the memory usage.
The first column is total, the second is used, and the third is free.
The output of the first line of is from the operating system (OS). That is to say, from the perspective of OS, there are a total of 24677460KB on the computer (the unit of free is KB by default) physical memory, namely FO[2][1];
Of these physical memory, 23276064KB (ie FO[2][2]) is used;
1401396KB (ie FO[2][3]) is available;
here is the first equation :
FO[2][1] = FO[2][2] + FO[2][3]
FO[2][4] represents the memory shared by several processes , Has now been deprecated, and its value is always 0 (of course, it may not be 0 on some systems, depending on how the free command is implemented).
Seven, network management
IP: address***.***.***.***
192.168.31.001< br> 192.168.31.002
192.168.31.002
Uniquely identify a computer in the network
1.ifconfig display
2.ifconfig enss33 192.168.6.234 set ip
p>
3.ping ip address, check whether the ip address can be used
4.netstat display network status
Netstat command is used to display various network related information , Such as network connection, routing table, interface status, etc. On the whole, the output of netstat can be divided into two parts:
One is Active Internet connections, called active TCP connection, in which “Recv “-Q” and “Send-Q” mean that %0A is the receive queue and the send queue. These numbers should generally be 0. If it is not, it means that the package is accumulating in the queue. This situation can only be seen in very rare cases.
The other is Active UNIX domain sockets, called active Unix domain sockets (same as network sockets, but can only be used for local communication, and the performance can be doubled).
Proto shows the protocol used by the connection, RefCnt shows the process number connected to this socket, Types shows the type of the socket, State shows the current state of the socket, and Path shows the path name used by other processes connected to the socket .
2, Linux view process through port:
netstat -nap | grep port number
Example: View the corresponding port number through nginx process
< p> Command:
ps -ef | grep nginx
Result:
root 9836 1 0 Jul11? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody 9841 9836 0 Jul11? 00:00:09 nginx: worker process
#View the occupied port through nginx process pid (process pid is 9836)
Command:
netstat -nap | grep 9836< br>Result:
tcp 0 0 0.0.0.0:8081 0.0.0.0:* LISTEN 9836/nginx
tcp 0 0 0.0.0.0:81 0.0.0.0:* LISTEN 9836/nginx
tcp 0 0 0.0.0.0:8082 0.0.0.0:* LISTEN 9836/nginx
tcp 0 0 0.0.0.0:8083 0.0.0.0:* LISTEN 9836/nginx
-p Show port process
Example: 1. View the process name corresponding to port 8081
Command:
netstat -nap | grep 8081
Result:
tcp 0 0 0.0.0.0 :8081 0.0.0.0:* LISTEN 9836/nginx
2, view the occupied port through pid
netstat -nap | grep process pid
netstat command is a monitoring TCP/IP network A very useful tool, it can display the routing table, the actual network connection and the status information of each network interface device.
Syntax options
netstat [options]
-a or –all: display all Sockets in the connection;
-A
-c or –continuous: continuously list the network status;
-C or –cache: display the cache information of the router configuration ;
-e or –extend: display other related information of the network;
-F or –fib: display FIB;
-g or –groups: display the list of group members of the multi-broadcast function;
-h or –help: online help;
-i or –interfaces: display network interface information form;
-l or –listening: display the Socket of the server under monitoring;
-M or –masquerade: display the disguised network connection;
-n or –numeric: use the ip address directly without going through the domain name server;
-N or –netlink or –symbolic: display Symbolic connection name of network hardware peripheral equipment;
-o or –timers: display timer;
-p or –programs: display program identification code and program name of the Socket being used;
-r Or –route: Display Routing Table;
-s or –statistice: Display network work information statistics table;
-t or –tcp: Display connection status of TCP transmission protocol;
-u Or –udp: display the connection status of the UDP transmission protocol;
-v or –verbose: display the command execution process;
-V or –version: display the version information;
-w or- -raw: display the connection status of the RAW transmission protocol;
-x or –unix: the effect of this parameter is the same as the specified “-A unix” parameter;
–ip or –inet: the parameter of this parameter The effect is the same as specifying the “-A inet” parameter.
Example
List all port conditions
[[email Protected] ~]# netstat -a # List all ports
[[email Protected] ~]# netstat -at # List all TCP Port
[[email Protected] ~]# netstat -au # List all UDP ports
List all Sockets in listening state
[[emailprotected] ~]# netstat -l # Only show listening Port
[[email Protected] ~]# netstat -lt # Display monitoring TCP port
[[email Protected] ~]# netstat -lu # Display monitoring UDP port
[[email Protected] ~]# netstat -lx # Display listening UNIX ports
Display statistics of each protocol
[[emailprotected] ~]# netstat -s # Display statistics of all ports
[[emailprotected] ~]# netstat -st # Display all TCP statistics
[[email Protected] ~]# netstat -su # Display all UDP statistics
Display PID and process name
[[emailprotected] ~]# netstat -p
Display core routing information
[[emailprotected] ~]# netstat -r
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
default gateway 0.0.0.0 UG 0 0 0 eth0
192.168.130.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
[[emailprotected] ~]# netstat -rn # Display the number format, do not query the host name
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 192.168.1 30.1 0.0.0.0 UG 0 0 0 eth0
192.168.130.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
[[emailprotected] ~]#
View ports and services
[[email protected] ~]# netstat -antp | grep ssh
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 734/sshd
tcp 0 52 192.168.130.20:22 119.129.118.189:58737 ESTABLISHED 1846/ sshd: [email protected]
tcp6 0 0 :::22 :::* LISTEN 734/sshd
[[email protected] ~]# netstat -antp | grep 22
tcp 0 0 0.0.0.0 :22 0.0.0.0:* LISTEN 734/sshd
tcp 0 52 192.168.130.20:22 119.129.118.189:58737 ESTABLISHED 1846/sshd: [email protected]
tcp6 0 0 :::22 :::* LISTEN 734/sshd
[[emailprotected] ~]#
netstat –help
[[emailprotected] ~]# netstat –help
usage: netstat [-vWeenNcCF] [
netstat [-vWnNcaeol] [
netstat {[-vWeenNac] -I[
-r, –route display routing table
-I,- -interfaces=
-i, –interfaces display interface table
-g, –groups display multicast group memberships
-s, –statistics display networking statistics (like SNMP)
-M, –masquerade display masqueraded connections
-v, –verbose be verbose
-W, –wide don’t truncate IP addresses
-n, –numeric don’t resolve names
–numeric-hosts don’t resolve host names
–numeric-ports don’t resolve port names
–numeric-users don’t resolve user names
-N, –symbolic resolve hardware names
-e, – extend display other/more information
-p, –programs display PID/Program name for sockets
-o, –timers display timers
-c, –continuous continuous listing
-l, –listening display listening server sockets
-a, –all display all sockets (default: connected)
-F, –fib display Forwarding Information Base (default)
-C, –cache display routing cache instead of FIB
-Z, –context display SELinux security context for sockets
–ax25 –ipx –netrom
List of possible address families (which support routing):
inet (DARPA Internet) inet6 (IPv6) ax25 (AMPR AX.25)
netrom (AMPR NET/ROM) ipx (Novell IPX) ddp (Appletalk DDP)
x25 (CCITT X.25)
SecureFXPortable: It can provide security file transfer. No matter what kind of server you are connecting to, it can provide secure transmission services
SecureCRTPortable: is a very easy-to-use SSH client that supports multiple tags, which greatly facilitates the management of multiple SSH session.
9. Linked file:
Hard-linked file: (file pointer plus 1)
ln -d source文名链接文件名
指向文件的指针多一个
删除文件,指向文件的指针少一个,文件指针为0时,才真正删除
ls -l< br> –
Soft link file: (shortcut)
ln -s source file name link file name
The pointer to the file will not
delete File, the file does not exist
ls -l
l
1.tomcat: is the root user
1. Language environment :Jdk
1) Check whether the machine has jdk installed
rpm -qa | grep java
2) Delete the existing jdk
yum -y remove java
rpm -e java-1.8. 0-openjdk-headless
rpm -e java-1.7.0-openjdk-headless
3)jdk installation
rpm -ivh jdk-8u171-linux-x64.rpm
4 )Check if the installation is successful
java -version
5) Configure jdk environment variables
vim /etc/profile write
JAVA_HOME=/usr/java/jdk1.8.0_171-amd64
export JAVA_HOME
6)Environmental variables take effect
source /etc/profile
2.tomcat:
1)Unzip the tomcat file
tar -xzvf apache-tomcat-8.5.30.tar.gz < br> 2) Copy the decompressed file to the /usr/local directory
cp -r apache-tomcat-8.5.30 /usr/local
3) Because the file name of apache-tomcat-8.5.30 is too old Long-term use is not convenient, create a link file tomcat
ln -s apache-tomcat-8.5.30 tomcat
4) Start tomcat
tomcat/bin/startup.sh
3. Check whether the tomcat installation is successful
Browse Enter the url of the device:
http:127.0.0.1:8080
2. Server: L–linux P–php A–apache M–mysql
LPAM
U– J – A – O
1. Operating system: linux
2. Language environment: jdk, php,…C++,—
3.tomcat:
4.Database: mysql, or….
3. Test environment:
Client—“Service End
B/S – web
1. Browser: ie, o, c
2. Language environment: java–> jdk php –>php< br>3. Testing tools: svn, Zen Tao, httpwatch, xenum, …
4. Automated testing tools:. . . .
5. Performance automated testing tools:. . . .
C/S ,APP,
1. Operating system
2. Real machine. . . , The simulator. . .
2.apk
3. Testing tools: svn, Zen Tao,…
4. Automated testing tools:. . . .
5. Performance automated testing tools:. . . .
10. Additional
How to install the database under Linux?
Use rpm or yum to install
1. To find whether mysql has been installed before, use the following command:
rpm -qa|grep -i mysql
2. If it has Installation, you need to delete the installed database, use the following command to delete the database
delete command: rpm -e –nodeps package name
3. Download the rpm package of mysql
You can use wget Download the specific address because you cannot use the link, please go to the official website to find it
4. Install the rpm package of MySQL Server
rpm -ivh MySQL-server-5.6.21-1.linux_glibc2.5.x86_64 .rpm
5. Install MySQL client
rpm -ivh MySQL-client-5.6.21-1.linux_glibc2.5.x86_64.rpm
6. Install MySQL development Dependent package
rpm -ivh MySQL-devel-5.6.21-1.linux_glibc2.5.x86_64.rpm
7. Start msyql
After the installation is complete, mysql is not started, run mysql The command will prompt the following error:
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket’/var/lib/mysql/mysql.sock’ (2)
You can use the following Command to start MySQL:
service mysql start
Install the dependent package libaio, which can be quickly installed through yum