标签:dex 组合 nload 后台 gets host name 数据 根据 load
Redis与Memcached的区别:
内存利用率:使用简单的key-value存储的话,Memcached的内存利用率更高,而如果Redis采用hash结构来做key-value存储,由于其组合式的压缩,其内存利用率会高于Memcached。
性能对比:由于Redis只使用单核,而Memcached可以使用多核,所以平均每一个核上Redis在存储小数据时比Memcached性能更高。而在100k以上的数据中,Memcached性能要高于Redis,虽然Redis最近也在存储大数据的性能上进行优化,但是比起Memcached,还是稍有逊色。
Redis支持数据的持久化,可以将内存中的数据保持在磁盘中,重启的时候可以再次加载进行使用
Redis支持数据的备份,即master-slave模式的数据备份。
Redis不仅仅支持简单的key-Value类型的数据,同时还提供list,set,zset,hash等数据结构的存储。
nginx: 192.168.4.4
tomcat-1: 192.168.4.5
tomcat-2: 192.168.4.6
redis-1: 192.168.4.7
redis-2: 192.168.4.8
vip:192.168.4.100
[root@nginx ~]# yum -y install zlib-devel pcre-devel openssl-devel
[root@nginx ~]# tar xf nginx-1.6.2.tar.gz
[root@nginx ~]# cd nginx-1.6.2
[root@nginx nginx-1.6.2]# ./configure && make && make install
[root@nginx nginx-1.6.2]# cd
[root@nginx ~]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
[root@nginx ~]# vim /usr/local/nginx/conf/nginx.conf
…
33 gzip on;
upstream backend {
server 192.168.4.5:8080 weight=1 max_fails=1 fail_timeout=10s;
server 192.168.4.6:8080 weight=1 max_fails=1 fail_timeout=10s;
}
39 server {
40 listen 80;
41 server_name localhost;
42
43 #charset koi8-r;
44
45 #access_log logs/host.access.log main;
46
47 location / {
48 root html;
49 index index.html index.htm;
proxy_pass http://backend;
51 }
…
[root@nginx ~]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@nginx ~]# nginx && netstat -anpt |grep :80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 4123/nginx
[root@tomcat-1 ~]# tar xf jdk-7u65-linux-x64.gz
[root@tomcat-1 ~]# mv jdk1.7.0_65 /usr/local/java
[root@tomcat-1 ~]# vim /etc/profile.d/java.sh
export JAVA_HOME=/usr/local/java
export PATH=$PATH:$JAVA_HOME/bin
[root@tomcat-1 ~]# source /etc/profile.d/java.sh
[root@tomcat-1 ~]# tar xf apache-tomcat-7.0.54.tar.gz
[root@tomcat-1 ~]# mv apache-tomcat-7.0.54 /usr/local/tomcat
[root@tomcat-2 ~]# cp tomcat-redis-session-manage-tomcat7.jar tomcat-juli.jar commons-logging-1.1.3.jar commons-pool2-2.2.jar jedis-2.5.2.jar /usr/local/tomcat/lib
[root@tomcat-1 ~]# vim /usr/local/tomcat/conf/context.xml
<Context>
…
<Valve className="com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve" />
<Manager className="com.orangefunction.tomcat.redissessions.RedisSessionManager"
host="192.168.4.7" #redis1的ip
port="6379"
database="0"
maxInactiveInterval="60" />
</Context>
[root@tomcat-1 ~]# vim /usr/local/tomcat/conf/server.xml
124 <Host name="localhost" appBase="webapps"
125 unpackWARs="true" autoDeploy="true">
<Context docBase="/web/webapp" path="" reloadable="false" >
</Context>
[root@tomcat-1 ~]# mkdir -p /web/webapp
[root@tomcat-1 ~]# cd /web/webapp
[root@tomcat-1 webapp]# vim index.jsp
Session ID:<%= session.getId() %><BR>
SessionPort:<%= request.getServerPort() %>
<% out.println("This tomcat server 192.168.4.5");%> #tomcat2改成192.168.4.6
[root@tomcat-1 ~]# /usr/local/tomcat/bin/startup.sh
[root@tomcat-1 ~]# netstat -anpt |grep :8080
tcp 0 0 :::8080 :::* LISTEN 26474/java
http://download.redis.io/releases/
1和2 安装方式一样,修改的配置文件不一样(下面看)
[root@reids-1 ~]# tar xf redis-3.2.5.tar.gz
[root@reids-1 ~]# cd redis-3.2.5
[root@reids-1 redis-3.2.5]# make
这里如果报错,tclsh8.5: not found 发现少了tcl 报错
解决方法:下载,安装tcl
#wget http://downloads.sourceforge.net/tcl/tcl8.5.9-src.tar.gz
#cd /tcl8.5.9-src/unix
#./configure
#make
#make install
接着make && make install 就没报错了
[root@reids-1 ~]# mkdir -p /usr/local/redis/bin
[root@reids-1 ~]# mkdir -p /usr/local/redis/etc
[root@reids-1 ~]# mkdir -p /usr/local/redis/var
src目录下这些文件作用如下
redis-server:Redis服务器的daemon启动程序
redis-cli:Redis命令行操作工具.你也可以用telnet根据其纯文本协议来操作
redis-benchmark:Redis性能测试工具,测试Redis在你的系统及你的配置下的读写性能.
redis-stat:Redis状态检测工具,可以检测Redis当前状态参数及延迟状况
[root@reids-1 redis-3.2.5]# cd src/
[root@reids-1 src]# cp redis-benchmark redis-check-aof redis-cli redis-server /usr/local/redis/bin/
[root@reids-1 src]# cp ../redis.conf /usr/local/redis/etc
[root@reids-1 ~]# vim /usr/local/redis/etc/redis.conf
128 daemonize yes #是否把redis-server启动在后台,默认是“否”。若改成yes,会生成一个pid
61 bind 0.0.0.0 #任意主机都可以访问
[root@reids-1 ~]# killall -9 redis-server
[root@reids-1 ~]# /usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf
[root@reids-1 ~]# netstat -anpt |grep :6379
tcp 0 0 0.0.0.0:6379 0.0.0.0:* LISTEN 29516/redis-server
[root@reids-1 ~]# redis-cli -p 6379 monitor
OK
…
测试:访问192.168.4.4
发现测试页面发生变化, 变得是ip sessionid不变
[root@redis-2 src]# vim /usr/local/redis/etc/redis.conf
128 daemonize yes
61 bind 0.0.0.0
265 # slaveof <masterip> <masterport>
slaveof 192.168.4.7 6379 #填写redis-1的ip和端口,同步redis-1的信息
[root@redis-2 ~]# /usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf
[root@redis-2 ~]# netstat -anpt |grep redis
tcp 0 0 0.0.0.0:6379 0.0.0.0:* LISTEN 29517/redis-server
tcp 0 0 192.168.4.8:42173 192.168.4.7:6379 ESTABLISHED 29517/redis-server
测试主从复制
[root@reids-1 ~]# /usr/local/redis/bin/redis-cli -h 192.168.4.7
192.168.4.7:6379> set name zhangsan
OK
[root@redis-2 ~]# /usr/local/redis/bin/redis-cli -h 192.168.4.8
192.168.4.8:6379> get name
"zhangsan"
两台安装方式一样,配置文件不一样
[root@reids-1 ~]# yum -y install keepalived
[root@reids-1 ~]# chkconfig keepalived --add
[root@reids-1 ~]# chkconfig keepalived on
[root@reids-1 ~]# vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
calabash@163.com
}
notification_email_from aaa@163.com
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id f-1 #将redis-2改为他的的标识
}
vrrp_script redis {
script /opt/chk_redis.sh
interval 2
weight -10
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
track_script {
redis
}
virtual_ipaddress {
192.168.4.100 #vip
}
}
[root@reids-1 ~]# /etc/init.d/keepalived start
[root@reids-1 ~]# vim /opt/check_redis.sh
#!/bin/bash
# check redis server st="/usr/local/nginx/sbin/nginx"
REDIS="/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf"
redispid=$(ps -C redis-server --no-header |wc -l)
if [ $redispid -eq 0 ];then
$REDIS
sleep 3
redispid=$(ps -C redis-server --no-header |wc -l)
if [ $redispid -eq 0 ];then
/etc/init.d/keepalived stop
echo "Keepalived stopped ,please check your redis !"|tee -a /var/log/messages
fi
fi
将redis的ip地址改为vip的ip地址,以支持vip漂移
[root@tomcat-1 ~]# vim /usr/local/tomcat/conf/context.xml
…..
36 host="192.168.4.100" # 将192.168.4.7改为 192.168.4.100
……
[root@reids-1 ~]# /etc/init.d/keepalived stop
Stopping keepalived: [ OK ]
[root@reids-1 ~]# killall -9 redis-server
测试vip漂移:
查看redis-2
测试session id主从复制:
nginx+tomcat+redis sesson id主从复制
标签:dex 组合 nload 后台 gets host name 数据 根据 load
原文地址:http://www.cnblogs.com/calabash/p/7707228.html