搜索词>>redis 耗时0.0040
  • redis 命令查看使用情况redis info命令详解_redis查看内存使用情况

    redis 命令查看使用情况redis info命令详解,redis查看内存使用情况。redis info命令的详细解释<p>通过redis-cli连接到redis服务</p> <pre> <code class="language-html">redis-cli -h 192.168.1.3 -p 6300 192.168.1.3:6300> 192.168.1.3:6300> auth pass 192.168.1.3:6300> info all</code></pre> <pre> <code class="language-bash"># Server(服务器信息) redis_version:3.0.0                              #redis服务器版本 redis_git_sha1:00000000                  #Git SHA1 redis_git_dirty:0                                    #Git dirty flag redis_build_id:6c2c390b97607ff0    #redis build id redis_mode:cluster                              #运行模式,单机或者集群 os:Linux 2.6.32-358.2.1.el6.x86_64 x86_64 #redis服务器的宿主操作系统 arch_bits:64                                         #架构(32或64位) multiplexing_api:epoll                        #redis所使用的事件处理机制 gcc_version:4.4.7                                #编译redis时所使用的gcc版本 process_id:12099                               #redis服务器进程的pid run_id:63bcd0e57adb695ff0bf873cf42d403ddbac1565  #redis服务器的随机标识符(用于sentinel和集群) tcp_port:9021                                #redis服务器监听端口 uptime_in_seconds:26157730   #redis服务器启动总时间,单位是秒 uptime_in_days:302                    #redis服务器启动总时间,单位是天 hz:10                                #redis内部调度(进行关闭timeout的客户端,删除过期key等等)频率,程序规定serverCron每秒运行10次。 lru_clock:14359959      #自增的时钟,用于LRU管理,该时钟100ms(hz=10,因此每1000ms/10=100ms执行一次定时任务)更新一次。 config_file:/redis_cluster/etc/9021.conf  #配置文件路径 # Clients(已连接客户端信息) connected_clients:1081       #已连接客户端的数量(不包括通过slave连接的客户端) client_longest_output_list:0 #当前连接的客户端当中,最长的输出列表,用client list命令观察omem字段最大值 client_biggest_input_buf:0   #当前连接的客户端当中,最大输入缓存,用client list命令观察qbuf和qbuf-free两个字段最大值 blocked_clients:0                   #正在等待阻塞命令(BLPOP、BRPOP、BRPOPLPUSH)的客户端的数量 # Memory(内存信息) used_memory:327494024                 #由redis分配器分配的内存总量,以字节为单位 used_memory_human:312.32M       #以人类可读的格式返回redis分配的内存总量 used_memory_rss:587247616         #从操作系统的角度,返回redis已分配的内存总量(俗称常驻集大小)。这个值和top命令的输出一致 used_memory_peak:1866541112    #redis的内存消耗峰值(以字节为单位)  used_memory_peak_human:1.74G #以人类可读的格式返回redis的内存消耗峰值 used_memory_lua:35840                   #lua引擎所使用的内存大小(以字节为单位) mem_fragmentation_ratio:1.79          #used_memory_rss和used_memory之间的比率,小于1表示使用了swap,大于1表示碎片比较多 mem_allocator:jemalloc-3.6.0            #在编译时指定的redis所使用的内存分配器。可以是libc、jemalloc或者tcmalloc # Persistence(rdb和aof的持久化相关信息) loading:0                                                    #服务器是否正在载入持久化文件 rdb_changes_since_last_save:28900855 #离最近一次成功生成rdb文件,写入命令的个数,即有多少个写入命令没有持久化 rdb_bgsave_in_progress:0                  #服务器是否正在创建rdb文件 rdb_last_save_time:1482358115        #离最近一次成功创建rdb文件的时间戳。当前时间戳 - rdb_last_save_time=多少秒未成功生成rdb文件 rdb_last_bgsave_status:ok                   #最近一次rdb持久化是否成功 rdb_last_bgsave_time_sec:2                #最近一次成功生成rdb文件耗时秒数 rdb_current_bgsave_time_sec:-1        #如果服务器正在创建rdb文件,那么这个域记录的就是当前的创建操作已经耗费的秒数 aof_enabled:1                                          #是否开启了aof aof_rewrite_in_progress:0                     #标识aof的rewrite操作是否在进行中 aof_rewrite_scheduled:0               #rewrite任务计划,当客户端发送bgrewriteaof指令,如果当前rewrite子进程正在执行,那么将客户端请求的bgrewriteaof变为计划任务,待aof子进程结束后执行rewrite  aof_last_rewrite_time_sec:-1            #最近一次aof rewrite耗费的时长 aof_current_rewrite_time_sec:-1      #如果rewrite操作正在进行,则记录所使用的时间,单位秒 aof_last_bgrewrite_status:ok             #上次bgrewriteaof操作的状态 aof_last_write_status:ok                     #上次aof写入状态 aof_current_size:4201740                 #aof当前尺寸 aof_base_size:4201687                    #服务器启动时或者aof重写最近一次执行之后aof文件的大小 aof_pending_rewrite:0                       #是否有aof重写操作在等待rdb文件创建完毕之后执行? aof_buffer_length:0                             #aof buffer的大小 aof_rewrite_buffer_length:0              #aof rewrite buffer的大小 aof_pending_bio_fsync:0                  #后台I/O队列里面,等待执行的fsync调用数量 aof_delayed_fsync:0                          #被延迟的fsync调用数量 # Stats(一般统计信息) total_connections_received:209561105 #新创建连接个数,如果新创建连接过多,过度地创建和销毁连接对性能有影响,说明短连接严重或连接池使用有问题,需调研代码的连接设置 total_commands_processed:2220123478  #redis处理的命令数 instantaneous_ops_per_sec:279                  #redis当前的qps,redis内部较实时的每秒执行的命令数 total_net_input_bytes:118515678789          #redis网络入口流量字节数 total_net_output_bytes:236361651271       #redis网络出口流量字节数 instantaneous_input_kbps:13.56                  #redis网络入口kps instantaneous_output_kbps:31.33               #redis网络出口kps rejected_connections:0                                   #拒绝的连接个数,redis连接个数达到maxclients限制,拒绝新连接的个数 sync_full:1                                                          #主从完全同步成功次数 sync_partial_ok:0                                             #主从部分同步成功次数 sync_partial_err:0                                            #主从部分同步失败次数 expired_keys:15598177                                #运行以来过期的key的数量 evicted_keys:0                                                 #运行以来剔除(超过了maxmemory后)的key的数量 keyspace_hits:1122202228                          #命中次数 keyspace_misses:577781396                     #没命中次数 pubsub_channels:0                                       #当前使用中的频道数量 pubsub_patterns:0                                         #当前使用的模式的数量 latest_fork_usec:15679                                 #最近一次fork操作阻塞redis进程的耗时数,单位微秒 migrate_cached_sockets:0                          # # Replication(主从信息,master上显示的信息) role:master                               #实例的角色,是master or slave connected_slaves:1              #连接的slave实例个数 slave0:ip=192.168.64.104,port=9021,state=online,offset=6713173004,lag=0 #lag从库多少秒未向主库发送REPLCONF命令 master_repl_offset:6713173145  #主从同步偏移量,此值如果和上面的offset相同说明主从一致没延迟 repl_backlog_active:1                   #复制积压缓冲区是否开启 repl_backlog_size:134217728    #复制积压缓冲大小 repl_backlog_first_byte_offset:6578955418  #复制缓冲区里偏移量的大小 repl_backlog_histlen:134217728   #此值等于 master_repl_offset - repl_backlog_first_byte_offset,该值不会超过repl_backlog_size的大小 # Replication(主从信息,slave上显示的信息) role:slave                                        #实例的角色,是master or slave master_host:192.168.64.102       #此节点对应的master的ip master_port:9021                          #此节点对应的master的port master_link_status:up                   #slave端可查看它与master之间同步状态,当复制断开后表示down master_last_io_seconds_ago:0  #主库多少秒未发送数据到从库? master_sync_in_progress:0        #从服务器是否在与主服务器进行同步 slave_repl_offset:6713173818   #slave复制偏移量 slave_priority:100                          #slave优先级 slave_read_only:1                         #从库是否设置只读 connected_slaves:0                      #连接的slave实例个数 master_repl_offset:0          repl_backlog_active:0                  #复制积压缓冲区是否开启 repl_backlog_size:134217728   #复制积压缓冲大小 repl_backlog_first_byte_offset:0 #复制缓冲区里偏移量的大小 repl_backlog_histlen:0           #此值等于 master_repl_offset - repl_backlog_first_byte_offset,该值不会超过repl_backlog_size的大小 # CPU(CPU计算量统计信息) used_cpu_sys:96894.66             #将所有redis主进程在核心态所占用的CPU时求和累计起来 used_cpu_user:87397.39           #将所有redis主进程在用户态所占用的CPU时求和累计起来 used_cpu_sys_children:6.37     #将后台进程在核心态所占用的CPU时求和累计起来 used_cpu_user_children:52.83 #将后台进程在用户态所占用的CPU时求和累计起来 # Commandstats(各种不同类型的命令的执行统计信息) cmdstat_get:calls=1664657469,usec=8266063320,usec_per_call=4.97   #call每个命令执行次数,usec总共消耗的CPU时长(单位微秒),平均每次消耗的CPU时长(单位微秒) # Cluster(集群相关信息) cluster_enabled:1   #实例是否启用集群模式 # Keyspace(数据库相关的统计信息) db0:keys=194690,expires=191702,avg_ttl=3607772262 #db0的key的数量,以及带有生存期的key的数,平均存活时间</code></pre>
  • redis在window系统上的下载安装使用说明

    redis在window系统上的下载安装使用说明redis在window系统上的下载安装使用说明<br /> 去redis的官方网站你会发现下载下来的都是源码,支持Linux的make编译方式,并没有window版本的redis下载,其实官方有说明 <h3>Windows</h3> The Redis project does not officially support Windows. However, the Microsoft Open Tech group develops and maintains this Windows port targeting Win64. <a href="https://github.com/MSOpenTech/redis" rel="external nofollow" target="_blank" >Learn more</a><br /> 大概就是说:<br /> Redis项目没有正式支持Windows。 但是,Microsoft Open Tech组织开发并维护了面向Win64的Windows 64位<br /> 也就是说window版本是不是由redis官方维护的,是Microsoft Open Tech组织。其项目的GitHub地址为<br /> <a href="http://github.com/MSOpenTech/redis" rel="external nofollow" target="_blank" >http://github.com/MSOpenTech/redis</a><br /> <br /> 下载步骤,打开上面的url,你将看到以下界面(可能会有一点版本变化): <div style="text-align:center"> <figure class="image" style="display:inline-block"><img srcset="" width="" size="" class="img-thumbnail" alt="下载页面" src="/resources/assist/images/blog/0838f0d2-178b-4181-94a0-8517074e979a.png" /> <figcaption>下载页面</figcaption> </figure> </div> <br /> <br /> 点击release<br /> <img srcset="" width="" size="" class="img-thumbnail" alt="re" src="/resources/assist/images/blog/2a4956c9-d247-48c4-b896-8a9405a14507.png" /><br /> 这时候你就可以看到下载的页面: <div style="text-align:center"> <figure class="image" style="display:inline-block"><img srcset="" width="" size="" class="img-thumbnail" alt="download redis" src="/resources/assist/images/blog/244c4b23-eb9d-44fa-8100-ab017c20a658.png" /> <figcaption>download redis</figcaption> </figure> </div> <br /> <br /> 选择zip版或者msi版本,我这里下载的zip版本下载.<br /> <br /> <br /> 加压下载后的zip: <figure class="image"><img srcset="" width="" size="" class="img-thumbnail" alt="解压文件" src="/resources/assist/images/blog/8d7d6242-404d-4f9e-98b2-3ac65284ffd0.png" /> <figcaption>解压文件</figcaption> </figure> <br /> <br /> 使用cmd执行命令 <pre> <code>F:\迅雷下载\Redis-x64-3.2.100>redis-server.exe redis.windows.conf</code></pre> <strong><span style="color:#ff0000">注意前面的路径改成你自己的路径</span></strong> <div style="text-align:center"> <figure class="image" style="display:inline-block"><img srcset="" width="" size="" class="img-thumbnail" alt="启动redis成功" src="/resources/assist/images/blog/6cdd0fda-90f4-45b1-8a7b-5f52880d2d16.png" /> <figcaption>启动redis成功</figcaption> </figure> </div> <br /> <br /> 到这里window系统上如何下载安装和启动redis已经完成。<br /> <br /> 将redis安装成系统服务: <pre> <code>redis-server.exe --service-install redis.windows.conf --loglevel verbose </code></pre> <br /> 卸载服务: <pre> <code>redis-server --service-uninstall </code></pre>  <br /> <br /> ------------------------------------------<br /> 由网友Clay提供最新的window版本 redis 下载地址:<a rel="external nofollow" target="_blank" href="https://github.com/tporadowski/redis/releases">https://github.com/tporadowski/redis/releases</a>【感谢支持】
  • Java连接redis启动报错Error redis clients jedis HostAndPort cant resolve localhost address

    Java连接redis启动报错Error redis clients jedis HostAndPort cant resolve localhost address<h2>问题描述</h2> 错误环境:<br /> 本地window开发环境没有问题。上到Linux环境,启动出现问题。<br /> 错误信息:<br /> Error redis clients jedis HostAndPort cant resolve localhost address <pre> <code>15:44:52.039 [localhost-startStop-1] DEBUG o.m.spring.SqlSessionFactoryBean - Parsed mapper file: 'file [/data/website/test/filetest/WEB-INF/classes/com/cqax/business/dao/WebConfigMapper.xml]' 07-Aug-2017 15:44:52.529 SEVERE [localhost-startStop-1] redis.clients.jedis.HostAndPort.getLocalHostQuietly cant resolve localhost address java.net.UnknownHostException: template: template: Name or service not known at java.net.InetAddress.getLocalHost(InetAddress.java:1473) at redis.clients.jedis.HostAndPort.getLocalHostQuietly(HostAndPort.java:105) at redis.clients.jedis.HostAndPort.<clinit>(HostAndPort.java:12) at redis.clients.jedis.JedisFactory.<init>(JedisFactory.java:37) at redis.clients.jedis.JedisPool.<init>(JedisPool.java:185) at redis.clients.jedis.JedisPool.<init>(JedisPool.java:162) at redis.clients.jedis.JedisPool.<init>(JedisPool.java:92) at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.createRedisPool(JedisConnectionFactory.java:227) at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.createPool(JedisConnectionFactory.java:204) at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.afterPropertiesSet(JedisConnectionFactory.java:195) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1531) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1276) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:208) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1138) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:585) at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1264) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:522) at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:496) at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:627) at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:169) at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:318) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1264) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:208) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1138) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:585) at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1264) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:208) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1138) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:585) at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1264) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:372) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1173) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1067) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108) at org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:634) at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:145) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1193) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1095) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) at org.springframework.aop.framework.autoproxy.BeanFactoryAdvisorRetrievalHelper.findAdvisorBeans(BeanFactoryAdvisorRetrievalHelper.java:92) at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findCandidateAdvisors(AbstractAdvisorAutoProxyCreator.java:102) at org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator.findCandidateAdvisors(AnnotationAwareAspectJAutoProxyCreator.java:88) at org.springframework.aop.aspectj.autoproxy.AspectJAwareAdvisorAutoProxyCreator.shouldSkip(AspectJAwareAdvisorAutoProxyCreator.java:103) at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessBeforeInstantiation(AbstractAutoProxyCreator.java:248) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInstantiation(AbstractAutowireCapableBeanFactory.java:1037) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.resolveBeforeInstantiation(AbstractAutowireCapableBeanFactory.java:1011) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:473) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1531) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1276) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) at org.springframework.aop.framework.autoproxy.BeanFactoryAdvisorRetrievalHelper.findAdvisorBeans(BeanFactoryAdvisorRetrievalHelper.java:92) at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findCandidateAdvisors(AbstractAdvisorAutoProxyCreator.java:102) at org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator.findCandidateAdvisors(AnnotationAwareAspectJAutoProxyCreator.java:88) at org.springframework.aop.aspectj.autoproxy.AspectJAwareAdvisorAutoProxyCreator.shouldSkip(AspectJAwareAdvisorAutoProxyCreator.java:103) at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessBeforeInstantiation(AbstractAutoProxyCreator.java:248) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInstantiation(AbstractAutowireCapableBeanFactory.java:1037) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.resolveBeforeInstantiation(AbstractAutowireCapableBeanFactory.java:1011) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:473) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:443) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:325) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4745) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5207) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1419) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409) at java.util.concurrent.FutureTask.run(FutureTask.java:262) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:744) Caused by: java.net.UnknownHostException: template: Name or service not known at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method) at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:901) at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1293) at java.net.InetAddress.getLocalHost(InetAddress.java:1469) ... 149 more </code></pre> <h2>问题解决</h2> 解决办法:<br /> 1.查看Linux系统的主机名 <pre> <code>[root@template conf]# hostname template [root@template conf]# </code></pre> 2.查看/etc/hosts文件中是否有127.0.0.1对应主机名,如果没有则添加<br /> <br /> <img alt="查看hosts" class="img-thumbnail" src="/resources/assist/images/blog/c635cbc26ec7400faf5c052c25a159c2.png" />
  • spring boot 整合redis实现spring的缓存框架

    spring boot 1.5整合redis实现spring的缓存框架,spring boot,redisspring boot 整合redis实现spring的缓存框架<br /> <br /> 1.创建一个spring boot项目<br /> <img alt="项目" class="img-thumbnail" src="/resources/assist/images/blog/87917c2a16564cc08bf8e7670ec943ea.jpg" /><br /> 2.配置pom.xml文件 <pre> <code class="language-xml"><?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.leftso</groupId> <artifactId>demo-springboot-redis</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>demo-springboot-redis</name> <description>Demo project for Spring Boot</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.3.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project> </code></pre> <br /> 3.在spring boot的application配置文件中配置redis的相关信息 <pre> <code>####################Redis 配置信息 ########################## # Redis数据库分片索引(默认为0) spring.redis.database=0 # Redis服务器地址 spring.redis.host=10.1.1.134 # Redis服务器连接端口 spring.redis.port=6379 # Redis服务器连接密码(默认为空) spring.redis.password= # 连接池最大连接数(使用负值表示没有限制) spring.redis.pool.max-active=8 # 连接池最大阻塞等待时间(使用负值表示没有限制) spring.redis.pool.max-wait=-1 # 连接池中的最大空闲连接 spring.redis.pool.max-idle=8 # 连接池中的最小空闲连接 spring.redis.pool.min-idle=0 # 连接超时时间(毫秒) spring.redis.timeout=0</code></pre> <br /> 4.配置redis整合入spring的缓存框架 <pre> <code class="language-java">package com.leftso.config; import java.lang.reflect.Method; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.CacheManager; import org.springframework.cache.annotation.CachingConfigurerSupport; import org.springframework.cache.annotation.EnableCaching; import org.springframework.cache.interceptor.KeyGenerator; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.redis.cache.RedisCacheManager; import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.core.RedisTemplate; @Configuration @EnableCaching // 继承CachingConfigurerSupport并重写方法,配合该注解实现spring缓存框架的启用 public class RedisConfig extends CachingConfigurerSupport { /** 载入通过配置文件配置的连接工场 **/ @Autowired RedisConnectionFactory redisConnectionFactory; @SuppressWarnings("rawtypes") @Autowired RedisTemplate redisTemplate; @Bean RedisTemplate<String, Object> objRedisTemplate() { RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>(); redisTemplate.setConnectionFactory(redisConnectionFactory); return redisTemplate; } /* * (non-Javadoc) * * @see org.springframework.cache.annotation.CachingConfigurerSupport# * cacheManager() */ @Bean // 必须添加此注解 @Override public CacheManager cacheManager() { RedisCacheManager redisCacheManager = new RedisCacheManager(redisTemplate); // 设置缓存过期时间 // redisCacheManager.setDefaultExpiration(60);//秒 return redisCacheManager; } /** * 重写缓存的key生成策略,可根据自身业务需要进行自己的配置生成条件 * * @see org.springframework.cache.annotation.CachingConfigurerSupport# * keyGenerator() */ @Bean // 必须项 @Override public KeyGenerator keyGenerator() { return new KeyGenerator() { @Override public Object generate(Object target, Method method, Object... params) { StringBuilder sb = new StringBuilder(); sb.append(target.getClass().getName()); sb.append(method.getName()); for (Object obj : params) { sb.append(obj.toString()); } return sb.toString(); } }; } } </code></pre> <br /> 5.创建一个测试的pojo和一个测试的controller <pre> <code class="language-java">package com.leftso.pojo; import java.io.Serializable; /** * * <pre> * [Summary] * 测试用简单类型 * [Detail] * TODO * [Author] * XQLEE * [Version] * v1.0 * 2017年5月8日上午9:58:42 * </pre> */ public class Address implements Serializable{ /** * */ private static final long serialVersionUID = 1L; private String id; private String city; private String detail; public Address() { } public Address(String id, String city, String detail) { super(); this.id = id; this.city = city; this.detail = detail; } /** * @return the id */ public String getId() { return id; } /** * @param id * the id to set */ public void setId(String id) { this.id = id; } /** * @return the city */ public String getCity() { return city; } /** * @param city * the city to set */ public void setCity(String city) { this.city = city; } /** * @return the detail */ public String getDetail() { return detail; } /** * @param detail * the detail to set */ public void setDetail(String detail) { this.detail = detail; } } </code></pre>   <pre> <code class="language-java">package com.leftso.controller; import org.springframework.cache.annotation.Cacheable; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; import com.leftso.pojo.Address; @RestController public class CacheTestCtrl { @GetMapping("/getAddr") @Cacheable(value = "address-cache") // 设置缓存的名称,也可以通过key属性指定缓存的key,keyGenerator指定key生成策略器(keyGenerator一般推荐在重写CachingConfigurerSupport类里面的方法适合全局指定) public Address getAddress() { Address addr = new Address("001", "重庆市", "渝北区"); System.out.println("==========你看见这句话表示没有缓存时候打印出来的========"); return addr; } } </code></pre> <br /> 6.启动spring boot项目,访问地址localhost:8080/getAddr<br /> 第一次访问将会在控制台中看到以下输出:<br /> <img alt="1" class="img-thumbnail" src="/resources/assist/images/blog/8273e3645def48cfb209a482857ff0ab.jpg" /><br /> <br /> 后面多次刷新都不会进入到该方法中去读取信息,而是通过缓存直接读取了缓存信息。<br /> <br /> <br /> 至此spring boot整合redis 实现基本的缓存已经完成。
  • spring boot 2.0 Redis整合_spring boot 2.0 集成Redis实现缓存框架(一)

    Spring Boot 2.0 Redis整合,通过spring boot 2.0整合Redis作为spring缓存框架的实现。spring boot 2.0 Redis整合_spring boot 2.0 集成Redis实现缓存框架(一)
  • centos7 redis安装配置以及集群

    centos7 redis安装配置以及集群//可直接 yum install redis-server<br /> =====以下为源码安装方式=====<br /> yum install gcc<br /> <br /> wget http://download.redis.io/releases/redis-3.2.1.tar.gz<br /> <br /> <br /> tar -zxvf redis-3.2.1.tar.gz<br /> <br /> 到redis3.2.1文件夹下执行 <br />  make<br /> <br /> make MALLOC=libc<br /> <br /> =====以上为源码安装方式=====<br /> <br /> 后台启动服务 <br /> src/redis-server &<br /> 指定配置文件启动<br /> src/redis-server redis6379.conf<br /> src/redis-server redis6380.conf<br /> src/redis-server redis6381.conf<br /> src/redis-server redis6382.conf<br /> src/redis-server redis6383.conf<br /> src/redis-server redis6384.conf<br /> src/redis-server redis6385.conf<br /> src/redis-server redis6386.conf<br /> <br /> src/redis-server redis.conf<br /> <br /> 客户端进入<br /> src/redis-cli -h 192.168.1.141 -p 6381<br /> <br /> src/redis-cli -c -h 192.168.1.143 -p 6383<br /> 关闭 <br /> shutdown<br /> <br /> 查看进程<br /> ps -ef| grep redis<br /> <br /> redis-trib.rb create --replicas 1 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005<br /> src/redis-trib.rb create --replicas 1  192.168.1.141:6379 192.168.1.142:6381 192.168.1.143:6383 192.168.1.141:6380 192.168.1.142:6382 192.168.1.143:6384 192.168.1.144:6385 192.168.1.144:6386 192.168.1.145:6387 192.168.1.145:6388 192.168.1.146:6389 192.168.1.146:6390<br /> <br /> <br /> 192.168.1.142:6380 192.168.1.143:6380 192.168.1.144:6385 192.168.1.144:6386 <br /> <br /> 安装ruby<br /> tar xzvf ruby-2.2.3.tar.gz -C /home<br /> <br /> cd ruby-2.3.0<br /> <br /> ./configure<br /> <br /> 关联ruby到redis<br /> gem install redis<br /> <br /> src/redis-trib.rb check 192.168.1.141:6379<br /> <br />  src/redis-trib.rb fix 192.168.1.143:6383<br /> <br /> flushall ——> 清空整个 Redis 服务器的数据(删除所有数据库的所有 key )<br /> <br /> flushdb ——> 清空当前数据库中的所有 key<br /> <br /> 组成集群的时候要打开6379和他的16379端口才行<br /> <br /> <br /> 检查节点状态<br /> src/redis-trib.rb check 192.168.1.141:6380<br /> <br /> 添加master节点  新节点  到  老节点<br /> src/redis-trib.rb add-node 192.168.1.145:6387 192.168.1.143:6384<br /> <br /> src/redis-trib.rb add-node 192.168.1.146:6389 192.168.1.142:6382<br /> <br /> src/redis-trib.rb add-node 192.168.1.141:6380 192.168.1.144:6386<br /> <br /> src/redis-trib.rb add-node 192.168.1.111:6391 192.168.1.145:6387<br /> <br /> <br /> 添加slave节点<br /> src/redis-trib.rb add-node 192.168.1.145:6387 192.168.1.145:6388<br /> <br /> 进入集群配置从节点 <br /> src/redis-cli -c -h 192.168.1.144 -p 6386<br /> <br /> src/redis-cli -c -h 192.168.1.145 -p 6388<br /> <br /> src/redis-cli -c -h 192.168.1.146 -p 6390<br /> <br /> src/redis-cli -c -h 192.168.1.111 -p 6392<br /> <br /> cluster replicate 4f5744474ad515f0aa6ca3ed5f3c9a666ded40e1<br /> <br /> 从新分片数据<br /> <br /> src/redis-trib.rb reshard 192.168.1.143:6385<br /> <br /> src/redis-trib.rb reshard 192.168.1.142:6381<br /> <br /> src/redis-trib.rb reshard 192.168.1.111:6391<br /> <br /> 填写主节点id  ,之后选择从所有节点上进行平均分配<br /> <br /> 16384总数量<br /> <br /> 删除从节点  <br /> src/redis-trib.rb del-node 192.168.1.141:6380 383fff8053e27d5a194c8c2ee16dd38b126c0b10<br /> <br /> 删除主节点<br /> src/redis-trib.rb reshard 192.168.1.142:6381<br /> src/redis-trib.rb del-node 192.168.1.142:6381 77f99b006027c44b9b8b59b93d785da3ca16e59a <br /> <br /> chmod +x -R redis-3.2.1<br /> 查看端口<br /> netstat -ntlp<br /> 拷贝文件<br /> cp -r redis-3.2.1 redis-3.2.1-80<br /> <br /> <br /> # redis-trib.rb add-node 192.168.3.61:6379 192.168.3.88:6379<br /> <br /> # redis-trib.rb add-node 192.168.3.61:7379 192.168.3.88:6379<br /> <br /> <br /> cluster forget 383fff8053e27d5a194c8c2ee16dd38b126c0b10<br /> <br /> cluster saveconfig<br /> <br /> <br /> <br /> <br /> CLUSTER FAILOVER 切换主从<br /> <br /> <br /> <br />         CLUSTER INFO 打印集群的信息<br />         CLUSTER NODES 列出集群当前已知的所有节点(node),以及这些节点的相关信息。<br />         //节点<br />         CLUSTER MEET <ip> <port> 将 ip 和 port 所指定的节点添加到集群当中,让它成为集群的一份子。<br />         CLUSTER FORGET <node_id> 从集群中移除 node_id 指定的节点。<br />         CLUSTER REPLICATE <node_id> 将当前节点设置为 node_id 指定的节点的从节点。<br />         CLUSTER SAVECONFIG 将节点的配置文件保存到硬盘里面。<br />         CLUSTER ADDSLOTS <slot> [slot ...] 将一个或多个槽(slot)指派(assign)给当前节点。<br />         CLUSTER DELSLOTS <slot> [slot ...] 移除一个或多个槽对当前节点的指派。<br />         CLUSTER FLUSHSLOTS 移除指派给当前节点的所有槽,让当前节点变成一个没有指派任何槽的节点。<br />         CLUSTER SETSLOT <slot> NODE <node_id> 将槽 slot 指派给 node_id 指定的节点。<br />         CLUSTER SETSLOT <slot> MIGRATING <node_id> 将本节点的槽 slot 迁移到 node_id 指定的节点中。<br />         CLUSTER SETSLOT <slot> IMPORTING <node_id> 从 node_id 指定的节点中导入槽 slot 到本节点。<br />         CLUSTER SETSLOT <slot> STABLE 取消对槽 slot 的导入(import)或者迁移(migrate)。<br />         //键<br />         CLUSTER KEYSLOT <key> 计算键 key 应该被放置在哪个槽上。<br />         CLUSTER COUNTKEYSINSLOT <slot> 返回槽 slot 目前包含的键值对数量。<br />         CLUSTER GETKEYSINSLOT <slot> <count> 返回 count 个 slot 槽中的键。<br />         //新增<br />         CLUSTER SLAVES node-id 返回一个master节点的slaves 列表<br /> <br /> <br />  
  • centos6 redis3.29 安装(yum和源码安装)完整步骤以及常用配置

    centos6 yum安装redis3.29,centos6 源码安装redis以及常用配置<h2>一、 <span style="font-family:宋体">检查</span>yum<span style="font-family:宋体">可以安装的版本</span></h2> <h3>1.1<span style="font-family:宋体">查看当前系统可以安装的</span>redis<span style="font-family:宋体">版本</span></h3> <p><span style="font-family:宋体">命令</span>:</p> <p><strong>[root@localhost ~]# yum list|grep redis</strong></p> <p>[root@localhost ~]#</p> <p> </p> <p><span style="font-family:宋体">发现没有可以安装的</span>,<span style="font-family:宋体">如果有则忽略下面的步骤</span></p> <h3>1.2<span style="font-family:宋体">安装</span>centos<span style="font-family:宋体">提供的</span>epel-release<span style="font-family:宋体">源</span></h3> <p><span style="font-family:宋体">命令</span>:</p> <pre> <code class="language-java">[root@localhost ~]# yum install epel-release</code></pre> <p><img alt="1" class="img-thumbnail" src="/resources/assist/images/blog/a4ba199bfd204d84bbdd4bac341c08aa.png" /></p> <p><span style="font-family:宋体">安装好以后再次查看可以安装的</span>redis<span style="font-family:宋体">版本</span></p> <p><span style="font-family:宋体">命令</span>:</p> <pre> <code class="language-java">[root@localhost ~]# yum list|grep redis php-nrk-Predis.noarch                       0.8.6-1.el6                  epel   php-pecl-redis.x86_64                       2.2.8-1.el6                  epel   php-redis.x86_64                            2.2.2-5.git6f7087f.el6       epel   python-redis.noarch                         2.0.0-1.el6                  epel   redis.x86_64                                2.4.10-1.el6                 epel   uwsgi-logger-redis.x86_64                   2.0.15-1.el6                 epel   uwsgi-router-redis.x86_64                   2.0.15-1.el6                 epel   [root@localhost ~]#</code></pre> <p><span style="font-family:宋体">现在有了可以安装的版本了。但是版本还是太低是</span>2.4<span style="font-family:宋体">的版本。</span></p> <p><span style="font-family:宋体">结论</span>:CentOS6<span style="font-family:宋体">不能直接通过</span>yum<span style="font-family:宋体">安装</span>redis3.X<span style="font-family:宋体">版本。需要源码安装</span>,centos7<span style="font-family:宋体">则可以。具体安装方式可根据使用的系统版本来抉择。</span></p> <p> </p> <h2 style="margin-left:36.0pt">二、 <span style="font-family:宋体">获取</span>redis<span style="font-family:宋体">安装资源以及环境</span></h2> <h3>2.1<span style="font-family:宋体">下载</span>redis<span style="font-family:宋体">的安装文件包</span></h3> <p><span style="font-family:宋体">官网地址</span>: <a href="https://redis.io/download" rel="external nofollow" target="_blank">https://redis.io/download</a></p> <p>Redis 3.2.9<span style="font-family:宋体">下载地址</span>: <a href="http://download.redis.io/releases/redis-3.2.9.tar.gz" rel="external nofollow" target="_blank">http://download.redis.io/releases/redis-3.2.9.tar.gz</a></p> <p> </p> <p><span style="font-family:宋体">直接下载命令</span>:</p> <pre> <code class="language-java">[root@localhost ~]# wget http://download.redis.io/releases/redis-3.2.9.tar.gz</code></pre> <p><span style="font-family:宋体">下载完成后在当前目录会有</span>redis-3.2.9.tar.gz<span style="font-family:宋体">包</span></p> <p><img alt="2" class="img-thumbnail" src="/resources/assist/images/blog/72c50fea69174343b711b862b7c7a1d2.png" /></p> <p> </p> <h3>2.2<span style="font-family:宋体">检查</span>gcc<span style="font-family:宋体">环境</span></h3> <p><span style="font-family:宋体">检查系统中是否有</span>gcc<span style="font-family:宋体">编译器</span>,<span style="font-family:宋体">因为源码安装需要使用</span>gcc<span style="font-family:宋体">编译</span></p> <p><span style="font-family:宋体">命令</span>:</p> <pre> <code class="language-java">[root@localhost ~]# rpm -qa|grep gcc gcc-4.4.7-4.el6.x86_64 libgcc-4.4.7-4.el6.x86_64 [root@localhost ~]#</code></pre> <p><span style="font-family:宋体">上面的命令执行结果标识系统已经安装有</span>gcc<span style="font-family:宋体">编译器</span>,<span style="font-family:宋体">如果没有则执行下面的命令</span>,<span style="font-family:宋体">有则忽略下面步骤</span></p> <p><span style="font-family:宋体">安装</span>GCC<span style="font-family:宋体">命令</span></p> <pre> <code>[root@localhost ~]# yum install –y gcc</code></pre> <p> </p> <h2><span style="font-family:宋体">三、安装</span>redis</h2> <h3>3.1<span style="font-family:宋体">创建</span>redis<span style="font-family:宋体">安装目录</span></h3> <p><span style="font-family:宋体">命令</span>:</p> <pre> <code class="language-java">[root@localhost ~]# mkdir -p /usr/local/redis-3.2.9 [root@localhost ~]#</code></pre> <h3>3.2<span style="font-family:宋体">解压下载的</span>redis<span style="font-family:宋体">安装文件</span></h3> <p><span style="font-family:宋体">命令</span>:</p> <pre> <code class="language-java">[root@localhost ~]# tar -xzvf redis-3.2.9.tar.gz</code></pre> <h3>3.3<span style="font-family:宋体">指定安装目录安装</span>redis</h3> <p><span style="font-family:宋体">首先进入解压后的</span>redis<span style="font-family:宋体">目录</span></p> <p><span style="font-family:宋体">命令</span>:</p> <pre> <code class="language-java">[root@localhost ~]# cd redis-3.2.9 [root@localhost redis-3.2.9]#</code></pre> <p><span style="font-family:宋体">指定目录安装</span>redis</p> <p><span style="font-family:宋体">命令</span>:</p> <pre> <code class="language-java">[root@localhost redis-3.2.9]#make PREFIX=/usr/local/redis-3.2.9 install</code></pre> <p><img alt="3" class="img-thumbnail" src="/resources/assist/images/blog/dc50ab10f63249c8ad7ae52bd5a5137d.png" /></p> <h3>3.4<span style="font-family:宋体">创建一个软连接方便访问寻找</span></h3> <p><span style="font-family:宋体">命令</span>:</p> <pre> <code class="language-java">ln -s /usr/local/redis-3.2.9 /usr/local/redis</code></pre> <p> </p> <h2><span style="font-family:宋体">四、配置</span>redis</h2> <h3>4.1<span style="font-family:宋体">添加配置文件到</span>/etc<span style="font-family:宋体">目录</span></h3> <p><span style="font-family:宋体">默认的</span>redis<span style="font-family:宋体">配置文件还在刚才解压的文件目录中</span>,<span style="font-family:宋体">在</span>Linux<span style="font-family:宋体">系统使用中,通常把配置的文件放在</span>/etc<span style="font-family:宋体">目录下。算一个规范。</span></p> <p> </p> <p><span style="font-family:宋体">将源码目录下的</span>redis<span style="font-family:宋体">配置文件添加一份到</span>/etc<span style="font-family:宋体">目录下</span></p> <p><span style="font-family:宋体">命令</span>:</p> <pre> <code class="language-java">[root@localhost redis-3.2.9]# pwd /root/redis-3.2.9 [root@localhost redis-3.2.9]# ll redis.conf -rw-rw-r--. 1 root root 46695 May 17 08:39 redis.conf [root@localhost redis-3.2.9]# cp redis.conf /etc/redis.conf</code></pre> <h3>4.2.<span style="font-family:宋体">修改</span>redis<span style="font-family:宋体">默认以后台进程方式启动</span></h3> <p><span style="font-family:宋体">编辑</span>/etc/redis.conf<span style="font-family:宋体">配置</span>redis<span style="font-family:宋体">以后台方式启动</span></p> <pre> <code class="language-java">[root@localhost redis-3.2.9]# vi /etc/redis.conf</code></pre> <p><img alt="4" class="img-thumbnail" src="/resources/assist/images/blog/a9e3c8b8406a45f58c4eee2f385a35e4.png" /></p> <p><span style="font-family:宋体">在文件中找到</span>daemonize<span style="font-family:宋体">配置</span>,<span style="font-family:宋体">默认是</span>no,<span style="font-family:宋体">修改成</span>yes</p> <p><img alt="5" class="img-thumbnail" src="/resources/assist/images/blog/f498bccd0e494038a896ce370945ced0.png" /></p> <p><span style="color:#e74c3c"><strong><span style="font-family:宋体">提示</span>:</strong><em><span style="font-family:宋体">配置文件配置项后面不要有空格</span></em></span></p> <p> </p> <h3>4.3<span style="font-family:宋体">配置</span>redis<span style="font-family:宋体">允许远程访问</span></h3> <p><span style="font-family:宋体">编辑</span>/etc/redis.conf<span style="font-family:宋体">配置</span>redis<span style="font-family:宋体">允许远程访问</span></p> <pre> <code class="language-java">[root@localhost redis-3.2.9]# vi /etc/redis.conf</code></pre> <p><img alt="6" class="img-thumbnail" src="/resources/assist/images/blog/5ac5d3d3ca214782b9a76513b1cde8fc.png" /></p> <p><span style="font-family:宋体">将</span>bind 127.0.0.1<span style="font-family:宋体">注释掉即可随意访问,如果不注释则只能通过bind后面的ip进行访问。如:</span><br />  </p> <pre> <code>bind 127.0.0.1 192.168.1.3</code></pre> <p><span style="color:#e74c3c"><strong>上面的配置标识只能本地或者访问自己的ip地址192.168.1.3进行访问</strong></span><br /> <br /> 为了测试方便,注释掉即可。生产请bind自己主机的局域网IP地址<br /> <br /> <img alt="7" class="img-thumbnail" src="/resources/assist/images/blog/3608e0016dc647e08bfa2c0fe5c4ac00.png" /></p> <p><span style="font-family:宋体">但是远程访问还不能读写</span>,<span style="font-family:宋体">所以继续配置</span></p> <p><span style="font-family:宋体">找到</span>protected-mode yes(<span style="color:#8e44ad"><strong>如果使用bind的方式则不需要修改</strong></span>)</p> <p><img alt="8" class="img-thumbnail" src="/resources/assist/images/blog/0d331967cc774469a18bfbc4e41afaf8.png" /></p> <p><span style="font-family:宋体">修改为</span>protected-mode no</p> <p><img alt="9" class="img-thumbnail" src="/resources/assist/images/blog/50f6d50040ee4b29bf59e28ca86992f2.png" /></p> <p> </p> <h3>4.4<span style="font-family:宋体">配置</span>redis<span style="font-family:宋体">访问密码</span></h3> <p><span style="font-family:宋体">编辑</span>/etc/redis.conf<span style="font-family:宋体">配置</span>redis<span style="font-family:宋体">设置访问密码</span></p> <p><span style="font-family:宋体">找到配置文件中的</span><span style="background-color:white"><span style="font-family:Consolas"><span style="color:black">requirepass</span></span></span><span style="background-color:white"><span style="font-family:宋体"><span style="color:black">配置</span></span></span></p> <p><img alt="10" class="img-thumbnail" src="/resources/assist/images/blog/f1c0f305ea6f4d7b8ef3601467340781.png" /></p> <p><span style="font-family:宋体">默认情况是注释的</span>,<span style="font-family:宋体">配置的</span><span style="background-color:white"><span style="font-family:Consolas"><span style="color:black">requirepass </span></span></span><span style="background-color:white"><span style="font-family:宋体"><span style="color:black">后面跟的</span></span></span><span style="background-color:white"><span style="font-family:Consolas"><span style="color:black">foobared</span></span></span><span style="background-color:white"><span style="font-family:宋体"><span style="color:black">就是密码</span></span></span></p> <p><span style="background-color:white"><span style="font-family:宋体"><span style="color:black">例如现在启用密码</span></span></span><span style="background-color:white"><span style="font-family:Consolas"><span style="color:black">,</span></span></span><span style="background-color:white"><span style="font-family:宋体"><span style="color:black">并且将密码设置为</span></span></span><span style="background-color:white"><span style="font-family:Consolas"><span style="color:black">123456</span></span></span><span style="background-color:white"><span style="font-family:宋体"><span style="color:black">,则配置为</span></span></span><span style="background-color:white"><span style="font-family:Consolas"><span style="color:black">:</span></span></span></p> <p><img alt="11" class="img-thumbnail" src="/resources/assist/images/blog/c39435d76b21443f8043f387536d662e.png" /></p> <p><span style="font-family:宋体">去掉</span>#<span style="font-family:宋体">并将后面的密码修改为</span>123456</p> <p><span style="color:#e74c3c"><strong><span style="font-family:宋体">提示</span></strong><em>:</em><em><span style="font-family:宋体">配置前后不要留空格</span></em></span><br />  </p> <span style="font-family:宋体">配置redis最大使用内存以及超出最大内存后的处理策略</span><br />   <p><strong>#maxmemory </strong><strong><bytes></strong></p> <p>redis-cache所能使用的最大内存(bytes),默认为0,表示"无限制",最终由OS物理内存大小决定(如果物理内存不足,有可能会使用swap)。此值尽量不要超过机器的物理内存尺寸,从性能和实施的角度考虑,可以为物理内存3/4。此配置需要和"maxmemory-policy"配合使用,当redis中内存数据达到maxmemory时,触发"清除策略"。在"内存不足"时,任何write操作(比如set,lpush等)都会触发"清除策略"的执行。在实际环境中,建议redis的所有物理机器的硬件配置保持一致(内存一致),同时确保master/slave中"maxmemory""policy"配置一致。</p> <p>当内存满了的时候,如果还接收到set 命令,redis 将先尝试剔除设置过expire 信息的key,而不管该key 的过期时间还没有到达。在删除时,</p> <p>将按照过期时间进行删除,最早将要被过期的key 将最先被删除。如果带有expire 信息的key 都删光了,内存还不够用,那么将返回错误。这样,redis 将不再接收写请求,只接收get 请求。maxmemory 的设置比较适合于把redis 当作于类似memcached的缓存来使用。</p> <p><strong># maxmemory-policy noeviction</strong></p> <p>内存不足"时,数据清除策略,默认为"noeviction。</p> <p><em>volatile-lru</em>  ->对"过期集合"中的数据采取LRU(近期最少使用)算法.如果对key使用"expire"指令指定了过期时间,那么此key将会被添加到"过期集合"中。将已经过期/LRU的数据优先移除.如果"过期集合"中全部移除仍不能满足内存需求,将OOM.<br /> <em>allkeys-lru</em> ->对所有的数据,采用LRU算法<br /> <em>volatile-random</em> ->对"过期集合"中的数据采取"随即选取"算法,并移除选中的K-V,直到"内存足够"为止. 如果如果"过期集合"中全部移除全部移除仍不能满足,将OOM<br /> <em>allkeys-random</em> ->对所有的数据,采取"随机选取"算法,并移除选中的K-V,直到"内存足够"为止<br /> <em>volatile-ttl</em> ->对"过期集合"中的数据采取TTL算法(最小存活时间),移除即将过期的数据.<br /> <em>noeviction</em> ->不做任何干扰操作,直接返回OOM异常<br /> 另外,如果数据的过期不会对"应用系统"带来异常,且系统中write操作比较密集,建议采取"allkeys-lru"<br /> <br /> <strong>举个栗子:</strong><br /> 配置最大使用内存2GB,超出后对不常使用的缓存清理,快过期缓存清理的配置为:</p> <pre> <code>#设置默认内存大小3GB maxmemory 3GB #设置清楚策略allkeys-lru maxmemory-policy allkeys-lru</code></pre> <h3>4.5<span style="font-family:宋体">创建</span>redis<span style="font-family:宋体">用户</span></h3> <p><span style="font-family:宋体">命令</span>:</p> <pre> <code class="language-java"># useradd -r -s /sbin/nologin -M redis</code></pre> <p>4.6<span style="font-family:宋体">创建</span>redis<span style="font-family:宋体">启动弄脚本便于使用</span>service<span style="font-family:宋体">管理</span>redis</p> <p><strong><span style="font-family:宋体">命令</span>:</strong></p> <pre> <code class="language-java">#vi  /etc/init.d/redis</code></pre> <p><span style="font-family:宋体">脚本内容</span>:<br />  </p> <pre> <code class="language-bash">#!/bin/bash #chkconfig: 2345 55 25 #description: Starts,stops and restart the redis-server #Ver:1.1  #Write by ND chengh(200808) #usage: ./script_name -p [port] {start|stop|status|restart} # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check networking is up. [ "$NETWORKING" = "no" ] && exit 0 RETVAL=0 REDIS_PORT=6379 PID= if [ "$1" = "-p" ]; then     REDIS_PORT=$2     shift 2 fi REDIS_DIR="/usr/local/redis" REDIS_CONF_DIR="/etc" REDIS="${REDIS_DIR}/bin/redis-server" PROG=$(basename $REDIS) CONF="${REDIS_CONF_DIR}/redis-${REDIS_PORT}.conf" if [ ! -f $CONF ]; then    if [ -f "${REDIS_CONF_DIR}/redis.conf" ];then       CONF="${REDIS_CONF_DIR}/redis.conf"    else       echo -n $"$CONF not exist.";warning;echo       exit 1    fi fi PID_FILE=`grep "pidfile" ${CONF}|cut -d ' ' -f2` PID_FILE=${PID_FILE:=/var/run/redis.pid} LOCKFILE="/var/lock/subsys/redis-${REDIS_PORT}" if [ ! -x $REDIS ]; then     echo -n $"$REDIS not exist.";warning;echo     exit 0 fi start() {     echo -n $"Starting $PROG: "     $REDIS $CONF     RETVAL=$?     if [ $RETVAL -eq 0 ]; then         success;echo;touch $LOCKFILE     else         failure;echo     fi     return $RETVAL } stop() {     echo -n $"Stopping $PROG: "     if [ -f $PID_FILE ] ;then        read PID <  "$PID_FILE"     else        failure;echo;        echo -n $"$PID_FILE not found.";failure;echo        return 1;     fi     if checkpid $PID; then      kill -TERM $PID >/dev/null 2>&1         RETVAL=$?         if [ $RETVAL -eq 0 ] ;then                 success;echo                 echo -n "Waiting for Redis to shutdown .."          while checkpid $PID;do                  echo -n "."                  sleep 1;                 done                 success;echo;rm -f $LOCKFILE         else                 failure;echo         fi     else         echo -n $"Redis is dead and $PID_FILE exists.";failure;echo         RETVAL=7     fi        return $RETVAL } restart() {     stop     start } rhstatus() {     status -p ${PID_FILE} $PROG } hid_status() {     rhstatus >/dev/null 2>&1 } case "$1" in     start)         hid_status && exit 0         start         ;;     stop)         rhstatus || exit 0         stop         ;;     restart)         restart         ;;     status)         rhstatus         RETVAL=$?         ;;     *)         echo $"Usage: $0 -p [port] {start|stop|status|restart}"         RETVAL=1 esac exit $RETVAL </code></pre> <p><span style="background-color:#fafafc"><span style="font-family:宋体"><span style="color:#333333">上面脚本中可根据具体</span></span></span><span style="background-color:#fafafc"><span style="font-family:"Tahoma",sans-serif"><span style="color:#333333">redis</span></span></span><span style="background-color:#fafafc"><span style="font-family:宋体"><span style="color:#333333">安装位置配置</span></span></span><span style="background-color:#fafafc"><span style="font-family:"Tahoma",sans-serif"><span style="color:#333333">redis-server</span></span></span><span style="background-color:#fafafc"><span style="font-family:宋体"><span style="color:#333333">的路径和</span></span></span><span style="background-color:#fafafc"><span style="font-family:"Tahoma",sans-serif"><span style="color:#333333">conf</span></span></span><span style="background-color:#fafafc"><span style="font-family:宋体"><span style="color:#333333">的路径</span></span></span></p> <p><span style="background-color:#fafafc"><span style="font-family:"Tahoma",sans-serif"><span style="color:#333333">redis</span></span></span><span style="background-color:#fafafc"><span style="font-family:宋体"><span style="color:#333333">默认安装在</span></span></span></p> <p><span style="background-color:#fafafc"><span style="font-family:"Tahoma",sans-serif"><span style="color:#333333">/usr/local/redis</span></span></span><span style="background-color:#fafafc"><span style="font-family:宋体"><span style="color:#333333">目录下</span></span></span></p> <p><span style="background-color:#fafafc"><span style="font-family:"Tahoma",sans-serif"><span style="color:#333333">Redis</span></span></span><span style="background-color:#fafafc"><span style="font-family:宋体"><span style="color:#333333">配置文件存放在</span></span></span></p> <p><span style="background-color:#fafafc"><span style="font-family:"Tahoma",sans-serif"><span style="color:#333333">/etc/redis.conf</span></span></span></p> <p> </p> <p><span style="background-color:#fafafc"><span style="font-family:宋体"><span style="color:#333333">修改脚本权限</span></span></span></p> <pre> <code class="language-java">#chmod 755 /etc/init.d/redis</code></pre> <p> </p> <p><span style="font-family:宋体">添加进</span>service<span style="font-family:宋体">管理</span></p> <pre> <code class="language-java">#chkconfig --add redis</code></pre> <p> </p> <p><span style="font-family:宋体">设置开机启动</span></p> <pre> <code class="language-java"># chkconfig redis on</code></pre> <p>4.7<span style="font-family:宋体">启动</span>redis</p> <pre> <code class="language-java">[root@localhost redis-3.2.9]# service redis start Starting redis-server:                                     [  OK  ]</code></pre> <p><img alt="12" class="img-thumbnail" src="/resources/assist/images/blog/3c9b6e9d57104e82a82649a844c5b1d8.png" /></p> <p> </p> <h2><span style="font-family:宋体">五、连接到</span>redis<span style="font-family:宋体">测试</span></h2> <p><span style="font-family:宋体">连接命令</span>:</p> <pre> <code class="language-java">#/usr/local/redis/bin/redis-cli -h 127.0.0.1 -p 6379</code></pre> <p> </p> <p><span style="font-family:宋体">设置一个值</span>:</p> <pre> <code>127.0.0.1:6379> set testKey testValue</code></pre> <p><img alt="13" class="img-thumbnail" src="/resources/assist/images/blog/963b924d72964889b49019bfa0695e2d.png" /></p> <p><span style="font-family:宋体">获取上面的设置值</span></p> <p><span style="font-family:宋体">命令</span>:</p> <pre> <code>127.0.0.1:6379> get testKey</code></pre> <p><img alt="14" class="img-thumbnail" src="/resources/assist/images/blog/82deb7d506ea4673970ad757e8f5492c.png" /></p> <p>删除上面的值<br /> 命令</p> <pre> <code>del testKey</code></pre> <p><br />  </p>
  • centos 7 安装和配置redis

    linux系统之centos 7 安装和配置redis,redis是一个高性能的key-value数据库,通常用于分布式缓存linux系统之centos 7 安装和配置redis,redis是一个高性能的key-value数据库,通常用于分布式缓存<br /> <br /> 1.通过yum方式安装redis<br /> 切换用户至root<br /> 执行命令: <pre> <code class="language-bash">yum install redis -y</code></pre> 2.查看安装的情况 <pre> <code> whereis redis redis: /etc/redis.conf</code></pre> <br /> 这里可以看到默认存放配置文件的地方<br /> <br /> 3.简单启动redis<br /> 命令: <pre> <code class="language-bash">redis-server</code></pre> <br /> 启动界面如下表示成功:<br /> <img alt="启动命令" class="img-thumbnail" src="/resources/assist/images/blog/16893e83794c4636a416a2e604d61c30.png" /><br /> <br /> 这里只是采用默认的方式启动最基本的服务,通常使用中并不这么玩。<br /> <br /> 4.一些常用的配置项<br /> vi打开/etc/redis.conf文件<br /> 4.1>取消 bind 127.0.0.1<br /> <span style="color:#e74c3c">通过vi找到bind地址,注释掉</span><br /> 4.2>正如上面所见,Redis默认不是以守护进程的方式运行,修改daemonize值为yes使其后台运行<br /> <span style="color:#e74c3c">通过vi查找到daemonize,将后面的值改为yes</span><br /> 4.3>取消保护模式,默认情况下redis启动了保护模式,只能在本地访问不能远程访问。如果不取消将会报错:<br /> DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified, no authentication password is requested to clients. In this mode connections are only accepted from the loopback interface. If you want to connect from external computers to Redis you may adopt one of the following solutions: 1) Just disable protected mode sending the command 'CONFIG SET protected-mode no' from the loopback interface by connecting to Redis from the same host the server is running, however MAKE SURE Redis is not publicly accessible from internet if you do so. Use CONFIG REWRITE to make this change permanent. 2) Alternatively you can just disable the protected mode by editing the Redis configuration file, and setting the protected mode option to 'no', and then restarting the server. 3) If you started the server manually just for testing, restart it with the '--protected-mode no' option. 4) Setup a bind address or an authentication password. NOTE: You only need to do one of the above things in order for the server to start accepting connections from the outside.<br /> <br /> <span style="color:#e74c3c">用vi找到protected-mode修改值为no</span><br /> <br /> 4.4>添加密码认证,默认情况redis是没有密码的但是实际使用中一般都会配置<br /> <span style="color:#e74c3c">通过vi查找到requirepass,可以发现默认有一行requirepass foobared被注释掉了。上面还有警告说明。将注释取消,后面跟的字符foobared便是密码改成自己需要的即可</span><br /> <br /> 5.通过指定配置文件的方式启动redis使其配置信息生效<br /> 虽然在第四步中我们配置了很多的信息,但是如果启动的时候不指定配置文件将不会生效<br /> 指定配置文件启动命令如下: <pre> <code>redis-server /etc/redis.conf</code></pre> <br /> <img alt="redis后台进程启动" class="img-thumbnail" src="/resources/assist/images/blog/945661ffad5f4496a79583b89e717287.png" /><br /> 从上不难看出已经后台运行了<br /> <br /> 至此redis的安装配置实用说明结束,其他复杂配置后续补充。
  • Redis 禁用FLUSHALL FLUSHDB KEYS 命令

    FLUSHALL FLUSHDB 命令会清空数据,而且从不失败,对于线上集群非常危险。KEYS * 命令,当数据规模较大时使用,会严重影响Redis性能,也非常危险。如果从根本上规避这些风险呢?Redis提供了非常简单且有效的方法,直接在配置文件中设置禁用这些命令。(error) ERR unknown command 'keys'/(error) ERR unknown command 'FLUSHDB'错误解决<h2>(error) ERR unknown command 'keys'问题解决<br /> (error) ERR unknown command 'FLUSHDB' 问题解决<br /> <br /> 背景</h2> FLUSHALL FLUSHDB 命令会清空数据,而且从不失败,对于线上集群非常危险。KEYS * 命令,当数据规模较大时使用,会严重影响Redis性能,也非常危险。如果从根本上规避这些风险呢?Redis提供了非常简单且有效的方法,直接在配置文件中设置禁用这些命令。<br /> <br /> 在redis的配置文件中设置 <pre> <code class="language-html">rename-command FLUSHALL "" rename-command FLUSHDB "" rename-command KEYS "</code></pre> <p>需要注意的一点是,rename-command命名无法直接对线上集群生效。如果需要使用rename-command,必须重启集群。</p> <p>所以建议一开始,就将该配置配置好。</p>
  • spring data redis设置/更新缓存的过期时间

    spring data redis设置缓存的过期时间,spring data redis更新缓存的过期时间spring data redis设置缓存的过期时间,spring data redis更新缓存的过期时间<br /> <br /> 通常使用spring data redis框架的时候对缓存的操作使用org.springframework.data.redis.core.<strong>RedisTemplate</strong> <h5><strong>RedisTemplate</strong>中有以下方法</h5> <span style="color:#ff0000">public Boolean expire(K key, final long timeout, final TimeUnit unit)</span><br /> 可以知道我们可以通过缓存的key值,设置缓存的过期时间<br /> <br /> 例如缓存设置过期时间为60秒<br /> <strong>redisTemplate.expire("testKey",60l,java.util.concurrent.TimeUnit.SECONDS);</strong><br />