架构图
Chient 192.168.122.1/24
|
Apache 192.168.122.10/24
__________|___________
| |
tomcat1 tomcat2
192.168.122.20/24 192.168.122.30/24
| |
―――――――――――
|
―――――――――――
| |
memcached1 memcached2
192.168.122.40/24 192.168.122.50/24
===========一、Apache 部分==============
一、材料
1、tomcat-connectors-1.2.37-src.tar.gz
2、配置yun安装源 (httpd httpd-devel )
二、安装配置
1、安装php php-devel
# yum install httpd httpd-devel -y
#echo "apache html test" > /var/www/html/index.html
2、配置tomcat-connectors
[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/sbin/apxs #如果没有/usr/sbin/apxs需要安装httpd-devel
[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
3、配置转发tomcat
root@localhost native]# vim /etc/httpd/conf/workers.properties
worker.list=wlb,jkstatus
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
4、启动apache
[root@localhost native]# service httpd start
=============二、Tomcat 部分===============
一、材料:
1、jdk-7u45-linux-x64.rpm
2、apache-tomcat-7.0.47.tar.gz
二、安装配置
1、安装jdk
#rpm -ivh jdk-7u45-linux-x64.rpm
[root@r6-3 ~]# rpm -ivh jdk-7u45-linux-x64.rpm
Preparing... ########################################### [100%]
1:jdk ########################################### [100%]
Unpacking JAR files...
rt.jar...
jsse.jar...
charsets.jar...
tools.jar...
localedata.jar...
jfxrt.jar...
2、配置环境变量
#vim /etc/bashrc
加入一下内容
export JAVA_HOME=/usr/java/jdk1.7.0_45/
export JAVA_BIN=/usr/java/jdk1.7.0_45/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
3、载入配置
#source /etc/bashrc
查看版本 [root@r6-3 ~]# 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 mod
4、安装tomcat
#tar zxf apache-tomcat-7.0.47.tar.gz
#mv apache-tomcat-7.0.47 /usr/local/tomcat
#cd /usr/local/tomcat/bin/
5、启动tomcat服务
[root@r6-3 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/java/jdk1.7.0_45/
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
1、查看启动
[root@r6-3 bin]# ps -elf | grep tomcat
0 S root 5580 1 3 80 0 - 239083 futex_ 10:27 pts/0 00:00:03 /usr/java/jdk1.7.0_45//bin/java - Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -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
0 S root 5602 3308 0 80 0 - 25811 pipe_w 10:29 pts/0 00:00:00 grep tomcat
[root@r6-3 bin]# lsof -i :8080
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
java 5580 root 42u IPv6 22002 0t0 TCP *:webcache (LISTEN)
#elinks http://192.168.122.30:8080
2、修改默认端口
#vim /usr/loacl/tomcat/conf/server.xml
<Connector port="80" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
3、重启 ./shutdown.sh && ./startup.sh
4、192.168.122.20重复上述配置
==============三、memcached 部分=================
一、材料
1、libevent-2.0.15-stable.tar.gz
2、memcached-1.4.5.tar.gz
二、安装配置
1、安装libevent
[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
2、安装memcached
[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 #r6可能需要cp /usr/local/lib/libevent-2.0.so.5 /lib64/这步
[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
telnet测试memcached
#telnet 192.168.122.40 11211
Trying 192.168.122.40...
Connected to 192.168.122.40.
Escape character is '^]'.
set key0 0 180 3 #设置key
123 #设置key 的value
STORED
get key0 #获取key0的值
VALUE key0 0 3
123
END
注意:set key1 0 3600 3
key1表示key的名字
0表示一个跟该key有关的自定义数据
3600表示该key的有效时间
3表示key1值的字节数
3、192.168.122.50重复上述配置
==============四、配置tomcat支持连接Memcached================
一、材料
1、kryo-1.04.jar
2、memcached-session-manager-1.5.1.jar
3、msm-kryo-serializer-1.5.1.jar
4、kryo-serializers-0.9.jar
5、memcached-session-manager-tc6-1.5.1.jar
6、reflectasm-1.01.jar
7、memcached-2.5.jar
8、minlog-1.2.jar
二、配置
#vim /usr/local/tomcat/conf/context.xml
在<Context></Context>中加入
<Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager"
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"
/>
三、重启tomcat服务
#echo "关闭tomcat" && /usr/local/tomcat/bin/shutdown.sh && echo "启动tomcat" && /usr/local/tomcat/bin/startup.sh
===============备注===============
memcached常用设置:
-p <num> 监听的端口
-l <ip_addr> 连接的IP地址, 默认是本机
-d start 启动memcached服务
-d restart 重起memcached服务
-d stop|shutdown 关闭正在运行的memcached服务
-d install 安装memcached服务
-d uninstall 卸载memcached服务
-u <username> 以<username>的身份运行 (仅在以root运行的时候有效)
-m <num> 最大内存使用,单位MB。默认64MB
-M 内存耗尽时返回错误,而不是删除项
-c <num> 最大同时连接数,默认是1024
-f <factor> 块大小增长因子,默认是1.25
-n <bytes> 最小分配空间,key+value+flags默认是48
-h 显示帮助