tomcat8 + nginx + memcached + cas 实现负载均衡的配置
来源:互联网 发布:linux线程相关系统调用 编辑:程序博客网 时间:2024/06/04 19:44
1,tomcat8的配置:
1.1修改tomcat8.x/conf/context.xml的配置如下:
<?xml version="1.0" encoding="UTF-8"?><!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.--><!-- The contents of this file will be loaded for each web application --><Context> <!-- Default set of monitored resources. If one of these changes, the --> <!-- web application will be reloaded. --> <WatchedResource>WEB-INF/web.xml</WatchedResource> <WatchedResource>${catalina.base}/conf/web.xml</WatchedResource> <!-- Uncomment this to disable session persistence across Tomcat restarts --> <!-- <Manager pathname="" /> <Resources cachingAllowed="true" cacheMaxSize="100000" /> <Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager" memcachedNodes="n1:127.0.0.1:11211" username="root" password="" sticky="false" sessionBackupAsync="false" lockingMode="uriPattern:/path1|/path2" requestUriIgnorePattern=".*\.(ico|png|gif|jpg|css|js)$" transcoderFactoryClass="de.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory" /> --> <Resources cachingAllowed="true" cacheMaxSize="100000" /> <Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager" memcachedNodes="n1:127.0.0.1:11211" username="root" password="" sticky="false" sessionBackupAsync="false" lockingMode="uriPattern:/path1|/path2" requestUriIgnorePattern=".*\.(ico|png|gif|jpg|css|js)$" sessionBackupTimeout="18000" transcoderFactoryClass="de.javakaffee.web.msm.serializer.javolution.JavolutionTranscoderFactory" copyCollectionsForSerialization="false" /></Context>
第一个参数:
localhost:11211 为Memcached服务器 多台以逗号分隔。
第二个参数:
memcached服务器的用户名
第三个参数
memcached服务器的密码配置OK。
1.2添加memcached如下依赖的jar包到tomcat8.x/lib/:
asm-5.1.jarcouchbase-client-1.4.12.jarjavolution-5.5.1.jarkryo-4.0.0.jarkryo-serializers-0.38.jarmemcached-session-manager-2.0.0.jarmemcached-session-manager-tc8-2.0.0.jarminlog-1.3.jarmsm-javolution-serializer-2.0.0.jarmsm-kryo-serializer-2.0.0.jarmsm-xstream-serializer-2.0.0.jarobjenesis-2.1.jarreflectasm-1.09.jarspymemcached-2.12.1.jar
2,nginx的配置:
#user nobody;worker_processes 1;#error_log logs/error.log;#error_log logs/error.log notice;#error_log logs/error.log info;#pid logs/nginx.pid;events { worker_connections 1024;}http { include mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log logs/access.log main; client_header_timeout 3m; client_body_timeout 3m; send_timeout 3m; sendfile on; tcp_nopush on; tcp_nodelay on; #keepalive_timeout 0; keepalive_timeout 65; gzip on; #设定负载均衡的服务器列表upstream 127.0.0.1 { #设定负载均衡的服务器列表 #ip_hash; #同一机器在多网情况下,路由切换,ip可能不同 #weigth参数表示权值,权值越高被分配到的几率越大 server 127.0.0.1:8085 weight=1 max_fails=20 fail_timeout=600s; server 127.0.0.1:8086 weight=1 max_fails=20 fail_timeout=600s;} map $http_upgrade $connection_upgrade { default upgrade; '' close; } server { listen 80; server_name localhost; charset UTF-8;#设定本虚拟主机的访问日志 access_log logs/host.access.log main;#对 "/" 所有应用启用负载均衡 location / { proxy_pass http://127.0.0.1; #保留用户真实信息 proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; index index.html index.htm index.aspx; } #对 "/Dossm3RabbitMQConsumer/" 启用负载均衡 location /Dossm3RabbitMQConsumer/ { proxy_pass http://localhost:8086; #保留用户真实信息 proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; index index.html index.htm index.aspx; } } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #}}
3,cas的配置():
3.1 修改/CAS/WEB-INF/spring-configuration/ticketRegistry.xml
<?xml version="1.0" encoding="UTF-8"?><!-- Licensed to Jasig under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. Jasig licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at the following location: http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.--><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"> <description> Configuration for the default TicketRegistry which stores the tickets in-memory and cleans them out as specified intervals. </description> <!-- memcached 配置开始 --> <!-- Ticket Registry --> <bean id="ticketRegistry" class="org.jasig.cas.ticket.registry.MemCacheTicketRegistry"> <constructor-arg index="0"> <bean class="net.spy.memcached.spring.MemcachedClientFactoryBean" p:servers="127.0.0.1:11211" p:protocol="BINARY" p:locatorType="ARRAY_MOD" p:failureMode="Redistribute" p:transcoder-ref="serialTranscoder"> <property name="hashAlg"> <util:constant static-field="net.spy.memcached.DefaultHashAlgorithm.FNV1A_64_HASH" /> </property> </bean> </constructor-arg> <!-- TGT timeout in seconds --> <constructor-arg index="1" value="36000" /> <!-- ST timeout in seconds --> <constructor-arg index="2" value="2" /> </bean> <bean id="serialTranscoder" class="net.spy.memcached.transcoders.SerializingTranscoder" p:compressionThreshold="2048" /> <!-- memcached 配置结束 --><!--Quartz --> <!-- 默认配置开始 --> <!-- Ticket Registry --> <!-- <bean id="ticketRegistry" class="org.jasig.cas.ticket.registry.DefaultTicketRegistry" />--><!-- TICKET REGISTRY CLEANER --><!-- <bean id="ticketRegistryCleaner" class="org.jasig.cas.ticket.registry.support.DefaultTicketRegistryCleaner"p:ticketRegistry-ref="ticketRegistry"p:logoutManager-ref="logoutManager" /><bean id="jobDetailTicketRegistryCleaner" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"p:targetObject-ref="ticketRegistryCleaner"p:targetMethod="clean" /><bean id="triggerJobDetailTicketRegistryCleaner" class="org.springframework.scheduling.quartz.SimpleTriggerBean"p:jobDetail-ref="jobDetailTicketRegistryCleaner"p:startDelay="200000"p:repeatInterval="50000000" /> --><!-- 默认配置结束 --> </beans>
第一个参数:
localhost:11211 为Memcached服务器 多台以逗号分隔。
第二个参数:
TGT票据在多少秒超时。
第三个参数
ST票据在多少秒超时。
compressionThreshold:启用了压缩,增加或减小需压缩的包的大小限制。
配置OK。
3.2 添加cas和memcached整合的如下依赖jar包到/CAS/WEB-INF/lib:
cas-server-integration-memcached-4.0.0.jarmockito-core-2.1.0-RC.1.jarspymemcached-2.11.2.jar
参考CAS官方配置:https://apereo.github.io/cas/4.2.x/installation/Memcached-Ticket-Registry.html
0 0
- tomcat8 + nginx + memcached + cas 实现负载均衡的配置
- NginX+Tomcat8的负载均衡配置
- Nginx + Memcached 实现Session共享的负载均衡
- Nginx + Memcached 实现Session共享的负载均衡
- Nginx + Memcached 实现Session共享的负载均衡
- Nginx+memcached+tomcat 负载均衡配置
- nginx +tomcat7+memcached负载均衡配置
- nginx+tomcat+memcached负载均衡配置
- Nginx+Tomcat+Memcached负载均衡配置流程
- nginx+tomcat+memcached配置负载均衡
- NGINX + TOMCAT + MEMCACHED实现HTTP负载均衡
- Windows+tomcat6+nginx+memcached实现负载均衡
- 配置Nginx实现负载均衡
- 配置Nginx实现负载均衡
- 配置Nginx实现负载均衡
- tomcat8集群实现session共享 nginx负载均衡
- tomcat8集群实现session共享 nginx负载均衡
- 详解之:linux下tomcat、nginx的负载均衡及memcached对session共享的实现配置详细总结
- 别人用jax-ws发布的webservice,我尝试了用axis调用webservice即wsdl可以。下面尝试另一种方式调用,用jax-ws方式去调用
- MAC OS下错误提示xcrun: error: invalid active developer path
- xml 与bean 转换 java
- 设置沉浸式状态栏
- Better Performance at Lower Occupancy(二)使用更少线程隐藏内存访问延迟
- tomcat8 + nginx + memcached + cas 实现负载均衡的配置
- php文件删除,unlink()
- centos + nginx + mysql + php 环境编译安装
- spring事物
- Git常用命令
- 实验三
- sphinx 使用教程-挺简单易懂
- 使用SAX解析XML文件
- Berzerk CodeForces
原创粉丝点击
热门IT博客
热门问题
老师的惩罚
人脸识别
我在镇武司摸鱼那些年
重生之率土为王
我在大康的咸鱼生活
盘龙之生命进化
天生仙种
凡人之先天五行
春回大明朝
姑娘不必设防,我是瞎子
重庆车牌
重庆汽车
重庆区
重庆人和
重庆在哪
重庆游记
重庆名人
重庆自由行
重庆公交车
重庆58
重庆属于
重庆市图片
重庆省会
重庆买房
重庆小吃街
重庆气候
重庆城市
重庆高铁站
重庆中学
重庆桑拿
重庆美食街
重庆市简介
重庆人
山城重庆
重庆地产
重庆市房产
重庆到
重庆到济宁
重庆到杭州
重庆市酒店
重庆到长沙
重庆重庆旅游攻略
重庆到无锡
济宁到重庆
重庆到绵阳
天津到重庆
重庆重庆旅游
重庆飞黔江
合肥到重庆
重庆在线
重庆飞东营