Home Operation and Maintenance Nginx How to use supervisor to manage nginx and tomcat containers

How to use supervisor to manage nginx and tomcat containers

May 12, 2023 pm 02:10 PM
nginx tomcat supervisor

Requirements:

Use docker to start nginx tomcat dual processes. In actual applications, multiple processes are relatively common.

1: Create dockerfile directory

mkdir -p /docker/web
Copy after login

2: Write dockerfile: /docker/web/dockerfile

from centos7

maintainer lin test@163.com

copy centos-base.repo /etc/yum.repos.d/centos-base.repo

copy nginx_install.sh /tmp/nginx_install.sh

run sh /tmp/nginx_install.sh; \rm -rf /usr/local/src/*

run sed -i -e '/worker_processes/a daemon off;' /usr/local/nginx/conf/nginx.conf;

 

copy jdk-8u162-linux-x64.tar.gz /usr/local/src/jdk-8u162-linux-x64.tar.gz

copy tomcat_install.sh /tmp/tomcat_install.sh

run sh /tmp/tomcat_install.sh; \rm -rf /usr/local/src/*

 

copy supervisor_install.sh /tmp/supervisor_install.sh

copy supervisord.conf /etc/supervisord.conf

copy start_tomcat.sh /usr/local/tomcat/bin/mystart.sh

run sh /tmp/supervisor_install.sh; \rm -rf /tmp/*.sh
Copy after login

3: Dockerfile integrated configuration file and installation file

3.1 The default source download is slow, change the yum source, copy the following centos-base.repo configuration file to the container and replace it

copy centos-base.repo /etc/yum.repos.d/centos-base.repo

[root@docker web]# cat centos-base.repo 

[base]

name=centos-$releasever - base

baseurl=http://mirrors.163.com/centos/$releasever/os/$basearch/

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/rpm-gpg-key-centos-7

 

#released updates

[updates]

name=centos-$releasever - updates

baseurl=http://mirrors.163.com/centos/$releasever/updates/$basearch/

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/rpm-gpg-key-centos-7

 

#additional packages that may be useful

[extras]

name=centos-$releasever - extras

baseurl=http://mirrors.163.com/centos/$releasever/extras/$basearch/

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/rpm-gpg-key-centos-7

 

#additional packages that extend functionality of existing packages

[centosplus]

name=centos-$releasever - plus

baseurl=http://mirrors.163.com/centos/$releasever/centosplus/$basearch/

gpgcheck=1

enabled=0

gpgkey=file:///etc/pki/rpm-gpg/rpm-gpg-key-centos-7
Copy after login

3.2nginx installation script

[root@docker web]# cat nginx_install.sh 

yum install -y wget tar gcc gcc-c++ make pcre pcre-devel zlib zlib-devel openssl openssl-devel

 

cd /usr/local/src

wget 'http://nginx.org/download/nginx-1.12.2.tar.gz'

tar -zxvf nginx-1.12.2.tar.gz

cd nginx-1.12.2

./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-stream --with-stream_ssl_module

make

make install

exit 0
Copy after login

3.3tomcat installation script

[root@docker web]# cat tomcat_install.sh 

yum install -y wget tar

cd /usr/local/src/

tar -zxvf jdk-8u162-linux-x64.tar.gz

mv jdk1.8.0_162 /usr/local/

#/usr/local/jdk1.8.0_162/bin/java -version

 

#配置java环境变量

echo 'java_home=/usr/local/jdk1.8.0_162/' >>/etc/profile

echo 'path=$path:$java_home/bin' >>/etc/profile

echo 'classpath=.:$java_home/lib/tools.jar:$java_home/lib/dt.jar:$classpath' >>/etc/profile

source /etc/profile

 

wget https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.5.38/bin/apache-tomcat-8.5.38.tar.gz

tar -zxvf apache-tomcat-8.5.38.tar.gz

mv apache-tomcat-8.5.38 /usr/local/tomcat
Copy after login

3.4 The configuration files, scripts, and installation packages involved in the dockerfile file are as follows

[root@docker web]# ll

total 185384

-rw-r--r-- 1 root root 835 mar 9 01:12 centos-base.repo

-rw-r--r-- 1 root root 669 mar 9 01:11 dockerfile

-rw-r--r-- 1 root root 189815615 mar 9 01:15 jdk-8u162-linux-x64.tar.gz

-rw-r--r-- 1 root root 340 mar 9 01:13 nginx_install.sh

-rw-r--r-- 1 root root 581 mar 9 01:17 tomcat_install.sh
Copy after login

4: One-click installation of supervisor: /docker/web/supervisor_install.sh

yum -y install epel-release
yum -y install python2-pip
pip install supervisor
Copy after login

5 : supervisor configuration file: /docker/web/supervisord.conf

[unix_http_server]

file=/tmp/supervisor.sock ; the path to the socket file

 

[supervisord]

logfile=/tmp/supervisord.log ; 日志

logfile_maxbytes=50mb ; 最大50m日志

logfile_backups=10 ; 轮循日志备份10个

loglevel=info ; 日志等级记录info的

pidfile=/tmp/supervisord.pid ;pid

nodaemon=true ;在前台启动

minfds=102400 ; 文件描述符限制

minprocs=2000 ; 进程数

 

[rpcinterface:supervisor]

supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

 

[supervisorctl]

serverurl=unix:///tmp/supervisor.sock ; use a unix:// url for a unix socket

 

[program:nginx]

command=/usr/local/nginx/sbin/nginx ; 前台启动nginx

autostart=true ; 随着supervisor自动启动

startsecs=10 ; 启动10s后算正常启动

autorestart=true ; 程序退出后自动重启

startretries=3 ; 启动失败自动重试次数

stdout_logfile_maxbytes=20mb ;stdout 日志文件大小最大20mb

stdout_logfile=/usr/local/nginx/logs/out.log

 

[program:tomcat]

command=sh /usr/local/tomcat/bin/mystart.sh ; 前台启动tomcat

autostart=true ; 随着supervisor自动启动

startsecs=10 ; 启动10s后算正常启动

autorestart=true ; 程序退出后自动重启

startretries=3 ; 启动失败自动重试次数

stdout_logfile_maxbytes=20mb ;stdout 日志文件大小最大20mb

stdout_logfile=/usr/local/tomcat/logs/catalina.out
Copy after login

6: tomcat startup script/docker/web/start_tomcat.sh

#由于supervisor无法使用source,需要编写个脚本来启动

source /etc/profile

/usr/local/tomcat/bin/catalina.sh run
Copy after login

7: Build image

cd /docker/web
docker build -t shijiange_web .

[root@docker web]# docker images
repository tag image id created size
shijiange_web latest bc06a9974252 7 seconds ago 1.33 gb
Copy after login

8: Start container test

[root@docker web]# docker run -d shijiange_web /bin/bash -c 'supervisord -c /etc/supervisord.conf'

76782ab71c3b1d2f818ad76214d6336ae11a524eeb9d211f154fe4ad5226015d

[root@docker web]# 

[root@docker web]# docker ps

container id image command created status ports names

76782ab71c3b shijiange_web "container-entrypo..." 12 seconds ago up 12 seconds happy_jones
Copy after login

9. Test verification:

[root@docker web]# docker exec -it 76782ab /bin/bash
bash-4.2# ifconfig
Copy after login

How to use supervisor to manage nginx and tomcat containers

10. Container verification: curl nginx

How to use supervisor to manage nginx and tomcat containers

11. Container verification: curl tomcat

How to use supervisor to manage nginx and tomcat containers

The above is the detailed content of How to use supervisor to manage nginx and tomcat containers. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to configure cloud server domain name in nginx How to configure cloud server domain name in nginx Apr 14, 2025 pm 12:18 PM

How to configure an Nginx domain name on a cloud server: Create an A record pointing to the public IP address of the cloud server. Add virtual host blocks in the Nginx configuration file, specifying the listening port, domain name, and website root directory. Restart Nginx to apply the changes. Access the domain name test configuration. Other notes: Install the SSL certificate to enable HTTPS, ensure that the firewall allows port 80 traffic, and wait for DNS resolution to take effect.

How to start nginx server How to start nginx server Apr 14, 2025 pm 12:27 PM

Starting an Nginx server requires different steps according to different operating systems: Linux/Unix system: Install the Nginx package (for example, using apt-get or yum). Use systemctl to start an Nginx service (for example, sudo systemctl start nginx). Windows system: Download and install Windows binary files. Start Nginx using the nginx.exe executable (for example, nginx.exe -c conf\nginx.conf). No matter which operating system you use, you can access the server IP

How to check nginx version How to check nginx version Apr 14, 2025 am 11:57 AM

The methods that can query the Nginx version are: use the nginx -v command; view the version directive in the nginx.conf file; open the Nginx error page and view the page title.

How to check the name of the docker container How to check the name of the docker container Apr 15, 2025 pm 12:21 PM

You can query the Docker container name by following the steps: List all containers (docker ps). Filter the container list (using the grep command). Gets the container name (located in the "NAMES" column).

How to run nginx apache How to run nginx apache Apr 14, 2025 pm 12:33 PM

To get Nginx to run Apache, you need to: 1. Install Nginx and Apache; 2. Configure the Nginx agent; 3. Start Nginx and Apache; 4. Test the configuration to ensure that you can see Apache content after accessing the domain name. In addition, you need to pay attention to other matters such as port number matching, virtual host configuration, and SSL/TLS settings.

How to check whether nginx is started How to check whether nginx is started Apr 14, 2025 pm 01:03 PM

How to confirm whether Nginx is started: 1. Use the command line: systemctl status nginx (Linux/Unix), netstat -ano | findstr 80 (Windows); 2. Check whether port 80 is open; 3. Check the Nginx startup message in the system log; 4. Use third-party tools, such as Nagios, Zabbix, and Icinga.

How to create a mirror in docker How to create a mirror in docker Apr 15, 2025 am 11:27 AM

Steps to create a Docker image: Write a Dockerfile that contains the build instructions. Build the image in the terminal, using the docker build command. Tag the image and assign names and tags using the docker tag command.

How to start containers by docker How to start containers by docker Apr 15, 2025 pm 12:27 PM

Docker container startup steps: Pull the container image: Run "docker pull [mirror name]". Create a container: Use "docker create [options] [mirror name] [commands and parameters]". Start the container: Execute "docker start [Container name or ID]". Check container status: Verify that the container is running with "docker ps".

See all articles