Example of using supervisor to manage nginx+tomcat containers

Example of using supervisor to manage nginx+tomcat containers

need:

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

1: Create a Dockerfile directory

mkdir -p /docker/web

2: Write Dockerfile: /docker/web/Dockerfile

FROM centos7

MAINTAINER lin [email protected]

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 files and installation files

3.1 The default source download is slow, change the yum source, copy the following CentOS-Base.repo configuration file to the container and change 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

 

#Configure java environment variables 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; maximum 50MB logfile_backups=10; 10 log backups in rotationloglevel=info; log level record infopidfile=/tmp/supervisord.pid;pid

nodaemon=true ; Start in foreground minfds=102400 ; File descriptor limit minprocs=2000 ; Number of processes [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 ; Start nginx in the foreground

autostart=true; automatically starts with supervisorstartsecs=10; a normal startup is considered after 10 seconds of startupautorestart=true; automatically restarts after the program exitsstartretries=3; the number of automatic retries when startup failsstdout_logfile_maxbytes=20MB; the maximum size of stdout log file is 20Mb

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

 

[program:tomcat]

command=sh /usr/local/tomcat/bin/mystart.sh ; Start tomcat in the foreground

autostart=true; automatically starts with supervisorstartsecs=10; a normal startup is considered after 10 seconds of startupautorestart=true; automatically restarts after the program exitsstartretries=3; the number of automatic retries when startup failsstdout_logfile_maxbytes=20MB; the maximum size of stdout log file is 20Mb

stdout_logfile=/usr/local/tomcat/logs/catalina.out

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

#Since supervisor cannot use source, you need to write a script to start source /etc/profile

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

7: Build the 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 

10. Container verification: curl nginx

11. Container verification: curl tomcat

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • How to set up virtual directories and configure virtual paths in Tomcat 7.0
  • Explanation of Tomcat using IDEA remote Debug
  • Tomcat uses Log4j to output catalina.out log
  • Centos7.5 configuration java environment installation tomcat explanation
  • Connector configuration in Tomcat
  • Explanation of the steps for Tomcat to support https access
  • Tomcat+Mysql high concurrency configuration optimization explanation
  • Explanation on the use and modification of Tomcat's default program publishing path
  • Detailed explanation of three ways to cut catalina.out logs in tomcat
  • Explanation of several ways to run Tomcat under Linux

<<:  js implements the algorithm for specifying the order and amount of red envelopes

>>:  Examples of optimization techniques for slow query efficiency in MySQL IN statements

Recommend

Summary of Vue's monitoring of keyboard events

Key Modifiers When listening for keyboard events,...

Native JS to implement paging click control

This is an interview question, which requires the...

What to do after installing Ubuntu 20.04 (beginner's guide)

Ubuntu 20.04 has been released, bringing many new...

Implementation steps for installing java environment in docker

This article is based on Linux centos8 to install...

How to install Android x86 in vmware virtual machine

Sometimes you just want to test an app but don’t ...

Docker View JVM Memory Usage

1. Enter the host machine of the docker container...

Why is UTF-8 not recommended in MySQL?

I recently encountered a bug where I was trying t...

Summary of Docker configuration container location and tips

Tips for using Docker 1. Clean up all stopped doc...

Web page comments cause text overflow in IE

The experimental code is as follows: </head>...

Summary of 4 solutions for returning values ​​on WeChat Mini Program pages

Table of contents Usage scenarios Solution 1. Use...

Several solutions for forgetting the MySQL password

Solution 1 Completely uninstall and delete all da...

VUE+SpringBoot implements paging function

This article mainly introduces how to implement a...

Docker image access to local elasticsearch port operation

Using the image service deployed by docker stack,...