docker-compose部署nginx代理tomcat群集
程序员文章站
2022-06-07 09:09:07
...
一、在hos主机先验证下
mkdir myconsete
上传一份jdk
cd myconsete/
wget https://mirrors.aliyun.com/apache/tomcat/tomcat-8/v8.5.56/bin/apache-tomcat-8.5.56.tar.gz 下载软件包
tar zxf jdk-8u211-linux-x64.tar.gz
tar zxf apache-tomcat-8.5.56.tar.gz
mv jdk1.8.0_211/ /usr/local/java
mv apache-tomcat-8.5.56 /usr/local/tomcat8
vim /etc/profile
export JAVA_HOME=/usr/local/java
export PATH=$JAVA_HOME/bin/:$PATH
./etc/profile (刷新)
java -version (查看版本)
/usr/local/tomcat8/bin/catalina.sh run (以前台方式启动)
二、编写dockerfile
cd tomcat/
vim Dockerfile
FROM centos-7
ADD jdk-8u211-linux-x64.tar.gz /usr/local/
ENV JAVA_HOME /usr/local/jdk1.8.0_211
ADD apache-tomcat-8.5.56.tar.gz /usr/local/
EXPOSE 8080
ENTRYPOINT ["/usr/local/apache-tomcat-8.5.56/bin/catalina.sh", "run"]
三、编写tomcat网页文件
cd ..
mkdir webserver
cd webserver/
mkdir {tomcat1,tomcat2}
vim tomcat1/index.jsp
<%
out.println("this is tomcat1");
%>
cp tomcat1/index.jsp tomcat2/ (更改下里面内容)
四、编写nginx代理
cd..
mkdir nginx
cd nginx/
vim default.conf
upstream webserver { (添加负载均衡主机)
server tomcat1:8080;
server tomcat2:8080;
}
server {
listen 80;
listen [::]:80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
proxy_pass http://webserver; (修改为负载均衡地址)
}
}
五、同步时间规划
cd ..
mkdir etc
cp /usr/share/zoneinfo/Asia/Shanghai etc/localtime
tree
六、编写docker-compose
cd ..
vim docker-compose.yml
version: "3"
services:
nginx:
image: nginx
restart: always
ports:
- 80:80
links:
- tomcat1:tomcat1
- tomcat2:tomcat2
volumes:
- ./etc/localtime:/etc/localtime
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
depends_on:
- tomcat1
- tomcat2
tomcat1:
hostname: tomcat1
build: ./tomcat
volumes:
- ./etc/localtime:/etc/localtime
- ./webserver/tomcat1:/usr/local/apache-tomcat-8.5.56/webapps/ROOT
tomcat2:
hostname: tomcat2
build: ./tomcat
volumes:
- ./etc/localtime:/etc/localtime
- ./webserver/tomcat2:/usr/local/apache-tomcat-8.5.56/webapps/ROOT
depends_on: 这个选项用作 先启动tomcat 在启动nginx
七、启动查看验证
docker-compose up -d
查看镜像:
网页访问
上一篇: Docker Compose基本介绍
推荐阅读
-
Vue项目部署的实现(阿里云+Nginx代理+PM2)
-
windows安装nginx部署步骤图解(反向代理与负载均衡)
-
.net core3.0部署Linux服务器 使用Docker容器和Nginx反代理教程
-
Vue项目部署的实现(阿里云+Nginx代理+PM2)
-
vue项目打包部署_nginx代理访问方法详解
-
Nginx部署tomcat/wildfly集群负载均衡
-
详解Nginx + Tomcat 反向代理 负载均衡 集群 部署指南
-
详解Nginx + Tomcat 反向代理 如何在高效的在一台服务器部署多个站点
-
详解Nginx反向代理到Tomcat服务器
-
vue项目部署到nginx/tomcat服务器的实现