最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

[已解决]运行redis-server出错:Creating Server TCP listening socket 6379 unable to bind socket

redis crifan 4902浏览 0评论

折腾:

[已解决]为Flask的后台任务而在CentOS中安装Redis

期间,去运行redis,结果出错:

(SIPEvents) ➜  redis-3.2.3 src/redis-server 
7998:C 03 Sep 21:15:13.528 # Warning: no config file specified, using the default config. In order to specify a config file use src/redis-server /path/to/redis.conf
7998:M 03 Sep 21:15:13.531 # Creating Server TCP listening socket *:6379: unable to bind socket

redis-server Creating Server TCP listening socket *:6379: unable to bind socket

Installing Redis on Debian as a Service | Thomas Hunter II

Redis Creating Server TCP listening socket *:6379: unable to bind socket – kinginblue的专栏 – 博客频道 – CSDN.NET

Redis Creating Server TCP listening socket *:6379: unable to bind socket – 程序园

redis配置时,bind IP问题? – 知乎

redis基本的安装使用 | 小喵爱你

(SIPEvents) ➜  redis-3.2.3 pwd
/root/tools/redis-3.2.3
(SIPEvents) ➜  redis-3.2.3 ll
total 196K
-rw-rw-r–  1 root root  74K Aug  2 17:00 00-RELEASENOTES
-rw-rw-r–  1 root root   53 Aug  2 17:00 BUGS
-rw-rw-r–  1 root root 1.8K Aug  2 17:00 CONTRIBUTING
-rw-rw-r–  1 root root 1.5K Aug  2 17:00 COPYING
drwxrwxr-x  7 root root 4.0K Sep  3 21:12 deps
-rw-rw-r–  1 root root   11 Aug  2 17:00 INSTALL
-rw-rw-r–  1 root root  151 Aug  2 17:00 Makefile
-rw-rw-r–  1 root root 4.2K Aug  2 17:00 MANIFESTO
-rw-rw-r–  1 root root 6.7K Aug  2 17:00 README.md
-rw-rw-r–  1 root root  46K Aug  2 17:00 redis.conf
-rwxrwxr-x  1 root root  271 Aug  2 17:00 runtest
-rwxrwxr-x  1 root root  280 Aug  2 17:00 runtest-cluster
-rwxrwxr-x  1 root root  281 Aug  2 17:00 runtest-sentinel
-rw-rw-r–  1 root root 7.0K Aug  2 17:00 sentinel.conf
drwxrwxr-x  2 root root 4.0K Sep  3 21:13 src
drwxrwxr-x 10 root root 4.0K Aug  2 17:00 tests
drwxrwxr-x  7 root root 4.0K Aug  2 17:00 utils
(SIPEvents) ➜  redis-3.2.3 mkdir /etc/redis
(SIPEvents) ➜  redis-3.2.3 cp redis.conf /etc/redis 
(SIPEvents) ➜  redis-3.2.3 ll /etc/redis/redis.conf 
-rw-r–r– 1 root root 46K Sep  3 21:59 /etc/redis/redis.conf

然后再去运行试试:

结果就可以了:

(SIPEvents) ➜  redis-3.2.3 src/redis-server /etc/redis/redis.conf 
                _._                                                  
           _.-“__ ”-._                                             
      _.-“    `.  `_.  ”-._           Redis 3.2.3 (00000000/0) 64 bit
  .-“ .-“`.  “`\/    _.,_ ”-._                                   
 (    ‘      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-…-` __…-.“-._|’` _.-‘|     Port: 6379
 |    `-._   `._    /     _.-‘    |     PID: 10353
  `-._    `-._  `-./  _.-‘    _.-‘                                   
 |`-._`-._    `-.__.-‘    _.-‘_.-‘|                                  
 |    `-._`-._        _.-‘_.-‘    |           http://redis.io        
  `-._    `-._`-.__.-‘_.-‘    _.-‘                                   
 |`-._`-._    `-.__.-‘    _.-‘_.-‘|                                  
 |    `-._`-._        _.-‘_.-‘    |                                  
  `-._    `-._`-.__.-‘_.-‘    _.-‘                                   
      `-._    `-.__.-‘    _.-‘                                       
          `-._        _.-‘                                           
              `-.__.-‘                                               
10353:M 03 Sep 22:01:12.263 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
10353:M 03 Sep 22:01:12.263 # Server started, Redis version 3.2.3
10353:M 03 Sep 22:01:12.263 # 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.
10353:M 03 Sep 22:01:12.263 # 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.
10353:M 03 Sep 22:01:12.263 * The server is now ready to accept connections on port 6379

如图:

-》

官网的教程:

Redis Quick Start – Redis

http://redis.io/topics/quickstart

不靠谱啊:

因为:说了,如果这是为了开发,则可以不用指定配置的。。。

详见:

[已解决]安装完毕redis后出错:Warning: no config file specified using the default config

然后去control+C去暂停:

^C10353:signal-handler (1472911501) Received SIGINT scheduling shutdown…
10353:M 03 Sep 22:05:01.842 # User requested shutdown…
10353:M 03 Sep 22:05:01.842 * Saving the final RDB snapshot before exiting.
10353:M 03 Sep 22:05:01.848 * DB saved on disk
10353:M 03 Sep 22:05:01.848 * Removing the pid file.
10353:M 03 Sep 22:05:01.848 # Redis is now ready to exit, bye bye…

然后再去测试是否正常工作:

(SIPEvents) ➜  SIPEvents redis-server /etc/redis/redis.conf &
[1] 10484
(SIPEvents) ➜  SIPEvents                 _._                                                  
           _.-“__ ”-._                                             
      _.-“    `.  `_.  ”-._           Redis 3.2.3 (00000000/0) 64 bit
  .-“ .-“`.  “`\/    _.,_ ”-._                                   
 (    ‘      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-…-` __…-.“-._|’` _.-‘|     Port: 6379
 |    `-._   `._    /     _.-‘    |     PID: 10484
  `-._    `-._  `-./  _.-‘    _.-‘                                   
 |`-._`-._    `-.__.-‘    _.-‘_.-‘|                                  
 |    `-._`-._        _.-‘_.-‘    |           http://redis.io        
  `-._    `-._`-.__.-‘_.-‘    _.-‘                                   
 |`-._`-._    `-.__.-‘    _.-‘_.-‘|                                  
 |    `-._`-._        _.-‘_.-‘    |                                  
  `-._    `-._`-.__.-‘_.-‘    _.-‘                                   
      `-._    `-.__.-‘    _.-‘                                       
          `-._        _.-‘                                           
              `-.__.-‘                                               
10484:M 03 Sep 22:10:51.132 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
10484:M 03 Sep 22:10:51.133 # Server started, Redis version 3.2.3
10484:M 03 Sep 22:10:51.133 # 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.
10484:M 03 Sep 22:10:51.133 # 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.
10484:M 03 Sep 22:10:51.133 * DB loaded from disk: 0.000 seconds
10484:M 03 Sep 22:10:51.133 * The server is now ready to accept connections on port 6379
(SIPEvents) ➜  SIPEvents redis-cli
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> set myname crifan
OK
127.0.0.1:6379> get myname
“crifan”
127.0.0.1:6379> help
redis-cli 3.2.3
To get help about Redis commands type:
      “help @<group>” to get a list of commands in <group>
      “help <command>” for help on <command>
      “help <tab>” to get a list of possible help topics
      “quit” to exit
To set redis-cli perferences:
      “:set hints” enable online hints
      “:set nohints” disable online hints
Set your preferences in ~/.redisclirc
127.0.0.1:6379> help set
  SET key value [EX seconds] [PX milliseconds] [NX|XX]
  summary: Set the string value of a key
  since: 1.0.0
  group: string
127.0.0.1:6379> help get
  GET key
  summary: Get the value of a key
  since: 1.0.0
  group: string
127.0.0.1:6379>

说明可以工作了。

[总结]

此处redis-server之所以没能正常工作,是因为没有提供配置文件。

redis提供了一个默认的配置文件,默认是放在源码内了,redis.conf

解决办法是:

使用默认的配置文件,且放到合适的地方:

然后使用配置文件去运行:

(SIPEvents) ➜  redis-3.2.3 pwd
/root/tools/redis-3.2.3
(SIPEvents) ➜  redis-3.2.3 ll
total 196K
-rw-rw-r–  1 root root  74K Aug  2 17:00 00-RELEASENOTES
-rw-rw-r–  1 root root   53 Aug  2 17:00 BUGS
-rw-rw-r–  1 root root 1.8K Aug  2 17:00 CONTRIBUTING
-rw-rw-r–  1 root root 1.5K Aug  2 17:00 COPYING
drwxrwxr-x  7 root root 4.0K Sep  3 21:12 deps
-rw-rw-r–  1 root root   11 Aug  2 17:00 INSTALL
-rw-rw-r–  1 root root  151 Aug  2 17:00 Makefile
-rw-rw-r–  1 root root 4.2K Aug  2 17:00 MANIFESTO
-rw-rw-r–  1 root root 6.7K Aug  2 17:00 README.md
-rw-rw-r–  1 root root  46K Aug  2 17:00 redis.conf
-rwxrwxr-x  1 root root  271 Aug  2 17:00 runtest
-rwxrwxr-x  1 root root  280 Aug  2 17:00 runtest-cluster
-rwxrwxr-x  1 root root  281 Aug  2 17:00 runtest-sentinel
-rw-rw-r–  1 root root 7.0K Aug  2 17:00 sentinel.conf
drwxrwxr-x  2 root root 4.0K Sep  3 21:13 src
drwxrwxr-x 10 root root 4.0K Aug  2 17:00 tests
drwxrwxr-x  7 root root 4.0K Aug  2 17:00 utils
(SIPEvents) ➜  redis-3.2.3 mkdir /etc/redis
(SIPEvents) ➜  redis-3.2.3 cp redis.conf /etc/redis
(SIPEvents) ➜  redis-3.2.3 ll /etc/redis/redis.conf
-rw-r–r– 1 root root 46K Sep  3 21:59 /etc/redis/redis.conf
redis-server /etc/redis/redis.conf

然后,想要测试是否正常工作,可以去:

redis-server /etc/redis/redis.conf &
redis-cli
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> set myname crifan
OK
127.0.0.1:6379> get myname
“crifan”

即可说明正常工作,可以正常保存和读取数据了。

转载请注明:在路上 » [已解决]运行redis-server出错:Creating Server TCP listening socket 6379 unable to bind socket

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
84 queries in 0.173 seconds, using 22.23MB memory