1. Environment construction
Reference: https://blog.csdn.net/llwy1428/article/details/105335108
Two, configuration management process
It is not recommended to write all process management configuration parameters in the supervisord.conf file. You can write a configuration file for each process and place it in the directory specified by include and import it into the supervisord.conf file.
Create the /etc/supervisor.d directory to store configuration files for process management. (The directory here can be customized, just correspond to the configuration file)
[root@localhost ~]# mkdir /etc/supervisord.d
Modify the include parameter in /etc/supervisord.conf and add the /etc/supervisor.d directory to include
[include]
files = /etc/supervisord.d/*.ini
Note: *.ini can specify one or more configuration files ending with .ini.
Three, service configuration template
1. Create a Java SpringBoot program HelloSupervisor
2. Type into a jar package (the process is omitted)
3. Create a directory:
[root@localhost ~]# mkdir /opt/HelloSupervisor
[root@localhost ~]# mkdir /opt/HelloSupervisor/logs
4. Install JDK
Refer to https://blog.csdn.net/llwy1428/article/details/85232267
5. Upload the jar package to the directory /opt/HelloSupervisor
6. Edit the configuration template of HelloSupervisor
[root@localhost ~]# vim /etc/supervisord.d/HelloSupervisor.ini
7. Write the following
;[program:HelloSupervisor]是被管理的进程配置参数,tomcat是进程的名称
[program:HelloSupervisor]
environment=JAVA_HOME=/opt/jdk1.8.0_241/bin ; 这里可以创建环境变量
directory=/opt/HelloSupervisor ; 程序的启动目录
command=/opt/jdk1.8.0_241/bin/java -Xms512m -Xmx1024m -Dspring.profiles.active=prd -Dserver.port=8080 -jar /opt/HelloSupervisor/HelloSupervisor.jar ; 启动命令,可以看出与手动在命令行启动的命令是一样的
autostart=true ; 在supervisord启动的时候也自动启动
startsecs=10 ; 启动10秒后没有异常退出,就表示进程正常启动了,默认为1秒
autorestart=true ; 程序退出后自动重启,可选值:[unexpected,true,false],默认为unexpected,表示进程意外杀死后才>重启
startretries=3 ; 启动失败自动重试次数,默认是3
user=root ; 用哪个用户启动进程,默认是root
priority=999 ; 进程启动优先级,默认999,值小的优先启动
redirect_stderr=true ; 把stderr重定向到stdout,默认false
stdout_logfile_maxbytes=20MB ; stdout 日志文件大小,默认50MB
stdout_logfile_backups = 20 ; stdout 日志文件备份数,默认是10
; stdout 日志文件,需要注意当指定目录不存在时无法正常启动,所以需要手动创建目录(supervisord 会自动创建日志文件)
stdout_logfile=/opt/HelloSupervisor/logs/log.log
stopasgroup=false ;默认为false,进程被杀死时,是否向这个进程组发送stop信号,包括子进程
killasgroup=false ;默认为false,向进程组发送kill信号,包括子进程
8. Permission to modify the configuration file
[root@localhost ~]# chmod 755 /etc/supervisord.d/HelloSupervisor.ini
9, restart the service
[root@localhost ~]# systemctl restart supervisord.service
10. Browser view
Enter the browser address bar: http://192.168.11.17:9001/ 192.168.11.17 is the ip of my virtual machine
You can see that the HelloSupervisor service is already running
11. Check the running status
[root@localhost ~]# netstat -lntp
HelloSupervisor occupies port 8080, you can see that the service has started
Four, service startup, restart, configuration reload and service shutdown
1. Start the specified service (take HelloSupervisor as an example)
[root@localhost ~]# supervisorctl start HelloSupervisor
2. Stop the specified service (take HelloSupervisor as an example)
[root@localhost ~]# supervisorctl stop HelloSupervisor
3. Restart the specified service (take HelloSupervisor as an example)
[root@localhost ~]# supervisorctl restart HelloSupervisor
4. Start the supervisor service
[root@localhost ~]# systemctl start supervisord
5. Stop the supervisor service
[root@localhost ~]# systemctl stop supervisord
6. View the running status of the supervisor service
[root@localhost ~]# systemctl status supervisord
7. Supervisor reloads configuration information
[root@localhost ~]# systemctl reload supervisord
8. The supervisor service restarts
[root@localhost ~]# systemctl restart supervisord
So far, Centos7 supervisor configuration management SpringBoot process operation is complete!