树莓派一个无法分配被请求地址问题(Cannot assign requested address)的解决过程
问题描述
在用 ecl
加载 swank
服务端时返回错误:
pi@rpi ~ $ ecl -load ~/.vim/bundle/slimv/slime/start-swank.lisp
;;; Loading "/home/pi/.vim/bundle/slimv/slime/start-swank.lisp"
;;; Loading "/opt/github/slimv/slime/swank-loader.lisp"
;;; Warning: No architecture feature found in (POWERPC PPC X86 X86-64 X86_64
AMD64 I686 I586 I486 PC386
IAPX386 SPARC64 SPARC HPPA64
HPPA ARM PENTIUM3 PENTIUM4
JAVA-1.4 JAVA-1.5 JAVA-1.6
JAVA-1.7).
;;; Loading #P"/usr/local/lib/ecl-16.1.2/cmp.fas"
;;; Loading "/home/pi/.slime/fasl/2014-10-10/ecl-16.1.2-linux-unknown/backend.fas"
;;; Loading "/home/pi/.slime/fasl/2014-10-10/ecl-16.1.2-linux-unknown/ecl.fas"
;;; Loading #P"/usr/local/lib/ecl-16.1.2/sockets.fas"
;;; Loading #P"/usr/local/lib/ecl-16.1.2/profile.fas"
;;; Loading #P"/usr/local/lib/ecl-16.1.2/serve-event.fas"
;;; Loading "/home/pi/.slime/fasl/2014-10-10/ecl-16.1.2-linux-unknown/gray.fas"
;;; Loading "/home/pi/.slime/fasl/2014-10-10/ecl-16.1.2-linux-unknown/match.fas"
;;; Loading "/home/pi/.slime/fasl/2014-10-10/ecl-16.1.2-linux-unknown/rpc.fas"
;;; Loading "/home/pi/.slime/fasl/2014-10-10/ecl-16.1.2-linux-unknown/swank.fas"
An error occurred during initialization:
Socket error in "bind": 99 (Cannot assign requested address).
pi@rpi ~ $
第一次尝试
先以 Cannot assign requested address
作为关键字在网上查了半天, 绝大多数的都说是连接太多端口不够, 要及时释放, 解决办法如下:
pi@rpi /usr/share/nginx $ sudo sysctl -w net.ipv4.tcp_timestamps=1
pi@rpi /usr/share/nginx $ sudo sysctl -w net.ipv4.tcp_tw_recycle=1
pi@rpi /usr/share/nginx $ cat /proc/sys/net/ipv4/tcp_timestamps
1
pi@rpi /usr/share/nginx $ cat /proc/sys/net/ipv4/tcp_tw_recycle
1
pi@rpi /usr/share/nginx $
第二次尝试
有的人说前面的说法不正确, 是端口范围要扩大(针对 ubuntu 12.04版本 ), 解决办法是:
pi@rpi /usr/share/nginx $ echo 32768 61000 > /proc/sys/net/ipv4/ip_local_port_range
pi@rpi /usr/share/nginx $ cat /proc/sys/net/ipv4/ip_local_port_range
32768 61000
可是貌似在我的树莓派上都没起作用.
开始第一次猜测
我的初步判断是因为启动了类似 nginx
这样的服务程序, 所以在地址分配方面发生了莫名其妙的冲突, 一个解决办法就是把这些服务全给停掉
pi@rpi ~ $ sudo service docker status
Docker is running.
pi@rpi ~ $ sudo service docker stop
Stopping Docker: docker.
pi@rpi ~ $ sudo service docker status
Docker is not running ... failed!
pi@rpi ~ $ sudo service redis-server status
redis-server is running
pi@rpi ~ $ sudo service redis-server stop
Stopping redis-server: redis-server.
pi@rpi ~ $ sudo service redis-server status
redis-server is not running
pi@rpi ~ $
服务全部停掉, 可是问题依旧.
开始第二次猜测
我继续猜测也有可能是网络配置引起的, 看看这个网络配置, 总感觉有些不太对劲, 可是具体哪里有问题, 也说不出来:
pi@rpi ~ $ ifconfig
docker0 Link encap:Ethernet HWaddr 02:42:ec:c9:aa:72
inet addr:172.17.0.1 Bcast:0.0.0.0 Mask:255.255.0.0
inet6 addr: fe80::cb3e:8ad4:3a00:2a07/64 Scope:Link
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
eth0 Link encap:Ethernet HWaddr b8:27:eb:48:8f:ee
inet addr:192.168.0.100 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::ba27:ebff:fe48:8fee/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2074 errors:0 dropped:0 overruns:0 frame:0
TX packets:1615 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:151891 (148.3 KiB) TX bytes:441121 (430.7 KiB)
pi@rpi ~ $
更换搜索关键字
忽然想到我是在用 ecl
启动 swank
的过程中报错的, 那么试着换换关键字搜索一下, 这回用 "swank
Cannot assign requested address
" 当关键字放狗来搜, 很幸运的第一个就搜到了一条貌似非常接近我的情况的Swank socket problem
他的问题跟我差不多,也是想通过 SBCL
加载 swank
时出错, 错误信息:
* (load "swank-loader.lisp")
...
* (swank:create-server :port 12345)
debugger invoked on a SB-BSD-SOCKETS:SOCKET-ERROR in thread #<THREAD
"initial thread" RUNNING {AA1B639}>:
Socket error in "bind": 99 (Cannot assign requested address)
回复提到要检查 loopback
接口
That usualy means you are trying to bind socket on the address not on
this machine.
I think slime determines your address by localhost or hostname, are
they right? And does loopback 127.0.0.1 exist?
然后楼主的反馈证实他的 loopback
接口没起来, 起来就好了:
Thanks for the hint, the loopback interface was not started.
Now it works :)
Cornelius
我上面的网络状况好像也没看到 loopback
接口, 先备份原来的配置文件, 再试着改改配置把它跑起来, 修改后的网络配置文件如下:
pi@rpi ~ $ sudo vi /etc/network/interfaces
1 auto lo
2 iface lo inet loopback
3 iface eth0 inet dhcp
4
5 allow-hotplug wlan0
6 auto wlan0
pi@rpi ~ $
修改后保存, 试着执行这个命令重启下网络配置:
sudo /etc/init.d/networking restart
结果没效果, 还是没搞起 lo
来, 只好用 sudo reboot
重启系统, 重启后终于发现了久违的 lo
接口:
pi@rpi ~ $ ifconfig
docker0 Link encap:Ethernet HWaddr 02:42:01:89:10:22
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
eth0 Link encap:Ethernet HWaddr b8:27:eb:48:8f:ee
inet addr:192.168.0.100 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::ba27:ebff:fe48:8fee/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:125 errors:0 dropped:0 overruns:0 frame:0
TX packets:146 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:15662 (15.2 KiB) TX bytes:20296 (19.8 KiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:8 errors:0 dropped:0 overruns:0 frame:0
TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1104 (1.0 KiB) TX bytes:1104 (1.0 KiB)
pi@rpi ~ $
泪流满面啊, 这回再试试, 哈哈, 终于成功:
pi@rpi ~ $ ecl -load ~/.vim/bundle/slimv/slime/start-swank.lisp
;;; Loading "/home/pi/.vim/bundle/slimv/slime/start-swank.lisp"
;;; Loading "/opt/github/slimv/slime/swank-loader.lisp"
;;; Warning: No architecture feature found in (POWERPC PPC X86 X86-64 X86_64
AMD64 I686 I586 I486 PC386
IAPX386 SPARC64 SPARC HPPA64
HPPA ARM PENTIUM3 PENTIUM4
JAVA-1.4 JAVA-1.5 JAVA-1.6
JAVA-1.7).
;;; Loading #P"/usr/local/lib/ecl-16.1.2/cmp.fas"
;;; Loading "/home/pi/.slime/fasl/2014-10-10/ecl-16.1.2-linux-unknown/backend.fas"
;;; Loading "/home/pi/.slime/fasl/2014-10-10/ecl-16.1.2-linux-unknown/ecl.fas"
;;; Loading #P"/usr/local/lib/ecl-16.1.2/sockets.fas"
;;; Loading #P"/usr/local/lib/ecl-16.1.2/profile.fas"
;;; Loading #P"/usr/local/lib/ecl-16.1.2/serve-event.fas"
;;; Loading "/home/pi/.slime/fasl/2014-10-10/ecl-16.1.2-linux-unknown/gray.fas"
;;; Loading "/home/pi/.slime/fasl/2014-10-10/ecl-16.1.2-linux-unknown/match.fas"
;;; Loading "/home/pi/.slime/fasl/2014-10-10/ecl-16.1.2-linux-unknown/rpc.fas"
;;; Loading "/home/pi/.slime/fasl/2014-10-10/ecl-16.1.2-linux-unknown/swank.fas"
;; Swank started at port: 4005.
再在 tmux
上开个窗口用 telnet
试着连一下:
pi@rpi ~ $ telnet 127.0.0.1 4005
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
很好, 终于看到 CL-USER>
这个提示符了:
CL-USER> (+ 1 2)
3
CL-USER>
至此, 问题完美解决, 教训就是:
不能光凭经验下结论, 一定要查看最基本的网络情况( ifconfig )
知识点
另外, 又了解到一个知识点: loopback
接口没起来的话, 也会导致 Socket error in "bind": 99 (Cannot assign requested address) 错误的出现.
来源:oschina
链接:https://my.oschina.net/u/219279/blog/683716