一、部署安装tomcat
在10和20上安装tomcat
[root@10 ~]# dnf install java-1.8.0-openjdk.x86_64 -y #安装java环境
[root@10 ~]# tar zxf apache-tomcat-9.0.93.tar.gz -C /usr/local/ #安装并启动tomcat
[root@10 ~]# ln -s /usr/local/apache-tomcat-9.0.93/ /usr/local/tomcat/
[root@10 ~]# /usr/local/tomcat/bin/startup.sh
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Using CATALINA_OPTS:
Tomcat started.[root@10 ~]# netstat -antlupe | grep java #查看端口
tcp6 0 0 :::8080 :::* LISTEN 0 30431 3308/java
tcp6 0 0 127.0.0.1:8005 :::* LISTEN 0 30443 3308/java
tomcat相关目录和文件
[root@10 ~]# ls /usr/local/tomcat/
bin BUILDING.txt conf CONTRIBUTING.md lib LICENSE logs NOTICE README.md RELEASE-NOTES RUNNING.txt temp webapps work
生成tomcat的启动文件[root@10 ~]# cat /usr/local/tomcat/conf/tomcat.conf
JAVA_HOME=/etc/alternatives/jre_openjdk[root@10 ~]# useradd -s /sbin/nologin -M tomcat
[root@10 ~]# chown -R tomcat.tomcat /usr/local/tomcat/
[root@10 ~]# cat /lib/systemd/system/tomcat.service
[Unit]
Description=Tomcat
#After=syslog.target network.target remote-fs.target nss-lookup.target
After=syslog.target network.target
[Service]
Type=forking
EnvironmentFile=/usr/local/tomcat/conf/tomcat.conf
ExecStart=/usr/local/tomcat/bin/startup.sh
ExecStop=/usr/local/tomcat/bin/shutdown.sh
PrivateTmp=true
User=tomcat
Group=tomcat
[Install]
WantedBy=multi-user.target[root@10 ~]# systemctl daemon-reload
[root@10 ~]# systemctl enable --now tomcat
tomcat负载均衡实现
[root@node1 ~]# vim /usr/local/nginx/conf.d/vhost.conf
upstream tomcat {
ip_bash;
#hash $cookie_JSESSIONID;
server 172.25.250.10:8080;
server 172.25.250.20:8080;
}
server {
listen 80;
server_name www.bwmis.org;location ~ \.jsp$ {
proxy_pass http://tomcat;}
}
[root@20 ~]# cp test.jsp /usr/local/tomcat/webapps/ROOT/ #10也要同样的操作测试
Memcached
kryo-3.0.3.jar asm-5.2.jar
objenesis-2.6.jar reflectasm-1.11.9.jar
minlog-1.3.1.jar kryo-serializers-0.45.jar
msm-kryo-serializer-2.3.2.jar
memcached-session-manager-tc9-2.3.2.jar
spymemcached-2.12.3.jar
memcached-session-manager-2.3.2.jar 放到/usr/local/tomcat/lib/这个目录下面
https://github.com/magro/memcached-session-manager/wiki/SetupAndConfiguration #下载jar包
[root@20 ~]# yum install memcached -y
[root@20 ~]# vim /etc/sysconfig/memcachedPORT="11211"
USER="memcached"
MAXCONN="1024"
CACHESIZE="64"
OPTIONS="-l 0.0.0.0,::1"[root@20 ~]# systemctl enable --now memcached
[root@10 ~]# netstat -antlupe | grep memcache #查看端口
[root@20 ~]# vim /usr/local/tomcat/conf/context.xml<Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager"
memcachedNodes="n1:172.25.250.10:11211,n2:172.25.250.20:11211"
failoverNodes="n1"
requestUriIgnorePattern=".*\.(ico|png|gif|jpg|css|js)$"
transcoderFactoryClass="de.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory"/>
root@10 lib]# systemctl stop tomcat #再次提交就会变到20