安装 supervisor,以及使用配置,直接在服务器上按我写的执行应该就可以

278 阅读1分钟

之前有总结过笔记,这里根据之前的笔记,简述下安装步骤,就是配置在一台 linux 服务器上进行配置的步骤,涉及到的内容详情看笔记:

1.安装
	easy_install supervisor		// 如果没有 easy_install,先安装
2.配置
	echo_supervisord_conf > /etc/supervisord.conf 	// 默认没有配置文件,我们首先生成
3.编辑配置文件
	vim /etc/supervisord.conf	
	[inet_http_server]
	port=*:9001
	[include]
	files = /etc/supervisor.d/*.ini			// 该目录不存在,需新建,放置各个需要监听的进程配置
4.配置目前的子进程
	mkdir /etc/supervisor.d/

	// laravel horizon 配置
	vim horizon.ini
		[program:horizon]
		process_name=%(program_name)s
		command=php /www/wwwroot/我们的项目目录/artisan horizon
		autostart=true
		autorestart=true
		;user=forge
		redirect_stderr=true
		stdout_logfile=/www/wwwroot/我们的项目目录/storage/logs/horizon.log

	// laravel 队列 配置
	vim laravel-work.ini
		[program:laravel-worker]
		process_name=%(program_name)s_%(process_num)02d
		command=php /www/wwwroot/我们的项目目录/artisan queue:work database --sleep=3 --tries=3
		autostart=true
		autorestart=true
		;user=forge
		numprocs=8
		redirect_stderr=true
		stdout_logfile=/www/wwwroot/我们的项目目录/storage/logs/laravel-worker.log

5.上面配置中,有关 [inet_http_server] 区块里的 *:9001,在阿里云服务器上,需外网访问,我们需要在 '阿里云安全组' 和 '服务器的 iptables' 分别配置

6.启用、停止、重启配置
	参考:https://www.load-page.com/manuals/web-server/chapter-tools/supervisor.html

	我们使用的是 CentOS 7,摘抄一遍配置:

		1>编辑服务脚本
		vim /usr/lib/systemd/system/supervisord.service

			# supervisord service for sysstemd (CentOS 7.0+)
			# by ET-CS (https://github.com/ET-CS)
			[Unit]
			Description=Supervisor daemon

			[Service]
			Type=forking
			ExecStart=/usr/bin/supervisord -c /etc/supervisord.conf
			ExecStop=/usr/bin/supervisorctl $OPTIONS shutdown
			ExecReload=/usr/bin/supervisorctl $OPTIONS reload
			KillMode=process
			Restart=on-failure
			RestartSec=42s
			[Install]
			WantedBy=multi-user.target
		2>注册服务
		systemctl enable supervisord.service
		3>使用
			启动:
				systemctl start supervisord.service
			停止:
				systemctl stop supervisord.service
			重启:
				systemctl restart supervisord.service