Linux安装redis,启动配置不生效(指定启动加载配置文件)

Redis配置加载详解
本文介绍了一个关于Redis配置加载的问题案例,详细解释了如何确保自定义的Redis配置文件被正确加载及生效的过程。通过实例演示了从配置文件的位置到具体启动命令的使用方法。

一、今天有个同学问我,为什么明明安装了redis,修改了配置,启动的时候,配置还是不生效。如下图是安装后的redis文件图。

root@iZbp17cj14ulhfrlj02rkaZ:~/redis-4.0.9# ls
00-RELEASENOTES  COPYING    Makefile   redis.conf       runtest-sentinel  tests
BUGS             INSTALL    README.md  runtest          sentinel.conf     utils
CONTRIBUTING     MANIFESTO  deps       runtest-cluster  src
root@iZbp17cj14ulhfrlj02rkaZ:~/redis-4.0.9#

二、想加载上图中的redis.conf,进入到src中寻找到启动文件redis-server

root@iZbp17cj14ulhfrlj02rkaZ:~/redis-4.0.9/src# ls
Makefile      endianconv.c      pqsort.h           sentinel.o
adlist.c      endianconv.h      pqsort.o           server.c
adlist.h      endianconv.o      pubsub.c           server.h
adlist.o      evict.c           pubsub.o           server.o
ae.c          evict.o           quicklist.c        setproctitle.c
ae.h          expire.c          quicklist.h        setproctitle.o
ae.o          expire.o          quicklist.o        sha1.c
ae_epoll.c    fmacros.h         rand.c             sha1.h
ae_evport.c   geo.c             rand.h             sha1.o
ae_kqueue.c   geo.h             rand.o             siphash.c
ae_select.c   geo.o             rax.c              siphash.o
anet.c        geohash.c         rax.h              slowlog.c
anet.h        geohash.h         rax.o              slowlog.h
anet.o        geohash.o         rax_malloc.h       slowlog.o
aof.c         geohash_helper.c  rdb.c              solarisfixes.h
aof.o         geohash_helper.h  rdb.h              sort.c
asciilogo.h   geohash_helper.o  rdb.o              sort.o
atomicvar.h   help.h            redis-benchmark    sparkline.c
bio.c         hyperloglog.c     redis-benchmark.c  sparkline.h
bio.h         hyperloglog.o     redis-benchmark.o  sparkline.o
bio.o         intset.c          redis-check-aof    syncio.c
bitops.c      intset.h          redis-check-aof.c  syncio.o
bitops.o      intset.o          redis-check-aof.o  t_hash.c
blocked.c     latency.c         redis-check-rdb    t_hash.o
blocked.o     latency.h         redis-check-rdb.c  t_list.c
childinfo.c   latency.o         redis-check-rdb.o  t_list.o
childinfo.o   lazyfree.c        redis-cli          t_set.c
cluster.c     lazyfree.o        redis-cli.c        t_set.o
cluster.h     lzf.h             redis-cli.o        t_string.c
cluster.o     lzfP.h            redis-sentinel     t_string.o
config.c      lzf_c.c           redis-server       t_zset.c
config.h      lzf_c.o           redis-trib.rb      t_zset.o
config.o      lzf_d.c           redisassert.h      testhelp.h
crc16.c       lzf_d.o           redismodule.h      util.c
crc16.o       memtest.c         release.c          util.h
crc64.c       memtest.o         release.h          util.o
crc64.h       mkreleasehdr.sh   release.o          valgrind.sup
crc64.o       module.c          replication.c      version.h
db.c          module.o          replication.o      ziplist.c
db.o          modules           rio.c              ziplist.h
debug.c       multi.c           rio.h              ziplist.o
debug.o       multi.o           rio.o              zipmap.c
debugmacro.h  networking.c      scripting.c        zipmap.h
defrag.c      networking.o      scripting.o        zipmap.o
defrag.o      notify.c          sds.c              zmalloc.c
dict.c        notify.o          sds.h              zmalloc.h
dict.h        object.c          sds.o              zmalloc.o
dict.o        object.o          sdsalloc.h
dump.rdb      pqsort.c          sentinel.c

三、启动时指定加载的配置文件

root@iZbp17cj14ulhfrlj02rkaZ:~/redis-4.0.9/src# ./redis-server /root/redis-4.0.9/redis.conf
4384:C 14 Apr 23:35:14.742 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
4384:C 14 Apr 23:35:14.742 # Redis version=4.0.9, bits=64, commit=00000000, modified=0, pid=4384, just started
4384:C 14 Apr 23:35:14.742 # Configuration loaded
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 4.0.9 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 4384
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

4384:M 14 Apr 23:35:14.744 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
4384:M 14 Apr 23:35:14.744 # Server initialized
4384:M 14 Apr 23:35:14.744 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
4384:M 14 Apr 23:35:14.744 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
4384:M 14 Apr 23:35:14.744 * DB loaded from disk: 0.000 seconds
4384:M 14 Apr 23:35:14.744 * Ready to accept connections

四、如下图所示,加载的配置文件,你修改的信息均会生效。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值