使用supervisord管理的进程不能继续使用jave -jar的方式直接启动,需要用supervisor提供的相关命令进行管理
1.部署supervisord
安装方式
直接使用yum方式安装
配置调整
更新/etc/supervisord.conf,打开ui
[inet_http_server] ; inet (TCP) server disabled by default
port=0.0.0.0:9002 ; (ip_address:port specifier, *:port for all iface)
username=user ; (default is no username (open server))
password=123 ; (default is no password (open server))
进入/etc/supervisord.d创建监控进程的ini文件如下
[wolf@wulaoer.org 🔥🔥🔥🔥 supervisord.d]# cat opt.ini
[program:opt]
directory=/apps/works/start/
command=启动命令 ---直接启动
autostart=true
startsecs=60
autorestart=true
startretries=30
user=root
priority=999
stopsignal=INT
redirect_stderr=true
stdout_logfile_maxbytes=500MB
stdout_logfile_backups = 100
stdout_logfile=/apps/works/logs/opt.log
stopasgroup=false
killasgroup=false
[root@k8s01-0002 supervisord.d]#
supervisor相关命令
[wolf@wulaoer.org 🔥🔥🔥🔥 ~ ]# supervisorctl status
[wolf@wulaoer.org 🔥🔥🔥🔥 ~ ]# supervisorctl stop usercenter
[wolf@wulaoer.org 🔥🔥🔥🔥 ~ ]# supervisorctl start usercenter
[wolf@wulaoer.org 🔥🔥🔥🔥 ~ ]# supervisorctl restart usercenter
[wolf@wulaoer.org 🔥🔥🔥🔥 ~ ]# supervisorctl reread
[wolf@wulaoer.org 🔥🔥🔥🔥 ~ ]# supervisorctl update
2.supervisor-monitor安装
supervisor-monitor是php写的所以环境要求有php
安装php
yum -y install php-fpm
然后更改vim /etc/php-fpm.d/www.conf
重点有四处,由于安装时和nginx同一主机,另外端口没有冲突,所以listen的两个没更改,之后nginx调用时会继续使用9000端口
user和group必须和nginx用户一致,默认是apache
listen = 127.0.0.1:9000
listen.allowed_clients = 127.0.0.1
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
; will be used.
; RPM: apache Choosed to be able to access some dir as httpd
user = root
; RPM: Keep a group allowed to write in log dir.
group = root
保存后启动/usr/sbin/php-fpm -R &
安装monitor
下载安装包
[wolf@wulaoer.org 🔥🔥🔥🔥 ~ ]# wget https://github.com/mlazarov/supervisord-monitor/archive/refs/tags/v1.1.0.tar.gz
[wolf@wulaoer.org 🔥🔥🔥🔥 ~ ]# tar -xvf v1.1.0.tar.gz
解压后mv更改名称,名称随意 mv supervisord-monitor-1.1.0 supervisord
进入目录
[wolf@wulaoer.org 🔥🔥🔥🔥 ~ ]# cd /apps/works/server/supervisord/application/config
[wolf@wulaoer.org 🔥🔥🔥🔥 ~ ]# cp supervisor.php.example supervisor.php
[wolf@wulaoer.org 🔥🔥🔥🔥 ~ ]# vim supervisor.php,重点更改如下,其余不用动,url后RPC2不用改,只要更改ip即可,有在supervisor中设置用户名密码则添加username等,没有可删除
$config['supervisor_servers'] = array(
'server20' => array(
'url' => 'http://x.x.x.x/RPC2',
'port' => '8888',
'username' => 'wulaoer',
'password' => 'wulaoer'
),
'server21' => array(
'url' => 'http://x.x.x.x/RPC2',
'port' => '8888',
'username' => 'wulaoer',
'password' => 'wulaoer'
),
'server23' => array(
'url' => 'http://x.x.x.x/RPC2',
'port' => '8888',
'username' => 'wulaoer',
'password' => 'wulaoer'
),
);
至此monitor配置完成,之后配置nginx即可,在此之前先设置个monitor的访问密码
[wolf@wulaoer.org 🔥🔥🔥🔥 ~ ]# yum -y install httpd-tools
设置efreight用户,路径对应nginx
[wolf@wulaoer.org 🔥🔥🔥🔥 ~ ]# htpasswd -c /usr/local/nginx/conf.d/.htpasswd wulaoer
nginx配置如下
[wolf@wulaoer.org 🔥🔥🔥🔥 ~ ]# cat supervisord.conf
server {
listen 8091 ;
server_name _;
root /apps/works/server/supervisord/public_html; --此处需指定public_html路径
location / {
index index.php index.html;
auth_basic "Basic Auth"; --添加验证
auth_basic_user_file "/usr/local/nginx/conf/.htpasswd"; --添加验证
}
location /control/ {
index index.php;
rewrite /(.*)$ /index.php?$1 last;
}
location ~ .php$ {
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000; # 这是php服务监控端口
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCHEME $scheme;
include fastcgi_params;
}
access_log /apps/works/logs/super.log;
}
[root@01-0002 vhost]#
启动nginx
可以在此查看进程状态和停止启动
您可以选择一种方式赞助本站
支付宝扫一扫赞助
微信钱包扫描赞助
赏