以前公司就用到这个、也简单写过一个文档、后来发现写的不够详细以至于别人看到我的文档、总是不知所措、这次利用空闲时间写一份详细的、共享给各位刚接触这个技术的小伙伴!!!
实验环境:虚拟机centOS6.6_x89_64 Minal模式
软件版本:apache-tomcat-7.0.64.tar.gz
jdk-7u45-linux-x64.tar.gz
libevent-2.0.21-stable.tar.gz
memcached-1.4.21.tar.gz
以及和tomcat版本相对经的jar包
实验前先关闭seLinux和防火墙
setenfor 0
service iptables stop
本次实验还会用到一些基础依赖包如果觉得没安装好 可以运行一下命令 防止后面编译报错
yum groupinstall -y Development tools
好了 不废话 Go!Go!Go!
1、所有文件包都放在/usr/local/src/
[[email protected] ~]# cd /usr/local/src/
[[email protected] src]# ll
总用量 144688
-rw-r--r-- 1 root root 8858187 11月 24 19:39 apache-tomcat-7.0.64.tar.gz
-rw-r--r-- 1 root root 138094686 11月 24 19:40 jdk-7u45-linux-x64.tar.gz
-rw-r--r-- 1 root root 850772 11月 24 19:39 libevent-2.0.21-stable.tar.gz
-rw-r--r-- 1 root root 345892 11月 24 19:39 memcached-1.4.21.tar.gz
drwxr-xr-x 2 root root 4096 11月 24 19:40 serssion-jar
2、安装java并配置环境变量、检测jdk版本
[[email protected] src]# tar zxvf jdk-7u45-linux-x64.tar.gz
[[email protected] src]# mv jdk1.7.0_45/ /usr/local/jdk7
[[email protected] src]# vim /etc/profile
..........................................................
export JAVA_HOME=/usr/local/jdk7
export JRE_HOME=/usr/local/jdk7
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib
..........................................................
如下图所示:
[[email protected] src]# source /etc/profile
[[email protected] src]# java -version
java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)
3、安装tomcat
[[email protected] src]# tar zxvf apache-tomcat-7.0.64.tar.gz
[[email protected] src]# mv apache-tomcat-7.0.64 /usr/local/tomcat
[[email protected] src]# vim /usr/local/tomcat/bin/catalina.sh
..........................................................
JAVA_HOME=/usr/local/jdk7
CATALINA_HOME=/usr/local/tomcat
JAVA_OPTS="-server -XX:PermSize=128M -XX:MaxPermSize=512M -Xms1024m -Xmx1024m -Duser.timezone=Asia/Shanghai -Djava.awt.headless=true"
..........................................................
如下图所示:
[[email protected] src]# /usr/local/tomcat/bin/startup.sh //启动tomcat
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/local/jdk7
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.
[[email protected] src]# ps aux |grep tomcat //可以看到tomcat已经启动成功
root 1237 2.0 73.8 2335144 174376 pts/0 Sl 21:05 0:04 /usr/local/jdk7/bin/java -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -server -XX:PermSize=128M -XX:MaxPermSize=512M -Xms1024m -Xmx1024m -Duser.timezone=Asia/Shanghai -Djava.awt.headless=true -Djava.endorsed.dirs=/usr/local/tomcat/endorsed -classpath /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/tomcat -Dcatalina.home=/usr/local/tomcat -Djava.io.tmpdir=/usr/local/tomcat/temp org.apache.catalina.startup.Bootstrap start
root 1271 0.0 0.3 103248 880 pts/0 S+ 21:09 0:00 grep tomcat
[[email protected] src]# curl localhost:8080 //测试tomcat可以看到 没有问题
<!DOCTYPE html>
<html lang="en">
<head>
<title>Apache Tomcat/7.0.64</title>
<link href="favicon.ico" rel="icon" type="image/x-icon" />
<link href="favicon.ico" rel="shortcut icon" type="image/x-icon" />
<link href="tomcat.css" rel="stylesheet" type="text/css" />
</head>
4、编译安装memcached
[[email protected] src]# cp serssion-jar/* /usr/local/tomcat/lib/ //将msm依赖的jar包放到$TOMCAT_HOME/lib下
[[email protected] src]# tar zxvf libevent-2.0.21-stable.tar.gz
[[email protected] src]# cd libevent-2.0.21-stable
[[email protected] libevent-2.0.21-stable]# ./configure --prefix=/usr/local/libevent
[[email protected] libevent-2.0.21-stable]# make && make install
#每次编译最好用 echo $? 查看下编译是否成功
[[email protected] libevent-2.0.21-stable]# cd ..
[[email protected] src]# tar zxvf memcached-1.4.21.tar.gz
[[email protected] src]# cd memcached-1.4.21
[[email protected] memcached-1.4.21]# ./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent
[[email protected] memcached-1.4.21]# make && make install
[[email protected] memcached-1.4.21]# echo $?
0
5、修改tomcat的配置文件
[[email protected] memcached-1.4.21]# cd /usr/local/tomcat/
[[email protected] tomcat]# vim conf/server.xml
..........................................................
<Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
#如果要配置通一台机器上的多个tomcat、那么jvmRoute的标签要改成不同的
..........................................................
如图所示:
[[email protected] tomcat]# vim conf/context.xml
..........................................................
<Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager"
memcachedNodes="n1:10.164.24.246:11211,n2:10.164.4.154:11211"
sticky="false"
sessionBackupAsync="false"
lockingMode="uriPattern:/path1|/path2"
requestUriIgnorePattern=".*\.(ico|png|gif|jpg|css|js)$" transcoderFactoryClass="de.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory"
/>
#memcachedNodes="n1:10.164.24.246:11211,n2:10.164.4.154:11211"
#这个地方 如果是一台mem服务器 那么就写n1:IP:PORT 如果多台就n1..,n2..,n3..
..........................................................
如图所示这里以一台为例:
6、启动memcached
[[email protected] tomcat]# cd /usr/local/memcached/
[[email protected] memcached]# bin/memcached -d -m 256 -p 11211 -u root
#重启tomcat
[[email protected] memcached]# ps aux |grep tomcat
root 1237 0.4 54.6 2336172 129032 pts/0 Sl 21:05 0:08 /usr/local/jdk7/bin/java -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -server -XX:PermSize=128M -XX:MaxPermSize=512M -Xms1024m -Xmx1024m -Duser.timezone=Asia/Shanghai -Djava.awt.headless=true -Djava.endorsed.dirs=/usr/local/tomcat/endorsed -classpath /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/tomcat -Dcatalina.home=/usr/local/tomcat -Djava.io.tmpdir=/usr/local/tomcat/temp org.apache.catalina.startup.Bootstrap start
[[email protected] memcached]# kill -9 1237
[[email protected] memcached]# /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/local/jdk7
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
#如下图可以看出 端口已被监听
[[email protected] memcached]# netstat -lnp |grep mem
tcp 0 0 0.0.0.0:11211 0.0.0.0:* LISTEN 8207/bin/memcached
tcp 0 0 :::11211 :::* LISTEN 8207/bin/memcached
udp 0 0 0.0.0.0:11211 0.0.0.0:* 8207/bin/memcached
udp 0 0 :::11211 :::* 8207/bin/memcached
[[email protected] memcached]# netstat -lnp |grep java
tcp 0 0 ::ffff:127.0.0.1:8005 :::* LISTEN 8225/java
tcp 0 0 :::8009 :::* LISTEN 8225/java
tcp 0 0 :::8080 :::* LISTEN 8225/java
7、测试memcached
[[email protected] memcached]# yum install -y telnet