Basic guide to server operation and maintenance
As a developer, the operation of the server is inevitable. The most common operation is to deploy the application to the server, and check the logs for troubleshooting in the production and test environment.
General servers are Linux operating systems and have no graphical interface, so any operation is done through the command line. Since the new generation of programmers start to contact the computer from the graphical interface, they are not very used to using the command line when they start to use it. If they are used to using the command line, they can do many interesting and efficient things to play the command line Productivity, allowing programmers to focus more on high-tech jobs.
Link server portal
The Mac can log in to the server directly by using its own terminal. Windows needs to download tools such as xshell
Login server SSH
There are two ways to log in to the server:
- Log in with password
- Password free login
SSH – L user IP / domain name
SSH: Secure Shell security Shell Protocol, a protocol designed to provide security for remote login sessions and other network services. Using SSH protocol can effectively prevent information leakage in the process of remote management.
Log in with password
Enter: SSH – L user IP / domain name
User: login user name
IP / Domain Name: the ID address of the public network to which the server belongs, or the domain name of the application. If you want to view the IP after domain name resolution, enter Ping domain name in the command line to view the public network IP to which the application belongs (provided that the server does not do load balancing, proxy…).
The terminal will prompt you to enter the password. At this time, enter the password. If the password is correct, you can log in to the server.
Password free login
For the first time, the password free login mode needs to be entered. The difference is that after login, you can add your own key to the server, and then you can log in without password next time.
Generate SSH key
Log in to the server and enter the. SSH in the ~ directory. Open the authorized_keys file. If not, create it. Add your own public key to the authorized_keys. After that, when you use SSH to enter the server again, you can log in directly without entering the password.
Tips: Mac can create a new. Sh file to add SSH – L user IP / domain name to the. Sh file, which is opened by the default terminal on the desktop. After that, you can double-click the. Sh file to enter the server directly (or even write other commands in. Sh to realize automation).
View the current directory location PWD
Display all files in the current directory LS
Ls: list all files in the current directory
LS – L: list the details of all files and files in the current directory
Enter exit directory CD
CD..: return to parent directory
CD /.: return to root
CD directory name: enter specific directory
New directory MKDIR
Start the run script/
View file content cat / tail
Cat xxx.xx: view all contents of the file
Tail – N number of lines xxx.xxx: view the number of lines XX at the end of the file
VI / VIM xxx.xxx: view and modify file content
Move files to specific directory MV
MV XX SSS: move XX files to SSS directory
It is recommended to move the file to the / tmp directory first when deleting the file (the temporary directory of Linux will be cleared after shutdown, so it is recommended to delete it in this directory).
Delete file RM
RM – f XXX: force file deletion
RM – R f XXX: – R indicates downward recursive deletion – f deletion does not prompt attention: RM – RF (does not follow the parameter) will delete the whole system, even if there is a parameter Linux does not have the concept of recycle bin, use it with caution
rm -f . : the plum blossom method should be used with caution, which may delete the entire server by mistake
Modify the file’s user right chown / Chmod
Chown – R user: user file: wildcards are supported for modifying the user rights file of a file
Chmod 777 XXXX: changing the file permission 777 means that the high permission (read, write, execute) login user’s group and others have the highest permission. (more dangerous operation)
View the related processes of Java programs JPS
JPS: View Java program process
Copy files to specific directory CP / SCP
CP – R copied copy: copy copied to the copy directory
SCP XXX root: IP: / Directory: copy XXX to the remote IP server directory
Start the service, shut down the terminal and continue to run nohup
Sometimes we need to run some jar packaged applications on the server. After the terminal is closed, the application will be closed. We can add nohup before the command to start jar application
Unzip / zip the file
Unzip – O xxx.xx – D SSS: unzip the file xxx.xx to SSS and overwrite it all
Zip – R XXX. Zip. / *: compress all files in the current directory
If there is no unzip zip command to execute, you can install unzip / zip
yum install -y unzip zip
At present, these commands can basically meet the requirements of daily development of charm server, but these are just some simple commands to operate the server. If there are more requirements to learn Linux systematically, it is also a big topic of operation and maintenance.
Pay attention to my public number and read interesting technical stories for the first time.
WeChat can also search the public number to focus on me: codexiulian
Eager to grow and progress with you!