---
title: "linux下nginx+memecached+tomcat负载均衡故障转移"
author: "cserw3c"
date: "2017-02-28T13:02:50Z"
tags: []
categories: ["开源软件"]
slug: "linux-nginx-memecached-tomcat"
draft: false
lastmod: "2017-02-28T13:02:50Z"
id: 2359452
url: "https://solomon2012.iteye.com/blog/2359452"
---

**Linux系统下搭建Nginx+memecached分布式部署说明**
一、准备工作。
1，安装nginx最新版本，系统采用nginx-1.10.3.tar.gz（http://nginx.org/en/download.html）。
2，安装libevent最新版本，系统采用libevent-2.0.20-stable.tar.gz （http://libevent.org/）。
3，安装memcached-1最新版本，系统采用memcached-1.2.2.tar.gz 
(https://github.com/memcached/memcached/wiki/ReleaseNotes)。
4，集成memecached+tomcat ,集成的Jar包。memcached-session-manager-2.1.1.jar
、memcached-session-manager-tc7-2.1.1.jar、spymemcached-2.10.3.jar
。

二、配置说明。
1，nginx 分别部署在正式环境 /deploy/nginx目录下。
2，memecached 部署在正式环境 /deploy/memecached 目录下。
3，nginx 配置文件见./conf/nginx.conf 。
4，tomcats中修改context.xml 。
5，tomcat ./lib 中添加msm所需jar包，memcached-session-manager-2.1.1.jar、memcached-session-manager-tc7-2.1.1.jar、spymemcached-2.10.3.jar。

三、环境说明。
1，启动nginx，命令如下，首次/deploy/nginx/sbin/nginx；热启动，修改了/deploy/nginx/conf/nginx.conf 可以直接 /deploy/nginx/sbin/nginx -s reload ，也可以kill掉 pid，然后执行/deploy/nginx/sbin/nginx。自动化启动，echo “/deploy/nginx/sbin/nginx”>>
/etc/rc.d/rc.local

2，启动memecached ，/deploy/memecached/bin/memcached -d -m 1024 -u root -p 11211 -c 256 -P /deploy/memecached/tmp/memecached.pid 。随开机启动。
echo “/deploy/memecached/bin/memcached -d -m 1024 -u root -p 11211 -c 256 -P /deploy/memecached/tmp/memecached.pid”>>/etc/rc.d/rc.local 。

3，nginx的配置Nginx 配置

![](http://dl2.iteye.com/upload/attachment/0123/3877/9bbb124f-15fc-3413-908f-860f626ef6c3.jpg)

4，tomcat中./conf/context.xml 配置如下

![](http://dl2.iteye.com/upload/attachment/0123/3879/e49436ce-5fbb-3ad0-916b-654f4e1f6d64.jpg)

四、jar包下载。
pom或者http://mvnrepository.com/

五、部署过程中遇到的问题链接地址。
1，install memecached
http://www.cnblogs.com/zgx/archive/2011/08/10/2134097.html
2，ibevent
http://www.cnblogs.com/kunhu/p/3632225.html
3，memecached some errors
http://f.dataguru.cn/thread-44149-1-1.html
4，some jars
http://blog.csdn.net/leihelloworld/article/details/25501361
5，auto start 
http://bardo.iteye.com/blog/954770
6，nginx
http://blog.csdn.net/shimiso/article/details/8979044
7，ln
ln -s /deploy/libevent/lib/libevent-2.0.so.5 /usr/lib64/libevent-2.0.so.5
8，attachments
如下附件.memcached-iteye.rar