Home > Article > Operation and Maintenance > How to troubleshoot problems by viewing logs during server operation and maintenance
The content of this article is about how to troubleshoot problems by checking logs during server operation and maintenance. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
As a developer, it is inevitable to operate the server. The most common operation is to deploy applications to servers and troubleshoot problems by viewing logs in production and test environments.
Generally, servers have Linux operating systems and no graphical interface, so any operation is done through the command line. Since the new generation of programmers start with the graphical interface, they start using the command line. If you are used to using the command line, you can do many interesting and efficient things using the command line, improve productivity, and allow programmers to focus more on high-tech work.
Mac can log in to the server directly using its own terminal. Windows requires downloading tools, for example:
Log in with password
user: login user name
ip/domain name: Server belongs The public network ID address, or the domain name of the application. If you want to view the IP after domain name resolution, enter ping domain name on the command line to view the public network IP to which the application belongs (provided that the server does not perform load balancing, proxy...). The terminal will prompt you to enter the password. Enter the password at this time. If the password is correct, you can log in to the server.
Password-free login method still requires you to enter a password to log in for the first time. The difference is that after logging in, you add your own key to the server, and you can use it without a password next time. Log in.
Generate ssh key
Log in to the server, enter .ssh in the ~ directory, open the authorized_keys file, create it if it does not exist, and add your public key to authorized_keys. When you use ssh to enter the server again, you can log in directly without entering a password. Tips: Mac can create a new .sh file, add ssh -l user ip/domain name to the .sh file, put it on the desktop and use the terminal to open it by default. In the future, you can double-click the .sh file to directly enter the server (you can even Write other commands in .sh to achieve automation). Exit the server exitexitView the current directory location pwd
pwd
Display all files in the current directory ls
ls -l: List all files and file details in the current directory
cd .. :Return to the upper directory
cd /.: Return to the root directoryCreate a new directory mkdir
mkdir file/filename
./xx.sh
View file content cat/tail
tail -n number of lines xxx.xxx: View the number of xx lines at the end of the file
Move the file to a specific directory mv
It is recommended that when deleting a file, you first move the file to the /tmp directory (the temporary directory of Linux will be cleared when you shut down, so it is recommended to delete it in this directory).
Delete files rm
rm -f xxx: forcefully delete files
rm -f
.: Use the plum blossom method with caution, it may be deleted by mistake. Delete the entire server
chown -R user:user file: Modify the user permissions of the file File supports wildcards
chmod 777 xxxx:Change File permission 777 means high permissions (read, write, execute). The logged-in user's group and others have the highest permissions. (A more dangerous operation)
View the related processes of the java program jpsjps: View the java program process
cp -r copyed copy: Copy copied to the copy directory
scp xxx root:ip:/directory: Copy xxx to the remote ip server directory
Sometimes we need to run some jar packaged applications on the server. The application will be closed after closing the terminal. We can add nohup before the command to start the jar application
unzip -o xxx.xx -d sss: Decompress the file xxx.xx to sss and overwrite all
zip -r xxx.zip ./*: Compress all files in the current directory of the file
yum install -y unzip zip
At present, these commands can basically meet the daily development of Yunxi server, but these are just some simple commands to operate the server. If there is more demand to learn Linux systematically, that is also a big problem. Topic operation and maintenance.
The above is the detailed content of How to troubleshoot problems by viewing logs during server operation and maintenance. For more information, please follow other related articles on the PHP Chinese website!