Error series - solutions to common exception problems and summary of system instructions

Recap

  • As a developer, I encounter many error reports in my daily work. I hope my summary can help my friends~
  • In daily work, I also encounter situations where I need to deploy projects or log in to the Linux system to operate. Many times I need to find some commands, so I decided to summarize some of the commands I often use daily and share them with my friends~~
  • Let’s take each scenario as an example to list some of my commonly used commands.

Scenario 1: The project cannot be accessed after the deployment project pm2 is started, so I used the following command to reproduce the problem

pm2 view process
pm2 ls
pm2 stops a project
pm2 stop 项目名
Start and rename process/application
pm2 start app.js --name 项目名
View log
pm2 logs

Scenario 2: yarn install reports error self signed certificate in certificate chain

error An unexpected error occurred: "https://registry.npmmirror.com/bcryptjs/-/bcryptjs-2.4.3.tgz: self signed certificate in certificate chain".
info If you think this is a bug, please open a bug report with the information provided in "/var/local/xxx/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

problem solved

yarn config set "strict-ssl" false -g

场景3:error node_modules/sharp: Command failed.


error /var/local/xxxxx/node_modules/sharp: Command failed.
Exit code: 1
Command: (node install/libvips && node install/dll-copy && prebuild-install) || (node install/can-compile && node-gyp rebuild && node install/dll-copy)
Arguments:
Directory: /var/local/xxxxxxxx/node_modules/sharp
Output:

problem solved

1. Download python
2. Set npm’s python environment variables
npm config set python=/usr/bin/python2.7
yarn config set python "/usr/bin/python2.7"


npm config set sharp_binary_host "https://npmmirror.com/mirrors/sharp" 
npm config set sharp_libvips_binary_host "https://npmmirror.com/mirrors/sharp-libvips"
3. If the above steps cannot solve the problem, please refer to my articles below.

Scenario 4: In some cases, Root authorization is required when logging into the Linux system to perform some operations.

problem solved

# 进入根路径
[serverName ~]$ cd /
# 查看文件列表
[serverName /]$ ls
bin  boot  conf  data  dev  docker-data  etc  home  lib  lib64  media  mnt  opt  plugins  proc  root  run  sbin  srv  storage  sys  tmp  usr  var
# 想要进入某个路径,发现没有权限
[serverName /]$ cd var/local/xxxxxx/
-bash: cd: var/local/xxxxxx/: Permission denied
# 开启权限
[serverName /]$ sudo su
[sudo] password for XXXXXX_USER_01:
[root@serverName /]# cd var/local/xxxxxx/
[root@serverName xxxxxx]# ls
xxxxxx-uat-2  yarn.lock
# 删除某个文件(yarn.lock)
[root@serverName xxxxxx]# rm -rf yarn.lock
[root@serverName xxxxxx]# ls
xxxxxx-uat-2
# 设置python
[root@serverName xxxxxx]# cd xxxxxx-uat-2/
[root@serverName xxxxxx-uat-2]# yarn config set python "/usr/lib64/python2.7"
yarn config v1.22.18
success Set "python" to "/usr/lib64/python2.7".
Done in 0.04s.
[root@serverName xxxxxx-uat-2]# yarn install

Scenario 5: Copy files from a directory with permissions to a directory without permissions

problem solved

# 开启权限,输入密码
[serverName /]$ sudo su
[sudo] password for XXXXXX_USER_01:
[root@servername var]# cd local
# mkdir 命令是 Linux操作系统中的一个基本工具,用于在文件系统中创建新的目录
[root@servername local]# mkdir uat-path
# mv 命令(move 的缩写),既可以在不同的目录之间移动文件或目录,也可以对文件和目录进行重命名。该命令的基本格式如下:
# 使用规则:mv 【选项】 源文件 目标文件
[root@servername local]# mv /home/path_01/td/project-uat-2 ./
[root@servername local]# ls
uat-path  project-uat-2
[root@servername local]# mv project-uat-2/ uat-path/
[root@servername local]# ls
uat-path
[root@servername local]# cd uat-path/

Scenario 6: Add var directory permissions to user1

problem solved

sudo chown -R USER_01:USER_01 /var

Scenario 7: Set the value of the environment variable NODE_TLS_REJECT_UNAUTHORIZED to 0 and temporarily disable SSL certificate

problem solved

yarn config set NODE_TLS_REJECT_UNAUTHORIZED 0

Example:

[USER_01@servername /app]$ yarn config set NODE_TLS_REJECT_UNAUTHORIZED 0
yarn config v1.22.18
success Set "NODE_TLS_REJECT_UNAUTHORIZED" to "0".
Done in 0.04s.

Scenario 8: Code execution encounters an error npm run deploy Error: connect->getConnection: All configured authentication methods failed

PS C:\my_files\my-project> npm run deploy

> [email protected] deploy
> node deploy.js

Error: connect->getConnection: All configured authentication methods failed
    at fmtError (C:\my_files\my-project\node_modules\ssh2-sftp-client\src\utils.js:55:18)
    at SftpClient.connect (C:\my_files\my-project\node_modules\ssh2-sftp-client\src\index.js:217:13)
    at async main (C:\my_files\my-project\deploy.js:16:5) {
  code: 'ERR_GENERIC_CLIENT',
  custom: true
}
undefined
C:\my_files\my-project\node_modules\ssh2-sftp-client\src\utils.js:55
  let newError = new Error(msg);
                 ^

Error: end: No SFTP connection available
    at fmtError (C:\my_files\my-project\node_modules\ssh2-sftp-client\src\utils.js:55:18)
    at haveConnection (C:\my_files\my-project\node_modules\ssh2-sftp-client\src\utils.js:311:20)
    at C:\my_files\my-project\node_modules\ssh2-sftp-client\src\index.js:1314:11
    at new Promise (<anonymous>)
    at SftpClient.end (C:\my_files\my-project\node_modules\ssh2-sftp-client\src\index.js:1305:12)
    at main (C:\my_files\my-project\deploy.js:25:12) {
  code: 'ERR_NOT_CONNECTED',
  custom: true
}
PS C:\my_files\my-project>

problem analysis

This problem occurs during the ssh2 connection process.

problem solved

    1. Change password
    1. Add slash escaping to configuration items

Scenario 9: Linux configures DNS resolution

Modify this file /etc/resolv.conf to configure DNS

Popular science

/etc/resolv.conf is the configuration file of the DNS client.
There are four main keywords in resolv.conf used to set the IP address of the DNS server and the DNS domain name, which are:

  • nameserver: Defines the IP address of the DNS server
  • domain: define local domain name
  • search: Define the search list of domain names
  • sortlist: Sort the returned domain names.
    Note: The most important thing here is the nameserver keyword. If the nameserver is not specified, the DNS service will not be found. Other keywords are optional.

Configuration example

cat /etc/resolv.conf
domain  xxx.com
search  www.xxx.com  xxx.com
nameserver 111.112.112.11
nameserver 111.112.112.11

Scenario 10: Check the hard disk and memory, check the space occupied by the disk, and check the Linux memory usage

Detailed explanation of df -h command

df -h Check the space occupied by the disk

  • Filesystem: Indicates which partition the file system is located on, so this column displays the device name;
  • Used: Indicates the amount of disk space used;
  • Available: Indicates the remaining disk space;
  • Use%: disk space usage;
  • Mounted on: The mount point of the file system, which is the directory location where the disk is mounted.

[xxxxx ~]$ df -h
Filesystem                        Size  Used Avail Use% Mounted on
aaaaaafs                          3.9G     0  3.9G   0% /dev
aaaas                             3.9G     0  3.9G   0% /dev/aaa
aaaas                             3.9G  114M  3.8G   3% /run
aaaas                             3.9G     0  3.9G   0% /sys/fs/cgroup

Detailed explanation of free -m command
  • Check linux memory usage
  • The -m parameter displays the memory usage in M ​​units.
[xxxxxxxxxxx ~]$ free -m
              total        used        free      shared  buff/cache   available
Mem:           7821        3451         304         208        4065        3862
Swap:          9723         327        9396
  • Mem: Memory usage overview table.

  • total: represents the total amount of physical memory – the total physical memory unit of the machine is: M

  • used: used memory {the total amount allocated to cache (including Buffer and cache), but some of the cache may not be actually used }

  • free: free physical memory – memory that has not been allocated

  • shared: shared memory, which is not used by general systems and will not be discussed here.

  • buffers: the number of buffers allocated by the system but not used

  • cached: The number of caches allocated by the system but not used

Scene 11: To be added

  • That’s all for today~
  • Friends, ( ̄ω ̄( ̄ω ̄〃 ( ̄ω ̄〃)ゝSee you tomorrow~~
  • Everyone, please be happy every day

Everyone is welcome to point out what needs to be corrected in the article ~
there is no end to learning and win-win cooperation

Insert image description here

Welcome the little brothers and sisters who pass by to put forward better opinions~~

Guess you like

Origin blog.csdn.net/tangdou369098655/article/details/133202154