Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

request help: Could APISIX use nacos as registry center #1731

Closed
keven0706 opened this issue Jun 18, 2020 · 17 comments
Closed

request help: Could APISIX use nacos as registry center #1731

keven0706 opened this issue Jun 18, 2020 · 17 comments
Labels
checking check first if this issue occurred

Comments

@keven0706
Copy link

Issue description

apisix can user nacos for regestry center?

Environment

  • apisix version (cmd: apisix version):
  • OS:
@membphis
Copy link
Member

that is todo, welcome PR.

@moonming
Copy link
Member

@keven0706 nacos supports DNS-based Service Discovery, so you can change the dns_resolver in config.yaml to nacos.
And Consul is the same way to works with APISIX, you can refer to this script: https://gist.github.com/moonming/32aed4922ea428db1abfe2edfd730b3a

@moonming
Copy link
Member

that is todo, welcome PR.

It is not a todo, Apache APISIX can works well with nacos and consul.

@membphis
Copy link
Member

I think only support DNS-based Service Discovery for nacos is not enough.

The nacos call it Dynamic Configuration Management, Apache APISIX need to support both of them.

@membphis
Copy link
Member

nacos supports DNS-based Service Discovery,

It needs to be written into the document.

@HuangDayu
Copy link

HuangDayu commented Oct 15, 2020

@keven0706 nacos supports DNS-based Service Discovery, so you can change the dns_resolver in config.yaml to nacos.
And Consul is the same way to works with APISIX, you can refer to this script: https://gist.github.com/moonming/32aed4922ea428db1abfe2edfd730b3a

China cannot access gist, can you provide a document? Thank you. issues/2431

@juzhiyuan juzhiyuan changed the title request help: request help: Could APISIX use nacos for registry center Oct 15, 2020
@juzhiyuan juzhiyuan changed the title request help: Could APISIX use nacos for registry center request help: Could APISIX use nacos as registry center Oct 15, 2020
@juzhiyuan
Copy link
Member

juzhiyuan commented Oct 15, 2020

Install Consul

  1. download consul
$ wget https://releases.hashicorp.com/consul/1.7.3/consul_1.7.3_linux_amd64.zip
  1. unzip to /usr/bin
$ sudo unzip consul_1.7.3_linux_amd64.zip -d /usr/bin
  1. create consul service file
$ sudo vim /lib/systemd/system/consul.service

[Unit]
Description=consul
[Service]
ExecStart=/usr/bin/consul agent -config-dir /etc/consul
KillSignal=SIGINT
  1. create server json file
$ sudo mkdir /etc/consul/

$ sudo vim /etc/consul/server.json
{
	"data_dir": "/var/consul",
	"log_level": "INFO",
	"node_name": "test",
	"server": true,
	"ui": true,
	"bootstrap_expect": 1,
	"client_addr": "0.0.0.0",
	"advertise_addr": "127.0.0.1",
	"ports": {
		"dns": 53
	},	
	"advertise_addr_wan": "127.0.0.1"
}
  1. start consul
$ sudo systemctl start consul

start service - golang version

$ git clone https://github.com/api7/consul-test-golang.git

$ cd consul-test-golang

$ nohup go run main.go &

install etcd -- need by Apache APISIX

$ sudo yum install etcd

$ nohup /usr/bin/etcd --enable-v2=true &

install openresty -- need by Apache APISIX

$ wget https://openresty.org/package/centos/openresty.repo

$ sudo mv openresty.repo /etc/yum.repos.d/

$ sudo yum install openresty -y

install Apache APISIX

  1. install from RPM, and you can get the latest version from https://github.com/apache/incubator-apisix/releases
$ wget https://github.com/apache/incubator-apisix/releases/download/1.3/apisix-1.3-0.el7.noarch.rpm

$ sudo yum install apisix-1.3-0.el7.noarch.rpm -y
  1. change config.yaml
$ vi /usr/local/apisix/conf/config.yaml

$ add consul address to `dns_resolver`
  dns_resolver:
   - 127.0.0.1
  1. start Apache APISIX:
$ sudo apisix start

Test

  1. add route in Apache APISIX:
$ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d '
{
    "uri": "/healthz",
    "upstream": {
        "type": "roundrobin",
        "nodes": {
            "go-consul-test.service.consul:8080": 1
        }
    }
}'

go-consul-test.service.consul is registered DNS SRV by consul-test-golang service

  1. test:
$ curl http://127.0.0.1:9080/healthz

will return:

{"message":"consul test healthz"}

Cool, it works!

If you have any questions, please goto https://github.com/apache/incubator-apisix

@juzhiyuan
Copy link
Member

@keven0706 nacos supports DNS-based Service Discovery, so you can change the dns_resolver in config.yaml to nacos.
And Consul is the same way to works with APISIX, you can refer to this script: https://gist.github.com/moonming/32aed4922ea428db1abfe2edfd730b3a

China cannot access gist, can you provide a document? Thank you. issues/2431

I just copied those steps from here[1], not sure if it's what you need.

[1] https://gist.github.com/moonming/32aed4922ea428db1abfe2edfd730b3a

@HuangDayu
Copy link

@juzhiyuan 非常感谢,我也看到了这篇博文。 Apache APISIX 101:如何使用 Consul 作为注册中心?
但是nacos的dns需要使用额外的服务生成,然而我再安装这个服务时,再次遇到了问题。

https://github.com/nacos-group/nacos-coredns-plugin
https://github.com/coredns/coredns
https://github.com/caddyserver/caddy

go get -u github.com/mholt/caddy
go: github.com/mholt/caddy upgrade => v1.0.5
go get: github.com/mholt/caddy@v1.0.5: parsing go.mod:
        module declares its path as: github.com/caddyserver/caddy
                but was required as: github.com/mholt/caddy
make: *** [godeps] Error 1

因为对Go不熟悉,在网上也找不到可行的解决方案,又卡在这了。

@juzhiyuan
Copy link
Member

Not sure what happened, just be patient to wait for others' reply.

@juzhiyuan juzhiyuan added the checking check first if this issue occurred label Oct 16, 2020
@spacewander
Copy link
Member

go get -u github.com/mholt/caddy

Why did you run this command?
When you install coredns, the caddy will be installed as a dependency. There should be no need to install it manually.
Or do I miss something?

@HuangDayu
Copy link

go get -u github.com/mholt/caddy

Why did you run this command?
When you install coredns, the caddy will be installed as a dependency. There should be no need to install it manually.
Or do I miss something?

nacos-coredns-plugin 用到了该模块,但是该模块的所有者变更了

@spacewander
Copy link
Member

I look through the code of nacos-coredns-plugin. It seems that https://github.com/nacos-group/nacos-coredns-plugin/tree/feature_switch_to_coredns_master_branch might be able to work.

@HuangDayu
Copy link

HuangDayu commented Oct 16, 2020

I look through the code of nacos-coredns-plugin. It seems that https://github.com/nacos-group/nacos-coredns-plugin/tree/feature_switch_to_coredns_master_branch might be able to work.

编译时出现的错误,如果可以的话,你也可以尝试一下,看能不能成功。

@jaredhuang
Copy link

@HuangDayu 碰到跟你一样的问题,我的解决方案是编译这个版本的 https://github.com/nacos-group/nacos-coredns-plugin/tree/v1.6.7 ,这个开发者有一直在维护的,编译的时候,打开 build.sh 里面的命令,手动一个,一个去执行。理解整个步骤,能编译出来的。
[root@test]# ./coredns -version log directory: /root/logs/nacos-go-client/ **register nacos plugin** CoreDNS-1.6.7 linux/amd64, go1.13, da7f65b-dirty

在测试CoreDNS的 nacos plugin 插件的时候,我发现 nacos plugin 是不支持 namespaceId 非 pulic 的。

@HuangDayu
Copy link

@HuangDayu 碰到跟你一样的问题,我的解决方案是编译这个版本的 https://github.com/nacos-group/nacos-coredns-plugin/tree/v1.6.7 ,这个开发者有一直在维护的,编译的时候,打开 build.sh 里面的命令,手动一个,一个去执行。理解整个步骤,能编译出来的。
[root@test]# ./coredns -version log directory: /root/logs/nacos-go-client/ **register nacos plugin** CoreDNS-1.6.7 linux/amd64, go1.13, da7f65b-dirty

在测试CoreDNS的 nacos plugin 插件的时候,我发现 nacos plugin 是不支持 namespaceId 非 pulic 的。

谢谢,不过我已经弃坑了,改用kong+consul

@membphis
Copy link
Member

谢谢,不过我已经弃坑了,改用kong+consul

Do you use the DNS way? If yes, the APISIX can work in the same way too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
checking check first if this issue occurred
Projects
None yet
Development

No branches or pull requests

7 participants