1. ホーム
  2. Linux

PM2管理用バックエンド・プログラムのLinuxへのインストールと使用方法

2022-02-21 18:10:12
<パス

序文

CentOS 8.3
node.jsをインストールした状態

ダウンロードとインストール

npm install pm2@latest -g
# or npm install -g pm2
# or
yarn global add pm2

pm2 update


<イグ

PM2のアップデート

cd /server/bc/pgz-bc/
vi private-geth.json

[
  {
    "name" : "geth",
    "cwd" : "/usr/geth/",
    "script" : "geth",
    "args" : "--datadir /server/bc/pgz-bc --networkid 9527 --http --http.port 8100 --http.api personal,eth,net,web3 --port 8000 -- nodiscover --allow-insecure-unlock",
    "log_date_format" : "YYYY-MM-DD HH:mm Z",
    "out_file" : "/server/bc/pgz-bc/log/geth_out.log",
    "error_file" : "/server/bc/pgz-bc/log/geth_err.log",
    "log_file" : "/server/bc/pgz-bc/log/geth_log.log",
    "merge_logs" : false,
    "watch" : false,
    "max_restarts" : 10,
    "exec_interpreter" : "none",
    "exec_mode" : "fork_mode"
  }
]


Webを使ったPM2のモニタリング

https://app.pm2.io/

geth.jsonの設定

pm2 start /server/bc/pgz-bc/private-geth.json


[PM2][WARN] Current process list is not synchronized with saved list. type 'pm2 save' to synchronize.




# startup
pm2 startup
# Start a process
pm2 start geth.js
# List all processes that have been started pm2 list
pm2 ls
# Monitor status in real time
pm2 monit
# View information about the specified application, id=0
pm2 info 0
# Stop geth
pm2 stop geth
# rerun geth
pm2 restart geth
# Delete geth
pm2 delete geth

pm2 stop 0 // stop the process
pm2 delete 0 // abort and delete the process
$ pm2 start app.js # Start the app.js application
$ pm2 start app.js -i 4 # cluster mode mode to start 4 instances of app.js application # 4 applications will be load balanced automatically
$ pm2 start app.js --name="api" # Start the application and name it "api"
$ pm2 start app.js --watch # Automatically restart the application when the file changes
$ pm2 start script.sh # Start the bash script
$ pm2 list # List all applications started by PM2
$ pm2 monit # Show CPU and memory usage for each application
$ pm2 show [app-name] # Show all information about the application
$ pm2 logs # Show logs for all applications
$ pm2 logs [app-name] # Show logs for the specified application
$ pm2 flush
$ pm2 stop all # Stop all applications
$ pm2 stop 0 # Stop the specified application with id 0
$ pm2 restart all # Restart all applications
$ pm2 reload all # Restart all applications in cluster mode
$ pm2 gracefulReload all # Graceful reload all apps in cluster mode
$ pm2 delete all # Shut down and delete all apps
$ pm2 delete 0 # Delete the specified app id 0
$ pm2 scale api 10 # Scale the app with the name api to 10 instances
$ pm2 reset [app-name] # Reset the number of restarts
$ pm2 startup # Create boot-up command
$ pm2 save # Save the current list of apps
$ pm2 resurrect # Reload the list of saved apps
$ pm2 update # Save processes, kill PM2 and restore processes
$ pm2 generate # Generate a sample json configuration file
$ pm2 deploy app.json prod setup # Setup "prod" remote server
$ pm2 deploy app.json prod # Update "prod" remote server
$ pm2 deploy app.json prod revert 2 # Revert "prod" remote server by 2
$ pm2 module:generate [name] # Generate sample module with name [name]
$ pm2 install pm2-logrotate # Install module (here a log rotation system)
$ pm2 uninstall pm2-logrotate # Uninstall module
$ pm2 publish 


cwd 現在の作業ディレクトリ、スクリプトディレクトリ
script: 実際の実行スクリプト
name: アプリケーションの名前
起動

pm2 start /server/bc/pgz-bc/private-geth.json



[PM2][WARN] Current process list is not synchronized with saved list. type 'pm2 save' to synchronize.






リモートブラウザのアクセスログ

共通コマンド

# startup
pm2 startup
# Start a process
pm2 start geth.js
# List all processes that have been started pm2 list
pm2 ls
# Monitor status in real time
pm2 monit
# View information about the specified application, id=0
pm2 info 0
# Stop geth
pm2 stop geth
# rerun geth
pm2 restart geth
# Delete geth
pm2 delete geth

pm2 stop 0 // stop the process
pm2 delete 0 // abort and delete the process
$ pm2 start app.js # Start the app.js application
$ pm2 start app.js -i 4 # cluster mode mode to start 4 instances of app.js application # 4 applications will be load balanced automatically
$ pm2 start app.js --name="api" # Start the application and name it "api"
$ pm2 start app.js --watch # Automatically restart the application when the file changes
$ pm2 start script.sh # Start the bash script
$ pm2 list # List all applications started by PM2
$ pm2 monit # Show CPU and memory usage for each application
$ pm2 show [app-name] # Show all information about the application
$ pm2 logs # Show logs for all applications
$ pm2 logs [app-name] # Show logs for the specified application
$ pm2 flush
$ pm2 stop all # Stop all applications
$ pm2 stop 0 # Stop the specified application with id 0
$ pm2 restart all # Restart all applications
$ pm2 reload all # Restart all applications in cluster mode
$ pm2 gracefulReload all # Graceful reload all apps in cluster mode
$ pm2 delete all # Shut down and delete all apps
$ pm2 delete 0 # Delete the specified app id 0
$ pm2 scale api 10 # Scale the app with the name api to 10 instances
$ pm2 reset [app-name] # Reset the number of restarts
$ pm2 startup # Create boot-up command
$ pm2 save # Save the current list of apps
$ pm2 resurrect # Reload the list of saved apps
$ pm2 update # Save processes, kill PM2 and restore processes
$ pm2 generate # Generate a sample json configuration file
$ pm2 deploy app.json prod setup # Setup "prod" remote server
$ pm2 deploy app.json prod # Update "prod" remote server
$ pm2 deploy app.json prod revert 2 # Revert "prod" remote server by 2
$ pm2 module:generate [name] # Generate sample module with name [name]
$ pm2 install pm2-logrotate # Install module (here a log rotation system)
$ pm2 uninstall pm2-logrotate # Uninstall module
$ pm2 publish 


エクストラ

PM2公式サイトアドレス(ショートカットコマンド):https://pm2.keymetrics.io/docs/usage/quick-start/
JSONファイルパラメータの意味使用: https://pm2.keymetrics.io/docs/usage/application-declaration/
geth build イーサリアムブロックチェーン プライベートチェーン:pusdn.com
node.jsのインストール: https://janeyork.blog.csdn.net/article/details/118362938