Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use supervisor to manage nginx+tomcat containers

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

How to use supervisor to manage nginx+tomcat containers? Many novices are not very clear about this. In order to help you solve this problem, the following editor will explain it in detail. People with this need can come and learn. I hope you can gain something.

Demand:

Using docker to start nginx + tomcat dual processes, in practical applications, multi-processes are still quite common.

1: create a dockerfile directory

Mkdir-p / docker/web

2: write dockerfile: / docker/web/Dockerfile

FROM centos7MAINTAINER lin test@163.comCOPY CentOS-Base.repo / etc/yum.repos.d/CentOS-Base.repoCOPY nginx_install.sh / tmp/nginx_install.shRUN 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.gzCOPY tomcat_install.sh / tmp/tomcat_install.shRUN sh / tmp/tomcat_install.sh;\ rm-rf / usr/local/src/* COPY supervisor_install.sh / tmp/supervisor_install.shCOPY supervisord.conf / etc/supervisord.confCOPY start_tomcat.sh / usr/local/tomcat/bin/mystart.shRUN sh / tmp/supervisor_install.sh;\ rm-rf / tmp/*.sh

3: configuration files and installation files for dockerfile integration

3.1The default source is slow to download. Change the yum source. Copy the following CentOS-Base.repo configuration file to the container for replacement.

COPY CentOS-Base.repo / etc/yum.repos.d/CentOS-Base.repo [root@docker web] # cat CentOS-Base.repo [base] name=CentOS-$releasever-Basebaseurl= http://mirrors.163.com/centos/$releasever/os/$basearch/gpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 # released updates [updates] name=CentOS-$releasever-Updatesbaseurl= http://mirrors.163.com/centos/$releasever/updates/$basearch/gpgcheck=1gpgkey=file:///etc/pki/rpm-gpg / RPM-GPG-KEY-CentOS-7 # additional packages that may be usefull [extras] name=CentOS-$releasever-Extrasbaseurl= http://mirrors.163.com/centos/$releasever/extras/$basearch/gpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 # additional packages that extend functionality of existing packages [centosplus] name=CentOS-$releasever-Plusbaseurl= http://mirrors.163.com/centos/$releasever/centosplus/$basearch/gpgcheck=1enabled=0gpgkey=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/srcwget 'http://nginx.org/download/nginx-1.12.2.tar.gz'tar-zxvf nginx-1.12.2.tar.gzcd nginx-1.12.2./configure-prefix=/usr/local/nginx-- with-http_ssl_module-- with-stream-- with-stream_ssl_modulemakemake installexit 0

3.3tomcat installation script

[root@docker web] # cat tomcat_install.sh yum install-y wget tarcd / usr/local/src/tar-zxvf jdk-8u162-linux-x64.tar.gzmv jdk1.8.0_162/ usr/local/#/usr/local/jdk1.8.0_162/bin/java-version # configure the java environment variable echo 'JAVA_HOME=/usr/local/jdk1.8.0_162/' > > / etc/profileecho' PATH=$PATH:$JAVA_HOME/bin' > > / etc/profileecho 'CLASSPATH=. : $JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:$CLASSPATH' > > / etc/profilesource / etc/profile wget https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.5.38/bin/apache-tomcat-8.5.38.tar.gztar-zxvf apache-tomcat-8.5.38.tar.gzmv apache-tomcat-8.5.38 / usr/local/tomcat

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

[root@docker web] # lltotal 185384 root root 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: install supervisor: / docker/web/supervisor_install.sh with one click

Yum-y install epel-releaseyum-y install python2-pippip 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; log _ maxbytes=50MB; maximum 50m log logfile _ backups=10; 10 loglevel=info of round robin log backup; pidfile=/tmp/supervisord.pid of log level record info; pidnodaemon=true; start minfds=102400 in the foreground; file descriptor limits 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; nginxautostart=true starts in the foreground; startsecs=10 starts automatically with supervisor; autorestart=true starts normally after starting for 10 seconds; startretries=3 restarts automatically after program exits; number of automatic retries that failed to start stdout_logfile_maxbytes=20MB Stdout log file size maximum 20Mbstdout_logfile=/usr/local/nginx/logs/out.log [program:tomcat] command=sh / usr/local/tomcat/bin/mystart.sh; foreground start tomcatautostart=true; automatically start startsecs=10 with supervisor; start autorestart=true normally after starting 10s; automatically restart startretries=3 after program exit; automatic retry number of failed startup stdout_logfile_maxbytes=20MB; stdout log file size maximum 20Mbstdout_logfile=/usr/local/tomcat/logs/catalina.out

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

# because supervisor cannot use source, you need to write a script to start source / etc/profile/usr/local/tomcat/bin/catalina.sh run

7: build an image

Cd / docker/webdocker build-t shijiange_web. [root@docker web] # docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEshijiange_web latest bc06a9974252 7 seconds ago 1.33 GB

8: start the 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 psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES76782ab71c3b shijiange_web "container-entrypo..." 12 seconds ago Up 12 seconds happy_jones

9. Test verification:

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

10. Container authentication: curl nginx

11. Container authentication: curl tomcat

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report