第四周 周二
早
反向代理
安装
nginx 1.26.1
平滑升级
负载均衡
1
、
nginx
反向代理配置
反向代理:⽤户直接访问反向代理服务器就可以获得⽬标服务器 (后端服务器)的资源。
前端服务器配置:(接收和响应客户端,代理另外一台主机)
[root@git ~]
# yum -y install gcc gcc-g++ openssl-devel pcre-devel
[root@git ~]
# ls
nginx-1.26.1.tar.gz
[root@git ~]
# tar -zxvf nginx-1.26.1.tar.gz
[root@git ~]
# ls
nginx-1.26.1 nginx-1.26.1.tar.gz
[root@git ~]
# cd nginx-1.26.1
[root@git nginx-1.26.1]
# ./configure --prefix=/usr/local/nginx --user=nginx -
-group=nginx --with-http_ssl_module --with-http_stub_status_module --with
http_realip_module --with-stream
[root@web1 ~]
# make && make install
[root@web1 nginx-1.26.1]
# useradd -s /bin/nologin -M nginx
[root@web1 ~]
# /usr/local/nginx/sbin/nginx
[root@web1 ~]
# firewall-cmd --zone=public --add-port=80/tcp --permanent
[root@web1 ~]
# firewall-cmd --reload
[root@web1 ~]
# netstat -lntup | grep nginx
tcp
0 0 0
.0.0.0:80
0
.0.0.0:* LISTEN
4402
/nginx: master
[root@web1 ~]
# vim /usr/local/nginx/conf/nginx.conf
添加监控模块(修改配置文件)
[root@sla nginx]
# vim /usr/local/nginx/conf/nginx.conf //
在
location
模块下面添
加新模块
status
location / {
root html;
index index.html index.htm;
}
location /status {
stub_status on;
access_log off;
}
[root@web1 ~]
# /usr/local/nginx/sbin/nginx -s reload
动态(后端)服务器配置:
修改
index.html
文件,并且发布
webfuwu
[root@web2 ~]
# echo "this is java web server" >
/usr/local/nginx/html/index.html
[root@web2 ~]
# /usr/local/nginx/sbin/nginx
[root@web1 ~]
# echo "this is static server" >
/usr/local/nginx/html/index.html
[root@web1 ~]
# /usr/local/nginx/sbin/nginx
[root@web1 ~]
# ps -aux | grep nginx //
查看现存进程信息
root
1331 0
.0
0
.2
46128 1160
? Ss
10
:16
0
:00 nginx:
master process /usr/local/nginx/sbin/nginx
nginx
1332 0
.0
0
.3
46580 1904
? S
10
:16
0
:00 nginx:
worker process
root
1338 0
.0
0
.2
112824 976
pts/0 R
+
10
:17
0
:00
grep
--
color
=
auto nginx
[root@web1 ~]
# curl localhost //
访问本机(
web1
)
this is static server
[root@web1 ~]
# curl 10.0.0.201 //
访问
web2
this is java web server
反向代理效果:当访问
200
主机(
web1
),(
nginx
反向代理
201
主机(
web2
)的服务器)返回
201
(
web2
)主机的页面。
在配置
⽂
件中添加
⼀⾏
反向代理块指令(
proxy_pass
),表示当访问本机地址
10
.0.0.200
的
80
端
⼝
时即可跳转到后端服务器
10
.0.0.201
的
80
端
⼝
上。
[root@web1 ~]
# vim /usr/local/nginx/conf/nginx.conf
location / {
# root html;
# index index.html index.htm;
proxy_pass http://10.0.0.201:80;
}
[root@web1 ~]
# /usr/local/nginx/sbin/nginx -s reload
代理百度
location / {
# root html;
# index index.html index.htm;
proxy_pass http://www.baidu.com:80;
}
nginx
代理其他服务器的时候,不需要对方同意,更加方便了模块化操作。
2
、代理优化(
1
)简单轮询
[root@web1 ~]
# vim /usr/local/nginx/conf/nginx.conf
http {
include mime.types;
default_type application/octet-stream;
upstream backend_servers {
server
10
.0.0.201:80;
server
10
.0.0.202:80;
}
location / {
# root html;
# index index.html index.htm;
proxy_pass http://backend_servers;
}
[root@web1 ~]
# /usr/local/nginx/sbin/nginx -s reload
3
、代理优化(
1
)
nginx
访客
IP
⿊名单
作为运维⼈员,我们可以选择允许哪些⽤户
IP
来访问我们的服务器,也可以选择允许哪个⽹段的⽤
户。
allow
:允许
deny
:拒绝
在
nginx
配置⽂件的
server
模块内可以添加下⾯的内容。 当访问被拒绝时,会显示
403
错误⻚
⾯。
202
(
web3
)设置除开
201
(
web2
)可以访问,其他主机都不可访问
[root@web3 ~]
# vim /usr/local/nginx/conf/nginx.conf
server {
listen
80
;
server_name localhost;
charset utf-8;
allow
10
.0.0.201; //
允许
10.0.0.201
⽤
户访问
deny
10
.0.0.0/24; //
拒绝
10.0.0
⽹
段的
⽤
户访问
deny all; //
拒绝所有
[root@web3 ~]
# /usr/local/nginx/sbin/nginx -s reload
[root@web1 ~]
# curl http://10.0.0.202
<html>
<head><title>403 Forbidden</title></head>
<body>
<center><h1>403 Forbidden</h1></center>
<hr><center>nginx/1.26.1</center>
</body>
</html>
[root@web2 ~]
# curl http://10.0.0.202
this is python web server
4
、
nginx
日志查看与分析
[root@web3 ~]
# cat /usr/local/nginx/logs/access.log
10
.0.0.201
- -
[30/Jul/2024:11:27:42
+
0800
]
"GET / HTTP/1.1"
200 26
"-"
"curl/7.29.0"
10
.0.0.200
- -
[30/Jul/2024:11:27:46
+
0800
]
"GET / HTTP/1.1"
403 153
"-"
"curl/7.29.0"
10
.0.0.200
- -
[30/Jul/2024:11:37:18
+
0800
]
"GET / HTTP/1.0"
403 555
"-"
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like
Gecko) Chrome/127.0.0.0 Safari/537.36 Edg/127.0.0.0"
访问来源
:
10.0.0.201
、
10.0.0.200
访问时间
:
2024
年
7
月
30
日
11
时
27
分
42
秒
2024
年
7
月
30
日
11
时
27
分
46
秒
2024
年
7
月
30
日
11
时
37
分
18
秒
访问方式和协议
:
GET
方法
HTTP/1.1
协议和
HTTP/1.0
协议
访问结果
:
200
状态码,表示请求成功,返回了
26
字节的数据。
403
状态码,表示禁止访问,分别返回了
153
字节和
555
字节的数据。
用户代理
:
curl/7.29.0
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like
Gecko) Chrome/127.0.0.0 Safari/537.36 Edg/127.0.0.0
[root@web3 ~]
# cat /usr/local/nginx/logs/error.log
2024
/07/30
11
:27:46 [error]
1750
#0: *6 access forbidden by rule, client:
10.0.0.200, server: localhost, request: "GET / HTTP/1.1", host: "10.0.0.202"
2024
/07/30
11
:37:23 [error]
1756
#0: *8 access forbidden by rule, client:
10.0.0.200, server: localhost, request: "GET / HTTP/1.0", host:
"backend_servers"
这段错误日志表明了以下情况:
在
2024
年
7
月
30
日
11
时
27
分
46
秒和
11
时
37
分
23
秒分别发生了两次访问被禁止的错误。
对于这两次错误,原因都是
“access forbidden by rule”
(被规则禁止访问)。
客户端的
IP
均为
10.0.0.200
,服务器名称为
“
localhost
”
。
请求方式分别为
“GET / HTTP/1.1”
和
“GET / HTTP/1.0”
。
请求的主机分别为
“10.0.0.202”
和
“backend_servers”
。
下午
nginx
默认情况下同一个文件只允许
1024
人访问
1
、代理优化(
2
)负载均衡
四层负载均衡使用
stream
模块,与七层的
http
模块同级。编译安装时需要加
--with-http_stub_
status_module
模块。
早期的网站流量和业务功能都比较简单,单台服务器足以满足基本的需求, 但是随着互联网的发
展,业务流量越来越大并且业务逻辑也跟着越来越复杂,单台服务器的性能及单点故障问题就凸显出来
了,因此需要多台服务器进行性能的水平扩展及避免单点故障出现。
负载均衡是将负载分摊到不同的服务单元,既保证服务的可用性,又保证响应足够快,给用户很好
的体验,快速增长的访问量和数据流量催生了各式各样的负载均衡的产品,很多专业的的负载均衡硬件
提供了很好的功能,但价格不菲,这使得负载均衡软件大受欢迎,
nginx
就是其中一个,在
linux
下有
nginx
、
Ivs
、
haproxy
等服务,可以提供复杂均衡服务。
(
1
)作用
解决服务器的高并发压力,提高应用程序的处理性能;
提供故障转移,实现高可用;
通过添加或减少服务器数量,增强网站的可扩展性;
在负载均衡器上进行过滤,可以提高系统的安全性;
1
、提高系统性能
负载均衡可以扩展网络设备和服务器的带宽,优化访问请求在服务器组之间的分配,提高系统的反
应速度和总体性能。
2
、监控服务器的运行状态
负载均衡能够监控服务器的运行状态,提高整个服务器组的可靠性。
3
、提供服务一致性
负载均衡器具有提供服务一致性的功能,负载均衡器通过读取客户端所发出 请求内的信息,进行重
写报头程序然后将请求发送至合适的服务器上,该服务器会维护着该客户端信息。在
http
通信当中,负
载均衡器提供服务一致性的功能就得到了很好的发挥,但提供该服务的途径并不是非常安全。但若将消
息加密后,负载均衡器就无法读取隐藏其中的信息了。
4
、摆脱停机时间
服务器托管公司可能会在维护期间将服务器关闭一段时间,这可能发生在业 务的高峰期。在基于云
服务器中,可以在将流量引导到另一台服务器的资源之后进行维护,前提是它们不在维护中,从而可以
消除网站的停机时间。
5
、管理服务器故障
由于它具有根据需要添加或删除实例的功能,因此可以跨云平台拥有多个数据中心。如果其中一台
服务器发生故障,则可以快速移动流量,将故障服务 器的流量流入到另一台服务器中。
6
、转发功能
按照一定的算法,将客户端请求转发到不同应用服务器上,减轻单个服务器 压力,提高系统并发
量。
7
、恢复添加
如检测到发生故障的应用服务器恢复工作,自动将其添加到处理用户请求队 伍中。
8
、分发流量
分发流量、请求到不同的服务器。使流量平均分配,提高整个集群的响应速 度、服务的高可用性。
(
2
)策略

(
3
)配置
环境准备:
[root@server ~]
# echo "i am static server" > /usr/local/nginx/html/index.html
[root@001 ~]
# echo "i am dynamic server 001" >
/usr/local/nginx/html/index.html
[root@002 ~]
# echo "i am dynamic server 002" >
/usr/local/nginx/html/index.html
[root@003 ~]
# echo "i am dynamic server 003" >
/usr/local/nginx/html/index.html
[root@server ~]
#/usr/local/nginx/sbin/nginx
[root@001 ~]
# /usr/local/nginx/sbin/nginx
[root@002 ~]
# /usr/local/nginx/sbin/nginx
[root@003 ~]
# /usr/local/nginx/sbin/nginx
1
、轮询:
[root@server ~]
# vim /usr/local/nginx/conf/nginx.conf
upstream server_group_name { //
配置
server_group_name
服务器组
server
10
.0.0.20:80;
server
10
.0.0.30:80;
server
10
.0.0.40:80;
}
server {
listen
80
;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
# root html;
# index index.html index.htm;
proxy_pass http://server_group_name; //
当请求访问到本机的默认路
径时,将请求转发到
server_group_name
组
}
......
}
[root@server ~]
# /usr/local/nginx/sbin/nginx -s reload
2
、权重:
//
权重默认为
1
,谁权重大,谁优先处理请求
.
[root@server ~]
# vim /usr/local/nginx/conf/nginx.conf
server
10
.0.0.20:80
weight
=
4
;
server
10
.0.0.30:80
weight
=
2
;
server
10
.0.0.40:80
weight
=
1
;
[root@server ~]
# /usr/local/nginx/sbin/nginx -s reload
3
、
ip_hash:
当对后端的多台动态应用服务器做负载均衡时,
ip_hash
指令能够将某个客户端
IP
的请求通过哈希算法
定位到同一台后端服务器上。
这样,当来自某一个
IP
的用户在后端
Web
服务器
A
上登录后,再访问该站点的其他
URL
,能保证其访问的
还是后端
web
服务器
A
。
注意
:
使用
ip_hash
指令无法保证后端服务器的负载均衡,可能导致有些后端服务器接收到的请求多,
有些后端服务器接受的请求少,而且设置后端服务器权重等方法将不起作用
.
[root@server ~]
# vim /usr/local/nginx/conf/nginx.conf
ip_hash;
server
10
.0.0.20:80
weight
=
4
;
server
10
.0.0.30:80
weight
=
2
;
server
10
.0.0.40:80
weight
=
1
;
[root@server ~]
# /usr/local/nginx/sbin/nginx -s reload
4
、
laest_conn:
least_conn
:最少连接,把请求转发给连接数较少的后端服务器。轮询算法是把请求平均地转发给各个
后端,使它们的负载大致相同;
但是,有些请求占用的时间很长,会导致其所在的后端负载较高。这种情况下,
least_conn
这种方式就
可以达到更好的负载均衡效果。
[root@server ~]
# vim /usr/local/nginx/conf/nginx.conf
least_conn;
server
10
.0.0.20:80
weight
=
4
;
server
10
.0.0.30:80
weight
=
2
;
server
10
.0.0.40:80
weight
=
1
;
[root@server ~]
# /usr/local/nginx/sbin/nginx -s reload
5
、
url_hash:
按访问
url
的
hash
结果来分配请求,使每个
url
定向到同一个后端服务器,要配合缓存命中来使用。同一
个资源多次请求,可能会到达不同的服务器上,导致不必要的多次下载,缓存命中率不高,以及一些资源
时间的浪费。而使用
ur_hash
,可以使得同一个
url (
也就是同一个资源请求
)
会到达同一台服务器,一
旦缓存住了资源,再次收到请求,就可以从缓存中读取。
[root@server ~]
# vim /usr/local/nginx/conf/nginx.conf
hash
$request_url
;
server
10
.0.0.20:80
weight
=
4
;
server
10
.0.0.30:80
weight
=
2
;
server
10
.0.0.40:80
weight
=
1
;
[root@server ~]
# /usr/local/nginx/sbin/nginx -s reload
(
4
)状态
在服务器组的组内服务器后填写该服务器的状态

[root@server ~]
# vim /usr/local/nginx/conf/nginx.conf
server
10
.0.0.30:80 down;
[root@server ~]
# /usr/local/nginx/sbin/nginx -s reload
2
、
nginx
版本平滑升级
(
1
)原理
1
、启动后完成配置加载和端⼝绑定等动作, 分离出指定数量的⼯作⼦进程 ,这些⼦进程会持有监
听端⼝的⽂件描述符
(fd)
,并通过在该描述符上添加监听事件来接受连接。
2
、
Nginx
主进程在启动完成后会进⼊等待状态,负责响应各类系 统消息,如
SIGCHLD
、
SIGHUPSIGUSR2
等。
3
、主进程⽀持的信号
TERM
、
INT
:⽴刻退出
QUIT
:等待⼯作进程结束后再退出
KILL
:强制终⽌进程
HUP
:重新加载配置⽂件,使⽤新的配置启动⼯作进程,并逐步关闭旧进程
USR1
:重新⽣成⽇志⽂件
USR2
:启动新的主进程,实现热升级
WINCH
:逐步关闭⼯作进程及⼯作进程⽀持的信号
(
2
)过程
1
、查看旧版
nginx
的编译参数
;
2
、编译新版本
Nginx
源码包,安装路径需与旧版⼀致,注意
:
不要执⾏
make install;
3
、备份⼆进制可执⾏⽂件,⽤新版本的替换
;
4
、确保配置⽂件⽆报错
;
5
、发送
USR2
信号:向主进程
(master)
发送
USR2
信号,
Nginx
会启动⼀个新版本的
master
进程和
对应⼯作进程,和旧版⼀起处理请求
;
6
、发送
WINCH
信号:向旧的
Nginx
主进程
(master)
发送
WINCH
信号,它会逐步关闭⾃⼰的⼯作进
程
(
主进程不退出
)
,这时所有请求都会由新版
Nginx
处理
7
、发送
QUIT
信号
:
升级完毕,可向旧的
Nginx
主进程
(master)
发送
(QUIT
、
TERM
、或者
KILL)
信
号,使旧的主进程退出
;
8
、验证
nginx
版本号,并访问测试
.
(
3
)配置
[root@server ~]
# /usr/local/nginx/sbin/nginx -v //
查看
nginx
当前的版本
nginx version: nginx/1.26.1
[root@server ~]
# kill -l //
了解
kill
1
) SIGHUP
2
) SIGINT
3
) SIGQUIT
4
) SIGILL
5
) SIGTRAP
6
) SIGABRT
7
) SIGBUS
8
) SIGFPE
9
) SIGKILL
10
) SIGUSR1
11
) SIGSEGV
12
) SIGUSR2
13
) SIGPIPE
14
) SIGALRM
15
) SIGTERM
16
) SIGSTKFLT
17
) SIGCHLD
18
) SIGCONT
19
) SIGSTOP
20
) SIGTSTP
21
) SIGTTIN
22
) SIGTTOU
23
) SIGURG
24
) SIGXCPU
25
) SIGXFSZ
26
) SIGVTALRM
27
) SIGPROF
28
) SIGWINCH
29
) SIGIO
30
) SIGPWR
31
) SIGSYS
34
) SIGRTMIN
35
) SIGRTMIN
+
1 36
) SIGRTMIN
+
2 37
) SIGRTMIN
+
3
38
) SIGRTMIN
+
4 39
) SIGRTMIN
+
5 40
) SIGRTMIN
+
6 41
) SIGRTMIN
+
7 42
)
SIGRTMIN
+
8
43
) SIGRTMIN
+
9 44
) SIGRTMIN
+
10 45
) SIGRTMIN
+
11 46
) SIGRTMIN
+
12 47
)
SIGRTMIN
+
13
48
) SIGRTMIN
+
14 49
) SIGRTMIN
+
15 50
) SIGRTMAX-14
51
) SIGRTMAX-13
52
) SIGRTMAX-
12
53
) SIGRTMAX-11
54
) SIGRTMAX-10
55
) SIGRTMAX-9
56
) SIGRTMAX-8
57
) SIGRTMAX-
7
58
) SIGRTMAX-6
59
) SIGRTMAX-5
60
) SIGRTMAX-4
61
) SIGRTMAX-3
62
) SIGRTMAX-
2
63
) SIGRTMAX-1
64
) SIGRTMAX
[root@server ~]
# ps -aux | grep nginx //
查看进程
root
1336 0
.0
0
.5
48360 2476
? Ss
15
:03
0
:00 nginx:
master process /usr/local/nginx/sbin/nginx
nginx
1419 0
.0
0
.4
48804 2324
? S
15
:45
0
:00 nginx:
worker process
root
1442 0
.0
0
.2
112824 980
pts/0 R
+
16
:20
0
:00
grep
--
color
=
auto nginx
[root@server ~]
# wget https://nginx.org/download/nginx-1.27.0.tar.gz
[root@server ~]
# tar -zxvf nginx-1.27.0.tar.gz
[root@server ~]
# cd nginx-1.27.0/
[root@server nginx-1.27.0]
# ./configure --prefix=/usr/local/nginx/ --
user=nginx --group=nginx --with-http_ssl_module --with
http_stub_status_module --with-http_realip_module --with-stream //
注意安装
目录一定与旧
nginx
目录一样
[root@server nginx-1.27.0]
# make && make install
[root@server nginx-1.27.0]
# ls /usr/local/nginx/sbin/
nginx nginx.old
[root@server nginx-1.27.0]
# /usr/local/nginx/sbin/nginx -v //
查看新
nginx
版
本号
-V
查看
nginx
版本信息和安装的模块
nginx version: nginx/1.27.0
[root@server nginx-1.27.0]
# /usr/local/nginx/sbin/nginx.old -v //
查询旧
nginx
版本号
nginx version: nginx/1.26.1
[root@server nginx-1.27.0]
# ps -aux | grep nginx //
查询当前运
⾏
的
nginx
的
pid
号
root
1336 0
.0
0
.5
48360 2476
? Ss
15
:03
0
:00 nginx:
master process /usr/local/nginx/sbin/nginx
nginx
1419 0
.0
0
.4
48804 2324
? S
15
:45
0
:00 nginx:
worker process
root
4434 0
.0
0
.2
112824 980
pts/0 R
+
16
:33
0
:00
grep
--
color
=
auto nginx
虽然主程序完成了升级,但此时正在
⼯
作的
nginx
进程并未完成升级,依旧是
1.26.1
⽼
版本的
nginx
在运
⾏
,所以这
⾥
要向
⽼
版本
nginx
进程发送信号。
[root@server nginx-1.27.0]
# kill -USR2 1336 //
发送
USR2
信号:向
⽼
版本的主进程发
送该信号,
nginx
会启动新版本的进程与
⽼
版本进程
⼀
起处理请求
[root@server nginx-1.27.0]
# ps -aux | grep nginx //
看到
⽼
版本与新版本
nginx
的
主进程和
⼯
作进程都在启动中
root
1336 0
.0
0
.5
48360 2476
? Ss
15
:03
0
:00 nginx:
master process /usr/local/nginx/sbin/nginx
nginx
1419 0
.0
0
.4
48804 2324
? S
15
:45
0
:00 nginx:
worker process
root
4435 0
.0
0
.6
46128 3340
? S
16
:37
0
:00 nginx:
master process /usr/local/nginx/sbin/nginx
nginx
4436 0
.0
0
.3
46584 1904
? S
16
:37
0
:00 nginx:
worker process
root
4438 0
.0
0
.2
112824 976
pts/0 R
+
16
:37
0
:00
grep
--
color
=
auto nginx
[root@server nginx-1.27.0]
# kill -WINCH 1419 //
发送
WINCH
信号:向
⽼
版本主进程发送
该信号,它会逐步关闭
⾃⼰
的
⼯
作进程(主进程不
会退出),此时的处理请求全部交与新版本的
nginx
处理
[root@server nginx-1.27.0]
# ps -aux | grep nginx
root
1336 0
.0
0
.5
48360 2476
? Ss
15
:03
0
:00 nginx:
master process /usr/local/nginx/sbin/nginx
root
4435 0
.0
0
.6
46128 3340
? S
16
:37
0
:00 nginx:
master process /usr/local/nginx/sbin/nginx
nginx
4436 0
.0
0
.3
46584 1904
? S
16
:37
0
:00 nginx:
worker process
nginx
4440 0
.0
0
.4
48804 2076
? S
16
:39
0
:00 nginx:
worker process
root
4442 0
.0
0
.2
112824 980
pts/0 R
+
16
:39
0
:00
grep
--
color
=
auto nginx
[root@server nginx-1.27.0]
# kill -QUIT 1336 //
发送
QUIT
信号:向
⽼
版本的主进程发
送该信号,让旧版本退出
[root@server nginx-1.27.0]
# ps -aux | grep nginx
root
4435 0
.0
0
.6
46128 3340
? S
16
:37
0
:00 nginx:
master process /usr/local/nginx/sbin/nginx
nginx
4436 0
.0
0
.3
46584 1904
? S
16
:37
0
:00 nginx:
worker process
root
4444 0
.0
0
.2
112824 980
pts/0 R
+
16
:40
0
:00
grep
--
color
=
auto nginx
[root@server nginx-1.27.0]
# curl -I localhost //
向本地主机(
localhost
)发送一
个
HTTP
请求头信息获取请求
,
获取关于服务器响应的一些基本信息
HTTP/1.1
200
OK //
状态码,表示请求成功
Server: nginx/1.27.0 //
显示了服务器使用的软件和版本
Date: Tue,
30
Jul
2024 08
:40:51 GMT
Content-Type: text/html //
说明了响应内容的类型
Content-Length:
24
//
表示响应主体的长度
Connection: keep-alive
Last-Modified: Tue,
30
Jul
2024 07
:02:04 GMT
ETag:
"66a88fec-18"
Accept-Ranges: bytes
如果服务器出现问题或访问被禁止,可能会得到不同的状态码,比如
403
Forbidden
或
500
Internal Server Error
等,并伴随相应的错误信息。
3
、配置
tomcat 10
运行环境
(
tomcat9
可以在
jdk8
环境运行 ,
tomcat10
必须在
jdk17
以上的版本运行)
[root@server ~]
# ls
jdk-22_linux-x64_bin.tar.gz
[root@server ~]
# tar -zxf jdk-22_linux-x64_bin.tar.gz
[root@server ~]
# mv jdk-22.0.2/ /usr/local/jdk22
[root@server ~]
# cd /usr/local/jdk22/
[root@server jdk22]
# ls
bin conf include jmods legal lib LICENSE man README release
[root@server jdk22]
# sed -n '$p' /etc/profile
unset
-f
pathmunge
[root@server jdk22]
# sed -i '$a export JAVA_HOME=/usr/local/jdk22/'
/etc/profile
[root@server jdk22]
# sed -n '$p' /etc/profile
export
JAVA_HOME
=
/usr/local/jdk22/
[root@server jdk22]
# source /etc/profile
[root@server jdk22]
# $JAVA_HOME
-bash
: /usr/local/jdk22/:
是一个目录
[root@server jdk22]
# sed -i '$a PATH=$JAVA_HOME/bin:$PATH' /etc/profile
[root@server jdk22]
# sed -n '$p' /etc/profile
PATH
=
$JAVA_HOME
/bin:
$PATH
[root@server jdk22]
# source /etc/profile
[root@server jdk22]
# java -version
java version
"22.0.2"
2024
-07-16
Java(TM) SE Runtime Environment (build
22
.0.2
+
9
-70
)
Java HotSpot(TM)
64
-Bit
Server VM (build
22
.0.2
+
9
-70
, mixed mode, sharing)
下载
tomcat 10
软件包
[root@server ~]
# wget https://dlcdn.apache.org/tomcat/tomcat-
10/v10.1.26/bin/apache-tomcat-10.1.26.tar.gz