redis缓存服务器(Nginx+Tomcat+redis+MySQL实现session会话共享)

一、redis介绍

redis是一个key-value存储系统。和Memcached类似,它支持存储的value类型相对更多,包括string(字符串)、list(链表)、set(集合)、zset(sorted set --有序集合)和hash(哈希类型)。与memcached一样,为了保证效率,数据都是缓存在内存中。区别的是redis会周期性的把更新的数据写入磁盘或者把修改操作写入追加的记录文件,并且在此基础上实现master-slave(主从)同步。

Redis是一个高性能的key-value数据库。redis的出现,很大程度补偿了memcached这类key/value存储的不足,在部分场合可以对关系数据库起到很好的补充作用。它提供了Java,C/C++,C#,PHP,JavaScript,Perl,Object-C,Python,Ruby等客户端,使用很方便。

如果简单地比较Redis与Memcached的区别,基本上有以下3点:
1、Redis不仅仅支持简单的k/v类型的数据,同时还提供list,set,zset,hash等
数据结构的存储。
2、Redis支持数据的备份,即master-slave模式的数据备份。
3、Redis支持数据的持久化,可以将内存中的数据保持在磁盘中,重启的时候可以再次加载进行使用。

在Redis中,并不是所有的数据都一直存储在内存中的。这是和Memcached相比一个最大的区别。Redis只会缓存所有的key的信息,如果Redis发现内存的使用量超过了某一个阀值,将触发swap的操作,Redis根据“swappability = age*log(size_in_memory)”计算出哪些key对应的value需要swap到磁盘。然后再将这些key对应的value持久化到磁盘中,同时在内存中清除。这种特性使得Redis可以保持超过其机器本身内存大小的数据。当然,机器本身的内存必须要能够保持所有的key,因为这些数据是不会进行swap操作的。

当从Redis中读取数据的时候,如果读取的key对应的value不在内存中,那么Redis就需要从swap文件中加载相应数据,然后再返回给请求方。

memcached和redis的比较

1、网络IO模型

Memcached是多线程,非阻塞IO复用的网络模型,分为监听主线程和worker子线程,监听线程监听网络连接,接受请求后,将连接描述字pipe 传递给worker线程,进行读写IO, 网络层使用libevent封装的事件库,多线程模型可以发挥多核作用。

Redis使用单线程的IO复用模型,自己封装了一个简单的AeEvent事件处理框架,主要实现了epoll、kqueue和select,对于单纯只有IO操作来说,单线程可以将速度优势发挥到最大,但是Redis也提供了一些简单的计算功能,比如排序、聚合等,对于这些操作,单线程模型实际会严重影响整体吞吐量,CPU计算过程中,整个IO调度都是被阻塞住的。

2、内存管理方面

Memcached使用预分配的内存池的方式,使用slab和大小不同的chunk来管理内存,value根据大小选择合适的chunk存储。Redis使用现场申请内存的方式来存储数据。

3、存储方式及其它方面

Memcached基本只支持简单的key-value存储,不支持持久化和复制等功能,Redis除key/value之外,还支持list,set,sortedset,hash等众多数据结构

 

二、如何保持session会话

目前,为了使web能适应大规模的访问,需要实现应用的集群部署。集群最有效的方案就是负载均衡,而实现负载均衡用户每一个请求都有可能被分配到不固定的服务器上,这样我们首先要解决session的统一来保证无论用户的请求被转发到哪个服务器上都能保证用户的正常使用,即需要实现session的共享机制。

在集群系统下实现session统一的有如下几种方案:

1、请求精确定位:sessionsticky,例如基于访问ip的hash策略,即当前用户的请求都集中定位到一台服务器中,这样单台服务器保存了用户的session登录信息,如果宕机,则等同于单点部署,会丢失,会话不复制。

2、session复制共享:sessionreplication,如tomcat自带session共享,主要是指集群环境下,多台应用服务器之间同步session,使session保持一致,对外透明。 如果其中一台服务器发生故障,根据负载均衡的原理,调度器会遍历寻找可用节点,分发请求,由于session已同步,故能保证用户的session信息不会丢失,会话复制,。

此方案的不足之处:

必须在同一种中间件之间完成(如:tomcat-tomcat之间).

session复制带来的性能损失会快速增加.特别是当session中保存了较大的对象,而且对象变化较快时, 性能下降更加显著,会消耗系统性能。这种特性使得web应用的水平扩展受到了限制。

Session内容通过广播同步给成员,会造成网络流量瓶颈,即便是内网瓶颈。在大并发下表现并不好

3、基于cache DB缓存的session共享

基于memcache/redis缓存的 session 共享

即使用cacheDB存取session信息,应用服务器接受新请求将session信息保存在cache DB中,当应用服务器发生故障时,调度器会遍历寻找可用节点,分发请求,当应用服务器发现session不在本机内存时,则去cache DB中查找,如果找到则复制到本机,这样实现session共享和高可用。

 redis缓存服务器(Nginx+Tomcat+redis+MySQL实现session会话共享)_第1张图片

三、nginx+tomcat+redis实现负载均衡、session共享

1、实验环境

 

主机

操作系统

IP地址

Nginx

Centos7.2

192.168.31.141

Tomcat-1

192.168.31.83

Tomcat-2

192.168.31.250

Mysql

192.168.31.225

Redis

192.168.31.106

 

2、实验拓扑

 

在这个图中,nginx做为反向代理,实现静动分离,将客户动态请求根据权重随机分配给两台tomcat服务器,redis做为两台tomcat的共享session数据服务器,mysql做为两台tomcat的后端数据库。

3、nginx安装配置

使用Nginx作为Tomcat的负载平衡器,Tomcat的会话Session数据存储在Redis,能够实现零宕机的7x24效果。因为将会话存储在Redis中,因此Nginx就不必配置成stick粘贴某个Tomcat方式,这样才能真正实现后台多个Tomcat负载平衡。

安装nginx:

安装zlib-devel、pcre-devel等依赖包

1
[root@www ~] # yum -y install gccgcc-c++ make libtoolzlibzlib-develpcrepcre-developensslopenssl-devel

注:

结合proxy和upstream模块实现后端web负载均衡

结合nginx默认自带的ngx_http_proxy_module模块 和ngx_http_upstream_module模块实现后端服务器的健康检查

创建nginx程序用户

1
[root@www ~] # useradd -s /sbin/nologin www

编译安装nginx

[root@www ~]# tar zxf nginx-1.10.2.tar.gz

1
2
3
4
[root@www ~] # cd nginx-1.10.2/
[root@www nginx-1.10.2] # ./configure --prefix=/usr/local/nginx1.10 --user=www --group=www --with-http_stub_status_module --with-http_realip_module --with-http_ssl_module
--with-http_gzip_static_module  --with-pcre  --with-http_flv_module
[root@www nginx-1.10.2] # make&& make install

优化nginx程序的执行路径

1
2
3
4
[root@www nginx-1.10.2] # ln -s /usr/local/nginx1.10/sbin/nginx /usr/local/sbin/
[root@www nginx-1.10.2] # nginx -t
nginx: the configuration  file  /usr/local/nginx1 .10 /conf/nginx .conf syntax is ok
nginx: configuration  file  /usr/local/nginx1 .10 /conf/nginx .conf  test  is successful

编写nginx服务脚本:脚本内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
[root@www ~] # cat /etc/init.d/nginx
#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# chkconfig: - 85 15
# pidfile: /usr/local/nginx1.10/logs/nginx.pid
# config: /usr/local/nginx1.10/conf/nginx.conf
nginxd= /usr/local/nginx1 .10 /sbin/nginx
nginx_config= /usr/local/nginx1 .10 /conf/nginx .conf
nginx_pid= /usr/local/nginx1 .10 /logs/nginx .pid
RETVAL=0
prog= "nginx"
# Source function library.
/etc/rc .d /init .d /functions
# Start nginx daemons functions.
start() {
if  [ -f $nginx_pid ] ;  then
echo  "nginx already running...."
exit  1
fi
echo  -n  "Starting $prog: "
    $nginxd -c ${nginx_config}
    RETVAL=$?
[ $RETVAL = 0 ] &&  touch  /var/lock/subsys/nginx
}
# Stop nginx daemons functions.
stop() {
echo  -n  "Stopping $prog: "
         $nginxd -s stop
         RETVAL=$?
[ $RETVAL = 0 ] && rm  -f  /var/lock/subsys/nginx
}
# reloadnginx service functions.
reload() {
echo  -n  "Reloading $prog: "
     $nginxd -s reload
}
# statusngnx service functions
status() {
if  [ -f $nginx_pid ] ;  then
echo   "$prog is running"
else
echo   "$prog is stop"
fi
}
case  "$1"  in
start)
start
         ;;
stop)
stop
         ;;
reload)
reload
         ;;
restart)
stop
start
         ;;
status)
status
         ;;
*)
echo  "Usage: $prog {start|stop|restart|reload|status}"
exit  1
         ;;
esac
[root@www ~] # chmod +x /etc/init.d/nginx
[root@www ~] # chkconfig --add nginx
[root@www ~] # chkconfignginx on
[root@www ~] # systemctl daemon-reload

配置nginx反向代理:反向代理+负载均衡+健康探测,nginx.conf文件内容:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
[root@www ~] # cat /usr/local/nginx1.10/conf/nginx.conf
user  wwwwww;
worker_processes  4;
worker_cpu_affinity 0001 0010 0100 1000;
error_log  logs /error .log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
worker_rlimit_nofile 10240;
pid        logs /nginx .pid;
events {
useepoll;
worker_connections  4096;
}
http {
includemime.types;
default_type  application /octet-stream ;
log_format  main   '$remote_addr - $remote_user [$time_local] "$request" '
                       '$status $body_bytes_sent "$http_referer" '
                       '"$http_user_agent" "$http_x_forwarded_for"' ;
access_log  logs /access .log  main;
server_tokens off;
sendfile        on;
tcp_nopush     on;
     #keepalive_timeout  0;
keepalive_timeout  65;
     #Compression Settings
gzip  on;
gzip_comp_level 6;
gzip_http_version 1.1;
gzip_proxied any;
gzip_min_length 1k;
gzip_buffers 16 8k;
gzip_types text /plain  text /css  text /javascript  application /json  application /javascript  application /x-javascript  application /xml ;
gzip_vary on;
     #end gzip
     # http_proxy Settings
client_max_body_size   10m;
client_body_buffer_size   128k;
proxy_connect_timeout   75;
proxy_send_timeout   75;
proxy_read_timeout   75;
proxy_buffer_size   4k;
proxy_buffers   4 32k;
proxy_busy_buffers_size   64k;
proxy_temp_file_write_size  64k;
     #load balance Settings
upstreambackend_tomcat {
server 192.168.31.83:8080 weight=1 max_fails=2 fail_timeout=10s;
server 192.168.31.250:8080 weight=1 max_fails=2 fail_timeout=10s;
     }
     #virtual host Settings
server {
listen       80;
server_name  www.benet.com;
charset utf-8;
location / {
root html;
index  index.jsp index.html index.htm;
         }
location ~* \.(jsp| do )$ {
proxy_pass  http: //backend_tomcat ;
proxy_redirect off;
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_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
         }
location  /nginx_status  {
stub_status on;
access_log off;
allow 192.168.31.0 /24 ;
deny all;
         }
     }
}

重启nginx服务,使修改生效

1
[root@www ~] # service  nginx restart

配置防火墙规测

1
2
3
4
[root@www ~] # firewall-cmd --permanent --add-port=80/tcp
success
[root@www ~] # firewall-cmd --reload 
success

4、安装部署tomcat应用程序服务器

在tomcat-1和tomcat-2节点上安装JDK

在安装tomcat之前必须先安装JDK,JDK的全称是java  development kit,是sun公司免费提供的java语言的软件开发工具包,其中包含java虚拟机(JVM),编写好的java源程序经过编译可形成java字节码,只要安装了JDK,就可以利用JVM解释这些字节码文件,从而保证了java的跨平台性。

安装JDK,配置java环境:

将jdk-7u65-linux-x64.gz解压

1
[root@tomcat-1 ~] # tar zxf jdk-7u65-linux-x64.gz

将解压的jdk1.7.0_65目录移致动到/usr/local/下并重命名为java

1
[root@tomcat-1 ~] # mv jdk1.7.0_65/ /usr/local/java

在/etc/profile文件中添加内容如下:

1
2
export  JAVA_HOME= /usr/local/java
export  PATH=$JAVA_HOME /bin :$PATH

通过source命令执行profile文件,使其生效。

1
2
3
[root@tomcat-1 ~] # source /etc/profile
[root@tomcat-1 ~] # echo $PATH
/usr/local/java/bin : /usr/local/sbin : /usr/local/bin : /usr/sbin : /usr/bin : /root/bin

按照相同方法在tomcat-2也安装JDK

分别在在tomcat-1和tomcat-2节点运行java  -version命令查看java版本是否和之前安装的一致。

1
2
3
4
[root@tomcat-1 ~] # java -version
java version  "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

至此java环境已经配置完成

在tomcat-1和tomcat-2节点安装配置tomcat

解压apache-tomcat-7.0.54.tar.gz包

1
[root@tomcat-1 ~] # tar zxf apache-tomcat-7.0.54.tar.gz

将解压生成的文件夹移动到/usr/local/下,并改名为tomcat7

1
[root@tomcat-1 ~] # mv apache-tomcat-7.0.54 /usr/local/tomcat7

配置tomcat环境变量

/etc/profile文件内容如下:

1
2
3
export  JAVA_HOME= /usr/local/java
export  CATALINA_HOME= /usr/local/tomcat7
export  PATH=$JAVA_HOME /bin :$CATALINA_HOME /bin :$PATH

通过source命令执行profile文件,使其生效。

1
2
3
[root@tomcat-1 ~] # source /etc/profile
[root@tomcat-1 ~] # echo $PATH
/usr/local/java/bin : /usr/local/tomcat7/bin : /usr/local/java/bin : /usr/local/sbin : /usr/local/bin : /usr/sbin : /usr/bin : /root/bin

查看tomcat的版本信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
[root@tomcat-1 ~] # catalina.sh version
Using CATALINA_BASE:    /usr/local/tomcat7
Using CATALINA_HOME:    /usr/local/tomcat7
Using CATALINA_TMPDIR:  /usr/local/tomcat7/temp
Using JRE_HOME:         /usr/local/java
Using CLASSPATH:        /usr/local/tomcat7/bin/bootstrap .jar: /usr/local/tomcat7/bin/tomcat-juli .jar
Server version: Apache Tomcat /7 .0.54
Server built:   May 19 2014 10:26:15
Server number:  7.0.54.0
OS Name:        Linux
OS Version:     3.10.0-327.el7.x86_64
Architecture:   amd64
JVM Version:    1.7.0_65-b17
JVM Vendor:     Oracle Corporation
启动tomcat
[root@tomcat-1 ~] # /usr/local/tomcat7/bin/startup.sh 
Using CATALINA_BASE:    /usr/local/tomcat7
Using CATALINA_HOME:    /usr/local/tomcat7
Using CATALINA_TMPDIR:  /usr/local/tomcat7/temp
Using JRE_HOME:         /usr/local/java
Using CLASSPATH:        /usr/local/tomcat7/bin/bootstrap .jar: /usr/local/tomcat7/bin/tomcat-juli .jar
Tomcat started.

Tomcat默认运行在8080端口,运行netstat命令查看8080端口监听的信息

1
2
3
[root@tomcat-1 ~] # netstat -anpt | grep java
tcp6       0      0 :::8009      :::*                    LISTEN      42330 /java          
tcp6       0      0 :::8080      :::*                    LISTEN      42330 /java

防火墙规则配置:

1
2
3
4
[root@tomcat-1 ~] # firewall-cmd --permanent --add-port=8080/tcp
success
[root@tomcat-1 ~] # firewall-cmd --reload
success

按照相同方法在tomcat-2也安装

打开浏览器分别对tomcat-1和tomcat-2访问测试

redis缓存服务器(Nginx+Tomcat+redis+MySQL实现session会话共享)_第2张图片

如果想关闭tomcat则运行/usr/local/tomcat7/bin/shutdown.sh命令

好了,大家可以看到访成功。说明我们的tomcat安装完成,下面我们来修改配置文件

1
2
[root@tomcat-1 ~] # vim /usr/local/tomcat
7 /conf/server .xml

设置默认虚拟主机,并增加jvmRoute

1
"Catalina"  defaultHost= "localhost"  jvmRoute= "tomcat-1" >

修改默认虚拟主机,并将网站文件路径指向/web/webapp1,在host段增加context段

1
2
3
4
"localhost"   appBase= "webapps"
unpackWARs= "true"  autoDeploy= "true" >
"/web/webapp1"  path= ""  reloadable= "true" />
< /Host >

增加文档目录与测试文件

1
2
3
[root@tomcat-1 ~] # mkdir -p /web/webapp1
[root@tomcat-1 ~] # cd /web/webapp1/
[root@ tomcat-1 webapp1] # viindex.jsp

index.jsp内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<%@page language= "java"  import = "java.util.*"  pageEncoding= "UTF-8" %>
< head >
tomcat-1<</code> <code class="bash plain">/title</code> <code class="bash plain">></code> </div> <div class="line number5 index4 alt2"> <code class="bash plain"><</code> <code class="bash plain">/head</code> <code class="bash plain">></code> </div> <div class="line number6 index5 alt1"> <code class="bash plain"><body></code> </div> <div class="line number7 index6 alt2"> <code class="bash plain"><h1><font color=</code> <code class="bash string">"red"</code> <code class="bash plain">>Session serviced by tomcat<</code> <code class="bash plain">/font</code> <code class="bash plain">><</code> <code class="bash plain">/h1</code> <code class="bash plain">></code> </div> <div class="line number8 index7 alt1"> <code class="bash plain"><table aligh=</code> <code class="bash string">"center"</code>  <code class="bash plain">border=</code> <code class="bash string">"1"</code> <code class="bash plain">></code> </div> <div class="line number9 index8 alt2"> <code class="bash plain"><</code> <code class="bash functions">tr</code> <code class="bash plain">></code> </div> <div class="line number10 index9 alt1"> <code class="bash plain"><td>Session ID<</code> <code class="bash plain">/td</code> <code class="bash plain">></code> </div> <div class="line number11 index10 alt2"> <code class="bash plain"><td><%=session.getId() %><</code> <code class="bash plain">/td</code> <code class="bash plain">></code> </div> <div class="line number12 index11 alt1"> <code class="bash plain"><% session.setAttribute(</code> <code class="bash string">"abc"</code> <code class="bash plain">,</code> <code class="bash string">"abc"</code> <code class="bash plain">);%></code> </div> <div class="line number13 index12 alt2"> <code class="bash plain"><</code> <code class="bash plain">/tr</code> <code class="bash plain">></code> </div> <div class="line number14 index13 alt1"> <code class="bash plain"><</code> <code class="bash functions">tr</code> <code class="bash plain">></code> </div> <div class="line number15 index14 alt2"> <code class="bash plain"><td>Created on<</code> <code class="bash plain">/td</code> <code class="bash plain">></code> </div> <div class="line number16 index15 alt1"> <code class="bash plain"><td><%= session.getCreationTime() %><</code> <code class="bash plain">/td</code> <code class="bash plain">></code> </div> <div class="line number17 index16 alt2"> <code class="bash plain"><</code> <code class="bash plain">/tr</code> <code class="bash plain">></code> </div> <div class="line number18 index17 alt1"> <code class="bash plain"><</code> <code class="bash plain">/table</code> <code class="bash plain">></code> </div> <div class="line number19 index18 alt2"> <code class="bash plain"><</code> <code class="bash plain">/body</code> <code class="bash plain">></code> </div> <div class="line number20 index19 alt1"> <code class="bash plain"><html></code> </div> </div> </td> </tr> </tbody> </table> </div> </div> <p class="正文"><strong>停止tomcat运行,检查配置文件并启动tomcat</strong></p> <div> <div id="highlighter_63463" class="syntaxhighlighter bash"> <table border="0"> <tbody> <tr> <td class="gutter"> <div class="line number1 index0 alt2"> 1 </div> <div class="line number2 index1 alt1"> 2 </div> <div class="line number3 index2 alt2"> 3 </div> <div class="line number4 index3 alt1"> 4 </div> <div class="line number5 index4 alt2"> 5 </div> <div class="line number6 index5 alt1"> 6 </div> <div class="line number7 index6 alt2"> 7 </div> <div class="line number8 index7 alt1"> 8 </div> <div class="line number9 index8 alt2"> 9 </div> <div class="line number10 index9 alt1"> 10 </div> <div class="line number11 index10 alt2"> 11 </div> <div class="line number12 index11 alt1"> 12 </div> <div class="line number13 index12 alt2"> 13 </div> <div class="line number14 index13 alt1"> 14 </div> <div class="line number15 index14 alt2"> 15 </div> <div class="line number16 index15 alt1"> 16 </div> <div class="line number17 index16 alt2"> 17 </div> <div class="line number18 index17 alt1"> 18 </div> <div class="line number19 index18 alt2"> 19 </div> <div class="line number20 index19 alt1"> 20 </div> <div class="line number21 index20 alt2"> 21 </div> <div class="line number22 index21 alt1"> 22 </div> <div class="line number23 index22 alt2"> 23 </div> <div class="line number24 index23 alt1"> 24 </div> <div class="line number25 index24 alt2"> 25 </div> <div class="line number26 index25 alt1"> 26 </div> </td> <td class="code"> <div> <div class="line number1 index0 alt2"> <code class="bash plain">[root@tomcat-1 ~]</code> <code class="bash comments"># shutdown.sh</code> </div> <div class="line number2 index1 alt1"> <code class="bash plain">[root@tomcat-1 ~]</code> <code class="bash comments"># netstat -anpt | grep java</code> </div> <div class="line number3 index2 alt2"> <code class="bash plain">[root@tomcat-1 ~]</code> <code class="bash comments"># catalina.shconfigtest</code> </div> <div class="line number4 index3 alt1"> <code class="bash plain">Using CATALINA_BASE:   </code> <code class="bash plain">/usr/local/tomcat7</code> </div> <div class="line number5 index4 alt2"> <code class="bash plain">Using CATALINA_HOME:   </code> <code class="bash plain">/usr/local/tomcat7</code> </div> <div class="line number6 index5 alt1"> <code class="bash plain">Using CATALINA_TMPDIR: </code> <code class="bash plain">/usr/local/tomcat7/temp</code> </div> <div class="line number7 index6 alt2"> <code class="bash plain">Using JRE_HOME:        </code> <code class="bash plain">/usr/local/java</code> </div> <div class="line number8 index7 alt1"> <code class="bash plain">Using CLASSPATH:       </code> <code class="bash plain">/usr/local/tomcat7/bin/bootstrap</code> <code class="bash plain">.jar:</code> <code class="bash plain">/usr/local/tomcat7/bin/tomcat-juli</code> <code class="bash plain">.jar</code> </div> <div class="line number9 index8 alt2"> <code class="bash plain">Nov 16, 2016 1:04:05 AM org.apache.catalina.core.AprLifecycleListenerinit</code> </div> <div class="line number10 index9 alt1"> <code class="bash plain">INFO: The APR based Apache Tomcat Native library </code> <code class="bash functions">which</code>  <code class="bash plain">allows optimal performance </code> <code class="bash keyword">in</code>  <code class="bash plain">production environments was not found on the java.library.path: </code> <code class="bash plain">/usr/java/packages/lib/amd64</code> <code class="bash plain">:</code> <code class="bash plain">/usr/lib64</code> <code class="bash plain">:</code> <code class="bash plain">/lib64</code> <code class="bash plain">:</code> <code class="bash plain">/lib</code> <code class="bash plain">:</code> <code class="bash plain">/usr/lib</code> </div> <div class="line number11 index10 alt2"> <code class="bash plain">Nov 16, 2016 1:04:05 AM org.apache.coyote.AbstractProtocolinit</code> </div> <div class="line number12 index11 alt1"> <code class="bash plain">INFO: Initializing ProtocolHandler [</code> <code class="bash string">"http-bio-8080"</code> <code class="bash plain">]</code> </div> <div class="line number13 index12 alt2"> <code class="bash plain">Nov 16, 2016 1:04:05 AM org.apache.coyote.AbstractProtocolinit</code> </div> <div class="line number14 index13 alt1"> <code class="bash plain">INFO: Initializing ProtocolHandler [</code> <code class="bash string">"ajp-bio-8009"</code> <code class="bash plain">]</code> </div> <div class="line number15 index14 alt2"> <code class="bash plain">Nov 16, 2016 1:04:05 AM org.apache.catalina.startup.Catalina load</code> </div> <div class="line number16 index15 alt1"> <code class="bash plain">INFO: Initialization processed </code> <code class="bash keyword">in</code>  <code class="bash plain">534 ms</code> </div> <div class="line number17 index16 alt2"> <code class="bash plain">[root@tomcat-1 ~]</code> <code class="bash comments"># startup.sh </code> </div> <div class="line number18 index17 alt1"> <code class="bash plain">Using CATALINA_BASE:   </code> <code class="bash plain">/usr/local/tomcat7</code> </div> <div class="line number19 index18 alt2"> <code class="bash plain">Using CATALINA_HOME:   </code> <code class="bash plain">/usr/local/tomcat7</code> </div> <div class="line number20 index19 alt1"> <code class="bash plain">Using CATALINA_TMPDIR: </code> <code class="bash plain">/usr/local/tomcat7/temp</code> </div> <div class="line number21 index20 alt2"> <code class="bash plain">Using JRE_HOME:        </code> <code class="bash plain">/usr/local/java</code> </div> <div class="line number22 index21 alt1"> <code class="bash plain">Using CLASSPATH:       </code> <code class="bash plain">/usr/local/tomcat7/bin/bootstrap</code> <code class="bash plain">.jar:</code> <code class="bash plain">/usr/local/tomcat7/bin/tomcat-juli</code> <code class="bash plain">.jar</code> </div> <div class="line number23 index22 alt2"> <code class="bash plain">Tomcat started.</code> </div> <div class="line number24 index23 alt1"> <code class="bash plain">[root@tomcat-1 ~]</code> <code class="bash comments"># netstat -anpt | grep java</code> </div> <div class="line number25 index24 alt2"> <code class="bash plain">tcp6       0      0 :::8009    :::*                    LISTEN      8180</code> <code class="bash plain">/java</code>            </div> <div class="line number26 index25 alt1"> <code class="bash plain">tcp6       0      0 :::8080    :::*                    LISTEN      8180</code> <code class="bash plain">/java</code> </div> </div> </td> </tr> </tbody> </table> </div> </div> <p class="正文"><strong>Tomcat-2节点与tomcat-1节点配置基本类似,只是jvmRoute不同,另外为了区分由哪个节点提供访问,测试页标题也不同(生产环境两个tomcat服务器提供的网页内容是相同的)。其他的配置都相同。</strong></p> <p class="正文"><strong>用浏览器访问nginx主机,验证负载均衡</strong></p> <p class="正文"><strong>第一次访问的结果</strong></p> <p class="正文"><a href="http://img.e-com-net.com/image/info8/43bf65f4a4a7431a952515ab13fb5fe2.png" target="_blank"><img title="XZGG`3(]IJ7)PARZMSUO4FH.png " src="http://img.e-com-net.com/image/info8/43bf65f4a4a7431a952515ab13fb5fe2.png" alt="redis缓存服务器(Nginx+Tomcat+redis+MySQL实现session会话共享)_第3张图片" width="444" height="167" style="border:1px solid black;"></a></p> <p class="正文"><strong>第二次访问的结果</strong></p> <p class="正文"><a href="http://img.e-com-net.com/image/info8/d877a33483ff4a52a366bbbef227731e.png" target="_blank"><img title="4BJLA`2CNU)YY~9]SU}UQKQ.png " src="http://img.e-com-net.com/image/info8/d877a33483ff4a52a366bbbef227731e.png" alt="redis缓存服务器(Nginx+Tomcat+redis+MySQL实现session会话共享)_第4张图片" width="477" height="167" style="border:1px solid black;"></a></p> <p class="正文"><strong>验证健康检查的方法可以关掉一台tomcat主机,用客户端浏览器测试访问。</strong></p> <p class="正文"><strong>从上面的结果能看出两次访问,nginx把访问请求分别分发给了后端的tomcat-1和tomcat-2,客户端的访问请求实现了负载均衡,但sessionid并一样。所以,到这里我们准备工作就全部完成了,下面我们来配置tomcat通过redis实现会话保持。</strong></p> <p class="正文"><strong>5、安装redis</strong></p> <p class="正文"><strong>下载redis源码,并进行相关操作,如下:</strong></p> <div> <div id="highlighter_30974" class="syntaxhighlighter bash"> <table border="0"> <tbody> <tr> <td class="gutter"> <div class="line number1 index0 alt2"> 1 </div> <div class="line number2 index1 alt1"> 2 </div> </td> <td class="code"> <div> <div class="line number1 index0 alt2"> <code class="bash plain">wget </code> </div> <div class="line number2 index1 alt1"> <code class="bash plain">http:</code> <code class="bash plain">//download</code> <code class="bash plain">.redis.io</code> <code class="bash plain">/releases/redis-3</code> <code class="bash plain">.2.3.</code> <code class="bash functions">tar</code> <code class="bash plain">.gz</code> </div> </div> </td> </tr> </tbody> </table> </div> </div> <p class="正文"><strong>解压安装redis</strong></p> <div> <div id="highlighter_277552" class="syntaxhighlighter bash"> <table border="0"> <tbody> <tr> <td class="gutter"> <div class="line number1 index0 alt2"> 1 </div> </td> <td class="code"> <div> <div class="line number1 index0 alt2"> <code class="bash plain">[root@redis ~]</code> <code class="bash comments"># tar zxf redis-3.2.3.tar.gz</code> </div> </div> </td> </tr> </tbody> </table> </div> </div> <p class="正文"><strong>解压完毕后,现在开始安装,如下:</strong></p> <div> <div id="highlighter_892063" class="syntaxhighlighter bash"> <table border="0"> <tbody> <tr> <td class="gutter"> <div class="line number1 index0 alt2"> 1 </div> <div class="line number2 index1 alt1"> 2 </div> </td> <td class="code"> <div> <div class="line number1 index0 alt2"> <code class="bash plain">[root@redis ~]</code> <code class="bash comments"># cd redis-3.2.3/</code> </div> <div class="line number2 index1 alt1"> <code class="bash plain">[root@redis redis-3.2.3]</code> <code class="bash comments"># make&& make install</code> </div> </div> </td> </tr> </tbody> </table> </div> </div> <p class="正文"><a href="http://img.e-com-net.com/image/info8/7d9a051923ae4eb1a18bcefa49af3155.png" target="_blank"><img title="DL@ZNHMAL$D3~BS{5LE(EDE.png" src="http://img.e-com-net.com/image/info8/7d9a051923ae4eb1a18bcefa49af3155.png" alt="redis缓存服务器(Nginx+Tomcat+redis+MySQL实现session会话共享)_第5张图片" width="380" height="152" style="border:1px solid black;"></a></p> <p class="正文"><a href="http://img.e-com-net.com/image/info8/0d91287873a64c59a0c7421329b4d730.png" target="_blank"><img title="]$_~FS2`(2RA1%X0{YVNS77.png " src="http://img.e-com-net.com/image/info8/0d91287873a64c59a0c7421329b4d730.png" alt="redis缓存服务器(Nginx+Tomcat+redis+MySQL实现session会话共享)_第6张图片" width="408" height="208" style="border:1px solid black;"></a></p> <p class="正文"><strong>通过上图,我们可以很容易的看出,redis安装到/usr/local,/usr/local/bin,/usr/local/share,/usr/local/include,/usr/local/lib,/usr/local/share/man目录下。</strong></p> <p class="正文"><strong>然后再切换到utils目录下,执行redis初始化脚本install_server.sh,如下:</strong></p> <div> <div id="highlighter_281243" class="syntaxhighlighter bash"> <table border="0"> <tbody> <tr> <td class="gutter"> <div class="line number1 index0 alt2"> 1 </div> <div class="line number2 index1 alt1"> 2 </div> <div class="line number3 index2 alt2"> 3 </div> <div class="line number4 index3 alt1"> 4 </div> <div class="line number5 index4 alt2"> 5 </div> <div class="line number6 index5 alt1"> 6 </div> <div class="line number7 index6 alt2"> 7 </div> <div class="line number8 index7 alt1"> 8 </div> <div class="line number9 index8 alt2"> 9 </div> <div class="line number10 index9 alt1"> 10 </div> <div class="line number11 index10 alt2"> 11 </div> <div class="line number12 index11 alt1"> 12 </div> <div class="line number13 index12 alt2"> 13 </div> <div class="line number14 index13 alt1"> 14 </div> <div class="line number15 index14 alt2"> 15 </div> <div class="line number16 index15 alt1"> 16 </div> <div class="line number17 index16 alt2"> 17 </div> <div class="line number18 index17 alt1"> 18 </div> <div class="line number19 index18 alt2"> 19 </div> <div class="line number20 index19 alt1"> 20 </div> <div class="line number21 index20 alt2"> 21 </div> <div class="line number22 index21 alt1"> 22 </div> <div class="line number23 index22 alt2"> 23 </div> <div class="line number24 index23 alt1"> 24 </div> <div class="line number25 index24 alt2"> 25 </div> <div class="line number26 index25 alt1"> 26 </div> <div class="line number27 index26 alt2"> 27 </div> <div class="line number28 index27 alt1"> 28 </div> </td> <td class="code"> <div> <div class="line number1 index0 alt2"> <code class="bash plain">[root@redis redis-3.2.3]</code> <code class="bash comments"># cdutils/</code> </div> <div class="line number2 index1 alt1"> <code class="bash plain">[root@redisutils]</code> <code class="bash comments"># ./install_server.sh</code> </div> <div class="line number3 index2 alt2"> <code class="bash plain">Welcome to the redis service installer</code> </div> <div class="line number4 index3 alt1"> <code class="bash plain">This script will help you easily </code> <code class="bash functions">set</code>  <code class="bash plain">up a running redis server</code> </div> <div class="line number5 index4 alt2"> <code class="bash spaces"> </code>  </div> <div class="line number6 index5 alt1"> <code class="bash plain">Please </code> <code class="bash functions">select</code>  <code class="bash plain">the redis port </code> <code class="bash keyword">for</code>  <code class="bash plain">this instance: [6379] </code> </div> <div class="line number7 index6 alt2"> <code class="bash plain">Selecting default: 6379</code> </div> <div class="line number8 index7 alt1"> <code class="bash plain">Please </code> <code class="bash functions">select</code>  <code class="bash plain">the redisconfig </code> <code class="bash functions">file</code>  <code class="bash plain">name [</code> <code class="bash plain">/etc/redis/6379</code> <code class="bash plain">.conf] </code> </div> <div class="line number9 index8 alt2"> <code class="bash plain">Selected default - </code> <code class="bash plain">/etc/redis/6379</code> <code class="bash plain">.conf</code> </div> <div class="line number10 index9 alt1"> <code class="bash plain">Please </code> <code class="bash functions">select</code>  <code class="bash plain">the redis log </code> <code class="bash functions">file</code>  <code class="bash plain">name [</code> <code class="bash plain">/var/log/redis_6379</code> <code class="bash plain">.log]</code> </div> <div class="line number11 index10 alt2"> <code class="bash plain">Selected default - </code> <code class="bash plain">/var/log/redis_6379</code> <code class="bash plain">.log</code> </div> <div class="line number12 index11 alt1"> <code class="bash plain">Please </code> <code class="bash functions">select</code>  <code class="bash plain">the data directory </code> <code class="bash keyword">for</code>  <code class="bash plain">this instance [</code> <code class="bash plain">/var/lib/redis/6379</code> <code class="bash plain">] </code> </div> <div class="line number13 index12 alt2"> <code class="bash plain">Selected default - </code> <code class="bash plain">/var/lib/redis/6379</code> </div> <div class="line number14 index13 alt1"> <code class="bash plain">Please </code> <code class="bash functions">select</code>  <code class="bash plain">the redis executable path [</code> <code class="bash plain">/usr/local/bin/redis-server</code> <code class="bash plain">] </code> </div> <div class="line number15 index14 alt2"> <code class="bash plain">Selected config:</code> </div> <div class="line number16 index15 alt1"> <code class="bash plain">Port           : 6379</code> </div> <div class="line number17 index16 alt2"> <code class="bash plain">Config </code> <code class="bash functions">file</code>     <code class="bash plain">: </code> <code class="bash plain">/etc/redis/6379</code> <code class="bash plain">.conf</code> </div> <div class="line number18 index17 alt1"> <code class="bash plain">Log </code> <code class="bash functions">file</code>        <code class="bash plain">: </code> <code class="bash plain">/var/log/redis_6379</code> <code class="bash plain">.log</code> </div> <div class="line number19 index18 alt2"> <code class="bash plain">Data </code> <code class="bash functions">dir</code>        <code class="bash plain">: </code> <code class="bash plain">/var/lib/redis/6379</code> </div> <div class="line number20 index19 alt1"> <code class="bash plain">Executable     : </code> <code class="bash plain">/usr/local/bin/redis-server</code> </div> <div class="line number21 index20 alt2"> <code class="bash plain">CliExecutable : </code> <code class="bash plain">/usr/local/bin/redis-cli</code> </div> <div class="line number22 index21 alt1"> <code class="bash plain">Is this ok? Then press ENTER to go on or Ctrl-C to abort.</code> </div> <div class="line number23 index22 alt2"> <code class="bash plain">Copied </code> <code class="bash plain">/tmp/6379</code> <code class="bash plain">.conf => </code> <code class="bash plain">/etc/init</code> <code class="bash plain">.d</code> <code class="bash plain">/redis_6379</code> </div> <div class="line number24 index23 alt1"> <code class="bash plain">Installing service...</code> </div> <div class="line number25 index24 alt2"> <code class="bash plain">Successfully added to chkconfig!</code> </div> <div class="line number26 index25 alt1"> <code class="bash plain">Successfully added to runlevels 345!</code> </div> <div class="line number27 index26 alt2"> <code class="bash plain">Starting Redis server...</code> </div> <div class="line number28 index27 alt1"> <code class="bash plain">Installation successful!</code> </div> </div> </td> </tr> </tbody> </table> </div> </div> <p class="正文"><strong>通过上面的安装过程,我们可以看出redis初始化后redis配置文件为/etc/redis/6379.conf,日志文件为/var/log/redis_6379.log,数据文件dump.rdb存放到/var/lib/redis/6379目录下,启动脚本为/etc/init.d/redis_6379。</strong></p> <p class="正文"><strong>现在我们要使用systemd,所以在 /etc/systems/system 下创建一个单位文件名字为 redis_6379.service。</strong></p> <div> <div id="highlighter_434817" class="syntaxhighlighter bash"> <table border="0"> <tbody> <tr> <td class="gutter"> <div class="line number1 index0 alt2"> 1 </div> </td> <td class="code"> <div> <div class="line number1 index0 alt2"> <code class="bash plain">[root@redisutils]</code> <code class="bash comments"># vi /etc/systemd/system/redis_6379.service</code> </div> </div> </td> </tr> </tbody> </table> </div> </div> <p class="正文"><strong>内容如下:</strong></p> <div> <div id="highlighter_8125" class="syntaxhighlighter bash"> <table border="0"> <tbody> <tr> <td class="gutter"> <div class="line number1 index0 alt2"> 1 </div> <div class="line number2 index1 alt1"> 2 </div> <div class="line number3 index2 alt2"> 3 </div> <div class="line number4 index3 alt1"> 4 </div> <div class="line number5 index4 alt2"> 5 </div> <div class="line number6 index5 alt1"> 6 </div> <div class="line number7 index6 alt2"> 7 </div> <div class="line number8 index7 alt1"> 8 </div> </td> <td class="code"> <div> <div class="line number1 index0 alt2"> <code class="bash plain">[Unit]</code> </div> <div class="line number2 index1 alt1"> <code class="bash plain">Description=Redis on port 6379</code> </div> <div class="line number3 index2 alt2"> <code class="bash plain">[Service]</code> </div> <div class="line number4 index3 alt1"> <code class="bash plain">Type=forking</code> </div> <div class="line number5 index4 alt2"> <code class="bash plain">ExecStart=</code> <code class="bash plain">/etc/init</code> <code class="bash plain">.d</code> <code class="bash plain">/redis_6379</code>  <code class="bash plain">start</code> </div> <div class="line number6 index5 alt1"> <code class="bash plain">ExecStop=</code> <code class="bash plain">/etc/init</code> <code class="bash plain">.d</code> <code class="bash plain">/redis_6379</code>  <code class="bash plain">stop</code> </div> <div class="line number7 index6 alt2"> <code class="bash plain">[Install]</code> </div> <div class="line number8 index7 alt1"> <code class="bash plain">WantedBy=multi-user.target</code> </div> </div> </td> </tr> </tbody> </table> </div> </div> <p class="正文"><strong>注:这里Type=forking是后台运行的形式</strong></p> <p class="正文"><strong>启动redis</strong></p> <div> <div id="highlighter_483145" class="syntaxhighlighter bash"> <table border="0"> <tbody> <tr> <td class="gutter"> <div class="line number1 index0 alt2"> 1 </div> <div class="line number2 index1 alt1"> 2 </div> <div class="line number3 index2 alt2"> 3 </div> <div class="line number4 index3 alt1"> 4 </div> <div class="line number5 index4 alt2"> 5 </div> <div class="line number6 index5 alt1"> 6 </div> <div class="line number7 index6 alt2"> 7 </div> <div class="line number8 index7 alt1"> 8 </div> <div class="line number9 index8 alt2"> 9 </div> <div class="line number10 index9 alt1"> 10 </div> <div class="line number11 index10 alt2"> 11 </div> <div class="line number12 index11 alt1"> 12 </div> <div class="line number13 index12 alt2"> 13 </div> <div class="line number14 index13 alt1"> 14 </div> <div class="line number15 index14 alt2"> 15 </div> <div class="line number16 index15 alt1"> 16 </div> <div class="line number17 index16 alt2"> 17 </div> </td> <td class="code"> <div> <div class="line number1 index0 alt2"> <code class="bash plain">[root@redisutils]</code> <code class="bash comments"># systemctl daemon-reload </code> </div> <div class="line number2 index1 alt1"> <code class="bash plain">[root@redisutils]</code> <code class="bash comments"># systemctl enable redis_6379.service</code> </div> <div class="line number3 index2 alt2"> <code class="bash plain">[root@redisutils]</code> <code class="bash comments"># systemctl start redis_6379.service</code> </div> <div class="line number4 index3 alt1"> <code class="bash plain">[root@redisutils]</code> <code class="bash comments"># systemctl status redis_6379.service </code> </div> <div class="line number5 index4 alt2"> <code class="bash plain">● redis_6379.service - Redis on port 6379</code> </div> <div class="line number6 index5 alt1"> <code class="bash spaces">   </code> <code class="bash plain">Loaded: loaded (</code> <code class="bash plain">/etc/systemd/system/redis_6379</code> <code class="bash plain">.service; enabled; vendor preset: disabled)</code> </div> <div class="line number7 index6 alt2"> <code class="bash spaces">   </code> <code class="bash plain">Active: active (running) since Wed 2016-11-16 21:07:26 CST; 4min 25s ago</code> </div> <div class="line number8 index7 alt1"> <code class="bash spaces">  </code> <code class="bash plain">Process: 7732 ExecStart=</code> <code class="bash plain">/etc/init</code> <code class="bash plain">.d</code> <code class="bash plain">/redis_6379</code>  <code class="bash plain">start (code=exited, status=0</code> <code class="bash plain">/SUCCESS</code> <code class="bash plain">)</code> </div> <div class="line number9 index8 alt2"> <code class="bash spaces"> </code> <code class="bash plain">Main PID: 7734 (redis-server)</code> </div> <div class="line number10 index9 alt1"> <code class="bash plain">CGroup: </code> <code class="bash plain">/system</code> <code class="bash plain">.slice</code> <code class="bash plain">/redis_6379</code> <code class="bash plain">.service</code> </div> <div class="line number11 index10 alt2"> <code class="bash plain">└─7734 </code> <code class="bash plain">/usr/local/bin/redis-server</code>  <code class="bash plain">127.0.0.1:6379</code> </div> <div class="line number12 index11 alt1"> <code class="bash spaces"> </code>  </div> <div class="line number13 index12 alt2"> <code class="bash plain">Nov 16 21:07:26 redissystemd[1]: Starting Redis on port 6379...</code> </div> <div class="line number14 index13 alt1"> <code class="bash plain">Nov 16 21:07:26 redis redis_6379[7732]: Starting Redis server...</code> </div> <div class="line number15 index14 alt2"> <code class="bash plain">Nov 16 21:07:26 redissystemd[1]: Started Redis on port 6379.</code> </div> <div class="line number16 index15 alt1"> <code class="bash plain">[root@redisutils]</code> <code class="bash comments"># netstat -anpt | grep 6379</code> </div> <div class="line number17 index16 alt2"> <code class="bash plain">tcp        0      0 127.0.0.1:6379     0.0.0.0:*     LISTEN      7734</code> <code class="bash plain">/redis-server</code>  <code class="bash plain">1</code> </div> </div> </td> </tr> </tbody> </table> </div> </div> <p class="正文"><strong>从显示结果可以看到redis默认监听的是127.0.0.1的6379端口</strong></p> <p class="正文"><strong>防火墙规则设置</strong></p> <div> <div id="highlighter_991695" class="syntaxhighlighter bash"> <table border="0"> <tbody> <tr> <td class="gutter"> <div class="line number1 index0 alt2"> 1 </div> <div class="line number2 index1 alt1"> 2 </div> <div class="line number3 index2 alt2"> 3 </div> <div class="line number4 index3 alt1"> 4 </div> </td> <td class="code"> <div> <div class="line number1 index0 alt2"> <code class="bash plain">[root@redisutils]</code> <code class="bash comments"># firewall-cmd --permanent --add-port=6379/tcp</code> </div> <div class="line number2 index1 alt1"> <code class="bash plain">success</code> </div> <div class="line number3 index2 alt2"> <code class="bash plain">[root@redisutils]</code> <code class="bash comments"># firewall-cmd --reload </code> </div> <div class="line number4 index3 alt1"> <code class="bash plain">success</code> </div> </div> </td> </tr> </tbody> </table> </div> </div> <p class="正文"><strong>现在来查看redis版本使用redis-cli –version命令,如下</strong></p> <div> <div id="highlighter_159718" class="syntaxhighlighter bash"> <table border="0"> <tbody> <tr> <td class="gutter"> <div class="line number1 index0 alt2"> 1 </div> <div class="line number2 index1 alt1"> 2 </div> </td> <td class="code"> <div> <div class="line number1 index0 alt2"> <code class="bash plain">[root@redisutils]</code> <code class="bash comments"># redis-cli --version</code> </div> <div class="line number2 index1 alt1"> <code class="bash plain">redis-cli 3.2.3</code> </div> </div> </td> </tr> </tbody> </table> </div> </div> <p class="正文"><strong>通过显示结果,我们可以看到redis版本是3.2.3。</strong></p> <p class="无间隔"><strong>到此源码方式安装redis就介绍完毕。</strong></p> <p class="无间隔"><strong>redis安装完毕之后,我们再来配置redis</strong></p> <p class="无间隔"><strong>设置redis监听的地址,添加监听redis主机的ip</strong></p> <p class="无间隔"><strong>考虑到安全性,我们需要启用redis的密码验证功能requirepass参数</strong></p> <p class="无间隔"><strong>最终redis配置文件如下:</strong></p> <div> <div id="highlighter_819818" class="syntaxhighlighter bash"> <table border="0"> <tbody> <tr> <td class="gutter"> <div class="line number1 index0 alt2"> 1 </div> <div class="line number2 index1 alt1"> 2 </div> <div class="line number3 index2 alt2"> 3 </div> <div class="line number4 index3 alt1"> 4 </div> <div class="line number5 index4 alt2"> 5 </div> <div class="line number6 index5 alt1"> 6 </div> <div class="line number7 index6 alt2"> 7 </div> <div class="line number8 index7 alt1"> 8 </div> <div class="line number9 index8 alt2"> 9 </div> <div class="line number10 index9 alt1"> 10 </div> <div class="line number11 index10 alt2"> 11 </div> <div class="line number12 index11 alt1"> 12 </div> <div class="line number13 index12 alt2"> 13 </div> <div class="line number14 index13 alt1"> 14 </div> <div class="line number15 index14 alt2"> 15 </div> <div class="line number16 index15 alt1"> 16 </div> <div class="line number17 index16 alt2"> 17 </div> <div class="line number18 index17 alt1"> 18 </div> <div class="line number19 index18 alt2"> 19 </div> <div class="line number20 index19 alt1"> 20 </div> <div class="line number21 index20 alt2"> 21 </div> <div class="line number22 index21 alt1"> 22 </div> <div class="line number23 index22 alt2"> 23 </div> <div class="line number24 index23 alt1"> 24 </div> <div class="line number25 index24 alt2"> 25 </div> <div class="line number26 index25 alt1"> 26 </div> <div class="line number27 index26 alt2"> 27 </div> <div class="line number28 index27 alt1"> 28 </div> <div class="line number29 index28 alt2"> 29 </div> <div class="line number30 index29 alt1"> 30 </div> <div class="line number31 index30 alt2"> 31 </div> <div class="line number32 index31 alt1"> 32 </div> <div class="line number33 index32 alt2"> 33 </div> <div class="line number34 index33 alt1"> 34 </div> <div class="line number35 index34 alt2"> 35 </div> <div class="line number36 index35 alt1"> 36 </div> <div class="line number37 index36 alt2"> 37 </div> <div class="line number38 index37 alt1"> 38 </div> <div class="line number39 index38 alt2"> 39 </div> <div class="line number40 index39 alt1"> 40 </div> <div class="line number41 index40 alt2"> 41 </div> <div class="line number42 index41 alt1"> 42 </div> <div class="line number43 index42 alt2"> 43 </div> <div class="line number44 index43 alt1"> 44 </div> <div class="line number45 index44 alt2"> 45 </div> <div class="line number46 index45 alt1"> 46 </div> <div class="line number47 index46 alt2"> 47 </div> <div class="line number48 index47 alt1"> 48 </div> <div class="line number49 index48 alt2"> 49 </div> <div class="line number50 index49 alt1"> 50 </div> <div class="line number51 index50 alt2"> 51 </div> <div class="line number52 index51 alt1"> 52 </div> <div class="line number53 index52 alt2"> 53 </div> <div class="line number54 index53 alt1"> 54 </div> </td> <td class="code"> <div> <div class="line number1 index0 alt2"> <code class="bash plain">[root@redis ~]</code> <code class="bash comments"># grep -Ev '^#|^$' /etc/redis/6379.conf </code> </div> <div class="line number2 index1 alt1"> <code class="bash plain">bind 127.0.0.1 192.168.31.106</code> </div> <div class="line number3 index2 alt2"> <code class="bash plain">protected-mode </code> <code class="bash functions">yes</code> </div> <div class="line number4 index3 alt1"> <code class="bash plain">port 6379</code> </div> <div class="line number5 index4 alt2"> <code class="bash plain">tcp-backlog 511</code> </div> <div class="line number6 index5 alt1"> <code class="bash plain">timeout 0</code> </div> <div class="line number7 index6 alt2"> <code class="bash plain">tcp-keepalive 300</code> </div> <div class="line number8 index7 alt1"> <code class="bash plain">daemonize </code> <code class="bash functions">yes</code> </div> <div class="line number9 index8 alt2"> <code class="bash plain">supervised no</code> </div> <div class="line number10 index9 alt1"> <code class="bash plain">pidfile </code> <code class="bash plain">/var/run/redis_6379</code> <code class="bash plain">.pid</code> </div> <div class="line number11 index10 alt2"> <code class="bash plain">loglevel notice</code> </div> <div class="line number12 index11 alt1"> <code class="bash plain">logfile </code> <code class="bash plain">/var/log/redis_6379</code> <code class="bash plain">.log</code> </div> <div class="line number13 index12 alt2"> <code class="bash plain">databases 16</code> </div> <div class="line number14 index13 alt1"> <code class="bash plain">save 900 1</code> </div> <div class="line number15 index14 alt2"> <code class="bash plain">save 300 10</code> </div> <div class="line number16 index15 alt1"> <code class="bash plain">save 60 10000</code> </div> <div class="line number17 index16 alt2"> <code class="bash plain">stop-writes-on-bgsave-error </code> <code class="bash functions">yes</code> </div> <div class="line number18 index17 alt1"> <code class="bash plain">rdbcompression </code> <code class="bash functions">yes</code> </div> <div class="line number19 index18 alt2"> <code class="bash plain">rdbchecksum </code> <code class="bash functions">yes</code> </div> <div class="line number20 index19 alt1"> <code class="bash plain">dbfilenamedump.rdb</code> </div> <div class="line number21 index20 alt2"> <code class="bash functions">dir</code>  <code class="bash plain">/var/lib/redis/6379</code> </div> <div class="line number22 index21 alt1"> <code class="bash plain">slave-serve-stale-data </code> <code class="bash functions">yes</code> </div> <div class="line number23 index22 alt2"> <code class="bash plain">slave-</code> <code class="bash functions">read</code> <code class="bash plain">-only </code> <code class="bash functions">yes</code> </div> <div class="line number24 index23 alt1"> <code class="bash plain">repl-diskless-</code> <code class="bash functions">sync</code>  <code class="bash plain">no</code> </div> <div class="line number25 index24 alt2"> <code class="bash plain">repl-diskless-</code> <code class="bash functions">sync</code> <code class="bash plain">-delay 5</code> </div> <div class="line number26 index25 alt1"> <code class="bash plain">repl-disable-tcp-nodelay no</code> </div> <div class="line number27 index26 alt2"> <code class="bash plain">slave-priority 100</code> </div> <div class="line number28 index27 alt1"> <code class="bash plain">requirepass </code> <code class="bash functions">pwd</code> <code class="bash plain">@123</code> </div> <div class="line number29 index28 alt2"> <code class="bash plain">appendonly no</code> </div> <div class="line number30 index29 alt1"> <code class="bash plain">appendfilename </code> <code class="bash string">"appendonly.aof"</code> </div> <div class="line number31 index30 alt2"> <code class="bash plain">appendfsynceverysec</code> </div> <div class="line number32 index31 alt1"> <code class="bash plain">no-appendfsync-on-rewrite no</code> </div> <div class="line number33 index32 alt2"> <code class="bash plain">auto-aof-rewrite-percentage 100</code> </div> <div class="line number34 index33 alt1"> <code class="bash plain">auto-aof-rewrite-min-size 64mb</code> </div> <div class="line number35 index34 alt2"> <code class="bash plain">aof-load-truncated </code> <code class="bash functions">yes</code> </div> <div class="line number36 index35 alt1"> <code class="bash plain">lua-</code> <code class="bash functions">time</code> <code class="bash plain">-limit 5000</code> </div> <div class="line number37 index36 alt2"> <code class="bash plain">slowlog-log-slower-than 10000</code> </div> <div class="line number38 index37 alt1"> <code class="bash plain">slowlog-max-len 128</code> </div> <div class="line number39 index38 alt2"> <code class="bash plain">latency-monitor-threshold 0</code> </div> <div class="line number40 index39 alt1"> <code class="bash plain">notify-keyspace-events </code> <code class="bash string">""</code> </div> <div class="line number41 index40 alt2"> <code class="bash functions">hash</code> <code class="bash plain">-max-ziplist-entries 512</code> </div> <div class="line number42 index41 alt1"> <code class="bash functions">hash</code> <code class="bash plain">-max-ziplist-value 64</code> </div> <div class="line number43 index42 alt2"> <code class="bash plain">list-max-ziplist-size -2</code> </div> <div class="line number44 index43 alt1"> <code class="bash plain">list-compress-depth 0</code> </div> <div class="line number45 index44 alt2"> <code class="bash functions">set</code> <code class="bash plain">-max-intset-entries 512</code> </div> <div class="line number46 index45 alt1"> <code class="bash plain">zset-max-ziplist-entries 128</code> </div> <div class="line number47 index46 alt2"> <code class="bash plain">zset-max-ziplist-value 64</code> </div> <div class="line number48 index47 alt1"> <code class="bash plain">hll-sparse-max-bytes 3000</code> </div> <div class="line number49 index48 alt2"> <code class="bash plain">activerehashing </code> <code class="bash functions">yes</code> </div> <div class="line number50 index49 alt1"> <code class="bash plain">client-output-buffer-limit normal 0 0 0</code> </div> <div class="line number51 index50 alt2"> <code class="bash plain">client-output-buffer-limit slave 256mb 64mb 60</code> </div> <div class="line number52 index51 alt1"> <code class="bash plain">client-output-buffer-limitpubsub 32mb 8mb 60</code> </div> <div class="line number53 index52 alt2"> <code class="bash plain">hz 10</code> </div> <div class="line number54 index53 alt1"> <code class="bash plain">aof-rewrite-incremental-fsync </code> <code class="bash functions">yes</code> </div> </div> </td> </tr> </tbody> </table> </div> </div> <p class="无间隔"><strong>重新启动redis服务</strong></p> <div> <div id="highlighter_727089" class="syntaxhighlighter bash"> <table border="0"> <tbody> <tr> <td class="gutter"> <div class="line number1 index0 alt2"> 1 </div> <div class="line number2 index1 alt1"> 2 </div> <div class="line number3 index2 alt2"> 3 </div> </td> <td class="code"> <div> <div class="line number1 index0 alt2"> <code class="bash plain">[root@redis ~]</code> <code class="bash comments"># systemctl restart redis_6379.service</code> </div> <div class="line number2 index1 alt1"> <code class="bash plain">[root@redis ~]</code> <code class="bash comments"># netstat -anpt | grep redis</code> </div> <div class="line number3 index2 alt2"> <code class="bash plain">tcp   0   0 192.168.31.106:6379     0.0.0.0:*   LISTEN      8418</code> <code class="bash plain">/redis-server</code>  <code class="bash plain">1</code> </div> </div> </td> </tr> </tbody> </table> </div> </div> <p class="无间隔"><strong>redis配置文件配置完毕后,我们来启动redis并进行简单的操作。如下:</strong></p> <div> <div id="highlighter_377988" class="syntaxhighlighter bash"> <table border="0"> <tbody> <tr> <td class="gutter"> <div class="line number1 index0 alt2"> 1 </div> <div class="line number2 index1 alt1"> 2 </div> <div class="line number3 index2 alt2"> 3 </div> <div class="line number4 index3 alt1"> 4 </div> <div class="line number5 index4 alt2"> 5 </div> <div class="line number6 index5 alt1"> 6 </div> <div class="line number7 index6 alt2"> 7 </div> <div class="line number8 index7 alt1"> 8 </div> </td> <td class="code"> <div> <div class="line number1 index0 alt2"> <code class="bash plain">[root@redis ~]</code> <code class="bash comments"># redis-cli -h 192.168.31.106 -p 6379 -a pwd@123</code> </div> <div class="line number2 index1 alt1"> <code class="bash plain">192.168.31.106:6379> keys *</code> </div> <div class="line number3 index2 alt2"> <code class="bash plain">(empty list or </code> <code class="bash functions">set</code> <code class="bash plain">)</code> </div> <div class="line number4 index3 alt1"> <code class="bash plain">192.168.31.106:6379> </code> <code class="bash functions">set</code>  <code class="bash plain">name lisi</code> </div> <div class="line number5 index4 alt2"> <code class="bash plain">OK</code> </div> <div class="line number6 index5 alt1"> <code class="bash plain">192.168.31.106:6379> get name</code> </div> <div class="line number7 index6 alt2"> <code class="bash string">"lisi"</code> </div> <div class="line number8 index7 alt1"> <code class="bash plain">192.168.31.106:6379></code> </div> </div> </td> </tr> </tbody> </table> </div> </div> <p class="无间隔"><strong>说明:</strong></p> <p class="无间隔"><strong>关于redis-cli -h 192.168.31.106 -p 6379 -a pwd@123的参数解释</strong></p> <p class="无间隔"><strong>这条命令是说要连接redis服务器,IP是192.168.31.106,端口是6379,密码是pwd@123。</strong></p> <p class="无间隔"><strong>keys *是查看redis所有的键值对。</strong></p> <p class="无间隔"><strong>set namelisi添加一个键值name,内容为lisi。</strong></p> <p class="无间隔"><strong>get name查看name这个键值的内容。</strong></p> <p class="无间隔"><strong>redis的命令使用暂时我们就介绍这么多</strong></p> <p class="无间隔"><strong>6、配置tomcat session redis同步</strong></p> <p class="无间隔"><strong>下载tomcat-redis-session-manager相应的jar包,主要有三个:</strong></p> <div> <div id="highlighter_962989" class="syntaxhighlighter bash"> <table border="0"> <tbody> <tr> <td class="gutter"> <div class="line number1 index0 alt2"> 1 </div> <div class="line number2 index1 alt1"> 2 </div> <div class="line number3 index2 alt2"> 3 </div> </td> <td class="code"> <div> <div class="line number1 index0 alt2"> <code class="bash plain">tomcat-redis-session-manage-tomcat7.jar</code> </div> <div class="line number2 index1 alt1"> <code class="bash plain">jedis-2.5.2.jar</code> </div> <div class="line number3 index2 alt2"> <code class="bash plain">commons-pool2-2.2.jar</code> </div> </div> </td> </tr> </tbody> </table> </div> </div> <p class="无间隔"><strong>下载完成后拷贝到$TOMCAT_HOME/lib中</strong></p> <div> <div id="highlighter_292922" class="syntaxhighlighter bash"> <table border="0"> <tbody> <tr> <td class="gutter"> <div class="line number1 index0 alt2"> 1 </div> </td> <td class="code"> <div> <div class="line number1 index0 alt2"> <code class="bash plain">[root@tomcat-1 ~]</code> <code class="bash comments"># cp tomcat-redis-session-manage-tomcat7.jar jedis-2.5.2.jar commons-pool2-2.2.jar /usr/local/tomcat7/lib/</code> </div> </div> </td> </tr> </tbody> </table> </div> </div> <p class="无间隔"><strong>修改tomcat的context.xml:</strong></p> <div> <div id="highlighter_471091" class="syntaxhighlighter bash"> <table border="0"> <tbody> <tr> <td class="gutter"> <div class="line number1 index0 alt2"> 1 </div> <div class="line number2 index1 alt1"> 2 </div> <div class="line number3 index2 alt2"> 3 </div> <div class="line number4 index3 alt1"> 4 </div> <div class="line number5 index4 alt2"> 5 </div> <div class="line number6 index5 alt1"> 6 </div> <div class="line number7 index6 alt2"> 7 </div> <div class="line number8 index7 alt1"> 8 </div> <div class="line number9 index8 alt2"> 9 </div> <div class="line number10 index9 alt1"> 10 </div> <div class="line number11 index10 alt2"> 11 </div> <div class="line number12 index11 alt1"> 12 </div> <div class="line number13 index12 alt2"> 13 </div> <div class="line number14 index13 alt1"> 14 </div> <div class="line number15 index14 alt2"> 15 </div> <div class="line number16 index15 alt1"> 16 </div> <div class="line number17 index16 alt2"> 17 </div> <div class="line number18 index17 alt1"> 18 </div> <div class="line number19 index18 alt2"> 19 </div> <div class="line number20 index19 alt1"> 20 </div> <div class="line number21 index20 alt2"> 21 </div> <div class="line number22 index21 alt1"> 22 </div> <div class="line number23 index22 alt2"> 23 </div> <div class="line number24 index23 alt1"> 24 </div> <div class="line number25 index24 alt2"> 25 </div> <div class="line number26 index25 alt1"> 26 </div> <div class="line number27 index26 alt2"> 27 </div> <div class="line number28 index27 alt1"> 28 </div> <div class="line number29 index28 alt2"> 29 </div> <div class="line number30 index29 alt1"> 30 </div> <div class="line number31 index30 alt2"> 31 </div> <div class="line number32 index31 alt1"> 32 </div> <div class="line number33 index32 alt2"> 33 </div> <div class="line number34 index33 alt1"> 34 </div> <div class="line number35 index34 alt2"> 35 </div> <div class="line number36 index35 alt1"> 36 </div> <div class="line number37 index36 alt2"> 37 </div> </td> <td class="code"> <div> <div class="line number1 index0 alt2"> <code class="bash plain">[root@tomcat-1 ~]</code> <code class="bash comments"># cat /usr/local/tomcat7/conf/context.xml </code> </div> <div class="line number2 index1 alt1"> <code class="bash plain"><?xml version=</code> <code class="bash string">'1.0'</code>  <code class="bash plain">encoding=</code> <code class="bash string">'utf-8'</code> <code class="bash plain">?></code> </div> <div class="line number3 index2 alt2"> <code class="bash plain"><!--</code> </div> <div class="line number4 index3 alt1"> <code class="bash spaces">  </code> <code class="bash plain">Licensed to the Apache Software Foundation (ASF) under one or </code> <code class="bash functions">more</code> </div> <div class="line number5 index4 alt2"> <code class="bash plain">contributor license agreements.  See the NOTICE </code> <code class="bash functions">file</code>  <code class="bash plain">distributed with</code> </div> <div class="line number6 index5 alt1"> <code class="bash plain">this work </code> <code class="bash keyword">for</code>  <code class="bash plain">additional information regarding copyright ownership.</code> </div> <div class="line number7 index6 alt2"> <code class="bash spaces">  </code> <code class="bash plain">The ASF licenses this </code> <code class="bash functions">file</code>  <code class="bash plain">to You under the Apache License, Version 2.0</code> </div> <div class="line number8 index7 alt1"> <code class="bash spaces">  </code> <code class="bash plain">(the </code> <code class="bash string">"License"</code> <code class="bash plain">); you may not use this </code> <code class="bash functions">file</code>  <code class="bash plain">except </code> <code class="bash keyword">in</code>  <code class="bash plain">compliance with</code> </div> <div class="line number9 index8 alt2"> <code class="bash plain">the License.  You may obtain a copy of the License at</code> </div> <div class="line number10 index9 alt1"> <code class="bash spaces">      </code> <code class="bash plain">http:</code> <code class="bash plain">//www</code> <code class="bash plain">.apache.org</code> <code class="bash plain">/licenses/LICENSE-2</code> <code class="bash plain">.0</code> </div> <div class="line number11 index10 alt2"> <code class="bash spaces">  </code> <code class="bash plain">Unless required by applicable law or agreed to </code> <code class="bash keyword">in</code>  <code class="bash plain">writing, software</code> </div> <div class="line number12 index11 alt1"> <code class="bash plain">distributed under the License is distributed on an </code> <code class="bash string">"AS IS"</code>  <code class="bash plain">BASIS,</code> </div> <div class="line number13 index12 alt2"> <code class="bash spaces">  </code> <code class="bash plain">WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</code> </div> <div class="line number14 index13 alt1"> <code class="bash spaces">  </code> <code class="bash plain">See the License </code> <code class="bash keyword">for</code>  <code class="bash plain">the specific language governing permissions and</code> </div> <div class="line number15 index14 alt2"> <code class="bash plain">limitations under the License.</code> </div> <div class="line number16 index15 alt1"> <code class="bash plain">--></code> </div> <div class="line number17 index16 alt2"> <code class="bash plain"><!-- The contents of this </code> <code class="bash functions">file</code>  <code class="bash plain">will be loaded </code> <code class="bash keyword">for</code>  <code class="bash plain">each web application --></code> </div> <div class="line number18 index17 alt1"> <code class="bash plain"><Context></code> </div> <div class="line number19 index18 alt2"> <code class="bash plain"><!-- Default </code> <code class="bash functions">set</code>  <code class="bash plain">of monitored resources --></code> </div> <div class="line number20 index19 alt1"> <code class="bash plain"><WatchedResource>WEB-INF</code> <code class="bash plain">/web</code> <code class="bash plain">.xml<</code> <code class="bash plain">/WatchedResource</code> <code class="bash plain">></code> </div> <div class="line number21 index20 alt2"> <code class="bash plain"><!-- Uncomment this to disable session persistence across Tomcat restarts --></code> </div> <div class="line number22 index21 alt1"> <code class="bash plain"><!--</code> </div> <div class="line number23 index22 alt2"> <code class="bash plain"><Manager pathname=</code> <code class="bash string">""</code>  <code class="bash plain">/></code> </div> <div class="line number24 index23 alt1"> <code class="bash spaces">    </code> <code class="bash plain">--></code> </div> <div class="line number25 index24 alt2"> <code class="bash plain"><!-- Uncomment this to </code> <code class="bash functions">enable</code>  <code class="bash plain">Comet connection tacking (provides events</code> </div> <div class="line number26 index25 alt1"> <code class="bash plain">on session expiration as well as webapp lifecycle) --></code> </div> <div class="line number27 index26 alt2"> <code class="bash plain"><!--</code> </div> <div class="line number28 index27 alt1"> <code class="bash plain"><Valve className=</code> <code class="bash string">"org.apache.catalina.valves.CometConnectionManagerValve"</code>  <code class="bash plain">/></code> </div> <div class="line number29 index28 alt2"> <code class="bash spaces">    </code> <code class="bash plain">--></code> </div> <div class="line number30 index29 alt1"> <code class="bash plain"><Valve className=</code> <code class="bash string">"com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve"</code>  <code class="bash plain">/></code> </div> <div class="line number31 index30 alt2"> <code class="bash plain"><Manager className=</code> <code class="bash string">"com.orangefunction.tomcat.redissessions.RedisSessionManager"</code> </div> <div class="line number32 index31 alt1"> <code class="bash plain">host=</code> <code class="bash string">"192.168.31.106"</code> </div> <div class="line number33 index32 alt2"> <code class="bash plain">password=</code> <code class="bash string">"pwd@123"</code> </div> <div class="line number34 index33 alt1"> <code class="bash plain">port=</code> <code class="bash string">"6379"</code> </div> <div class="line number35 index34 alt2"> <code class="bash plain">database=</code> <code class="bash string">"0"</code> </div> <div class="line number36 index35 alt1"> <code class="bash plain">maxInactiveInterval=</code> <code class="bash string">"60"</code>  <code class="bash plain">/></code> </div> <div class="line number37 index36 alt2"> <code class="bash plain"><</code> <code class="bash plain">/Context</code> <code class="bash plain">></code> </div> </div> </td> </tr> </tbody> </table> </div> </div> <p class="无间隔"><strong>重启tomcat服务</strong></p> <p class="无间隔"><strong>说明:</strong></p> <div> <div id="highlighter_386979" class="syntaxhighlighter bash"> <table border="0"> <tbody> <tr> <td class="gutter"> <div class="line number1 index0 alt2"> 1 </div> <div class="line number2 index1 alt1"> 2 </div> <div class="line number3 index2 alt2"> 3 </div> <div class="line number4 index3 alt1"> 4 </div> <div class="line number5 index4 alt2"> 5 </div> <div class="line number6 index5 alt1"> 6 </div> <div class="line number7 index6 alt2"> 7 </div> <div class="line number8 index7 alt1"> 8 </div> <div class="line number9 index8 alt2"> 9 </div> <div class="line number10 index9 alt1"> 10 </div> <div class="line number11 index10 alt2"> 11 </div> <div class="line number12 index11 alt1"> 12 </div> <div class="line number13 index12 alt2"> 13 </div> <div class="line number14 index13 alt1"> 14 </div> </td> <td class="code"> <div> <div class="line number1 index0 alt2"> <code class="bash plain">maxInactiveInterval=</code> <code class="bash string">"60"</code> <code class="bash plain">:session的失效时间</code> </div> <div class="line number2 index1 alt1"> <code class="bash plain">[root@tomcat-1 ~]</code> <code class="bash comments"># shutdown.sh </code> </div> <div class="line number3 index2 alt2"> <code class="bash plain">Using CATALINA_BASE:   </code> <code class="bash plain">/usr/local/tomcat7</code> </div> <div class="line number4 index3 alt1"> <code class="bash plain">Using CATALINA_HOME:   </code> <code class="bash plain">/usr/local/tomcat7</code> </div> <div class="line number5 index4 alt2"> <code class="bash plain">Using CATALINA_TMPDIR: </code> <code class="bash plain">/usr/local/tomcat7/temp</code> </div> <div class="line number6 index5 alt1"> <code class="bash plain">Using JRE_HOME:        </code> <code class="bash plain">/usr/local/java</code> </div> <div class="line number7 index6 alt2"> <code class="bash plain">Using CLASSPATH:       </code> <code class="bash plain">/usr/local/tomcat7/bin/bootstrap</code> <code class="bash plain">.jar:</code> <code class="bash plain">/usr/local/tomcat7/bin/tomcat-juli</code> <code class="bash plain">.jar</code> </div> <div class="line number8 index7 alt1"> <code class="bash plain">[root@tomcat-1 ~]</code> <code class="bash comments"># startup.sh </code> </div> <div class="line number9 index8 alt2"> <code class="bash plain">Using CATALINA_BASE:   </code> <code class="bash plain">/usr/local/tomcat7</code> </div> <div class="line number10 index9 alt1"> <code class="bash plain">Using CATALINA_HOME:   </code> <code class="bash plain">/usr/local/tomcat7</code> </div> <div class="line number11 index10 alt2"> <code class="bash plain">Using CATALINA_TMPDIR: </code> <code class="bash plain">/usr/local/tomcat7/temp</code> </div> <div class="line number12 index11 alt1"> <code class="bash plain">Using JRE_HOME:        </code> <code class="bash plain">/usr/local/java</code> </div> <div class="line number13 index12 alt2"> <code class="bash plain">Using CLASSPATH:       </code> <code class="bash plain">/usr/local/tomcat7/bin/bootstrap</code> <code class="bash plain">.jar:</code> <code class="bash plain">/usr/local/tomcat7/bin/tomcat-juli</code> <code class="bash plain">.jar</code> </div> <div class="line number14 index13 alt1"> <code class="bash plain">Tomcat started.</code> </div> </div> </td> </tr> </tbody> </table> </div> </div> <p class="无间隔"><strong>tomcat-2执行和tomcat-1相同的操作</strong></p> <p class="无间隔"><strong>通过浏览器访问http://192.168.31.141/index.jsp测试页</strong></p> <p class="无间隔"><a href="http://img.e-com-net.com/image/info8/052a47cb238f4f37a67ed6535e9bccf7.jpg" target="_blank"><img title="OKLX%HF4B]9X{]{3%(7]4S8.png" src="http://img.e-com-net.com/image/info8/052a47cb238f4f37a67ed6535e9bccf7.jpg" alt="redis缓存服务器(Nginx+Tomcat+redis+MySQL实现session会话共享)_第7张图片" width="500" height="198" style="border:1px solid black;"></a></p> <p class="无间隔"><strong>刷新页面</strong></p> <p class="无间隔"><a href="http://img.e-com-net.com/image/info8/dabfd7f841444211b067f18d1c6ca64b.jpg" target="_blank"><img title="}JLU]RKBB3WPX9`H~XZF})J.png " src="http://img.e-com-net.com/image/info8/dabfd7f841444211b067f18d1c6ca64b.jpg" alt="redis缓存服务器(Nginx+Tomcat+redis+MySQL实现session会话共享)_第8张图片" width="500" height="200" style="border:1px solid black;"></a></p> <p class="无间隔"><strong>可以看出,分别访问了不同的tomcat,但是得到的session却是相同的,说明达到了集群的目的。</strong></p> <p class="无间隔"><strong>注:从Tomcat6开始默认开启了Session持久化设置,测试时可以关闭本地Session持久化,其实也很简单,在Tomcat的conf目录下的context.xml文件中,取消注释下面那段配置即可:</strong></p> <p class="无间隔"><strong>修改前:</strong></p> <div> <div id="highlighter_830009" class="syntaxhighlighter bash"> <table border="0"> <tbody> <tr> <td class="gutter"> <div class="line number1 index0 alt2"> 1 </div> <div class="line number2 index1 alt1"> 2 </div> <div class="line number3 index2 alt2"> 3 </div> <div class="line number4 index3 alt1"> 4 </div> </td> <td class="code"> <div> <div class="line number1 index0 alt2"> <code class="bash plain"><!-- Uncomment this to disable session persistence across Tomcat restarts --></code> </div> <div class="line number2 index1 alt1"> <code class="bash plain"><!--</code> </div> <div class="line number3 index2 alt2"> <code class="bash plain"><Manager pathname=</code> <code class="bash string">""</code>  <code class="bash plain">/></code> </div> <div class="line number4 index3 alt1"> <code class="bash plain">--></code> </div> </div> </td> </tr> </tbody> </table> </div> </div> <p class="无间隔"><strong>修改后:</strong></p> <div> <div id="highlighter_876942" class="syntaxhighlighter bash"> <table border="0"> <tbody> <tr> <td class="gutter"> <div class="line number1 index0 alt2"> 1 </div> <div class="line number2 index1 alt1"> 2 </div> </td> <td class="code"> <div> <div class="line number1 index0 alt2"> <code class="bash plain"><!-- Uncomment this to disable session persistence across Tomcat restarts --></code> </div> <div class="line number2 index1 alt1"> <code class="bash plain"><Manager pathname=</code> <code class="bash string">""</code>  <code class="bash plain">/></code> </div> </div> </td> </tr> </tbody> </table> </div> </div> <p class="无间隔"><strong>重启tomcat服务</strong></p> <p class="正文"><strong>查看redis:</strong></p> <div> <div id="highlighter_701861" class="syntaxhighlighter bash"> <table border="0"> <tbody> <tr> <td class="gutter"> <div class="line number1 index0 alt2"> 1 </div> <div class="line number2 index1 alt1"> 2 </div> <div class="line number3 index2 alt2"> 3 </div> <div class="line number4 index3 alt1"> 4 </div> <div class="line number5 index4 alt2"> 5 </div> <div class="line number6 index5 alt1"> 6 </div> </td> <td class="code"> <div> <div class="line number1 index0 alt2"> <code class="bash plain">[root@redis ~]</code> <code class="bash comments"># redis-cli -h 192.168.31.106 -p 6379 -a pwd@123</code> </div> <div class="line number2 index1 alt1"> <code class="bash plain">192.168.31.106:6379> keys *</code> </div> <div class="line number3 index2 alt2"> <code class="bash plain">1) </code> <code class="bash string">"6C3F950BE6413AD2E0EF00F930881224.tomcat-1.tomcat-1"</code> </div> <div class="line number4 index3 alt1"> <code class="bash plain">2) </code> <code class="bash string">"name"</code> </div> <div class="line number5 index4 alt2"> <code class="bash plain">3) </code> <code class="bash string">"7A6D5D4C5B1EA52C4E9EED1C5523FEB5.tomcat-2.tomcat-2"</code> </div> <div class="line number6 index5 alt1"> <code class="bash plain">4) </code> <code class="bash string">"32C35EEA064884F065E93CB00C690662.tomcat-1.tomcat-1"</code> </div> </div> </td> </tr> </tbody> </table> </div> </div> <p class="正文"><strong>7、tomcat连接数据库</strong></p> <p class="正文"><strong>192.168.31.225作为mysql数据库服务器</strong></p> <div> <div id="highlighter_78607" class="syntaxhighlighter bash"> <table border="0"> <tbody> <tr> <td class="gutter"> <div class="line number1 index0 alt2"> 1 </div> <div class="line number2 index1 alt1"> 2 </div> <div class="line number3 index2 alt2"> 3 </div> <div class="line number4 index3 alt1"> 4 </div> <div class="line number5 index4 alt2"> 5 </div> <div class="line number6 index5 alt1"> 6 </div> <div class="line number7 index6 alt2"> 7 </div> <div class="line number8 index7 alt1"> 8 </div> <div class="line number9 index8 alt2"> 9 </div> <div class="line number10 index9 alt1"> 10 </div> <div class="line number11 index10 alt2"> 11 </div> <div class="line number12 index11 alt1"> 12 </div> </td> <td class="code"> <div> <div class="line number1 index0 alt2"> <code class="bash plain">[root@db ~]</code> <code class="bash comments"># mysql -uroot -p123.abc</code> </div> <div class="line number2 index1 alt1"> <code class="bash plain">mysql> grant all on *.* to javauser@</code> <code class="bash string">'192.168.31.%'</code>  <code class="bash plain">identified by </code> <code class="bash string">'javapasswd'</code> <code class="bash plain">;</code> </div> <div class="line number3 index2 alt2"> <code class="bash plain">Query OK, 0 rows affected, 1 warning (0.02 sec)</code> </div> <div class="line number4 index3 alt1"> <code class="bash spaces"> </code>  </div> <div class="line number5 index4 alt2"> <code class="bash plain">mysql> create database javatest;</code> </div> <div class="line number6 index5 alt1"> <code class="bash plain">Query OK, 1 row affected (0.01 sec)</code> </div> <div class="line number7 index6 alt2"> <code class="bash spaces"> </code>  </div> <div class="line number8 index7 alt1"> <code class="bash plain">mysql> use javatest;</code> </div> <div class="line number9 index8 alt2"> <code class="bash plain">Database changed</code> </div> <div class="line number10 index9 alt1"> <code class="bash spaces"> </code>  </div> <div class="line number11 index10 alt2"> <code class="bash plain">mysql> create table testdata(</code> <code class="bash functions">id</code>  <code class="bash plain">int not null auto_increment primary key,foo varchar(25),bar int);</code> </div> <div class="line number12 index11 alt1"> <code class="bash plain">Query OK, 0 rows affected (0.02 sec)</code> </div> </div> </td> </tr> </tbody> </table> </div> </div> <p class="正文"><strong>插入些数据</strong></p> <div> <div id="highlighter_559318" class="syntaxhighlighter bash"> <table border="0"> <tbody> <tr> <td class="gutter"> <div class="line number1 index0 alt2"> 1 </div> <div class="line number2 index1 alt1"> 2 </div> <div class="line number3 index2 alt2"> 3 </div> <div class="line number4 index3 alt1"> 4 </div> <div class="line number5 index4 alt2"> 5 </div> <div class="line number6 index5 alt1"> 6 </div> <div class="line number7 index6 alt2"> 7 </div> <div class="line number8 index7 alt1"> 8 </div> <div class="line number9 index8 alt2"> 9 </div> <div class="line number10 index9 alt1"> 10 </div> <div class="line number11 index10 alt2"> 11 </div> </td> <td class="code"> <div> <div class="line number1 index0 alt2"> <code class="bash plain">mysql> insert into testdata(foo,bar) values (</code> <code class="bash string">'hello'</code> <code class="bash plain">,</code> <code class="bash string">'123456'</code> <code class="bash plain">),(</code> <code class="bash string">'ok'</code> <code class="bash plain">,</code> <code class="bash string">'654321'</code> <code class="bash plain">);</code> </div> <div class="line number2 index1 alt1"> <code class="bash plain">Query OK, 2 rows affected (0.04 sec)</code> </div> <div class="line number3 index2 alt2"> <code class="bash plain">Records: 2  Duplicates: 0  Warnings: 0</code> </div> <div class="line number4 index3 alt1"> <code class="bash plain">mysql> </code> <code class="bash functions">select</code>  <code class="bash plain">* from testdata;</code> </div> <div class="line number5 index4 alt2"> <code class="bash plain">+----+-------+--------+</code> </div> <div class="line number6 index5 alt1"> <code class="bash plain">| </code> <code class="bash functions">id</code>  <code class="bash plain">| foo   | bar    |</code> </div> <div class="line number7 index6 alt2"> <code class="bash plain">+----+-------+--------+</code> </div> <div class="line number8 index7 alt1"> <code class="bash plain">|  1 | hello | 123456 |</code> </div> <div class="line number9 index8 alt2"> <code class="bash plain">|  2 | ok    | 654321 |</code> </div> <div class="line number10 index9 alt1"> <code class="bash plain">+----+-------+--------+</code> </div> <div class="line number11 index10 alt2"> <code class="bash plain">2 rows </code> <code class="bash keyword">in</code>  <code class="bash functions">set</code>  <code class="bash plain">(0.00 sec)</code> </div> </div> </td> </tr> </tbody> </table> </div> </div> <p class="正文"><strong>mysql防火墙配置</strong></p> <p class="正文"><strong>配置tomcat服务器连接mysql数据库</strong></p> <p class="无间隔"><strong>下载mysql-connector-java-5.1.22-bin.jar并复制到$CATALINA_HOME/lib目录下</strong></p> <div> <div id="highlighter_880389" class="syntaxhighlighter bash"> <table border="0"> <tbody> <tr> <td class="gutter"> <div class="line number1 index0 alt2"> 1 </div> <div class="line number2 index1 alt1"> 2 </div> <div class="line number3 index2 alt2"> 3 </div> <div class="line number4 index3 alt1"> 4 </div> <div class="line number5 index4 alt2"> 5 </div> <div class="line number6 index5 alt1"> 6 </div> <div class="line number7 index6 alt2"> 7 </div> <div class="line number8 index7 alt1"> 8 </div> <div class="line number9 index8 alt2"> 9 </div> <div class="line number10 index9 alt1"> 10 </div> <div class="line number11 index10 alt2"> 11 </div> <div class="line number12 index11 alt1"> 12 </div> <div class="line number13 index12 alt2"> 13 </div> </td> <td class="code"> <div> <div class="line number1 index0 alt2"> <code class="bash plain">[root@tomcat-1 ~]</code> <code class="bash comments"># cp mysql-connector-java-5.1.22-bin.jar /usr/local/tomcat7/lib/</code> </div> <div class="line number2 index1 alt1"> <code class="bash plain">[root@tomcat-1 ~]</code> <code class="bash comments"># ls /usr/local/tomcat7/lib/mysql-connector-java-5.1.22-bin.jar </code> </div> <div class="line number3 index2 alt2"> <code class="bash plain">/usr/local/tomcat7/lib/mysql-connector-java-5</code> <code class="bash plain">.1.22-bin.jar</code> </div> <div class="line number4 index3 alt1"> <code class="bash spaces"> </code>  </div> <div class="line number5 index4 alt2"> <code class="bash plain">context configuration</code> </div> <div class="line number6 index5 alt1"> <code class="bash plain">configure the JNDI datasource </code> <code class="bash keyword">in</code>  <code class="bash plain">tomcat by adding a declaration </code> <code class="bash keyword">for</code>  <code class="bash plain">your resource to your</code> </div> <div class="line number7 index6 alt2"> <code class="bash plain">context</code> </div> <div class="line number8 index7 alt1"> <code class="bash plain">[root@tomcat-1 ~]</code> <code class="bash comments"># vi /usr/local/tomcat7/conf/context.xml</code> </div> <div class="line number9 index8 alt2"> <code class="bash plain">在<Context>中添加如下内容:</code> </div> <div class="line number10 index9 alt1"> <code class="bash plain"><Resource name=</code> <code class="bash string">"jdbc/TestDB"</code>  <code class="bash plain">auth=</code> <code class="bash string">"Container"</code>  <code class="bash functions">type</code> <code class="bash plain">=</code> <code class="bash string">"javax.sql.DataSource"</code> </div> <div class="line number11 index10 alt2"> <code class="bash plain">maxActive=</code> <code class="bash string">"100"</code>  <code class="bash plain">maxIdle=</code> <code class="bash string">"30"</code>  <code class="bash plain">maxWait=</code> <code class="bash string">"10000"</code> </div> <div class="line number12 index11 alt1"> <code class="bash plain">username=</code> <code class="bash string">"javauser"</code>  <code class="bash plain">password=</code> <code class="bash string">"javapass"</code>  <code class="bash plain">driverClassName=</code> <code class="bash string">"com.mysql.jdbc.Driver"</code> </div> <div class="line number13 index12 alt2"> <code class="bash plain">url=</code> <code class="bash string">"jdbc:mysql://192.168.31.225:3306/javatest"</code> <code class="bash plain">/></code> </div> </div> </td> </tr> </tbody> </table> </div> </div> <p class="正文"><strong>保存修改并退出</strong></p> <div> <div id="highlighter_778040" class="syntaxhighlighter bash"> <table border="0"> <tbody> <tr> <td class="gutter"> <div class="line number1 index0 alt2"> 1 </div> <div class="line number2 index1 alt1"> 2 </div> <div class="line number3 index2 alt2"> 3 </div> </td> <td class="code"> <div> <div class="line number1 index0 alt2"> <code class="bash plain">web.xml configuration</code> </div> <div class="line number2 index1 alt1"> <code class="bash plain">[root@tomcat-1 ~]</code> <code class="bash comments"># mkdir /web/webapp1/WEB-INF</code> </div> <div class="line number3 index2 alt2"> <code class="bash plain">[root@tomcat-1 ~]</code> <code class="bash comments"># vi /web/webapp1/WEB-INF/web.xml</code> </div> </div> </td> </tr> </tbody> </table> </div> </div> <p class="正文"><strong>添加内容如下:</strong></p> <div> <div id="highlighter_612654" class="syntaxhighlighter bash"> <table border="0"> <tbody> <tr> <td class="gutter"> <div class="line number1 index0 alt2"> 1 </div> <div class="line number2 index1 alt1"> 2 </div> <div class="line number3 index2 alt2"> 3 </div> <div class="line number4 index3 alt1"> 4 </div> <div class="line number5 index4 alt2"> 5 </div> <div class="line number6 index5 alt1"> 6 </div> <div class="line number7 index6 alt2"> 7 </div> <div class="line number8 index7 alt1"> 8 </div> <div class="line number9 index8 alt2"> 9 </div> <div class="line number10 index9 alt1"> 10 </div> <div class="line number11 index10 alt2"> 11 </div> <div class="line number12 index11 alt1"> 12 </div> <div class="line number13 index12 alt2"> 13 </div> </td> <td class="code"> <div> <div class="line number1 index0 alt2"> <code class="bash plain"><web-app xmlns=</code> <code class="bash string">"http://java.sun.com/xml/ns/j2ee"</code> </div> <div class="line number2 index1 alt1"> <code class="bash plain">xmlns:xsi=</code> <code class="bash string">"http://www.w3.org/2001/XMLSchema-instance"</code> </div> <div class="line number3 index2 alt2"> <code class="bash plain">xsi:schemaLocation="http:</code> <code class="bash plain">//java</code> <code class="bash plain">.sun.com</code> <code class="bash plain">/xml/ns/j2ee</code> </div> <div class="line number4 index3 alt1"> <code class="bash plain">http:</code> <code class="bash plain">//java</code> <code class="bash plain">.sun.com</code> <code class="bash plain">/xml/ns/j2ee/web-app_2_4</code> <code class="bash plain">.xsd"</code> </div> <div class="line number5 index4 alt2"> <code class="bash plain">version=</code> <code class="bash string">"2.4"</code> <code class="bash plain">></code> </div> <div class="line number6 index5 alt1"> <code class="bash plain"><description>MySQL Test App<</code> <code class="bash plain">/description</code> <code class="bash plain">></code> </div> <div class="line number7 index6 alt2"> <code class="bash plain"><resource-ref></code> </div> <div class="line number8 index7 alt1"> <code class="bash plain"><description>DB Connection<</code> <code class="bash plain">/description</code> <code class="bash plain">></code> </div> <div class="line number9 index8 alt2"> <code class="bash plain"><res-ref-name>jdbc</code> <code class="bash plain">/TestDB</code> <code class="bash plain"><</code> <code class="bash plain">/res-ref-name</code> <code class="bash plain">></code> </div> <div class="line number10 index9 alt1"> <code class="bash plain"><res-</code> <code class="bash functions">type</code> <code class="bash plain">>javax.sql.DataSource<</code> <code class="bash plain">/res-type</code> <code class="bash plain">></code> </div> <div class="line number11 index10 alt2"> <code class="bash plain"><res-auth>Container<</code> <code class="bash plain">/res-auth</code> <code class="bash plain">></code> </div> <div class="line number12 index11 alt1"> <code class="bash plain"><</code> <code class="bash plain">/resource-ref</code> <code class="bash plain">></code> </div> <div class="line number13 index12 alt2"> <code class="bash plain"><</code> <code class="bash plain">/web-app</code> <code class="bash plain">></code> </div> </div> </td> </tr> </tbody> </table> </div> </div> <p class="正文"><strong>保存修改并退出,重启tomcat服务</strong></p> <div> <div id="highlighter_306107" class="syntaxhighlighter bash"> <table border="0"> <tbody> <tr> <td class="gutter"> <div class="line number1 index0 alt2"> 1 </div> <div class="line number2 index1 alt1"> 2 </div> <div class="line number3 index2 alt2"> 3 </div> <div class="line number4 index3 alt1"> 4 </div> <div class="line number5 index4 alt2"> 5 </div> <div class="line number6 index5 alt1"> 6 </div> <div class="line number7 index6 alt2"> 7 </div> <div class="line number8 index7 alt1"> 8 </div> <div class="line number9 index8 alt2"> 9 </div> <div class="line number10 index9 alt1"> 10 </div> <div class="line number11 index10 alt2"> 11 </div> <div class="line number12 index11 alt1"> 12 </div> <div class="line number13 index12 alt2"> 13 </div> <div class="line number14 index13 alt1"> 14 </div> <div class="line number15 index14 alt2"> 15 </div> <div class="line number16 index15 alt1"> 16 </div> <div class="line number17 index16 alt2"> 17 </div> <div class="line number18 index17 alt1"> 18 </div> <div class="line number19 index18 alt2"> 19 </div> <div class="line number20 index19 alt1"> 20 </div> <div class="line number21 index20 alt2"> 21 </div> <div class="line number22 index21 alt1"> 22 </div> <div class="line number23 index22 alt2"> 23 </div> <div class="line number24 index23 alt1"> 24 </div> <div class="line number25 index24 alt2"> 25 </div> <div class="line number26 index25 alt1"> 26 </div> <div class="line number27 index26 alt2"> 27 </div> <div class="line number28 index27 alt1"> 28 </div> <div class="line number29 index28 alt2"> 29 </div> <div class="line number30 index29 alt1"> 30 </div> <div class="line number31 index30 alt2"> 31 </div> <div class="line number32 index31 alt1"> 32 </div> <div class="line number33 index32 alt2"> 33 </div> <div class="line number34 index33 alt1"> 34 </div> <div class="line number35 index34 alt2"> 35 </div> <div class="line number36 index35 alt1"> 36 </div> <div class="line number37 index36 alt2"> 37 </div> <div class="line number38 index37 alt1"> 38 </div> <div class="line number39 index38 alt2"> 39 </div> <div class="line number40 index39 alt1"> 40 </div> <div class="line number41 index40 alt2"> 41 </div> <div class="line number42 index41 alt1"> 42 </div> </td> <td class="code"> <div> <div class="line number1 index0 alt2"> <code class="bash plain">[root@tomcat-1 ~]</code> <code class="bash comments"># shutdown.sh </code> </div> <div class="line number2 index1 alt1"> <code class="bash plain">Using CATALINA_BASE:   </code> <code class="bash plain">/usr/local/tomcat7</code> </div> <div class="line number3 index2 alt2"> <code class="bash plain">Using CATALINA_HOME:   </code> <code class="bash plain">/usr/local/tomcat7</code> </div> <div class="line number4 index3 alt1"> <code class="bash plain">Using CATALINA_TMPDIR: </code> <code class="bash plain">/usr/local/tomcat7/temp</code> </div> <div class="line number5 index4 alt2"> <code class="bash plain">Using JRE_HOME:        </code> <code class="bash plain">/usr/local/java</code> </div> <div class="line number6 index5 alt1"> <code class="bash plain">Using CLASSPATH:       </code> <code class="bash plain">/usr/local/tomcat7/bin/bootstrap</code> <code class="bash plain">.jar:</code> <code class="bash plain">/usr/local/tomcat7/bin/tomcat-juli</code> <code class="bash plain">.jar</code> </div> <div class="line number7 index6 alt2"> <code class="bash plain">[root@tomcat-1 ~]</code> <code class="bash comments"># startup.sh </code> </div> <div class="line number8 index7 alt1"> <code class="bash plain">Using CATALINA_BASE:   </code> <code class="bash plain">/usr/local/tomcat7</code> </div> <div class="line number9 index8 alt2"> <code class="bash plain">Using CATALINA_HOME:   </code> <code class="bash plain">/usr/local/tomcat7</code> </div> <div class="line number10 index9 alt1"> <code class="bash plain">Using CATALINA_TMPDIR: </code> <code class="bash plain">/usr/local/tomcat7/temp</code> </div> <div class="line number11 index10 alt2"> <code class="bash plain">Using JRE_HOME:        </code> <code class="bash plain">/usr/local/java</code> </div> <div class="line number12 index11 alt1"> <code class="bash plain">Using CLASSPATH:       </code> <code class="bash plain">/usr/local/tomcat7/bin/bootstrap</code> <code class="bash plain">.jar:</code> <code class="bash plain">/usr/local/tomcat7/bin/tomcat-juli</code> <code class="bash plain">.jar</code> </div> <div class="line number13 index12 alt2"> <code class="bash plain">Tomcat started.</code> </div> <div class="line number14 index13 alt1"> <code class="bash plain">tomcat-2进行和tomcat-1相同的操用</code> </div> <div class="line number15 index14 alt2"> <code class="bash plain">Test code</code> </div> <div class="line number16 index15 alt1"> <code class="bash plain">Now create a simple </code> <code class="bash functions">test</code> <code class="bash plain">.jsp page,内容如下:</code> </div> <div class="line number17 index16 alt2"> <code class="bash plain">[root@tomcat-2 ~]</code> <code class="bash comments"># vi /web/webapp1/test.jsp</code> </div> <div class="line number18 index17 alt1"> <code class="bash plain">[root@tomcat-2 webapp1]</code> <code class="bash comments"># cattest.jsp</code> </div> <div class="line number19 index18 alt2"> <code class="bash plain"><%@ page language=</code> <code class="bash string">"java"</code>  <code class="bash functions">import</code> <code class="bash plain">=</code> <code class="bash string">"java.sql.*"</code>  <code class="bash plain">pageEncoding=</code> <code class="bash string">"GB2312"</code> <code class="bash plain">%></code> </div> <div class="line number20 index19 alt1"> <code class="bash plain"><html></code> </div> <div class="line number21 index20 alt2"> <code class="bash plain"><</code> <code class="bash functions">head</code> <code class="bash plain">></code> </div> <div class="line number22 index21 alt1"> <code class="bash plain"><title>MySQL<</code> <code class="bash plain">/title</code> <code class="bash plain">></code> </div> <div class="line number23 index22 alt2"> <code class="bash plain"><</code> <code class="bash plain">/head</code> <code class="bash plain">></code> </div> <div class="line number24 index23 alt1"> <code class="bash plain"><body></code> </div> <div class="line number25 index24 alt2"> <code class="bash plain">connect MySQL<br></code> </div> <div class="line number26 index25 alt1"> <code class="bash plain"><%</code> </div> <div class="line number27 index26 alt2"> <code class="bash plain">String driverClass=</code> <code class="bash string">"com.mysql.jdbc.Driver"</code> <code class="bash plain">;</code> </div> <div class="line number28 index27 alt1"> <code class="bash plain">String url=</code> <code class="bash string">"jdbc:mysql://192.168.31.225:3306/javatest"</code> <code class="bash plain">;</code> </div> <div class="line number29 index28 alt2"> <code class="bash plain">String username = </code> <code class="bash string">"javauser"</code> <code class="bash plain">; </code> </div> <div class="line number30 index29 alt1"> <code class="bash plain">String password = </code> <code class="bash string">"javapasswd"</code> <code class="bash plain">; </code> </div> <div class="line number31 index30 alt2"> <code class="bash plain">Class.forName(driverClass); </code> </div> <div class="line number32 index31 alt1"> <code class="bash plain">Connection conn=DriverManager.getConnection(url, username, password); </code> </div> <div class="line number33 index32 alt2"> <code class="bash plain">Statement stmt=conn.createStatement();</code> </div> <div class="line number34 index33 alt1"> <code class="bash plain">ResultSetrs = stmt.executeQuery(</code> <code class="bash string">"select * from testdata"</code> <code class="bash plain">); </code> </div> <div class="line number35 index34 alt2"> <code class="bash keyword">while</code> <code class="bash plain">(rs.next()){</code> </div> <div class="line number36 index35 alt1"> <code class="bash plain">out.println(</code> <code class="bash string">"<br>foo:"</code> <code class="bash plain">+rs.getString(2)+</code> <code class="bash string">"bar:"</code> <code class="bash plain">+rs.getString(3));</code> </div> <div class="line number37 index36 alt2"> <code class="bash plain">}</code> </div> <div class="line number38 index37 alt1"> <code class="bash plain">rs.close();</code> </div> <div class="line number39 index38 alt2"> <code class="bash plain">stmt.close();</code> </div> <div class="line number40 index39 alt1"> <code class="bash plain">conn.close();</code> </div> <div class="line number41 index40 alt2"> <code class="bash plain">%></code> </div> <div class="line number42 index41 alt1"> <code class="bash plain"><</code> <code class="bash plain">/body</code> <code class="bash plain">><</code> <code class="bash plain">/html</code> <code class="bash plain">></code> </div> </div> </td> </tr> </tbody> </table> </div> </div> <p class="正文"><strong>通过浏览器访问http://192.168.31.141/test.jsp测试页</strong></p> <p class="正文"><a href="http://img.e-com-net.com/image/info8/885f8091ed0b406eac70d3f5c9ab6617.png" target="_blank"><img title="JB1MOI~CDV_BDGPVNLB[M33.png" src="http://img.e-com-net.com/image/info8/885f8091ed0b406eac70d3f5c9ab6617.png" alt="redis缓存服务器(Nginx+Tomcat+redis+MySQL实现session会话共享)_第9张图片" width="316" height="148" style="border:1px solid black;"></a></p> <p class="无间隔"><strong>注:</strong></p> <p class="无间隔"><strong>以上配置可以参考tomcat docs</strong></p> <p class="无间隔"><a href="http://img.e-com-net.com/image/info8/61d187e5a05d46c8b8cedee91f394ff8.jpg" target="_blank"><img title="2OE1JD2QDIWMAMVTZ33T1YE.jpg" src="http://img.e-com-net.com/image/info8/61d187e5a05d46c8b8cedee91f394ff8.jpg" alt="redis缓存服务器(Nginx+Tomcat+redis+MySQL实现session会话共享)_第10张图片" width="490" height="222" style="border:1px solid black;"></a></p> <p class="无间隔"><a href="http://img.e-com-net.com/image/info8/b880c646ba044e519fe8786291a72057.jpg" target="_blank"><img title="04T}T71U9R`{S2VFE%HWI28.png " src="http://img.e-com-net.com/image/info8/b880c646ba044e519fe8786291a72057.jpg" alt="redis缓存服务器(Nginx+Tomcat+redis+MySQL实现session会话共享)_第11张图片" width="500" height="194" style="border:1px solid black;"></a></p> <p class="无间隔"><a href="http://img.e-com-net.com/image/info8/c9239bec764b4e17a976be23ce1cc7c4.jpg" target="_blank"><img title="FJAKY`0%[)X(F)AEY91M6NU.png " src="http://img.e-com-net.com/image/info8/c9239bec764b4e17a976be23ce1cc7c4.jpg" alt="redis缓存服务器(Nginx+Tomcat+redis+MySQL实现session会话共享)_第12张图片" width="500" height="215" style="border:1px solid black;"></a></p> </div> <p>转载于:https://www.cnblogs.com/Easonlou/p/6627092.html</p> </div> </div> </div> </div> </div> <!--PC和WAP自适应版--> <div id="SOHUCS" sid="1294641997918838784"></div> <script type="text/javascript" src="/views/front/js/chanyan.js"></script> <!-- 文章页-底部 动态广告位 --> <div class="youdao-fixed-ad" id="detail_ad_bottom"></div> </div> <div class="col-md-3"> <div class="row" id="ad"> <!-- 文章页-右侧1 动态广告位 --> <div id="right-1" class="col-lg-12 col-md-12 col-sm-4 col-xs-4 ad"> <div class="youdao-fixed-ad" id="detail_ad_1"> </div> </div> <!-- 文章页-右侧2 动态广告位 --> <div id="right-2" class="col-lg-12 col-md-12 col-sm-4 col-xs-4 ad"> <div class="youdao-fixed-ad" id="detail_ad_2"></div> </div> <!-- 文章页-右侧3 动态广告位 --> <div id="right-3" class="col-lg-12 col-md-12 col-sm-4 col-xs-4 ad"> <div class="youdao-fixed-ad" id="detail_ad_3"></div> </div> </div> </div> </div> </div> </div> <div class="container"> <h4 class="pt20 mb15 mt0 border-top">你可能感兴趣的:(redis缓存服务器(Nginx+Tomcat+redis+MySQL实现session会话共享))</h4> <div id="paradigm-article-related"> <div class="recommend-post mb30"> <ul class="widget-links"> <li><a href="/article/1835512920797179904.htm" title="element实现动态路由+面包屑" target="_blank">element实现动态路由+面包屑</a> <span class="text-muted">软件技术NINI</span> <a class="tag" taget="_blank" href="/search/vue%E6%A1%88%E4%BE%8B/1.htm">vue案例</a><a class="tag" taget="_blank" href="/search/vue.js/1.htm">vue.js</a><a class="tag" taget="_blank" href="/search/%E5%89%8D%E7%AB%AF/1.htm">前端</a> <div>el-breadcrumb是ElementUI组件库中的一个面包屑导航组件,它用于显示当前页面的路径,帮助用户快速理解和导航到应用的各个部分。在Vue.js项目中,如果你已经安装了ElementUI,就可以很方便地使用el-breadcrumb组件。以下是一个基本的使用示例:安装ElementUI(如果你还没有安装的话):你可以通过npm或yarn来安装ElementUI。bash复制代码npmi</div> </li> <li><a href="/article/1835511912192897024.htm" title="微服务下功能权限与数据权限的设计与实现" target="_blank">微服务下功能权限与数据权限的设计与实现</a> <span class="text-muted">nbsaas-boot</span> <a class="tag" taget="_blank" href="/search/%E5%BE%AE%E6%9C%8D%E5%8A%A1/1.htm">微服务</a><a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/%E6%9E%B6%E6%9E%84/1.htm">架构</a> <div>在微服务架构下,系统的功能权限和数据权限控制显得尤为重要。随着系统规模的扩大和微服务数量的增加,如何保证不同用户和服务之间的访问权限准确、细粒度地控制,成为设计安全策略的关键。本文将讨论如何在微服务体系中设计和实现功能权限与数据权限控制。1.功能权限与数据权限的定义功能权限:指用户或系统角色对特定功能的访问权限。通常是某个用户角色能否执行某个操作,比如查看订单、创建订单、修改用户资料等。数据权限:</div> </li> <li><a href="/article/1835511163450912768.htm" title="2021年12月19日,春蕾教育集团团建活动感受——黄晓丹" target="_blank">2021年12月19日,春蕾教育集团团建活动感受——黄晓丹</a> <span class="text-muted">黄错错加油</span> <div>感受:1.从陌生到熟悉的过程。游戏环节让我们在轻松的氛围中得到了锻炼,也增长了不少知识。2.游戏过程中,我们贡献的是个人力量,展现的是团队的力量。它磨合的往往不止是工作的熟悉,更是观念上契合度的贴近。3.这和工作是一样的道理。在各自的岗位上,每个人摆正自己的位置、各司其职充分发挥才能,并团结一致劲往一处使,才能实现最大的成功。新知:1.团队精神需要不断地创新。过去,人们把创新看作是冒风险,现在人们</div> </li> <li><a href="/article/1835508761310097408.htm" title="店群合一模式下的社区团购新发展——结合链动 2+1 模式、AI 智能名片与 S2B2C 商城小程序源码" target="_blank">店群合一模式下的社区团购新发展——结合链动 2+1 模式、AI 智能名片与 S2B2C 商城小程序源码</a> <span class="text-muted">说私域</span> <a class="tag" taget="_blank" href="/search/%E4%BA%BA%E5%B7%A5%E6%99%BA%E8%83%BD/1.htm">人工智能</a><a class="tag" taget="_blank" href="/search/%E5%B0%8F%E7%A8%8B%E5%BA%8F/1.htm">小程序</a> <div>摘要:本文探讨了店群合一的社区团购平台在当今商业环境中的重要性和优势。通过分析店群合一模式如何将互联网社群与线下终端紧密结合,阐述了链动2+1模式、AI智能名片和S2B2C商城小程序源码在这一模式中的应用价值。这些创新元素的结合为社区团购带来了新的机遇,提升了用户信任感、拓展了营销渠道,并实现了线上线下的完美融合。一、引言随着互联网技术的不断发展,社区团购作为一种新兴的商业模式,在满足消费者日常需</div> </li> <li><a href="/article/1835508130268672000.htm" title="消息中间件有哪些常见类型" target="_blank">消息中间件有哪些常见类型</a> <span class="text-muted">xmh-sxh-1314</span> <a class="tag" taget="_blank" href="/search/java/1.htm">java</a> <div>消息中间件根据其设计理念和用途,可以大致分为以下几种常见类型:点对点消息队列(Point-to-PointMessagingQueues):在这种模型中,消息被发送到特定的队列中,消费者从队列中取出并处理消息。队列中的消息只能被一个消费者消费,消费后即被删除。常见的实现包括IBM的MQSeries、RabbitMQ的部分使用场景等。适用于任务分发、负载均衡等场景。发布/订阅消息模型(Pub/Sub</div> </li> <li><a href="/article/1835505228137459712.htm" title="腾讯云技术深度探索:构建高效云原生微服务架构" target="_blank">腾讯云技术深度探索:构建高效云原生微服务架构</a> <span class="text-muted">我的运维人生</span> <a class="tag" taget="_blank" href="/search/%E4%BA%91%E5%8E%9F%E7%94%9F/1.htm">云原生</a><a class="tag" taget="_blank" href="/search/%E6%9E%B6%E6%9E%84/1.htm">架构</a><a class="tag" taget="_blank" href="/search/%E8%85%BE%E8%AE%AF%E4%BA%91/1.htm">腾讯云</a><a class="tag" taget="_blank" href="/search/%E8%BF%90%E7%BB%B4%E5%BC%80%E5%8F%91/1.htm">运维开发</a><a class="tag" taget="_blank" href="/search/%E6%8A%80%E6%9C%AF%E5%85%B1%E4%BA%AB/1.htm">技术共享</a> <div>腾讯云技术深度探索:构建高效云原生微服务架构在当今快速发展的技术环境中,云原生技术已成为企业数字化转型的关键驱动力。腾讯云作为行业领先的云服务提供商,不断推出创新的产品和技术,助力企业构建高效、可扩展的云原生微服务架构。本文将深入探讨腾讯云在微服务领域的最新进展,并通过一个实际案例展示如何在腾讯云平台上构建云原生应用。腾讯云微服务架构概览腾讯云微服务架构基于云原生理念,旨在帮助企业快速实现应用的容</div> </li> <li><a href="/article/1835500750684385280.htm" title="拥有断舍离的心态,过精简生活--《断舍离》读书笔记" target="_blank">拥有断舍离的心态,过精简生活--《断舍离》读书笔记</a> <span class="text-muted">爱吃丸子的小樱桃</span> <div>不知不觉间房间里的东西越来越多,虽然摆放整齐,但也时常会觉得空间逼仄,令人心生烦闷。抱着断舍离的态度,我开始阅读《断舍离》这本书,希望从书中能找到一些有效的方法,帮助我实现空间、物品上的断舍离。《断舍离》是日本作家山下英子通过自己的经历、思考和实践总结而成的,整体内涵也从刚开始的私人生活哲学的“断舍离”升华成了“人生实践哲学”,接着又成为每个人都能实行的“改变人生的断舍离”,从“哲学”逐渐升华成“</div> </li> <li><a href="/article/1835497710975807488.htm" title="从0到500+,我是如何利用自媒体赚钱?" target="_blank">从0到500+,我是如何利用自媒体赚钱?</a> <span class="text-muted">一列脚印</span> <div>运营公众号半个多月,从零基础的小白到现在慢慢懂了一些运营的知识。做好公众号是很不容易的,要做很多事情;排版、码字、引流…通通需要自己解决,业余时间全都花费在这上面涨这么多粉丝是真的不容易,对比知乎大佬来说,我们这种没资源,没人脉,还没钱的小透明来说,想要一个月涨粉上万,怕是今天没睡醒(不过你有的方法,算我piapia打脸)至少我是清醒的,自己慢慢努力,实现我的万粉目标!大家快来围观、支持我吧!孩子</div> </li> <li><a href="/article/1835497665337585664.htm" title="使用LLaVa和Ollama实现多模态RAG示例" target="_blank">使用LLaVa和Ollama实现多模态RAG示例</a> <span class="text-muted">llzwxh888</span> <a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/%E4%BA%BA%E5%B7%A5%E6%99%BA%E8%83%BD/1.htm">人工智能</a><a class="tag" taget="_blank" href="/search/%E5%BC%80%E5%8F%91%E8%AF%AD%E8%A8%80/1.htm">开发语言</a> <div>本文将详细介绍如何使用LLaVa和Ollama实现多模态RAG(检索增强生成),通过提取图像中的结构化数据、生成图像字幕等功能来展示这一技术的强大之处。安装环境首先,您需要安装以下依赖包:!pipinstallllama-index-multi-modal-llms-ollama!pipinstallllama-index-readers-file!pipinstallunstructured!p</div> </li> <li><a href="/article/1835497283932745728.htm" title="利用LangChain的StackExchange组件实现智能问答系统" target="_blank">利用LangChain的StackExchange组件实现智能问答系统</a> <span class="text-muted">nseejrukjhad</span> <a class="tag" taget="_blank" href="/search/langchain/1.htm">langchain</a><a class="tag" taget="_blank" href="/search/microsoft/1.htm">microsoft</a><a class="tag" taget="_blank" href="/search/%E6%95%B0%E6%8D%AE%E5%BA%93/1.htm">数据库</a><a class="tag" taget="_blank" href="/search/python/1.htm">python</a> <div>利用LangChain的StackExchange组件实现智能问答系统引言在当今的软件开发世界中,StackOverflow已经成为程序员解决问题的首选平台之一。而LangChain作为一个强大的AI应用开发框架,提供了StackExchange组件,使我们能够轻松地将StackOverflow的海量知识库集成到我们的应用中。本文将详细介绍如何使用LangChain的StackExchange组件</div> </li> <li><a href="/article/1835493374514262016.htm" title="MongoDB Oplog 窗口" target="_blank">MongoDB Oplog 窗口</a> <span class="text-muted">喝醉酒的小白</span> <a class="tag" taget="_blank" href="/search/MongoDB/1.htm">MongoDB</a><a class="tag" taget="_blank" href="/search/%E8%BF%90%E7%BB%B4/1.htm">运维</a> <div>在MongoDB中,oplog(操作日志)是一个特殊的日志系统,用于记录对数据库的所有写操作。oplog允许副本集成员(通常是从节点)应用主节点上已经执行的操作,从而保持数据的一致性。它是MongoDB副本集实现数据复制的基础。MongoDBOplog窗口oplog窗口是指在MongoDB副本集中,从节点可以用来同步数据的时间范围。这个窗口通常由以下因素决定:Oplog大小:oplog的大小是有限</div> </li> <li><a href="/article/1835493247179386880.htm" title="Faiss Tips:高效向量搜索与聚类的利器" target="_blank">Faiss Tips:高效向量搜索与聚类的利器</a> <span class="text-muted">焦习娜Samantha</span> <div>FaissTips:高效向量搜索与聚类的利器faiss_tipsSomeusefultipsforfaiss项目地址:https://gitcode.com/gh_mirrors/fa/faiss_tips项目介绍Faiss是由FacebookAIResearch开发的一个用于高效相似性搜索和密集向量聚类的库。它支持多种硬件平台,包括CPU和GPU,能够在海量数据集上实现快速的近似最近邻搜索(AN</div> </li> <li><a href="/article/1835491859351302144.htm" title="Python 实现图片裁剪(附代码) | Python工具" target="_blank">Python 实现图片裁剪(附代码) | Python工具</a> <span class="text-muted">剑客阿良_ALiang</span> <div>前言本文提供将图片按照自定义尺寸进行裁剪的工具方法,一如既往的实用主义。环境依赖ffmpeg环境安装,可以参考我的另一篇文章:windowsffmpeg安装部署_阿良的博客-CSDN博客本文主要使用到的不是ffmpeg,而是ffprobe也在上面这篇文章中的zip包中。ffmpy安装:pipinstallffmpy-ihttps://pypi.douban.com/simple代码不废话了,上代码</div> </li> <li><a href="/article/1835491101276991488.htm" title="数据仓库——维度表一致性" target="_blank">数据仓库——维度表一致性</a> <span class="text-muted">墨染丶eye</span> <a class="tag" taget="_blank" href="/search/%E8%83%8C%E8%AF%B5/1.htm">背诵</a><a class="tag" taget="_blank" href="/search/%E6%95%B0%E6%8D%AE%E4%BB%93%E5%BA%93/1.htm">数据仓库</a> <div>数据仓库基础笔记思维导图已经整理完毕,完整连接为:数据仓库基础知识笔记思维导图维度一致性问题从逻辑层面来看,当一系列星型模型共享一组公共维度时,所涉及的维度称为一致性维度。当维度表存在不一致时,短期的成功难以弥补长期的错误。维度时确保不同过程中信息集成起来实现横向钻取货活动的关键。造成横向钻取失败的原因维度结构的差别,因为维度的差别,分析工作涉及的领域从简单到复杂,但是都是通过复杂的报表来弥补设计</div> </li> <li><a href="/article/1835490218409553920.htm" title="01-Git初识" target="_blank">01-Git初识</a> <span class="text-muted">Meereen</span> <a class="tag" taget="_blank" href="/search/Git/1.htm">Git</a><a class="tag" taget="_blank" href="/search/git/1.htm">git</a> <div>01-Git初识概念:一个免费开源,分布式的代码版本控制系统,帮助开发团队维护代码作用:记录代码内容。切换代码版本,多人开发时高效合并代码内容如何学:个人本机使用:Git基础命令和概念多人共享使用:团队开发同一个项目的代码版本管理Git配置用户信息配置:用户名和邮箱,应用在每次提交代码版本时表明自己的身份命令:查看git版本号git-v配置用户名gitconfig--globaluser.name</div> </li> <li><a href="/article/1835490092068728832.htm" title="Redis系列:Geo 类型赋能亿级地图位置计算" target="_blank">Redis系列:Geo 类型赋能亿级地图位置计算</a> <span class="text-muted">Ly768768</span> <a class="tag" taget="_blank" href="/search/redis/1.htm">redis</a><a class="tag" taget="_blank" href="/search/bootstrap/1.htm">bootstrap</a><a class="tag" taget="_blank" href="/search/%E6%95%B0%E6%8D%AE%E5%BA%93/1.htm">数据库</a> <div>1前言我们在篇深刻理解高性能Redis的本质的时候就介绍过Redis的几种基本数据结构,它是基于不同业务场景而设计的:动态字符串(REDIS_STRING):整数(REDIS_ENCODING_INT)、字符串(REDIS_ENCODING_RAW)双端列表(REDIS_ENCODING_LINKEDLIST)压缩列表(REDIS_ENCODING_ZIPLIST)跳跃表(REDIS_ENCODI</div> </li> <li><a href="/article/1835489588169240576.htm" title="ARM驱动学习之5 LEDS驱动" target="_blank">ARM驱动学习之5 LEDS驱动</a> <span class="text-muted">JT灬新一</span> <a class="tag" taget="_blank" href="/search/%E5%B5%8C%E5%85%A5%E5%BC%8F/1.htm">嵌入式</a><a class="tag" taget="_blank" href="/search/C/1.htm">C</a><a class="tag" taget="_blank" href="/search/%E5%BA%95%E5%B1%82/1.htm">底层</a><a class="tag" taget="_blank" href="/search/arm%E5%BC%80%E5%8F%91/1.htm">arm开发</a><a class="tag" taget="_blank" href="/search/%E5%AD%A6%E4%B9%A0/1.htm">学习</a><a class="tag" taget="_blank" href="/search/%E5%8D%95%E7%89%87%E6%9C%BA/1.htm">单片机</a> <div>ARM驱动学习之5LEDS驱动知识点:•linuxGPIO申请函数和赋值函数–gpio_request–gpio_set_value•三星平台配置GPIO函数–s3c_gpio_cfgpin•GPIO配置输出模式的宏变量–S3C_GPIO_OUTPUT注意点:DRIVER_NAME和DEVICE_NAME匹配。实现步骤:1.加入需要的头文件://Linux平台的gpio头文件#include//三</div> </li> <li><a href="/article/1835489438243844096.htm" title="Low Power概念介绍-Voltage Area" target="_blank">Low Power概念介绍-Voltage Area</a> <span class="text-muted">飞奔的大虎</span> <div>随着智能手机,以及物联网的普及,芯片功耗的问题最近几年得到了越来越多的重视。为了实现集成电路的低功耗设计目标,我们需要在系统设计阶段就采用低功耗设计的方案。而且,随着设计流程的逐步推进,到了芯片后端设计阶段,降低芯片功耗的方法已经很少了,节省的功耗百分比也不断下降。芯片的功耗主要由静态功耗(staticleakagepower)和动态功耗(dynamicpower)构成。静态功耗主要是指电路处于等</div> </li> <li><a href="/article/1835485681187647488.htm" title="【华为OD技术面试真题精选 - 非技术题】 -HR面,综合面_华为od hr面" target="_blank">【华为OD技术面试真题精选 - 非技术题】 -HR面,综合面_华为od hr面</a> <span class="text-muted">一个射手座的程序媛</span> <a class="tag" taget="_blank" href="/search/%E7%A8%8B%E5%BA%8F%E5%91%98/1.htm">程序员</a><a class="tag" taget="_blank" href="/search/%E5%8D%8E%E4%B8%BAod/1.htm">华为od</a><a class="tag" taget="_blank" href="/search/%E9%9D%A2%E8%AF%95/1.htm">面试</a><a class="tag" taget="_blank" href="/search/%E8%81%8C%E5%9C%BA%E5%92%8C%E5%8F%91%E5%B1%95/1.htm">职场和发展</a> <div>最后的话最近很多小伙伴找我要Linux学习资料,于是我翻箱倒柜,整理了一些优质资源,涵盖视频、电子书、PPT等共享给大家!资料预览给大家整理的视频资料:给大家整理的电子书资料:如果本文对你有帮助,欢迎点赞、收藏、转发给朋友,让我有持续创作的动力!网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。需要这份系统化的资料的朋友,可以点击这里获</div> </li> <li><a href="/article/1835479645701632000.htm" title="道阻且长,行则将至" target="_blank">道阻且长,行则将至</a> <span class="text-muted">sweet橘子</span> <div>本文参与书香澜梦主题征文“行”文章原创首发,文责自负。我们每一个人都应该有属于自己的愿望或者是理想,人一但有了理想也就算是有了方向,它就会像灯塔一样指引我们前进的方向,哪怕是再远大的理想,如果坚持,那么我相信它就一定有收获。屈原是我最喜欢的一个浪漫主义的诗人,他曾今说过:“路漫漫其修远兮,吾将上下而求索。”人生的道路很长,但是为了实现自己的理想抱负我愿意付出我毕生的精力,只专注这一件事,因为“道阻</div> </li> <li><a href="/article/1835477614848995328.htm" title="insert into select 主键自增_mybatis拦截器实现主键自动生成" target="_blank">insert into select 主键自增_mybatis拦截器实现主键自动生成</a> <span class="text-muted">weixin_39521651</span> <a class="tag" taget="_blank" href="/search/insert/1.htm">insert</a><a class="tag" taget="_blank" href="/search/into/1.htm">into</a><a class="tag" taget="_blank" href="/search/select/1.htm">select</a><a class="tag" taget="_blank" href="/search/%E4%B8%BB%E9%94%AE%E8%87%AA%E5%A2%9E/1.htm">主键自增</a><a class="tag" taget="_blank" href="/search/mybatis/1.htm">mybatis</a><a class="tag" taget="_blank" href="/search/delete%E8%BF%94%E5%9B%9E%E5%80%BC/1.htm">delete返回值</a><a class="tag" taget="_blank" href="/search/mybatis/1.htm">mybatis</a><a class="tag" taget="_blank" href="/search/insert%E8%BF%94%E5%9B%9E%E4%B8%BB%E9%94%AE/1.htm">insert返回主键</a><a class="tag" taget="_blank" href="/search/mybatis/1.htm">mybatis</a><a class="tag" taget="_blank" href="/search/insert%E8%BF%94%E5%9B%9E%E5%AF%B9%E8%B1%A1/1.htm">insert返回对象</a><a class="tag" taget="_blank" href="/search/mybatis/1.htm">mybatis</a><a class="tag" taget="_blank" href="/search/plus/1.htm">plus</a><a class="tag" taget="_blank" href="/search/insert%E8%BF%94%E5%9B%9E%E4%B8%BB%E9%94%AE/1.htm">insert返回主键</a><a class="tag" taget="_blank" href="/search/mybatis/1.htm">mybatis</a><a class="tag" taget="_blank" href="/search/plus/1.htm">plus</a><a class="tag" taget="_blank" href="/search/%E6%8F%92%E5%85%A5%E7%94%9F%E6%88%90id/1.htm">插入生成id</a> <div>前言前阵子和朋友聊天,他说他们项目有个需求,要实现主键自动生成,不想每次新增的时候,都手动设置主键。于是我就问他,那你们数据库表设置主键自动递增不就得了。他的回答是他们项目目前的id都是采用雪花算法来生成,因此为了项目稳定性,不会切换id的生成方式。朋友问我有没有什么实现思路,他们公司的orm框架是mybatis,我就建议他说,不然让你老大把mybatis切换成mybatis-plus。mybat</div> </li> <li><a href="/article/1835477111977111552.htm" title="和自己结婚,是一种怎样的体验" target="_blank">和自己结婚,是一种怎样的体验</a> <span class="text-muted">只如初见_2020</span> <div>一个17岁谈恋爱,19岁结婚,然后离了三次婚的女人,站在台上说:“现在我结婚了,和那个一直以来,真正想在一起的人结婚了,那个人就是我自己。”她说,在我9岁前,我已经在二十几个寄养家庭中待过。我从童年到成年,就只有一个目标,不要被落下。而我实现这一目标的方式就是,我要结婚。我第一次的结婚对象,是我17岁时遇到的人。我们两年之后结了婚,当时我19岁。他是个非常好的人,来自于非常棒的家庭,他是工商管理硕</div> </li> <li><a href="/article/1835476093189058560.htm" title="Java 重写(Override)与重载(Overload)" target="_blank">Java 重写(Override)与重载(Overload)</a> <span class="text-muted">叨唧唧的</span> <div>Java重写(Override)与重载(Overload)重写(Override)重写是子类对父类的允许访问的方法的实现过程进行重新编写,返回值和形参都不能改变。即外壳不变,核心重写!重写的好处在于子类可以根据需要,定义特定于自己的行为。也就是说子类能够根据需要实现父类的方法。重写方法不能抛出新的检查异常或者比被重写方法申明更加宽泛的异常。例如:父类的一个方法申明了一个检查异常IOExceptio</div> </li> <li><a href="/article/1835473957185220608.htm" title="网络编程基础" target="_blank">网络编程基础</a> <span class="text-muted">记得开心一点啊</span> <a class="tag" taget="_blank" href="/search/%E7%BD%91%E7%BB%9C/1.htm">网络</a> <div>目录♫什么是网络编程♫Socket套接字♪什么是Socket套接字♪数据报套接字♪流套接字♫数据报套接字通信模型♪数据报套接字通讯模型♪DatagramSocket♪DatagramPacket♪实现UDP的服务端代码♪实现UDP的客户端代码♫流套接字通信模型♪流套接字通讯模型♪ServerSocket♪Socket♪实现TCP的服务端代码♪实现TCP的客户端代码♫什么是网络编程网络编程,指网络上</div> </li> <li><a href="/article/1835472571445899264.htm" title="xilinx vivado PULLMODE 设置思路" target="_blank">xilinx vivado PULLMODE 设置思路</a> <span class="text-muted">坚持每天写程序</span> <a class="tag" taget="_blank" href="/search/fpga%E5%BC%80%E5%8F%91/1.htm">fpga开发</a> <div>1.xilinx引脚分类XilinxIO的分类:以XC7A100TFGG484为例,其引脚分类如下:1.UserIO(用户IO):用户使用的普通IO1.1专用(Dedicated)IO:命名为IO_LXXY_#、IO_XX_#的引脚,有固定的特定用途,多为底层特定功能的直接实现,如差分对信号、关键控制信号等,不能随意变更。1.2多功能(Multi-Function)IO:命名为IO_LXXY_ZZ</div> </li> <li><a href="/article/1835469859710922752.htm" title="母亲节如何做小红书营销" target="_blank">母亲节如何做小红书营销</a> <span class="text-muted">美橙传媒</span> <div>小红书的一举一动引起了外界的高度关注。通过爆款笔记和流行话题,我们可以看到“干货”类型的内容在小红书中偏向实用的生活经验共享和生活指南非常受欢迎。根据运营社的分析,这种现象是由小红书用户心智和内容社区背后机制共同决定的。首先,小红书将使用“强搜索”逻辑为用户提供特定的“搜索场景”。在“我必须这样生活”中,大量使用了满足小红书站用户喜好和需求的内容。内容社区自制的高质量内容也吸引了寻找营销新途径的品</div> </li> <li><a href="/article/1835469798838988800.htm" title="Python实现简单的机器学习算法" target="_blank">Python实现简单的机器学习算法</a> <span class="text-muted">master_chenchengg</span> <a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/%E5%8A%9E%E5%85%AC%E6%95%88%E7%8E%87/1.htm">办公效率</a><a class="tag" taget="_blank" href="/search/python%E5%BC%80%E5%8F%91/1.htm">python开发</a><a class="tag" taget="_blank" href="/search/IT/1.htm">IT</a> <div>Python实现简单的机器学习算法开篇:初探机器学习的奇妙之旅搭建环境:一切从安装开始必备工具箱第一步:安装Anaconda和JupyterNotebook小贴士:如何配置Python环境变量算法初体验:从零开始的Python机器学习线性回归:让数据说话数据准备:从哪里找数据编码实战:Python实现线性回归模型评估:如何判断模型好坏逻辑回归:从分类开始理论入门:什么是逻辑回归代码实现:使用skl</div> </li> <li><a href="/article/1835468915828944896.htm" title="C语言 判断回文数" target="_blank">C语言 判断回文数</a> <span class="text-muted">Y雨何时停T</span> <a class="tag" taget="_blank" href="/search/c%E8%AF%AD%E8%A8%80/1.htm">c语言</a><a class="tag" taget="_blank" href="/search/%E5%AD%A6%E4%B9%A0/1.htm">学习</a> <div>一,回文数概念“回文”是指正读反读都能读通的句子,它是古今中外都有的一种修辞方式和文字游戏,如“我为人人,人人为我”等。在数学中也有这样一类数字有这样的特征,成为回文数。设n是一任意自然数。若将n的各位数字反向排列所得自然数n1与n相等,则称n为一回文数。例如,若n=1234321,则称n为一回文数;但若n=1234567,则n不是回文数。二,判断回文数实现思路一:数组与字符串将数字每一位按顺序放</div> </li> <li><a href="/article/1835467944805625856.htm" title="九月班级管理工作反思" target="_blank">九月班级管理工作反思</a> <span class="text-muted">追梦蜂</span> <div>这个月应该算是最难的一个月,我已N年没当班主任,然后我又开始当了。职称是一方面,想到我如果退休了,不能再接触学生了,那该是多么遗憾的事!我的学生梁*铭是我的榜样,她那么努力,那么拼,那么上进,为什么我不行?虽然我面临的工作很难,但是高考数学也不容易。她拿下来了!满分150分她考了146分!我目睹她的艰辛,她的拼搏!还有,我要为我的孩子做榜样,如何竭尽全力,实现梦想。还有,服务,为社会做事,也是会有</div> </li> <li><a href="/article/1835466923974946816.htm" title="2021-01-24" target="_blank">2021-01-24</a> <span class="text-muted">9ce517ee104c</span> <div>【打卡素材】《香帅金融学讲义》【标题】公司治理:怎样同床异梦地过下去【日期】2021.1.24【字数】公司本质上是一连串的合约关系。降低合同执行中的各种摩擦是公司正常有效运行的基础。协同各方的利益、制衡各方的权力是关键。为解决利益冲突问题、协同各方利益,进行权力制衡的机制设计就是公司治理机制。001什么是公司治理治理是管理的基础,治理机制越好,权、责、利就越清晰,管理的目标也就会更容易实现。002</div> </li> <li><a href="/article/119.htm" title="Spring中@Value注解,需要注意的地方" target="_blank">Spring中@Value注解,需要注意的地方</a> <span class="text-muted">无量</span> <a class="tag" taget="_blank" href="/search/spring/1.htm">spring</a><a class="tag" taget="_blank" href="/search/bean/1.htm">bean</a><a class="tag" taget="_blank" href="/search/%40Value/1.htm">@Value</a><a class="tag" taget="_blank" href="/search/xml/1.htm">xml</a> <div>Spring 3以后,支持@Value注解的方式获取properties文件中的配置值,简化了读取配置文件的复杂操作 1、在applicationContext.xml文件(或引用文件中)中配置properties文件 <bean id="appProperty" class="org.springframework.beans.fac</div> </li> <li><a href="/article/246.htm" title="mongoDB 分片" target="_blank">mongoDB 分片</a> <span class="text-muted">开窍的石头</span> <a class="tag" taget="_blank" href="/search/mongodb/1.htm">mongodb</a> <div>    mongoDB的分片。要mongos查询数据时候 先查询configsvr看数据在那台shard上,configsvr上边放的是metar信息,指的是那条数据在那个片上。由此可以看出mongo在做分片的时候咱们至少要有一个configsvr,和两个以上的shard(片)信息。     第一步启动两台以上的mongo服务 &nb</div> </li> <li><a href="/article/373.htm" title="OVER(PARTITION BY)函数用法" target="_blank">OVER(PARTITION BY)函数用法</a> <span class="text-muted">0624chenhong</span> <a class="tag" taget="_blank" href="/search/oracle/1.htm">oracle</a> <div>这篇写得很好,引自 http://www.cnblogs.com/lanzi/archive/2010/10/26/1861338.html OVER(PARTITION BY)函数用法 2010年10月26日 OVER(PARTITION BY)函数介绍 开窗函数        &nb</div> </li> <li><a href="/article/500.htm" title="Android开发中,ADB server didn't ACK 解决方法" target="_blank">Android开发中,ADB server didn't ACK 解决方法</a> <span class="text-muted">一炮送你回车库</span> <a class="tag" taget="_blank" href="/search/Android%E5%BC%80%E5%8F%91/1.htm">Android开发</a> <div>首先通知:凡是安装360、豌豆荚、腾讯管家的全部卸载,然后再尝试。   一直没搞明白这个问题咋出现的,但今天看到一个方法,搞定了!原来是豌豆荚占用了 5037 端口导致。 参见原文章:一个豌豆荚引发的血案——关于ADB server didn't ACK的问题 简单来讲,首先将Windows任务进程中的豌豆荚干掉,如果还是不行,再继续按下列步骤排查。 &nb</div> </li> <li><a href="/article/627.htm" title="canvas中的像素绘制问题" target="_blank">canvas中的像素绘制问题</a> <span class="text-muted">换个号韩国红果果</span> <a class="tag" taget="_blank" href="/search/JavaScript/1.htm">JavaScript</a><a class="tag" taget="_blank" href="/search/canvas/1.htm">canvas</a> <div>pixl的绘制,1.如果绘制点正处于相邻像素交叉线,绘制x像素的线宽,则从交叉线分别向前向后绘制x/2个像素,如果x/2是整数,则刚好填满x个像素,如果是小数,则先把整数格填满,再去绘制剩下的小数部分,绘制时,是将小数部分的颜色用来除以一个像素的宽度,颜色会变淡。所以要用整数坐标来画的话(即绘制点正处于相邻像素交叉线时),线宽必须是2的整数倍。否则会出现不饱满的像素。 2.如果绘制点为一个像素的</div> </li> <li><a href="/article/754.htm" title="编码乱码问题" target="_blank">编码乱码问题</a> <span class="text-muted">灵静志远</span> <a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/jvm/1.htm">jvm</a><a class="tag" taget="_blank" href="/search/jsp/1.htm">jsp</a><a class="tag" taget="_blank" href="/search/%E7%BC%96%E7%A0%81/1.htm">编码</a> <div>1、JVM中单个字符占用的字节长度跟编码方式有关,而默认编码方式又跟平台是一一对应的或说平台决定了默认字符编码方式;2、对于单个字符:ISO-8859-1单字节编码,GBK双字节编码,UTF-8三字节编码;因此中文平台(中文平台默认字符集编码GBK)下一个中文字符占2个字节,而英文平台(英文平台默认字符集编码Cp1252(类似于ISO-8859-1))。 3、getBytes()、getByte</div> </li> <li><a href="/article/881.htm" title="java 求几个月后的日期" target="_blank">java 求几个月后的日期</a> <span class="text-muted">darkranger</span> <a class="tag" taget="_blank" href="/search/calendar/1.htm">calendar</a><a class="tag" taget="_blank" href="/search/getinstance/1.htm">getinstance</a> <div>Date plandate = planDate.toDate(); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); Calendar cal = Calendar.getInstance(); cal.setTime(plandate); // 取得三个月后时间 cal.add(Calendar.M</div> </li> <li><a href="/article/1008.htm" title="数据库设计的三大范式(通俗易懂)" target="_blank">数据库设计的三大范式(通俗易懂)</a> <span class="text-muted">aijuans</span> <a class="tag" taget="_blank" href="/search/%E6%95%B0%E6%8D%AE%E5%BA%93%E5%A4%8D%E4%B9%A0/1.htm">数据库复习</a> <div>关系数据库中的关系必须满足一定的要求。满足不同程度要求的为不同范式。数据库的设计范式是数据库设计所需要满足的规范。只有理解数据库的设计范式,才能设计出高效率、优雅的数据库,否则可能会设计出错误的数据库. 目前,主要有六种范式:第一范式、第二范式、第三范式、BC范式、第四范式和第五范式。满足最低要求的叫第一范式,简称1NF。在第一范式基础上进一步满足一些要求的为第二范式,简称2NF。其余依此类推。</div> </li> <li><a href="/article/1135.htm" title="想学工作流怎么入手" target="_blank">想学工作流怎么入手</a> <span class="text-muted">atongyeye</span> <a class="tag" taget="_blank" href="/search/jbpm/1.htm">jbpm</a> <div>工作流在工作中变得越来越重要,很多朋友想学工作流却不知如何入手。 很多朋友习惯性的这看一点,那了解一点,既不系统,也容易半途而废。好比学武功,最好的办法是有一本武功秘籍。研究明白,则犹如打通任督二脉。 系统学习工作流,很重要的一本书《JBPM工作流开发指南》。 本人苦苦学习两个月,基本上可以解决大部分流程问题。整理一下学习思路,有兴趣的朋友可以参考下。 1  首先要</div> </li> <li><a href="/article/1262.htm" title="Context和SQLiteOpenHelper创建数据库" target="_blank">Context和SQLiteOpenHelper创建数据库</a> <span class="text-muted">百合不是茶</span> <a class="tag" taget="_blank" href="/search/android/1.htm">android</a><a class="tag" taget="_blank" href="/search/Context%E5%88%9B%E5%BB%BA%E6%95%B0%E6%8D%AE%E5%BA%93/1.htm">Context创建数据库</a> <div>       一直以为安卓数据库的创建就是使用SQLiteOpenHelper创建,但是最近在android的一本书上看到了Context也可以创建数据库,下面我们一起分析这两种方式创建数据库的方式和区别,重点在SQLiteOpenHelper     一:SQLiteOpenHelper创建数据库:   1,SQLi</div> </li> <li><a href="/article/1389.htm" title="浅谈group by和distinct" target="_blank">浅谈group by和distinct</a> <span class="text-muted">bijian1013</span> <a class="tag" taget="_blank" href="/search/oracle/1.htm">oracle</a><a class="tag" taget="_blank" href="/search/%E6%95%B0%E6%8D%AE%E5%BA%93/1.htm">数据库</a><a class="tag" taget="_blank" href="/search/group+by/1.htm">group by</a><a class="tag" taget="_blank" href="/search/distinct/1.htm">distinct</a> <div>        group by和distinct只了去重意义一样,但是group by应用范围更广泛些,如分组汇总或者从聚合函数里筛选数据等。         譬如:统计每id数并且只显示数大于3 select id ,count(id) from ta</div> </li> <li><a href="/article/1516.htm" title="vi opertion" target="_blank">vi opertion</a> <span class="text-muted">征客丶</span> <a class="tag" taget="_blank" href="/search/mac/1.htm">mac</a><a class="tag" taget="_blank" href="/search/opration/1.htm">opration</a><a class="tag" taget="_blank" href="/search/vi/1.htm">vi</a> <div>进入 command mode (命令行模式) 按 esc 键 再按 shift + 冒号 注:以下命令中 带 $ 【在命令行模式下进行】,不带 $ 【在非命令行模式下进行】 一、文件操作 1.1、强制退出不保存 $ q! 1.2、保存 $ w 1.3、保存并退出 $ wq 1.4、刷新或重新加载已打开的文件 $ e 二、光标移动 2.1、跳到指定行 数字</div> </li> <li><a href="/article/1643.htm" title="【Spark十四】深入Spark RDD第三部分RDD基本API" target="_blank">【Spark十四】深入Spark RDD第三部分RDD基本API</a> <span class="text-muted">bit1129</span> <a class="tag" taget="_blank" href="/search/spark/1.htm">spark</a> <div>  对于K/V类型的RDD,如下操作是什么含义?   val rdd = sc.parallelize(List(("A",3),("C",6),("A",1),("B",5)) rdd.reduceByKey(_+_).collect  reduceByKey在这里的操作,是把</div> </li> <li><a href="/article/1770.htm" title="java类加载机制" target="_blank">java类加载机制</a> <span class="text-muted">BlueSkator</span> <a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/%E8%99%9A%E6%8B%9F%E6%9C%BA/1.htm">虚拟机</a> <div>java类加载机制 1.java类加载器的树状结构 引导类加载器 ^ | 扩展类加载器 ^ | 系统类加载器 java使用代理模式来完成类加载,java的类加载器也有类似于继承的关系,引导类是最顶层的加载器,它是所有类的根加载器,它负责加载java核心库。当一个类加载器接到装载类到虚拟机的请求时,通常会代理给父类加载器,若已经是根加载器了,就自己完成加载。 虚拟机区分一个Cla</div> </li> <li><a href="/article/1897.htm" title="动态添加文本框" target="_blank">动态添加文本框</a> <span class="text-muted">BreakingBad</span> <a class="tag" taget="_blank" href="/search/%E6%96%87%E6%9C%AC%E6%A1%86/1.htm">文本框</a> <div>  <script>     var num=1; function AddInput() {      var str="";     str+="<input </div> </li> <li><a href="/article/2024.htm" title="读《研磨设计模式》-代码笔记-单例模式" target="_blank">读《研磨设计模式》-代码笔记-单例模式</a> <span class="text-muted">bylijinnan</span> <a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F/1.htm">设计模式</a> <div>声明: 本文只为方便我个人查阅和理解,详细的分析以及源代码请移步 原作者的博客http://chjavach.iteye.com/ public class Singleton { } /* * 懒汉模式。注意,getInstance如果在多线程环境中调用,需要加上synchronized,否则存在线程不安全问题 */ class LazySingleton</div> </li> <li><a href="/article/2151.htm" title="iOS应用打包发布常见问题" target="_blank">iOS应用打包发布常见问题</a> <span class="text-muted">chenhbc</span> <a class="tag" taget="_blank" href="/search/ios/1.htm">ios</a><a class="tag" taget="_blank" href="/search/iOS%E5%8F%91%E5%B8%83/1.htm">iOS发布</a><a class="tag" taget="_blank" href="/search/iOS%E4%B8%8A%E4%BC%A0/1.htm">iOS上传</a><a class="tag" taget="_blank" href="/search/iOS%E6%89%93%E5%8C%85/1.htm">iOS打包</a> <div>这个月公司安排我一个人做iOS客户端开发,由于急着用,我先发布一个版本,由于第一次发布iOS应用,期间出了不少问题,记录于此。   1、使用Application Loader 发布时报错:Communication error.please use diagnostic mode to check connectivity.you need to have outbound acc</div> </li> <li><a href="/article/2278.htm" title="工作流复杂拓扑结构处理新思路" target="_blank">工作流复杂拓扑结构处理新思路</a> <span class="text-muted">comsci</span> <a class="tag" taget="_blank" href="/search/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F/1.htm">设计模式</a><a class="tag" taget="_blank" href="/search/%E5%B7%A5%E4%BD%9C/1.htm">工作</a><a class="tag" taget="_blank" href="/search/%E7%AE%97%E6%B3%95/1.htm">算法</a><a class="tag" taget="_blank" href="/search/%E4%BC%81%E4%B8%9A%E5%BA%94%E7%94%A8/1.htm">企业应用</a><a class="tag" taget="_blank" href="/search/OO/1.htm">OO</a> <div> 我们走的设计路线和国外的产品不太一样,不一样在哪里呢?  国外的流程的设计思路是通过事先定义一整套规则(类似XPDL)来约束和控制流程图的复杂度(我对国外的产品了解不够多,仅仅是在有限的了解程度上面提出这样的看法),从而避免在流程引擎中处理这些复杂的图的问题,而我们却没有通过事先定义这样的复杂的规则来约束和降低用户自定义流程图的灵活性,这样一来,在引擎和流程流转控制这一个层面就会遇到很</div> </li> <li><a href="/article/2405.htm" title="oracle 11g新特性Flashback data archive" target="_blank">oracle 11g新特性Flashback data archive</a> <span class="text-muted">daizj</span> <a class="tag" taget="_blank" href="/search/oracle/1.htm">oracle</a> <div>1. 什么是flashback data archive Flashback data archive是oracle 11g中引入的一个新特性。Flashback archive是一个新的数据库对象,用于存储一个或多表的历史数据。Flashback archive是一个逻辑对象,概念上类似于表空间。实际上flashback archive可以看作是存储一个或多个表的所有事务变化的逻辑空间。 </div> </li> <li><a href="/article/2532.htm" title="多叉树:2-3-4树" target="_blank">多叉树:2-3-4树</a> <span class="text-muted">dieslrae</span> <a class="tag" taget="_blank" href="/search/%E6%A0%91/1.htm">树</a> <div>    平衡树多叉树,每个节点最多有4个子节点和3个数据项,2,3,4的含义是指一个节点可能含有的子节点的个数,效率比红黑树稍差.一般不允许出现重复关键字值.2-3-4树有以下特征:     1、有一个数据项的节点总是有2个子节点(称为2-节点)     2、有两个数据项的节点总是有3个子节点(称为3-节</div> </li> <li><a href="/article/2659.htm" title="C语言学习七动态分配 malloc的使用" target="_blank">C语言学习七动态分配 malloc的使用</a> <span class="text-muted">dcj3sjt126com</span> <a class="tag" taget="_blank" href="/search/c/1.htm">c</a><a class="tag" taget="_blank" href="/search/language/1.htm">language</a><a class="tag" taget="_blank" href="/search/malloc/1.htm">malloc</a> <div>/* 2013年3月15日15:16:24 malloc 就memory(内存) allocate(分配)的缩写 本程序没有实际含义,只是理解使用 */ # include <stdio.h> # include <malloc.h> int main(void) { int i = 5; //分配了4个字节 静态分配 int * p </div> </li> <li><a href="/article/2786.htm" title="Objective-C编码规范[译]" target="_blank">Objective-C编码规范[译]</a> <span class="text-muted">dcj3sjt126com</span> <a class="tag" taget="_blank" href="/search/%E4%BB%A3%E7%A0%81%E8%A7%84%E8%8C%83/1.htm">代码规范</a> <div>  原文链接 : The official raywenderlich.com Objective-C style guide 原文作者 : raywenderlich.com Team 译文出自 : raywenderlich.com Objective-C编码规范 译者 : Sam Lau </div> </li> <li><a href="/article/2913.htm" title="0.性能优化-目录" target="_blank">0.性能优化-目录</a> <span class="text-muted">frank1234</span> <a class="tag" taget="_blank" href="/search/%E6%80%A7%E8%83%BD%E4%BC%98%E5%8C%96/1.htm">性能优化</a> <div>从今天开始笔者陆续发表一些性能测试相关的文章,主要是对自己前段时间学习的总结,由于水平有限,性能测试领域很深,本人理解的也比较浅,欢迎各位大咖批评指正。 主要内容包括: 一、性能测试指标 吞吐量、TPS、响应时间、负载、可扩展性、PV、思考时间 http://frank1234.iteye.com/blog/2180305 二、性能测试策略 生产环境相同 基准测试 预热等 htt</div> </li> <li><a href="/article/3040.htm" title="Java父类取得子类传递的泛型参数Class类型" target="_blank">Java父类取得子类传递的泛型参数Class类型</a> <span class="text-muted">happyqing</span> <a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/%E6%B3%9B%E5%9E%8B/1.htm">泛型</a><a class="tag" taget="_blank" href="/search/%E7%88%B6%E7%B1%BB/1.htm">父类</a><a class="tag" taget="_blank" href="/search/%E5%AD%90%E7%B1%BB/1.htm">子类</a><a class="tag" taget="_blank" href="/search/Class/1.htm">Class</a> <div>  import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import org.junit.Test; abstract class BaseDao<T> { public void getType() { //Class<E> clazz =</div> </li> <li><a href="/article/3167.htm" title="跟我学SpringMVC目录汇总贴、PDF下载、源码下载" target="_blank">跟我学SpringMVC目录汇总贴、PDF下载、源码下载</a> <span class="text-muted">jinnianshilongnian</span> <a class="tag" taget="_blank" href="/search/springMVC/1.htm">springMVC</a> <div>  ----广告-------------------------------------------------------------- 网站核心商详页开发 掌握Java技术,掌握并发/异步工具使用,熟悉spring、ibatis框架; 掌握数据库技术,表设计和索引优化,分库分表/读写分离; 了解缓存技术,熟练使用如Redis/Memcached等主流技术; 了解Ngin</div> </li> <li><a href="/article/3294.htm" title="the HTTP rewrite module requires the PCRE library" target="_blank">the HTTP rewrite module requires the PCRE library</a> <span class="text-muted">流浪鱼</span> <a class="tag" taget="_blank" href="/search/rewrite/1.htm">rewrite</a> <div>./configure: error: the HTTP rewrite module requires the PCRE library. 模块依赖性Nginx需要依赖下面3个包 1. gzip 模块需要 zlib 库 ( 下载: http://www.zlib.net/ ) 2. rewrite 模块需要 pcre 库 ( 下载: http://www.pcre.org/ ) 3. s</div> </li> <li><a href="/article/3421.htm" title="第12章 Ajax(中)" target="_blank">第12章 Ajax(中)</a> <span class="text-muted">onestopweb</span> <a class="tag" taget="_blank" href="/search/Ajax/1.htm">Ajax</a> <div>index.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/</div> </li> <li><a href="/article/3548.htm" title="Optimize query with Query Stripping in Web Intelligence" target="_blank">Optimize query with Query Stripping in Web Intelligence</a> <span class="text-muted">blueoxygen</span> <a class="tag" taget="_blank" href="/search/BO/1.htm">BO</a> <div>http://wiki.sdn.sap.com/wiki/display/BOBJ/Optimize+query+with+Query+Stripping+in+Web+Intelligence and a very straightfoward video http://www.sdn.sap.com/irj/scn/events?rid=/library/uuid/40ec3a0c-936</div> </li> <li><a href="/article/3675.htm" title="Java开发者写SQL时常犯的10个错误" target="_blank">Java开发者写SQL时常犯的10个错误</a> <span class="text-muted">tomcat_oracle</span> <a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/sql/1.htm">sql</a> <div>1、不用PreparedStatements   有意思的是,在JDBC出现了许多年后的今天,这个错误依然出现在博客、论坛和邮件列表中,即便要记住和理解它是一件很简单的事。开发者不使用PreparedStatements的原因可能有如下几个:   他们对PreparedStatements不了解   他们认为使用PreparedStatements太慢了   他们认为写Prepar</div> </li> <li><a href="/article/3802.htm" title="世纪互联与结盟有感" target="_blank">世纪互联与结盟有感</a> <span class="text-muted">阿尔萨斯</span> <div> 10月10日,世纪互联与(Foxcon)签约成立合资公司,有感。 全球电子制造业巨头(全球500强企业)与世纪互联共同看好IDC、云计算等业务在中国的增长空间,双方迅速果断出手,在资本层面上达成合作,此举体现了全球电子制造业巨头对世纪互联IDC业务的欣赏与信任,另一方面反映出世纪互联目前良好的运营状况与广阔的发展前景。 众所周知,精于电子产品制造(世界第一),对于世纪互联而言,能够与结盟</div> </li> </ul> </div> </div> </div> <div> <div class="container"> <div class="indexes"> <strong>按字母分类:</strong> <a href="/tags/A/1.htm" target="_blank">A</a><a href="/tags/B/1.htm" target="_blank">B</a><a href="/tags/C/1.htm" target="_blank">C</a><a href="/tags/D/1.htm" target="_blank">D</a><a href="/tags/E/1.htm" target="_blank">E</a><a href="/tags/F/1.htm" target="_blank">F</a><a href="/tags/G/1.htm" target="_blank">G</a><a href="/tags/H/1.htm" target="_blank">H</a><a href="/tags/I/1.htm" target="_blank">I</a><a href="/tags/J/1.htm" target="_blank">J</a><a href="/tags/K/1.htm" target="_blank">K</a><a href="/tags/L/1.htm" target="_blank">L</a><a href="/tags/M/1.htm" target="_blank">M</a><a href="/tags/N/1.htm" target="_blank">N</a><a href="/tags/O/1.htm" target="_blank">O</a><a href="/tags/P/1.htm" target="_blank">P</a><a href="/tags/Q/1.htm" target="_blank">Q</a><a href="/tags/R/1.htm" target="_blank">R</a><a href="/tags/S/1.htm" target="_blank">S</a><a href="/tags/T/1.htm" target="_blank">T</a><a href="/tags/U/1.htm" target="_blank">U</a><a href="/tags/V/1.htm" target="_blank">V</a><a href="/tags/W/1.htm" target="_blank">W</a><a href="/tags/X/1.htm" target="_blank">X</a><a href="/tags/Y/1.htm" target="_blank">Y</a><a href="/tags/Z/1.htm" target="_blank">Z</a><a href="/tags/0/1.htm" target="_blank">其他</a> </div> </div> </div> <footer id="footer" class="mb30 mt30"> <div class="container"> <div class="footBglm"> <a target="_blank" href="/">首页</a> - <a target="_blank" href="/custom/about.htm">关于我们</a> - <a target="_blank" href="/search/Java/1.htm">站内搜索</a> - <a target="_blank" href="/sitemap.txt">Sitemap</a> - <a target="_blank" href="/custom/delete.htm">侵权投诉</a> </div> <div class="copyright">版权所有 IT知识库 CopyRight © 2000-2050 E-COM-NET.COM , All Rights Reserved. <!-- <a href="https://beian.miit.gov.cn/" rel="nofollow" target="_blank">京ICP备09083238号</a><br>--> </div> </div> </footer> <!-- 代码高亮 --> <script type="text/javascript" src="/static/syntaxhighlighter/scripts/shCore.js"></script> <script type="text/javascript" src="/static/syntaxhighlighter/scripts/shLegacy.js"></script> <script type="text/javascript" src="/static/syntaxhighlighter/scripts/shAutoloader.js"></script> <link type="text/css" rel="stylesheet" href="/static/syntaxhighlighter/styles/shCoreDefault.css"/> <script type="text/javascript" src="/static/syntaxhighlighter/src/my_start_1.js"></script> </body> </html>