10 Nginx 构建动态网站架构 lnmt


安装 LNMT 架构

下载 tomcat

1
2
3
4
5
6
7
# CentOS7 修改主机名
[root@nginx-node2 ~]# hostnamectl set-hostname tomcat-node1
[root@nginx-node2 ~]# bash

# 下载tomcat
# wget https://www-us.apache.org/dist/tomcat/tomcat-9/v9.0.27/bin/apache-tomcat-9.0.27.tar.gz
# wget http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-9/v9.0.7/bin/apache-tomcat-9.0.7.tar.gz

安装 JDK

1
2
3
4
5
6
[root@tomcat-node1 code]# yum install java -y

[root@tomcat-node1 code]# java -version
openjdk version "1.8.0_232"
OpenJDK Runtime Environment (build 1.8.0_232-b09)
OpenJDK 64-Bit Server VM (build 25.232-b09, mixed mode)

安装 tomcat

1
2
3
4
[root@proxy tmp]# mkdir -p /soft/tools
[root@tomcat-node1 tools]# wget http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-9/v9.0.7/bin/apache-tomcat-9.0.7.tar.gz
[root@tomcat-node1 tools]# tar -zxvf apache-tomcat-9.0.27.tar.gz -C /soft
[root@tomcat-node1 soft]# cp -r apache-tomcat-9.0.27/ tomcat-8080

解决 CentOS7 启动tomcat慢

1
2
yum install rng-tools 
systemctl start rngd

启动 tomcat

1
2
3
4
[root@tomcat-node1 bin]# cd /soft/tomcat-8080/bin/
[root@tomcat-node1 bin]# sh startup.sh

[root@tomcat-node1 bin]# netstat -tnlp

配置 Nginx proxy 负载均衡

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[root@proxy conf.d]# vim jsp.conf 

upstream jsp_pool {
server 172.17.70.228:8080;
}

server {
listen 80;
server_name 60.205.217.112;

location / {
proxy_pass http://jsp_pool;
include proxy_params;
}

}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@proxy conf.d]# cat /etc/nginx/proxy_params
proxy_redirect default;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_connect_timeout 60;
proxy_send_timeout 60;
proxy_read_timeout 60;

proxy_buffer_size 32k;
proxy_buffering on;
proxy_buffers 4 128k;
proxy_busy_buffers_size 256k;
proxy_max_temp_file_size 256k;
1
2
[root@proxy conf.d]# nginx -t
[root@proxy conf.d]# nginx -s reload

JVM故障排查思路