Copyright Notice: Copyright © 2018-2019 cool white open no ice Copyright https://blog.csdn.net/qq_21082615/article/details/91430978
Description: When the project is getting bigger, with the online server to deploy more and more, updated, and the management will be very troublesome, it is necessary to start up the script on each server, this article will explain how to deploy supervisor to manage the service process.
A, supervisor monitoring the deployment process
准备工作:需要守护监听进程的服务器,例如:192.168.0.121
1.安装setuptools
yum install python-setuptools -y
2.下载meld3和supervisor
wget https://pypi.python.org/packages/0f/5e/3a57c223d8faba2c3c2d69699f7e6cfdd1e5cc31e79cdd0dd48d44580b50/meld3-1.0.1.tar.gz#md5=2f045abe0ae108e3c8343172cffbe21d
wget https://pypi.python.org/packages/31/7e/788fc6566211e77c395ea272058eb71299c65cc5e55b6214d479c6c2ec9a/supervisor-3.3.3.tar.gz#md5=0fe86dfec4e5c5d98324d24c4cf944bd
3.解压安装meld3和supervisor
tar xf meld3-1.0.1.tar.gz
cd meld3-1.0.1
python setup.py install
cd ../
tar xf supervisor-3.3.3.tar.gz
cd supervisor-3.3.3
python setup.py install
4.生成supervisord配置文件
mkdir /etc/supervisor
cd /etc/supervisor
echo_supervisord_conf > supervisord.conf
5.修改配置开启远程web页面访问,去掉前面的;号
[inet_http_server] ; inet (TCP) server disabled by default
port=0.0.0.0:9001 ; ip_address:port specifier, *:port for all iface
username=user ; default is no username (open server)
password=123 ; default is no password (open server)
6.启动服务并访问页面
/usr/bin/supervisord -c /etc/supervisor/supervisord.conf
http://ip地址:9001 访问地址之后页面是什么都没有的,应为还没有守护进程
7.安装jdk以及tomcat,守护进程
yum install java-1.8.0-openjdk java-1.8.0-openjdk-devel -y
wget https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-7/v7.0.82/bin/apache-tomcat-8.5.35.tar.gz
tar -xf apache-tomcat-8.5.35.tar.gz -C /data/app
cd /data/app
ln -sv apache-tomcat-8.5.35.tar.gz/ tomcat
8.配置supervisord.conf文件
mkdir /etc/supervisor/conf.d
cd conf.d
vi tomcat.ini
[program:tomcat]
user=root
command=/data/app/tomcat/bin/catalina.sh run;启动tomcat
autostart=true
autorestart=true
startsecs=5
priority=1
stopasgroup=true
killasgroup=true
stdout_logfile=/data/app/tomcat/logs/catalina.out
说明:
program:tomcat------->页面展示名称
command-------------->执行命令
修改文件supervisord.conf,在文件最下面
[include]
files = /etc/supervisor/config.d/*.ini
8.执行命令
supervisorctl update
这时候在刷新页面就会出现tomcat进程了
9.其他命令
supervisorctl status
supervisorctl stop tomcat #关闭tomcat进程
supervisorctl start tomcat #启动tomcat进程
supervisorctl restart tomcat #重启tomcat进程
supervisorctl reread
supervisorctl update
Second, the deployment supervisor-monitor monitoring
准备工作:监控守护进程服务器,例如:192.168.0.120
1.首先部署nginx
安装编译工具及库文件
yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel
首先要安装 PCRE
cd /usr/local/src/
下载pcre
wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz
解压pcre
tar zxvf pcre-8.35.tar.gz
编译安装
cd pcre-8.35
./configure
make && make install
2.下载安装nginx
cd /usr/local/src/
下载nginx
wget http://nginx.org/download/nginx-1.6.2.tar.gz
解压
tar zxvf nginx-1.6.2.tar.gz
编译安装
cd nginx-1.6.2
./configure --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.35
make
make install
3.修改nginx配置文件
vi /usr/local/webserver/nginx/conf/nginx.conf
user www www;
worker_processes 2; #设置值和CPU核心数一致
error_log /usr/local/webserver/nginx/logs/nginx_error.log crit; #日志位置和日志级别
pid /usr/local/webserver/nginx/nginx.pid;
Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 65535;
events
{
use epoll;
worker_connections 65535;
}
http
{
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
charset gb2312;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 8m;
sendfile on;
tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
#limit_zone crawler $binary_remote_addr 10m;
#下面是server虚拟主机的配置
server
{
listen 80;#监听端口
server_name localhost;#域名
index index.html index.htm index.php;
root /usr/local/webserver/nginx/html;#站点目录
location ~ ..(php|php5)?$ { #fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; } location ~ ..(gif|jpg|jpeg|png|bmp|swf|ico)$
{
expires 30d;
# access_log off;
}
location ~ .*.(js|css)?$
{
expires 15d;
# access_log off;
}
access_log off;
}
}
4.校验并启动nginx
/usr/local/webserver/nginx/sbin/nginx -t
/usr/local/webserver/nginx/sbin/nginx
5.访问nginx
http://ip
6.安装php
yum -y install php-fpm
vi /etc/php-fpm.d/www.conf
user = root
group = root
7.启动php
/usr/sbin/php-fpm -R &
8.查看php是否启动成功
netstat -antp
9.测试php
配置nginx
vi /usr/local/webserver/nginx/conf/nginx.conf
location ~ .php$ {
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;
}
10.在/usr/local/webserver/nginx/html下新建index.php文件
vi /usr/local/webserver/nginx/html/index.php
<?php
phpinfo();
?>
11.刷新nginx配置并访问页面
/usr/local/webserver/nginx/sbin/nginx -s reload
http://ip
成功的话会出现php版本信息
12.安装supervisord-monitor
下载supervisord-monitor源码
git clone https://github.com/mlazarov/supervisord-monitor.git
修改php文件
cd /usr/local/webserver/nginx/html/supervisord-monitor/application/config
cp supervisor.php.example supervisor.php
vi supervisor.php
$config['supervisor_servers'] = array(
'server01' => array(
'url' => 'http://部署supervisor服务器ip/RPC2',
'port' => '9001',
'username' => 'user(上面配置的supervisor)',
'password' => '123'
)
);
13.配置nginx
新建conf.d
mkdir /usr/local/webserver/nginx/conf/conf.d
新建配置文件supervisor
vi supervisor.conf
server {
listen 80 default_server;
server_name 本机IP地址;
root /usr/local/webserver/nginx/html/supervisord-monitor/public_html;
location / {
index index.php;
}
location /control/ {
index index.php;
rewrite /(.*)$ /index.php?$1 last;
}
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;
}
}
将配置文件引入nginx.conf
vi /usr/local/webserver/nginx/conf/nginx.conf
在server之前引入即可
include /usr/local/webserver/nginx/conf/conf.d/*.conf;
14.校验配置文件并更新
/usr/local/webserver/nginx/sbin/nginx -t
/usr/local/webserver/nginx/sbin/nginx -s reload
15.访问supervisord-monitor监控
http://IP地址
出现下图就是部署成功了
Third, if the new one reason or another server daemon only need to modify the following configuration you can monitor the server, other operations are a step
vi supervisor.php
$config['supervisor_servers'] = array(
'server01' => array(
'url' => 'http://部署supervisor服务器ip/RPC2',
'port' => '9001',
'username' => 'user(上面配置的supervisor)',
'password' => '123'
),'server02' => array(
'url' => 'http://部署supervisor服务器ip/RPC2',
'port' => '9001',
'username' => 'user(上面配置的supervisor)',
'password' => '123'
)
);