You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2020/10/15 15:08:48 UTC

[GitHub] [apisix] juzhiyuan commented on issue #1731: request help: Could APISIX use nacos as registry center

juzhiyuan commented on issue #1731:
URL: https://github.com/apache/apisix/issues/1731#issuecomment-709390658


   ```
   ## Install Consul
   1. download consul
   ```
   wget https://releases.hashicorp.com/consul/1.7.3/consul_1.7.3_linux_amd64.zip
   ```
   
   2. unzip to `/usr/bin` 
   
   ```
   sudo unzip consul_1.7.3_linux_amd64.zip -d /usr/bin
   ```
   
   3. 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
   ```
   
   4. 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"
   }
   ```
   
   5. 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
   ```
   
   2. change config.yaml
   
   vi /usr/local/apisix/conf/config.yaml
   
   add consul address to `dns_resolver`:
   
   ```
     dns_resolver:
      - 127.0.0.1
   ```
   
   3. 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**
   
   
   2. 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
   ```


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org