Mac下Nginx负载+Tomcat集群+memcached实现

2018-07-19  本文已影响16人  Hush____

最近,要接手cas的单点认证,所以提前学习了这个。nginx负载、分发多台tomcat的过程中,memcached实现了session共享。虽然网上也有很多的示例,总结下自己吸收到的并记录下来。

nginx简单安装配置:

pengchengdeMacBook-Pro:nginx pengcheng$ nginx -v
nginx version: nginx/1.15.1
  1. 启动命令:sudo nginx(nginx默认端口是80,直接访问http://localhost,会有个欢迎页面)
  2. 停止命令:sudo nginx -s stop
  3. 重启命令:sudo nginx -s reload
  4. 杀进程停止有三种方式:从容停止、快速停止和强制停止。我这使用的话,就是 快速停止:
pengchengdeMacBook-Pro:nginx pengcheng$ ps -ef | grep nginx
    0  7183     1   0  2:22下午 ??         0:00.00 nginx: master process nginx
   -2  7184  7183   0  2:22下午 ??         0:00.00 nginx: worker process
  501  7298   899   0  2:27下午 ttys000    0:00.00 grep nginx
pengchengdeMacBook-Pro:nginx pengcheng$ sudo kill -TERM 7183
  1. 负载均衡
  2. 动静分离
  3. 反向代理
pengchengdeMacBook-Pro:nginx pengcheng$ pwd
/usr/local/etc/nginx

upstream test_cluster {
    server localhost:8081 weight=1;
    server localhost:9080 weight=2;
}
location / {
     root   html;
     index  index.html index.htm;
     proxy_pass http://test_cluster;
}

tomcat配置:

memcached集成tomcat中:

pengchengdeMacBook-Pro:/ pengcheng$ memcached -d -p 11211 -u nobody -c 1024 -m 64
pengchengdeMacBook-Pro:/ pengcheng$ telnet localhost 11211
Trying ::1...
Connected to localhost.
Escape character is '^]'.

<Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager" 
    memcachedNodes="n1:127.0.0.1:11211" 
    sticky="false" 
    requestUriIgnorePattern= ".*\.(png|gif|jpg|css|js)$"   
    sessionBackupAsync= "true"  
    sessionBackupTimeout= "1800000"     
    copyCollectionsForSerialization="false"
    transcoderFactoryClass="de.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory"   
  />

对应序列化,要往tomcat的lib下添加对应的jar包。


可以自己找或者滴滴我
上一篇下一篇

猜你喜欢

热点阅读