search
HomeOperation and MaintenanceNginxHow to use supervisor to manage nginx and tomcat containers

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

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

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

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

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

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

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

yum -y install epel-release
yum -y install python2-pip
pip install supervisor

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

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

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

source /etc/profile

/usr/local/tomcat/bin/catalina.sh run

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

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

9. Test verification:

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

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
This article is reproduced at:亿速云. If there is any infringement, please contact admin@php.cn delete
The Advantages of NGINX: Speed, Efficiency, and ControlThe Advantages of NGINX: Speed, Efficiency, and ControlMay 12, 2025 am 12:13 AM

The reason why NGINX is popular is its advantages in speed, efficiency and control. 1) Speed: Adopt asynchronous and non-blocking processing, supports high concurrent connections, and has strong static file service capabilities. 2) Efficiency: Low memory usage and powerful load balancing function. 3) Control: Through flexible configuration file management behavior, modular design facilitates expansion.

NGINX vs. Apache: Community, Support, and ResourcesNGINX vs. Apache: Community, Support, and ResourcesMay 11, 2025 am 12:19 AM

The differences between NGINX and Apache in terms of community, support and resources are as follows: 1. Although the NGINX community is small, it is active and professional, and official support provides advanced features and professional services through NGINXPlus. 2.Apache has a huge and active community, and official support is mainly provided through rich documentation and community resources.

NGINX Unit: An Introduction to the Application ServerNGINX Unit: An Introduction to the Application ServerMay 10, 2025 am 12:17 AM

NGINXUnit is an open source application server that supports a variety of programming languages ​​and frameworks, such as Python, PHP, Java, Go, etc. 1. It supports dynamic configuration and can adjust application configuration without restarting the server. 2.NGINXUnit supports multi-language applications, simplifying the management of multi-language environments. 3. With configuration files, you can easily deploy and manage applications, such as running Python and PHP applications. 4. It also supports advanced configurations such as routing and load balancing to help manage and scale applications.

Using NGINX: Optimizing Website Performance and ReliabilityUsing NGINX: Optimizing Website Performance and ReliabilityMay 09, 2025 am 12:19 AM

NGINX can improve website performance and reliability by: 1. Process static content as a web server; 2. forward requests as a reverse proxy server; 3. allocate requests as a load balancer; 4. Reduce backend pressure as a cache server. NGINX can significantly improve website performance through configuration optimizations such as enabling Gzip compression and adjusting connection pooling.

NGINX's Purpose: Serving Web Content and MoreNGINX's Purpose: Serving Web Content and MoreMay 08, 2025 am 12:07 AM

NGINXserveswebcontentandactsasareverseproxy,loadbalancer,andmore.1)ItefficientlyservesstaticcontentlikeHTMLandimages.2)Itfunctionsasareverseproxyandloadbalancer,distributingtrafficacrossservers.3)NGINXenhancesperformancethroughcaching.4)Itofferssecur

NGINX Unit: Streamlining Application DeploymentNGINX Unit: Streamlining Application DeploymentMay 07, 2025 am 12:08 AM

NGINXUnit simplifies application deployment with dynamic configuration and multilingual support. 1) Dynamic configuration can be modified without restarting the server. 2) Supports multiple programming languages, such as Python, PHP, and Java. 3) Adopt asynchronous non-blocking I/O model to improve high concurrency processing performance.

NGINX's Impact: Web Servers and BeyondNGINX's Impact: Web Servers and BeyondMay 06, 2025 am 12:05 AM

NGINX initially solved the C10K problem and has now developed into an all-rounder who handles load balancing, reverse proxying and API gateways. 1) It is well-known for event-driven and non-blocking architectures and is suitable for high concurrency. 2) NGINX can be used as an HTTP and reverse proxy server, supporting IMAP/POP3. 3) Its working principle is based on event-driven and asynchronous I/O models, improving performance. 4) Basic usage includes configuring virtual hosts and load balancing, and advanced usage involves complex load balancing and caching strategies. 5) Common errors include configuration syntax errors and permission issues, and debugging skills include using nginx-t command and stub_status module. 6) Performance optimization suggestions include adjusting worker parameters, using gzip compression and

Nginx Troubleshooting: Diagnosing and Resolving Common ErrorsNginx Troubleshooting: Diagnosing and Resolving Common ErrorsMay 05, 2025 am 12:09 AM

Diagnosis and solutions for common errors of Nginx include: 1. View log files, 2. Adjust configuration files, 3. Optimize performance. By analyzing logs, adjusting timeout settings and optimizing cache and load balancing, errors such as 404, 502, 504 can be effectively resolved to improve website stability and performance.

See all articles

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 Article

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment