由于需要测试go-zero rpc,需要安装Etcd进行测试,在下载完安装包解压后,执行启动指令报错:
[root@node01 etcd-v3.5.15]# ./etcd
{"level":"warn","ts":"2024-07-26T14:02:59.016025+0800","caller":"embed/config.go:687","msg":"Running http and grpc server on single port. This is not recommended for production."}
{"level":"info","ts":"2024-07-26T14:02:59.016109+0800","caller":"etcdmain/etcd.go:73","msg":"Running: ","args":["./etcd"]}
{"level":"warn","ts":"2024-07-26T14:02:59.016132+0800","caller":"etcdmain/etcd.go:105","msg":"'data-dir' was empty; using default","data-dir":"default.etcd"}
{"level":"warn","ts":"2024-07-26T14:02:59.016156+0800","caller":"embed/config.go:687","msg":"Running http and grpc server on single port. This is not recommended for production."}
{"level":"info","ts":"2024-07-26T14:02:59.016163+0800","caller":"embed/etcd.go:128","msg":"configuring peer listeners","listen-peer-urls":["http://localhost:2380"]}
{"level":"error","ts":"2024-07-26T14:02:59.016747+0800","caller":"embed/etcd.go:538","msg":"creating peer listener failed","error":"listen tcp: lookup localhost on [::1]:53: read udp [::1]:54954->[::1]:53: read: connection refused","stacktrace":"go.etcd.io/etcd/server/v3/embed.configurePeerListeners\n\tgo.etcd.io/etcd/server/v3/embed/etcd.go:538\ngo.etcd.io/etcd/server/v3/embed.StartEtcd\n\tgo.etcd.io/etcd/server/v3/embed/etcd.go:132\ngo.etcd.io/etcd/server/v3/etcdmain.startEtcd\n\tgo.etcd.io/etcd/server/v3/etcdmain/etcd.go:228\ngo.etcd.io/etcd/server/v3/etcdmain.startEtcdOrProxyV2\n\tgo.etcd.io/etcd/server/v3/etcdmain/etcd.go:135\ngo.etcd.io/etcd/server/v3/etcdmain.Main\n\tgo.etcd.io/etcd/server/v3/etcdmain/main.go:40\nmain.main\n\tgo.etcd.io/etcd/server/v3/main.go:31\nruntime.main\n\truntime/proc.go:267"}
{"level":"info","ts":"2024-07-26T14:02:59.016810+0800","caller":"embed/etcd.go:377","msg":"closing etcd server","name":"default","data-dir":"default.etcd","advertise-peer-urls":["http://localhost:2380"],"advertise-client-urls":["http://localhost:2379"]}
{"level":"info","ts":"2024-07-26T14:02:59.016817+0800","caller":"embed/etcd.go:379","msg":"closed etcd server","name":"default","data-dir":"default.etcd","advertise-peer-urls":["http://localhost:2380"],"advertise-client-urls":["http://localhost:2379"]}
{"level":"warn","ts":"2024-07-26T14:02:59.016849+0800","caller":"etcdmain/etcd.go:146","msg":"failed to start etcd","error":"listen tcp: lookup localhost on [::1]:53: read udp [::1]:54954->[::1]:53: read: connection refused"}
{"level":"fatal","ts":"2024-07-26T14:02:59.016864+0800","caller":"etcdmain/etcd.go:204","msg":"discovery failed","error":"listen tcp: lookup localhost on [::1]:53: read udp [::1]:54954->[::1]:53: read: connection refused","stacktrace":"go.etcd.io/etcd/server/v3/etcdmain.startEtcdOrProxyV2\n\tgo.etcd.io/etcd/server/v3/etcdmain/etcd.go:204\ngo.etcd.io/etcd/server/v3/etcdmain.Main\n\tgo.etcd.io/etcd/server/v3/etcdmain/main.go:40\nmain.main\n\tgo.etcd.io/etcd/server/v3/main.go:31\nruntime.main\n\truntime/proc.go:267"}
具体原因是虚拟机centos系统本身IP没设置映射,添加localhost映射就正常了:
#vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6