192.168.10.10
192.168.10.20
192.168.10.30
location ~ \.jsp$ { proxy_pass http://192.168.10.50:8080; } location ~ \.(jsp|html)$ { root /usr/share/nginx/html; }
192.168.10.40和192.168.10.50用脚本完成搭建此处安装附上脚本:
#!/bin/bash # 定义变量 JDK_PACKAGE="jdk-8u201-linux-x64.rpm" JDK_INSTALL_PATH="/usr/java/jdk1.8.0_201-amd64" TOMCAT_PACKAGE="apache-tomcat-9.0.16.tar.gz" TOMCAT_INSTALL_PATH="/usr/local/tomcat" TOMCAT_USER="tomcat" TOMCAT_GROUP="tomcat" # Function to install JDK install_jdk() { if [ -e "$JDK_PACKAGE" ]; then rpm -ivh "$JDK_PACKAGE" &> /dev/null if [ $? -eq 0 ]; then echo -e "E[1;32m JDK 安装成功 E[0m" else echo -e "E[1;31m JDK 安装失败 E[0m" fi else echo "无 JDK 包" fi } # Function to modify environment variables setup_environment() { echo " export JAVA_HOME=$JDK_INSTALL_PATH export CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar export PATH=$JAVA_HOME/bin:$PATH" >> /etc/profile source /etc/profile } # Function to install Tomcat install_tomcat() { if [ -e "$TOMCAT_PACKAGE" ]; then tar zxvf "$TOMCAT_PACKAGE" &> /dev/null cp -r $(basename "$TOMCAT_PACKAGE" .tar.gz) "$TOMCAT_INSTALL_PATH" useradd -s /sbin/nologin "$TOMCAT_USER" chown "$TOMCAT_USER":"$TOMCAT_GROUP" "$TOMCAT_INSTALL_PATH" -R cat > /usr/lib/systemd/system/tomcat.service <<EOF [Unit] Description=Tomcat After=syslog.target network.target [Service] Type=forking ExecStart=$TOMCAT_INSTALL_PATH/bin/startup.sh ExecStop=$TOMCAT_INSTALL_PATH/bin/shutdown.sh RestartSec=3 PrivateTmp=true User=$TOMCAT_USER Group=$TOMCAT_GROUP [Install] WantedBy=multi-user.target EOF systemctl daemon-reload systemctl start tomcat if systemctl status tomcat &> /dev/null; then echo -e "E[1;32m Tomcat 启动成功 E[0m" else echo -e "E[1;31m Tomcat 启动失败 E[0m" fi else echo "无 Tomcat 安装包" fi } # Main script execution install_jdk setup_environment java -version install_tomcat # Create symbolic links for Tomcat binary files ln -s $TOMCAT_INSTALL_PATH/bin/* /usr/bin # 检查 JDK 版本 echo -e "E[1;36m 检查 JDK 版本: E[0m" java -version # 检查 Tomcat 版本 echo -e "E[1;36m 检查 Tomcat 版本: E[0m" cat $TOMCAT_INSTALL_PATH/RELEASE-NOTES | grep "Apache Tomcat Version" # 获取本机 IP 地址 IP_ADDRESS=$(hostname -I | awk '{print $1}') # 将 IP 地址写入到 index.jsp 文件 echo $IP_ADDRESS > /usr/local/tomcat/webapps/ROOT/index.jsp echo "IP 地址已写入到 /usr/local/tomcat/webapps/ROOT/index.jsp 文件中"
192.168.10.40
192.168.10.50
结果验证:
实操Nginx+Tomcat多实例部署,实现负载均衡和动静分离
weixin_521429612024-07-02 15:26
相关推荐
苹果醋316 分钟前
React源码02 - 基础知识 React API 一览群联云防护小杜3 小时前
如何给负载均衡平台做好安全防御codeMaster__hyd6 小时前
CentOS7系统下部署tomcat,浏览器访问localhost:8080/ljh5746491197 小时前
负载均衡的原理阿松哥哥20189 小时前
linux环境使用源码方式安装nginx(centos)与君共勉1213813 小时前
Nginx 负载均衡的实现Monly2114 小时前
Java(若依):修改Tomcat的版本Ttang2314 小时前
Tomcat原理(6)——tomcat完整实现okok__TXF14 小时前
Nginx + Lua脚本打配合青灯文案114 小时前
前端 HTTP 请求由 Nginx 反向代理和 API 网关到后端服务的流程