REDIR + supervisor port mapping and monitoring

Keywords: Linux supervisor yum git github

I. redir

Redir can map the port of a machine to a port of the machine, supporting TCP connection.
Git address: https://github.com/troglobit/...
Download: git clone https://github.com/troglobit/...

Installation:

# cd /redir
yum -y install automake
yum -y install autoconf
# ./autogen.sh
# ./configure        //The default directory is / usr/local. If you need to modify the directory, use ා / configure --prefix=/usr 
# make -j5
# sudo make install-strip
//View help information ා redir --help
//View version

Function:

redir -I mysql3307 :4001 192.168.100.100:3307  //Map port 3307 of 192.168.100.100 to port 4001 of this computer

Login authentication:

# mysql -uroot -p -P4001 -h127.0.0.1

Function:

/usr/local/bin/redir -n -I mysql3306  :4000 192.168.100.100:3306

II. Installation and use of Supervisor

  Supervisor(http://supervisord.org/ )It is a client/server service developed in Python, a process management tool under Linux/Unix system, and does not support Windows system. It can easily monitor, start, stop and restart one or more processes. When a process managed by supervisor is accidentally killed, supervisor will automatically pull it up again after monitoring that the process is dead. It is very convenient to achieve the function of automatic process recovery, and no longer need to write a shell script to control it. Supervisor requires that the program to be managed is a non daemon program. Supervisor will help you convert it into a daemon program. Therefore, if you use supervisor to manage processes, the processes need to be started in a non daemon way.
Website: http://supervisord.org/instal...

2.1 installation

# yum install python-setuptools
# easy_install supervisor
//Or: pip install supervisor

2.2 configure supervisor

A. create folders and profiles

# mkdir supervisor
# echo_supervisord_conf > /etc/supervisor/supervisord.conf        
//When the supervisor service is started, the default configuration is / etc / supervisor.conf. Do not bother to use - c in the directory 

B. content of modification supervisor.conf
At the [include] node at the end of the file
Change; files = relative/directory/.ini to files = conf.d/.conf
Save and exit
C. execute the supervisorctl reload command to make the configuration file effective.
D. create the conf.d folder under / etc/supervisor /, and projectname.conf (named after the project name)
E. open the ProjectName.conf file and add the following contents:

[program: ProjectName]
command=dotnet ProjectName.dll ; Command to run the program
directory=/root/Publishing/PublishOutput/ ; Directory of command execution
autorestart=true ; Whether the program automatically restarts when it exits unexpectedly
autostart=true ; Auto start or not
stderr_logfile=/var/log/ProjectName.err.log ; Error log file
stdout_logfile=/var/log/ProjectName.out.log ; Output log file
environment=ASPNETCORE_ENVIRONMENT=Production ; Process environment variable
user=root ; User identity of process execution
stopsignal=INT
startsecs=1 ; Automatic restart interval

Save and exit
Example:

[root@vm-test03 conf.d]# cat supervisor_mysql3306.conf 
[program:mysql3306]
command=/usr/local/bin/redir -n -I mysql3306  :4000 192.168.100.100:3306
autostart = true
autorestart = true
startsecs = 1
user = root
stdout_logfile = /data/supervisor/logs/mysql3306_info.log
stderr_logfile = /data/supervisor/logs/mysql3306_err.log

supervisorctl
supervisorctl stop programxxx, Stop a process(programxxx),programxxx by [program:beepkg] This example is beepkg. 
supervisorctl start programxxx,  Start a process.
supervisorctl restart programxxx,Restart a process.
supervisorctl status,  View process status.
supervisorctl stop groupworker ,Restart all properties named groupworker The process of this group(start,restart Empathy). 
supervisorctl stop all,  Stop all processes, note: start,restart,stop Will not load the latest profile.
supervisorctl reload,   Load the latest configuration file, stop the original process, start and manage all processes according to the new configuration.
supervisorctl update,  According to the latest configuration file, start the process with new configuration or changes. The process without changes will not be affected and restarted

2.3 configure systemd to start:

[root@vm-test03 conf.d]# cat /usr/lib/systemd/system/supervisord.service 
[Unit]
Description=Supervisor daemon

[Service]
Type=forking
ExecStart=/usr/bin/supervisord -c /etc/supervisor/supervisord.conf
ExecStop=/usr/bin/supervisorctl shutdown
ExecReload=/usr/bin/supervisorctl reload

KillMode=process
Restart=on-failure
RestartSec=42s

[Install]
WantedBy=multi-user.target

Posted by gca07738 on Sun, 10 Nov 2019 13:36:27 -0800