MAC remote connection server CentOS
Local MAC, remote Cent0S Linux release 8.2.2004 (Core)
Suddenly you are given an interface document that reports errors, including 404 and 500. Are you confused as to what project the server is running and what environment the server is in? I was confused, so today I will record a detailed remote connection to the server for you, and then use a series of operations to locate the place where the error was reported.
-
Remote connection server
Directly use MAC terminal SSH to remotely connect to the server
Write an SSH configuration file to facilitate direct connection to the remote server in the future without having to repeatedly enter the account and password.
Enter the ssh directory. If there is a config file, go directly to edit it. If not, just create a new and edit the config file.
tong ~/.ssh $ cd ~/.ssh tong ~/.ssh $ ll total 40 drwx------ 7 tong staff 224B Aug 29 17:17 . drwxr-x---+ 98 tong staff 3.1K Aug 30 10:11 .. -rw-r--r-- 1 tong staff 301B Aug 29 15:26 config -rw------- 1 tong staff 2.5K Dec 7 2022 id_rsa -rw-r--r-- 1 tong staff 576B Dec 7 2022 id_rsa.pub -rw------- 1 tong staff 1.7K Aug 29 15:26 known_hosts -rw------- 1 tong staff 1.5K Aug 29 15:23 known_hosts.old tong ~/.ssh $ vim config
Host myserver # myserver 是可以自定义的名字,之后就使用这个别名直接连接指定的服务器 HostName 123.123.123.123 # 实际的远程服务器域名 或 IP 地址 Port 22 # SSH 端口,默认为 22,如果不是 22,需要修改,注意要开启该端口,一般服务器都默认开启 User root # 登录用户名 PassWordAuthentication yes # 允许使用密码身份验证
After editing, enter
:wq
to exit and save, then execute the commandssh_copy_id myserver
, entering the server password once in the middle.tong ~/.ssh $ ssh_copy_id myserver /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys [email protected] 's password: Number of key(s) added: 1 Now try logging into the machine, with: "ssh -o 'PreferredAuthentications=password' -o 'PubkeyAuthentication=no' 'nnserver'" and check to make sure that only the key(s) you wanted were added. tong ~/.ssh $
Next, you can directly use the command to log in to the server remotely without entering a password.
tong ~/.ssh $ ssh myserver Welcome to Huawei Cloud Service Last failed login: Wed Aug 30 00:31:10 CST 2023 from 123.123.123.123 on ssh:notty There were 2 failed login attempts since the last successful login. Last login: Tue Aug 29 17:17:02 2023 from 123.123.123.123 (base) [root@Server-3401572e-0499-44a9 ~]#
-
Check the corresponding port number according to the test interface url
netstat -anp | Grip 65
(base) [root@Server-3401572e- ~]# netstat -anp | grep 65 tcp 0 0 127.0.0.1:6655 0.0.0.0:* LISTEN 889536/python tcp 0 0 0.0.0.0:65 0.0.0.0:* LISTEN 487900/nginx: maste
After extracting useful information, it can be seen that the Nginx proxy is used. Now we have to find the Nginx configuration file to see where the proxy is?
(base) [root@Server-3401572e-0499 ~]# cd / (base) [root@Server-3401572e-0499 /]# find / -name nginx /usr/local/nginx /usr/local/srs/srs.oschina/trunk/objs/nginx /root/anaconda3/pkgs/notebook-6.0.3-py38_0/lib/python3.8/site-packages/notebook/static/components/codemirror/mode/nginx /root/anaconda3/lib/python3.8/site-packages/notebook/static/components/codemirror/mode/nginx /home/nginx /home/nginx/sbin/nginx (base) [root@Server-3401572e-0499 /]# cd /home/nginx/sbin/ (base) [root@Server-3401572e-0499 sbin]# ./nginx -t nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
At this point we have found the location of the nginx configuration file and directly checked
nginx.conf
the configuration file to find the listening65
server.server { listen 65; server_name localhost; location / { proxy_connect_timeout 300s; proxy_send_timeout 300s; proxy_read_timeout 300s; proxy_pass http://127.0.0.1:6655; charset utf-8; } }
It can be seen that the one listening on 65 reaches port 6655.
(base) [root@Server-3401572e-0499-44a9 sbin]# netstat -anp | grep 6655 tcp 0 0 127.0.0.1:6655 0.0.0.0:* LISTEN 889536/python (base) [root@Server-3401572e-0499-44a9-88bb-b2b2061f3c4e sbin]# conda env list # conda environments: # base * /root/anaconda3 detection /root/anaconda3/envs/detection pygdal /root/anaconda3/envs/pygdal (base) [root@Server-3401572e-0499-44a9 sbin]# ps -ef | grep python root 713634 1 0 Apr02 ? 00:19:42 python FDEMO4.py root 889536 1 0 Jun15 ? 02:58:26 python EXGApi.py root 1046006 1045923 0 10:38 pts/4 00:00:00 grep --color=auto python (base) [root@Server-3401572e-0499-44a9 sbin]# cd / (base) [root@Server-3401572e-0499-44a9 /]# find / -name EXGApi.py /root/model/EXGApi.py (base) [root@Server-3401572e-0499-44a9 /]# cd ~/model/ (base) [root@Server-3401572e-0499-44a9 model]# ll total 8636 drwxr-xr-x 233 root root 12288 Aug 14 2022 exg -rw-r--r-- 1 root root 7910788 Aug 29 11:06 EXGApi.out -rw-r--r-- 1 root root 13351 Jun 15 16:55 EXGApi.py -rw-r--r-- 1 root root 237289 Aug 30 03:16 fdemo4.log -rw-r--r-- 1 root root 380102 Apr 2 22:36 fdemo4.out -rw-r--r-- 1 root root 7050 Apr 2 22:36 FDEMO4.py drwxr-xr-x 4539 root root 135168 Aug 28 10:38 jpgresult -rw-r--r-- 1 root root 108259 Aug 7 2022 model.out drwxr-xr-x 2 root root 4096 Apr 5 11:59 receive drwxr-xr-x 164 root root 4096 Apr 5 11:59 result drwxr-xr-x 2 root root 4096 Jul 4 2022 reve
-
Check the log files and code to locate the problem
This step is basically completed. We have found the code and seen the
.out
output file. All that is left is to open the log file with vim, search and locate the error report according to the error document, and then find the corresponding code in the code and modify it. !