單點登錄(cas)、緩存技術與負載均衡
基于動態緩存的電子商務優化
針對電子商務網站的特點和性能要求,在Web服務器前端設置動態緩存服務器,作為Web服務器的前置機,實現動態內容的緩存,加快了響應用戶訪問的速度;通過一定的替換和更新策略保證用戶訪問到最新的內容,對提高Web服務器峰值負載下的運行能力,減少訪問動態內容的延遲時間起到優化作用。
參考文獻:http://www.docin.com/p-152105671.html
《基于動態緩存的電子商務平臺優化研究》
集群與負載均衡
welcome to use these PowerPoint templates, New Content design, 10 years experience
集群 Cluster
概念:
一組獨立的計算機系統構成 一個松耦合的多處理器系統,他們之間通過網絡實現進程間的通信。應用程序之間可以通過網絡共享內存信息消息傳送。實現分布式計算。
集群與負載均衡
welcome to use these PowerPoint templates, New Content design, 10 years experience
負載均衡Load balance
概念:
網絡的負載均衡是一種動態均衡技術。基于現有的網絡結構,提供了一種擴展服務器帶寬和增加服務器吞吐量的廉價有效方法。提高了數據的處理能力、靈活性和可用性。
特點:
(1)高可靠性(HA)。利用集群管理軟件,當主服務器故障時,備份服務器能夠自動接管主服務器的工作,并及時切換過去,以實現對用戶的不間斷服務。 (2)高性能計算(HP)。即充分利用集群中的每一臺計算機的資源,實現復雜運算的并行處理。 (3)負載平衡。即把負載壓力根據某種算法合理分配到集群中的每一臺計算機上,以減輕主服務器的壓力,降低對主服務器的硬件和軟件要求。
網羅天下實施策略
總體網絡架構圖
Nginx代理RedisCluster Tomcat1Cluster Tomcat2Mysql MusterMysql SlaveFTP應用服務器集群MysqlDB 主從緩存服務器5Web 服務器1PC1以太網2數據庫服務器1通信鏈路1智能手機1云1便攜電腦1平板電腦1防火墻1FTP 服務器.191代理服務器.14符號計數說明單位說明圖例Cluster Tomcat3Cluster Tomcat4
網羅天下實施策略 設計原理
Nginx:服務的代理與客戶端請求與分發。SSL證書的配置。80及443端口的監聽。
Redis:動態緩存服務器,Session共享。
Tomcat:Web應用服務器集群。
JbossCache:單點登錄票據的共享。
關鍵技術
Nginx 安裝
安裝nginx,下載下面的插件安裝,否則nginx無法識別tomcat中jvmRoute,從而無法達到session復制的效果。
tar xzf nginx-upstream-jvm-route-0.1.tar.gz
tar xzf nginx-1.0.5.tar.gz
Nginx 配置
1、 nginx.conf中http{}中配置upstream wlotx {
ip_hash;
server 192.168.1.218:8080;#Tomcat1
server 192.168.1.219:8080; #Tomcat2
}
關鍵技術
Nginx 配置
2、 Server 80端口選段:
server {
listen 80;
server_name buseniss.wlotx.com;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
index index.html index.htm index.jsp;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 3;
proxy_send_timeout 30;
proxy_read_timeout 30;
proxy_pass http://wlotx;
}
關鍵技術
Nginx 配置
3、 HTTPS 443端口 Server 選段:
server {
listen 443;
server_name cas.wlotx.com;
ssl on;
ssl_certificate /usr/local/nginx/conf/server.crt;
ssl_certificate_key /usr/local/nginx/conf/server.key;
ssl_session_timeout 5m;
ssl_protocols SSLv3 TLSv1;
ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
ssl_prefer_server_ciphers on;
location / {
root html;
index index.html index.htm;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_connect_timeout 3;
proxy_send_timeout 30;
proxy_read_timeout 30;
proxy_pass http://wlotx;
}
}
關鍵技術
Redis安裝及配置
daemonize yes
pidfile /usr/local/redis/var/redis.pid
port 6379
timeout 300
loglevel debug
logfile /usr/local/redis/var/redis.log
databases 16
save 900 1
save 300 10
save 60 10000
rdbcompression yes
dbfilename dump.rdb
dir /usr/local/redis/var/
appendonly no
appendfsync always
glueoutputbuf yes
shareobjects no
shareobjectspoolsize 1024
關鍵技術 Redis安裝及配置
?將上面內容寫為redis.conf并保存到/usr/local/redis/etc/目錄下。
?然后在命令行執行: /usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf
?即可在后臺啟動redis服務,這時通過 telnet 127.0.0.1 6379 可查看redis的服務狀態。
關鍵技術
JBossCacheTicketRegistry+組播
由于單點登錄系統的特殊性,不能簡單使用session復制技術來實現多服務器間的登錄信息共享。
JBossCacheTicketRegistry提供了針對單點登錄系統集群的共享策略。
在cas項目工程里spring-configuration/ticketRegistry.xml文件里面的DefaultTicketRegistry換成JBossCacheTicketRegistry緩存 ;在class文件里添加jbossCache.xml文件添加jboss的緩存配置。
jbossCache.xml中依賴組播。
<attribute name="ClusterConfig">
<config>
<UDP mcast_addr="224.0.0.8" mcast_port="48866"
ip_ttl="32" ip_mcast="true"
bind_addr="192.168.1.219"
關鍵技術
Tomcat Cluster 安裝
安裝tomcat
tar zxf apache-tomcat-6.0.29.tar.gz
mv apache-tomcat-6.0.29/usr/local/tomcat
cp tomcat-replication.jar /usr/local/tomcat/lib
在另一臺機器上安裝tomcat_2,步驟同1
分別在tomcat服務器安裝jdk
chmod 755 jdk-6u26-linux-i586-rpm.bin
./jdk-6u26-linux-i586-rpm.bin
cat >>/etc/profile <<EOF
export JAVA_HOME=/usr/java/jdk1.6.0_26
export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH:$HOMR/bin
EOF;
source /etc/profile //使環境變量立即生效
關鍵技術
Tomcat Cluster 配置1
<Connector port="8443" className="org.apache.coyote.http11.Http11Protocol"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="true" disableUploadTimeout="true"
cceptCount="100" scheme="https" secure="true"
SSLEnabled="true" clientAuth="false"
keystoreFile="wlotx2012" keystorePass="wlotx2012"
sslProtocol="TLS"
truststorefile="%JAVA_HOME%/jre/lib/security/cacerts" truststoretype="JKS" truststorepass="changeit"
/>
關鍵技術
Tomcat Cluster 配置2
<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat1">
<Valve className="org.apache.catalina.valves.RemoteIpValve" remoteIpHeader="X-Forwarded-For" protocolHeader="X-Forwarded-Proto" protocolHeaderHttpsValue="https"/>
注:標紅部分為Nginx和TomcatSSL請求間的證書轉化。
關鍵技術
Tomcat Cluster 配置3
基于JBossCache的單點登錄系統Tomcat配置:
<Host name="cas.wlotx.com" appBase="/data/www"
unpackWARs="true" autoDeploy="false" deployOnStartup="false">
<Context path="" docBase="/data/www/cas" reloadable="true" distributable="true">
</Context>
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="cas_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
關鍵技術
Tomcat Cluster 配置4
基于Redis session 共享的應用系統配置:
<Host name="edu.wlotx.com" appBase="/data/www"
unpackWARs="true" autoDeploy="false" distributable="true">
<Context path="" docBase="/data/www/teachmysql" reloadable="true" distributable="true">
<Valve className="com.radiadesign.catalina.session.RedisSessionHandlerValve" />
<Manager className=“com.radiadesign.catalina.session.RedisSessionManager” host="192.168.1.218"
port="6379" database="0" maxInactiveInterval="600" />
</Context>
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="edu_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
關鍵技術
Nginx+Tomcat+SSL
實際上,大規模的網站都有很多臺Web服務器和應用服務器組成,用戶的請求可能是經由 Varnish、HAProxy、Nginx之后才到應用服務器,中間有好幾層。而中小規模的典型部署常見的是 Nginx+Tomcat 這種兩層配置,而Tomcat 會多于一臺,Nginx 作為靜態文件處理和負載均衡。
如果Nginx作為前端代理的話,則Tomcat根本不需要自己處理 https,全是Nginx處理的。用戶首先和Nginx建立連接,完成SSL握手,而后Nginx 作為代理以 http 協議將請求轉給 tomcat 處理,Nginx再把 tomcat 的輸出通過SSL 加密發回給用戶,這中間是透明的,Tomcat只是在處理 http 請求而已。因此,這種情況下不需要配置 Tomcat 的SSL,只需要配置 Nginx 的SSL 和 Proxy。