2018-12-03

2018-12-03  本文已影响0人  4e0b3c520bb8

memcache+apache+tomcat  干货信息

++++++++++++

+ Client          +  192.168.122.1/24 (真实机做客户端)

++++++++++++

|

++++++++++++

+ Apache        +  192.168.122.10/24

++++++++++++

________________|_______________

|                                                  |

+++++++++++++              +++++++++++++

+        Tomcat  1    +              +        Tomcat  2    +

+++++++++++++            +++++++++++++

eth0 192.168.122.20/24          DIP eth0 192.168.122.30/24

|______________________________|

______________|_______________

|                                          |

|                                            |

+++++++++++++++          ++++++++++++++++

+  memcahe master    +          +    memcache backup    +

+++++++++++++++          ++++++++++++++++

192.168.122.40/24                  192.168.122.50/24

部署 Apache

[root@localhost ~]# yum install httpd httpd-devel

[root@localhost ~]# echo “apache html test” > /var/www/html/index.html

[root@localhost ~]# cd /tmp

[root@localhost tmp]# tar zxvf tomcat-connectors-1.2.32-src.tar.gz

[root@localhost tmp]# cd tomcat-connectors-1.2.32-src/native

[root@localhost native]# ./configure  --with-apxs=/usr/bin/apxs  #如果没有/usr/bin/apxs需要安装httpd-devel

aclocal-1.15  执行autoreconf -ivf      yum install  automake autoconf

[root@localhost native]# make && make install

[root@localhost native]# cp  ../conf/httpd-jk.conf  /etc/httpd/conf.d/jk.conf

[root@localhost native]# vim /etc/httpd/conf.d/jk.conf

JkMount    /*.jsp wlb

[root@localhost native]# cp ../conf/workers.properties /etc/httpd/conf

[root@localhost native]# vim /etc/httpd/conf/workers.properties

worker.list=wlb

worker.wlb.type=lb

worker.wlb.balance_workers=tomcat1,tomcat2

worker.tomcat1.type=ajp13

worker.tomcat1.host=192.168.122.20

worker.tomcat1.port=8009

worker.tomcat1.lbfactor=1

worker.tomcat2.type=ajp13

worker.tomcat2.host=192.168.122.30

worker.tomcat2.port=8009

worker.tomcat2.lbfactor=1

[root@localhost native]# service httpd start

部署 Tomcat 1 & Tomcat 2

[root@localhost ~]# service httpd stop

[root@localhost ~]# cd /tmp

[root@localhost tmp]# chmod +x jdk-6u27-linux-i586.bin

[root@localhost tmp]# ./jdk-6u27-linux-i586.bin

[root@localhost tmp]# mv  jdk1.6.0_27/  /usr/local/jdk

使用1.8版本以下的openjdk

yum install java-1.7.0-openjdk.x86_64

[root@localhost tmp]# vim /etc/bashrc

export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.141-2.6.10.1.el7_3.x86_64/jre/

export JAVA_BIN=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.141-2.6.10.1.el7_3.x86_64/jre/bin/

export PATH=$JAVA_HOME/bin:$PATH

export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

export JAVA_HOME JAVA_BIN PATH CLASSPATH

[root@localhost tmp]# source /etc/bashrc

[root@localhost tmp]# java -version

[root@localhost tmp]# tar zxf apache-tomcat-6.0.32.tar.gz

[root@localhost tmp]# mv apache-tomcat-6.0.32 /usr/local/tomcat

[root@localhost tmp]# cd /usr/local/tomcat/bin

[root@localhost bin]# ./startup.sh

[root@localhost bin]# vim /usr/local/tomcat/webapps/ROOT/index.jsp

#Tomcat2 修改为别的颜色

<%= request.getSession().getId() %>

Tomcat 1

#Tomcat 2

阶段测试

1.访问 index.html 由 Aapche 处理,

2.访问 index.jsp 交给 Tomcat 1 与 Tomcat 2 负载处理,

3.访问 index.jsp 时在 Tomcat 1 与 Tomcat 2 之间进行切换,但是 session_id 也随之变化

部署 Memcache 1 & Memcache 2

[root@localhost tmp]# tar xf libevent-2.0.15-stable.tar.gz

[root@localhost tmp]# cd libevent-2.0.15-stable

[root@localhost libevent-2.0.15-stable]# ./configure && make && make install

[root@localhost tmp]# tar xf memcached-1.4.5.tar.gz

[root@localhost tmp]# cd memcached-1.4.5

[root@localhost memcached-1.4.5]# ./configure && make && make install

[root@localhost memcached-1.4.5]# memcached -h

[root@localhost memcached-1.4.5]# memcached -p 11211 -l 192.168.122.40 -u root -m 10 -c 10 -vvv -f 1.2 -n 60

部署 Tomcat 1 & Tomcat 2 支持连接 Memcached

[root@localhost tmp]# cp  session/*.jar  /usr/local/tomcat/lib

[root@localhost tmp]# vim /usr/local/tomcat/conf/context.xml

memcachedNodes="n1:192.168.122.40:11211,n2:192.168.122.50:11211"

failoverNodes="n1"

requestUriIgnorePattern=".*\.(ico|png|gif|jpg|css|js)$"

transcoderFactoryClass="de.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory"

/>

注意:定义内容要写在<Context></Context>里面

[root@localhost tmp]# /usr/local/tomcat/bin/shutdown.sh

[root@localhost tmp]# /usr/local/tomcat/bin/startup.sh

最终测试

1.访问 index.html 由 Aapche 处理,

2.访问 index.jsp 交给 Tomcat 1 与 Tomcat 2 负载处理,

3.访问 index.jsp 时在 Tomcat 1 与 Tomcat 2 之间进行切换,并且 session_id 不会变化

上一篇下一篇

猜你喜欢

热点阅读