1. 监控的作用
1. supervisor
可以通过配置[inet_http_server]
开启web界面管理,为什么还要使用supervisor-monitor
2. supervisor-monitor
是通过RPC远程调用进行管理多台服务器上的supervisor
服务进程的,如果不使用它,假如一个公司有多个服务器,每个上面都部署了supervisor
服务,那么管理起来就很不方便,每次需要逐个登录所有的supervisor
服务去进行管理,而如果使用了supervisor-monitor
,通过简单配置就能将所有服务器上的supervisor
服务呈现在一个web管理面板上,管理效率就会大大提升。
2. 监控的安装与配置
1. supervisor-monitor
是使用php语言开发的,所以我们需要安装php环境
-
安装php
yum -y install php-fpm
-
修改配置文件中的用户,保持和
nginx
用户一致vim /etc/php-fpm.d/www.conf user = root group = root
-
启动php服务
/usr/sbin/php-fpm -R &
2. 测试php是否安装成功
-
新建php测试配置文件
vi /etc/nginx/conf.d/php.conf
-
内容如下
server { listen 8082; # 注意端口不要被占用 server_name 10.10.139.182; root /usr/share/nginx/html/; location ~ .php$ { try_files $uri =404; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCHEME $scheme; include fastcgi_params; } }
-
添加测试页面
vim /usr/share/nginx/html/index.php
-
内容如下
<?php phpinfo(); ?>
-
重启nginx
systemctl restart nginx
-
浏览器访问
http://10.10.139.182/8082/index.php
端口
3. 安装supervisord-monitor
-
克隆
git clone https://github.com/mlazarov/supervisord-monitor.git
-
进入到
supervisord-monitor/application/config
中,将默认的配置文件重命名下:cd /root/supervisord-monitor/application/config cp supervisor.php.example supervisor.php
-
修改
supervisor.php
配置文件- 还可以通过修改配置文件,使得web界面展示不同效果
$config['supervisor_servers'] = array( '10.10.139.182' => array( 'url' => 'http://10.10.139.182/RPC2', 'port' => '9001', 'username' => 'admin', 'password' => 'password@' ), );
此处需要注意:使用
supervisor-monitor
时,port必须写成:0.0.0.0,而不能写本地回环地址或者本机ip,否则会出错
如果用户名和密码写错,到时候web管理界面会显示如下内容
4. 配置nginx
-
内容如下
vim /etc/nginx/conf.d/supervisor.conf
server { listen 8082 default_server; server_name 10.10.139.182; root /root/supervisord-monitor/public_html; location / { index index.php index.html; } 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; } }
5. 浏览器访问http://10.10.139.182:8082/
3. 使用httpd-tools
配置访问密码
1.安装httpd-tools
yum -y install httpd-tools
2.生成密码文件
htpasswd -c /etc/nginx/conf.d/.htpasswd 用户名
3.如果想增加或修改密码
htpasswd -m /etc/nginx/conf.d/.htpasswd 用户名(如果重名则修改原有账户密码)
4.修改nginx配置文件,添加以下内容
location / {
index index.php index.html;
auth_basic "Basic Auth";
auth_basic_user_file "/etc/nginx/conf.d/.htpasswd";
}
- 修改后如下
server {
listen 8082 default_server;
server_name 10.10.139.182;
root /root/supervisord-monitor/public_html;
location / {
index index.php index.html;
auth_basic "Basic Auth";
auth_basic_user_file "/etc/nginx/conf.d/.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;
}
}