Nginx简介
Nginx是一款轻量级的Web 服务器/反向代理服务器
占有内存少,并发能力强
官方测试nginx能够支撑5万并发链接,并且CPU、内存等资源消耗却非常低,运行非常稳定。
Tengine淘宝基于Nginx研发的web服务器
Nginx:对请求进行分配
tomcat:是服务器
高并发场景
负载均衡(load Balance ):将请求/数据【均匀】分摊到多个操作单元上执行,负载均衡的关键在于【均匀】
代理其实就是一个中介,A和B本来可以直连,中间插入一个C,C就是中介。
正向代理:代理人明确买家的目标是谁,代理人帮我们去联系目标
反向代理:客户只需要发送请求到代理服务器,代理服务器会将请求转发给内部的服务器去处理,处理完毕之
后会将结果返回给客户
但整个过程中客户和实际处理服务器是不会直接建立连接的
虽然正向代理服务器和反向代理服务器所处的位置都是客户端和真实服务器之间,所做的事情也都是把客户端的请求转发给服务器,再把服务器的响应转发给客户端,但是二者之间还是有一定的差异的。
1、正向代理其实是客户端的代理,帮助客户端访问其无法访问的服务器资源。反向代理则是服务器的代理,帮助服务器做负载均衡,安全防护等。
2、正向代理一般是客户端架设的,比如在自己的机器上安装一个代理软件。而反向代理一般是服务器架设的,比如在自己的机器集群中部署一个反向代理服务器。
3、正向代理中,服务器不知道真正的客户端到底是谁,以为访问自己的就是真实的客户端。而在反向代理中,客户端不知道真正的服务器是谁,以为自己访问的就是真实的服务器。
4、正向代理和反向代理的作用和目的不同。正向代理主要是用来解决访问限制问题。而反向代理则是提供负载均衡、安全防护等作用。二者均能提高访问速度
Nginx源码安装
[root@basiscs ~]# rm -rf * (删除无关文件)
[root@basiscs ~]# rz (上传安装包)
[root@basiscs ~]# tar -zxf nginx-1.8.1.tar.gz (解压文件)
[root@basiscs ~]# rm -rf nginx-1.8.1.tar.gz (删除安装包)
[root@basiscs ~]# yum install gcc pcre-devel zlib-devel openssl-devel -y(需要安装nginx依赖的软件,因为Nginx是源码)
[root@basiscs ~]# cd nginx-1.8.1
[root@basiscs nginx-1.8.1]# ll
-rwxr-xr-x 1 1001 aaa 2478 Jan 26 2016 configure
[root@basiscs nginx-1.8.1]# vim configure (配置文件)
[root@basiscs nginx-1.8.1]# ./configure --prefix=/opt/nginx (配置安装路径,不是安装)
[root@basiscs nginx-1.8.1]# make && make install (开始编译并安装nginx)
开启Ngxi
[root@basiscs nginx-1.8.1]# cd /opt/nginx/sbin (cd到nginx的命令和脚本库)
[root@basiscs sbin]# ./nginx (启动nginx)
输入192.168.111.100:80(ip地址就行,端口号默认80)
export JAVA_HOME=/usr/java/jdk1.8.0_231-amd64
export NGINX_HOME=/opt/nginx
export TOMCAT_HOME=/opt/apache-tomcat-8.5.47
export PATH=$JAVA_HOME:$TOMCAT_HOME/bin:$PATH
export PATH=$NGINX_HOME/sbin:$PATH
~
常用命令
[root@basiscs ~]# cd /opt/nginx/sbin
[root@basiscs sbin]# ./nginx (启动nginx)
[root@basiscs sbin]# cd
[root@basiscs ~]# cat /opt/nginx/logs/nginx.pid (进程号,id号)
14876
[root@basiscs ~]# ps -ef | grep 14876
root 14876 1 0 20:33 ? 00:00:00 nginx: master process ./nginx
nobody 14877 14876 0 20:33 ? 00:00:00 nginx: worker process
root 14964 14750 0 20:34 pts/0 00:00:00 grep --color=auto 14876 (执行进程命令都会显示)
[root@basiscs ~]# vim /etc/profile
第一种
export JAVA_HOME=/usr/java/jdk1.8.0_231-amd64
export NGINX_HOME=/opt/nginx
export TOMCAT_HOME=/opt/apache-tomcat-8.5.47
export PATH=$JAVA_HOME:$TOMCAT_HOME/bin:$PATH
export PATH=$NGINX_HOME/sbin:$PATH
第二种
export JAVA_HOME=/usr/java/jdk1.8.0_231-amd64
export NGINX_HOME=/opt/nginx
export TOMCAT_HOME=/opt/apache-tomcat-8.5.47
export PATH=$JAVA_HOME:$TOMCAT_HOME/bin:$NGINX_HOME/sbin:$PATH
[root@basiscs ~]# source /etc/profile
[root@basiscs ~]# nginx -t(检查配置是否成功)
nginx: the configuration file /opt/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /opt/nginx/conf/nginx.conf test is successful
[root@basiscs sbin]# nginx -s quit
关闭nginx:
nginx -s stop :快速停止nginx
quit :完整有序的停止nginx
[root@basiscs ~]# nginx (启动nginx)
[root@basiscs ~]# ps -ef | grep nginx
root 16774 1 0 21:04 ? 00:00:00 nginx: master process nginx
nobody 16775 16774 0 21:04 ? 00:00:00 nginx: worker process
root 16799 14750 0 21:05 pts/0 00:00:00 grep --color=auto nginx
[root@basiscs ~]# cat /opt/nginx/logs/nginx.pid
16774
[root@basiscs ~]# cat /opt/nginx/logs/
cat: /opt/nginx/logs/: Is a directory
kill `cat /opt/nginx/logs/nginx.pid` (安装目录,关闭nginx服务)
nginx -s reload :修改配置后重新加载生效
nginx -s reopen :重新打开日志文件
安装目录
conf配置文件
html静态资源文件
sbin可执行文件
logs日志文件
配置文件
[root@basiscs ~]# cd /opt/nginx/
[root@basiscs nginx]# ls -sarln conf
4 -rw-r--r-- 1 0 0 2656 Mar 17 19:45 nginx.conf.default
4 -rw-r--r-- 1 0 0 2656 Mar 17 19:45 nginx.conf
...
[root@basiscs nginx]# ls -sarln logs/ (显示日志信息)
total 12
4 -rw-r--r-- 1 0 0 6 Mar 17 21:04 nginx.pid
4 -rw-r--r-- 1 0 0 832 Mar 17 20:58 error.log
4 -rw-r--r-- 1 0 0 3472 Mar 17 21:04 access.log
[root@basiscs nginx]# cat conf/nginx.conf
Nginx负载均衡
集群搭建
节点分布
basiscs 上安装 Nginx Tomcat JDK
node1和node2安装 Tomcat JDK
节点\角色
(100)basiscs Nginx Tomcat JDK
(98)node1 无 Tomcat JDK
(99)node2 无 Tomcat JDK
basiscs
[root@basiscs opt]# cd nginx
[root@basiscs nginx]# cd conf/
[root@basiscs conf]# ll
-rw-r--r-- 1 root root 2656 Mar 17 19:45 nginx.conf
[root@basiscs conf]# vim nginx.conf (修改配置)
删除所有内容,粘贴下面内容
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 0;
upstream joffee {
server 192.168.111.100:8080;
server 192.168.111.99:8080;
server 192.168.111.998:8080;
}
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://joffee;
}
}
}
[root@basiscs conf]# vi /opt/apache-tomcat-8.5.47/webapps/ROOT/index.jsp (修改tomcat展示页面)
删除所有内容,粘贴下面内容
<%@ page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>joffee集群</title>
<link href="favicon.ico" rel="icon" type="image/x-icon" />
<link href="favicon.ico" rel="shortcut icon" type="image/x-icon"/>
</head>
<body>
<h1>welcome to joffee集群</h1>
<h2>Server:<%=request.getLocalAddr() %></h2>
<h2>Port:<%=request.getLocalPort() %></h2>
<h2>Client:<%=request.getRemoteAddr() %></h2>
<h2>Session:<%=session.getId() %></h2>
<hr/>
<img src="/static/img/qbl.jpg" height="200px" />
</body>
</html>
[root@basiscs conf]# scp /opt/apache-tomcat-8.5.47/webapps/ROOT/index.jsp 192.168.111.99:/opt/apache-tomcat-8.5.47/webapps/ROOT/ (复制到192.168.111.99:/opt/...目录下)
[root@basiscs conf]# scp /opt/apache-tomcat-8.5.47/webapps/ROOT/index.jsp 192.168.111.98:/opt/apache-tomcat-8.5.47/webapps/ROOT/ (复制到192.168.111.98:/opt/...目录下)
[root@basiscs conf]# cd /opt/apache-tomcat-8.5.47/bin/
[root@basiscs bin]# ll
-rwxrwxrwx 1 root root 1904 Oct 7 2019 startup.sh
[root@basiscs bin]# chmod 777 startup.sh(使用撰写工具)
[root@basiscs bin]# ./startup.sh (启动tomcat)
[root@basiscs logs]# nginx(启动nginx,访问Nginx,会依次将Tomcat页面显示到页面)
[root@basiscs logs]# nginx -s reload (重新加载nginx)
[root@basiscs bin]# cd ..
[root@basiscs apache-tomcat-8.5.47]# ll
drwxr-x--- 2 root root 4096 Mar 18 19:40 logs
[root@basiscs apache-tomcat-8.5.47]# cd logs
[root@basiscs apache-tomcat-8.5.47]# cd logs
[root@basiscs logs]# ll
-rw-r----- 1 root root 53054 Mar 18 19:40 catalina.out (保存着错误信息)
node2
[root@node2 opt]# yum install -y lrzsz
[root@node2 opt]# rm -rf * (删除该目录下所有文件)
[root@node2 opt]# rz (上传apache-tomcat-8.5.47.tar.gz)
[root@node2 opt]# tar -zxf apache-tomcat-8.5.47.tar.gz(解压)
[root@node2 opt]# ll
total 10028
drwxr-xr-x 9 root root 220 Mar 15 00:36 apache-tomcat-8.5.47
-rw-r--r-- 1 root root 10267082 Feb 28 16:26 apache-tomcat-8.5.47.tar.gz
[root@node2 opt]# rm -rf apache-tomcat-8.5.47.tar.gz(删除安装包)
[root@node2 opt]# rz(上传jdk-8u231-linux-x64.rpm包)
[root@node2 opt]# ll
total 174404
drwxr-xr-x 9 root root 220 Mar 15 00:36 apache-tomcat-8.5.47
-rw-r--r-- 1 root root 178589686 Feb 28 16:20 jdk-8u231-linux-x64.rpm
[root@node2 opt]# rpm -ivh jdk-8u231-linux-x64.rpm(安装jdk)
[root@node2 opt]# rm -rf jdk-8u231-linux-x64.rpm(删除安装包)
[root@node2 opt]# cd /opt/apache-tomcat-8.5.47/bin/
[root@node2 bin]# ll
[root@node2 bin]# chmod 777 startup.sh
[root@node2 bin]# ./startup.sh
Node1
1.安装tomcat
[root@node1 ~]# yum install -y lrzsz
[root@node1 ~]# ll
[root@node1 ~]# rm -rf *
[root@node1 ~]# rz (上传apache-tomcat-8.5.47.tar.gz)
[root@node1 ~]# tar -zxf apache-tomcat-8.5.47.tar.gz -C /opt/ (解压到指定的目录)
[root@node1 ~]# rm -rf apache-tomcat-8.5.47.tar.gz (删除安装包)
[root@node1 ~]# cd /opt/
[root@node1 opt]# ll
total 0
drwxr-xr-x 9 root root 220 Mar 15 00:39 apache-tomcat-8.5.47
drwxr-xr-x. 3 root root 32 Mar 10 10:52 bdp
[root@node1 opt]# rm -rf bdp
[root@node1 opt]# ll
total 0
drwxr-xr-x 9 root root 220 Mar 15 00:39 apache-tomcat-8.5.47
[root@node1 opt]# rz (上传jdk-8u231-linux-x64.rpm)
[root@node1 opt]# rpm -ivh jdk-8u231-linux-x64.rpm(安装jdk)
[root@node1 opt]# rm -rf jdk-8u231-linux-x64.rpm(删除安装包)
[root@node1 opt]# ll
total 0
drwxr-xr-x 9 root root 220 Mar 15 00:39 apache-tomcat-8.5.47
[root@node1 opt]# java -version(查看java版本)
java version "1.8.0_231"
Java(TM) SE Runtime Environment (build 1.8.0_231-b11)
[root@node1 bin]# chmod 777 startup.sh(赋予权限)
[root@node1 bin]# ./startup.sh (启动tomcat)
负载策略
请求轮询
依次转发给配置的服务器
增加权重
谁的权重越大,分发到的请求就越多
upstream joffee {
server 192.168.58.101:8080 weight=2;
server 192.168.58.103:8080 weight=1;
}
最少连接数
在连接负载最少的情况下,nginx会尽量避免将过多的请求分发给繁忙的应用程序服务器,而是将
新请求分发给不太繁忙的服务器,避免服务器过载
upstream joffee {
least_conn;
server 192.168.58.101:8080;
server 192.168.58.103:8080;
}
IpHash
确保来自同一客户端的请求将始终定向到同一台服务器,除非此服务器不可用
upstream joffee {
ip_hash;
server 192.168.58.101:8080;
server 192.168.58.103:8080;
}
Nginx资源静态化
图床
由外部服务器统一管理图片
配置静态资源
[root@basiscs logs]# cat /opt/nginx/conf/nginx.conf.default(查看conf默认配置)
[root@basiscs logs]# cd /opt/nginx/
[root@basiscs nginx]# cd conf/
[root@basiscs conf]# vim nginx.conf
[root@basiscs logs]# vi /opt/apache-tomcat-8.5.47/webapps/ROOT/index.jsp
<img src="/static/joffee.jpg" height="200px" />
[root@basiscs conf]# ssh 192.168.111.99 (连接另外一台linux)
[root@node2 ~]# vi /opt/apache-tomcat-8.5.47/webapps/ROOT/index.jsp
<img src="/static/joffee.jpg" height="200px" />
[root@node2 ~]# exit
[root@basiscs /]# ll cd /opt/nginx/html/
-rw-r--r-- 1 root root 537 Mar 17 19:45 50x.html
-rw-r--r-- 1 root root 612 Mar 17 19:45 index.html
[root@basiscs /]# mkdir -p /opt/nginx/html/static/ (创建图片位置文件夹)
[root@basiscs /]# cd -p /opt/nginx/html/static/
[root@basiscs /]# cd /opt/nginx/html/static/
[root@basiscs static]# rz (上传图片1.jpg)
[root@basiscs static]# ll
total 184
-rw-r--r-- 1 root root 187526 Mar 18 21:37 1.jpg
[root@basiscs static]# mv 1.jpg joffee.jpg (改名为joffee.jpg)
[root@basiscs static]# ll
total 184
-rw-r--r-- 1 root root 187526 Mar 18 21:37 joffee.jpg
[root@basiscs static]# vim /opt/nginx/conf/nginx.conf
location ^~ /static/ {
root html;
}
[root@basiscs static]# nginx -s reload (重新加载nginx)
/opt/apache-tomcat-8.5.47/webapps/ROOT/index.jsp
<%@ page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>joffee集群</title>
<link href="favicon.ico" rel="icon" type="image/x-icon" />
<link href="favicon.ico" rel="shortcut icon" type="image/x-icon"/>
</head>
<body>
<h1>welcome to joffee集群</h1>
<h2>Server:<%=request.getLocalAddr() %></h2>
<h2>Port:<%=request.getLocalPort() %></h2>
<h2>Client:<%=request.getRemoteAddr() %></h2>
<h2>Session:<%=session.getId() %></h2>
<hr/>
<img src="/static/joffee.jpg" height="200px" />
</body>
</html>
路径路由规则
location = / {
#规则A
}
location = /login {
#规则B
}
location ^~ /static/ {
#规则C
}
location ~ \.(gif|jpg|png|js|css)$ {
#规则D
}
location ~* \.png$ {
#规则E
}
location !~ \.xhtml$ {
#规则F
}
location !~* \.xhtml$ {
#规则G
}
location / {
#规则H
}
访问根目录/, 比如http://localhost/ 将匹配规则A
访问 http://localhost/login 将匹配规则B,http://localhost/register 则匹配规则H
访问 http://localhost/static/a.html 将匹配规则C
访问 http://localhost/a.gif, http://localhost/b.jpg 将匹配规则D和规则E,但是规则D
顺序优先,规则E不起作用, 而 http://localhost/static/c.png 则优先匹配到 规则C
访问 http://localhost/a.PNG 则匹配规则E, 而不会匹配规则D,因为规则E不区分大小写。
访问 http://localhost/a.xhtml 不会匹配规则F和规则G,http://localhost/a.XHTML不会
匹配规则G,因为不区分大小写。规则F,规则G属于排除法,符合匹配规则但是不会匹配到,所以想想看
实际应用中哪里会用到。
访问 http://localhost/category/id/1111 则最终匹配到规则H,因为以上规则都不匹配,这个
时候应该是nginx转发请求给后端应用服务器,比如FastCGI(php),tomcat(jsp),nginx作为
方向代理服务器存在。
单Linux搭建多Tomcat
打开所有会话,basiscs和node1和node2都执行下面命令
[root@basiscs ~]# cd /opt/
[root@basiscs opt]# ll
total 0
drwxr-xr-x 9 root root 220 Nov 14 2019 apache-tomcat-8.5.47
drwxr-xr-x 11 root root 151 Mar 18 21:04 nginx
[root@basiscs opt]# mv apache-tomcat-8.5.47 apache-tomcat-8080 (复制重命名apache-tomcat-8080)
[root@basiscs opt]# cp -r apache-tomcat-8080 apache-tomcat-18080 (复制-r目录)
[root@basiscs opt]# ll
total 0
drwxr-xr-x 9 root root 220 Mar 19 13:33 apache-tomcat-18080
drwxr-xr-x 9 root root 220 Nov 14 2019 apache-tomcat-8080
drwxr-xr-x 11 root root 151 Mar 18 21:04 nginx
[root@basiscs opt]# vim /etc/profile (配置tomcat环境)
#tomcat8080
export CATALINA_HOME=/opt/apache-tomcat-8080
export CATALINA_BASE=/opt/apache-tomcat-8080
export TOMCAT_HOME=/opt/apache-tomcat-8080
#tomcat18080
export CATALINA_HOME18080=/opt/apache-tomcat-18080
export CATALINA_BASE18080=/opt/apache-tomcat-18080
export TOMCAT_HOME18080=/opt/apache-tomcat-18080
[root@basiscs opt]# source /etc/profile (重新加载)
[root@basiscs opt]# vim /opt/apache-tomcat-18080/conf/server.xml
只需要修改tomcat18080即可,第一台保持不变
22--默认为8005--》修改为18005
<Server port="18005" shutdown="SHUTDOWN">
69--默认为8080--》修改为18080
<Connector port="18080" protocol="HTTP/1.1" connectionTimeout="20000"
redirectPort="8443" />
116-默认为8009--》修改为18009
<Connector port="18009" protocol="AJP/1.3" redirectPort="8443" />
[root@basiscs opt]# vim /opt/apache-tomcat-18080/bin/catalina.sh
####################第二台tomcat配置,113行开始(去除注释的第一行)
export CATALINA_BASE=$CATALINA_BASE18080
export CATALINA_HOME=$CATALINA_HOME18080
export TOMCAT_HOME=$TOMCAT_HOME18080
[root@basiscs opt]# ps -ef | grep tom
root 13612 1 0 10:42 ? 00:00:27 /usr/java/jdk1.8.0_231-amd64/bin/java
...
[root@basiscs opt]# kill -9 13612 (这里需要分开执行,以为pid=13612 每台不一样)
[root@basiscs opt]# ps -ef | grep tom
root 25985 24634 0 14:12 pts/0 00:00:00 grep --color=auto tom
[root@basiscs opt]# cd /opt/
[root@basiscs opt]# ./apache-tomcat-8080/bin/startup.sh
[root@basiscs opt]# ./apache-tomcat-18080/bin/startup.sh
启动Tomcat
./apache-tomcat8080/bin/startup.sh
./apache-tomcat18080/bin/startup.sh
虚拟主机
虚拟主机使用的是特殊的软硬件技术,它把一台运行在因特网上的服务器主机分成一台台“虚拟”的
主机,每台虚拟主机都可以是一个独立的网站,可以具有独立的域名,具有完整的Intemet服务器
功能(WWW、FTP、Email等),同一台主机上的虚拟主机之间是完全独立的。从网站访问者来
看,每一台虚拟主机和一台独立的主机完全一样。
分类
1、基于域名的虚拟主机,通过域名来区分虚拟主机
2、基于端口的虚拟主机,通过端口来区分虚拟主机
基于域名
修改Window的 C:\Windows\System32\drivers\etc\hosts 文件
192.168.58.100 www.joffee666.com
192.168.58.100 www.joffee888.com
[root@basiscs opt]# vim /opt/nginx/conf/nginx.conf
upstream wan666 {
server 192.168.111.100:8080;
server 192.168.111.99:8080;
server 192.168.111.98:8080;
}
upstream wan888 {
server 192.168.111.100:18080;
server 192.168.111.99:18080;
server 192.168.111.98:18080;
}
server {
listen 80;
server_name www.joffee666.com;
location / {
proxy_pass http://wan666;
}
}
server {
listen 80;
server_name www.joffee888.com;
location / {
proxy_pass http://wan888;
}
location ^~ /static/ {
root html;
}
}
[root@basiscs opt]# nginx -s reload
基于端口
修改Window的 C:\Windows\System32\drivers\etc\hosts 文件
[root@basiscs opt]# vim /opt/nginx/conf/nginx.conf
upstream wan8080 {
server 192.168.111.100:8080;
server 192.168.111.99:8080;
server 192.168.111.98:8080;
}
upstream wan18080 {
server 192.168.111.100:18080;
server 192.168.111.99:18080;
server 192.168.111.98:18080;
}
server {
listen 3333;
server_name www.joffee10086.com;
location / {
proxy_pass http://wan8080;
}
}
server {
listen 4444;
server_name www.joffee10086.com;
location / {
proxy_pass http://wan18080;
}
}
[root@basiscs opt]# nginx -s reload
Session一致性
节点分布
[root@basiscs opt]# yum install memcached -y (安装数据库)
[root@basiscs opt]# systemctl status memcached (查看memcached状态)
Active: inactive (dead)
[root@basiscs opt]# systemctl start memcached
[root@basiscs opt]# systemctl status memcached
Active: active (running)
[root@basiscs opt]# systemctl enable memcached(关闭memcached)
[root@basiscs opt]# vim /etc/sysconfig/memcached (不做改变)
[root@basiscs opt]# cd /opt/apache-tomcat-18080/lib/
[root@basiscs lib]# rz (上传tomcat8.5整合memcached专用jar.zip)
[root@basiscs lib]# unzip tomcat8.5整合memcached专用jar.zip (解压)
[root@basiscs lib]# ll
drwxr-xr-x 2 root root 316 Jun 20 2020 tomcat8╒√║╧memcached╫и╙├jar
[root@basiscs lib]# cd tomcat8╒√║╧memcached╫и╙├jar
[root@basiscs tomcat8╒√║╧memcached╫и╙├jar]# mv ./* ../ (将jar包移到上一级目录)
[root@basiscs tomcat8╒√║╧memcached╫и╙├jar]# ll
total 0
[root@basiscs tomcat8╒√║╧memcached╫и╙├jar]# cd ..
[root@basiscs lib]# ll
-rw-r--r-- 1 root root 1095109 Feb 28 20:04 tomcat8.5整合memcached专用jar.zip
drwxr-xr-x 2 root root 6 Mar 19 18:46 tomcat8╒√║╧memcached╫и╙├jar
[root@basiscs lib]# rm -rf tomcat8╒√║╧memcached╫и╙├jar tomcat8.5整合memcached专用jar.zip(删除)
[root@basiscs lib]# vim /opt/apache-tomcat-18080/conf/server.xml
追加 jvmRoute="jvm18080",相同项目如果想共享session,需要把jvmRoute命名一致
<Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm18080">
</Engine>
[root@basiscs lib]# vim /opt/apache-tomcat-18080/conf/context.xml
<Manager
className="de.javakaffee.web.msm.MemcachedBackupSessionManager"
memcachedNodes="n1:192.168.58.101:11211"
sticky="true"
lockingMode="auto"
sessionBackupAsync="false"
requestUriIgnorePattern=".*\.(ico|png|gif|jpg|css|js)$"
sessionBackupTimeout="1000"
transcoderFactoryClass="de.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory" />
[root@basiscs lib]# cd ..
[root@basiscs apache-tomcat-18080]# cd ..
[root@basiscs opt]# ll
drwxr-xr-x 9 root root 220 Mar 19 13:33 apache-tomcat-18080
...
[root@basiscs opt]# scp -r apache-tomcat-18080 192.168.111.99:/opt/ (传到192.168.111.99)
[root@basiscs opt]# scp -r apache-tomcat-18080 192.168.111.98:/opt/ (传到192.168.111.98)
打开所有会话,同时操作
[root@basiscs opt]# ./apache-tomcat-18080/bin/shutdown.sh
[root@basiscs opt]# ps -ef | grep tom (查看只有一台)
[root@basiscs opt]# ./apache-tomcat-18080/bin/startup.sh (运行)