Docker部署Nginx详细步骤之前的文章有,请参考之前的文章呦~
这里就说一下docker运行nginx的命令:
docker run -d -p 80:80 --name nginx nginx
Docker部署Tomcat详细步骤之前的文章有,请参考之前的文章哟~
这里就说一下docker运行tomcat的命令:
docker run -d -p 8081:8080 --name tomcat8081 tomcat
docker run -d -p 8082:8080 --name tomcat8082 tomcat
使用Docker命令进入tomcat8080容进入/usr/local/tomcat/webapps目录结构下,创建index.html并写入唯一标识8080,同理可得,进入tomcat8081容器,执行同样的操作。
[root@VM-4-9-centos conf]# docker exec -it tomcat8080 /bin/bash
root@3febc79a7600:/usr/local/tomcat# ls
BUILDING.txt CONTRIBUTING.md LICENSE NOTICE README.md RELEASE-NOTES RUNNING.txt bin conf lib logs native-jni-lib temp webapps webappsnull work
root@3febc79a7600:/usr/local/tomcat# cd webapps
root@3febc79a7600:/usr/local/tomcat/webapps# ls
ROOT docs examples host-manager manager
root@3febc79a7600:/usr/local/tomcat/webapps# cd ROOT/
root@3febc79a7600:/usr/local/tomcat/webapps/ROOT# ls
RELEASE-NOTES.txt WEB-INF asf-logo-wide.svg bg-button.png bg-middle.png bg-nav.png bg-upper.png favicon.ico index.html index.jsp tomcat.css tomcat.svg
root@3febc79a7600:/usr/local/tomcat/webapps/ROOT# cat index.html
8080
root@3febc79a7600:/usr/local/tomcat/webapps/ROOT#
执行结果:
同理操作tomcat8081容器。。。。
进入Nginx目录下,修改Nginx.conf的配置文件,设置负载均衡的代理
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
# 配置tomcat的俩台代理IP地址
upstream myServers {
server X.X.X.X:8080;
server X.X.X.X:8081;
}
server{
listen 80;
server_name X.X.X.X;
location /{
proxy_pass http://myServers;
}
}
}
保存完Nginx.conf文件后,重新启动Nginx服务器,然后进行访问。
docker restart nginx