Centos 6.7 Tomcat Session集群
规划结构图http://s3.运维网.com/wyfs02/M01/75/4A/wKiom1Y0j6KgIUO2AAGsnIPzqFk818.jpg nginx接收用户请求反向代理至后端应用服务器
应用服务器或者session服务器其中一台宕机,不影响客户端会话的信息
OS:CentOS release 6.7 (Final)
Memcached设置
两台memcached1 2 各进行配置
1.安装memcached
# yum install memcached
#yum install memcached
2.启动服务
# service memcachedstart
Starting memcached:
# service memcached start
Starting memcached: [ OK]
3.测试
# ss -tln
State Recv-Q Send-Q LocalAddress:Port Peer Address:Port
LISTEN 0 128 :::11211 :::*
LISTEN 0 128 *:11211 *:*
]# telnet 192.168.1.180 11211
Trying 192.168.1.180...
Connected to 192.168.1.180.
Escape character is '^]'.
quit
Connection closed by foreign host.
# ss –tln
State Recv-Q Send-Q LocalAddress:Port Peer Address:Port
LISTEN 0 128 :::11211 :::*
LISTEN 0 128 *:11211 *:*
]# telnet 192.168.1.190 11211
Trying 192.168.1.190...
Connected to 192.168.1.190.
Escape character is '^]'.
quit
Connection closed by foreign host.
Tomcat设置
1.TomcatA B 安装
参照tomcat基本安装
2.上传jar文件
分别把依赖包上传到 Tomcat A B
]# pwd
/usr/local/tomcat/lib
http://s3.运维网.com/wyfs02/M00/75/4A/wKiom1Y0kAqg51xoAABig1uJ1l0141.jpg
3.TomcatA 设置
3.1创建目录
# mkdir -pv/usr/local/tomcat/webapps/test/WEB-INF/{classes,lib}
mkdir: created directory`/usr/local/tomcat/webapps/test'
mkdir: created directory`/usr/local/tomcat/webapps/test/WEB-INF'
mkdir: created directory`/usr/local/tomcat/webapps/test/WEB-INF/classes'
mkdir: created directory`/usr/local/tomcat/webapps/test/WEB-INF/lib'
修改权限
# chown -R tomcat /usr/local/tomcat/webapps/test/
3.2 创建主页内容
]#vim/usr/local/tomcat/webapps/test/index.jsp
TomcatA
TomcatA.zrd.com
Session ID
Created on
3.3 修改server.xml
高亮部分为 添加的内容其他不要修改
# vim/usr/local/tomcat/conf/server.xml
4.TomcatB 设置
4.1创建目录
# mkdir -pv/usr/local/tomcat/webapps/test/WEB-INF/{classes,lib}
mkdir: created directory`/usr/local/tomcat/webapps/test'
mkdir: created directory`/usr/local/tomcat/webapps/test/WEB-INF'
mkdir: created directory `/usr/local/tomcat/webapps/test/WEB-INF/classes'
mkdir: created directory`/usr/local/tomcat/webapps/test/WEB-INF/lib'
4.2创建主页内容
#]vim/usr/local/tomcat/webapps/test/index.jsp
TomcatB
TomcatB.zrd.com
Session ID
Created on
4.3 修改server.xml
添加高亮部分内容,其他不用改动
# vim/usr/local/tomcat/conf/server.xml
proxy设置
使用nginx作为反向代理服务器
1.安装
需要配置epel源(http://mirrors.sohu.com/fedora-epel/6/x86_64/)
yum install nginx
2.修改配置文件
高亮部分为添加的内容,其他不动
# cat/etc/nginx/nginx.conf
# For more information on configuration,see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes1;
error_log /var/log/nginx/error.log;
#error_log/var/log/nginx/error.lognotice;
#error_log/var/log/nginx/error.loginfo;
pid /run/nginx.pid;
events {
worker_connections1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_formatmain'$remote_addr - $remote_user [$time_local]"$request" '
'$status $body_bytes_sent"$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.logmain;
sendfile on;
#tcp_nopush on;
#keepalive_timeout0;
keepalive_timeout65;
#gzipon;
# Load modular configuration files from the /etc/nginx/conf.ddirectory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
index index.html index.htm;
upstream tomcats {
# ip_hash;
server 192.168.1.150:8080;
server 192.168.1.160:8080;
}
server {
listen 80;
server_namelocalhost;
root /usr/share/nginx/html;
#charset koi8-r;
#access_log/var/log/nginx/host.access.logmain;
location / {
proxy_pass http://tomcats/;
}
# redirect server error pages to the static page /40x.html
#
error_page404 /404.html;
location = /40x.html {
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503504/50x.html;
location = /50x.html {
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_indexindex.php;
# fastcgi_paramSCRIPT_FILENAME/scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# denyall;
#}
}
# another virtual host using mix of IP-, name-, and port-basedconfiguration
#
#server {
# listen 8000;
# listen somename:8080;
# server_namesomename aliasanother.alias;
# root html;
# location / {
# }
#}
# HTTPS server
#
#server {
# listen 443;
# server_namelocalhost;
# root html;
# ssl on;
# ssl_certificate cert.pem;
# ssl_certificate_keycert.key;
# ssl_session_timeout5m;
# ssl_protocolsSSLv2 SSLv3 TLSv1;
# ssl_ciphersHIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# }
#}
}
测试
启动服务
memcached
# service memcachedstart
Starting memcached:
# service memcachedstart
Starting memcached:
Tomcat
# service tomcat start
# service tomcat start
nginx
# service nginx start
轮询测试
http://s3.运维网.com/wyfs02/M00/75/47/wKioL1Y0kHWwx4DkAADnZUzG4Qo180.jpg
http://s3.运维网.com/wyfs02/M01/75/4A/wKiom1Y0kFyBK-cuAADgJcxh-10432.jpg
关闭Memcached2,故障转移是否成功
# service memcached stop
Stopping memcached:
故障转移到Memcached1成功
http://s3.运维网.com/wyfs02/M01/75/47/wKioL1Y0kMjQKeNiAAGkhFVqryc758.jpg
配置文件
TomcatA B
http://blog.运维网.com/e/u261/themes/default/images/spacer.gifhttp://blog.运维网.com/e/u261/themes/default/images/spacer.gif
nginx
http://blog.运维网.com/e/u261/themes/default/images/spacer.gif
附件:http://down.运维网.com/data/2366273
页:
[1]